private static void Receive(IAsyncResult result) { if (connection == null || result == null) { return; } IPEndPoint source = null; byte[] message = connection.EndReceive(result, ref source); connection.BeginReceive(new AsyncCallback(Receive), connection); if (source.Address.Equals(localhost)) { if (!portMap.ContainsKey(source)) { connection?.SendAsync(new byte[] { 244, Convert.ToByte((portMap[source] = MIDI.ConnectAbleton()).Name.Substring(18)) }, 2, source); } if (message[0] < 128) { NoteOnMessage msg = new NoteOnMessage(Channel.Channel1, (Key)message[0], message[1]); portMap[source].NoteOn(null, in msg); } else if (message[0] == 245) { MIDI.Disconnect(portMap[source]); portMap.Remove(source); } } }
private void Unloaded(object sender, EventArgs e) { _launchpad.Window = null; Preferences.AlwaysOnTopChanged -= UpdateTopmost; if (_launchpad.GetType() == typeof(VirtualLaunchpad)) { MIDI.Disconnect(_launchpad); } _launchpad = null; }
void Launchpad_LockToggle() { VirtualLaunchpad lp = (VirtualLaunchpad)_launchpad; Preferences.VirtualLaunchpadsToggle(lp.VirtualIndex); bool state = Preferences.VirtualLaunchpads.Contains(lp.VirtualIndex); LockToggle.SetState(state); if (!state && lp.Window == null) { MIDI.Disconnect(lp); } }
void Unloaded(object sender, CancelEventArgs e) { _launchpad.Window = null; Preferences.AlwaysOnTopChanged -= UpdateTopmost; _launchpad.Info?.SetPopout(true); if (_launchpad is VirtualLaunchpad lp && !Preferences.VirtualLaunchpads.Contains(lp.VirtualIndex)) { MIDI.Disconnect(_launchpad); } _launchpad = null; foreach (IDisposable observable in observables) { observable.Dispose(); } this.Content = null; }
static void Receive(IAsyncResult result) { lock (locker) { if (connection == null || result == null) { return; } IPEndPoint source = null; byte[] message = connection?.EndReceive(result, ref source); connection?.BeginReceive(new AsyncCallback(Receive), connection); if (!source.Address.Equals(localhost)) { return; } if (!portMap.ContainsKey(source)) { if (message[0] == 247) { App.Args = new string[] { Encoding.UTF8.GetString(message.Skip(1).ToArray()) }; if (handlingFileOpen) { return; } handlingFileOpen = true; Dispatcher.UIThread.InvokeAsync(async() => { if (Program.Project == null) { App.Windows.OfType <SplashWindow>().First().ReadFile(App.Args[0]); } else { await Program.Project.AskClose(); } App.Args = null; handlingFileOpen = false; }); } else if (message[0] >= 242 && message[0] <= 244) { connection?.SendAsync(new byte[] { 244, Convert.ToByte((portMap[source] = MIDI.ConnectAbleton(244 - message[0])).Name.Substring(18)) }, 2, source); } } else if (message[0] < 128) { portMap[source].HandleNote(message[0], message[1]); } else if (message[0] == 245) { MIDI.Disconnect(portMap[source]); portMap.Remove(source); } else if (message[0] == 246 && Program.Project != null) { Program.Project.BPM = BitConverter.ToUInt16(message, 1); } } }