Browse Source

add mididump.js for midi debug stuff

master
noerw 1 year ago
parent
commit
a2d27260a9
2 changed files with 60 additions and 1 deletions
  1. 58
    0
      mididump.js
  2. 2
    1
      package.json

+ 58
- 0
mididump.js View File

@@ -0,0 +1,58 @@
1
+#! /usr/bin/env node
2
+
3
+'use strict';
4
+
5
+var program   = require('commander'),
6
+    midi      = require('midi'),
7
+    WebSocket = require('ws'),
8
+    WebSocketServer = WebSocket.Server;
9
+
10
+// Define version/args
11
+program
12
+    .version('0.4.0')
13
+    .option('-i, --input <n>',  'MIDI input number  - act as server', parseInt)
14
+    .parse(process.argv);
15
+
16
+// Initialize MIDI IN/OUT
17
+var input  = new midi.input(), output = new midi.output();
18
+
19
+// List MIDI ports
20
+if (!program.input) {
21
+    program.outputHelp();
22
+
23
+    console.log("\n  MIDI IN ports:\n");
24
+    for (var p = 0; p < input.getPortCount(); p++) {
25
+        console.log(p + " -", input.getPortName(p));
26
+    }
27
+    console.log("\n  MIDI OUT ports:\n");
28
+    for (var p = 0; p < output.getPortCount(); p++) {
29
+        console.log(p + " -", output.getPortName(p));
30
+    }
31
+    process.exit(0);
32
+}
33
+
34
+// if started with input param, open the MIDI-in port & start websocket server
35
+if (program.input) {
36
+    if (program.input >= 0 && program.input < input.getPortCount()) {
37
+        console.log("MIDI IN: " + input.getPortName(program.input));
38
+        input.openPort(program.input);
39
+        // don't ignore any signals. (types are: sysex, clock, active sensing)
40
+        input.ignoreTypes(false, false, false);
41
+
42
+        createServer(program.port || 1234);
43
+    } else {
44
+        console.log("Invalid input number. Use -l to list them.");
45
+        process.exit(1);
46
+    }
47
+}
48
+
49
+function createServer(port) {
50
+      input.on('message', function(deltaTime, message) {
51
+          var msg = {
52
+              midi: message,
53
+              deltaTime: deltaTime
54
+          };
55
+          console.log(msg);
56
+      });
57
+}
58
+

+ 2
- 1
package.json View File

@@ -5,7 +5,8 @@
5 5
   "main": "midisrv.js",
6 6
   "bin": "./midisrv.js",
7 7
   "scripts": {
8
-    "start": "node midisrv.js"
8
+    "start": "node midisrv.js",
9
+    "dump": "node mididump.js"
9 10
   },
10 11
   "repository": {
11 12
     "type": "git",

Loading…
Cancel
Save