1
1
/*
2
2
metro.c:
3
3
4
- Copyright (C) 2000 Gabriel Maldonado
4
+ Copyright (C) 2000 Gabriel Maldonado, (C) 2019 Gleb Rogozinsky
5
5
6
6
This file is part of Csound.
7
7
@@ -31,6 +31,15 @@ typedef struct {
31
31
int32_t flag ;
32
32
} METRO ;
33
33
34
+ // METRO2 ADDED BY GLEB ROGOZINSKY Oct 2019
35
+ typedef struct {
36
+ OPDS h ;
37
+ MYFLT * sr , * xcps , * kswng , * iamp , * iphs ;
38
+ double amp2 , curphs , curphs2 , swng_init ;
39
+ int32_t flag , flag2 ;
40
+ } METRO2 ;
41
+ //
42
+
34
43
typedef struct {
35
44
OPDS h ;
36
45
MYFLT * trig , * ndx , * maxtics , * ifn , * outargs [VARGMAX ];
@@ -64,8 +73,8 @@ static int32_t metro_set(CSOUND *csound, METRO *p)
64
73
65
74
static int32_t metro (CSOUND * csound , METRO * p )
66
75
{
67
- IGN (csound );
68
76
double phs = p -> curphs ;
77
+ IGN (csound );
69
78
if (phs == 0.0 && p -> flag ) {
70
79
* p -> sr = FL (1.0 );
71
80
p -> flag = 0 ;
@@ -81,6 +90,67 @@ static int32_t metro(CSOUND *csound, METRO *p)
81
90
return OK ;
82
91
}
83
92
93
+ /* GLEB ROGOZINSKY Oct 2019
94
+ Opcode metro2 in addition to 'classic' metro opcode,
95
+ allows swinging with possibiliy of setting its own amplitude value
96
+ */
97
+ static int32_t metro2_set (CSOUND * csound , METRO2 * p )
98
+ {
99
+ double phs = * p -> iphs ;
100
+ double swng = * p -> kswng ;
101
+ int32 longphs ;
102
+ p -> amp2 = * p -> iamp ;
103
+
104
+ if (phs >= 0.0 ) {
105
+ if (UNLIKELY ((longphs = (int32 )phs )))
106
+ csound -> Warning (csound , Str ("metro2:init phase truncation" ));
107
+ p -> curphs = (MYFLT )phs - (MYFLT )longphs ;
108
+ p -> curphs2 = (MYFLT )phs - (MYFLT )longphs + 1.0 - (MYFLT )swng ;
109
+ }
110
+ p -> flag = 1 ;
111
+ p -> flag2 = 1 ;
112
+ p -> swng_init = (MYFLT )swng ;
113
+ return OK ;
114
+ }
115
+
116
+ static int32_t metro2 (CSOUND * csound , METRO2 * p )
117
+ {
118
+ double phs = p -> curphs ;
119
+ double phs2 = p -> curphs2 ;
120
+ double phs2_init = p -> swng_init ;
121
+ double amp2 = p -> amp2 ;
122
+ double swng = * p -> kswng ;
123
+ IGN (csound );
124
+ // MAIN TICK
125
+ if (phs == 0.0 && p -> flag ) {
126
+ * p -> sr = FL (1.0 );
127
+ p -> flag = 0 ;
128
+ }
129
+ else if ((phs += * p -> xcps * CS_ONEDKR * 0.5 ) >= 1.0 ) {
130
+ * p -> sr = FL (1.0 );
131
+ phs -= 1.0 ;
132
+ p -> flag = 0 ;
133
+ }
134
+ else
135
+ * p -> sr = FL (0.0 );
136
+ p -> curphs = phs ;
137
+
138
+ // SWINGING TICK
139
+ if (phs2 == 0.0 && p -> flag2 ) {
140
+ * p -> sr = FL (amp2 );
141
+ p -> flag2 = 0 ;
142
+ }
143
+ else if ((phs2 += * p -> xcps * CS_ONEDKR * 0.5 ) >= (1.0 + swng - phs2_init ) ) {
144
+ * p -> sr = FL (amp2 );
145
+ phs2 -= 1.0 ;
146
+ p -> flag2 = 0 ;
147
+ }
148
+ p -> curphs2 = phs2 ;
149
+
150
+ return OK ;
151
+ }
152
+ //
153
+
84
154
static int32_t split_trig_set (CSOUND * csound , SPLIT_TRIG * p )
85
155
{
86
156
@@ -255,15 +325,15 @@ static int32_t timeseq(CSOUND *csound, TIMEDSEQ *p)
255
325
256
326
static OENTRY localops [] = {
257
327
{ "metro" , S (METRO ), 0 , 3 , "k" , "ko" , (SUBR )metro_set , (SUBR )metro },
328
+ { "metro2" , S (METRO2 ), 0 , 3 , "k" , "kkpo" , (SUBR )metro2_set , (SUBR )metro2 },
258
329
{ "splitrig" , S (SPLIT_TRIG ), 0 , 3 , "" , "kkiiz" ,
259
330
(SUBR )split_trig_set , (SUBR )split_trig },
260
331
{ "timedseq" ,S (TIMEDSEQ ), TR , 3 , "k" , "kiz" , (SUBR )timeseq_set , (SUBR )timeseq }
261
- };
332
+ };O
262
333
263
334
int32_t metro_init_ (CSOUND * csound )
264
335
{
265
336
return csound -> AppendOpcodes (csound , & (localops [0 ]),
266
337
(int32_t
267
338
) (sizeof (localops ) / sizeof (OENTRY )));
268
339
}
269
-
0 commit comments