Skip to content

Commit

Permalink
auto-load waveform for videos with sound
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasbaur committed Apr 20, 2018
1 parent 74586df commit 639390b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 91 deletions.
50 changes: 31 additions & 19 deletions App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,39 @@ public void OnKeyDown(object sender, KeyEventArgs e)
private void HandleClArgs(IList<string> args)
{
if (args.Count <= 1) return;
for (var i = 1; i < args.Count; i++)
{
try
{
//for (var i = 1; i < args.Count; i++)
//{
// try
// {

string filerooted;
if (!Path.IsPathRooted(args[i]))
{
filerooted = Directory.GetCurrentDirectory() + "\\" + args[i];
}
else
{
filerooted = args[i];
}
viewh.loadMultipleFilesOrDirectory(new[] { filerooted });
}
catch (Exception)
{
// ignored
}
// string filerooted;
// if (!Path.IsPathRooted(args[i]))
// {
// filerooted = Directory.GetCurrentDirectory() + "\\" + args[i];
// }
// else
// {
// filerooted = args[i];
// }
// viewh.loadMultipleFilesOrDirectory(new[] { filerooted });
// }
// catch (Exception)
// {
// // ignored
// }
//}

string path = args[1];
for (var i = 2; i < args.Count; i++)
{
path += " " + args[i];
}
if (!Path.IsPathRooted(path))
{
path = Directory.GetCurrentDirectory() + "\\" + path;
}
viewh.loadFile(path);

}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand Down
7 changes: 2 additions & 5 deletions Controls/MainHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ public partial class MainHandler
{

//Config
public static string BuildVersion = "1.0.2.2";
public static MEDIABACKEND Mediabackend = MEDIABACKEND.MEDIAKIT;



public static string BuildVersion = "1.0.2.3";
public static MEDIABACKEND MediaBackend = MEDIABACKEND.MEDIAKIT;

private static Timeline timeline = null;

Expand Down
65 changes: 34 additions & 31 deletions Controls/MainHandlerFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void loadMultipleFilesOrDirectory(string[] filenames)

}

private bool loadFile(string filepath)
public bool loadFile(string filepath)
{
return loadFile(filepath, Defaults.Colors.Foreground, Defaults.Colors.Background);
}
Expand All @@ -72,11 +72,10 @@ private bool loadFile(string filepath,
string type = filepath.Substring(index + 1).ToLower();
switch (type)
{
case "mp4":
case "avi":
case "wmv":
case "mp4":
case "mov":
case "m4a":
case "mov":
case "mkv":
case "divx":
case "mpg":
Expand All @@ -99,6 +98,7 @@ private bool loadFile(string filepath,
case "wma":
case "wav":
case "mp3":
case "m4a":
case "flac":
ftype = SSI_FILE_TYPE.AUDIO;
break;
Expand Down Expand Up @@ -136,22 +136,22 @@ private bool loadFile(string filepath,
switch (ftype)
{
case SSI_FILE_TYPE.VIDEO:
loadMediaFile(filepath, MediaType.VIDEO);
loaded = true;
break;

case SSI_FILE_TYPE.AUDIO:

string type = filepath.Substring(index + 1);
Signal signal = null;
loadAudioSignalFile(filepath, foreground, background);
if (ftype != SSI_FILE_TYPE.AUDIO)
{
loadMediaFile(filepath, MediaType.VIDEO);
}

IMedia media = loadMediaFile(filepath, MediaType.AUDIO);
Signal signal = loadAudioSignalFile(filepath, foreground, background);

if (signal != null)
{
signal.Media = media;
{
signal.Media = loadMediaFile(filepath, MediaType.AUDIO);
}

loaded = true;

break;

case SSI_FILE_TYPE.ANNOTATION:
Expand Down Expand Up @@ -214,14 +214,11 @@ private void addMedia(IMedia media)
media.Pause();
mediaList.Add(media);


if (media.GetMediaType() != MediaType.AUDIO)
{
addMediaBox(media);
}



control.navigator.playButton.IsEnabled = true;
}

Expand All @@ -233,9 +230,7 @@ private IMedia loadMediaFile(string filename, MediaType type)
return null;
}



if(Mediabackend == MEDIABACKEND.MEDIAKIT)
if(MediaBackend == MEDIABACKEND.MEDIAKIT)
{
try
{
Expand All @@ -246,24 +241,23 @@ private IMedia loadMediaFile(string filename, MediaType type)
addMedia(media);
return media;
}

catch
{
return null;
//ignore the file
}

}
else if(Mediabackend == MEDIABACKEND.MEDIA)
else if(MediaBackend == MEDIABACKEND.MEDIA)
{
try
{
Media media = new Media(filename, type);
media.OnMediaMouseDown += OnMediaMouseDown;
media.OnMediaMouseUp += OnMediaMouseUp;
media.OnMediaMouseMove += OnMediaMouseMove;
addMedia(media);
return media;
Media media = new Media(filename, type);
media.OnMediaMouseDown += OnMediaMouseDown;
media.OnMediaMouseUp += OnMediaMouseUp;
media.OnMediaMouseMove += OnMediaMouseMove;
addMedia(media);
return media;
}

catch
Expand Down Expand Up @@ -391,15 +385,24 @@ private Signal loadAudioSignalFile(string filename, Color signalColor, Color bac
}


Signal signal;

signal = Signal.LoadAudioFile(filename);
Signal signal = null;

try
{
signal = Signal.LoadAudioFile(filename);
}
catch (Exception e)
{
return null;
}

if (signal != null && signal.loaded)
{
this.control.signalbar.Height = new GridLength(control.signalAndAnnoGrid.ActualHeight / 2 - 30);
this.control.signalstatusbar.Visibility = Visibility.Visible;
addSignalTrack(signal, signalColor, backgroundColor);
}

return signal;
}

Expand Down
14 changes: 5 additions & 9 deletions Controls/MainHandlerMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ private void addMediaBox(IMedia media)

MediaBoxStatic.Select(box);
updateNavigator();


}

public void clearMediaBox()
Expand All @@ -69,15 +67,13 @@ private void updateMediaBox(MediaBox box)
control.mediaStatusFileNameLabel.Text = Path.GetFileName(media.GetFilepath());
control.mediaStatusFileNameLabel.ToolTip = media.GetFilepath();
control.mediaStatusSampleRateLabel.Text = media.GetSampleRate().ToString() + " Hz";
control.mediaVolumeControl.Visibility = Visibility.Collapsed;
if (media.HasAudio())
{
control.mediaVolumeControl.volumeSlider.Value = media.GetVolume();
control.mediaVolumeControl.Visibility = Visibility.Visible;
}
else
{
control.mediaVolumeControl.Visibility = Visibility.Collapsed;
}
media.SetVolume(0.0);
//control.mediaVolumeControl.volumeSlider.Value = media.GetVolume();
//control.mediaVolumeControl.Visibility = Visibility.Visible;
}
control.mediaCloseButton.Visibility = playIsPlaying ? Visibility.Hidden : Visibility.Visible;

if (AnnoTierStatic.Selected != null)
Expand Down
10 changes: 5 additions & 5 deletions Types/AnnoListFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static AnnoList LoadfromFile(string filepath)
list.Scheme = new AnnoScheme();
list.Scheme.Labels = new List<AnnoScheme.Label>();

try
//try
{
XmlDocument doc = new XmlDocument();
doc.Load(filepath);
Expand Down Expand Up @@ -584,10 +584,10 @@ public static AnnoList LoadfromFile(string filepath)


}
catch
{
MessageBox.Show("An exception occured while reading annotation from '" + filepath + "'");
}
//catch(Exception e)
//{
// MessageBox.Show("An exception occured while reading annotation from '" + filepath + "'");
//}

return list;
}
Expand Down
37 changes: 15 additions & 22 deletions Types/SignalFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,30 +484,23 @@ public static bool LoadDataV2b(Signal signal, FileStream fs)
public static Signal LoadAudioFile(string filepath)
{
Signal signal = null;

using (var reader = new AudioFileReader(filepath))
{
try
{
int bytesPerSample = (reader.WaveFormat.BitsPerSample / 8);
var samples = (uint) (reader.Length / (bytesPerSample));
var seconds = reader.TotalTime.TotalSeconds;
double rate = reader.WaveFormat.SampleRate;
uint dimension = (uint) reader.WaveFormat.Channels;

Signal.Type type = (bytesPerSample == 2) ? Signal.Type.SHORT : Signal.Type.FLOAT;
signal = new Signal(filepath, rate, dimension, (uint) bytesPerSample, (samples/dimension), type);
reader.Read(signal.data, 0, (int)samples);
{
int bytesPerSample = (reader.WaveFormat.BitsPerSample / 8);
var samples = (uint) (reader.Length / (bytesPerSample));
var seconds = reader.TotalTime.TotalSeconds;
double rate = reader.WaveFormat.SampleRate;
uint dimension = (uint) reader.WaveFormat.Channels;

Signal.Type type = (bytesPerSample == 2) ? Signal.Type.SHORT : Signal.Type.FLOAT;
signal = new Signal(filepath, rate, dimension, (uint) bytesPerSample, (samples/dimension), type);
reader.Read(signal.data, 0, (int)samples);

signal.minmax();
signal.isAudio = true;
signal.loaded = true;
}
catch (Exception e)
{
MessageTools.Error(e.ToString());
}

}
signal.minmax();
signal.isAudio = true;
signal.loaded = true;
}

return signal;
}
Expand Down
Binary file modified bin/nova.exe
Binary file not shown.

0 comments on commit 639390b

Please sign in to comment.