![]() |
Maestro - Midi Player Tool Kit for Unity Version 2.18.2
|
Scripted MIDI authoring, editing, and export APIs (Maestro Pro). More...
Topics | |
| Initialization and Import | |
| Constructor, reset, and event-list import/merge APIs. | |
| Tempo and Time Conversion | |
| Tempo state and tick/millisecond conversion helpers. | |
| Sequence State and Event Collections | |
| Core sequence metadata and event-list accessors. | |
| Loading Existing MIDI Content | |
| Load MIDI data into the writer from file system or MidiDB. | |
| Track Statistics | |
| Build per-track counters from current event content. | |
| MIDI Event Creation API | |
| Author notes, controls, tempo/signature, and meta events. | |
| Event List Maintenance and Timing Recalculation | |
| Delete, sort, and recompute timing data for event lists. | |
| Export and Diagnostics | |
| Export to MIDI outputs and inspect writer/raw event state. | |
Classes | |
| class | MidiPlayerTK.MPTKWriter |
| Create, build, write, import, and play MIDI from script. See full examples in: More... | |
MIDI Event Creation API | |
Add musical, control, and meta events to the sequence. This section is the main authoring API for building MIDI content: notes, chords, program/controller changes, pitch wheel, tempo/signature, and text meta events. | |
| bool | MidiPlayerTK.MPTKWriter.ExtendedText [get, set] |
| If true, META text (for example lyrics) is written with UTF-8 encoding. Default is false. Standard MIDI text meta events are ASCII. With this extension, you can also store and display non-ASCII characters (Korean, Chinese, Japanese, accented Latin characters, and more). To enable reading UTF8 characters from an MPTK MIDI player, set MidiFilePlayer.MPTK_ExtendedText to true. . | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddNote (int track, long tick, int channel, int note, int velocity, int length) |
| Adds a NoteOn event at an absolute tick position. A corresponding NoteOff is generated automatically when length is greater than 0. If length is less than 0, no automatic NoteOff is created. | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddSilence (int track, long tick, int channel, int length) |
| Adds a silence placeholder. . | |
| void | MidiPlayerTK.MPTKWriter.AddChordFromScale (int track, long tick, int channel, MPTKScaleLib scale, MPTKChordBuilder chord) |
| Adds a chord built from a scale range. | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddRawEvent (MPTKEvent mptkEvent) |
| Adds an event directly from an MPTKEvent instance. . | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddOff (int track, long tick, int channel, int note) |
| Adds a note-off event. It must always follow the corresponding NoteOn, on the same channel. | |
| void | MidiPlayerTK.MPTKWriter.AddChordFromLib (int track, long tick, int channel, MPTKChordName chordName, MPTKChordBuilder chord) |
| Adds a chord from a chord library. | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddChangePreset (int track, long tick, int channel, int preset) |
| Adds a preset change. | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddChannelAfterTouch (int track, long tick, int channel, int afterTouchPressure) |
| Adds a Channel After-Touch event. | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddControlChange (int track, long tick, int channel, MPTKController controller, int controllerValue) |
| Creates a general Control Change event (CC). | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddPitchWheelChange (int track, long tick, int channel, float pitchWheel) |
| Creates a Pitch Wheel event from a normalized value. pitchWheel: | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddBPMChange (int track, long tick, int bpm) |
| Adds a tempo change to the MIDI stream. There is no channel parameter because a tempo change is applied to all tracks and channels. Subsequent duration/time conversions use the new BPM value. | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddTempoChange (int track, long tick, int microsecondsPerQuarterNote) |
| Adds a tempo change to the MIDI stream in microseconds per quarter note. There is no channel parameter because a tempo change is applied to all tracks and channels. Subsequent duration/time conversions use the new tempo value. | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddTimeSignature (int track, long tick, int numerator=4, int denominator=2, int ticksInMetronomeClick=24, int no32ndNotesInQuarterNote=32) |
| Creates a TimeSignature meta event (optional). The internal sequencer default is 4,2,24,32. No channel is required because time signature applies globally. More information: https://paxstellar.fr/2020/09/11/midi-timing/. | |
| MPTKEvent | MidiPlayerTK.MPTKWriter.AddText (int track, long tick, MPTKMeta typeMeta, string text) |
| Creates a MIDI text event. | |
Event List Maintenance and Timing Recalculation | |
Modify event collections and recompute sorted/timed state. Use these methods to delete subsets of events, apply stable sorting, and rebuild real-time/measure/beat values after content changes. | |
| void | MidiPlayerTK.MPTKWriter.CalculateTiming (bool logPerf=false, bool logDebug=false) |
| Calculates real-time position, measure, and beat for each event. | |
Export and Diagnostics | |
Export MIDI files and inspect generated output/logs. This section converts MPTK events to NAudio structures, writes files to disk or MidiDB, and provides detailed logging helpers for validation. | |
| MidiFile | MidiPlayerTK.MPTKWriter.BuildNAudioMidi () |
| Builds an NAudio MidiFile object from MPTK_MidiEvents. WriteToMidiDB and WriteToFile call this method before exporting. | |
| bool | MidiPlayerTK.MPTKWriter.LogWriter () |
| Logs writer state and MIDI events. | |
| void | MidiPlayerTK.MPTKWriter.LogTempoMap () |
| Logs information about the tempo map. | |
| void | MidiPlayerTK.MPTKWriter.LogSignMap () |
| Logs information about the signature map. | |
| void | MidiPlayerTK.MPTKWriter.LogTrackStat () |
| Logs information about track statistics. | |
| bool | MidiPlayerTK.MPTKWriter.LogRaw () |
| Logs raw NAudio MIDI events built from the current writer state. | |
Scripted MIDI authoring, editing, and export APIs (Maestro Pro).
This module covers the MPTKWriter class and its workflow-oriented API.
| MPTKEvent MidiPlayerTK.MPTKWriter.AddNote | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| int | note, | ||
| int | velocity, | ||
| int | length ) |
Adds a NoteOn event at an absolute tick position.
A corresponding NoteOff is generated automatically when length is greater than 0.
If length is less than 0, no automatic NoteOff is created.
| track | Track for this event (do not add to track 0) |
| tick | Absolute tick position 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. |
| length | Duration in ticks. If less than 0, you must add NoteOff manually with AddOff. |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddSilence | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| int | length ) |
Adds a silence placeholder.
.
| track | Track for this event (do not add to track 0) |
| tick | Tick time for this event. |
| channel | Channel must be in the range 0-15 |
| length | Duration in ticks. |
| void MidiPlayerTK.MPTKWriter.AddChordFromScale | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| MPTKScaleLib | scale, | ||
| MPTKChordBuilder | chord ) |
Adds a chord built from a scale range.
| track | Track for this event (do not add to track 0) |
| tick | Start tick for all generated notes. |
| channel | MIDI channel (0-15). |
| scale | Scale definition (see MPTKScaleLib). |
| chord | Chord builder settings (see MPTKChordBuilder). |
| void MidiPlayerTK.MPTKWriter.CalculateTiming | ( | bool | logPerf = false, |
| bool | logDebug = false ) |
Calculates real-time position, measure, and beat for each event.
| logPerf | Enable performance logging. |
| logDebug | Enable detailed debug logging. |
| MidiFile MidiPlayerTK.MPTKWriter.BuildNAudioMidi | ( | ) |
Builds an NAudio MidiFile object from MPTK_MidiEvents. WriteToMidiDB and WriteToFile call this method before exporting.
| bool MidiPlayerTK.MPTKWriter.LogWriter | ( | ) |
Logs writer state and MIDI events.
| bool MidiPlayerTK.MPTKWriter.LogRaw | ( | ) |
Logs raw NAudio MIDI events built from the current writer state.
Adds an event directly from an MPTKEvent instance.
.
The following fields must be set in the input event:
| mptkEvent | Event to add. |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddOff | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| int | note ) |
Adds a note-off event.
It must always follow the corresponding NoteOn, on the same channel.
| track | Track for this event (do not add to track 0) |
| tick | Absolute tick position for this event. |
| channel | Channel must be in the range 0-15 |
| note | Note must be in the range 0-127 |
| void MidiPlayerTK.MPTKWriter.AddChordFromLib | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| MPTKChordName | chordName, | ||
| MPTKChordBuilder | chord ) |
Adds a chord from a chord library.
| track | Track for this event (do not add to track 0) |
| tick | Start tick for all generated notes. |
| channel | MIDI channel (0-15). |
| chordName | Chord name (see MPTKChordName). |
| chord | Chord builder settings (see MPTKChordBuilder). |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddChangePreset | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| int | preset ) |
Adds a preset change.
| track | Track for this event (do not add to track 0) |
| tick | 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 |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddChannelAfterTouch | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| int | afterTouchPressure ) |
Adds a Channel After-Touch event.
| track | Track for this event (do not add to track 0) |
| tick | Tick time for this event |
| channel | Channel must be in the range 0-15 |
| afterTouchPressure | After-touch pressure from 0 to 127 |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddControlChange | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| MPTKController | controller, | ||
| int | controllerValue ) |
Creates a general Control Change event (CC).
| track | Track for this event (do not add to track 0) |
| tick | Tick time for this event |
| channel | Channel must be in the range 0-15 |
| controller | The MIDI Controller. See MPTKController |
| controllerValue | Controller value |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddPitchWheelChange | ( | int | track, |
| long | tick, | ||
| int | channel, | ||
| float | pitchWheel ) |
Creates a Pitch Wheel event from a normalized value.
pitchWheel:
| track | Track for this event (do not add to track 0) |
| tick | Tick time for this event |
| channel | Channel must be in the range 0-15 |
| pitchWheel | Normalized pitch-wheel value in range [0..1]. |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddBPMChange | ( | int | track, |
| long | tick, | ||
| int | bpm ) |
Adds a tempo change to the MIDI stream. There is no channel parameter because a tempo change is applied to all tracks and channels.
Subsequent duration/time conversions use the new BPM value.
| track | Track for this event (it is good practice to use track 0 for this event). |
| tick | Absolute tick position for this event. |
| bpm | Quarters per minute. |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddTempoChange | ( | int | track, |
| long | tick, | ||
| int | microsecondsPerQuarterNote ) |
Adds a tempo change to the MIDI stream in microseconds per quarter note.
There is no channel parameter because a tempo change is applied to all tracks and channels.
Subsequent duration/time conversions use the new tempo value.
| track | Track for this event (it is good practice to use track 0 for this event). |
| tick | Absolute tick position for this event. |
| microsecondsPerQuarterNote | Tempo in microseconds per quarter note. |
| MPTKEvent MidiPlayerTK.MPTKWriter.AddTimeSignature | ( | int | track, |
| long | tick, | ||
| int | numerator = 4, | ||
| int | denominator = 2, | ||
| int | ticksInMetronomeClick = 24, | ||
| int | no32ndNotesInQuarterNote = 32 ) |
Creates a TimeSignature meta event (optional). The internal sequencer default is 4,2,24,32. No channel is required because time signature applies globally. More information: https://paxstellar.fr/2020/09/11/midi-timing/.
| track | Track for this event (it is good practice to use track 0 for this event). |
| tick | Absolute tick position where the event is added. |
| numerator | Numerator, beats per measure. Will be MPTKSignature.NumberBeatsMeasure in MPTK_SignMap |
| denominator | Denominator, beat unit: 1 means 2, 2 means 4 (crochet), 3 means 8 (quaver), 4 means 16, ... |
| ticksInMetronomeClick | Ticks in Metronome Click. Set to 24 for a standard value. |
| no32ndNotesInQuarterNote | Number of 32nd notes per quarter note. Standard MIDI value is usually 8. |
Creates a MIDI text event.
| track | Track for this event (good practice: track 0). |
| tick | Absolute tick position of this event. |
| typeMeta | Meta-event type. |
| text | The text associated with this MIDI event. |
|
getset |
If true, META text (for example lyrics) is written with UTF-8 encoding. Default is false.
Standard MIDI text meta events are ASCII. With this extension, you can also store and display
non-ASCII characters (Korean, Chinese, Japanese, accented Latin characters, and more).
To enable reading UTF8 characters from an MPTK MIDI player, set MidiFilePlayer.MPTK_ExtendedText to true.
.