mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
eac3to gui: audio extraction working
This commit is contained in:
@@ -9,6 +9,12 @@ namespace CUETools.Codecs.BDLPCM
|
||||
[AudioDecoderClass("cuetools", "mpls", 2)]
|
||||
public class MPLSReader : IAudioSource
|
||||
{
|
||||
public unsafe MPLSReader(string path, Stream IO, ushort pid)
|
||||
: this(path, IO)
|
||||
{
|
||||
settings.Pid = pid;
|
||||
}
|
||||
|
||||
public unsafe MPLSReader(string path, Stream IO)
|
||||
{
|
||||
settings = new BDLPCMReaderSettings();
|
||||
|
||||
@@ -103,6 +103,10 @@
|
||||
<Project>{e75f7ccd-4266-42e1-a039-dc7eb5edd8f6}</Project>
|
||||
<Name>CUETools.Codecs.BDLPCM</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\CUETools.Codecs.FLAKE\CUETools.Codecs.FLAKE.csproj">
|
||||
<Project>{082d6b9e-326e-4d15-9798-edae9ede70a6}</Project>
|
||||
<Name>CUETools.Codecs.FLAKE</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\CUETools.Codecs\CUETools.Codecs.csproj">
|
||||
<Project>{6458a13a-30ef-45a9-9d58-e5031b17bee2}</Project>
|
||||
<Name>CUETools.Codecs</Name>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
MinWidth="300" MaxWidth="1200" MinHeight="300" MaxHeight="300"
|
||||
Title="CUETools eac3to" Height="300" Width="600" Closing="Window_Closing">
|
||||
<StackPanel>
|
||||
<StackPanel x:Name="stackParams">
|
||||
<DockPanel>
|
||||
<Label x:Name="labelSource" Content="Source" Margin="8" Width="80"/>
|
||||
<Button x:Name="buttonBrowseSource" Content="Browse" Click="ButtonBrowseSource_Click" DockPanel.Dock="Right" Margin="8"/>
|
||||
@@ -26,7 +27,8 @@
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Rectangle Fill="{Binding Name}" Width="16" Height="16" Margin="0,2,5,2" />
|
||||
<TextBlock Text="{Binding FileName}" Margin="10,0" />
|
||||
<TextBlock Text="{Binding Duration}" />
|
||||
<TextBlock Text="{Binding Duration, StringFormat={}({0:hh\\:mm\\:ss})}" />
|
||||
<TextBlock Text="{Binding Chapters.Count, StringFormat={}{0,2} chapters}" Margin="10,0" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
@@ -63,9 +65,11 @@
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<DockPanel>
|
||||
<Button x:Name="buttonExtract" Content="Extract" DockPanel.Dock="Right" Margin="8"/>
|
||||
<Label></Label>
|
||||
<Button x:Name="buttonStop" Content="Stop" DockPanel.Dock="Left" Margin="8" Click="buttonStop_Click" Visibility="Hidden" Width="80"/>
|
||||
<Button x:Name="buttonExtract" Content="Extract" DockPanel.Dock="Right" Margin="8" Click="buttonExtract_Click"/>
|
||||
<ProgressBar Minimum="0" Maximum="100" Name="pbStatus" Margin="8" Visibility="Collapsed"/>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
|
||||
@@ -16,6 +16,10 @@ using System.Windows.Navigation;
|
||||
using CUETools.Codecs.BDLPCM;
|
||||
using CUETools.CDImage;
|
||||
using CUETools.CTDB;
|
||||
using System.ComponentModel;
|
||||
using Krystalware.UploadHelper;
|
||||
using CUETools.Codecs;
|
||||
using CUETools.Codecs.FLAKE;
|
||||
//using Microsoft.Win32;
|
||||
|
||||
namespace CUETools.eac3ui
|
||||
@@ -88,6 +92,7 @@ namespace CUETools.eac3ui
|
||||
private void cmbTitleSet_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
cmbMetadata.ItemsSource = new List<CTDBResponseMeta>();
|
||||
ctdb = null;
|
||||
|
||||
var audios = new List<MPLSStream>();
|
||||
if (e.AddedItems.Count == 1)
|
||||
@@ -96,21 +101,50 @@ namespace CUETools.eac3ui
|
||||
rdr.MPLSHeader.play_item.ForEach(i => i.audio.ForEach(v => { if (!audios.Exists(v1 => v1.pid == v.pid)) audios.Add(v); }));
|
||||
|
||||
var chapters = rdr.Chapters;
|
||||
if (chapters.Count > 2)
|
||||
{
|
||||
string strtoc = "";
|
||||
for (int i = 0; i < chapters.Count; i++)
|
||||
strtoc += string.Format(" {0}", chapters[i] / 600);
|
||||
strtoc = strtoc.Substring(1);
|
||||
CDImageLayout toc = new CDImageLayout(strtoc);
|
||||
var ctdb = new CUEToolsDB(toc, null);
|
||||
//Console.Error.WriteLine("Contacting CTDB...");
|
||||
ctdb.ContactDB(null, "CUETools.eac3to 2.1.7", "", false, true, CTDBMetadataSearch.Extensive);
|
||||
cmbMetadata.ItemsSource = ctdb.Metadata;
|
||||
cmbMetadata.SelectedIndex = 0;
|
||||
ctdb = new CUEToolsDB(toc, null);
|
||||
workerCtdb = new BackgroundWorker();
|
||||
workerCtdb.DoWork += workerCtdb_DoWork;
|
||||
workerCtdb.RunWorkerAsync();
|
||||
}
|
||||
}
|
||||
cmbAudioTrack.ItemsSource = audios;
|
||||
cmbAudioTrack.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
void workerCtdb_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
//Console.Error.WriteLine("Contacting CTDB...");
|
||||
this.Dispatcher.Invoke(() =>
|
||||
{
|
||||
pbStatus.Visibility = Visibility.Visible;
|
||||
pbStatus.IsIndeterminate = true;
|
||||
});
|
||||
//ctdb.UploadHelper.onProgress += worker_ctdbProgress;
|
||||
ctdb.ContactDB(null, "CUETools.eac3to 2.1.7", "", false, true, CTDBMetadataSearch.Extensive);
|
||||
this.Dispatcher.Invoke(() =>
|
||||
{
|
||||
pbStatus.Visibility = Visibility.Collapsed;
|
||||
pbStatus.IsIndeterminate = false;
|
||||
cmbMetadata.ItemsSource = ctdb.Metadata;
|
||||
cmbMetadata.SelectedIndex = 0;
|
||||
});
|
||||
}
|
||||
|
||||
//private void worker_ctdbProgress(object sender, UploadProgressEventArgs args)
|
||||
//{
|
||||
// this.Dispatcher.Invoke(() =>
|
||||
// {
|
||||
// pbStatus.Value = (int)args.percent;
|
||||
// });
|
||||
//}
|
||||
|
||||
private void cmbAudioTrack_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.AddedItems.Count == 1)
|
||||
@@ -118,5 +152,107 @@ namespace CUETools.eac3ui
|
||||
MPLSStream stream = (MPLSStream)(e.AddedItems[0]);
|
||||
}
|
||||
}
|
||||
|
||||
BackgroundWorker workerCtdb;
|
||||
CUEToolsDB ctdb;
|
||||
|
||||
BackgroundWorker workerExtract;
|
||||
CTDBResponseMeta meta;
|
||||
MPLSReader reader;
|
||||
ushort pid;
|
||||
string outputPath;
|
||||
|
||||
private void buttonExtract_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (cmbTitleSet.SelectedItem == null) return;
|
||||
pid = ((MPLSStream)cmbAudioTrack.SelectedItem).pid;
|
||||
reader = new MPLSReader((cmbTitleSet.SelectedItem as MPLSReader).Path, null, pid);
|
||||
meta = cmbMetadata.SelectedItem as CTDBResponseMeta;
|
||||
outputPath = Path.Combine(textBoxDestination.Text, meta != null ? meta.artist + " - " + meta.year + " - " + meta.album + ".flac" : "image.flac");
|
||||
|
||||
pbStatus.Visibility = Visibility.Visible;
|
||||
pbStatus.Value = 0.0;
|
||||
//pbStatus.IsIndeterminate = true;
|
||||
stackParams.IsEnabled = false;
|
||||
buttonExtract.IsEnabled = false;
|
||||
buttonStop.Visibility = Visibility.Visible;
|
||||
buttonStop.IsEnabled = true;
|
||||
|
||||
workerExtract = new BackgroundWorker();
|
||||
workerExtract.WorkerSupportsCancellation = true;
|
||||
workerExtract.DoWork += workerExtract_DoWork;
|
||||
workerExtract.RunWorkerAsync();
|
||||
}
|
||||
|
||||
void workerExtract_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
AudioBuffer buff = new AudioBuffer(reader, 0x10000);
|
||||
FlakeWriterSettings settings = new FlakeWriterSettings()
|
||||
{
|
||||
PCM = reader.PCM,
|
||||
Padding = 16536,
|
||||
EncoderMode = "5"
|
||||
};
|
||||
var start = DateTime.Now;
|
||||
TimeSpan lastPrint = TimeSpan.FromMilliseconds(0);
|
||||
var writer = new FlakeWriter(outputPath, settings);
|
||||
try
|
||||
{
|
||||
while (reader.Read(buff, -1) != 0)
|
||||
{
|
||||
writer.Write(buff);
|
||||
TimeSpan elapsed = DateTime.Now - start;
|
||||
if ((elapsed - lastPrint).TotalMilliseconds > 60)
|
||||
{
|
||||
long length = Math.Max((long)(reader.Duration.TotalSeconds * reader.PCM.SampleRate), Math.Max(reader.Position, 1));
|
||||
this.Dispatcher.Invoke(() =>
|
||||
{
|
||||
pbStatus.Value = 100.0 * reader.Position / length;
|
||||
});
|
||||
lastPrint = elapsed;
|
||||
}
|
||||
if (workerExtract.CancellationPending)
|
||||
{
|
||||
throw new Exception("aborted");
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Dispatcher.Invoke(() =>
|
||||
{
|
||||
MessageBox.Show(this, ex.Message, "Extraction failed");
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.Close();
|
||||
reader = null;
|
||||
}
|
||||
|
||||
this.Dispatcher.Invoke(() =>
|
||||
{
|
||||
pbStatus.Visibility = Visibility.Collapsed;
|
||||
//pbStatus.IsIndeterminate = false;
|
||||
stackParams.IsEnabled = true;
|
||||
buttonExtract.IsEnabled = true;
|
||||
buttonStop.Visibility = Visibility.Hidden;
|
||||
buttonStop.IsEnabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
private void buttonStop_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
workerExtract.CancelAsync();
|
||||
buttonStop.Visibility = Visibility.Hidden;
|
||||
buttonStop.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user