public override bool Equals(object obj)
        {
            #region Guard

            if (!(obj is SysExMessage))
            {
                return(false);
            }

            #endregion

            SysExMessage message = (SysExMessage)obj;

            bool equals = true;

            if (this.Length != message.Length)
            {
                equals = false;
            }

            for (int i = 0; i < this.Length && equals; i++)
            {
                if (this[i] != message[i])
                {
                    equals = false;
                }
            }

            return(equals);
        }
        public IMidiMessage Clone()
        {
            IMidiMessage ret = null;

            if (this.MessageType == MessageType.Channel)
            {
                ret = new ChannelMessage(MessageData);
            }
            else if (this.MessageType == MessageType.Meta)
            {
                ret = new MetaMessage(this.MetaType, byteData);
            }
            else if (this.MessageType == MessageType.SystemCommon)
            {
                ret = new SysCommonMessage(MessageData);
            }
            else if (this.MessageType == MessageType.SystemExclusive)
            {
                ret = new SysExMessage(byteData);
            }
            else if (this.MessageType == MessageType.SystemRealtime)
            {
                ret = SysRealtimeMessage.FromType(realtimeType);
                ;
            }
            return(ret);
        }
Пример #3
0
 public void Record(SysExMessage message)
 {
     if (clock.IsRunning)
     {
         buffer.Add(new TimestampedMessage(clock.Ticks, message));
     }
 }
Пример #4
0
        /// <summary>
        /// Initializes the MidiHeaderBuilder with the specified SysExMessage.
        /// </summary>
        /// <param name="message">
        /// The SysExMessage to use for initializing the MidiHeaderBuilder.
        /// </param>
        public void InitializeBuffer(SysExMessage message)
        {
            // If this is a start system exclusive message.
            if (message.SysExType == SysExType.Start)
            {
                BufferLength = message.Length;

                // Copy entire message.
                for (int i = 0; i < BufferLength; i++)
                {
                    data[i] = message[i];
                }
            }
            // Else this is a continuation message.
            else
            {
                BufferLength = message.Length - 1;

                // Copy all but the first byte of message.
                for (int i = 0; i < BufferLength; i++)
                {
                    data[i] = message[i + 1];
                }
            }
        }
Пример #5
0
        public override void Send(SysExMessage message)
        {
            // System exclusive cancels running status.
            runningStatus = 0;

            base.Send(message);
        }
Пример #6
0
        private void HandleMidiInMessage(Sanford.Multimedia.Midi.SysExMessage msg)
        {
            var data = msg.GetBytes();
            var kmsg = SysExMessage.Parse(data);

            if (kmsg != null)
            {
                lock (MessageQueue)
                    MessageQueue.Enqueue(kmsg);
            }
        }
Пример #7
0
        public void SendSysExMessage(SysExMessage msg)
        {
            var sem = new Sanford.Multimedia.Midi.SysExMessage(
                new[] { (byte)SysExType.Start }
                .Concat(SysExMessage.ManufacturerId)
                .Concat(SysExMessage.ProductType)
                .Concat(SysExMessage.DeviceId)
                .Concat(msg.GetMessageContent())
                .Concat(new byte[] { 247 })
                .ToArray());

            OutputMidiDevice.Send(sem);
        }
Пример #8
0
        private void Write(SysExMessage message)
        {
            // System exclusive message cancel running status.
            runningStatus = 0;

            //trackData.Add((byte)message.Status);

            //WriteVariableLengthValue(message.Length - 1);

            for (int i = 1; i < message.Length; i++)
            {
                //trackData.Add(message[i]);
            }
        }
Пример #9
0
        public virtual void Send(SysExMessage message)
        {
            #region Require

            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            #endregion

            lock (lockObject)
            {
                headerBuilder.InitializeBuffer(message);
                headerBuilder.Build();

                // Prepare system exclusive buffer.
                int result = midiOutPrepareHeader(Handle, headerBuilder.Result, SizeOfMidiHeader);

                // If the system exclusive buffer was prepared successfully.
                if (result == MidiDeviceException.MMSYSERR_NOERROR)
                {
                    bufferCount++;

                    // Send system exclusive message.
                    result = midiOutLongMsg(Handle, headerBuilder.Result, SizeOfMidiHeader);

                    // If the system exclusive message could not be sent.
                    if (result != MidiDeviceException.MMSYSERR_NOERROR)
                    {
                        midiOutUnprepareHeader(Handle, headerBuilder.Result, SizeOfMidiHeader);
                        bufferCount--;
                        headerBuilder.Destroy();

                        // Throw an exception.
                        throw new OutputDeviceException(result);
                    }
                }
                // Else the system exclusive buffer could not be prepared.
                else
                {
                    // Destroy system exclusive buffer.
                    headerBuilder.Destroy();

                    // Throw an exception.
                    throw new OutputDeviceException(result);
                }
            }
        }
        public virtual void Send(SysExMessage message)
        {
            lock (lockObject)
            {
                if (message.Length == 0)
                {
                    return;
                }

                headerBuilder.InitializeBuffer(message);
                headerBuilder.Build();

                // Prepare system exclusive buffer.
                int result = midiOutPrepareHeader(Handle, headerBuilder.Result, SizeOfMidiHeader);

                // If the system exclusive buffer was prepared successfully.
                if (result == MidiDeviceException.MMSYSERR_NOERROR)
                {
                    bufferCount++;

                    // Send system exclusive message.
                    result = midiOutLongMsg(Handle, headerBuilder.Result, SizeOfMidiHeader);

                    // If the system exclusive message could not be sent.
                    if (result != MidiDeviceException.MMSYSERR_NOERROR)
                    {
                        midiOutUnprepareHeader(Handle, headerBuilder.Result, SizeOfMidiHeader);
                        bufferCount--;
                        headerBuilder.Destroy();

                        // Throw an exception.
                        throw new OutputDeviceException(result);
                    }
                }
                // Else the system exclusive buffer could not be prepared.
                else
                {
                    // Destroy system exclusive buffer.
                    headerBuilder.Destroy();

                    // Throw an exception.
                    throw new OutputDeviceException(result);
                }
            }
        }
