Maestro - Midi Player Tool Kit for Unity Version 2.18.2
Loading...
Searching...
No Matches

Runtime state for one MIDI channel in the synth.
A channel contains independent settings used to render events on that channel: More...

Public Member Functions

override string ToString ()
 Builds a debug string that summarizes the channel state.
Example output:
int Controller (MPTKController numController, int valueController=-1)
 Reads or writes a controller value.

Returns
Current value if reading, previous value if writing, or -1 on error.

.

Public Attributes

int LastPreset
 Last preset used on this channel. Used when restoring after a forced preset.
int LastBank
 Last bank used on this channel. Used when restoring after a forced bank.
byte[] key_pressure

Properties

int Channel [get]
 Zero-based channel number. Standard MIDI channels are 0 to 15; channel 9 is conventionally percussion.
bool Enable [get, set]
 Enables (unmutes) or disables (mutes) this channel. All channels are unmuted when MIDI starts playing (MidiFilePlayer.MPTK_Play).
To mute channels just before playback starts, use MidiFilePlayer.OnEventStartPlayMidi.
int NoteCount [get, set]
 Gets or sets the number of NoteOn events played since MIDI start. You can also set it, for example to reset it to 0.
float Volume [get, set]
 Gets or sets channel volume, from 0.0 to 1.0.
int PresetNum [get, set]
 Gets or sets the current preset number for this channel.
Value must be between 0 and 127 (with a full GM SoundFont). Each MIDI channel can play a different preset and bank.
You can inspect available banks and presets from Maestro / SoundFont Setup (right panel), then click the eye icon buttons.
int BankNum [get, set]
 Gets or sets the current bank number for this channel.
Each MIDI channel can play a different preset and bank.
You can inspect available banks and presets from Maestro / SoundFont Setup (right panel), then click the eye icon buttons.
string PresetName [get]
 Gets the current preset name for this channel.
Each MIDI channel can use a different preset.
int ForcedPreset [get, set]
 Gets or sets a forced preset for this channel.
When set to a value >= 0, the channel always uses this preset, even if a Program Change is received. Set to -1 to disable this behavior.
int ForcedBank [get, set]
 Gets or sets a forced bank for this channel.
When set to a value >= 0, the channel always uses this bank, even if a bank change message is received. Set to -1 to disable this behavior.

Detailed Description

Runtime state for one MIDI channel in the synth.
A channel contains independent settings used to render events on that channel:

  • Current instrument (preset) and bank
  • Volume
  • Mute state (see Enable)
  • Pitch bend and controller values

Channels are zero-based in MPTK (0 to 15). In General MIDI, channel 9 is typically used for percussion.

// Display preset name
GUILayout.Label(midiFilePlayer.MPTK_Channels[channel].PresetName ?? "not set", myStyle.TitleLabel3, GUILayout.Width(140));
// Display preset and bank index
int presetNum = midiFilePlayer.MPTK_Channels[channel].PresetNum;
int bankNum = midiFilePlayer.MPTK_Channels[channel].BankNum;
int presetForced = midiFilePlayer.MPTK_Channels[channel].ForcedPreset;

Member Function Documentation

◆ ToString()

override string MidiPlayerTK.MPTKChannel.ToString ( )

Builds a debug string that summarizes the channel state.
Example output:

  • Channel:2 Enabled [Preset:18, Bank:0] 'Rock Organ' Count:1 Volume:1
  • Channel:4 Muted [Preset:F44, Bank:0] 'Stereo Strings Trem' Count:33 Volume:0,50
Returns
Information string

◆ Controller()

int MidiPlayerTK.MPTKChannel.Controller ( MPTKController numController,
int valueController = -1 )

Reads or writes a controller value.

Returns
Current value if reading, previous value if writing, or -1 on error.

.

GUILayout.Label("Sustain switch", myStyle.LabelRight, GUILayout.Width(120), GUILayout.Height(25));
// Is sustain enabled on the current channel?
bool sustain = midiStreamPlayer.MPTK_Channels[StreamChannel].Controller(MPTKController.Sustain) < 64 ? false : true;
// Switch sustain state
if (GUILayout.Button(sustain ? "Sustain On" : "Sustain Off", sustain ? myStyle.BtSelected : myStyle.BtStandard, GUILayout.Width(buttonTinyWidth)))
// Send a MIDI event control change for sustain
midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
{
Command = MPTKCommand.ControlChange,
Controller = MPTKController.Sustain,
Value = sustain ? 0 : 64, // enable / disable sustain
Channel = StreamChannel
});
Parameters
numControllerController to read or write
valueControllerValue to set. Default is -1 to read only (no write).
  • SontFont 2.01 NRPN Message (Sect. 9.6, p. 74) *‍/

Member Data Documentation

◆ key_pressure

byte [] MidiPlayerTK.MPTKChannel.key_pressure

MIDI polyphonic key pressure from [0;127]

Property Documentation

◆ Volume

float MidiPlayerTK.MPTKChannel.Volume
getset

Gets or sets channel volume, from 0.0 to 1.0.

// Slider to change volume
float currentVolume = midiFilePlayer.MPTK_Channels[channel].Volume;
float volume = HelperDemo.GUI_Slider(null, currentVolume, 0f, 1f, alignCaptionRight: true, enableButton: false, widthCaption: -1, widthSlider: 100, widthLabelValue: 40);
if (volume != currentVolume)
midiFilePlayer.MPTK_Channels[channel].Volume = volume;

◆ PresetNum

int MidiPlayerTK.MPTKChannel.PresetNum
getset

