Пример #1
0
        /// <summary>
        /// Visits system exclusive messages.
        /// </summary>
        /// <param name="message">
        /// The system exclusive message to visit.
        /// </param>
        public override void Visit(SysExMessage message)
        {
            midiStream.WriteByte((byte)message.Status);
            WriteVariableLengthQuantity(message.Length);

            for (int i = 0; i < message.Length; i++)
            {
                midiStream.WriteByte(message[i]);
            }

            runningStatus = 0;
        }
Пример #2
0
        /// <summary>
        /// Handles triggering the system exclusive message received event.
        /// </summary>
        /// <param name="header">
        /// Midi header containing the system exclusive message.
        /// </param>
        /// <param name="timeStamp">
        /// Number of milliseconds that have passed since the input device
        /// began recording.
        /// </param>
        private void DispatchSysExMessage(MidiHeader header, int timeStamp)
        {
            // Create array for holding system exclusive data.
            byte[] data = new byte[header.bytesRecorded - 1];

            // Get status byte.
            byte status = Marshal.ReadByte(header.data);

            // Copy system exclusive data into array (status byte is
            // excluded).
            for (int i = 1; i < header.bytesRecorded; i++)
            {
                data[i - 1] = Marshal.ReadByte(header.data, i);
            }

            // Create message.
            SysExMessage msg = new SysExMessage((SysExType)status, data);

            // Raise event.
            SysExReceived(this, new SysExEventArgs(msg, timeStamp));
        }
Пример #3
0
        /// <summary>
        /// Sends system exclusive messages.
        /// </summary>
        /// <param name="message">
        /// The system exclusive message to send.
        /// </param>
        public void Send(SysExMessage message)
        {
            // Guard.
            if (!IsOpen())
            {
                return;
            }

            // Create header.
            MidiHeader header = new MidiHeader();

            // System exclusive message data.
            string msg = message.Message;

            //
            // Initialize header.
            //

            header.data         = Marshal.StringToHGlobalAnsi(msg);
            header.bufferLength = msg.Length;
            header.flags        = 0;

            // Prepare header.
            ThrowOnError(midiOutPrepareHeader(handle, ref header,
                                              Marshal.SizeOf(header)));

            // Place header in queue to be retrieved later.
            syncHeaderQueue.Enqueue(header);

            // Send message.
            ThrowOnError(midiOutLongMsg(handle, ref header,
                                        Marshal.SizeOf(header)));

            // System exclusive messages cancel running status.
            runningStatus = 0;
        }
Пример #4
0
 /// <summary>
 /// Visit system exclusive messages.
 /// </summary>
 /// <param name="message">
 /// The message to visit.
 /// </param>
 public override void Visit(SysExMessage message)
 {
     // Send message.
     this.SendMessage(message);
     //this._midiSender.Send(message);
 }
Пример #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="message"></param>
 public virtual void Visit(SysExMessage message)
 {
 }
Пример #6
0
        /// <summary>
        /// Visits system exclusive messages.
        /// </summary>
        /// <param name="message">
        /// The system exclusive message to visit.
        /// </param>
        public override void Visit(SysExMessage message)
        {
            midiStream.WriteByte((byte)message.Status);
            WriteVariableLengthQuantity(message.Length);

            for(int i = 0; i < message.Length; i++)
            {
                midiStream.WriteByte(message[i]);
            }

            runningStatus = 0;
        }
Пример #7
0
        /// <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)
        {
            int status = 0;
            int runningStatus = 0;

            // Read length of track.
            binReader.ReadBytes(LengthByteCount);

            // Continue reading Midi events until the end of the track.
            while(true)
            {
                // 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 mType = (MetaType)binReader.ReadByte();

                        // If this is the end of the track.
                        if(mType == MetaType.EndOfTrack)
                        {
                            // Make sure end of track message has the same
                            // ticks value as the end of track message in the
                            // file.
                            tracks[trackNum].Slide(tracks[trackNum].Count - 1, ticks);

                            // Break out of loop - finished with this track.
                            break;
                        }

                        // 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(mType, 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);
            }
        }