Пример #11
0
        private void HandleSysExMessage(object state)
        {
            lock (lockObject)
            {
                var    param     = (MidiInParams)state;
                IntPtr headerPtr = param.Param1;

                MidiHeader header = (MidiHeader)Marshal.PtrToStructure(headerPtr, typeof(MidiHeader));

                if (!resetting)
                {
                    for (int i = 0; i < header.bytesRecorded; i++)
                    {
                        sysExData.Add(Marshal.ReadByte(header.data, i));
                    }

                    if (sysExData.Count > 1 && sysExData[0] == 0xF0 && sysExData[sysExData.Count - 1] == 0xF7)
                    {
                        SysExMessage message = new SysExMessage(sysExData.ToArray());
                        message.Timestamp = param.Param2.ToInt32();

                        sysExData.Clear();

                        OnMessageReceived(message);
                        OnSysExMessageReceived(new SysExMessageEventArgs(message));
                    }

                    int result = AddSysExBuffer();

                    if (result != DeviceException.MMSYSERR_NOERROR)
                    {
                        Exception ex = new InputDeviceException(result);

                        OnError(new ErrorEventArgs(ex));
                    }
                }

                ReleaseBuffer(headerPtr);
            }
        }
Пример #12
0
        private void Write(int deltaTicks, SysExMessage message)
        {
            #region Require

            if (IsDisposed)
            {
                throw new ObjectDisposedException("OutputStream");
            }

            #endregion

            // Delta time.
            events.AddRange(BitConverter.GetBytes(deltaTicks + offsetTicks));

            // Stream ID.
            events.AddRange(streamID);

            // Event code.
            byte[] eventCode = BitConverter.GetBytes(message.Length);
            eventCode[eventCode.Length - 1] = MEVT_LONGMSG;
            events.AddRange(eventCode);

            byte[] sysExData;

            if (message.Length % 4 != 0)
            {
                sysExData = new byte[message.Length + (message.Length % 4)];
                message.GetBytes().CopyTo(sysExData, 0);
            }
            else
            {
                sysExData = message.GetBytes();
            }

            // SysEx data.
            events.AddRange(sysExData);

            offsetTicks = 0;
        }
Пример #13
0
 public SysExMessageEventArgs(SysExMessage message)
 {
     this.message = message;
 }
        public virtual void Send(SysExMessage message)
        {
            lock (lockObject)
            {
                if (message.Length == 0)
                    return;

                headerBuilder.InitializeBuffer(message);
                headerBuilder.Build();

                // Prepare system exclusive buffer.
                int result = midiOutPrepareHeader(Handle, headerBuilder.Result, SizeOfMidiHeader);

                // If the system exclusive buffer was prepared successfully.
                if (result == MidiDeviceException.MMSYSERR_NOERROR)
                {
                    bufferCount++;

                    // Send system exclusive message.
                    result = midiOutLongMsg(Handle, headerBuilder.Result, SizeOfMidiHeader);

                    // If the system exclusive message could not be sent.
                    if (result != MidiDeviceException.MMSYSERR_NOERROR)
                    {
                        midiOutUnprepareHeader(Handle, headerBuilder.Result, SizeOfMidiHeader);
                        bufferCount--;
                        headerBuilder.Destroy();

                        // Throw an exception.
                        throw new OutputDeviceException(result);
                    }
                }
                // Else the system exclusive buffer could not be prepared.
                else
                {
                    // Destroy system exclusive buffer.
                    headerBuilder.Destroy();

                    // Throw an exception.
                    throw new OutputDeviceException(result);
                }
            }
        }
