/// <summary> /// Creates a new channel (short) midi message object. /// </summary> /// <param name="command">The channel command.</param> /// <param name="channel">The (zero-based) channel number.</param> /// <param name="parameter1">The (optional) first parameter of the midi message.</param> /// <param name="parameter2">The (optional) second parameter of the midi message.</param> /// <returns>Never returns null.</returns> public MidiChannelMessage CreateChannelMessage(MidiChannelCommand command, byte channel, byte parameter1, byte parameter2) { Contract.Requires(channel >= 0 && channel <= 15); Contract.Ensures(Contract.Result <MidiChannelMessage>() != null); Check.IfArgumentOutOfRange <byte>(channel, 0, 15, "channel"); MidiData data = new MidiData(); data.Status = (byte)((int)command | channel); data.Parameter1 = parameter1; data.Parameter2 = parameter2; MidiChannelMessage message = (MidiChannelMessage)this.Lookup(data); if (message == null) { if (command == MidiChannelCommand.ControlChange) { message = new MidiControllerMessage(data); } else { message = new MidiChannelMessage(data); } this.Add(message); } return(message); }
/// <summary> /// Creates a new channel (short) midi message object. /// </summary> /// <param name="command">The channel command.</param> /// <param name="channel">The (zero-based) channel number.</param> /// <param name="parameter1">The (optional) first parameter of the midi message.</param> /// <param name="parameter2">The (optional) second parameter of the midi message.</param> /// <returns>Never returns null.</returns> public MidiChannelMessage CreateChannelMessage(MidiChannelCommand command, byte channel, byte parameter1, byte parameter2) { Check.IfArgumentOutOfRange <byte>(channel, 0, 15, nameof(channel)); var data = new MidiData { Status = (byte)((int)command | channel), Parameter1 = parameter1, Parameter2 = parameter2 }; var message = (MidiChannelMessage)Lookup(data); if (message == null) { if (command == MidiChannelCommand.ControlChange) { message = new MidiControllerMessage(data); } else { message = new MidiChannelMessage(data); } Add(message); } return(message); }