Пример #8
0
 /// <summary>
 /// Visit system exclusive messages.
 /// </summary>
 /// <param name="message">
 /// The message to visit.
 /// </param>
 public override void Visit(SysExMessage message)
 {
     // Send message.
     this.SendMessage(message);
     //this._midiSender.Send(message);
 }
Пример #9
0
        /// <summary>
        /// Sends system exclusive messages.
        /// </summary>
        /// <param name="message">
        /// The system exclusive message to send.
        /// </param>
        public void Send(SysExMessage message)
        {
            // Guard.
            if(!IsOpen())
                return;

            // Create header.
            MidiHeader header = new MidiHeader();

            // System exclusive message data.
            string msg = message.Message;

            //
            // Initialize header.
            //

            header.data = Marshal.StringToHGlobalAnsi(msg);
            header.bufferLength = msg.Length;
            header.flags = 0;

            // Prepare header.
            ThrowOnError(midiOutPrepareHeader(handle, ref header,
                Marshal.SizeOf(header)));

            // Place header in queue to be retrieved later.
            syncHeaderQueue.Enqueue(header);

            // Send message.
            ThrowOnError(midiOutLongMsg(handle, ref header,
                Marshal.SizeOf(header)));

            // System exclusive messages cancel running status.
            runningStatus = 0;
        }
Пример #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 public virtual void Visit(SysExMessage message)
 {
 }
Пример #11
0
        /// <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)
        {
            int status        = 0;
            int runningStatus = 0;

            // Read length of track.
            binReader.ReadBytes(LengthByteCount);

            // Continue reading Midi events until the end of the track.
            while (true)
            {
                // 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 mType = (MetaType)binReader.ReadByte();

                        // If this is the end of the track.
                        if (mType == MetaType.EndOfTrack)
                        {
                            // Make sure end of track message has the same
                            // ticks value as the end of track message in the
                            // file.
                            tracks[trackNum].Slide(tracks[trackNum].Count - 1, ticks);

                            // Break out of loop - finished with this track.
                            break;
                        }

                        // 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(mType, 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);
            }
        }
Пример #12
0
        /// <summary>
        /// Handles triggering the system exclusive message received event.
        /// </summary>
        /// <param name="header">
        /// Midi header containing the system exclusive message.
        /// </param>
        /// <param name="timeStamp">
        /// Number of milliseconds that have passed since the input device 
        /// began recording.
        /// </param>
        private void DispatchSysExMessage(MidiHeader header, int timeStamp)
        {
            // Create array for holding system exclusive data.
            byte[] data = new byte[header.bytesRecorded - 1];

            // Get status byte.
            byte status = Marshal.ReadByte(header.data);

            // Copy system exclusive data into array (status byte is
            // excluded).
            for(int i = 1; i < header.bytesRecorded; i++)
            {
                data[i - 1] = Marshal.ReadByte(header.data, i);
            }

            // Create message.
            SysExMessage msg = new SysExMessage((SysExType)status, data);

            // Raise event.
            SysExReceived(this, new SysExEventArgs(msg, timeStamp));
        }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the SysExEventArgs class with the
 /// specified system exclusive message and the time stamp.
 /// </summary>
 /// <param name="message">
 /// The system exclusive message for this event.
 /// </param>
 /// <param name="timeStamp">
 /// The time in milliseconds since the input device began recording.
 /// </param>
 public SysExEventArgs(SysExMessage message, int timeStamp)
 {
     this.message   = message;
     this.timeStamp = timeStamp;
 }
Пример #14
0
        /// <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);
        }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the SysExEventArgs class with the 
 /// specified system exclusive message and the time stamp.
 /// </summary>
 /// <param name="message">
 /// The system exclusive message for this event.
 /// </param>
 /// <param name="timeStamp">
 /// The time in milliseconds since the input device began recording.
 /// </param>
 public SysExEventArgs(SysExMessage message, int timeStamp)
 {
     this.message = message;
     this.timeStamp = timeStamp;
 }
Пример #16
0
        /// <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);
        }