Skip to content

Commit

Permalink
Minor fixes and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Sep 21, 2023
1 parent 1610129 commit c0f38e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ or [**Apple App Store**](https://apps.apple.com/us/app/jazz-midi/id1506447231).
- MIDI files
- MPE
- SMPTE
- UMP
- UMP (MIDI 2.0)
- Additional modules

## Install
Expand Down Expand Up @@ -202,6 +202,26 @@ JZZ.MIDI.midi(450); // => 69.38905773230853
JZZ.MIDI.midi('A5'); // => 69
```

## MIDI 2.0

`MIDI2()` is a sort of adapter that enables MIDI 2.0 in all subsequent chained calls.
`MIDI1()` returns the operation back to MIDI 1.0.
Note that connected MIDI nodes don't require any actions to receive and transfer MIDI 2.0 messages:

```js
var first = JZZ.Widget();
var second = JZZ.Widget();
first.connect(second);
second.connect(function (msg) { console.log(msg.toString()); });

first
.send([0x90, 0x3c, 0x7f]) // 90 3c 7f -- Note On
.MIDI2() // enable MIDI 2.0
.send([0x20, 0x90, 0x3c, 0x7f]) // 20903c7f -- Note On
.MIDI1() // reset to MIDI 1.0
.send([0x90, 0x3c, 0x7f]) // 90 3c 7f -- Note On
```

## Additional modules
- [**JZZ-midi-SMF**](https://github.com/jazz-soft/JZZ-midi-SMF) - Standard MIDI files: read / write / play
- [**JZZ-midi-GM**](https://github.com/jazz-soft/JZZ-midi-GM) - General MIDI instrument names: MIDI to string / string to MIDI
Expand Down
13 changes: 9 additions & 4 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,15 @@
}
return this._thenable();
};
function _midi(msg) { return msg.isMidi2 ? new UMP(msg) : new MIDI(msg); }
function _midi(msg) { return msg.isMidi2 ? new UMP(msg) : MIDI.apply(null, arguments); }
_M.prototype._emit = function(msg) {
var i;
for (i = 0; i < this._handles.length; i++) this._handles[i].apply(this, [MIDI(msg)._stamp(this)]);
var i, m;
for (i = 0; i < this._handles.length; i++) {
m = _midi(msg);
this._handles[i].apply(this, [m._stamp(this)]);
}
for (i = 0; i < this._outs.length; i++) {
var m = _midi(msg);
m = _midi(msg);
if (!m._stamped(this._outs[i])) this._outs[i].send(m._stamp(this));
}
};
Expand Down Expand Up @@ -3348,6 +3351,8 @@

JZZ.UMP = UMP;
_J.prototype.UMP = UMP;
JZZ.MIDI2 = UMP;
_J.prototype.MIDI2 = UMP;

JZZ.lib = {};
JZZ.lib.now = _now;
Expand Down

0 comments on commit c0f38e5

Please sign in to comment.