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_PlayChordFromRange (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
int MPTK_ChannelBankGetIndex (int channel)
 
int MPTK_ChannelControllerGet (int channel, int controller)
 
int MPTK_ChannelCount ()
 
bool MPTK_ChannelEnableGet (int channel)
 
void MPTK_ChannelEnableSet (int channel, bool enable)
 
int MPTK_ChannelForcedPresetGet (int channel)
 
bool MPTK_ChannelForcedPresetSet (int channel, int preset, int bank=-1)
 
string MPTK_ChannelInfo (int channel)
 
int MPTK_ChannelNoteCount (int channel)
 
bool MPTK_ChannelPresetChange (int channel, int preset, int bank=-1)
 
int MPTK_ChannelPresetGetIndex (int channel)
 
string MPTK_ChannelPresetGetName (int channel)
 
float MPTK_ChannelVolumeGet (int channel)
 
void MPTK_ChannelVolumeSet (int channel, float volume)
 
void MPTK_ChorusSetDefault ()
 
void MPTK_ClearAllSound (bool destroyAudioSource=false, int _idSession=-1)
 
void MPTK_InitSynth (int channelCount=16, bool resetActiveVoices=false)
 
void MPTK_ResetStat ()
 
void MPTK_ReverbSetDefault ()
 
void MPTK_SFChorusSetDefault ()
 
void MPTK_SFFilterSetDefault ()
 
void MPTK_SFReverbSetDefault ()
 
void MPTK_StartSequencerMidi ()
 
void MPTK_StopSynth ()
 
IEnumerator MPTK_WaitAllNotesOff (int _idSession=-1)
 
delegate void OnAudioFrameStartHandler (double synthTime)
 

Properties

string MPTK_RangeName [get]
 
int MPTK_RangeSelected [get, set]
 
- Properties inherited from MidiPlayerTK.MidiSynth
bool MPTK_ApplySFChorus [get, set]
 Apply chorus effect as defined in the SoundFont.
This effect is processed with the fluidsynth algo independently on each voices but with a small decrease of performace(10%). More...
 
bool MPTK_ApplySFFilter [get, set]
 
bool MPTK_ApplySFReverb [get, set]
 Apply reverberation effect as defined in the SoundFont.
This effect is processed with the fluidsynth algo independently on each voices but with a small decrease of performace(40%). More...
 
bool MPTK_ApplyUnityChorus [get, set]
 
bool MPTK_ApplyUnityReverb [get, set]
 
float MPTK_ChorusDelay [get, set]
 
float MPTK_ChorusDepth [get, set]
 
float MPTK_ChorusDryMix [get, set]
 
float MPTK_ChorusRate [get, set]
 
float MPTK_ChorusWetMix1 [get, set]
 
float MPTK_ChorusWetMix2 [get, set]
 
float MPTK_ChorusWetMix3 [get, set]
 
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]
 
float MPTK_ReverbDecayHFRatio [get, set]
 
float MPTK_ReverbDecayTime [get, set]
 
float MPTK_ReverbDelay [get, set]
 
float MPTK_ReverbDensity [get, set]
 
float MPTK_ReverbDiffusion [get, set]
 
float MPTK_ReverbDryLevel [get, set]
 
float MPTK_ReverbHFReference [get, set]
 
float MPTK_ReverbLevel [get, set]
 
float MPTK_ReverbLFReference [get, set]
 
float MPTK_ReverbReflectionDelay [get, set]
 
float MPTK_ReverbReflectionLevel [get, set]
 
float MPTK_ReverbRoom [get, set]
 
float MPTK_ReverbRoomHF [get, set]
 
float MPTK_ReverbRoomLF [get, set]
 
float MPTK_SFChorusDepth [get, set]
 
float MPTK_SFChorusLevel [get, set]
 
float MPTK_SFChorusSpeed [get, set]
 
float MPTK_SFChorusWidth [get, set]
 
float MPTK_SFFilterQModOffset [get, set]
 
float MPTK_SFReverbDamp [get, set]
 
float MPTK_SFReverbLevel [get, set]
 
float MPTK_SFReverbRoomSize [get, set]
 
float MPTK_SFReverbWidth [get, set]
 
