Skip to content

Commit

Permalink
Waveforms are now more useful:
Browse files Browse the repository at this point in the history
 - Closes #12
 - Refactored a bunch of stuff
 - Fixed some bugs with the volume slider and fades
 - Fixed a bug where if no fade out was specified the sound cue wouldn't respect it's duration field
 - Fixed some threading issues
 - WaveFormRenderer now exclusively runs on the main thread
 - Improved mouse capturing
 - The waveform now responds to the volume slider
 - Added a playback marker to the waveform
 - Added In and Out point draggable markers to the waveform to make it easier to set the start time and duration of clips
 - Lots of bugfixes (and new bugs!) to the WaveForm control
 - Added transport controls to the waveform window
  • Loading branch information
space928 committed Mar 29, 2024
1 parent b78c98b commit c1e8168
Show file tree
Hide file tree
Showing 9 changed files with 698 additions and 421 deletions.
387 changes: 387 additions & 0 deletions QPlayer/Models/PeakFile.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion QPlayer/QPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<Title>QPlayer</Title>
<Version>1.5.1-beta</Version>
<Version>1.5.2-beta</Version>
<Authors>Thomas Mathieson</Authors>
<Company>Thomas Mathieson</Company>
<Copyright>©️ Thomas Mathieson 2024</Copyright>
Expand Down
File renamed without changes.
21 changes: 17 additions & 4 deletions QPlayer/ViewModels/SoundCueViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ [Reactive] public override TimeSpan PlaybackTime
public SoundCueViewModel(MainViewModel mainViewModel) : base(mainViewModel)
{
OpenMediaFileCommand = new(OpenMediaFileExecute);
audioProgressUpdater = new Timer(100);
audioProgressUpdater = new Timer(50);
audioProgressUpdater.Elapsed += AudioProgressUpdater_Elapsed;
fadeOutTimer = new Timer
{
Expand All @@ -72,7 +72,7 @@ public SoundCueViewModel(MainViewModel mainViewModel) : base(mainViewModel)
break;
}
};
waveFormRenderer = new WaveFormRenderer();
waveFormRenderer = new WaveFormRenderer(this);
}

/// <summary>
Expand Down Expand Up @@ -133,7 +133,8 @@ public override void Go()
}
}
mainViewModel.AudioPlaybackManager.PlaySound(fadeInOutProvider, (x)=>Stop());
fadeInOutProvider.BeginFade(1, Math.Max(FadeIn * 1000, 1000/(double)fadeInOutProvider.WaveFormat.SampleRate), FadeType);
fadeInOutProvider.Volume = 0;
fadeInOutProvider.BeginFade(Volume, Math.Max(FadeIn * 1000, 1000/(double)fadeInOutProvider.WaveFormat.SampleRate), FadeType);
}

public override void Pause()
Expand All @@ -144,6 +145,9 @@ public override void Pause()
mainViewModel.AudioPlaybackManager.StopSound(fadeInOutProvider);
audioProgressUpdater.Stop();
fadeOutTimer.Stop();
OnPropertyChanged(nameof(PlaybackTime));
OnPropertyChanged(nameof(PlaybackTimeString));
OnPropertyChanged(nameof(PlaybackTimeStringShort));
}

public override void Stop()
Expand Down Expand Up @@ -241,6 +245,11 @@ private void AudioProgressUpdater_Elapsed(object? sender, ElapsedEventArgs e)
OnPropertyChanged(nameof(PlaybackTime));
OnPropertyChanged(nameof(PlaybackTimeString));
OnPropertyChanged(nameof(PlaybackTimeStringShort));

// When not using a fadeout, there's nothing to stop the sound early if it's been trimmed.
// This won't be very accurate, but should work for now...
if (PlaybackTime >= Duration)
Stop();
}, null);
}

Expand Down Expand Up @@ -306,7 +315,11 @@ private void LoadAudioFile()
return await PeakFileWriter.LoadOrGeneratePeakFile(path);
}).ContinueWith(x =>
{
waveFormRenderer.PeakFile = x.Result;
// Make sure this happens on the UI thread...
synchronizationContext?.Post(x =>
{
waveFormRenderer.PeakFile = (PeakFile?)x;
}, x.Result);
});
} catch (Exception ex)
{
Expand Down
Loading

0 comments on commit c1e8168

Please sign in to comment.