Esempio n. 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);
                }
            }
        }
        /// <summary>
        /// Initializes an instance of the SongPositionPointer class with the
        /// specified pulses per quarter note.
        /// </summary>
        /// <param name="ppqn">
        /// Pulses per quarter note resolution.
        /// </param>
        /// <exception cref="ArgumentException">
        /// If the pulses per quarter note value is invalid.
        /// </exception>
        public SongPositionPointer(int ppqn)
        {
            // Enforce preconditions
            if(ppqn < TickGenerator.PpqnMin ||
                ppqn % TickGenerator.PpqnMin != 0)
                throw new ArgumentException(
                    "Pulses per quarter note invalid value.", "ppqn");

            message = new SysCommonMessage(SysCommonType.SongPositionPointer);

            tickScale = ppqn / TickGenerator.PpqnMin;
        }
Esempio n. 3
0
        /// <summary>
        /// Sends a system common message.
        /// </summary>
        /// <param name="message">
        /// The system common message to send.
        /// </param>
        /// <exception cref="OutputDeviceException">
        /// Thrown if an error occurred while sending the message.
        /// </exception>
        public void Send(SysCommonMessage message)
        {
            // Guard.
            if (!IsOpen())
            {
                return;
            }

            ThrowOnError(midiOutShortMsg(handle, message.Message));

            // System common messages cancel running status.
            runningStatus = 0;
        }
        /// <summary>
        /// Initializes an instance of the SongPositionPointer class with the
        /// specified pulses per quarter note.
        /// </summary>
        /// <param name="ppqn">
        /// Pulses per quarter note resolution.
        /// </param>
        /// <exception cref="ArgumentException">
        /// If the pulses per quarter note value is invalid.
        /// </exception>
        public SongPositionPointer(int ppqn)
        {
            // Enforce preconditions
            if (ppqn < TickGenerator.PpqnMin ||
                ppqn % TickGenerator.PpqnMin != 0)
            {
                throw new ArgumentException(
                          "Pulses per quarter note invalid value.", "ppqn");
            }

            message = new SysCommonMessage(SysCommonType.SongPositionPointer);

            tickScale = ppqn / TickGenerator.PpqnMin;
        }
        /// <summary>
        /// Initializes a new instance of the SongPositionPointer class with 
        /// the specified system common message and pulses per quarter note.
        /// </summary>
        /// <param name="ppqn">
        /// Pulses per quarter note resolution.
        /// </param>
        /// <param name="message">
        /// The system common message to use for initialization.
        /// </param>      
        /// <exception cref="ArgumentException">
        /// If the specified message is not a song position pointer message or
        /// the pulses per quarter note value is invalid.
        /// </exception>
        public SongPositionPointer(int ppqn, SysCommonMessage message)
        {
            // Enforce preconditions.
            if(ppqn < TickGenerator.PpqnMin ||
                ppqn % TickGenerator.PpqnMin != 0)
                throw new ArgumentException(
                    "Pulses per quarter note invalid value.", "ppqn");
            else if(message.Type != SysCommonType.SongPositionPointer)
                throw new ArgumentException(
                "Not song position pointer message.", "message");

            this.message = (SysCommonMessage)message.Clone();

            tickScale = ppqn / TickGenerator.PpqnMin;
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the SysCommonMessage class with a
        /// system common message packed as an integer.
        /// </summary>
        /// <param name="message">
        /// The packed system common message to use for initialization.
        /// </param>
        public SysCommonMessage(int message)
        {
            int status = ShortMessage.UnpackStatus(message);

            // Enforce preconditions.
            if (!SysCommonMessage.IsSysCommonMessage(status))
            {
                throw new ArgumentException(
                          "Message is not a system common message.", "message");
            }

            //
            // Initialize properties.
            //

            Type  = (SysCommonType)ShortMessage.UnpackStatus(message);
            Data1 = ShortMessage.UnpackData1(message);
            Data2 = ShortMessage.UnpackData2(message);
        }
        /// <summary>
        /// Initializes a new instance of the SongPositionPointer class with
        /// the specified system common message and pulses per quarter note.
        /// </summary>
        /// <param name="ppqn">
        /// Pulses per quarter note resolution.
        /// </param>
        /// <param name="message">
        /// The system common message to use for initialization.
        /// </param>
        /// <exception cref="ArgumentException">
        /// If the specified message is not a song position pointer message or
        /// the pulses per quarter note value is invalid.
        /// </exception>
        public SongPositionPointer(int ppqn, SysCommonMessage message)
        {
            // Enforce preconditions.
            if (ppqn < TickGenerator.PpqnMin ||
                ppqn % TickGenerator.PpqnMin != 0)
            {
                throw new ArgumentException(
                          "Pulses per quarter note invalid value.", "ppqn");
            }
            else if (message.Type != SysCommonType.SongPositionPointer)
            {
                throw new ArgumentException(
                          "Not song position pointer message.", "message");
            }

            this.message = (SysCommonMessage)message.Clone();

            tickScale = ppqn / TickGenerator.PpqnMin;
        }
Esempio n. 8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="message"></param>
 public virtual void Visit(SysCommonMessage message)
 {
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the SysCommonEventArgs class with the
 /// specified SysCommonMessage and time stamp.
 /// </summary>
 /// <param name="message">
 /// The SysCommonMessage for this event.
 /// </param>
 /// <param name="timeStamp">
 /// The time in milliseconds since the input device began recording.
 /// </param>
 public SysCommonEventArgs(SysCommonMessage message, int timeStamp)
 {
     this.message = message;
     this.timeStamp = timeStamp;
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the SysCommonMessage class with 
 /// another instance of the SysCommonMessage class.
 /// </summary>
 /// <param name="message">
 /// The SysCommonMessage instance to use for initialization.
 /// </param>
 public SysCommonMessage(SysCommonMessage message)
 {
     Type = message.Type;
     Data1 = message.Data1;
     Data2 = message.Data2;
 }
Esempio n. 11
0
        /// <summary>
        /// Sends a system common message.
        /// </summary>
        /// <param name="message">
        /// The system common message to send.
        /// </param>
        /// <exception cref="OutputDeviceException">
        /// Thrown if an error occurred while sending the message.
        /// </exception>
        public void Send(SysCommonMessage message)
        {
            // Guard.
            if(!IsOpen())
                return;

            ThrowOnError(midiOutShortMsg(handle, message.Message));

            // System common messages cancel running status.
            runningStatus = 0;
        }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the SysCommonEventArgs class with the
 /// specified SysCommonMessage and time stamp.
 /// </summary>
 /// <param name="message">
 /// The SysCommonMessage for this event.
 /// </param>
 /// <param name="timeStamp">
 /// The time in milliseconds since the input device began recording.
 /// </param>
 public SysCommonEventArgs(SysCommonMessage message, int timeStamp)
 {
     this.message   = message;
     this.timeStamp = timeStamp;
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the SysCommonMessage class with
 /// another instance of the SysCommonMessage class.
 /// </summary>
 /// <param name="message">
 /// The SysCommonMessage instance to use for initialization.
 /// </param>
 public SysCommonMessage(SysCommonMessage message)
 {
     Type  = message.Type;
     Data1 = message.Data1;
     Data2 = message.Data2;
 }
Esempio n. 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 public virtual void Visit(SysCommonMessage message)
 {
 }
Esempio n. 15
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);
                }
            }
        }