Metronome objects are used to synchronize blocks of musical material (i.e., by making sure they start playing together), e.g., for live coding applications. It is very hard otherwise (you need a steady hand, and luck) to start things together at the exact same time. Of course, Metronome objects can be used for other things (e.g., GUI animation).
A metronome has a tempo (e.g., 60 BPM), and a time signature (e.g., 4/4).
A program may have several metronomes active at the same time.
Metronome is included in the music library, so, you need the following in your program:
from music import *
Use the following function to create a Metronome object:
|Metronome(tempo, timeSignature)||Creates a metronome with the provided tempo (a positive integer denoting beats-per-minute, default is 60) and timeSignature (a list denoting how many beats are in each measure of music, default is [4, 4] meaning 4/4).|
Once a Metronome, m, has been created, the following functions are available:
|m.start()||Start metronome ticking.|
|m.stop()||Stop metronome ticking.|
|m.add(function, parameters, beatToStart, repeatFlag)||Add this function (a function name) to be called with the given parameters (a list), on the specified beat (1 means first beat in measure, 2, means 2nd beat in measure, and so on; 0 means the absolute next beat), and whether to call it repeatedly (True or False).
NOTE: If beatToStart is larger than time signature (e.g., beat 5 in 4/4) this means skip measures (e.g., start on the 1 beat of the 2nd measure). If the function is repeated, skipping of measures is also repeated (e.g., start on the 1 beat of every 2nd measure). This allows for complex rhythms to be created and kept synchronized.
|m.remove(function)||Remove provided function (a function name) from the internal list of functions called by the metronome. If this function has been added several times, remove the first addition. Call it again to remove more.|
|m.removeAll()||Clear all functions to be called by metronome.|
|m.setTempo(tempo)||Set metronome’s tempo (an integer meaning beats per minute, e.g., 60).|
|m.getTempo()||Return metronome’s tempo.|
|m.setTimeSignature(timeSignature)||Set metronome’s time signature (a list, e.g., [4, 4] meaning 4/4).|
|m.getTimeSignature()||Get metronome’s time signature.|
|m.soundOn(pitch, volume, channel)||Produce a sound for every metronome tick. Parameters are optional – use provided pitch to produce sound (default is 35); volume for first (strong) beat – subsequent beats sound at 70% of that (default is 127); and channel (default 9).|
|m.soundOff()||Stop producing sounds for metronome ticks.|
|m.show()||Print out the metronome ticks on the console.|
|m.hide()||Stop printing out metronome ticks on the console.|