retriggering Gen counter

Thomas Robotham's icon

Hi,
I'm looking to be able to reset a gen counter while it's still going.
This would then reset the integer that's being fed into peek, to start playing the audio file from the begining.
I've tried various solutions using the codebox to no avail - any help would be appreciated.

{
    "patcher" :     {
        "fileversion" : 1,
        "appversion" :         {
            "major" : 8,
            "minor" : 1,
            "revision" : 0,
            "architecture" : "x64",
            "modernui" : 1
        }
,
        "classnamespace" : "box",
        "rect" : [ 593.0, 293.0, 640.0, 480.0 ],
        "bglocked" : 0,
        "openinpresentation" : 0,
        "default_fontsize" : 12.0,
        "default_fontface" : 0,
        "default_fontname" : "Arial",
        "gridonopen" : 1,
        "gridsize" : [ 15.0, 15.0 ],
        "gridsnaponopen" : 1,
        "objectsnaponopen" : 1,
        "statusbarvisible" : 2,
        "toolbarvisible" : 1,
        "lefttoolbarpinned" : 0,
        "toptoolbarpinned" : 0,
        "righttoolbarpinned" : 0,
        "bottomtoolbarpinned" : 0,
        "toolbars_unpinned_last_save" : 0,
        "tallnewobj" : 0,
        "boxanimatetime" : 200,
        "enablehscroll" : 1,
        "enablevscroll" : 1,
        "devicewidth" : 0.0,
        "description" : "",
        "digest" : "",
        "tags" : "",
        "style" : "",
        "subpatcher_template" : "",
        "boxes" : [             {
                "box" :                 {
                    "id" : "obj-91",
                    "maxclass" : "comment",
                    "numinlets" : 1,
                    "numoutlets" : 0,
                    "patching_rect" : [ 126.0, 100.0, 197.0, 20.0 ],
                    "text" : "<< be able to retrigger gen counter"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-84",
                    "maxclass" : "message",
                    "numinlets" : 2,
                    "numoutlets" : 1,
                    "outlettype" : [ "" ],
                    "patching_rect" : [ 65.0, 127.0, 29.5, 22.0 ],
                    "text" : "0"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-83",
                    "maxclass" : "message",
                    "numinlets" : 2,
                    "numoutlets" : 1,
                    "outlettype" : [ "" ],
                    "patching_rect" : [ 96.5, 100.0, 29.5, 22.0 ],
                    "text" : "1"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-181",
                    "maxclass" : "newobj",
                    "numinlets" : 1,
                    "numoutlets" : 2,
                    "outlettype" : [ "bang", "bang" ],
                    "patching_rect" : [ 105.0, 210.0, 42.0, 22.0 ],
                    "text" : "edge~"
                }

            }
,             {
                "box" :                 {
                    "fontface" : 0,
                    "fontname" : "Arial",
                    "fontsize" : 12.0,
                    "id" : "obj-180",
                    "maxclass" : "number~",
                    "mode" : 2,
                    "numinlets" : 2,
                    "numoutlets" : 2,
                    "outlettype" : [ "signal", "float" ],
                    "patching_rect" : [ 157.5, 210.0, 134.0, 22.0 ],
                    "sig" : 0.0
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-177",
                    "maxclass" : "message",
                    "numinlets" : 2,
                    "numoutlets" : 1,
                    "outlettype" : [ "" ],
                    "patching_rect" : [ 223.0, 299.0, 35.0, 22.0 ],
                    "text" : "open"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-142",
                    "maxclass" : "message",
                    "numinlets" : 2,
                    "numoutlets" : 1,
                    "outlettype" : [ "" ],
                    "patching_rect" : [ 180.0, 341.0, 33.0, 22.0 ],
                    "text" : "read"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-143",
                    "maxclass" : "newobj",
                    "numinlets" : 1,
                    "numoutlets" : 2,
                    "outlettype" : [ "float", "bang" ],
                    "patching_rect" : [ 223.0, 341.0, 119.0, 22.0 ],
                    "text" : "buffer~ sampleAudio"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-69",
                    "maxclass" : "button",
                    "numinlets" : 1,
                    "numoutlets" : 1,
                    "outlettype" : [ "bang" ],
                    "parameter_enable" : 0,
                    "patching_rect" : [ 105.0, 249.0, 24.0, 24.0 ]
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-12",
                    "maxclass" : "newobj",
                    "numinlets" : 1,
                    "numoutlets" : 3,
                    "outlettype" : [ "signal", "signal", "signal" ],
                    "patcher" :                     {
                        "fileversion" : 1,
                        "appversion" :                         {
                            "major" : 8,
                            "minor" : 1,
                            "revision" : 0,
                            "architecture" : "x64",
                            "modernui" : 1
                        }
,
                        "classnamespace" : "dsp.gen",
                        "rect" : [ 2300.0, 418.0, 947.0, 784.0 ],
                        "bglocked" : 0,
                        "openinpresentation" : 0,
                        "default_fontsize" : 12.0,
                        "default_fontface" : 0,
                        "default_fontname" : "Arial",
                        "gridonopen" : 1,
                        "gridsize" : [ 15.0, 15.0 ],
                        "gridsnaponopen" : 1,
                        "objectsnaponopen" : 1,
                        "statusbarvisible" : 2,
                        "toolbarvisible" : 1,
                        "lefttoolbarpinned" : 0,
                        "toptoolbarpinned" : 0,
                        "righttoolbarpinned" : 0,
                        "bottomtoolbarpinned" : 0,
                        "toolbars_unpinned_last_save" : 0,
                        "tallnewobj" : 0,
                        "boxanimatetime" : 200,
                        "enablehscroll" : 1,
                        "enablevscroll" : 1,
                        "devicewidth" : 0.0,
                        "description" : "",
                        "digest" : "",
                        "tags" : "",
                        "style" : "",
                        "subpatcher_template" : "",
                        "boxes" : [                             {
                                "box" :                                 {
                                    "id" : "obj-55",
                                    "maxclass" : "newobj",
                                    "numinlets" : 1,
                                    "numoutlets" : 1,
                                    "outlettype" : [ "" ],
                                    "patching_rect" : [ 315.5, 228.0, 26.0, 22.0 ],
                                    "text" : "!- 1"
                                }

                            }
,                             {
                                "box" :                                 {
                                    "id" : "obj-52",
                                    "maxclass" : "newobj",
                                    "numinlets" : 2,

example.maxpat
text/plain 11.67 KB


👽'tW∆s ∆lienz👽's icon

i couldn't quite figure out what you were trying to do with your specific patch(other than looping and retriggering), so here's a simplification of everything just to show how to address a buffer~ (using counter within gen~), get it looping, and allow for retriggering:

Max Patch
Copy patch and select New From Clipboard in Max.

(also, if you ever need to paste to forums like i did above, go into the outer/parent/main patch, select all, and then from the 'Edit' menu of Max, choose "Copy Compressed", then simply paste here)

hope it helps

Thomas Robotham's icon

Thanks for the patch, it was indeed helpful. - This explains why I could not send consecutive messages (0, 1) from a .js function to resest the counter.

My overall goal is to essentially have the basic functionality of a MSP play~ or groove~ object, but within GEN. Three inputs that can Stop, Play/Retrigger, and Loop.

- The play/retrigger is now the pulse input from the click.
- A stop can be done by sending a retrigger and counter increment of 0~
- The loop (on/off) is something im still missing. Do you have any clues?

Max Patch
Copy patch and select New From Clipboard in Max.

Thanks!


👽'tW∆s ∆lienz👽's icon

just to be complete, i'm going to include several versions to show the progression...
loop on/off can be more event-based and as simple as this:

Max Patch
Copy patch and select New From Clipboard in Max.

and it's actually not essential if the object never got any more complex than this to have the counter keep running, but... it's not as efficient as it can be(and is not good practice to let things address parts of memory which don't exist even though here in gen~, the way the peek object is designed automatically protects us from crashes when we do that) ...so here's one solution to accomplish that, too:

Max Patch
Copy patch and select New From Clipboard in Max.

(and just to help others who might find this thread, some of this comes from me searching/reviewing these other threads, in particular Evan's 1st solution here is what i used to stop the count when looping is off:
https://cycling74.com/forums/help-with-one-shot-buffer-in-gen
but this one by Andrew is also a great one, just to show how sample-accurate control of different processes can work:
https://cycling74.com/forums/sample-and-loop )

Edit: and one even-more-complete version here, because i realize loading in files which have a different sample-rate than the system-rate will cause the playback-rate to be inaccurate:

Max Patch
Copy patch and select New From Clipboard in Max.

Graham Wakefield's icon

Hey there,

Here's a couple of alternative ways I'd write that:

Max Patch
Copy patch and select New From Clipboard in Max.

Graham