MidiPlayerTK.MidiStreamPlayer

Build and Play Real Time Music in relation with user actions or algorithms. This class must be used with the prefab MidiStreamPlayer.
More...

Inheritance diagram for MidiPlayerTK.MidiStreamPlayer:
MidiPlayerTK.MidiSynth MidiPlayerTK.MidiSynth

Public Member Functions

MPTKChordBuilder MPTK_PlayChordFromLib (MPTKChordBuilder chord)
 
MPTKChordBuilder MPTK_PlayChordFromScale (MPTKChordBuilder chord)
 
void MPTK_PlayEvent (List< MPTKEvent > mptkEvents)
 
void MPTK_PlayEvent (MPTKEvent mptkEvent)
 
void MPTK_PlayPitchWheelChange (int channel, float pitchWheel)
 
void MPTK_PlayPitchWheelSensitivity (int channel, int sensitivity)
 
void MPTK_StartMidiStream ()
 
void MPTK_StopChord (MPTKChordBuilder chord)
 
void MPTK_StopEvent (MPTKEvent mptkEvent)
 
- Public Member Functions inherited from MidiPlayerTK.MidiSynth
void MPTK_ClearAllSound (bool destroyAudioSource=false, int _idSession=-1)
 
void MPTK_InitSynth (int channelCount=16, bool preserveChannelInfo=false)
 
void MPTK_ResetStat ()
 
void MPTK_StartSequencerMidi ()
 
void MPTK_StartSynth ()
 
void MPTK_StopSynth ()
 
IEnumerator MPTK_WaitAllNotesOff (int _idSession=-1)
 
delegate void OnAudioFrameStartHandler (double synthTime)
 

Properties

MPTKChannels MPTK_Channels [get]
 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...
 
string MPTK_ScaleName [get]
 
MPTKScaleName MPTK_ScaleSelected [get, set]
 
- Properties inherited from MidiPlayerTK.MidiSynth
int MPTK_IndexSynthBuffSize [get, set]
 
int MPTK_IndexSynthRate [get, set]
 
string MPTK_InstrumentPlayed [get]
 
bool MPTK_IsSpatialSynthMaster [get]
 
bool MPTK_KeepPlayingNonLooped [get, set]
 
float MPTK_MaxDistance [get, set]
 
bool MPTK_PauseOnDistance [get, set]
 
bool MPTK_Spatialize [get, set]
 
int MPTK_SpatialSynthIndex [get]
 
int MPTK_SynthRate [get, set]
 
int MPTK_ThreadMidiPriority [get, set]
 
string MPTK_TrackName [get]
 
int MPTK_TransExcludedChannel [get, set]
 
int MPTK_Transpose [get, set]
 
float MPTK_Volume [get, set]
 

Additional Inherited Members

- Public Types inherited from MidiPlayerTK.MidiSynth
enum  ModeSpatializer { Channel , Track }
 
- Static Public Member Functions inherited from MidiPlayerTK.MidiSynth
static StringBuilder MPTK_BuildInfoSynth (MidiSynth synth)
 Build a string with performance and information about the MIDI reader and the MIDI synthesizer. DEBUG_PERF_AUDIO DEBUG_HISTO_DSPSIZE DEBUG_PERF_MIDI More...
 
- Public Attributes inherited from MidiPlayerTK.MidiSynth
bool MPTK_ApplyModLfo
 
bool MPTK_ApplyRealTimeModulator
 
bool MPTK_ApplyVibLfo
 
bool MPTK_AudioSettingFromUnity
 
bool MPTK_AutoBuffer = true
 
int MPTK_AutoCleanVoiceLimit
 
bool MPTK_CorePlayer
 
float MPTK_CutOffVolume = 0.0001f
 
bool MPTK_DirectSendToPlayer
 
MPTKEffectSoundFont MPTK_EffectSoundFont
 
MPTKEffectUnity MPTK_EffectUnity
 Unlike SoundFont effects, they applied to the whole player. On the other hand, the Unity effects parameters are rich and, obviously based on Uniy algo!
https://docs.unity3d.com/Manual/class-AudioEffectMixer.html
Only most important effect are integrated in Maestro: Reverb and Chorus. On need, others effects could be added. More...
 
bool MPTK_EnableChangeTempo
 
bool MPTK_EnableFreeSynthRate = false
 
bool MPTK_EnablePanChange
 
bool MPTK_EnablePresetDrum
 
