Beispiel #1
0
        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) && message[0] >= 243 && message[0] <= 244)
                {
                    connection?.SendAsync(new byte[] { 244, Convert.ToByte((portMap[source] = MIDI.ConnectAbleton(244 - message[0])).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);
                }
                else if (message[0] == 246 && Program.Project != null)
                {
                    Program.Project.BPM = BitConverter.ToUInt16(message, 1);
                }
            }
        }
Beispiel #2
0
        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);
                }
            }
        }