Nodejs MPP midi playing.

143 views
Skip to first unread message

augustbe...@gmail.com

unread,
Apr 27, 2018, 6:13:52 PM4/27/18
to Multiplayer Piano Forum
As you may know, I've been working on a nodejs midi player for MPP. Unfortunately, the midi player i programmed is pretty buggy, and i can't figure out what's wrong. Could anyone make a simple bot in nodejs that plays only one midi file? It would be easiest if you use Lamp's nodejs to MPP bot template. I already programmed a file system and some commands, i just need a better core of the midi player.
btw i'm using midi-player-js node module.
Here is my current code:
//music stuff var keys = [], keyBase = ["c", "cs", "d", "ds", "e", "f", "fs", "g", "gs", "a", "as", "b"]; var Player = new MidiPlayer.Player(function(event) { //event.noteNumber < 109 is basically asking if the note is lower than the C# right above the highest C on the piano, which seems weird to ask, because event.noteNumber <= 108 is more clear ("is the note c7 or below?" rather than "is the note below cs7?") if (event.name === "Note on" && event.noteNumber >= 21 && event.noteNumber <= 108 && event.channel !== 10) { clientList[proxynum].startNote(keys[event.noteNumber + transpose], event.velocity / 127); if (octmode >= 1){ clientList[proxynum].startNote(keys[event.noteNumber + 12 + transpose], event.velocity / 127);} if (octmode >= 2) {clientList[proxynum].startNote(keys[event.noteNumber - 12 + transpose], event.velocity / 127);} // if (octmode >= 3) {clientList[proxynum].startNote(keys[event.noteNumber + 24 + transpose], event.velocity / 127);} if (octmode >= 4) {clientList[proxynum].startNote(keys[event.noteNumber - 24 + transpose], event.velocity / 127);} for (var i = 0; i < 128; i++) keys.push(keyBase[i % 12] + (Math.floor(i / 12) - 2)); //0.0127 //console.log(clientList.length) //any MIDI velocity 79 (0x4f) or above (127 or 0x7f is the max) will play a note louder than 100% velocity on your code with that 0.0127 } if(event.name === "Set Tempo") Player.setTempo(event.data + itempo); proxynum++; if (proxynum == clientList.length) {proxynum = 0;} });


Currently it's in proxy mode, but it shouldn't matter. Any problems with the proxies would be lags.

Lamp

unread,
Apr 30, 2018, 6:59:31 PM4/30/18
to Multiplayer Piano Forum
(for convenience here is the output of the midi-player-js example: https://paste.ubuntu.com/p/WS6tdq7pPw/ )

I was thinking it would be easiest to use the event.noteName and convert it to the note names that MPP uses.
So here are the note names, in order, of MPP keys (using Object.keys(MPP.piano.keys).join(" "))
a-1 as-1 b-1 c0 cs0 d0 ds0 e0 f0 fs0 g0 gs0 a0 as0 b0 c1 cs1 d1 ds1 e1 f1 fs1 g1 gs1 a1 as1 b1 c2 cs2 d2 ds2 e2 f2 fs2 g2 gs2 a2 as2 b2 c3 cs3 d3 ds3 e3 f3 fs3 g3 gs3 a3 as3 b3 c4 cs4 d4 ds4 e4 f4 fs4 g4 gs4 a4 as4 b4 c5 cs5 d5 ds5 e5 f5 fs5 g5 gs5 a5 as5 b5 c6 cs6 d6 ds6 e6 f6 fs6 g6 gs6 a6 as6 b6 c7

And here are the corresponding key names emmitted by the player ( https://repl.it/@ledlamp89/midi-player-js-key-names )
A0 Bb0 B0 C1 Db1 D1 Eb1 E1 F1 Gb1 G1 Ab1 A1 Bb1 B1 C2 Db2 D2 Eb2 E2 F2 Gb2 G2 Ab2 A2 Bb2 B2 C3 Db3 D3 Eb3 E3 F3 Gb3 G3 Ab3 A3 Bb3 B3 C4 Db4 D4 Eb4 E4 F4 Gb4 G4 Ab4 A4 Bb4 B4 C5 Db5 D5 Eb5 E5 F5 Gb5 G5 Ab5 A5 Bb5 B5 C6 Db6 D6 Eb6 E6 F6 Gb6 G6 Ab6 A6 Bb6 B6 C7 Db7 D7 Eb7 E7 F7 Gb7 G7 Ab7 A7 Bb7 B7 C8

Unfortunately they do not correspond; it looks like all the octave numbers from the player are 1 greater than MPP's names (octaves range from 0 to 8, instead of -1 to 7)
However you could map those names to the corresponding MPP names. You could also do that with MIDI key numbers.

Ok so here is what I made: https://repl.it/@ledlamp89/mpp-midi-player
It's pretty cool but unfortunately it is also rather wonky. I think it may just be a problem with midi-player-js itself.
Reply all
Reply to author
Forward
0 new messages