Skip to content

Commit

Permalink
Non-blocking MIDI player #1520
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Dec 31, 2024
1 parent e4e0fe3 commit e70c23a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2024 QL-Win Contributors
// Copyright © 2017–2025 QL-Win Contributors
//
// This file is part of QuickLook program.
//
Expand All @@ -24,9 +24,7 @@
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand Down Expand Up @@ -56,8 +54,6 @@ private set
}
}

public event PropertyChangedEventHandler PropertyChanged;

public MidiPlayer(ViewerPanel panle, ContextObject context)
{
_vp = panle;
Expand All @@ -76,7 +72,7 @@ public void Dispose()
_outputDevice = null;
}

public void LoadAndPlay(string path, MediaInfoLib info)
public void LoadAndPlay(string path)
{
_midiFile = MidiFile.Read(path);
_vp.metaTitle.Text = Path.GetFileName(path);
Expand Down Expand Up @@ -200,13 +196,13 @@ public void LoadAndPlay(string path, MediaInfoLib info)
}
};

// Playback supported by DryWetMidi will block the current thread
// So we should run it in a new thread
_ = Task.Run(() => _playback?.Play());
_playback.Start();
_vp.buttonPlayPause.Content = FontSymbols.Pause;
_context.IsBusy = false;
}

public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ public void LoadAndPlay(string path, MediaInfoLib info)
if (audioCodec?.Equals("MIDI", StringComparison.OrdinalIgnoreCase) ?? false)
{
_midiPlayer = new MidiPlayer(this, _context);
_midiPlayer.LoadAndPlay(path, info);
return; // MIDI player will handle the playback at all
_midiPlayer.LoadAndPlay(path);
return; // Midi player will handle the playback at all
}
}

Expand Down

0 comments on commit e70c23a

Please sign in to comment.