/// <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]; } } }
public override void Send(SysExMessage message) { // System exclusive cancels running status. runningStatus = 0; base.Send(message); }
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 void Record(SysExMessage message) { if (clock.IsRunning) { buffer.Add(new TimestampedMessage(clock.Ticks, message)); } }
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]); } }
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); } } }
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 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); } }
public SysExMessageEventArgs(SysExMessage message) { this.message = message; }