Skip to content

Commit

Permalink
Version 0.0.15: Refactored to use @hypersphere/omnibus internaly.
Browse files Browse the repository at this point in the history
  • Loading branch information
kulak-at committed Feb 19, 2022
1 parent afed883 commit 3038f2f
Show file tree
Hide file tree
Showing 18 changed files with 1,042 additions and 933 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.0.15] 2022-02-19
- Migrated from custom event bus to `@hypersphere/omnibus`
- Better typings for `MidivalInput` methods
- Slight change in `MidivalInput` callback parameters: see [MIGRATION.md](./MIGRATION.md)

## [0.0.14] 2021-09-06
- Added manufacturer field in IMIDIInput and IMIDIOutput interfaces.
- Ability to listen to only specific devices (based on name / manufacturer).
Expand Down
10 changes: 10 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Migration Guide
This is migration guide explaining breaking changes between versions:

## [0.0.15]

### Method signature changes
- `onAll*` methods do not have separate key extracted as a first argument. Instead they comply with other callbacks (first parameter is always `MidiMessage` or derived interface)
- `onAllControlChange` and `onControlChange` now expose it's parameters in better form: In addition to `MidiMessage` interface they now include `control` and `value`.
- `onAllProgramChange` and `onProgramChange` now expose it's parameters in better form: In addition to `MidiMessage` interface they now include `program` and `value`.
- `onAllNoteOn`, `onAllNoteOff`, `onNoteOn` and `onNoteOff` and now expose it's parameters in better form: In addition to `MidiMessage` interface they now include `note` and `velocity`.
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ Once you obtain access to the MIDI Input you can interact with it.
You can subscribe to note on.

```javascript
input.onAllNoteOn((key, midiMessage) => {
console.log("Note On:", key, "velocity:", cmidiMessage.data2);
input.onAllNoteOn(({ note, velocity }) => {
console.log("Note On:", note, "velocity:", velocity);
});
```

You can also subscribe to a specific key:

```javascript
input.onNoteOn(60, (midiMessage) => {
console.log("C pressed with velocity", midiMessage.data2);
input.onNoteOn(60, ({ velocity }) => {
console.log("C pressed with velocity", velocity);
});
```

