http://nodebox.net/code/index.php/OSC
The Osc code from the stock market music project https://reactivemusic.net/?p=12029 is not really doing Osc.
But… it works well going from php->max. In the other direction its using a kluge of nc and an alarm clock shell program – to receive messages from Max in UDP, but its really kind of horrible – so I’m going to look again for an OSC library in php.
update 2/2013 This is hard to believe, but I haven’t yet found a real OSC libraries for php. Apparently php is so uncool, that nobody wants to write for it anymore. Anyway, the code above, works unidirectionally, so its of some use for existing php code.
Local files are max-php-osc-tester.maxpat and max-osc-play.php in tkzic/api
Analysis that might help with parsing:
from Captain Caveman
http://forum.cockos.com/showthread.php?t=99076
Using node.js
Time compressed video of Irish railway data from November 30th 2012.
After many years…. I was able to get this running
Also using sample webSockets code from here to handle the map points: https://masteringjs.io/tutorials/node/websockets
I would like to update all of this in node for max – but its also nice to have an example of doing OSC communication with Max the old way.
This map is centered on Dublin. Each train is a different color and the train number gets printed next to the current position. So for example you can see P607 coming into Dublin from the South.
It gets updates every 10 seconds or so – but sometimes the trains seem to ‘jump’ so I don’t think the actual data itself gets updated that fast.
https://github.com/tkzic/internet-sensors
folder: trains
Install node.js on your computer (or a separate server). Instructions here: http://nodejs.org
In a terminal window go to the project folder ie., /internetsensors/trains
type: npm init
(just accept all the default values)
The following node packages are required. Install using npm. For example:
type: npm install request
Do the same with all these packages
These instructions are a bit confusing. A simpler UI is in the works. (that’s funny – I said it 8 years ago)
node ./max-train1.js
When you connect to the node server in a web browser, for example using the following url:
http://localhost:8124
You will get a message welcoming you and asking you to enter your name. After you enter your name, Max will send you a response. Then you can enter map points using the following format:
Dublin 53.15 -6.90
The map point will be drawn on the map in the Max patch.
Data communication is done with OSC messages. Here’s how
Here’s what the raw data looks like:
Note: if there’s no data at this link, check the time of day. Trains stop running around midnight UTC.
Essentially what this program does is collect current train position data from Ireland and display it as points on an XY grid.
components:
The server is written in node.js. This was my first real project using node. So I tried to make it do a bunch of things, just to test them out.The necessary features are
This is probably the most confusing part about this program. You can run it on the Mac in localhost mode, or you can run the node.js program on a separate server, as long as there is a direct ip path back to the computer where Max is running. Running a separate server makes more sense if you are using the chat or a remote web control aspect of this. I have run the node program on a Ubuntu server on my local network without making any changes other than to the IP addresses as explained next.
You need to make 2 changes to go from localhost mode, to separate server mode:
In the client program, max.html – near the top, change the ip address from localhost to the specific ip like this:
// note: if you want to run this program on something other than localhost, then put in the ip // address of the server here, instead of local host... // var socket = io.connect('http://localhost:8124'); // var socket = io.connect(192.168.1.10:8124');
In the server program, max-train1.js – change the destination address for UDP to the address of the computer where max is running:
var dSendAddress = '127.0.0.1'; // send response messages to max at this address // do this if max is running somewhere other than the same computer as the node server // var dSendAddress = '192.168.1.104'; // send response messages to max at this address
Also in the Max patch max-train3.maxpat you will need to change the [udpsend] object to give it the host address of the node server.
train-drawing4.maxpat
Data recorder:
To be able to save and replay data I included a data recorder in the patch. Its a revision of the data recorder from CNMAT by Michael Z. This version
The actual code for the patch is horrendous. Its filled with debugging objects and is a maze of patch cords lacking explanation. But it works…
A variation on the Midi synthesizer from this post: https://reactivemusic.net/?p=4960
The synthesizer was built in PureData (Pd extended) using the visual interface on a MacBook. Then the pd file was run in command line mode on the r-pi. The sound card is a Griffin i-Mic, running at 22.5 Khz sample rate. Although there’s no reason why you couldn’t use the builtin DAC on the r-pi.
The r-pi is connected via the ethernet port to a wi-fi network which receives Osc (Open Sound Control) messages from an iPod running touch-Osc. The network connection could have been made using a USB wifi adapter.
All together the cost of this arrangement (less the iPod) would be less than $50. The software is all open source. The huge financial barriers to working with music synthesis and signal processing, that have been associated with these fields for years, simply don’t exist anymore.
Alternative ways of controlling the synth – if a wiFi router is not available, include:
Notes:
Pd file: tkzic/rpi/pd/piSynth1_OSC.pd
recieve port is 8000 – and it uses page 1 of the simple touchOSC template
pd-extended -nogui -noadc piSynth1_Osc.pd
Note: there is some special code to prevent seg faults when you go from page 2 to page 1 of the touchOSC template
Here’s a great tutorial on using OSC with Pure Data
http://en.flossmanuals.net/pure-data/network-data/osc/
This device works as a bridge to allow devices that have ethernet but not wifi, to become wifi devices.
To access the config page, hook up an ethernet cable, and goto: www.mywifiext.com
Here’s more documentation:
http://kb.netgear.com/app/answers/detail/a_id/14157/~/wnce2001-faqs
This device allows wifi access using the Arduino Ethernet Shield. This is currently the easiest solution for using touch-OSC.
A thought exercise – to come up with various ways of making wireless Midi systems based on projects I’ve already done.
* indicates method not tried yet.
Bi-directional communication from touchOSC to Arduino using an ethernet shield.
In this version, the Macbook is directly connected to the Arduino to provide a serial monitor for status updates.
How it works: press a toggle, or move a fader, in touchOSC – it sends a message to the Arduino which lights up, or fades, an LED – then sends back an OSC message to touchOSC to light up the toggle button. (note: local feedback should be off for the toggle button in touchOSC. This is the default)
https://github.com/tkzic/max-projects
folder: arduino-osc
***update 1/20/2016 there is a new sketch that uses the OSCuino library from CNMAT instead of ardosc. The sketches should be interchangeable. https://github.com/CNMAT/OSC . The sketch is in a folder called: OSCuino_tz and is based on work by Trippylightning at: http://trippylighting.com/teensy-arduino-ect/touchosc-and-arduino-oscuino/
Copy the OSC_ethernet_test1/ folder to Documents/Arduino. This puts it in the Arduino sketchbook.
The sketch uses: #include <ArdOSC.h>
Download ArdOSC from: https://github.com/recotana/ArdOSC
This post was the key to figuring out how to make this work: http://arduino.cc/forum/index.php?topic=137549.0
update 1/2016: A version of the Arduino sketch that uses a fixed IP instead of DHCP is located in the folder: OSC_ethernet_fixedIP/
The IP is set to 192.168.1.177 but you can change it to any valid address on your network.
// generic Arduino OSC program // works from Max or touchOSC // // plug LED into pin 5 (and gnd) // // requires ethernet shield // // use serial monitor to get the ip address // // use these OSC commands (will work from first page of touchOSC simple layout // // /1/fader1 // /1/toggle1 //
#include <SPI.h> #include <Ethernet.h> #include <ArdOSC.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x0B, 0xCE }; //physical mac address
OSCServer server; OSCClient client;
int serverPort = 8000; //Touch OSC Port (outgoing) int destPort = 9000; //Touch OSC Port (incoming) int ledPin = 5; int flag=0;
void setup(){
pinMode(2, OUTPUT); Serial.begin(9600); Serial.println("DNS and DHCP-based OSC server"); // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: while(true); } // print your local IP address: Serial.print("Arduino IP address: "); for (byte thisByte = 0; thisByte < 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(Ethernet.localIP()[thisByte], DEC); Serial.print("."); } Serial.println(); Serial.println();
//start the OSCserver server.begin(serverPort);
//add OSC callback function. One function is needed for every TouchOSC interface element that is to send/receive OSC commands. server.addCallback("/1/toggle1", &funcOnOff); server.addCallback("/1/fader1", &funcFader); }
void loop(){
if(server.aviableCheck()>0){ // Serial.println("alive! "); } }
//When the button on the TouchOSC inteface is pressed, a message is sent from the iDevice //to the Arduino to switch (togle) the LED on the Arduino on/off //then a messeage is sent bak from the Arduino to the iDevice to toggle the buttom on/off
void funcOnOff(OSCMessage *_mes){ float value = _mes->getArgFloat(0); //TouchOSC expects float values
//create new osc message OSCMessage newMes;
//set destination ip address & port no newMes.setAddress(_mes->getIpAddress(),destPort); newMes.beginMessage("/1/toggle1");
Serial.println(value); if(value < 1.0) { digitalWrite(ledPin, LOW); } else{ digitalWrite(ledPin, HIGH); }
newMes.addArgFloat(value);
//send osc message // // turn local feedback off on touch-osc control to test this client.send(&newMes);
}
// new callback for fader - using same comments //When the button on the TouchOSC inteface is pressed, a message is sent from the iDevice //to the Arduino to switch (togle) the LED on the Arduino on/off //then a messeage is sent bak from the Arduino to the iDevice to toggle the buttom on/off
void funcFader(OSCMessage *_mes){ float value = _mes->getArgFloat(0); //TouchOSC expects float values
//create new osc message OSCMessage newMes;
//set destination ip address & port no newMes.setAddress(_mes->getIpAddress(),destPort); newMes.beginMessage("/1/fader1");
Serial.println(value); int ledValue = value * 255.0; analogWrite(ledPin, ledValue);
newMes.addArgFloat(value);
//send osc message // // turn local feedback off on touch-osc control to test this client.send(&newMes);
}
http://hackaday.com/2011/03/31/using-touchosc-with-your-projects/
uses the p5 library in processing
http://dangerousprototypes.com/2012/01/28/processing-arduino-touchosc/
http://www.urimicrofluidics.com/index.php/arduino/56
This post was the key to making Arduino+EthernetShield work with touchOSC. Without using Processing as an intermediary. Got it working tonight and will update this post with details.
http://arduino.cc/forum/index.php?topic=137549.0
By pakspul