/// <summary> /// Initializes a new instance of the SysExMessage class with the /// specified system exclusive type and data. /// </summary> /// <param name="type"> /// The type of system exclusive message. /// </param> /// <param name="data"> /// The system exclusive data. /// </param> public SysExMessage(SysExType type, byte[] data) { this.type = type; // If this is a regular system exclusive message. if (this.type == SysExType.Start) { // Create storage for message data which includes an extra byte // for the status value. message = new StringBuilder(data.Length + 1); message.Length = message.Capacity; // Store status value. message[0] = (char)this.type; } // Else this is a continuation message or an escaped message. else { message = new StringBuilder(data.Length); } // Copy data into message. for (int i = 0; i < data.Length; i++) { this[i] = data[i]; } }
/// <summary> /// Initializes a new instance of the SysExMessage class with the /// specified system exclusive type and data. /// </summary> /// <param name="type"> /// The type of system exclusive message. /// </param> /// <param name="data"> /// The system exclusive data. /// </param> public SysExMessage(SysExType type, byte[] data) { this.type = type; // If this is a regular system exclusive message. if(this.type == SysExType.Start) { // Create storage for message data which includes an extra byte // for the status value. message = new StringBuilder(data.Length + 1); message.Length = message.Capacity; // Store status value. message[0] = (char)this.type; } // Else this is a continuation message or an escaped message. else { message = new StringBuilder(data.Length); } // Copy data into message. for(int i = 0; i < data.Length; i++) { this[i] = data[i]; } }
/// <summary> /// Initializes a new instance of the SysExMessage class with /// another instance of the SysExMessage class. /// </summary> /// <param name="message"> /// The SysExMessage instance to use for initialization. /// </param> public SysExMessage(SysExMessage message) { type = message.type; this.message = new StringBuilder(message.Message); }
/// <summary> /// Initializes a new instance of the SysExMessage class with /// another instance of the SysExMessage class. /// </summary> /// <param name="message"> /// The SysExMessage instance to use for initialization. /// </param> public SysExMessage(SysExMessage message) { type = message.type; this.message = new StringBuilder(message.Message); }
/// <summary> /// Reads the data for the next track from the Midi file. /// </summary> /// <param name="trackNum"> /// The track number. /// </param> private void ReadNextTrack(int trackNum) { MetaType metaType = MetaType.TrackName; int status = 0; int runningStatus = 0; // Read length of track. binReader.ReadBytes(LengthByteCount); // Continue reading Midi events until the end of the track. while (metaType != MetaType.EndOfTrack) { // Next Midi message in track. IMidiMessage msg = null; // Ticks for next Midi event. int ticks = ReadVariableLengthQuantity(); // Read status byte for the next Midi message. status = binReader.ReadByte(); // If this is a status byte. if ((status & StatusFlag) == StatusFlag) { // If the next Midi message is a channel message. if (ChannelMessage.IsChannelMessage(status)) { // Read channel message from the Midi file. msg = ReadChannelMessage(status); // Update running status. runningStatus = status; } // Else if the next Midi message is a meta message. else if (MetaMessage.IsMetaMessage(status)) { // Read the type of meta message. metaType = (MetaType)binReader.ReadByte(); // Read the length of the meta message data. int length = ReadVariableLengthQuantity(); // Read the meta message data. byte[] data = binReader.ReadBytes(length); // Create meta message. msg = new MetaMessage(metaType, data); } // Else if the next Midi message is a system exclusive // message. else if (SysExMessage.IsSysExMessage(status)) { // The type of system exclusive message. SysExType type = (SysExType)status; // Read the length of the system exclusive data. int length = ReadVariableLengthQuantity(); // Read the system exclusive data. byte[] data = binReader.ReadBytes(length); // Create system exclusive message. msg = new SysExMessage(type, data); } } // Assumes running status. else { // Create channel message. msg = ReadChannelMessage(runningStatus, status); } // Create the next Midi event and store it in the specified // track. MidiEvent e = new MidiEvent(msg, ticks); tracks[trackNum].Add(e); } }