Expand All @@ -79,15 +79,15 @@ input.onNoteOn(60, (midiMessage) => {
You can subscribe to note off. The note off takes into account both Note Off message as well as Note On with Velocity 0.

```javascript
input.onAllNoteOff((key, midiMessage) => {
console.log("Note Off:", key);
input.onAllNoteOff(({ note }) => {
console.log("Note Off:", note);
});
```

You can also subscribe to a specific key:
```javascript
input.onNoteOff(60, (midiMessage) => {
console.log("C depressed with velocity", midiMessage.data2); // velocity should be 0.
input.onNoteOff(60, ({ velocity }) => {
console.log("C depressed with velocity", velocity); // velocity should be 0.
});
```

Expand All @@ -96,20 +96,20 @@ input.onNoteOff(60, (midiMessage) => {
To listen to Control Change (MIDI CC) messages like modulation, synth parameter change and more, you can do the following:

```javascript
input.onAllControlChange((param, midiMessage => {
console.log(`Param: ${param}, value: ${midiMessage.data2}`);
}));
input.onAllControlChange(({ control, value}) => {
console.log(`Param: ${control}, value: ${value}`);
});
```

You can also listen to the single control parameter (like Modulation wheel, Volume or Pan only). The full table with MIDI CC messages can be found in [the official MIDI CC documentation](https://www.midi.org/specifications-old/item/table-3-control-change-messages-data-bytes-2).

```javascript
input.onControlChange(7, (midiMessage) => {
console.log('Volume change to value:', midiMessage.data2));
input.onControlChange(7, ({value}) => {
console.log('Volume change to value:', value));
});

input.onControlChange(1, (midiMessage) => {
console.log('Modulation Wheel value changed to:', midiMessage.data2);
input.onControlChange(1, ({value}) => {
console.log('Modulation Wheel value changed to:', value);
})
```

Expand All @@ -118,16 +118,16 @@ input.onControlChange(1, (midiMessage) => {
You can listen to program change messages:

```javascript
input.onAllProgramChange((program, midiMessage) => {
console.log(`Program ${program} changed to: ${midiMessage.data2}`);
input.onAllProgramChange(({ program, value }) => {
console.log(`Program ${program} changed to: ${value}`);
});
```

You can also listen to a single program channel:

```javascript
input.onProgramChange(1, (midiMessage) => {
console.log(`Program 1 changed to:`, midiMessage.data2);
input.onProgramChange(1, ({value}) => {
console.log(`Program 1 changed to:`, value);
});
```

Expand All @@ -136,7 +136,7 @@ input.onProgramChange(1, (midiMessage) => {
You can listen to Poly Key Pressure:

```javascript
input.onAllPolyKeyPressure((key, midiMessage) => {});
input.onAllPolyKeyPressure((midiMessage) => {});
```

you can listen to a specific key:
Expand Down Expand Up @@ -197,6 +197,8 @@ If you want to stop listening to all the messages and unregister all callbacks s
input.disconnect();
```

## MIDI Outputs
## Changelog and migration guide

For changelog see [CHANGELOG.md](./CHANGELOG.md).

Under construction.
For migration guide see [MIGRATION.md](./MIGRATION.md).
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "@midival/core",
"version": "0.0.14",
"version": "0.0.15",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/jest": "^27.4.0",
"@types/webmidi": "^2.0.6",
"gh-pages": "^3.2.3",
"jest": "^27.1.0",
"prettier": "^2.3.2",
"ts-jest": "^27.0.5",
"typedoc": "^0.21.9",
"typescript": "^4.4.2"
"jest": "^27.5.1",
"prettier": "^2.5.1",
"ts-jest": "^27.1.3",
"typedoc": "^0.22.11",
"typescript": "^4.5.5"
},
"scripts": {
"compile": "tsc",
Expand All @@ -22,5 +22,7 @@
"docs": "typedoc",
"deploy": "gh-pages -d docs"
},
"dependencies": {}
"dependencies": {
"@hypersphere/omnibus": "^0.0.2"
}
}
20 changes: 15 additions & 5 deletions src/MIDIValInput.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ describe("MIDIValInput", () => {
expect(note65Callback).toBeCalledTimes(1);
expect(note66Callback).toBeCalledTimes(0);

expect(allCallback.mock.calls[0][1]).toEqual({
expect(allCallback.mock.calls[0][0]).toEqual({
command: MidiCommand.NoteOn,
channel: 1,
data1: 65,
data2: 128,
note: 65,
velocity: 128,
});
});

Expand All @@ -78,11 +80,13 @@ describe("MIDIValInput", () => {
expect(note20Callback).toBeCalledTimes(1);
expect(note50Callback).toBeCalledTimes(0);

expect(allCallback.mock.calls[0][1]).toEqual({
expect(allCallback.mock.calls[0][0]).toEqual({
command: MidiCommand.NoteOff,
channel: 1,
data1: 20,
data2: 0,
note: 20,
velocity: 0,
});
});

Expand All @@ -109,11 +113,13 @@ describe("MIDIValInput", () => {
expect(control20Change).toBeCalledTimes(1);
expect(control21Change).toBeCalledTimes(0);

expect(allCallback.mock.calls[0][1]).toEqual({
expect(allCallback.mock.calls[0][0]).toEqual({
command: MidiCommand.ControlChange,
channel: 1,
data1: 20,
data2: 0,
control: 20,
value: 0,
});
});

Expand All @@ -140,11 +146,13 @@ describe("MIDIValInput", () => {
expect(program20Change).toBeCalledTimes(1);
expect(program21Change).toBeCalledTimes(0);

expect(allCallback.mock.calls[0][1]).toEqual({
expect(allCallback.mock.calls[0][0]).toEqual({
command: MidiCommand.ProgramChange,
channel: 1,
data1: 20,
data2: 23,
program: 20,
value: 23,
});
});

Expand Down Expand Up @@ -183,13 +191,15 @@ describe("MIDIValInput", () => {
};
mock.sendMessage(makeMessage(msg));
expect(callback).toBeCalledTimes(1);
expect(callback).toHaveBeenLastCalledWith(true, msg);
expect(callback).toHaveBeenLastCalledWith(true, {...msg, value: 127, control: MidiControlChange.LocalControlOnOff});

let msg2 = {
channel: 1,
command: MidiCommand.ControlChange,
data1: MidiControlChange.LocalControlOnOff,
data2: 0, // OFF
control: MidiControlChange.LocalControlOnOff,
value: 0,
};
mock.sendMessage(makeMessage(msg2));
expect(callback).toBeCalledTimes(2);
Expand Down
Loading

0 comments on commit 3038f2f

Please # to comment.