var midi = require('midi'), mal = require('../'), rtpmidi = require('rtpmidi'); var input = new midi.input(), output = new midi.output(); input.openVirtualPort("Test Input"); input.ignoreTypes(false, false, false); output.openVirtualPort("Test Output"); var session = rtpmidi.manager.createSession({ name: 'Network Session', port: 5006 }); session.connect({ address: '127.0.0.1', port: 5004 }); var port = new mal.VirtualPort(); // Add some inputs and outputs to our virtual port port.addInput(input); port.addInput(session); port.addOutput(output); port.addOutput(session);
// The main node definition - most things happen in here function MIDIRTPOut(n) { // Create a RED node RED.nodes.createNode(this,n); var node = this; var message = MidiMessage; // Do whatever you need to do in here - declare callbacks etc // Note: this sample doesn't do anything much - it will only send // this message once at startup... // Look at other real nodes for some better ideas of what to do.... var msg = {}; this.localsession = n.localsession; this.bonjourname = n.bonjourname; this.port = parseInt(n.port); this.topic = n.topic; msg.payload = this.localsession; // send out the message to the rest of the workspace. this.send(msg); var sessions = rtpmidi.manager.getSessions(), remoteSessions = rtpmidi.manager.getRemoteSessions(); rtpmidi.manager.on('sessionAdded', function(event) { console.log('A local session was created:' + event); }); rtpmidi.manager.on('sessionRemoved', function(event) { console.log('A local session was removed:' + event); }); console.log("Session name:" + this.localsession); var session = rtpmidi.manager.createSession({ localName: this.localsession, bonjourName: this.bonjourname, port: this.port }); // Connect to a remote session session.connect({ address: '127.0.0.1', port: this.port}); session.on('streamAdded', function(event) { console.log('The stream "' + event.stream.name + '" was added to the session "' + session.localName +'"'); }); session.on('streamRemoved', function(event) { console.log('The stream "' + event.stream.name + '" was removed from the session "' + session.localName +'"'); }); rtpmidi.manager.on('remoteSessionAdded', function(event) { console.log('A remote session was discovered'); console.log('Connecting...'); session.connect(event.remoteSession); }); rtpmidi.manager.on('remoteSessionRemoved', function(event) { console.log('A remote session disappered'); }); session.on('ready', function() { console.log("Session ready"); // Send a note setInterval(function() { session.sendMessage([0x80, 0x40]); session.sendMessage([0x90, 0x40, 0x7f]); }, 1000); }); // Route the messages session.on('message', function(deltaTime, message) { console.log('Received a message', message); var msg = {}; msg.topic = this.topic; msg.payload = message; // send out the message to the rest of the workspace. node.send(msg); console.log('Sent message', message); //var appleMidiMessage = session.parseBuffer(message); //var rtpMidiMessage = new MidiMessage().parseBuffer(message); // console.log("appleMidiMessage:" + appleMidiMessage); }); this.on("close", function() { // Called when the node is shutdown - eg on redeploy. // Allows ports to be closed, connections dropped etc. // eg: this.client.disconnect(); }); }