1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#ifndef UDO_TEMPOTOOLS
#define UDO_TEMPOTOOLS ##
/*
Tempo tools
This file is part of the SONICS UDO collection by Richard Knight 2021
License: GPL-2.0-or-later
http://1bpm.net
*/
/*
Get the beat time (1/4 note) and quarter beat time (1/16 note) in seconds
for a given BPM
ibeattime, iquartertime tempotime ibpm
ibeattime the 1/4 note time in seconds
iquartertime the 1/16 note time in seconds
ibpm the beats per minute value
*/
opcode tempotime, ii, i
itempo xin
ibeattime = 60.0 / itempo
iquartertime = ibeattime * .25
xout ibeattime, iquartertime
endop
/*
Get the swung time (when iquarterindex is 1 or 3) for a given time
Using iquartertime as the 1/16 beat time and iswing as multiplier of
iquartertime to add to the time (iswing should be less than one)
itime swinger iquarterindex, iquartertime, itime, iswing
itime the time with swing applied
iquarterindex the quarter beat index MIN(0) MAX(3)
iquartertime time of one 1/16th beat
itime the normal/quantised time
iswing the swing amount MIN(0) MAX(1)
*/
opcode swinger, i, iiii
iquarterindex, iquartertime, itime, iswing xin
if (iquarterindex == 1 || iquarterindex == 3) then
itime = itime + (iswing * iquartertime)
endif
xout itime
endop
/*
Metronome with random variation
ktrigger drunkenmetro kfreq
ktrigger the metronome trigger
kfreq metronome frequency in hz
*/
opcode drunkenmetro, k, k
kfreq xin
kbtime = 1.0 / kfreq
kmetro metro kfreq
kdeltime random 0, (1.0 / kfreq) * 0.9
kout vdel_k kmetro, kdeltime, 1
xout kout
endop
#end
|