Spaces:
Running
Running
File size: 1,140 Bytes
f23825d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
// abstraction layer for pitch-bend and controller events
import { controllerMidiEvent, pitchBendMidiEvent } from "../midi/MidiEvent"
import { isControllerEventWithType, isPitchBendEvent } from "../track"
export type ValueEventType =
| { type: "pitchBend" }
| { type: "controller"; controllerType: number }
export const createValueEvent = (t: ValueEventType) => (value: number) => {
switch (t.type) {
case "pitchBend":
return pitchBendMidiEvent(0, 0, Math.round(value))
case "controller":
return controllerMidiEvent(0, 0, t.controllerType, Math.round(value))
}
}
export const isValueEvent = (t: ValueEventType) => {
switch (t.type) {
case "pitchBend":
return isPitchBendEvent
case "controller":
return isControllerEventWithType(t.controllerType)
}
}
export const isEqualValueEventType = (
item: ValueEventType,
other: ValueEventType,
): boolean => {
switch (item.type) {
case "pitchBend":
return other.type === "pitchBend"
case "controller":
return (
other.type === "controller" &&
item.controllerType === other.controllerType
)
}
}
|