public void onPlay() { sequencer.Start(); }
public void Start() { _MIDISequencer.Start(); }
private void Load() { Loading = 0; outDevice = new OutputDevice(0); sequencer = new Sequencer(); sequence = new Sequence(); sequencer.ChannelMessagePlayed += delegate (object o, ChannelMessageEventArgs args) { ChannelCommand cmd = args.Message.Command; int channel = args.Message.MidiChannel; int data1 = args.Message.Data1; int data2 = args.Message.Data2; if (cmd == ChannelCommand.NoteOff || data2 == 0) { if (lastPlayed[channel, data1] != null) { Note n = lastPlayed[channel, data1]; n.Playing = false; } } else if (cmd == ChannelCommand.NoteOn) { Note n = new Note() { Key = data1, Length = 0, Playing = true, Position = 0, Time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond, Channel = channel, Velocity = data2 }; lock (notes) notes.Add(n); if (lastPlayed[channel, data1] != null) lastPlayed[channel, data1].Playing = false; lastPlayed[channel, data1] = n; } lock (backlog) { backlog.Enqueue(new Event(delegate { outDevice.Send(args.Message); if (cmd == ChannelCommand.NoteOff || data2 == 0) if (Keyboard.KeyPressed[data1] > 0) Keyboard.KeyPressed[data1]--; else if (cmd == ChannelCommand.NoteOn) Keyboard.KeyPressed[data1]++; else if (cmd == ChannelCommand.Controller) if (data1 == 0x07) Keyboard.ChannelVolume[channel] = data2; else if (cmd == ChannelCommand.PitchWheel) { int pitchValue = Get14BitValue(data1, data2); Keyboard.Pitchwheel[channel] = pitchValue; } }, Delay)); } }; sequencer.SysExMessagePlayed += delegate (object o, SysExMessageEventArgs args) { lock (backlog) backlog.Enqueue(new Event(() => outDevice.Send(args.Message), Delay)); }; sequencer.Chased += delegate (object o, ChasedEventArgs args) { foreach (ChannelMessage message in args.Messages) lock (backlog) backlog.Enqueue(new Event(() => outDevice.Send(message), Delay)); }; sequencer.Stopped += delegate (object o, StoppedEventArgs args) { foreach (ChannelMessage message in args.Messages) lock (backlog) backlog.Enqueue(new Event(() => outDevice.Send(message), Delay)); }; sequence.LoadCompleted += delegate (object o, AsyncCompletedEventArgs args) { Loading = -1; sequencer.Sequence = sequence; sequencer.Start(); }; sequence.LoadProgressChanged += delegate (object sender, ProgressChangedEventArgs args) { Loading = args.ProgressPercentage; }; sequence.LoadAsync(MIDIFile); }