[puredata] Handling multiple button presses simultaneously

  • Hi there,

    Unfortunately my pd ambitions have outrun my basic knowledge, so I require a little help with an app I'm writing. Is there an efficient way to track multiple button presses within pd?

    Ideally I'd want something analogous to a function in another programming language where pressing each button triggers an independent instance of the function (which is ended by that button being lifted). This way there might be multiple versions of this function running for the different buttons held down.

    Hope this makes sense, Hemmer

  • @hemmer - first, welcome to the world of pd app development. it gets easier...

    second, if you do not already know about it, there's a good site for learning pd here: http://en.flossmanuals.net/PureData/

    and now to your specific question. pd employs "abstractions" (see http://en.flossmanuals.net/PureData/Abstractions and http://puredata.hurleur.com/sujet-1187-abstraction-why-use-etc), which are essentially subroutines (or subpatches as they're called in pd land) that encapsulate a function to be called from multiple places. these abstractions can be defined with parameters - represented in pd as a dollar sign followed by a number, such as '$1' (see http://en.flossmanuals.net/PureData/DollarSigns).

    for the example you give, you might create one such pd abstraction - let's call it button_function.pd for sake of this example, which made use of $1 and $2 to represent the column and row position of a monome button, respectively. then your main application would would actually need to contain an object for each button to be handled with such a function, i.e., [button_function 0 1], [button_function 0 2], etc.

    this may confuse more than it helps, but you can also look under the hood at one of my pd apps to see how i employ abstractions:
    pd_mlr - http://docs.monome.org/doku.php?id=app:pd_mlr
    loopy - http://post.monome.org/comments.php?DiscussionID=9132

    if you have questions, feel free to ask...

  • ah i see. i had actually tried abstractions/subpatches but couldn't see how to do it without using 64 of them! is there a way to programmatically create the objects? i guess i was hoping for a neater way to handle it, but then handling multitouch is intrinsically complex i guess.

    one idea i had was to have a subpatch that when initiated stores the button coords. when it was called again if the coords were different it would recursively call a version of itself. this way you would only have instances for the current buttons (i think). this is actually all a moot point as pd doesn't allow an abstraction within itself...

    thanks for your help, greatly appreciated.