bool MPTK_Spatialize [get, set]
 
int MPTK_SpatialSynthIndex [get]
 
int MPTK_SynthRate [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 }
 
- 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
 
bool MPTK_EnableChangeTempo
 
bool MPTK_EnableFreeSynthRate = false
 
bool MPTK_EnablePanChange
 
bool MPTK_EnablePresetDrum
 
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_ResetChannel = true
 
float MPTK_SFChorusAmplify
 
float MPTK_SFFilterFreqOffset = 0f
 
float MPTK_SFReverbAmplify
 
bool MPTK_SpatialSynthEnabled
 
int MPTK_StatVoiceCountActive
 
int MPTK_StatVoiceCountFree
 
int MPTK_StatVoiceCountPlaying
 
int MPTK_StatVoicePlayed
 
float MPTK_StatVoiceRatioReused
 
bool MPTK_WeakDevice
 
Action< int, long, int, int > OnBeatEvent
 Action executed at each quarter with: More...
 
EventSynthClass OnEventSynthAwake
 
EventSynthClass OnEventSynthStarted
 
Func< MPTKEvent, bool > OnMidiEvent
 
bool playOnlyFirstWave
 
- Static Public Attributes inherited from MidiPlayerTK.MidiSynth
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.

A quick example:

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>();
}
void Play()
{
// Pitch wheel change integrated in the play event
midiStreamPlayer.MPTK_PlayEvent(new MPTKEvent()
{
Command = MPTKCommand.PitchWheelChange,
Value = 10000, // Value between 0 and 16383, center at 8192 (no change)
});
// Play a note
mptkEvent = new MPTKEvent()
{
Channel = 0, // Between 0 and 15
Duration = -1, // Infinite
Value = 60, // Between 0 and 127, with 60 plays a C4
Velocity = 100, // Max 127
};
midiStreamPlayer.MPTK_PlayEvent(mptkEvent);
}
// more later .... stop the note
void Stop()
{
midiStreamPlayer.MPTK_StopEvent(mptkEvent);
}
}
Description of a MIDI Event. It's the heart of MPTK! Essential to handling MIDI by script from all ot...
Definition: MPTKEvent.cs:418
Build and Play Real Time Music in relation with user actions or algorithms. This class must be used w...
Definition: MidiStreamPlayer.cs:79
void MPTK_PlayEvent(MPTKEvent mptkEvent)
Definition: MidiStreamPlayer.cs:133
void MPTK_StopEvent(MPTKEvent mptkEvent)
Definition: MidiStreamPlayer.cs:266
Definition: MidiFileEditorPlayer.cs:6
MPTKCommand
Definition: MPTKEvent.cs:12

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_PlayChordFromRange()

MPTKChordBuilder MidiPlayerTK.MidiStreamPlayer.MPTK_PlayChordFromRange ( MPTKChordBuilder  chord)

Play a chord from the current selected range (MPTK_RangeSelected), Tonic and Degree are defined in parameter MPTKChord chord.
Major range is selected if no range 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);
}
}
MPTKChordBuilder MPTK_PlayChordFromLib(MPTKChordBuilder chord)
Definition: ExtStreamPlayerPro.cs:192
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 PlayOneNote()
{
//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(NoteDuration * 1000f), // millisecond, -1 to play indefinitely
Velocity = Velocity, // Sound can vary depending on the velocity
Delay = Convert.ToInt64(NoteDelay * 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.MTPK_ModifySynthParameter((fluid_gen_type)indexGenerator[i], valueGenerator[i] / 100f, MPTKModeGeneratorChange.Override);
#endif
midiStreamPlayer.MPTK_PlayEvent(NotePlaying);
}
bool MTPK_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 semitons 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:103

◆ 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);
}
}
Parameters
mptkEventan instance of the class MPTKEvent which is used to produced a note from MPTK_PlayEvent

Property Documentation

◆ MPTK_RangeName

string MidiPlayerTK.MidiStreamPlayer.MPTK_RangeName
get

Name of range selected (musical scale).

Version
Maestro Pro

◆ MPTK_RangeSelected

int MidiPlayerTK.MidiStreamPlayer.MPTK_RangeSelected
getset

Current selected range (musical scale)

Version
Maestro Pro