(max) counter, key, ggate, gswitch, stripnote

Friday I modified the random note from table patcher to playback either in order or randomly. Along the way I introduced some new objects (and some that I’ve used before, but still need explaining). Before talking about the counter object, let’s make our way around the patcher and discuss some of the other objects.

(download the RandomCounter.maxpat)


The key object reports computer keys pressed as number codes. It can output platform specific codes, or ASCII (American Standard Code for Information Interchange) codes. ASCII codes are preferable, as they will allow your patchers to be platform independent — running the same way on Mac and Windows.

The select object is looking for the number 32, which is the ASCII code for the spacebar. When the spacebar is pressed, select finds the 32 and outputs a bang. Using key in this way allows for the spacebar to turn the toggle on and off (bangs reverse the state of a toggle object).

ggate and gswitch

Just below the select object is a graphic gate, ggate. Further down the patcher chain is a graphic switch, gswitch. I’ve put them side by side below (ggate on left, gswitch on right.



Both objects have a control inlet as the left-most inlet. The control inlet can be used to change the routing of the object. Clicking on the objects has the same effect (changing the routing).

The ggate routes a single input to one of two outputs. The gswitch routes two inputs to one output.


In earlier version of the random note patcher, note velocity turned the toggle on and off. But if you wanted to change base notes you had to lift up one MIDI note before pressing another, as any noteoff stops the patcher even if another MIDI note is being held down.

The stripnote object (lower right part of patcher) listens to midi note numbers and velocities, but only passes that data through if the velocity is non-zero. It strips note off messages from the data stream. The patcher now starts and stops with the spacebar, and transposes the itable output to the last MIDI key pressed. You don’t have to continue to hold the key.

A common mistake is to only connect the note input to stripnote. If you make this mistake, you will not get any output from stripnote, as you have to have a non-zero velocity to pass through data.


Now we get to the part of the patcher that changes what we here. Previous versions of the patcher have played the notes in any order (randomly). Adding a counter object allows for playback of the stored intervals in order.

The counter object counts bangs. In its simplest form, you specify a minimum and maximum count as arguments, and the count will continuously loop from min to max. You can change the direction of the count, or have the count alternate up and down, with messages to the object. You can also change the min or max of the count.

The number box above the counter is changing both the range of the random object and the max of the counter. Since you specify the range of the random, but the output is 0 to 1 less than the range. Counter has to specify the actual boundaries of the range. In order to make the counter match to the output of the random object, you need to subtract 1 from the range argument.

Both counter and random are outputting index values to send to a table. Both outputs are connected to the inlet of the gswitch. Clicking on the gswitch changes between the counter (ordered output) and random output.


Leave a Reply