Пример #15
0
        public override void Send(SysExMessage message)
        {
            // System exclusive cancels running status.
            runningStatus = 0;

            base.Send(message);
        }
Пример #16
0
 public SysExMessageEventArgs(SysExMessage message)
 {
     this.message = message;
 }
        /// <summary>
        /// Initializes the MidiHeaderBuilder with the specified SysExMessage.
        /// </summary>
        /// <param name="message">
        /// The SysExMessage to use for initializing the MidiHeaderBuilder.
        /// </param>
        public void InitializeBuffer(SysExMessage message)
        {
            // If this is a start system exclusive message.
            if(message.SysExType == SysExType.Start)
            {
                BufferLength = message.Length;

                // Copy entire message.
                for(int i = 0; i < BufferLength; i++)
                {
                    data[i] = message[i];
                }
            }
            // Else this is a continuation message.
            else
            {
                BufferLength = message.Length - 1;

                // Copy all but the first byte of message.
                for(int i = 0; i < BufferLength; i++)
                {
                    data[i] = message[i + 1];
                }
            }
        }
Пример #18
0
        private void HandleSysExMessage(object state)
        {
            lock(lockObject)
            {
                IntPtr headerPtr = (IntPtr)state;

                MidiHeader header = (MidiHeader)Marshal.PtrToStructure(headerPtr, typeof(MidiHeader));

                if(!resetting)
                {
                    for(int i = 0; i < header.bytesRecorded; i++)
                    {
                        sysExData.Add(Marshal.ReadByte(header.data, i));
                    }

                    if(sysExData[0] == 0xF0 && sysExData[sysExData.Count - 1] == 0xF7)
                    {
                        SysExMessage message = new SysExMessage(sysExData.ToArray());

                        sysExData.Clear();

                        OnSysExMessageReceived(new SysExMessageEventArgs(message));
                    }

                    int result = AddSysExBuffer();

                    if(result != DeviceException.MMSYSERR_NOERROR)
                    {
                        Exception ex = new InputDeviceException(result);

                        OnError(new ErrorEventArgs(ex));
                    }
                }

                ReleaseBuffer(headerPtr);
            }
        }
 public SysExMessageEventArgs(SysExMessage message, int absoluteTicks = -1)
 {
     this.message       = message;
     this.AbsoluteTicks = absoluteTicks;
 }
        public virtual void Send(SysExMessage message)
        {
            #region Require

            if(IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            #endregion

            lock(lockObject)
            {
                headerBuilder.InitializeBuffer(message);
                headerBuilder.Build();

                // Prepare system exclusive buffer.
                int result = NativeMethods.midiOutPrepareHeader(Handle, headerBuilder.Result, SizeOfMidiHeader);

                // If the system exclusive buffer was prepared successfully.
                if(result == MidiDeviceException.MMSYSERR_NOERROR)
                {
                    bufferCount++;

                    // Send system exclusive message.
                    result = NativeMethods.midiOutLongMsg(Handle, headerBuilder.Result, SizeOfMidiHeader);

                    // If the system exclusive message could not be sent.
                    if(result != MidiDeviceException.MMSYSERR_NOERROR)
                    {
                        NativeMethods.midiOutUnprepareHeader(Handle, headerBuilder.Result, SizeOfMidiHeader);
                        bufferCount--;
                        headerBuilder.Destroy();

                        // Throw an exception.
                        throw new OutputDeviceException(result);
                    }
                }
                // Else the system exclusive buffer could not be prepared.
                else
                {
                    // Destroy system exclusive buffer.
                    headerBuilder.Destroy();

                    // Throw an exception.
                    throw new OutputDeviceException(result);
                }
            }
        }
Пример #21
0
        private void Write(int deltaTicks, SysExMessage message)
        {
            #region Require

            if(IsDisposed)
            {
                throw new ObjectDisposedException("OutputStream");
            }

            #endregion

            // Delta time.
            events.AddRange(BitConverter.GetBytes(deltaTicks + offsetTicks));

            // Stream ID.
            events.AddRange(streamID);

            // Event code.
            byte[] eventCode = BitConverter.GetBytes(message.Length);
            eventCode[eventCode.Length - 1] = MEVT_LONGMSG;
            events.AddRange(eventCode);

            byte[] sysExData;

            if(message.Length % 4 != 0)
            {
                sysExData = new byte[message.Length + (message.Length % 4)];
                message.GetBytes().CopyTo(sysExData, 0);
            }
            else
            {
                sysExData = message.GetBytes();
            }

            // SysEx data.
            events.AddRange(sysExData);

            offsetTicks = 0;
        }
        private void Write(SysExMessage message)
        {
            // System exclusive message cancel running status.
            runningStatus = 0;

            trackData.Add((byte)message.Status);

            WriteVariableLengthValue(message.Length - 1);

            for (int i = 1; i < message.Length; i++)
            {
                trackData.Add(message[i]);
            }
        }