mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 10:19:07 +00:00
Non-blocking MIDI player #1520
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// Copyright © 2024 QL-Win Contributors
|
// Copyright © 2017–2025 QL-Win Contributors
|
||||||
//
|
//
|
||||||
// This file is part of QuickLook program.
|
// This file is part of QuickLook program.
|
||||||
//
|
//
|
||||||
@@ -24,9 +24,7 @@ using System;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
@@ -56,8 +54,6 @@ internal class MidiPlayer : IDisposable, INotifyPropertyChanged
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
|
||||||
|
|
||||||
public MidiPlayer(ViewerPanel panle, ContextObject context)
|
public MidiPlayer(ViewerPanel panle, ContextObject context)
|
||||||
{
|
{
|
||||||
_vp = panle;
|
_vp = panle;
|
||||||
@@ -76,7 +72,7 @@ internal class MidiPlayer : IDisposable, INotifyPropertyChanged
|
|||||||
_outputDevice = null;
|
_outputDevice = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadAndPlay(string path, MediaInfoLib info)
|
public void LoadAndPlay(string path)
|
||||||
{
|
{
|
||||||
_midiFile = MidiFile.Read(path);
|
_midiFile = MidiFile.Read(path);
|
||||||
_vp.metaTitle.Text = Path.GetFileName(path);
|
_vp.metaTitle.Text = Path.GetFileName(path);
|
||||||
@@ -200,13 +196,13 @@ internal class MidiPlayer : IDisposable, INotifyPropertyChanged
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Playback supported by DryWetMidi will block the current thread
|
_playback.Start();
|
||||||
// So we should run it in a new thread
|
|
||||||
_ = Task.Run(() => _playback?.Play());
|
|
||||||
_vp.buttonPlayPause.Content = FontSymbols.Pause;
|
_vp.buttonPlayPause.Content = FontSymbols.Pause;
|
||||||
_context.IsBusy = false;
|
_context.IsBusy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
[NotifyPropertyChangedInvocator]
|
[NotifyPropertyChangedInvocator]
|
||||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||||
{
|
{
|
||||||
|
@@ -397,8 +397,8 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan
|
|||||||
if (audioCodec?.Equals("MIDI", StringComparison.OrdinalIgnoreCase) ?? false)
|
if (audioCodec?.Equals("MIDI", StringComparison.OrdinalIgnoreCase) ?? false)
|
||||||
{
|
{
|
||||||
_midiPlayer = new MidiPlayer(this, _context);
|
_midiPlayer = new MidiPlayer(this, _context);
|
||||||
_midiPlayer.LoadAndPlay(path, info);
|
_midiPlayer.LoadAndPlay(path);
|
||||||
return; // MIDI player will handle the playback at all
|
return; // Midi player will handle the playback at all
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user