Ejemplo n.º 1
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];
                }
            }
        }
Ejemplo n.º 2
0
        public override void Send(SysExMessage message)
        {
            // System exclusive cancels running status.
            runningStatus = 0;

            base.Send(message);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public void Record(SysExMessage message)
 {
     if (clock.IsRunning)
     {
         buffer.Add(new TimestampedMessage(clock.Ticks, message));
     }
 }
Ejemplo n.º 5
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]);
            }
        }
Ejemplo n.º 6
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);
                }
            }
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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();

                        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);
            }
        }
Ejemplo n.º 9
0
 public SysExMessageEventArgs(SysExMessage message)
 {
     this.message = message;
 }