Ejemplo n.º 1
0
        private void OnShortMessage(int message)
        {
            try
            {
                byte statusByte, firstDataByte, secondDataByte;
                MidiWinApi.UnpackShortEventBytes(message, out statusByte, out firstDataByte, out secondDataByte);

                var midiEvent = _bytesToMidiEventConverter.Convert(statusByte, new[] { firstDataByte, secondDataByte });
                OnEventReceived(midiEvent);

                if (RaiseMidiTimeCodeReceived)
                {
                    var midiTimeCodeEvent = midiEvent as MidiTimeCodeEvent;
                    if (midiTimeCodeEvent != null)
                    {
                        TryRaiseMidiTimeCodeReceived(midiTimeCodeEvent);
                    }
                }
            }
            catch (Exception ex)
            {
                var exception = new MidiDeviceException($"Failed to parse short message.", ex);
                exception.Data.Add("Message", message);
                OnError(exception);
            }
        }
Ejemplo n.º 2
0
        private static void OnNetworkEvent(PacketHeader header, Connection connection, byte[] binaryMidiEvent)
        {
            MidiEvent midiEvent = btomec.Convert(binaryMidiEvent);

            ForwardEvent(midiEvent);
        }
Ejemplo n.º 3
0
        private void serverThread()
        {
            while (true)
            {
                try
                {
                    //Get the other IP, read data
                    IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
                    Byte[]     receiveBytes     = udpServer.Receive(ref RemoteIpEndPoint);
                    byte[]     data             = new byte[receiveBytes.Length - 1];
                    Array.Copy(receiveBytes, 1, data, 0, receiveBytes.Length - 1);
                    string returnData = Encoding.ASCII.GetString(data);

                    Console.WriteLine(RemoteIpEndPoint.Address.ToString()
                                      + ":" + returnData.ToString());

                    switch (receiveBytes[0])
                    {
                    case 10:
                        //If midi, play it
                        BytesToMidiEventConverter converter = new BytesToMidiEventConverter();
                        MidiEvent tmpevent = converter.Convert(data);
                        PlayMidi(tmpevent);
                        break;

                    case 20:
                        //Reacts
                        if (returnData.ToString() == "IsAnybodyThere")
                        {
                            if (connectionStatus != ConnectionStatus.Connected && connectionStatus != ConnectionStatus.Connecting)
                            {
                                address = RemoteIpEndPoint.Address.ToString();

                                MethodInvoker inv = delegate
                                {
                                    Connect(true);
                                };
                                Invoke(inv);
                            }
                            else
                            {
                                //Answers
                                SendData(Encoding.ASCII.GetBytes("YesThereIs"), (int)code.connectionData);
                            }
                        }
                        else if (returnData.ToString() == "YesThereIs")
                        {
                            //Connection is established
                            connectionStatus = ConnectionStatus.Connected;
                        }
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception)
                {
                    connectionStatus = ConnectionStatus.Disconnected;
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        public static void SendMidiEvent(MidiPort port, byte data1, byte data2, byte data3)
        {
            var me = midiConverter.Convert(new byte[] { data1, data2, data3 });

            SendMidiEvent(port, me);
        }
        private void Convert_Bytes_Offset_Length(BytesToMidiEventConverter bytesToMidiEventConverter, byte[] bytes, int offset, int length, MidiEvent expectedMidiEvent)
        {
            var midiEvent = bytesToMidiEventConverter.Convert(bytes, offset, length);

            CompareEvents(expectedMidiEvent, midiEvent);
        }
        private void Convert_Bytes(BytesToMidiEventConverter bytesToMidiEventConverter, byte[] bytes, MidiEvent expectedMidiEvent)
        {
            var midiEvent = bytesToMidiEventConverter.Convert(bytes);

            CompareEvents(expectedMidiEvent, midiEvent);
        }
        private void Convert_StatusByte_DataBytes(BytesToMidiEventConverter bytesToMidiEventConverter, byte statusByte, byte[] dataBytes, MidiEvent expectedMidiEvent)
        {
            var midiEvent = bytesToMidiEventConverter.Convert(statusByte, dataBytes);

            CompareEvents(expectedMidiEvent, midiEvent);
        }