Last active
August 8, 2017 20:28
-
-
Save alexeybondarenko/3af4e140a41be8ee408e90ef1ca7f8f8 to your computer and use it in GitHub Desktop.
Tutorial. How to create MIDI synthesizer with MIDI API and Node JS https://medium.com/nebo-15/tutorial-how-to-create-midi-synthesizer-with-midi-api-and-node-js-48d41c162009
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const socket = new binaryServer({ | |
port: 3001, | |
}); | |
function playTone(tone, stream) { | |
if (tone > 61 || tone < 1) { | |
console.log('undefined tone', tone); | |
return; | |
} | |
const filePath = path.resolve(__dirname, 'wav', `${tone}.wav`); | |
const file = fs.createReadStream(filePath); | |
file.pipe(stream); | |
file.on('end', () => { | |
file.unpipe(stream); | |
}); | |
return file; | |
} | |
socket.on('connection', (client) => { | |
client.on('stream', (stream, meta) => { | |
stream.on('data', (data) => { | |
console.log(data); | |
const tone = data.readInt8(1); | |
playTone(tone, stream); | |
}); | |
stream.on('end', () => { | |
console.log('end of stream'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment