Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ export class Track {
(event) => event.type === "noteOff"
) as (MidiNoteOffEvent & WithAbsoluteTime)[];

let channelIsSet = false;

while (noteOns.length) {
const currentNote = noteOns.shift();

// Set the channel based on the note.
this.channel = currentNote.channel;
channelIsSet = true;

// Find the corresponding note off.
const offIndex = noteOffs.findIndex(
Expand Down Expand Up @@ -119,6 +122,10 @@ export class Track {
(event) => event.type === "controller"
) as (MidiControllerEvent & WithAbsoluteTime)[];
controlChanges.forEach((event) => {
if (!channelIsSet) {
this.channel = event.channel;
channelIsSet = true;
}
this.addCC({
number: event.controllerType,
ticks: event.absoluteTime,
Expand All @@ -130,6 +137,10 @@ export class Track {
(event) => event.type === "pitchBend"
) as (MidiPitchBendEvent & WithAbsoluteTime)[];
pitchBends.forEach((event) => {
if (!channelIsSet) {
this.channel = event.channel;
channelIsSet = true;
}
this.addPitchBend({
ticks: event.absoluteTime,
// Scale the value between -2^13 to 2^13 to -2 to 2.
Expand Down