int MPTK_InstrumentNum
 
bool MPTK_KillByExclusiveClass = true
 
float MPTK_LeanSynthStarting = 0.05f
 
bool MPTK_LogEvents
 
bool MPTK_LogWave
 
bool MPTK_ReleaseSameNote = true
 
uint MPTK_ReleaseTimeMin = 500000
 
float MPTK_ReleaseTimeMod = 1f
 
bool MPTK_SpatialSynthEnabled
 
int MPTK_StatVoiceCountActive
 
int MPTK_StatVoiceCountFree
 
int MPTK_StatVoiceCountPlaying
 
int MPTK_StatVoiceCountReused
 
int MPTK_StatVoicePlayed
 
int MPTK_StatVoiceRatioReused
 
int MPTK_ThreadMidiWait = 10
 
bool MPTK_WeakDevice
 
Action< int, long, int, int > OnBeatEvent
 Action is executed at each beat and received these parameters: More...
 
EventSynthClass OnEventSynthAwake
 
EventSynthClass OnEventSynthStarted
 
Func< MPTKEvent, bool > OnMidiEvent
 
bool playOnlyFirstWave
 
- Static Public Attributes inherited from MidiPlayerTK.MidiSynth
const float FLUID_CHORUS_DEFAULT_DEPTH = 4.25f
 
const float FLUID_CHORUS_DEFAULT_LEVEL = 0.6f
 
const int FLUID_CHORUS_DEFAULT_N = 3
 
const float FLUID_CHORUS_DEFAULT_SPEED = 0.2f
 
const float FLUID_CHORUS_DEFAULT_WIDTH = 10f
 
const float FLUID_REVERB_DEFAULT_DAMP = 0.3f
 
const float FLUID_REVERB_DEFAULT_LEVEL = 0.7f
 
const float FLUID_REVERB_DEFAULT_ROOMSIZE = 0.5f
 
const float FLUID_REVERB_DEFAULT_WIDTH = 0.8f
 
static List< MidiFilePlayerSpatialSynths
 
- Events inherited from MidiPlayerTK.MidiSynth
OnAudioFrameStartHandler OnAudioFrameStart
 

Detailed Description

Build and Play Real Time Music in relation with user actions or algorithms. This class must be used with the prefab MidiStreamPlayer.

Attention

No MIDI file is necessary, the notes are generated by your scripts from your own algorithms by using the methods and properties of this class.
The main function MPTK_PlayEvent() and the class MPTKEvent are able to create all kind of MIDI events as note-on.
All the values must be set in MPTKEvent, command, note value, duration ... for more details look at the class MPTKEvent.

A note-on must also be stopped, : if duration = -1 the note is infinite, it's the goal of MPTK_StopEvent() to stop the note with a note-off.
On top of that, the Pro version adds playing chords with MPTK_PlayChordFromRange() and MPTK_PlayChordFromLib().
For playing scales, have a look to the class MPTKRangeLib
For more information see here https://paxstellar.fr/midi-file-player-detailed-view-2-2/
and look at the demo TestMidiStream with the source code TestMidiStream.cs.

This class inherits from MidiSynth so all properties, events, methods from MidiSynth are available in this class.

