MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / MidiFileGenerator

Class MidiFileGenerator

packages/alphatab/src/midi/MidiFileGenerator.ts:94–2470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92 * @public
93 */
94export class MidiFileGenerator {
95 private static readonly _defaultDurationDead: number = 30;
96 private static readonly _defaultDurationPalmMute: number = 80;
97
98 private readonly _score: Score;
99 private _settings: Settings;
100 private _handler: IMidiFileHandler;
101 private _programsPerChannel: Map<number, number> = new Map<number, number>();
102
103 private _currentTime: number = 0;
104 private _calculatedBeatTimers: Set<number> = new Set<number>();
105
106 /**
107 * Gets a lookup object which can be used to quickly find beats and bars
108 * at a given midi tick position.
109 */
110 public readonly tickLookup: MidiTickLookup = new MidiTickLookup();
111
112 /**
113 * Gets or sets whether transposition pitches should be applied to the individual midi events or not.
114 */
115 public applyTranspositionPitches: boolean = true;
116
117 /**
118 * The computed sync points for synchronizing the midi file with an external backing track.
119 */
120 public syncPoints: BackingTrackSyncPoint[] = [];
121
122 /**
123 * Gets the transposition pitches for the individual midi channels.
124 */
125 public readonly transpositionPitches: Map<number, number> = new Map<number, number>();
126
127 /**
128 * Initializes a new instance of the {@link MidiFileGenerator} class.
129 * @param score The score for which the midi file should be generated.
130 * @param settings The settings ot use for generation.
131 * @param handler The handler that should be used for generating midi events.
132 */
133 public constructor(score: Score, settings: Settings | null, handler: IMidiFileHandler) {
134 this._score = score;
135 this._settings = !settings ? new Settings() : settings;
136 this._handler = handler;
137 }
138
139 /**
140 * Starts the generation of the midi file.
141 */
142 public generate(): void {
143 this.transpositionPitches.clear();
144 this._calculatedBeatTimers.clear();
145 this._currentTime = 0;
146
147 // initialize tracks
148 for (const track of this._score.tracks) {
149 this._generateTrack(track);
150 }
151

Callers

nothing calls this directly

Calls 1

toTicksMethod · 0.80

Tested by

no test coverage detected