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

Real-time MIDI event playback for interactive, gameplay, and procedural music systems. More...

Topics

 Live MIDI Events
 Play and stop MIDI events in real time.
 MIDI Channels and Controls
 Work with per-channel state such as instrument, volume, and pitch behavior.
 Chords and Scales
 Build and play chords from scale or library definitions.
 Maestro Pro Extensions
 Advanced scale/chord and real-time control features available in Maestro Pro.

Classes

class  MidiPlayerTK.MidiStreamPlayer
 Builds and plays real-time music in response to user actions or algorithmic logic. This class is intended to be used with the MidiStreamPlayer prefab. More...

Functions

void MidiPlayerTK.MidiStreamPlayer.MPTK_PlayEvent (List< MPTKEvent > mptkEvents)
 Plays a list of MIDI events from MPTKEvent instances. Runs in a thread so the call returns immediately. See also the method MPTK_StopEvent to stop a note from an instance of MPTKEvent.

Detailed Description

Real-time MIDI event playback for interactive, gameplay, and procedural music systems.

MidiStreamPlayer is the live-event playback MIDI message component in Maestro MPTK. Instead of loading a complete MIDI file, your code creates and sends events at runtime. For setup guidance and news, see https://paxstellar.fr/midi-file-player-detailed-view-2-2/

Typical scenarios
  • interactive instruments and keyboard input,
  • gameplay-driven musical responses,
  • generative/procedural music systems,
  • runtime control of pitch wheel, channels, and chords.

MidiStreamPlayer inherits from MidiSynth, so synthesis and channel features from MidiSynth remain available.

Recommended reading order:

  1. MidiStreamPlayer Overview
  2. Real-Time MIDI Messages Workflow
  3. MPTKEvent Concept and Data Model
  4. Chords, Scales, and Live Harmony
  5. MidiStreamPlayer Pro Extensions
See also
MidiStreamPlayer Overview
Real-Time MIDI Messages Workflow
MPTKEvent Concept and Data Model
Chords, Scales, and Live Harmony
MidiStreamPlayer Pro Extensions

Function Documentation

◆ MPTK_PlayEvent()

void MidiPlayerTK.MidiStreamPlayer.MPTK_PlayEvent ( List< MPTKEvent > mptkEvents)

Plays a list of MIDI events from MPTKEvent instances. Runs in a thread so the call returns immediately. See also the method MPTK_StopEvent to stop a note from an instance of MPTKEvent.

private void MaestroPlayOneNote()
{
//Debug.Log($"{StreamChannel} {midiStreamPlayer.MPTK_ChannelPresetGetName(StreamChannel)}");
// Start playing a new note
NotePlaying = new MPTKEvent()
{
Command = MPTKCommand.NoteOn,
Value = CurrentNote, // note to played, ex 60=C5. Use the method from class HelperNoteLabel to convert to string
Channel = StreamChannel,
Duration = Convert.ToInt64(CurrentDuration * 1000f), // millisecond, -1 to play indefinitely
Velocity = CurrentVelocity, // Sound can vary depending on the velocity
Delay = Convert.ToInt64(CurrentDelay * 1000f),
};
#if MPTK_PRO
// Applied to the current note playing all the real time generators defined
for (int i = 0; i < nbrGenerator; i++)
if (indexGenerator[i] >= 0)
NotePlaying.ModifySynthParameter((fluid_gen_type)indexGenerator[i], valueGenerator[i] / 100f, MPTKModeGeneratorChange.Override);
#endif
midiStreamPlayer.MPTK_PlayEvent(NotePlaying);
}
Parameters
mptkEventsList of MPTKEvent instances to play.