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

Channel collection and per-channel playback state. More...

Classes

class  MidiPlayerTK.MPTKChannels
 Collection of MIDI channels managed by a MIDI synth.
A standard MIDI synth uses 16 channels (0 to 15). Each channel keeps an independent state, including: More...
class  MidiPlayerTK.MPTKChannel
 Runtime state for one MIDI channel in the synth.
A channel contains independent settings used to render events on that channel: More...

Functions

 MidiPlayerTK.MPTKChannels.MPTKChannels ()
 Parameterless constructor kept for serialization and code stripping preservation.

Properties

bool MidiPlayerTK.MPTKChannel.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.

Detailed Description

Channel collection and per-channel playback state.

Properties

◆ Enable

bool MidiPlayerTK.MPTKChannel.Enable
getset

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.

See demo: Assets\MidiPlayer\Demo\FreeMVP\MidiLoop.cs

// Start is called before the first frame update
void Start()
{
// Find existing MidiFilePlayer in the scene hierarchy
// ---------------------------------------------------
midiFilePlayer = FindFirstObjectByType<MidiFilePlayer>();
if (midiFilePlayer == null)
{
Debug.LogWarning("Can't find a MidiFilePlayer Prefab in the current Scene Hierarchy. Add it with the Maestro menu.");
return;
}
midiFilePlayer.MPTK_PlayOnStart = false;
// Set Listeners
// -------------
// triggered when MIDI starts playing (Indeed, will be triggered at every restart)
midiFilePlayer.OnEventStartPlayMidi.AddListener(StartPlay);
// triggered when MIDI ends playing (Indeed, will be triggered at every end of restart)
midiFilePlayer.OnEventEndPlayMidi.AddListener(EndPlay);
// triggered every time a group of MIDI events are ready to be played by the MIDI synth.
midiFilePlayer.OnEventNotesMidi.AddListener(MidiReadEvents);
LoadAndPlay();
}
public void StartPlay(string midiname)
{
// Enable or disable MIDI channel. it's not possible before because channel are not yet allocated
for (int channel = 0; channel < midiFilePlayer.MPTK_Channels.Length; channel++)
// Enable only ChannelSelected or all channels if ChannelSelected equal -1
if (channel == ChannelSelected || ChannelSelected == -1)
// v2.10.1 midiFilePlayer.MPTK_ChannelEnableSet(channel, true);
midiFilePlayer.MPTK_Channels[channel].Enable= true;
else
// Disable this channel
// v2.10.1 midiFilePlayer.MPTK_ChannelEnableSet(channel, false);
midiFilePlayer.MPTK_Channels[channel].Enable = false;
Debug.Log($"<color=green>Start at tick:{midiFilePlayer.MPTK_TickCurrent}</color>" +
$" MPTK_DeltaTicksPerQuarterNote:{midiFilePlayer.MPTK_MidiLoaded.MPTK_DeltaTicksPerQuarterNote}" +
$" MPTK_NumberBeatsMeasure:{midiFilePlayer.MPTK_MidiLoaded.MPTK_NumberBeatsMeasure}" +
$" MPTK_NumberQuarterBeat:{midiFilePlayer.MPTK_MidiLoaded.MPTK_NumberQuarterBeat}");
}
Returns
True if the channel is enabled.
// 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*/
}