Last active
November 5, 2019 17:33
-
-
Save peterthorsteinson/5db924c468f2f03a7eaa1c217cf2044e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Starting and Stopping midi playback on multiple threads | |
using System; | |
using System.Threading; | |
using Melanchall.DryWetMidi.Devices; | |
using Melanchall.DryWetMidi.Smf; | |
class Program | |
{ | |
public static Playback playback; | |
static void Main() | |
{ | |
Thread thread = new Thread(SecondaryThread); | |
thread.Start(); | |
var outputDevice = OutputDevice.GetById(0); | |
playback = MidiFile.Read("legend.mid").GetPlayback(outputDevice); | |
playback.InterruptNotesOnStop = true; | |
Console.WriteLine("Starting on main thread."); | |
playback.Start(); | |
Thread.Sleep(5000); | |
Console.WriteLine("Starting on main thread."); | |
playback.MoveToStart(); | |
playback.Start(); | |
Thread.Sleep(5000); | |
Console.WriteLine("Changing midi file in main thread."); | |
playback = MidiFile.Read("jupiter.mid").GetPlayback(outputDevice); | |
playback.InterruptNotesOnStop = true; | |
playback.Start(); | |
Console.ReadLine(); | |
} | |
public static void SecondaryThread() | |
{ | |
Thread.Sleep(3000); | |
Console.WriteLine("Stoping on secondary thread."); | |
playback.Stop(); | |
Thread.Sleep(6000); | |
Console.WriteLine("Stoping on secondary thread."); | |
playback.Stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment