Example #1
0
        /// <summary>
        /// Reads the next channel message.
        /// </summary>
        /// <param name="status">
        /// The status value for the next channel message.
        /// </param>
        /// <param name="data1">
        /// The first data byte.
        /// </param>
        /// <returns>
        /// The next channel message.
        /// </returns>
        private ChannelMessage ReadChannelMessage(int status, int data1)
        {
            ChannelMessage msg;
            ChannelCommand command = (ChannelCommand)(status & ChannelMask);
            int channel = status & ~ChannelMask;

            // If this is a channel message that has two data bytes.
            if(command != ChannelCommand.ChannelPressure &&
                command != ChannelCommand.ProgramChange)
            {
                // Get second data byte.
                int data2 = binReader.ReadByte();

                // Create channel message.
                msg = new ChannelMessage(command, channel, data1, data2);
            }
            // Else this channel message only has one data byte.
            else
            {
                // Create channel message.
                msg = new ChannelMessage(command, channel, data1);
            }

            return msg;
        }
Example #2
0
        /// <summary>
        /// Determines the type of message received and triggers the correct
        /// event in response.
        /// </summary>
        /// <param name="message">
        /// The short Midi message received.
        /// </param>
        /// <param name="timeStamp">
        /// Number of milliseconds that have passed since the input device 
        /// began recording.
        /// </param>
        private void DispatchShortMessage(int message, int timeStamp)
        {
            // Unpack status value.
            int status = ShortMessage.UnpackStatus(message);

            // If a channel message was received.
            if(ChannelMessage.IsChannelMessage(status))
            {
                // If anyone is listening for channel messages.
                if(ChannelMessageReceived != null)
                {
                    // Create channel message.
                    ChannelMessage msg = new ChannelMessage(message);

                    // Create channel message event argument.
                    ChannelMessageEventArgs e = 
                        new ChannelMessageEventArgs(msg, timeStamp);

                    // Trigger channel message received event.
                    ChannelMessageReceived(this, e);
                }
            }
            // Else if a system common message was received
            else if(SysCommonMessage.IsSysCommonMessage(status))
            {
                // If anyone is listening for system common messages
                if(SysCommonReceived != null)
                {
                    // Create system common message.
                    SysCommonMessage msg = new SysCommonMessage(message);

                    // Create system common event argument.
                    SysCommonEventArgs e = new SysCommonEventArgs(msg, timeStamp);

                    // Trigger system common received event.
                    SysCommonReceived(this, e);
                }
            }
            // Else if a system realtime message was received
            else if(SysRealtimeMessage.IsSysRealtimeMessage(status))
            {
                // If anyone is listening for system realtime messages
                if(SysRealtimeReceived != null)
                {
                    // Create system realtime message.
                    SysRealtimeMessage msg = new SysRealtimeMessage(message);

                    // Create system realtime event argument.
                    SysRealtimeEventArgs e = new SysRealtimeEventArgs(msg, timeStamp);

                    // Trigger system realtime received event.
                    SysRealtimeReceived(this, e);
                }
            }
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the ChannelMessageEventArgs class with the 
 /// specified ChannelMessage and time stamp.
 /// </summary>
 /// <param name="message">
 /// The ChannelMessage for this event.
 /// </param>
 /// <param name="timeStamp">
 /// The time in milliseconds since the input device began recording.
 /// </param>
 public ChannelMessageEventArgs(ChannelMessage message, int timeStamp)
 {
     this.message = message;
     this.timeStamp = timeStamp;
 }
Example #4
0
        /// <summary>
        /// Visits channel messages.
        /// </summary>
        /// <param name="message">
        /// The ChannelMessage to visit.
        /// </param>
        public void Visit(ChannelMessage message)
        {
            // If the running status does not match the channel message's 
            // status.
            if(runningStatus != message.Status)
            {
                // Update status value.
                runningStatus = message.Status;

                // Send message with status value.
                MidiSender.Send(message, true);
            }
            // Else the running status matches the channel message's status.
            else
            {
                // Send message without status value.
                MidiSender.Send(message, false);
            } 
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the ChannelMessage class with 
 /// another instance of the ChannelMessage class.
 /// </summary>
 /// <param name="message">
 /// The ChannelMessage instance to use for initialization.
 /// </param>
 public ChannelMessage(ChannelMessage message)
 {
     Command = message.Command;
     MidiChannel = message.MidiChannel;
     Data1 = message.Data1;
     Data2 = message.Data2;
 }