Skip to content

metro

Trigger Metronome.

Generate a metronomic signal to be used in any circumstance an isochronous trigger is needed.

Syntax

ktrig  = metro( kfreq [, initphase])
ktrig  metro  kfreq [, initphase]

Initialization

initphase - initial phase value (in the 0 to 1 range)

Performance

ktrig - output trigger signal

kfreq - frequency of trigger bangs in cps

metro is a simple opcode that outputs a sequence of isochronous bangs (that is 1 values) each 1/kfreq seconds. Trigger signals can be used in any circumstance, mainly to temporize realtime algorithmic compositional structures.

📝 Note

metro will produce a trigger signal of 1 when its phase is exactly 0 or 1. If you want to skip the initial trigger, use a very small value like 0.00000001.

Control-rate limit and comparison with metro2

metro remains supported and keeps its historical timing. Like metro2, it can emit at most one trigger per control cycle, so frequencies above kr cannot produce every requested trigger.

When metro's phase crosses one, it subtracts only one cycle. If kfreq exceeds kr, whole cycles can remain in its phase state. It can then keep emitting triggers after kfreq drops, even when the new frequency is zero. For example, with kr=100 and the default initial phase, running at 250 Hz for three control cycles and then setting the frequency to zero produces three more triggers. This timing is retained for compatibility with existing scores.

metro2 discards all completed phase cycles, so high frequencies do not leave these extra triggers after the frequency drops. It also adds swing and a separate offbeat amplitude. For evenly spaced triggers of amplitude 1, use:

ktrig metro2 kfreq, 0.5

Here, kswing=0.5 places offbeats midway between main beats, and the default iamp=1 gives both the same amplitude. No extra timing option is needed. Both opcodes still produce at most one trigger per control cycle.

Review the timing when changing an existing score from metro to metro2. In metro, initial phase spans one trigger interval; in metro2, it spans a main-beat/offbeat pair. The same nonzero initial phase therefore need not produce the same first trigger.

Examples

Here is an example of the metro opcode. It uses the file metro.csd

Example of the metro opcode.
<CsoundSynthesizer>
<CsOptions>
-odac -B441 -b441
</CsOptions>
<CsInstruments>

sr     =        44100
ksmps  =        441
nchnls =        2
0dbfs  =        1

       instr    1
ktrig metro 0.2
printk2 ktrig
        endin

</CsInstruments>
<CsScore>
i 1 0 20


</CsScore>
</CsoundSynthesizer>

Here is another example of the metro opcode. It uses the file metro-2.csd

Another example of the metro opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac   ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o metro-2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1

kpch    random   1,20           ;produce values at k-rate
ktrig   metro    10             ;trigger 10 times per second
kval    samphold kpch, ktrig    ;change value whenever ktrig = 1 
asig    buzz     1, 220, kval, 1;harmonics
        outs     asig, asig

endin
</CsInstruments>
<CsScore>
f 1 0 4096 10 1 ; sine

i 1 0 10
e
</CsScore>
</CsoundSynthesizer>

See also

Sensing and Control: Tempo and Sequencing

metro2, metrobpm

More information on this opcode in the Floss Manuals: https://flossmanual.csound.com/csound-language/control-structures

Credits

Written by Gabriel Maldonado.

First Example written by Andrés Cabrera.

New in Csound 5 (Previously available only on CsoundAV)