Skip to content

Commit c4a18bc

Browse files
committed
add rinkterm
1 parent 35c5b24 commit c4a18bc

File tree

6 files changed

+52
-11
lines changed

6 files changed

+52
-11
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ of the rinklink bridge
1818
For staying inside the midi spec, only valid midi messages are sent.
1919
Comunication is done through `Note-on`, `Note-off` and `Poly-KeyPress` messages.
2020
Each of those messages has their very own meaning:
21-
21+
x
2222
| purpose | midi message type | raw payload | midi messge (3 bytes) |
2323
| ---------------- | ----------------- | ------------------------- | -------------------------------------- |
2424
| transfer 1 byte | `Note-on` | `0bABCDEFGH` | `0b1000xxAx` `0b0BCDEFGH` `0bxxxxxxxx` |

index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@ module.exports = class RinkLink {
55
this.input = JZZ().openMidiIn(/ice(skate|link|rink).*/gi);
66
this.output = JZZ().openMidiIn(/ice(skate|link|rink).*/gi);
77

8-
if((this.input._err || this.output._err) && !mock) {
8+
if((this.input._err.length > 0 || this.output._err > 0) && !mock) {
99
throw new Error("could not open midi device!");
1010
}
1111

1212
this.subscribers = [];
1313
this.message_buffer = [];
1414

15-
this.input.connect(this._onMidiMessage);
15+
this.input.connect(message => this._onMidiMessage(message));
1616
}
1717

1818
close() {
1919
this.input.close();
2020
this.output.close();
2121
}
2222

23-
_onMidiMessage(message) {
24-
const d = message.data;
23+
_onMidiMessage(d) {
2524
if (d[0] >> 4 == 0xA) { // end of packet
2625
this._flush_buffer();
2726
} else if (d[0] >> 4 == 0x8) { // single byte
@@ -80,9 +79,9 @@ module.exports = class RinkLink {
8079

8180
grouped_data.forEach(b => {
8281
if (typeof(b) != "number") {
83-
this.output.send(new Uint8Array([0x90 | b[0] >> 7 | (b[1] >> 7) << 1, b[0] & 0b01111111, b[1] & 0b01111111]))
82+
this.output.send(new JZZ.MIDI([0x90 | b[0] >> 7 | (b[1] >> 7) << 1, b[0] & 0b01111111, b[1] & 0b01111111]))
8483
} else {
85-
this.output.send(new Uint8Array([0x80 | b >> 7, b & 0b01111111, 0x00]))
84+
this.output.send(new JZZ.MIDI([0x80 | b >> 7, b & 0b01111111, 0x00]))
8685
}
8786
})
8887
this.output.send(new JZZ.MIDI([0xA0, 0x00, 0x00])); // flush the line

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"mocha": "^5.2.0"
2828
},
2929
"bin": {
30-
"rinkflash": "./flasher.js"
30+
"rinkflash": "./tools/flasher.js",
31+
"rinkterm": "./tools/terminal.js"
3132
}
3233
}

test/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('RinkLink', function() {
1818
if(!data.every((b, i) => b >= 0 && b <= i == 0 ? 255 : 127)) {
1919
done(new Error("value out of bounds: " + JSON.stringify(Array.from(data))))
2020
}
21-
link._onMidiMessage({data});
21+
link._onMidiMessage(data);
2222
};
2323
link.subscribe(data => {
2424
const to_compare = Array.from(test_payload).map(b => typeof(b) === "string" ? b.charCodeAt(0) : b)
@@ -36,7 +36,7 @@ describe('RinkLink', function() {
3636
const link = new RinkLink(true);
3737

3838
// loopback the output
39-
link.output.send = data => setTimeout(() => link._onMidiMessage({data}), 10);
39+
link.output.send = data => setTimeout(() => link._onMidiMessage(data), 10);
4040

4141
test_payload = 42;
4242

flasher.js tools/flasher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
const fs = require('fs');
8-
const RinkLink = require('./index');
8+
const RinkLink = require('../index');
99

1010
if (process.argv.length !== 3) {
1111
console.error("filename missing!")

tools/terminal.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/node
2+
3+
/**
4+
* A cli tool to comunicate over a line based software serial interface
5+
*/
6+
7+
const readline = require('readline');
8+
const RinkLink = require('../index');
9+
10+
11+
const rl = readline.createInterface({
12+
input: process.stdin,
13+
output: process.stdout,
14+
prompt: "> ",
15+
});
16+
17+
try {
18+
const link = new RinkLink();
19+
20+
rl.prompt();
21+
rl.on('line', l => {
22+
link.send(l);
23+
rl.prompt(true);
24+
})
25+
26+
rl.on('close', () => {
27+
rl.setPrompt('');
28+
rl.clearLine();
29+
rl.write("bye.\n");
30+
process.exit(0);
31+
});
32+
33+
link.subscribe(message => {
34+
rl.pause();
35+
rl.clearLine();
36+
rl.write(`< ${message.map(b => String.fromCharCode(b)).reduce((c, a) => c + a)}\n`);
37+
})
38+
} catch (e) {
39+
console.error(e.message);
40+
process.exit(-1);
41+
}

0 commit comments

Comments
 (0)