Skip to content

Commit

Permalink
release: 0.1.6 fixing typing issue in MIDIValInput
Browse files Browse the repository at this point in the history
  • Loading branch information
kulak-at committed Feb 3, 2024
1 parent e2c5bce commit b26c5ce
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
41 changes: 12 additions & 29 deletions src/MIDIValInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<B, T> = T extends OmnibusKeys<B> ? T : never
export type ReverseParameters<T> = T extends [infer K] ? K : T
Expand Down Expand Up @@ -61,32 +62,14 @@ const DefaultOptions: MIDIValInputOptions = {

export class MIDIValInput {
private unregisterInput: UnregisterCallback;
private omnibus = this.buildBus()
private omnibus = buildInputBus()

private midiInput: IMIDIInput;

private tempoSamples: number[] = [];

private rpn: [number, number] = [-1, -1];

private buildBus() {
return Omnibus.builder()
.register('pithchBend', args<PitchBendMessage>())
.register('sysex', args<[Uint8Array]>())
.register('channelPressure', args<MidiMessage>())
.register('noteOn', args<NoteMessage>())
.register('noteOff', args<NoteMessage>())
.register('controlChange', args<ControlChangeMessage>())
.register('programChange', args<ProgramChangeMessage>())
.register('polyKeyPressure', args<MidiMessage>())
.register('clockPulse', args<void>())
.register('clockStart', args<void>())
.register('clockStop', args<void>())
.register('clockContinue', args<void>())
.register('registeredParameterData', args<RegisteredParameterData>())
.build()
}

constructor(
input: IMIDIInput,
private readonly options: MIDIValInputOptions = DefaultOptions
Expand Down Expand Up @@ -292,7 +275,7 @@ export class MIDIValInput {
}
}

private onBusKeyValue<K extends OmnibusKeys<typeof this.omnibus>, V extends keyof OmnibusValue<typeof this.omnibus, K>>(
private onBusKeyValue<K extends MIDIValInputBusKeys, V extends keyof MIDIValInputBusValue<K>>(
event: K,
key: V,
value: OmnibusValue<typeof this.omnibus, K>[V],
Expand Down Expand Up @@ -380,7 +363,7 @@ export class MIDIValInput {
* @returns Unregister callback.
*/
onPitchBend(
callback: CallbackType<OmnibusParams<typeof this.omnibus, 'pithchBend'>>
callback: CallbackType<MIDIValInputBusParams<'pithchBend'>>
): UnregisterCallback {
return this.omnibus.on('pithchBend', callback);
}
Expand Down Expand Up @@ -544,7 +527,7 @@ export class MIDIValInput {
}

onChannelPressure(
callback: CallbackType<OmnibusParams<typeof this.omnibus, "channelPressure">>
callback: CallbackType<MIDIValInputBusParams<"channelPressure">>
) {
return this.omnibus.on("channelPressure", callback);
}
Expand Down Expand Up @@ -603,7 +586,7 @@ export class MIDIValInput {

// RPN
onMpeConfiguration(
callback: CallbackType<OmnibusParams<typeof this.omnibus, "registeredParameterData">>
callback: CallbackType<MIDIValInputBusParams<"registeredParameterData">>
) {
return this.onBusKeyValue(
"registeredParameterData",
Expand All @@ -614,7 +597,7 @@ export class MIDIValInput {
}

onPitchBendSensitivity(
callback: CallbackType<OmnibusParams<typeof this.omnibus, "registeredParameterData">>
callback: CallbackType<MIDIValInputBusParams<"registeredParameterData">>
) {
return this.onBusKeyValue(
"registeredParameterData",
Expand All @@ -625,7 +608,7 @@ export class MIDIValInput {
}

onChannelFineTuning(
callback: CallbackType<OmnibusParams<typeof this.omnibus, "registeredParameterData">>
callback: CallbackType<MIDIValInputBusParams<"registeredParameterData">>
) {
return this.onBusKeyValue(
"registeredParameterData",
Expand All @@ -636,7 +619,7 @@ export class MIDIValInput {
}

onChannelCoarseTuning(
callback: CallbackType<OmnibusParams<typeof this.omnibus, "registeredParameterData">>
callback: CallbackType<MIDIValInputBusParams<"registeredParameterData">>
) {
return this.onBusKeyValue(
"registeredParameterData",
Expand All @@ -647,7 +630,7 @@ export class MIDIValInput {
}

onTuningProgramChange(
callback: CallbackType<OmnibusParams<typeof this.omnibus, "registeredParameterData">>
callback: CallbackType<MIDIValInputBusParams<"registeredParameterData">>
) {
return this.onBusKeyValue(
"registeredParameterData",
Expand All @@ -658,7 +641,7 @@ export class MIDIValInput {
}

onTuningBankChange(
callback: CallbackType<OmnibusParams<typeof this.omnibus, "registeredParameterData">>
callback: CallbackType<MIDIValInputBusParams<"registeredParameterData">>
) {
return this.onBusKeyValue(
"registeredParameterData",
Expand All @@ -669,7 +652,7 @@ export class MIDIValInput {
}

onModulationDepthChange(
callback: CallbackType<OmnibusParams<typeof this.omnibus, "registeredParameterData">>
callback: CallbackType<MIDIValInputBusParams<"registeredParameterData">>
) {
return this.onBusKeyValue(
"registeredParameterData",
Expand Down
27 changes: 27 additions & 0 deletions src/buildInputBus.ts
Original file line number Diff line number Diff line change
@@ -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<PitchBendMessage>())
.register('sysex', args<[Uint8Array]>())
.register('channelPressure', args<MidiMessage>())
.register('noteOn', args<NoteMessage>())
.register('noteOff', args<NoteMessage>())
.register('controlChange', args<ControlChangeMessage>())
.register('programChange', args<ProgramChangeMessage>())
.register('polyKeyPressure', args<MidiMessage>())
.register('clockPulse', args<void>())
.register('clockStart', args<void>())
.register('clockStop', args<void>())
.register('clockContinue', args<void>())
.register('registeredParameterData', args<RegisteredParameterData>())
.build()
}

export type MIDIValInputBusKeys = OmnibusKeys<ReturnType<typeof buildInputBus>>
export type MIDIValInputBusValue<T extends MIDIValInputBusKeys> = OmnibusValue<ReturnType<typeof buildInputBus>, T>
export type MIDIValInputBusParams<T extends MIDIValInputBusKeys> = OmnibusParams<ReturnType<typeof buildInputBus>, T>

0 comments on commit b26c5ce

Please # to comment.