예제 #1
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);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Handles system common received events.
        /// </summary>
        /// <param name="sender">
        /// The MIDI receiver responsible for the event.
        /// </param>
        /// <param name="e">
        /// Information about the event.
        /// </param>
        private void SysCommonReceivedHandler(object sender, SysCommonEventArgs e)
        {
            // Guard.
            if (!SlaveEnabled)
            {
                return;
            }

            // If the position has changed.
            if (e.Message.Type == SysCommonType.SongPositionPointer &&
                PositionChanged != null)
            {
                SongPositionPointer spp =
                    new SongPositionPointer(tickGenerator.Ppqn, e.Message);

                bool wasRunning = IsRunning();

                // If the tick Generator is running, stop it momentarily to
                // give listeners a chance to update their position when the
                // PositionChanged event is raised.
                //
                // Ideally, any master device sending a song position pointer
                // messages would send a stop message first so that the slave
                // is not running when the position is changed.
                if (wasRunning)
                {
                    tickGenerator.Stop();
                }

                PositionChanged(this,
                                new PositionChangedEventArgs(spp.PositionInTicks));

                if (MasterEnabled)
                {
                    midiSender.Send(e.Message);
                }

                // Restart tick generator if it was previously running.
                if (wasRunning)
                {
                    tickGenerator.Start();
                }
            }
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Handles system common received events.
        /// </summary>
        /// <param name="sender">
        /// The MIDI receiver responsible for the event.
        /// </param>
        /// <param name="e">
        /// Information about the event.
        /// </param>
        private void SysCommonReceivedHandler(object sender, SysCommonEventArgs e)
        {
            // Guard.
            if(!SlaveEnabled)
                return;

            // If the position has changed.
            if(e.Message.Type == SysCommonType.SongPositionPointer &&
                PositionChanged != null)
            {
                SongPositionPointer spp =
                    new SongPositionPointer(tickGenerator.Ppqn, e.Message);

                bool wasRunning = IsRunning();

                // If the tick Generator is running, stop it momentarily to
                // give listeners a chance to update their position when the
                // PositionChanged event is raised.
                //
                // Ideally, any master device sending a song position pointer
                // messages would send a stop message first so that the slave
                // is not running when the position is changed.
                if(wasRunning)
                    tickGenerator.Stop();

                PositionChanged(this,
                    new PositionChangedEventArgs(spp.PositionInTicks));

                if(MasterEnabled)
                    midiSender.Send(e.Message);

                // Restart tick generator if it was previously running.
                if(wasRunning)
                    tickGenerator.Start();
            }
        }