Creating a metro object using BPM

In Supercollider, Max Msp etc you will find a metro object that will trigger events at a certain rate based on BPM. Is there some built in functionality in Processing I can use for the same functionality. This needs to be 100% accurate so using draw() and frameRate will not be sufficient since it varies slightly. Alternatively does anyone have a suggestion on how this can be done?

Answers

  • edited November 2016
    1. There is no such thing as 100% accuracy.
    2. You can get better accuracy from frameRate and the draw loop simply by running on faster hardware.
    3. If you really, really need close to millisecond accuracy, there are ways to do it. See discussion and debates in this thread: Timing for draw loop. Briefly, tight loops will get you time-aligned, but they can stress your processor and cause interaction lag. Some alternatives are less precise, but also have fewer downsides.
  • edited November 2016

    Hi, thanks for the reply.

    I did a simple test setting frameRate to 120 and printing the frameRate variable. Some of the output is shown below. As you can see it goes as high as 127,29.. and this is far to unaccurate in terms of making music. Therefore I need something more stable. I will review the other thread to see if I find a solution.

    120.879265
    119.83711
    120.369385
    120.872314
    119.90422
    120.26277
    120.80755
    119.867615
    120.40936
    120.59332
    121.1965
    120.27273
    120.69504
    119.70904
    115.85873
    125.79986
    127.29039
    125.85537
    125.78165
    124.242294
    124.33107
    124.44801
    
    • You can use thread() to create a Thread to run a function.
    • Then you can have an infinite loop there, timed w/ delay().
    • But you can't directly access the canvas. Use a separate PGraphics instead.
  • You might also be interested in Praxis -- I haven't tried it yet, but it is also a patch-based IDE, and it mentions "low-latency audio" as part of its design.

  • Thanks for the replies.

    Praxis looks just like what I need and I am so glad you informed me jeremydouglass. I am working with audio and visuals but I have never come across Praxis(!) and I can't wait to explore the software - thanks!

  • @keykeeper yes, if you're doing audio and visuals together, come try out Praxis LIVE, and give me a shout if you need any help. I've not exactly been uncritical of Processing for audio! Praxis LIVE's architecture has a better approach for this.

    There are two issues with your approach if you're wanting accurate audio BPM without jitter. Firstly, you need to sync audio triggering to the soundcard clock, not the system clock - they'll drift! Secondly, you need to trigger things in the audio thread itself - triggering things from draw() or a background thread is useless.

Sign In or Register to comment.