![](/media/cache/profiles/531a7a573b64cf81c7dfbdbfe8ab8c6f.jpg.50x50_q85.jpg)
LineLedControl
Dependencies: EthernetNetIf LPD8806 mbed
Fork of OSCReceiver by
OSCReceiver.cpp@0:cbfa819100c7, 2011-01-10 (annotated)
- Committer:
- xshige
- Date:
- Mon Jan 10 04:08:25 2011 +0000
- Revision:
- 0:cbfa819100c7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xshige | 0:cbfa819100c7 | 1 | // |
xshige | 0:cbfa819100c7 | 2 | // OSC Receiver |
xshige | 0:cbfa819100c7 | 3 | // |
xshige | 0:cbfa819100c7 | 4 | // date: 2011/1/10 |
xshige | 0:cbfa819100c7 | 5 | // version: 0.7 |
xshige | 0:cbfa819100c7 | 6 | // written by: xshige |
xshige | 0:cbfa819100c7 | 7 | // |
xshige | 0:cbfa819100c7 | 8 | // please find OSC Sender program at the bottom of this file |
xshige | 0:cbfa819100c7 | 9 | // |
xshige | 0:cbfa819100c7 | 10 | /* |
xshige | 0:cbfa819100c7 | 11 | The followings are supported: |
xshige | 0:cbfa819100c7 | 12 | |
xshige | 0:cbfa819100c7 | 13 | Transport Type: |
xshige | 0:cbfa819100c7 | 14 | UDP |
xshige | 0:cbfa819100c7 | 15 | |
xshige | 0:cbfa819100c7 | 16 | Features: |
xshige | 0:cbfa819100c7 | 17 | Packet Parsing (Client) |
xshige | 0:cbfa819100c7 | 18 | Not Supported:Packet Construction (Server) |
xshige | 0:cbfa819100c7 | 19 | Bundle NOT Support |
xshige | 0:cbfa819100c7 | 20 | Timetag NOT Support |
xshige | 0:cbfa819100c7 | 21 | |
xshige | 0:cbfa819100c7 | 22 | Type Support: |
xshige | 0:cbfa819100c7 | 23 | i: int32 |
xshige | 0:cbfa819100c7 | 24 | b: blob |
xshige | 0:cbfa819100c7 | 25 | s: string |
xshige | 0:cbfa819100c7 | 26 | f: float32 |
xshige | 0:cbfa819100c7 | 27 | m: MIDI message(port id, status byte, data1, data2) // I don't know the detail |
xshige | 0:cbfa819100c7 | 28 | |
xshige | 0:cbfa819100c7 | 29 | */ |
xshige | 0:cbfa819100c7 | 30 | |
xshige | 0:cbfa819100c7 | 31 | |
xshige | 0:cbfa819100c7 | 32 | #include "mbed.h" |
xshige | 0:cbfa819100c7 | 33 | #include "EthernetNetIf.h" |
xshige | 0:cbfa819100c7 | 34 | #include "UDPSocket.h" |
xshige | 0:cbfa819100c7 | 35 | |
xshige | 0:cbfa819100c7 | 36 | //#define DHCP |
xshige | 0:cbfa819100c7 | 37 | |
xshige | 0:cbfa819100c7 | 38 | //#define INPUT_PORT 12000 |
xshige | 0:cbfa819100c7 | 39 | #define INPUT_PORT 57130 |
xshige | 0:cbfa819100c7 | 40 | |
xshige | 0:cbfa819100c7 | 41 | #ifdef DHCP |
xshige | 0:cbfa819100c7 | 42 | EthernetNetIf eth; |
xshige | 0:cbfa819100c7 | 43 | #else |
xshige | 0:cbfa819100c7 | 44 | EthernetNetIf eth( |
xshige | 0:cbfa819100c7 | 45 | IpAddr(192,168,0,25), //IP Address |
xshige | 0:cbfa819100c7 | 46 | IpAddr(255,255,255,0), //Network Mask |
xshige | 0:cbfa819100c7 | 47 | IpAddr(192,168,0,1), //Gateway |
xshige | 0:cbfa819100c7 | 48 | IpAddr(192,168,0,1) //DNS |
xshige | 0:cbfa819100c7 | 49 | ); |
xshige | 0:cbfa819100c7 | 50 | #endif |
xshige | 0:cbfa819100c7 | 51 | |
xshige | 0:cbfa819100c7 | 52 | //--- OSC related stuff --- |
xshige | 0:cbfa819100c7 | 53 | union OSCarg { |
xshige | 0:cbfa819100c7 | 54 | // char*, int and float are assumed four bytes |
xshige | 0:cbfa819100c7 | 55 | char *address; |
xshige | 0:cbfa819100c7 | 56 | char *typeTag; |
xshige | 0:cbfa819100c7 | 57 | int i; |
xshige | 0:cbfa819100c7 | 58 | float f; |
xshige | 0:cbfa819100c7 | 59 | char *s; |
xshige | 0:cbfa819100c7 | 60 | struct { |
xshige | 0:cbfa819100c7 | 61 | int len; // is "int i" |
xshige | 0:cbfa819100c7 | 62 | char *p; |
xshige | 0:cbfa819100c7 | 63 | } blob; |
xshige | 0:cbfa819100c7 | 64 | char m[4]; // for MIDI |
xshige | 0:cbfa819100c7 | 65 | char _b[4]; // endian conversion temp variable |
xshige | 0:cbfa819100c7 | 66 | }; |
xshige | 0:cbfa819100c7 | 67 | |
xshige | 0:cbfa819100c7 | 68 | void getOSCmsg(char *packet , union OSCarg *msg){ |
xshige | 0:cbfa819100c7 | 69 | // Caution: the returned result points to packet as blobs or strings (not newly allocatd) |
xshige | 0:cbfa819100c7 | 70 | char *p, *typeTag; char c; |
xshige | 0:cbfa819100c7 | 71 | |
xshige | 0:cbfa819100c7 | 72 | msg[0].address = packet; // address |
xshige | 0:cbfa819100c7 | 73 | msg[1].typeTag = packet+4*(strlen(msg[0].s)/4+1);//typeTag |
xshige | 0:cbfa819100c7 | 74 | typeTag=msg[1].s+1; // skip ',' |
xshige | 0:cbfa819100c7 | 75 | p= msg[1].s+4*(strlen(msg[1].s)/4+1); |
xshige | 0:cbfa819100c7 | 76 | for(int n=0; n<strlen(typeTag); n++){ |
xshige | 0:cbfa819100c7 | 77 | c = typeTag[n]; |
xshige | 0:cbfa819100c7 | 78 | if (('s'==c)) { |
xshige | 0:cbfa819100c7 | 79 | msg[n+2].s=p; |
xshige | 0:cbfa819100c7 | 80 | p += 4*(strlen(msg[n+2].s)/4+1); |
xshige | 0:cbfa819100c7 | 81 | } else if (('i'==c)||('f'==c)) { |
xshige | 0:cbfa819100c7 | 82 | // chang endian (big to little) |
xshige | 0:cbfa819100c7 | 83 | msg[n+2]._b[3]=p[0]; |
xshige | 0:cbfa819100c7 | 84 | msg[n+2]._b[2]=p[1]; |
xshige | 0:cbfa819100c7 | 85 | msg[n+2]._b[1]=p[2]; |
xshige | 0:cbfa819100c7 | 86 | msg[n+2]._b[0]=p[3]; |
xshige | 0:cbfa819100c7 | 87 | p +=4; |
xshige | 0:cbfa819100c7 | 88 | } else if ('b'==c) { |
xshige | 0:cbfa819100c7 | 89 | // chang endian (big to little) |
xshige | 0:cbfa819100c7 | 90 | // get lenth of blog (copy to msg[n].blog.len) |
xshige | 0:cbfa819100c7 | 91 | msg[n+2]._b[3]=p[0]; |
xshige | 0:cbfa819100c7 | 92 | msg[n+2]._b[2]=p[1]; |
xshige | 0:cbfa819100c7 | 93 | msg[n+2]._b[1]=p[2]; |
xshige | 0:cbfa819100c7 | 94 | msg[n+2]._b[0]=p[3]; |
xshige | 0:cbfa819100c7 | 95 | p +=4; |
xshige | 0:cbfa819100c7 | 96 | // get ponter of blog (copy to msg[n].blog.p) |
xshige | 0:cbfa819100c7 | 97 | msg[n+2].blob.p=p; |
xshige | 0:cbfa819100c7 | 98 | p += 4*(msg[n+2].blob.len/4+1); |
xshige | 0:cbfa819100c7 | 99 | } else if ('m'==c) { |
xshige | 0:cbfa819100c7 | 100 | // get midi data (copy to msg[n].m[]) |
xshige | 0:cbfa819100c7 | 101 | msg[n+2].m[0]=p[0]; |
xshige | 0:cbfa819100c7 | 102 | msg[n+2].m[1]=p[1]; |
xshige | 0:cbfa819100c7 | 103 | msg[n+2].m[2]=p[2]; |
xshige | 0:cbfa819100c7 | 104 | msg[n+2].m[3]=p[3]; |
xshige | 0:cbfa819100c7 | 105 | p +=4; |
xshige | 0:cbfa819100c7 | 106 | } else { |
xshige | 0:cbfa819100c7 | 107 | printf("*** Not Supported TypeTag:%s ****\n",typeTag); |
xshige | 0:cbfa819100c7 | 108 | } |
xshige | 0:cbfa819100c7 | 109 | }; |
xshige | 0:cbfa819100c7 | 110 | |
xshige | 0:cbfa819100c7 | 111 | } |
xshige | 0:cbfa819100c7 | 112 | //------------------------------------------- |
xshige | 0:cbfa819100c7 | 113 | |
xshige | 0:cbfa819100c7 | 114 | UDPSocket udp; |
xshige | 0:cbfa819100c7 | 115 | |
xshige | 0:cbfa819100c7 | 116 | |
xshige | 0:cbfa819100c7 | 117 | void onUDPSocketEvent(UDPSocketEvent e) |
xshige | 0:cbfa819100c7 | 118 | { |
xshige | 0:cbfa819100c7 | 119 | union OSCarg msg[10]; |
xshige | 0:cbfa819100c7 | 120 | |
xshige | 0:cbfa819100c7 | 121 | switch(e) |
xshige | 0:cbfa819100c7 | 122 | { |
xshige | 0:cbfa819100c7 | 123 | case UDPSOCKET_READABLE: //The only event for now |
xshige | 0:cbfa819100c7 | 124 | char buf[256] = {0}; |
xshige | 0:cbfa819100c7 | 125 | Host host; |
xshige | 0:cbfa819100c7 | 126 | while( int len = udp.recvfrom( buf, 256, &host ) ) |
xshige | 0:cbfa819100c7 | 127 | { |
xshige | 0:cbfa819100c7 | 128 | if( len <= 0 ) |
xshige | 0:cbfa819100c7 | 129 | break; |
xshige | 0:cbfa819100c7 | 130 | printf("\r\nFrom %d.%d.%d.%d:\r\n", |
xshige | 0:cbfa819100c7 | 131 | host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3]); |
xshige | 0:cbfa819100c7 | 132 | |
xshige | 0:cbfa819100c7 | 133 | getOSCmsg(buf,msg); |
xshige | 0:cbfa819100c7 | 134 | // address pattern samples |
xshige | 0:cbfa819100c7 | 135 | if (strcmp(msg[0].address,"/test")==0) { |
xshige | 0:cbfa819100c7 | 136 | printf("OSCmsg: %s %s %d %f %s %d\n", |
xshige | 0:cbfa819100c7 | 137 | msg[0].address, msg[1].typeTag,msg[2].i, msg[3].f, msg[4].s, msg[5].blob.len); |
xshige | 0:cbfa819100c7 | 138 | printf("blob content:\n"); |
xshige | 0:cbfa819100c7 | 139 | char *p=msg[5].blob.p; |
xshige | 0:cbfa819100c7 | 140 | for(int n=0; n<msg[5].blob.len; p++,n++) printf(" %02X",(unsigned char)(*p)); |
xshige | 0:cbfa819100c7 | 141 | printf("\n"); |
xshige | 0:cbfa819100c7 | 142 | break; |
xshige | 0:cbfa819100c7 | 143 | } |
xshige | 0:cbfa819100c7 | 144 | if (strcmp(msg[0].address,"/kb/m")==0) { |
xshige | 0:cbfa819100c7 | 145 | printf("OSCmsg: %s %s %d %d %d\n", |
xshige | 0:cbfa819100c7 | 146 | msg[0].address, msg[1].typeTag,msg[2].i, msg[3].i, msg[4].i); |
xshige | 0:cbfa819100c7 | 147 | break; |
xshige | 0:cbfa819100c7 | 148 | } |
xshige | 0:cbfa819100c7 | 149 | if (strcmp(msg[0].address,"/cc/m")==0) { |
xshige | 0:cbfa819100c7 | 150 | printf("OSCmsg: %s %s %d %d %d\n", |
xshige | 0:cbfa819100c7 | 151 | msg[0].address, msg[1].typeTag,msg[2].i, msg[3].i, msg[4].i); |
xshige | 0:cbfa819100c7 | 152 | break; |
xshige | 0:cbfa819100c7 | 153 | } |
xshige | 0:cbfa819100c7 | 154 | if (strcmp(msg[0].address,"/1/fader1")==0) { |
xshige | 0:cbfa819100c7 | 155 | printf("OSCmsg: %s %s %f\n", |
xshige | 0:cbfa819100c7 | 156 | msg[0].address, msg[1].typeTag,msg[2].f); |
xshige | 0:cbfa819100c7 | 157 | break; |
xshige | 0:cbfa819100c7 | 158 | } |
xshige | 0:cbfa819100c7 | 159 | if (strcmp(msg[0].address,"/1/knob1")==0) { |
xshige | 0:cbfa819100c7 | 160 | printf("OSCmsg: %s %s %f\n", |
xshige | 0:cbfa819100c7 | 161 | msg[0].address, msg[1].typeTag, msg[2].f); |
xshige | 0:cbfa819100c7 | 162 | break; |
xshige | 0:cbfa819100c7 | 163 | } |
xshige | 0:cbfa819100c7 | 164 | if (strcmp(msg[0].address,"/1/butt/A1")==0) { |
xshige | 0:cbfa819100c7 | 165 | printf("OSCmsg: %s %s %i\n", |
xshige | 0:cbfa819100c7 | 166 | msg[0].address, msg[1].typeTag, msg[2].i); |
xshige | 0:cbfa819100c7 | 167 | break; |
xshige | 0:cbfa819100c7 | 168 | } |
xshige | 0:cbfa819100c7 | 169 | if (strcmp(msg[0].address,"/1/butt/B1")==0) { |
xshige | 0:cbfa819100c7 | 170 | printf("OSCmsg: %s %s %i\n", |
xshige | 0:cbfa819100c7 | 171 | msg[0].address, msg[1].typeTag, msg[2].i); |
xshige | 0:cbfa819100c7 | 172 | break; |
xshige | 0:cbfa819100c7 | 173 | } |
xshige | 0:cbfa819100c7 | 174 | if (strcmp(msg[0].address,"/mouse/dragged")==0) { |
xshige | 0:cbfa819100c7 | 175 | printf("OSCmsg: %s %s %i %i\n", |
xshige | 0:cbfa819100c7 | 176 | msg[0].address, msg[1].typeTag, msg[2].i, msg[3].i); |
xshige | 0:cbfa819100c7 | 177 | break; |
xshige | 0:cbfa819100c7 | 178 | } |
xshige | 0:cbfa819100c7 | 179 | if (strcmp(msg[0].address,"/mouse/pressed")==0) { |
xshige | 0:cbfa819100c7 | 180 | printf("OSCmsg: %s %s %i %i\n", |
xshige | 0:cbfa819100c7 | 181 | msg[0].address, msg[1].typeTag, msg[2].i, msg[3].i); |
xshige | 0:cbfa819100c7 | 182 | break; |
xshige | 0:cbfa819100c7 | 183 | } |
xshige | 0:cbfa819100c7 | 184 | if (strcmp(msg[0].address,"/1/xy")==0) { |
xshige | 0:cbfa819100c7 | 185 | printf("OSCmsg: %s %s %f %f %d\n", |
xshige | 0:cbfa819100c7 | 186 | msg[0].address, msg[1].typeTag, msg[2].f, msg[3].f, msg[4].i); |
xshige | 0:cbfa819100c7 | 187 | break; |
xshige | 0:cbfa819100c7 | 188 | } |
xshige | 0:cbfa819100c7 | 189 | printf("undefined OSCmsg:%s %s\n",msg[0].address, msg[1].typeTag); |
xshige | 0:cbfa819100c7 | 190 | } // while |
xshige | 0:cbfa819100c7 | 191 | break; |
xshige | 0:cbfa819100c7 | 192 | } // case |
xshige | 0:cbfa819100c7 | 193 | } |
xshige | 0:cbfa819100c7 | 194 | |
xshige | 0:cbfa819100c7 | 195 | int main() { |
xshige | 0:cbfa819100c7 | 196 | // make debug port Fast |
xshige | 0:cbfa819100c7 | 197 | Serial pc(USBTX, USBRX); |
xshige | 0:cbfa819100c7 | 198 | // pc.baud(9600); |
xshige | 0:cbfa819100c7 | 199 | pc.baud(115200); |
xshige | 0:cbfa819100c7 | 200 | // pc.baud(230400); |
xshige | 0:cbfa819100c7 | 201 | |
xshige | 0:cbfa819100c7 | 202 | printf("Setting up...\r\n"); |
xshige | 0:cbfa819100c7 | 203 | EthernetErr ethErr = eth.setup(); |
xshige | 0:cbfa819100c7 | 204 | if(ethErr) |
xshige | 0:cbfa819100c7 | 205 | { |
xshige | 0:cbfa819100c7 | 206 | printf("Error %d in setup.\r\n", ethErr); |
xshige | 0:cbfa819100c7 | 207 | return -1; |
xshige | 0:cbfa819100c7 | 208 | } |
xshige | 0:cbfa819100c7 | 209 | printf("Setup OK\r\n"); |
xshige | 0:cbfa819100c7 | 210 | |
xshige | 0:cbfa819100c7 | 211 | |
xshige | 0:cbfa819100c7 | 212 | // port setup |
xshige | 0:cbfa819100c7 | 213 | Host recHost(IpAddr(192, 168, 0, 7), INPUT_PORT, NULL); |
xshige | 0:cbfa819100c7 | 214 | udp.setOnEvent(&onUDPSocketEvent); |
xshige | 0:cbfa819100c7 | 215 | udp.bind(recHost); |
xshige | 0:cbfa819100c7 | 216 | |
xshige | 0:cbfa819100c7 | 217 | Timer tmr; |
xshige | 0:cbfa819100c7 | 218 | tmr.start(); |
xshige | 0:cbfa819100c7 | 219 | while(true) |
xshige | 0:cbfa819100c7 | 220 | { |
xshige | 0:cbfa819100c7 | 221 | Net::poll(); |
xshige | 0:cbfa819100c7 | 222 | if(tmr.read() > 5) |
xshige | 0:cbfa819100c7 | 223 | { |
xshige | 0:cbfa819100c7 | 224 | tmr.reset(); |
xshige | 0:cbfa819100c7 | 225 | } |
xshige | 0:cbfa819100c7 | 226 | } |
xshige | 0:cbfa819100c7 | 227 | |
xshige | 0:cbfa819100c7 | 228 | |
xshige | 0:cbfa819100c7 | 229 | } |
xshige | 0:cbfa819100c7 | 230 | //---------------------------------------------------------------------------------------------------------- |
xshige | 0:cbfa819100c7 | 231 | /* |
xshige | 0:cbfa819100c7 | 232 | |
xshige | 0:cbfa819100c7 | 233 | // |
xshige | 0:cbfa819100c7 | 234 | // OSC mouse (OSC Sender) |
xshige | 0:cbfa819100c7 | 235 | // |
xshige | 0:cbfa819100c7 | 236 | // written in: processing(refer to: http://processing.org/) |
xshige | 0:cbfa819100c7 | 237 | // |
xshige | 0:cbfa819100c7 | 238 | // please install oscP5 lib |
xshige | 0:cbfa819100c7 | 239 | // you can download this from: http://www.sojamo.de/libraries/oscP5/ |
xshige | 0:cbfa819100c7 | 240 | |
xshige | 0:cbfa819100c7 | 241 | import oscP5.*; |
xshige | 0:cbfa819100c7 | 242 | |
xshige | 0:cbfa819100c7 | 243 | // initialise all OSC functionality |
xshige | 0:cbfa819100c7 | 244 | void initOsc() { |
xshige | 0:cbfa819100c7 | 245 | host = "192.168.0.25"; // mbed IP address (change this to fit your mbed) |
xshige | 0:cbfa819100c7 | 246 | sendToPort = 57130; // mbed port# (chang this if you need) |
xshige | 0:cbfa819100c7 | 247 | receiveAtPort = 12000; // not used at this time |
xshige | 0:cbfa819100c7 | 248 | oscP5event = "oscEvent"; // the analyser method |
xshige | 0:cbfa819100c7 | 249 | oscP5 = new OscP5(this, host, sendToPort, receiveAtPort, oscP5event); |
xshige | 0:cbfa819100c7 | 250 | } |
xshige | 0:cbfa819100c7 | 251 | |
xshige | 0:cbfa819100c7 | 252 | // oscP5 instance for the osc communication |
xshige | 0:cbfa819100c7 | 253 | OscP5 oscP5; |
xshige | 0:cbfa819100c7 | 254 | int receiveAtPort; |
xshige | 0:cbfa819100c7 | 255 | int sendToPort; |
xshige | 0:cbfa819100c7 | 256 | String host; |
xshige | 0:cbfa819100c7 | 257 | String oscP5event; |
xshige | 0:cbfa819100c7 | 258 | |
xshige | 0:cbfa819100c7 | 259 | void setup(){ |
xshige | 0:cbfa819100c7 | 260 | background(0); |
xshige | 0:cbfa819100c7 | 261 | size(400, 400); |
xshige | 0:cbfa819100c7 | 262 | initOsc(); |
xshige | 0:cbfa819100c7 | 263 | sendTestMsg(); |
xshige | 0:cbfa819100c7 | 264 | } |
xshige | 0:cbfa819100c7 | 265 | |
xshige | 0:cbfa819100c7 | 266 | void oscEvent(OscIn oscIn) { |
xshige | 0:cbfa819100c7 | 267 | println("\n\nreceived a message ... forwarding to analyseMessage(OscIn)"); |
xshige | 0:cbfa819100c7 | 268 | analyseMessage(oscIn); |
xshige | 0:cbfa819100c7 | 269 | } |
xshige | 0:cbfa819100c7 | 270 | |
xshige | 0:cbfa819100c7 | 271 | void analyseMessage(OscIn oscIn) { |
xshige | 0:cbfa819100c7 | 272 | println("you have received an osc message "+ |
xshige | 0:cbfa819100c7 | 273 | oscIn.getAddrPatternAsBytes()+" "+oscIn.getTypetagAsBytes() |
xshige | 0:cbfa819100c7 | 274 | ); |
xshige | 0:cbfa819100c7 | 275 | byte[] o = oscIn.getBytes(); |
xshige | 0:cbfa819100c7 | 276 | for(int i=0;i<o.length;i++) { |
xshige | 0:cbfa819100c7 | 277 | if ((i%4)==0) println("\n--------------------"); |
xshige | 0:cbfa819100c7 | 278 | print(hex(o[i],2)+"("+char(o[i])+")"+":"); |
xshige | 0:cbfa819100c7 | 279 | if ((((i+1)%4)==0)&&((i+1)>=4)) { |
xshige | 0:cbfa819100c7 | 280 | int data= (0x1000000*(o[i-3]&0xFF)+ |
xshige | 0:cbfa819100c7 | 281 | 0x10000*(o[i-2]&0xFF)+ |
xshige | 0:cbfa819100c7 | 282 | 0x100*(o[i-1]&0xFF)+ |
xshige | 0:cbfa819100c7 | 283 | (o[i]&0xFF)); |
xshige | 0:cbfa819100c7 | 284 | print("\nint: "+data); |
xshige | 0:cbfa819100c7 | 285 | print("\nfloat: "+Float.intBitsToFloat(data)); |
xshige | 0:cbfa819100c7 | 286 | } |
xshige | 0:cbfa819100c7 | 287 | } |
xshige | 0:cbfa819100c7 | 288 | } |
xshige | 0:cbfa819100c7 | 289 | |
xshige | 0:cbfa819100c7 | 290 | void draw() { |
xshige | 0:cbfa819100c7 | 291 | } |
xshige | 0:cbfa819100c7 | 292 | |
xshige | 0:cbfa819100c7 | 293 | void sendTestMsg() { |
xshige | 0:cbfa819100c7 | 294 | OscMessage oscMsg= oscP5.newMsg("/test"); |
xshige | 0:cbfa819100c7 | 295 | oscMsg.add(mouseY); |
xshige | 0:cbfa819100c7 | 296 | oscMsg.add(34.55); |
xshige | 0:cbfa819100c7 | 297 | oscMsg.add("yippyy!"); |
xshige | 0:cbfa819100c7 | 298 | // add a byte blob to the osc message |
xshige | 0:cbfa819100c7 | 299 | oscMsg.add( |
xshige | 0:cbfa819100c7 | 300 | new byte[] {0x00, 0x01, 0x10, 0x20,0x30,0x40,0x50,0x60,0x7F, |
xshige | 0:cbfa819100c7 | 301 | -128,-1,(byte)0x80,(byte)0x90,(byte)0xA0,(byte)0xB0,(byte)0xC0, |
xshige | 0:cbfa819100c7 | 302 | (byte)0xD0,(byte)0xE0,(byte)0xFF}); |
xshige | 0:cbfa819100c7 | 303 | // 0x80,0x90,0xFE,0xFF etc do not work because byte is 127 thru -128. |
xshige | 0:cbfa819100c7 | 304 | // so do it like: (byte)0xFF |
xshige | 0:cbfa819100c7 | 305 | oscP5.send(oscMsg); |
xshige | 0:cbfa819100c7 | 306 | } |
xshige | 0:cbfa819100c7 | 307 | |
xshige | 0:cbfa819100c7 | 308 | void mousePressed() { |
xshige | 0:cbfa819100c7 | 309 | OscMessage oscMsg= oscP5.newMsg("/mouse/pressed"); |
xshige | 0:cbfa819100c7 | 310 | oscMsg.add(mouseX); |
xshige | 0:cbfa819100c7 | 311 | oscMsg.add(mouseY); |
xshige | 0:cbfa819100c7 | 312 | oscP5.send(oscMsg); |
xshige | 0:cbfa819100c7 | 313 | // |
xshige | 0:cbfa819100c7 | 314 | oscMsg= oscP5.newMsg("/1/xy"); |
xshige | 0:cbfa819100c7 | 315 | oscMsg.add(mouseX*1.0/width); |
xshige | 0:cbfa819100c7 | 316 | oscMsg.add(mouseY*1.0/height); |
xshige | 0:cbfa819100c7 | 317 | oscMsg.add(1);// button status:pressed |
xshige | 0:cbfa819100c7 | 318 | oscP5.send(oscMsg); |
xshige | 0:cbfa819100c7 | 319 | } |
xshige | 0:cbfa819100c7 | 320 | |
xshige | 0:cbfa819100c7 | 321 | void mouseDragged() { |
xshige | 0:cbfa819100c7 | 322 | OscMessage oscMsg= oscP5.newMsg("/mouse/dragged"); |
xshige | 0:cbfa819100c7 | 323 | oscMsg.add(mouseX); |
xshige | 0:cbfa819100c7 | 324 | oscMsg.add(mouseY); |
xshige | 0:cbfa819100c7 | 325 | oscP5.send(oscMsg); |
xshige | 0:cbfa819100c7 | 326 | // |
xshige | 0:cbfa819100c7 | 327 | oscMsg= oscP5.newMsg("/1/xy"); |
xshige | 0:cbfa819100c7 | 328 | oscMsg.add(mouseX*1.0/width); |
xshige | 0:cbfa819100c7 | 329 | oscMsg.add(mouseY*1.0/height); |
xshige | 0:cbfa819100c7 | 330 | oscMsg.add(1); // button status:pressed |
xshige | 0:cbfa819100c7 | 331 | oscP5.send(oscMsg); |
xshige | 0:cbfa819100c7 | 332 | } |
xshige | 0:cbfa819100c7 | 333 | |
xshige | 0:cbfa819100c7 | 334 | void mouseReleased() { |
xshige | 0:cbfa819100c7 | 335 | OscMessage oscMsg= oscP5.newMsg("/1/xy"); |
xshige | 0:cbfa819100c7 | 336 | oscMsg.add(mouseX*1.0/width); |
xshige | 0:cbfa819100c7 | 337 | oscMsg.add(mouseY*1.0/height); |
xshige | 0:cbfa819100c7 | 338 | oscMsg.add(0); // button status:released |
xshige | 0:cbfa819100c7 | 339 | oscP5.send(oscMsg); |
xshige | 0:cbfa819100c7 | 340 | } |
xshige | 0:cbfa819100c7 | 341 | */ |
xshige | 0:cbfa819100c7 | 342 | //---------------------------------------------------------------------------------------------------------- |