diff --git a/CHANGELOG.md b/CHANGELOG.md index 810a89f..a8396fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [0.1.6] +- Fixed typing issue in `MIDIValInput` + ## [0.1.5] - Adding `.once` method that allows to listen to an event once (as a callback or a promise) diff --git a/package.json b/package.json index 0176f39..512d4fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@midival/core", - "version": "0.1.5", + "version": "0.1.6", "main": "dist/index.js", "types": "dist/index.d.ts", "license": "MIT", diff --git a/src/MIDIValInput.ts b/src/MIDIValInput.ts index f9fffc6..903dd7a 100644 --- a/src/MIDIValInput.ts +++ b/src/MIDIValInput.ts @@ -30,6 +30,7 @@ import { toRegisteredParameterKey, } from "./utils/midiRegisteredParameters"; import { OmnibusKeys, OmnibusParams, OmnibusValue } from "./types/omnibus"; +import { MIDIValInputBusKeys, MIDIValInputBusParams, MIDIValInputBusValue, buildInputBus } from "./buildInputBus"; type OmnibusKeysCheck = T extends OmnibusKeys ? T : never export type ReverseParameters = T extends [infer K] ? K : T @@ -61,7 +62,7 @@ const DefaultOptions: MIDIValInputOptions = { export class MIDIValInput { private unregisterInput: UnregisterCallback; - private omnibus = this.buildBus() + private omnibus = buildInputBus() private midiInput: IMIDIInput; @@ -69,24 +70,6 @@ export class MIDIValInput { private rpn: [number, number] = [-1, -1]; - private buildBus() { - return Omnibus.builder() - .register('pithchBend', args()) - .register('sysex', args<[Uint8Array]>()) - .register('channelPressure', args()) - .register('noteOn', args()) - .register('noteOff', args()) - .register('controlChange', args()) - .register('programChange', args()) - .register('polyKeyPressure', args()) - .register('clockPulse', args()) - .register('clockStart', args()) - .register('clockStop', args()) - .register('clockContinue', args()) - .register('registeredParameterData', args()) - .build() - } - constructor( input: IMIDIInput, private readonly options: MIDIValInputOptions = DefaultOptions @@ -292,7 +275,7 @@ export class MIDIValInput { } } - private onBusKeyValue, V extends keyof OmnibusValue>( + private onBusKeyValue>( event: K, key: V, value: OmnibusValue[V], @@ -380,7 +363,7 @@ export class MIDIValInput { * @returns Unregister callback. */ onPitchBend( - callback: CallbackType> + callback: CallbackType> ): UnregisterCallback { return this.omnibus.on('pithchBend', callback); } @@ -544,7 +527,7 @@ export class MIDIValInput { } onChannelPressure( - callback: CallbackType> + callback: CallbackType> ) { return this.omnibus.on("channelPressure", callback); } @@ -603,7 +586,7 @@ export class MIDIValInput { // RPN onMpeConfiguration( - callback: CallbackType> + callback: CallbackType> ) { return this.onBusKeyValue( "registeredParameterData", @@ -614,7 +597,7 @@ export class MIDIValInput { } onPitchBendSensitivity( - callback: CallbackType> + callback: CallbackType> ) { return this.onBusKeyValue( "registeredParameterData", @@ -625,7 +608,7 @@ export class MIDIValInput { } onChannelFineTuning( - callback: CallbackType> + callback: CallbackType> ) { return this.onBusKeyValue( "registeredParameterData", @@ -636,7 +619,7 @@ export class MIDIValInput { } onChannelCoarseTuning( - callback: CallbackType> + callback: CallbackType> ) { return this.onBusKeyValue( "registeredParameterData", @@ -647,7 +630,7 @@ export class MIDIValInput { } onTuningProgramChange( - callback: CallbackType> + callback: CallbackType> ) { return this.onBusKeyValue( "registeredParameterData", @@ -658,7 +641,7 @@ export class MIDIValInput { } onTuningBankChange( - callback: CallbackType> + callback: CallbackType> ) { return this.onBusKeyValue( "registeredParameterData", @@ -669,7 +652,7 @@ export class MIDIValInput { } onModulationDepthChange( - callback: CallbackType> + callback: CallbackType> ) { return this.onBusKeyValue( "registeredParameterData", diff --git a/src/buildInputBus.ts b/src/buildInputBus.ts new file mode 100644 index 0000000..25816a4 --- /dev/null +++ b/src/buildInputBus.ts @@ -0,0 +1,27 @@ +import { Omnibus, args } from "@hypersphere/omnibus" +import { PitchBendMessage, RegisteredParameterData } from "./MIDIValInput" +import { MidiMessage } from "./utils/MIDIMessageConvert" +import { ControlChangeMessage, NoteMessage, ProgramChangeMessage } from "./types/messages" +import { OmnibusKeys, OmnibusParams, OmnibusValue } from "./types/omnibus" + +export const buildInputBus = () => { + return Omnibus.builder() + .register('pithchBend', args()) + .register('sysex', args<[Uint8Array]>()) + .register('channelPressure', args()) + .register('noteOn', args()) + .register('noteOff', args()) + .register('controlChange', args()) + .register('programChange', args()) + .register('polyKeyPressure', args()) + .register('clockPulse', args()) + .register('clockStart', args()) + .register('clockStop', args()) + .register('clockContinue', args()) + .register('registeredParameterData', args()) + .build() +} + +export type MIDIValInputBusKeys = OmnibusKeys> +export type MIDIValInputBusValue = OmnibusValue, T> +export type MIDIValInputBusParams = OmnibusParams, T>