Skip to content

metro2

Trigger Metronome with Swing and Accents.

Syntax

ktrig  = metro2( kfreq, kswing [, iamp, initphase, icorrect])
ktrig  metro2  kfreq, kswing [, iamp, initphase, icorrect]

Initialization

iamp (optional, default=1) -- offbeat trigger amplitude

initphase (optional, default=0) -- initial phase value, normally between 0 and 1.

icorrect (optional, default=0) -- zero preserves the original timing, including startup offbeats and the one-control-cycle offset between the two clocks. Set to 1 for corrected timing: both clocks advance together, the initial swing comes from its first control-rate value, and a nonzero initial phase does not emit an offbeat that has already passed. Corrected mode requires a finite, nonnegative frequency and initial phase, and swing between 0 and 1.

For example, ktrig metro2 4, .65, -1, 0, 1 selects corrected timing, with 1 for main beats and -1 for offbeats.

Performance

ktrig - output trigger signal

kfreq - frequency of trigger bangs in cps

kswing - value (in the 0 to 1 range)

metro2 is a modification of 'classic' metro opcode with additional swinging. The swinging clicks can be modulated at k-rate. Also, swinging clicks can have their own amplitude value set by iamp.

📝 Note

metro2 as well as 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.

Examples

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

Example of the metro2 opcode.
<CsoundSynthesizer>
<CsOptions>
-odac ; for RT audio
</CsOptions>
        <CsInstruments>

sr = 44100
ksmps = 16
nchnls = 2
0dbfs = 1.0

ga1 init 0   ; delay aux

instr 1 ; main triggering instrument
kndx init 0
kndx2 init -1
; the clicks are 1/16th notes @ 137 BPM
kT metro2 (4*137/60), p4, -1
if (kT == 0) goto Halt
        k1 table kndx, 1, 0, 0, 1
        kndx += 1
        if (k1 == 0) goto Next
                event "i", 2, 0, 0.35, k1
Next: 
; positive amplitude values of down-beat clicks 
; are used to trigger kick (instr 3)
if (kT < 1) goto Halt
        kndx2 += 1
        kndx2 wrap kndx2, 0, 2 
        if kndx2 != 0 goto Halt
        event "i", 3, 0, 0.2
Halt:
endin

instr 2  ; simple subtractive bass
kAE linsegr 0, 0.005, 1, p3/2, .7, .04, 0, .04, 0
kFE linsegr 1, 0.005, 2, p3/2, .7, .04, .1, .04, .1
ifr = cpspch(p4)
a1 vco2 1, ifr
a2 vco2 1, ifr * 1.005
a3 vco2 1, ifr * 0.993
aM = (a1+a2+a3)/3
aM moogvcf aM*kAE, 1000 * kFE, 0.5
outs aM, aM
ga1 += aM * 0.25
endin

instr 3 ; simple techno kick
k1 linseg 200, p3, 10
k2 linseg 0,0.001,1,0.25,0
a1 oscil 0.3*k2, k1
outs a1,a1
endin

instr 99 ; feedback delay for bass
a1 delayr 0.5
ab deltap 0.33
   delayw ga1 + ab*0.3
outs ab,ab
ga1 = 0
endin

</CsInstruments>
<CsScore>
t 0 137 
; ftable1 is the bass sequence to played with various swings
f1 0 16 -2 6.00 0 0 7.00 0 0 6.00 0 6.00 0 0 7.00 0 7.01 6.00 0
; 4 measure pattern of different swinging 
i1 0 16 0.5
i1 + .  0.65
i1 + .  0.4
i99 0 46
</CsScore>
</CsoundSynthesizer>

Here is another example of the metro2 Opcode. It uses the file metro2_corrected. It selects corrected timing and starts after the first offbeat. It prints 1 for main beats and -1 for offbeats:

Corrected metro2 timing
<CsoundSynthesizer>
<CsOptions>
-n -d -m0
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 1
0dbfs = 1

instr 1
  ; The final argument selects corrected timing.
  ; Phase .75 starts after the .65 offbeat, so that offbeat is skipped.
  kTrigger metro2 4, .65, -1, .75, 1
  kTime timeinsts
  if kTrigger != 0 then
    printks "Time: %.4f s, trigger: %+.0f\n", 0, kTime, kTrigger
  endif
endin
</CsInstruments>
<CsScore>
i 1 0 2
e
</CsScore>
</CsoundSynthesizer>

See also

Sensing and Control: Tempo and Sequencing

Credits

Author: Gleb Rogozinsky;
St.Petersburg, October 2019

New in Csound version 6.14