oscmessaging speed

edited January 2017 in Library Questions

hi i need to send an oscmessage to another program. I need to have it go faster than a loop in the draw method. but if i do it in the normal way it is too fast. Since i am using controlP5 i cant use delay() in the loop. I can't find anyway to slow down a loop without using draw and millis().

Tagged:

Answers

  • thanks

    i figured that thread() was the answer, but couldn't get it to work i will try again.

  • You can use delay() or millis() in a threaded method without slowing down the rest of the program.

  • _here was a simple example i found in the forum https://forum.processing.org/two/discussion/12022/open-sound-control-message-lisener-instead-of-draw-loop

    RenderClock clock;

    float x = 0;

    void setup() { size(200, 200); noLoop(); clock = new RenderClock(10); //This detour seems to be neccessary because a direct call of // clock.run(); will have the effect that the canvas will not be drawn at all. thread("startClock"); }

    void startClock() { clock.run(); }

    // does nothing but has to be there. void draw() { }

    void render() { x += 1; background(204); line(x, 0, x, height); redraw(); }

    class RenderClock extends Thread { int framesPerSecond; RenderClock(int framesPerSecond) { this.framesPerSecond = framesPerSecond; }

    void run() { while (true) { try { sleep((long)(1000 / framesPerSecond)); render(); } catch(InterruptedException e) { } } } }

  • Is there a particular reason why you need to draw upon receiving an OSC event? Seems like you want to send independently from the draw thread, which is a very different case from the thread you are referring to.

  • edited January 2017

    @dfamil --

    I need to have it go faster than a loop in the draw method.

    Could you explain this requirement more? What are you trying to accomplish?

    In practice this might be impossible to guarantee (network latency, gremlins) so a more robust solution might involve checking if the new message has arrived at the beginning of each draw loop and then skipping the loop entirely (or almost entirely) if there is no message. There are also other loop-independent timing solutions. But it really depends on what you are trying to do. I may just be repeating @colouredmirrorball here....

  • hi

    i am sending the osc data to a separate graphic that is drawing the data(this was suppled by the artist and is written in openFramworks. the data being drawn was going too fast. Here is how i alter the code

    void sendOsc() { if (theFlagState==true ) { currentRow++; readCSV(readTable, currentRow); } else { currentRow = 0; } }

    void startClock() { clock.run(); }

    class RenderClock extends Thread { int framesPerSecond; RenderClock(int framesPerSecond) {

    this.framesPerSecond = framesPerSecond;
    

    } void run() { while (true) { try { sleep((long)(10 / framesPerSecond)); sendOsc(); } catch(InterruptedException e) { } } } }

  • edited January 2017

    I think I'm starting to understand...?

    1. You have a UI / data sender in Processing, and a renderer in OpenFrameworks.

    2. Your OpenFrameworks client needs to draw at a speed faster than 60fps (or whatever your Processing top draw loop speed is), but slower than 300fps (or whatever a non-throttled Processing loop is able to send over OSC), because [secret reasons].

    I haven't tried these, but two approaches:

    1. Create a thread that runs your message sender. Put the millis() time checker in that thread. Control draw speed with delay variable used by your thread.
    2. Add an OSC queue to the OpenFrameworks application, and put the draw speed timer there. If you need to control the speed parameter of drawing from your UI, control it with a never-queued OSC message.

    You could also implement both solutions -- one to throttle data generations, one to control draw speed. This would be more robust against latency fluctuations if you are running these over a network.

Sign In or Register to comment.