jdachtera / node-rtpmidi

A node js implementation of Apples Network Midi Protocol.
92 stars 17 forks source link

A little help if possible #3

Closed Isilwing closed 10 years ago

Isilwing commented 10 years ago

Hello again jdachtera,

Sorry to bother you with this off topic question but i think there is no one better than you to ask about it, if you have time ill appreciate it, if you dont i will understand it perfectly.

Im trying to make a display for the timecode but im stuck with the way to pass variables between modules in node. This is what did to your example/mtc.js, i tried moving the http server without luck, i tried using socket.io but not sure if thats the way to go, so i ended using jquery on the http side and i get a value on screen but only of when i did the request, i have to refresh the whole thing to see a change in the code as the variable is filled only when i do the http request. If you have time, can you give me a hint or example of how i can handle in this scenario the node variables in the http module, or what do you think thats the best approach to achive this? (i replaced the brackets with - - so you can read it all)

Regards and thanks

var rtpmidi = require('../index'), session = rtpmidi.manager.createSession({ localName: 'LOCAL RTPMidi Session', bonjourName: 'Midi Test', port: 5006 });

// http test

var http = require("http");

// Create a clock var mtc = new rtpmidi.MTC();

mtc.setSource(session); mtc.on('change', function() { // Log the time code HH:MM:SS:FF // console.log('Position: ' + mtc.songPosition + ' Time: ' + mtc.getSMTPEString()); console.log(mtc.getSMTPEString());

});

// Connect to a remote session session.connect({ address: '127.0.0.1', port: 5004 });

// testing with http

http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/html; charset=utf-8"}); response.write( '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' + '-head-\n -meta charset="utf-8"-\n -title-MTC display -/title-\n' + '-style type="text/css"-* {font-family:arial, sans-serif;}-/style-\n' + '-script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"--/script-\n' + '-script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"--/script-\n' + '-/head-\n-body-' + '-div style="width: 100%; height: 300px; background-color:black; color:white;"- -div style="text-align: center; padding-top: 30px;"- -h1- -p id="display"- -/p- -/h1 - -/div- -/div-\n' + '-script type="text/javascript"-\n' + 'var autorefresh=setInterval(\n' + 'function()\n' + '{\n' + '$("#display").html("'+mtc.getSMTPEString()+'");\n' + 'e.preventDefault();\n' + '},200)\n' + '-/script-\n' + '\n-/body-\n-/html-'

);

response.end(); }).listen(8888);

jdachtera commented 10 years ago

I think socket.io would be appropriate since it's probably faster than constantly asking for changes via ajax. Also as far as I know socket.io downgrades to ajax if websockets are not available. Something like this would be a good start:

http://stackoverflow.com/questions/9914816/what-is-an-example-of-the-simplest-possible-socket-io-example

I also started implementing a Websocket server for this library. You can take a look at it, too. It's located in webapi.js. But I think it's not functional at the moment.

Another thing that may be interesting for you is my new port of this library to the chrome app platform. I just published a sample app: https://github.com/jdachtera/rtpmidi-chrome

Isilwing commented 10 years ago

Thanks a lot for your advices! I make it run using socket.io as you suggested, amazing work bro! This is a new language for me and im amazed of what it can do! Thanks again for your work and advices.!