[MPTK PRO] Build and Write a MIDI file from different sources.
More...
Public Member Functions | |
MidiFileWriter2 () | |
MidiFileWriter2 (int deltaTicksPerQuarterNote, int midiFileType) | |
void | MPTK_AddBPMChange (int track, long absoluteTime, int bpm) |
void | MPTK_AddChangePreset (int track, long absoluteTime, int channel, int preset) |
void | MPTK_AddChangePresetMilli (int track, float timeToPlay, int channel, int preset) |
void | MPTK_AddChannelAfterTouch (int track, long absoluteTime, int channel, int afterTouchPressure) |
void | MPTK_AddChannelAfterTouchMilli (int track, float timeToPlay, int channel, int afterTouchPressure) |
void | MPTK_AddChordFromLib (int track, long absoluteTime, int channel, MPTKChordName chordName, MPTKChordBuilder chord) |
void | MPTK_AddChordFromRange (int track, long absoluteTime, int channel, MPTKRangeLib range, MPTKChordBuilder chord) |
void | MPTK_AddControlChange (int track, long absoluteTime, int channel, MPTKController controller, int controllerValue) |
void | MPTK_AddControlChangeMilli (int track, float timeToPlay, int channel, MPTKController controller, int controllerValue) |
void | MPTK_AddNote (int track, long absoluteTime, int channel, int note, int velocity, int duration) |
void | MPTK_AddNoteMilli (int track, float timeToPlay, int channel, int note, int velocity, float duration) |
void | MPTK_AddOff (int track, long absoluteTime, int channel, int note) |
void | MPTK_AddOffMilli (int track, float timeToPlay, int channel, int note) |
void | MPTK_AddPitchWheelChange (int track, long absoluteTime, int channel, float pitchWheel) |
void | MPTK_AddPitchWheelChangeMilli (int track, float timeToPlay, int channel, float pitchWheel) |
void | MPTK_AddTempoChange (int track, long absoluteTime, int microsecondsPerQuarterNote) |
void | MPTK_AddText (int track, long absoluteTime, MPTKMeta typeMeta, string text) |
void | MPTK_AddTextMilli (int track, float timeToPlay, MPTKMeta typeMeta, string text) |
void | MPTK_AddTimeSignature (int track, long absoluteTime, int numerator=4, int denominator=4, int ticksInMetronomeClick=24, int no32ndNotesInQuarterNote=32) |
MidiFile | MPTK_BuildNAudioMidi () |
void | MPTK_Clear () |
long | MPTK_ConvertMilliToTick (float time) |
float | MPTK_ConvertTickToMilli (long tick) |
void | MPTK_CreateTrack (int count) |
bool | MPTK_Debug (string filename=null) |
void | MPTK_EndTrack (int trackNumber) |
bool | MPTK_LoadFromFile (string filename) |
bool | MPTK_LoadFromMidiDB (int indexMidiDb) |
bool | MPTK_LoadFromMPTK (List< TrackMidiEvent > midiEvents, int track=1) |
void | MPTK_SortEvents () |
bool | MPTK_WriteToFile (string filename) |
bool | MPTK_WriteToMidiDB (string filename) |
Static Public Member Functions | |
static int | MPTK_BPM2MPQN (int bpm) |
static int | MPTK_GetMicrosecondsPerQuaterNote (int bpm) |
static int | MPTK_MPQN2BPM (int microsecondsPerQuaterNote) |
Public Attributes | |
int | MPTK_DeltaTicksPerQuarterNote |
int | MPTK_MidiFileType |
string | MPTK_MidiName |
Properties | |
int | Bpm [get] |
int | MPTK_MicrosecondsPerQuaterNote [get] |
float | MPTK_PulseLenght [get] |
int | MPTK_TrackCount [get] |
[MPTK PRO] Build and Write a MIDI file from different sources.
See full example with these scripts:
MidiPlayerTK.MidiFileWriter2.MidiFileWriter2 | ( | ) |
Create an empty MidiFileWriter2. Set default value from the midi norm:
MidiPlayerTK.MidiFileWriter2.MidiFileWriter2 | ( | int | deltaTicksPerQuarterNote, |
int | midiFileType | ||
) |
Create a MidiFileWriter2 with specific header midi value (for advanced use)
deltaTicksPerQuarterNote | Delta Ticks Per Quarter Note |
midiFileType | type of Midi format. Must be 0 or 1 (better) |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddBPMChange | ( | int | track, |
long | absoluteTime, | ||
int | bpm | ||
) |
Add a tempo change to the midi stream. There is no channel in parameter because tempo change is apply to the whole midi.
track | Track for this event |
absoluteTime | Tick time for this event |
bpm | quarter per minute |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddChangePreset | ( | int | track, |
long | absoluteTime, | ||
int | channel, | ||
int | preset | ||
) |
Add a change preset
track | Track for this event |
absoluteTime | Tick time for this event |
channel | Channel must be in the range 0-15 |
preset | Preset (program/patch) must be in the range 0-127 |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddChangePresetMilli | ( | int | track, |
float | timeToPlay, | ||
int | channel, | ||
int | preset | ||
) |
Add a change preset
track | Track for this event |
timeToPlay | time in millisecond to play the note from the start of the Midi |
channel | Channel must be in the range 0-15 |
preset | Preset (program/patch) must be in the range 0-127 |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddChannelAfterTouch | ( | int | track, |
long | absoluteTime, | ||
int | channel, | ||
int | afterTouchPressure | ||
) |
Add a Channel After-Touch Event
track | Track for this event |
absoluteTime | Tick time for this event |
channel | Channel must be in the range 0-15 |
afterTouchPressure | After-touch pressure from 0 to 127 |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddChannelAfterTouchMilli | ( | int | track, |
float | timeToPlay, | ||
int | channel, | ||
int | afterTouchPressure | ||
) |
Add a Channel After-Touch Event
track | Track for this event |
timeToPlay | time in millisecond to play the note from the start of the Midi |
channel | Channel must be in the range 0-15 |
afterTouchPressure | After-touch pressure from 0 to 127 |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddChordFromLib | ( | int | track, |
long | absoluteTime, | ||
int | channel, | ||
MPTKChordName | chordName, | ||
MPTKChordBuilder | chord | ||
) |
Add a chord from a library of chord
track | |
absoluteTime | |
channel | |
chordName | Name of the chord See MPTKChordName |
chord | See MPTKChordBuilder |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddChordFromRange | ( | int | track, |
long | absoluteTime, | ||
int | channel, | ||
MPTKRangeLib | range, | ||
MPTKChordBuilder | chord | ||
) |
Add a chord from a range
track | |
absoluteTime | |
channel | |
range | See MPTKRangeLib |
chord | See MPTKChordBuilder |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddControlChange | ( | int | track, |
long | absoluteTime, | ||
int | channel, | ||
MPTKController | controller, | ||
int | controllerValue | ||
) |
Creates a general control change event (CC)
track | Track for this event |
absoluteTime | Tick time for this event |
channel | Channel must be in the range 0-15 |
controller | The MIDI Controller. See MPTKController |
controllerValue | Controller value |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddControlChangeMilli | ( | int | track, |
float | timeToPlay, | ||
int | channel, | ||
MPTKController | controller, | ||
int | controllerValue | ||
) |
Creates a control change event
track | Track for this event |
timeToPlay | time in millisecond to play the note from the start of the Midi |
channel | Channel must be in the range 0-15 |
controller | The MIDI Controller. See MPTKController |
controllerValue | Controller value |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddNote | ( | int | track, |
long | absoluteTime, | ||
int | channel, | ||
int | note, | ||
int | velocity, | ||
int | duration | ||
) |
Add a note on event at an absolute time (tick count). The corresponding Noteoff is automatically created if duration > 0
track | Track for this event |
absoluteTime | Tick time for this event |
channel | Channel must be in the range 0-15 |
note | Note must be in the range 0-127 |
velocity | Velocity must be in the range 0-127. |
duration | Tick duration. No noteoff is added if duration is <= 0, need to be added with MPTK_AddOff |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddNoteMilli | ( | int | track, |
float | timeToPlay, | ||
int | channel, | ||
int | note, | ||
int | velocity, | ||
float | duration | ||
) |
Add a note on event at a specific time in millisecond The corresponding Noteoff is automatically created if duration > 0
track | Track for this event |
timeToPlay | time in millisecond to play the note from the start of the Midi |
channel | Channel must be in the range 0-15 |
note | Note must be in the range 0-127 |
velocity | Velocity must be in the range 0-127. |
duration | Duration in millisecond. No noteoff is added if duration is <= 0, need to be added with MPTK_AddOffMilli |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddOff | ( | int | track, |
long | absoluteTime, | ||
int | channel, | ||
int | note | ||
) |
Add a note off event.
track | Track for this event |
absoluteTime | Tick time for this event |
channel | Channel must be in the range 0-15 |
note | Note must be in the range 0-127 |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddOffMilli | ( | int | track, |
float | timeToPlay, | ||
int | channel, | ||
int | note | ||
) |
Add a note off event at a specific time in millisecond The corresponding Noteoff is automatically created if duration > 0
track | Track for this event |
timeToPlay | time in millisecond to play the note from the start of the Midi |
channel | Channel must be in the range 0-15 |
note | Note must be in the range 0-127 |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddPitchWheelChange | ( | int | track, |
long | absoluteTime, | ||
int | channel, | ||
float | pitchWheel | ||
) |
Creates a control change event (CC) for the pitch (Pitch Wheel)
pitchWheel=
track | Track for this event |
absoluteTime | Tick time for this event |
channel | Channel must be in the range 0-15 |
pitchWheel | Normalized Pitch Wheel Value. Range 0 to 1. V2.88.2 range normalized from 0 to 1. |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddPitchWheelChangeMilli | ( | int | track, |
float | timeToPlay, | ||
int | channel, | ||
float | pitchWheel | ||
) |
Creates a control change event (CC) for the pitch (Pitch Wheel)
track | Track for this event |
timeToPlay | time in millisecond to play the note from the start of the Midi |
channel | Channel must be in the range 0-15 |
pitchWheel | Pitch Wheel Value. 1:normal value, 0:pitch mini, 2:pitch max |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddTempoChange | ( | int | track, |
long | absoluteTime, | ||
int | microsecondsPerQuarterNote | ||
) |
Add a tempo change to the midi stream in microseconds per quarter note. There is no channel in parameter because tempo change apply to the whole midi.
track | Track for this event |
absoluteTime | Tick time for this event |
microsecondsPerQuarterNote | Microseconds per quarter note |
void MidiPlayerTK.MidiFileWriter2.MPTK_AddText | ( | int | track, |
long | absoluteTime, | ||
MPTKMeta | typeMeta, | ||
string | text | ||
) |
Create a new TimeSignatureEvent. This event is optionnal. Midi sequencer assumes the default value is 4,4,24,32. No track nor channel as teampo change applied to the whole midi.
track | Track for this event | ||
absoluteTime | Absolute time of this event | ||
typeMeta | MetaEvent type (must be one that is
|
void MidiPlayerTK.MidiFileWriter2.MPTK_AddTextMilli | ( | int | track, |
float | timeToPlay, | ||
MPTKMeta | typeMeta, | ||
string | text | ||
) |
Create a new TimeSignatureEvent. This event is optionnal. Midi sequencer assumes the default value is 4,4,24,32. No track nor channel as teampo change applied to the whole midi.
track | Track for this event | ||
timeToPlay | time in millisecond to play the note from the start of the Midi | ||
typeMeta | MetaEvent type (must be one that is
|
void MidiPlayerTK.MidiFileWriter2.MPTK_AddTimeSignature | ( | int | track, |
long | absoluteTime, | ||
int | numerator = 4 , |
||
int | denominator = 4 , |
||
int | ticksInMetronomeClick = 24 , |
||
int | no32ndNotesInQuarterNote = 32 |
||
) |
Create a new TimeSignatureEvent. This event is optionnal. Internal Midi sequencer assumes the default value is 4,4,24,32. No track nor channel as teampo change applied to the whole midi.
track | Track for this event |
absoluteTime | Time at which to create this event |
numerator | Numerator |
denominator | Denominator |
ticksInMetronomeClick | Ticks in Metronome Click. Set to 24 for a standard value. |
no32ndNotesInQuarterNote | No of 32nd Notes in Quarter Click. Set to 32 for a standard value. |
More info here https://paxstellar.fr/2020/09/11/midi-timing/
|
static |
Convert BPM to duration of a quarter in microsecond
bpm | m |
MidiFile MidiPlayerTK.MidiFileWriter2.MPTK_BuildNAudioMidi | ( | ) |
Build a NAudio midi object from the midi events
void MidiPlayerTK.MidiFileWriter2.MPTK_Clear | ( | ) |
Remove all midi events
long MidiPlayerTK.MidiFileWriter2.MPTK_ConvertMilliToTick | ( | float | time | ) |
Convert a real time duration in millisecond to a number of tick regarding the current tempo.
time | duration in milliseconds |
float MidiPlayerTK.MidiFileWriter2.MPTK_ConvertTickToMilli | ( | long | tick | ) |
Convert the tick duration to a real time duration in millisecond regarding the current tempo.
tick | duration in ticks |
void MidiPlayerTK.MidiFileWriter2.MPTK_CreateTrack | ( | int | count | ) |
DEPRECATED Create more tracks in the stream (one default track is created at init).
From version 2.88 tracks will be created automatically when writing Midi to a file. See MPTK_WriteToFile.
count | number of tracks to create |
bool MidiPlayerTK.MidiFileWriter2.MPTK_Debug | ( | string | filename = null | ) |
Write Midi file to an OS folder
filename | filename of the midi file |
void MidiPlayerTK.MidiFileWriter2.MPTK_EndTrack | ( | int | trackNumber | ) |
DEPRECATED Close the track (mandatory for a well formed midi file). From version 2.88 tracks will be ended automatically when writing Midi to a file. See MPTK_WriteToFile.
trackNumber | Track number to close |
|
static |
DEPRECATED - use MPTK_BPM2MPQN in place - Convert BPM to duration of a quarter in microsecond
bpm | m |
bool MidiPlayerTK.MidiFileWriter2.MPTK_LoadFromFile | ( | string | filename | ) |
Load a Midi file from OS system file (could be dependant of the OS)
filename |
bool MidiPlayerTK.MidiFileWriter2.MPTK_LoadFromMidiDB | ( | int | indexMidiDb | ) |
Create a MidiFileWriter2 from a Midi found in MPTK MidiDB
indexMidiDb |
bool MidiPlayerTK.MidiFileWriter2.MPTK_LoadFromMPTK | ( | List< TrackMidiEvent > | midiEvents, |
int | track = 1 |
||
) |
Create a MidiFileWriter2 from a MidiFilePlayer. A midi file must be loaded before from a MidiFilePlayer gameobject (as in example) or from a call to MidiFileWriter2.MPTK_LoadFromFile(filename).
midiEvents | List of TrackMidiEvent |
track | TRack count, default 1 |
|
static |
Convert duration of a quarter in microsecond to Beats Per Minute
microsecondsPerQuaterNote |
void MidiPlayerTK.MidiFileWriter2.MPTK_SortEvents | ( | ) |
Sort the events by ascending absolute time. Typically, midi events are created ordered with increase time, but if not, this method must be called before writing to file or playing. Info: the TmidiEvents list of events will rebuild with this method.
bool MidiPlayerTK.MidiFileWriter2.MPTK_WriteToFile | ( | string | filename | ) |
Write Midi file to an OS folder
filename | filename of the midi file |
bool MidiPlayerTK.MidiFileWriter2.MPTK_WriteToMidiDB | ( | string | filename | ) |
Write Midi file to MidiDB. To be used only in edit mode not in a standalone application.
filename | filename of the midi file without any folder and any extension |
int MidiPlayerTK.MidiFileWriter2.MPTK_DeltaTicksPerQuarterNote |
From Midi Header: Delta Ticks Per Quarter Note. Represent the duration time in "ticks" which make up a quarter-note. For instance, if 96, then a duration of an eighth-note in the file would be 48.
int MidiPlayerTK.MidiFileWriter2.MPTK_MidiFileType |
Get the midi file type of the loaded midi (0,1,2)
string MidiPlayerTK.MidiFileWriter2.MPTK_MidiName |
Name of this midi stream
|
get |
Get current Beats Per Minute https://en.wikipedia.org/wiki/Tempo
|
get |
Get current Microseconds Per Quater Note https://en.wikipedia.org/wiki/Tempo The tempo is given in micro seconds per quarter beat. To convert this to BPM use method MPTK_MPQN2BPM This value can change during the playing when a change tempo event is defined. See here for more information https://paxstellar.fr/2020/09/11/midi-timing/
|
get |
Lenght in millisecond of a tick. Obviously depends on the current tempo and the ticks per quarter.
|
get |
Get the count of track. Track management is done automatically, they are created and ended as required. The count of tracks is limited to 64.