Note
  • A full example bellow.
  • You can't directly copy paste this extract. But the full source code is available for free with Maestro MPTK free.
  • Some features are available only with the Pro version.
    private MPTKEvent[] eventsMidi;
    // blues en C minor: C,D#,F,F#,G,A# http://patrick.murris.com/musique/gammes_piano.htm?base=3&scale=0%2C3%2C5%2C6%2C7%2C10&octaves=1
    // for playing from the keyboard
    private int[] keysToNote = { 60, 63, 65, 66, 67, 70, 72, 75, 77 };
    // Update is called once per frame
    void Update()
    {
    // Check that SoundFont is loaded and add a little wait (0.5 s by default) because Unity AudioSource need some time to be started
    return;
    //
    // Play note from the keyboard
    // ---------------------------
    // Better in Start(), here only for demo clarity
    if (eventsMidi == null)
    // Can play simultanesously 10 notes from keyboard
    eventsMidi = new MPTKEvent[10];
    // Check if key 1 to 9 is down (top alpha keyboard)
    for (int key = 0; key < 9; key++)
    {
    if (Input.GetKeyDown(KeyCode.Alpha1 + key))
    {
    // Create a new note and play
    eventsMidi[key] = new MPTKEvent()
    {
    Command = MPTKCommand.NoteOn,
    Channel = StreamChannel, // From 0 to 15
    Duration = -1, // Infinite, note-off when key is released, see bellow.
    Value = keysToNote[key], // blues en C minor: C,D#,F,F#,G,A# http://patrick.murris.com/musique/gammes_piano.htm?base=3&scale=0%2C3%2C5%2C6%2C7%2C10&octaves=1
    Velocity = 100
    };
    // Send the note-on MIDI event to the MIDI synth
    midiStreamPlayer.MPTK_PlayEvent(eventsMidi[key]);
    }
    // If the note is active and the corresponding key is released then stop the note
    if (eventsMidi[key] != null && Input.GetKeyUp(KeyCode.Alpha1 + key))
    {
    midiStreamPlayer.MPTK_StopEvent(eventsMidi[key]);
    eventsMidi[key] = null;
    }
    }
    //
    // Change preset with arrow keys
    // -----------------------------
    if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.UpArrow))
    {
    if (Input.GetKeyDown(KeyCode.DownArrow)) CurrentPreset--;
    if (Input.GetKeyDown(KeyCode.UpArrow)) CurrentPreset++;
    CurrentPreset = Mathf.Clamp(CurrentPreset, 0, 127);
    // Send the patch (other name for preset) change MIDI event to the MIDI synth
    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
    {
    Command = MPTKCommand.PatchChange,
    Value = CurrentPreset, // From 0 to 127
    Channel = StreamChannel, // From 0 to 15
    });
    }
    #if MPTK_PRO
    //
    // Change pitch
    // ------------
    if (PitchChange != DEFAULT_PITCH)
    {
    // If user change the pitch, wait 1/2 second before returning to median value
    if (Time.realtimeSinceStartup - LastTimePitchChange > 0.5f)
    {
    PitchChange = Mathf.SmoothDamp(PitchChange, DEFAULT_PITCH, ref currentVelocityPitch, 0.5f, 10000, Time.unscaledDeltaTime);
    if (Mathf.Abs(PitchChange - DEFAULT_PITCH) < 0.001f)
    PitchChange = DEFAULT_PITCH;
    //Debug.Log("DEFAULT_PITCH " + DEFAULT_PITCH + " " + PitchChange + " " + currentVelocityPitch);
    midiStreamPlayer.MPTK_PlayPitchWheelChange(StreamChannel, PitchChange);
    }
    }
    #endif
    //
    // Loop playing on notes and presets
    // ---------------------------------
    if (midiStreamPlayer != null && (IsplayingLoopPresets || IsplayingLoopNotes))
    {
    float time = Time.realtimeSinceStartup - LastTimeChange;
    if (time > LoopDelay)
    {
    // It's time to generate some notes ;-)
    LastTimeChange = Time.realtimeSinceStartup;
    for (int indexNote = 0; indexNote < CountNoteToPlay; indexNote++)
    {
    // Loop on preset
    if (IsplayingLoopPresets)
    {
    if (++CurrentPreset > EndLoopPreset) CurrentPreset = StartLoopPreset;
    if (CurrentPreset < StartLoopPreset) CurrentPreset = StartLoopPreset;
    midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
    {
    Command = MPTKCommand.PatchChange,
    Value = CurrentPreset,
    Channel = StreamChannel,
    });
    }
    // Loop on note
    if (IsplayingLoopNotes)
    {
    if (++CurrentNote > EndLoopingNote) CurrentNote = StartLoopingNote;
    if (CurrentNote < StartLoopingNote) CurrentNote = StartLoopingNote;
    }
    // Play note or chord or scale without stopping the current (useful for performance test)
    MaestroPlay(false);
    }
    }
    }
    }
    void MaestroPlay(bool stopCurrent)
    {
    if (RandomNote)
    {
    if (StartLoopingNote >= EndLoopingNote)
    CurrentNote = StartLoopingNote;
    else
    CurrentNote = UnityEngine.Random.Range(StartLoopingNote, EndLoopingNote);
    }
    if (RandomDuration)
    {
    CurrentDuration = UnityEngine.Random.Range(0.1f, 2f);
    if (!RandomDelay)
    LoopDelay = CurrentDuration;
    }
    if (RandomDelay)
    LoopDelay = UnityEngine.Random.Range(0.01f, 2f);
    #if MPTK_PRO
    if (FoldOutChord && (ChordPlay || ChordLibPlay || ScaleLibPlay))
    {
    if (RandomNote)
    {
    CountNoteChord = UnityEngine.Random.Range(3, 5);
    DegreeChord = UnityEngine.Random.Range(1, 8);
    CurrentChord = UnityEngine.Random.Range(StartLoopingNote, EndLoopingNote);
    }
    if (stopCurrent)
    MaestroStopChord();
    if (ChordPlay)
    MaestroPlayOneChord();
    if (ChordLibPlay)
    MaestroPlayOneChordFromLib();
    if (ScaleLibPlay)
    MaestroPlayScale();
    }
    else
    #endif
    {
    if (stopCurrent)
    MaestroStopOneNote();
    MaestroPlayOneNote();
    }
    }
    #if MPTK_PRO
    MPTKChordBuilder ChordPlaying;
    MPTKChordBuilder ChordLibPlaying;
    private void MaestroPlayScale()
    {
    // get the current scale selected
    MPTKScaleLib scale = MPTKScaleLib.CreateScale((MPTKScaleName)CurrentScale, true);
    for (int ecart = 0; ecart < scale.Count; ecart++)
    {
    NotePlaying = new MPTKEvent()
    {
    Command = MPTKCommand.NoteOn, // midi command
    Value = CurrentNote + scale[ecart], // from 0 to 127, 48 for C4, 60 for C5, ...
    Channel = StreamChannel, // from 0 to 15, 9 reserved for drum
    Duration = DelayPlayScale, // note duration in millisecond, -1 to play indefinitely, MPTK_StopEvent to stop
    Velocity = CurrentVelocity, // from 0 to 127, sound can vary depending on the velocity
    Delay = ecart * DelayPlayScale, // delay in millisecond before playing the note. Use it yo play chord with Arpeggio
    };
    midiStreamPlayer.MPTK_PlayEvent(NotePlaying);
    }
    }
    private void MaestroPlayOneChord()
    {
    // Start playing a new chord and save in ChordPlaying to stop it later
    ChordPlaying = new MPTKChordBuilder(true)
    {
    // Parameters to build the chord
    Tonic = CurrentNote,
    Count = CountNoteChord,
    Degree = DegreeChord,
    // Midi Parameters how to play the chord
    Channel = StreamChannel,
    Arpeggio = ArpeggioPlayChord, // delay in milliseconds between each notes of the chord
    Duration = Convert.ToInt64(CurrentDuration * 1000f), // millisecond, -1 to play indefinitely
    Velocity = CurrentVelocity, // Sound can vary depending on the velocity
    Delay = Convert.ToInt64(CurrentDelay * 1000f),
    };
    //Debug.Log(DegreeChord);
    midiStreamPlayer.MPTK_PlayChordFromScale(ChordPlaying);
    }
    private void MaestroPlayOneChordFromLib()
    {
    // Start playing a new chord and save in ChordLibPlaying to stop it later
    ChordLibPlaying = new MPTKChordBuilder(true)
    {
    // Parameters to build the chord
    Tonic = CurrentNote,
    FromLib = CurrentChord,
    // Midi Parameters how to play the chord
    Channel = StreamChannel,
    Arpeggio = ArpeggioPlayChord, // delay in milliseconds between each notes of the chord
    Duration = Convert.ToInt64(CurrentDuration * 1000f), // millisecond, -1 to play indefinitely
    Velocity = CurrentVelocity, // Sound can vary depending on the velocity
    Delay = Convert.ToInt64(CurrentDelay * 1000f),
    };
    //Debug.Log(DegreeChord);
    midiStreamPlayer.MPTK_PlayChordFromLib(ChordLibPlaying);
    }
    private void MaestroStopChord()
    {
    if (ChordPlaying != null)
    midiStreamPlayer.MPTK_StopChord(ChordPlaying);
    if (ChordLibPlaying != null)
    midiStreamPlayer.MPTK_StopChord(ChordLibPlaying);
    }
    #else
    private void PlayScale() { }
    private void PlayOneChord() { }
    private void PlayOneChordFromLib() { }
    private void StopChord() { }
    #endif
    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);
    }
    private void MaestroStopOneNote()
    {
    if (NotePlaying != null)
    {
    //Debug.Log("Stop note");
    // Stop the note (method to simulate a real human on a keyboard: duration is not known when a note is triggered.
    midiStreamPlayer.MPTK_StopEvent(NotePlaying);
    NotePlaying = null;
    }
    }
    Description of a MIDI Event. It's the heart of MPTK! Essential to handling MIDI by script from all ot...
    Definition: MPTKEvent.cs:45
    Singleton class to manage all globales MPTK features. More information here: https://paxstellar....
    Definition: MidiPlayerGlobal.cs:16
    static bool MPTK_IsReady(float delay=0.5f)
    Definition: MidiPlayerGlobal.cs:525
    MPTKCommand
    Definition: MPTKEnum.cs:12
    MPTKScaleName
    List of ranges available
    Definition: MPTKScaleLib.cs:254

