Skip to content

Commit

Permalink
update ProgramChange from pc to progNum
Browse files Browse the repository at this point in the history
- add progNum keyword handler
- update midicmd handler to handle 'progNum' case
  • Loading branch information
nkymut committed Jan 21, 2025
1 parent f95eada commit a4792e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion packages/core/controls.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,6 @@ export const { midichan } = registerControl('midichan');
export const { control } = registerControl('control');
export const { ccn } = registerControl('ccn');
export const { ccv } = registerControl('ccv');
export const { pc } = registerControl('pc');
export const { sysexid } = registerControl('sysexid');
export const { sysexdata } = registerControl('sysexdata');
export const { polyTouch } = registerControl('polyTouch');
Expand Down
18 changes: 14 additions & 4 deletions packages/midi/midi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Pattern.prototype.midi = function (output) {
midicmd,
gain = 1,
velocity = 0.9,
pc,
progNum,
sysexid,
sysexdata,
} = hap.value;
Expand Down Expand Up @@ -206,11 +206,11 @@ Pattern.prototype.midi = function (output) {
});
}
// Handle program change
if (pc !== undefined) {
if (typeof pc !== 'number' || pc < 0 || pc > 127) {
if (progNum !== undefined) {
if (typeof progNum !== 'number' || progNum < 0 || progNum > 127) {
throw new Error('expected pc (program change) to be a number between 0 and 127');
}
device.sendProgramChange(pc, midichan, { time: timeOffsetString });
device.sendProgramChange(progNum, midichan, { time: timeOffsetString });
}
// Handle sysex
if (sysexid !== undefined && sysexdata !== undefined) {
Expand Down Expand Up @@ -245,6 +245,8 @@ Pattern.prototype.midi = function (output) {
const scaled = Math.round(ccv * 127);
device.sendControlChange(ccn, scaled, midichan, { time: timeOffsetString });
}

// Handle midicmd
if (hap.whole.begin + 0 === 0) {
// we need to start here because we have the timing info
device.sendStart({ time: timeOffsetString });
Expand All @@ -257,6 +259,14 @@ Pattern.prototype.midi = function (output) {
device.sendStop({ time: timeOffsetString });
} else if (['continue'].includes(midicmd)) {
device.sendContinue({ time: timeOffsetString });
} else if (Array.isArray(midicmd)) {
if (midicmd[0] === 'progNum') {
if (typeof midicmd[1] !== 'number' || midicmd[1] < 0 || midicmd[1] > 127) {
throw new Error('expected pc (program change) to be a number between 0 and 127');
} else {
device.sendProgramChange(midicmd[1], midichan, { time: timeOffsetString });
}
}
}
});
};
Expand Down

0 comments on commit a4792e2

Please sign in to comment.