MidiPlayerTK.MPTKChannels

Description and list of MIDI Channels associated to the MIDI synth.
Each MIDI synth has 16 channels that carry all the relevant MIDI information. More...

Inherits IEnumerable< MPTKChannel >.

Public Member Functions

void ResetExtension (int channelNum=-1)
 

Public Attributes

bool EnableResetChannel = true
 

Properties

bool EnableAll [set]
 
int Length [get]
 
MPTKChannel this[int channel] [get, set]
 
float VolumeAll [set]
 

Detailed Description

Description and list of MIDI Channels associated to the MIDI synth.
Each MIDI synth has 16 channels that carry all the relevant MIDI information.

  • Current instrument / bank
  • Volume
  • Mute / Unmute (see Enable)
  • Pitch bend ...

They serve to distinguish between instruments and provide independent control over each one.
By transmitting MIDI messages on their respective channels, you can alter the instrument, volume, pitch, and other parameters.
Within the Maestro Midi Player Toolkit, MIDI channels are designated numerically from 0 to 15. Notably, channel 9 is set aside specifically for drum sounds.

HelperDemo.GUI_Horizontal(HelperDemo.Zone.BEGIN);
GUILayout.Label("Channel Preset Name Preset / Bank",
myStyle.TitleLabel3, GUILayout.Width(60 + 140 + 120 + 100 + 110));
GUILayout.Label(" Count Enabled Volume",
myStyle.TitleLabel3, GUILayout.Width(900));
HelperDemo.GUI_Horizontal(HelperDemo.Zone.END);
// Also available for MidiStreamPlayer, MidiInReader, MidiExternalPlayer.
for (int channel = 0; channel < midiFilePlayer.MPTK_Channels.Length; channel++)
{
HelperDemo.GUI_Horizontal(HelperDemo.Zone.BEGIN);
// Display channel number and log info
if (GUILayout.Button($" {channel:00}", myStyle.TitleLabel3, GUILayout.Width(60)))
Debug.Log(midiFilePlayer.MPTK_Channels[channel].ToString());
// 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;
// Check if preset is forced and build a string info
string sPreset = presetForced == -1 ? $"{presetNum} / {bankNum}" : $"F{presetForced} / {bankNum}";
// Slider to change the preset on this channel from -1 (disable forced) to 127.
int forcePreset = (int)HelperDemo.GUI_Slider(sPreset, presetNum, -1f, 127f, alignCaptionRight: true, widthCaption: 120, widthSlider: 100, widthLabelValue: -1);
if (forcePreset != presetNum)
{
// 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;
}
// Display count note by channel
GUILayout.Label($"{midiFilePlayer.MPTK_Channels[channel].NoteCount,-5}", myStyle.LabelRight, GUILayout.Width(100));
// Toggle to enable or disable a channel
GUILayout.Label(" ", myStyle.TitleLabel3, GUILayout.Width(20));
bool state = GUILayout.Toggle(midiFilePlayer.MPTK_Channels[channel].Enable, "", GUILayout.MaxWidth(20));
if (state != midiFilePlayer.MPTK_Channels[channel].Enable)
{
midiFilePlayer.MPTK_Channels[channel].Enable = state;
Debug.LogFormat("Channel {0} state:{1}, preset:{2}", channel, state, midiFilePlayer.MPTK_Channels[channel].PresetName ?? "not set"); /*2.84*/
}
// 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;
HelperDemo.GUI_Horizontal(HelperDemo.Zone.END);
}

Member Function Documentation

◆ ResetExtension()

void MidiPlayerTK.MPTKChannels.ResetExtension ( int  channelNum = -1)

Reset Maestro channels extension information.

  • LastBank is set to -1 (no last bank feature when reset)
  • ForcedBank is disable
  • ForcedPreset is disable
  • Enable is set to true
  • Volume is set to max (1) Other information like current preset, bank, controller are not reset.
    Version
    2.10.1
Parameters
channelNumselect the channel number to reset, by default all

Member Data Documentation

◆ EnableResetChannel

bool MidiPlayerTK.MPTKChannels.EnableResetChannel = true

Enable to reset all channels when MIDI start playing (if true, Channels member is allocated at the synth reinit). Default is true.
Weird behaviors could occurs if set to false with MidiFilePlayer but could be useful for MidiStreamPlayer.

Version
2.10.1

Property Documentation

◆ EnableAll

bool MidiPlayerTK.MPTKChannels.EnableAll
set

Enable or disable all channels for playing

// Also available for MidiStreamPlayer, MidiInReader, MidiExternalPlayer.
if (GUILayout.Button("Enable All", GUILayout.Width(100)))
midiFilePlayer.MPTK_Channels.EnableAll = true;
if (GUILayout.Button("Disable All", GUILayout.Width(100)))
midiFilePlayer.MPTK_Channels.EnableAll = false;

◆ Length

int MidiPlayerTK.MPTKChannels.Length
get

Channel count. Classically 16 when MIDI is read from a MIDI file.
Can be extended but not compliant with MIDI file, only for internal use (experimental)

◆ this[int channel]

MPTKChannel MidiPlayerTK.MPTKChannels.this[int channel]
getset

Allows access to all channels in the MIDI Synth. Within the Maestro Midi Player Toolkit, MIDI channels are designated numerically from 0 to 15. Notably, channel 9 is set aside specifically for drum sounds.

// Force a random preset between 0 and 127 for each channels
// midiFilePlayer.MPTK_Channels.ResetExtension(); to return to origin preset
foreach (MPTKChannel mptkChannel in midiFilePlayer.MPTK_Channels)
mptkChannel.ForcedPreset = UnityEngine.Random.Range(0, 127);
Description of a MIDI Channel associated to the MIDI synth. They serve to distinguish between instrum...
Definition: MPTKChannels.cs:212
Parameters
channelChannel number between 0 and 15 included
Returns

◆ VolumeAll

float MidiPlayerTK.MPTKChannels.VolumeAll
set

Set the volume for all channels as a percentage between 0 and 1.