Gets or sets the current preset number for this channel.
Value must be between 0 and 127 (with a full GM SoundFont). Each MIDI channel can play a different preset and bank.
You can inspect available banks and presets from Maestro / SoundFont Setup (right panel), then click the eye icon buttons.

// Select any value in the range 0 and 16383 for the bank
int newBank = (int)HelperDemo.GUI_Slider("Free Bank", midiStreamPlayer.MPTK_Channels[StreamChannel].BankNum, 0, 128 * 128 - 1, alignCaptionRight: false, widthCaption: 100, widthSlider: 115, widthLabelValue: 30);
// Select any value in the range 0 and 127 for the preset
int newPreset = (int)HelperDemo.GUI_Slider("Free Preset", midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum, 0, 127, alignCaptionRight: true, widthCaption: 100, widthSlider: 115, widthLabelValue: 30);
// If user made change for bank or preset ...
if (newBank != midiStreamPlayer.MPTK_Channels[StreamChannel].BankNum ||
newPreset != midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum)
{
// ... apply the change to the MidiStreamPlayer for the current channel.
// If the bank or the preset doestn't exist
// - the method returns false
// - the bank and preset are still registered in the channel
// - when a note-on is received on this channel, the first preset of the first bank is used to play (usually piano).
midiStreamPlayer.MPTK_Channels[StreamChannel].BankNum = newBank;
if (midiStreamPlayer.MPTK_Channels[StreamChannel].BankNum != newBank)
Debug.Log($"Bank {newBank} not set ");
else
Debug.Log($"Bank set to:{newBank}");
midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum = newPreset;
if (midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum != newPreset)
Debug.Log($"Preset {newPreset} not set ");
else
Debug.Log($"Preset set to:{newPreset}");
// Read the current preset name
Debug.Log($"Current preset name '{midiStreamPlayer.MPTK_Channels[StreamChannel].PresetName}'");
}

◆ BankNum

int MidiPlayerTK.MPTKChannel.BankNum
getset

Gets or sets the current bank number for this channel.
Each MIDI channel can play a different preset and bank.
You can inspect available banks and presets from Maestro / SoundFont Setup (right panel), then click the eye icon buttons.

// Select any value in the range 0 and 16383 for the bank
int newBank = (int)HelperDemo.GUI_Slider("Free Bank", midiStreamPlayer.MPTK_Channels[StreamChannel].BankNum, 0, 128 * 128 - 1, alignCaptionRight: false, widthCaption: 100, widthSlider: 115, widthLabelValue: 30);
// Select any value in the range 0 and 127 for the preset
int newPreset = (int)HelperDemo.GUI_Slider("Free Preset", midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum, 0, 127, alignCaptionRight: true, widthCaption: 100, widthSlider: 115, widthLabelValue: 30);
// If user made change for bank or preset ...
if (newBank != midiStreamPlayer.MPTK_Channels[StreamChannel].BankNum ||
newPreset != midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum)
{
// ... apply the change to the MidiStreamPlayer for the current channel.
// If the bank or the preset doestn't exist
// - the method returns false
// - the bank and preset are still registered in the channel
// - when a note-on is received on this channel, the first preset of the first bank is used to play (usually piano).
midiStreamPlayer.MPTK_Channels[StreamChannel].BankNum = newBank;
if (midiStreamPlayer.MPTK_Channels[StreamChannel].BankNum != newBank)
Debug.Log($"Bank {newBank} not set ");
else
Debug.Log($"Bank set to:{newBank}");
midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum = newPreset;
if (midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum != newPreset)
Debug.Log($"Preset {newPreset} not set ");
else
Debug.Log($"Preset set to:{newPreset}");
// Read the current preset name
Debug.Log($"Current preset name '{midiStreamPlayer.MPTK_Channels[StreamChannel].PresetName}'");
}

◆ PresetName

string MidiPlayerTK.MPTKChannel.PresetName
get

Gets the current preset name for this channel.
Each MIDI channel can use a different preset.

Returns
Preset name, or "no preset defined" if unavailable.
// Defined preset with CurrentPreset (value defined in inspector to 0).
midiStreamPlayer.MPTK_Channels[StreamChannel].PresetNum = CurrentPreset;
Debug.LogFormat($" Preset '{midiStreamPlayer.MPTK_Channels[StreamChannel].PresetName}' defined on channel {StreamChannel}");

◆ ForcedPreset

int MidiPlayerTK.MPTKChannel.ForcedPreset
getset

Gets or sets a forced preset for this channel.
When set to a value >= 0, the channel always uses this preset, even if a Program Change is received. Set to -1 to disable this behavior.

Returns
Preset index, or -1 when not forced.
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
// Before v2.10.1 midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
midiFilePlayer.MPTK_Channels[channel].ForcedBank = forceBank;
midiFilePlayer.MPTK_Channels[channel].ForcedPreset = forcePreset;

◆ ForcedBank

int MidiPlayerTK.MPTKChannel.ForcedBank
getset

Gets or sets a forced bank for this channel.
When set to a value >= 0, the channel always uses this bank, even if a bank change message is received. Set to -1 to disable this behavior.

Returns
Bank index, or -1 when not forced.
// Force a preset and a bank whatever the MIDI events from the MIDI file.
// set forcePreset to -1 to restore to the last preset and bank value known from the MIDI file.
// let forcebank to -1 to not force the bank.
// Before v2.10.1 midiFilePlayer.MPTK_ChannelForcedPresetSet(channel, forcePreset, forceBank);
midiFilePlayer.MPTK_Channels[channel].ForcedBank = forceBank;
midiFilePlayer.MPTK_Channels[channel].ForcedPreset = forcePreset;