Closed colinfwren closed 1 year ago
In tonejs/midi
pitch bend events are a separate array in the track, the ticks of these won't align with a specific note tick so will need to calculate if a pitch bend falls between the notes duration and then if does add the command.
Looks like the pitchbend value is between -2 and 2 based on the logic in @tonejs/midi
's addPitchBend
function:
this.addPitchBend({
ticks: event.absoluteTime,
// Scale the value between -2^13 to 2^13 to -2 to 2.
value: event.value / Math.pow(2, 13),
});
The event.value
comes from midi-file
which maps the pitch bend 7-bit value to a number between 0
and 16383
based on the MIDI spec, which uses the middle value 8192
as 0
with values below it being a negative pitch bend and those above it being a postive pitch bend.
To map this to pulse/sweep there will need to be a calculation of note duration and pitch to find the appropriate speed
Sweep seems to be the easiest option as can create a maps of bend durations to first digit and bend pitch to second digit.
Implementation logic for pitch:
const pitchVals = [0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2]
const fullPitchVals = [0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2, 0, -2, -1.8, -1.5, -1.2, -0.9, -0.6, -0.3]
const pitchBendVal = 0.015625
const mappedPitchVal = pitchVals.reduce((prev, curr) => Math.abs(curr - pitchBendVal) < Math.abs(prev - pitchBendVal) ? curr : prev)
const signedMappedPitchVal = pitchBendVal < 0 ? mappedPitchVal * -1 : mappedPitchVal
const mappedPitchValIndex = fullPitchVals.indexOf(signedMappedPitchVal)
const pitchAsHex = convertToHex(mappedPitchValIndex)
implementation for speed:
const ppq = data.header.ppq // normally 480
const noteTickLengths = [0, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625].map((duration) => ppq * duration)
const mappedNoteDuration = noteTickLengths.reduce((prev, curr) => Math.abs(curr - note.durationTicks) < Math.abs(prev - note.durationTicks) ? curr : prev)
const noteTickIndex = noteTickLengths.indexOf(mappedNoteDuration)
const speedAsHex = convertToHex((noteTickIndex + 1)* 2)
Add support for pitch-bending (
pitchBend
inmidi-file
) and map that to a either aP
orS
command (allow user to define this?)LSDJ Manual for
P
LSDJ manual for
S