/// <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); }
/// <summary> /// Creates a new short midi message object. /// </summary> /// <param name="message">A full short midi message with the lower 3 bytes filled.</param> /// <returns>Never returns null.</returns> public MidiShortMessage CreateShortMessage(int message) { MidiShortMessage result = Lookup(message); if (result == null) { int statusChannel = MidiData.GetStatus(message); byte status = (byte)(statusChannel & (byte)0xF0); if (status == 0xF0) { if (statusChannel >= 0xF8) { result = new MidiSysRealtimeMessage(message); } else { result = new MidiSysCommonMessage(message); } } else if (status == (byte)MidiChannelCommand.ControlChange) { result = new MidiControllerMessage(message); } else { result = new MidiChannelMessage(message); } Add(result); } return(result); }
/// <summary> /// Creates a new midi controller message object. /// </summary> /// <param name="channel">The (zero-based) midi channel number.</param> /// <param name="controller">The type of continuous controller.</param> /// <param name="value">The (optional) parameter (usually value) of the controller.</param> /// <returns>Returns a new instance.</returns> public MidiControllerMessage CreateControllerMessage(byte channel, MidiControllerType controller, byte value) { Contract.Ensures(Contract.Result <MidiControllerMessage>() != null); Check.IfArgumentOutOfRange <byte>(channel, 0, 15, "channel"); MidiData data = new MidiData(); data.Status = (byte)((int)MidiChannelCommand.ControlChange | channel); data.Parameter1 = (byte)controller; data.Parameter2 = value; MidiControllerMessage message = (MidiControllerMessage)this.Lookup(data); if (message == null) { message = new MidiControllerMessage(data); this.Add(message); } return(message); }
/// <summary> /// Creates a new midi controller message object. /// </summary> /// <param name="channel">The (zero-based) midi channel number.</param> /// <param name="controller">The type of continuous controller.</param> /// <param name="value">The (optional) parameter (usually value) of the controller.</param> /// <returns>Returns a new instance.</returns> public MidiControllerMessage CreateControllerMessage(byte channel, MidiControllerType controller, byte value) { Check.IfArgumentOutOfRange <byte>(channel, 0, 15, nameof(channel)); var data = new MidiData { Status = (byte)((int)MidiChannelCommand.ControlChange | channel), Parameter1 = (byte)controller, Parameter2 = value }; var message = (MidiControllerMessage)Lookup(data); if (message == null) { message = new MidiControllerMessage(data); Add(message); } return(message); }
/// <summary> /// Creates a new short midi message object. /// </summary> /// <param name="message">A full short midi message with the lower 3 bytes filled.</param> /// <returns>Never returns null.</returns> public MidiShortMessage CreateShortMessage(int message) { Contract.Ensures(Contract.Result <MidiShortMessage>() != null); MidiShortMessage result = this.Lookup(message); if (result == null) { int statusChannel = MidiData.GetStatus(message); byte status = (byte)(statusChannel & (byte)0xF0); if (status == 0xF0) { if (statusChannel >= 0xF8) { result = new MidiSysRealTimeMessage(message); } else { result = new MidiSysCommonMessage(message); } } else if (status == (byte)MidiChannelCommand.ControlChange) { result = new MidiControllerMessage(message); } else { result = new MidiChannelMessage(message); } this.Add(result); } return(result); }