Member Function Documentation

◆ MPTK_PlayChordFromLib()

MPTKChordBuilder MidiPlayerTK.MidiStreamPlayer.MPTK_PlayChordFromLib ( MPTKChordBuilder  chord)

Play a chord from the chord library. See file ChordLib.csv in folder Resources/GeneratorTemplate.
The Tonic is used to buid the chord

Version
Maestro Pro
private void PlayOneChordFromLib()
{
// Start playing a new chord
ChordLibPlaying = new MPTKChordBuilder(true)
{
// Parameters to build the chord
Tonic = CurrentNote,
FromLib = CurrentChord,
// Midi Parameters how to play the chord
Channel = StreamChannel,
// delay in milliseconds between each notes of the chord
Arpeggio = ArpeggioPlayChord,
// millisecond, -1 to play indefinitely
Duration = Convert.ToInt64(NoteDuration * 1000f),
// Sound can vary depending on the velocity
Velocity = Velocity,
Delay = Convert.ToInt64(NoteDelay * 1000f),
};
midiStreamPlayer.MPTK_PlayChordFromLib(ChordLibPlaying);
}
Build Chord and Play with MidiStreamPlayer.
Definition: MPTKChordBuilder.cs:12
Parameters
chordrequired: Tonic and FromLib on top of the classical Midi parameters
Returns

