コード例 #1
0
ファイル: MessageWriter.cs プロジェクト: timdetering/Endogine
        /// <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
ファイル: InputDevice.cs プロジェクト: timdetering/Endogine
        /// <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
ファイル: OutputDevice.cs プロジェクト: timdetering/Endogine
        /// <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
ファイル: TrackPlayer.cs プロジェクト: timdetering/Endogine
 /// <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
ファイル: MessageWriter.cs プロジェクト: timdetering/Endogine
        /// <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
ファイル: TrackPlayer.cs プロジェクト: timdetering/Endogine
 /// <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
ファイル: OutputDevice.cs プロジェクト: timdetering/Endogine
        /// <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
ファイル: InputDevice.cs プロジェクト: timdetering/Endogine
        /// <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
ファイル: SysExMessage.cs プロジェクト: timdetering/Endogine
 /// <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
ファイル: SysExMessage.cs プロジェクト: timdetering/Endogine
        /// <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
ファイル: SysExMessage.cs プロジェクト: timdetering/Endogine
 /// <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
ファイル: SysExMessage.cs プロジェクト: timdetering/Endogine
        /// <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);
        }