(maxmsp) timer and tempo detection

The timer object can be used for detecting elapsed time between events. By default, it tells you the time in milliseconds out its left outlet, but it also can output a formatted time value (hh:mm:ss or beats/bars/tics, for example) out the right outlet.

Bang in the left inlet starts the timer. Bang in the right inlet reports elapsed time. Connecting one bang (or other event) to both right and left inlets reports the time and restarts the timer. Such as arrangement is very useful for keeping track of beats.

The timerTempo.maxpat shows a way that the timer can be used for tempo detection. The math portion of the patcher is very simple. You take the elapsed time in milliseconds, use reverse divide ( !/ ) to divide 1000 by the number of ms to give you the number of beats in one second, and then multiply that value by 60 to find the number of beats per minute. Use floating-point math for the entire sequence.

Once you have the tempo in bpm you can use the tempo message to transport to set the transport to that tempo.

The top portion of the patcher just adds a bit of functionality. The key/select object combination allows for the use of the space bar to set the tempo. The split object after the timer is useful to ignore large timer values that result from inactivity (not attempts at setting the tempo). I chose 2000 ms (2 sec) as my split range, meaning that the slowest tempo result would be 30 bpm.

The timerTempo patcher also uses the active message to a metro using musical time values to allow for a toggle to start and stop the metro. Of course, the transport still has to be running for the metro to work with musical time values. If you use the active message you do not need to specify autostart and autostarttime attributes for the metro object.


Comments

Leave a Reply