Successfully reported this slideshow.

Sbaw091027

2,831 views

Published on

  • Be the first to comment

Sbaw091027

  1. 1. // ofxOscMessage m; m.setAddress( "/setxy" ); m.addFloatArg( float(x) / float(ofGetWidth())); m.addFloatArg( float(y) / float(ofGetHeight())); sender.sendMessage( m );
  2. 2. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxOsc.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); //OSC ofxOscSender sender;
  3. 3. string message; int sliderValue; ofPoint position; }; #endif
  4. 4. #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); //OSC //IP port IP:127.0.0.1 port:3000 sender.setup("127.0.0.1", 3000); // OSC "/message" ofxOscMessage m; m.setAddress( "/message" ); m.addStringArg("oF -> Max: connected"); // sender.sendMessage(m); //OSC port:3001 receiver.setup(3001); sliderValue = 0; }
  5. 5. void testApp::update(){ //OSC // while(receiver.hasWaitingMessages()){ //OSC ofxOscMessage m; // receiver.getNextMessage(&m); //OSC "/slider" if ( m.getAddress() == "/slider" ){ //sliderValue int sliderValue = m.getArgAsInt32(0); } //OSC "/position" if ( m.getAddress() == "/position" ){ //position x y int position.x = m.getArgAsInt32(0)/127.0 * ofGetWidth(); position.y = ofGetHeight() - m.getArgAsInt32(1)/127.0 * ofGetHeight(); } }
  6. 6. void testApp::draw(){ //sliderValue ofSetColor(255, 255, 255); string buf; buf = "slider value: " + ofToString(sliderValue, 4); ofDrawBitmapString( buf, 20, 20 ); //positoin ofSetColor(0, 31, 255); ofCircle(position.x, position.y, 40); } void testApp::keyPressed(int key){ } void testApp::keyReleased(int key){ } void testApp::mouseMoved(int x, int y){ // OSC OSC "/mouse/position" ofxOscMessage m; m.setAddress( "/mouse/position" ); m.addIntArg( x ); m.addIntArg( y ); sender.sendMessage( m ); }
  7. 7. void testApp::mouseDragged(int x, int y, int button){ } void testApp::mousePressed(int x, int y, int button){ // OSC OSC "/mouse/mouse" 1 ofxOscMessage m; m.setAddress( "/mouse/button" ); m.addIntArg(1); sender.sendMessage( m ); } void testApp::mouseReleased(int x, int y, int button){ // OSC OSC "/mouse/mouse" 0 ofxOscMessage m; m.setAddress( "/mouse/button" ); m.addIntArg(0); sender.sendMessage( m ); } void testApp::windowResized(int w, int h){ }
  8. 8. ( //FM SynthDef("fm2", { arg bus = 0, freq = 440, carPartial = 0.5, modPartial = 0.5, detune=2.0, index = 3, mul = 0.2, ts = 1; var mod; var car; mod = SinOsc.ar( freq * modPartial, 0, freq * index * LFNoise1.kr(5.reciprocal).abs); car = SinOsc.ar( [(freq * carPartial) + mod,(freq+detune * carPartial) + mod], 0, mul); car = FreeVerb.ar( car* EnvGen.kr(Env.new([0,1], [5])), 0.5, 0.8, 0.2, 1.0); Out.ar(bus, car); }).load(s); )
  9. 9. //OSCResponder ( var play=false; // ON/OFF OSC "/toggle" OSCresponderNode(nil, "/toggle", { arg time, resp, msg; if(msg[1] == 1, { s.sendMsg("/s_new", "fm2", x=s.nextNodeID, 1,1); play=true; }, { s.sendMsg("/n_free", x); play=false; } ) }).add;
  10. 10. //FM OSC "/setxy" OSCresponderNode(nil, "/setxy", { arg time, resp, msg; var mod, index; mod = msg[1]*4.0; index = msg[2]*100.0; if(play == true, { s.sendMsg("/n_set", x, "modPartial", mod, "index", index); }); }).add; )
  11. 11. #ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxOsc.h" #define HOST "localhost" #define PORT 57120 class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofxOscSender sender; //OSC string info; // };
  12. 12. #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); // OSC sender.setup( HOST, PORT ); } void testApp::update(){ } void testApp::draw(){ // ofDrawBitmapString(info, 10, 10); } void testApp::keyPressed(int key){} void testApp::keyReleased(int key){} void testApp::mouseMoved(int x, int y){}
  13. 13. void testApp::mouseDragged(int x, int y, int button){ // OSC "/setxy" ofxOscMessage m; m.setAddress( "/setxy" ); m.addFloatArg( float(x) / float(ofGetWidth())); m.addFloatArg( float(y) / float(ofGetHeight())); sender.sendMessage( m ); info = m.getAddress()+" "+ m.getArgAsString(0)+ " "+ m.getArgAsString(1); } void testApp::mousePressed(int x, int y, int button){ // OSC "/toggle" ofxOscMessage m; m.setAddress( "/toggle" ); m.addIntArg( 1 ); sender.sendMessage( m ); info = m.getAddress() + " " + m.getArgAsString(0); }
  14. 14. void testApp::mouseReleased(int x, int y, int button){ // OSC "/toggle" ofxOscMessage m; m.setAddress( "/toggle" ); m.addIntArg( 0 ); sender.sendMessage( m ); info = m.getAddress() + " " + m.getArgAsString(0); } void testApp::windowResized(int w, int h){}

×