/// <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 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); }