/* Remote-Lang (gedit version). 1.27.09 Joe Mariglio. Remote-interprets SC code to a language app at user-specified IP addr. Currently this is hard-coded to port 57120 (default). This allows for *2-way* remote interpreter access. Obviously, trust is an issue. LAN passwords are useful for this.*/ //run the following block on the local machine: ( var win, addr, addrbox, txtv, res, echo, port, post_win, doc, res_addr; win = JSCWindow.new("remote_lang", Rect(128,64,660,512)) // .alpha_(0.9) .front.onClose_({~res.remove;~echo.remove}); win.view.decorator_(FlowLayout(win.view.bounds)); addr = "127.0.0.1"; port = 57120; addrbox = JSCTextField(win, Rect(0,0,640,24)) .string_(addr) .action_({|field| addr = field.value}); txtv = JSCTextView(win, Rect(0,12,640,480)) // for access to skins (optional) // .background_(~skinBkColor) // .stringColor_(~skinStColor) .hasVerticalScroller_(true) .autohidesScrollers_(true) .focus(true); //.enterInterpretsSelection_(false); txtv.keyDownAction = {|view,char,modifiers,unicode,keycode| if (unicode == 5){ if(addr != "127.0.0.1", {view.selectedString.postln;}); NetAddr(addr, port).sendMsg('/interp', view.selectedString); } }; ~res = res = OSCresponder(nil, '/interp', { |t,r,m,a| ("a:"+a).postln; ("t+:"+t).postln; ("cmd:"+m[1]).postln; "result:".postln; m[1].asString.interpret.postln } ).add; post_win = JSCWindow.new("remote_post").front; ~doc = doc = JSCTextView.new(post_win, Rect(0,0,480,640)) // .onClose_({echo.remove}) ; ~echo = echo = OSCresponder(nil, '/echo', {|t,r,m,a| var post; if(m[1].asString.size > 0, { if (res_addr.isNil, {res_addr = a}); post = doc.string; if (res_addr!=a, { doc.string_(post ++ "\n" ++"*********"++ a.asString++"*********"++ "\n"++m[1].asString); res_addr = a; }, { doc.string_(post ++ "\n" ++ m[1].asString); }); }); }).add; ) //for remote host server windows (reads in from "/etc/hosts"): ( var file, lines, dict; file = FileReader.read("../../etc/hosts"); dict = Dictionary.new; lines = file[9..].collect({|x| x[0].asString.split($\t) }); lines.do{|x| dict.add(x[0]->x[1]) }; dict.keys.collect{|ip| Server.new(dict.at(ip), NetAddr(ip, 57110)).makeWindow; }; ) //run the following line on any remote machines you'd like to communicate with ~addr = NetAddr("192.168.2.2", 57120); ~res = OSCresponder(nil, '/interp',{|t,r,m,a| var post; m[1].asString.interpret.postln; defer({ Routine({ Document.allDocuments[0].string; wait(0.1); post = Document.allDocuments[0].currentString; a.sendMsg('/echo', post); Emacs.evalLispExpression( ['sclang-clear-post-buffer'].asLispString ); }).play; },0.2); }).add; ~rout = Routine({ var post; loop({ wait(5); Document.allDocuments[0].string; wait(0.1); post = Document.allDocuments[0].currentString; ~addr.sendMsg('/echo', post); Emacs.evalLispExpression(['sclang-clear-post-buffer'].asLispString) }) }).play; //formatting removed for convenience: ~addr = NetAddr("192.168.2.2", 57120); ~res = OSCresponder(nil, '/interp',{|t,r,m,a| var post; m[1].asString.interpret.postln; defer({Routine({Document.allDocuments[0].string;wait(0.1);post = Document.allDocuments[0].currentString;a.sendMsg('/echo', post);Emacs.evalLispExpression( ['sclang-clear-post-buffer'].asLispString );}).play;},0.2);}).add; ~rout = Routine({ var post; loop({wait(5); Document.allDocuments[0].string; wait(0.1); post = Document.allDocuments[0].currentString; ~addr.sendMsg('/echo', post);Emacs.evalLispExpression(['sclang-clear-post-buffer'].asLispString)})}).play;