◆ MPTK_PlayChordFromScale()

MPTKChordBuilder MidiPlayerTK.MidiStreamPlayer.MPTK_PlayChordFromScale ( MPTKChordBuilder  chord)

Play a chord from the current selected scale (MPTK_ScaleSelected), Tonic and Degree are defined in parameter MPTKChord chord.
Major scale is selected if no scale is defined.
See file GammeDefinition.csv in folder Resources/GeneratorTemplate

Version
Maestro Pro
using MidiPlayerTK; // Add a reference to the MPTK namespace at the top of your script
using UnityEngine;
public class YourClass : MonoBehaviour
{
// Need a reference to the prefab MidiStreamPlayer you have added in your scene hierarchy.
public MidiStreamPlayer midiStreamPlayer;
// This object will be pass to the MPTK_PlayEvent for playing an event
MPTKEvent mptkEvent;
void Start()
{
// Find the MidiStreamPlayer. Could be also set directly from the inspector.
midiStreamPlayer = FindObjectOfType<MidiStreamPlayer>();
}
private void PlayOneChordFromLib()
{
// Start playing a new chord
MPTKChordBuilder ChordLibPlaying = new MPTKChordBuilder(true)
{
// Parameters to build the chord
Tonic = 60,
FromLib = 2,
// Midi Parameters how to play the chord
Channel = 0,
// delay in milliseconds between each notes of the chord
Arpeggio = 100,
// millisecond, -1 to play indefinitely
Duration = 500,
// Sound can vary depending on the velocity
Velocity = 100,
Delay = 0,
};
midiStreamPlayer.MPTK_PlayChordFromLib(ChordLibPlaying);
}
}
Build and Play Real Time Music in relation with user actions or algorithms. This class must be used w...
Definition: MidiStreamPlayer.cs:36
MPTKChordBuilder MPTK_PlayChordFromLib(MPTKChordBuilder chord)
Definition: ExtStreamPlayerPro.cs:194
Definition: MidiFileEditorPlayer.cs:6
Parameters
chordrequired: Tonic and Degree on top of the classical Midi parameters
Returns

◆ MPTK_PlayEvent() [1/2]

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

Play a list MIDI event from an instance of the class MPTKEvent.
Run in a thread so the call return 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);
}
bool ModifySynthParameter(fluid_gen_type genType, float value, MPTKModeGeneratorChange mode)
Definition: MPTKEventPro.cs:80
Parameters
mptkEventsList of instance of the class MPTKEvent

◆ MPTK_PlayEvent() [2/2]

void MidiPlayerTK.MidiStreamPlayer.MPTK_PlayEvent ( MPTKEvent  mptkEvent)

Play one midi event from an instance of the class MPTKEvent.
Run in a thread so the call return immediately.
See also the method MPTK_StopEvent to stop a note from an instance of MPTKEvent.

midiStreamPlayer.MPTK_PlayEvent
(
new MPTKEvent()
{
Channel = 9,
Duration = 999999,
Value = 48,
Velocity = 100
}
);
Parameters
mptkEventinstance of the class MPTKEvent

◆ MPTK_PlayPitchWheelChange()

void MidiPlayerTK.MidiStreamPlayer.MPTK_PlayPitchWheelChange ( int  channel,
float  pitchWheel 
)

[Play a Midi pitch change event for all notes on the channel.

Version
Maestro Pro
Parameters
channelChannel must be in the range 0-15
pitchWheelNormalized Pitch Wheel Value. Range 0 to 1. V2.88.2 range normalized from 0 to 1.
  • 0 minimum (equivalent to value 0 for midi standard event)
  • 0.5 centered (equivalent to value 8192 for midi standard event)
  • 1 maximum (equivalent to value 16383 for midi standard event)


◆ MPTK_PlayPitchWheelSensitivity()

void MidiPlayerTK.MidiStreamPlayer.MPTK_PlayPitchWheelSensitivity ( int  channel,
int  sensitivity 
)

Play a midi pitch sensitivity change for all notes on the channel.

Version
Maestro Pro
Parameters
channelChannel must be in the range 0-15
sensitivityPitch change sensitivity from 0 to 24 semitones up and down. Default value 2.\ Example: 4, means semitones range is from -4 to 4 when MPTK_PlayPitchWheelChange change from 0 to 1.

◆ MPTK_StartMidiStream()

void MidiPlayerTK.MidiStreamPlayer.MPTK_StartMidiStream ( )

Force starting of the MidiStream. May be useful from another gamecomponent which want send midi command at the start of the application.

// Find a MidiStreamPlayer Prefab from the scene
MidiStreamPlayer MidiStream = FindObjectOfType<MidiStreamPlayer>();
MidiStream.MPTK_StartMidiStream();
void MPTK_StartMidiStream()
Definition: MidiStreamPlayer.cs:79

◆ MPTK_StopChord()

void MidiPlayerTK.MidiStreamPlayer.MPTK_StopChord ( MPTKChordBuilder  chord)

Stop playing the chord. All samples associated to the chord are stopped by sending a noteoff.

Version
Maestro Pro
Parameters
chord

◆ MPTK_StopEvent()

void MidiPlayerTK.MidiStreamPlayer.MPTK_StopEvent ( MPTKEvent  mptkEvent)

Stop playing the note. All samples associated to the note are stopped by sending a noteoff.
Take into parameter an instance of the class MPTKEvent which is used to produced a note from MPTK_PlayEvent.

void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
// Assign our "Hello, World!"-equivalent note (using MPTKEvent's defaults plus Value = 60 for C5.
// HelperNoteLabel class could be your friend)
**mptkEvent** = new MPTKEvent() { Value = 60 };
// Start playing our "Hello, World!"-equivalent note
midiStreamPlayer.MPTK_PlayEvent(mptkEvent);
}
else if (Input.GetKeyUp(KeyCode.Space))
{
// Stop playing our "Hello, World!"-equivalent note
midiStreamPlayer.** MPTK_StopEvent** (mptkEvent);
}
}
void MPTK_StopEvent(MPTKEvent mptkEvent)
Definition: MidiStreamPlayer.cs:242
Parameters
mptkEventan instance of the class MPTKEvent which is used to produced a note from MPTK_PlayEvent

Property Documentation

◆ MPTK_Channels

MPTKChannels MidiPlayerTK.MidiStreamPlayer.MPTK_Channels
get

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);
}

◆ MPTK_ScaleName

string MidiPlayerTK.MidiStreamPlayer.MPTK_ScaleName
get

Scale Name selected (musical scale).

Version
Maestro Pro

◆ MPTK_ScaleSelected

MPTKScaleName MidiPlayerTK.MidiStreamPlayer.MPTK_ScaleSelected
getset

Current selected scale

Version
Maestro Pro