56
56
SUB , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , SUB , - 1 , SUB , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , SUB , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , SUB , - 1 , SUB , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , SUB , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , SUB , - 1 , SUB , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , SUB , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , SUB , - 1 , SUB , - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , 0 , 0 )
57
57
58
58
notes = [melody_notes , rhythm_notes , drum_beats , hi_hat , bass_notes ]
59
- channels = [gu .synth_channel (i ) for i in range (len (notes ))]
59
+ channels = [gu .synth_channel (i ) for i in range (len (notes ) + 1 )] # Extra channel for tones
60
+
61
+ # Configure the synth to play our notes
62
+ channels [0 ].configure (waveforms = Channel .TRIANGLE + Channel .SQUARE ,
63
+ attack = 0.016 ,
64
+ decay = 0.168 ,
65
+ sustain = 0xafff / 65535 ,
66
+ release = 0.168 ,
67
+ volume = 10000 / 65535 )
68
+
69
+ channels [1 ].configure (waveforms = Channel .SINE + Channel .SQUARE ,
70
+ attack = 0.038 ,
71
+ decay = 0.300 ,
72
+ sustain = 0 ,
73
+ release = 0 ,
74
+ volume = 12000 / 65535 )
75
+
76
+ channels [2 ].configure (waveforms = Channel .NOISE ,
77
+ attack = 0.005 ,
78
+ decay = 0.010 ,
79
+ sustain = 16000 / 65535 ,
80
+ release = 0.100 ,
81
+ volume = 18000 / 65535 )
82
+
83
+ channels [3 ].configure (waveforms = Channel .NOISE ,
84
+ attack = 0.005 ,
85
+ decay = 0.005 ,
86
+ sustain = 8000 / 65535 ,
87
+ release = 0.040 ,
88
+ volume = 8000 / 65535 )
89
+
90
+ channels [4 ].configure (waveforms = Channel .SQUARE ,
91
+ attack = 0.010 ,
92
+ decay = 0.100 ,
93
+ sustain = 0 ,
94
+ release = 0.500 ,
95
+ volume = 12000 / 65535 )
60
96
61
97
62
98
def gradient (r , g , b ):
@@ -116,6 +152,8 @@ def outline_text(text):
116
152
# The current synth beat
117
153
beat = 0
118
154
155
+ text = ""
156
+
119
157
120
158
def next_beat ():
121
159
global beat
@@ -145,37 +183,12 @@ def tick(timer):
145
183
146
184
if gu .is_pressed (CosmicUnicorn .SWITCH_A ):
147
185
if not was_a_pressed :
148
- # Configure the synth to play our notes
149
- channels [0 ].configure (waveforms = Channel .TRIANGLE + Channel .SQUARE ,
150
- attack = 0.016 ,
151
- decay = 0.168 ,
152
- sustain = 0xafff / 65535 ,
153
- release = 0.168 ,
154
- volume = 10000 / 65535 )
155
- channels [1 ].configure (waveforms = Channel .SINE + Channel .SQUARE ,
156
- attack = 0.038 ,
157
- decay = 0.300 ,
158
- sustain = 0 ,
159
- release = 0 ,
160
- volume = 12000 / 65535 )
161
- channels [2 ].configure (waveforms = Channel .NOISE ,
162
- attack = 0.005 ,
163
- decay = 0.010 ,
164
- sustain = 16000 / 65535 ,
165
- release = 0.100 ,
166
- volume = 18000 / 65535 )
167
- channels [3 ].configure (waveforms = Channel .NOISE ,
168
- attack = 0.005 ,
169
- decay = 0.005 ,
170
- sustain = 8000 / 65535 ,
171
- release = 0.040 ,
172
- volume = 8000 / 65535 )
173
- channels [4 ].configure (waveforms = Channel .SQUARE ,
174
- attack = 0.010 ,
175
- decay = 0.100 ,
176
- sustain = 0 ,
177
- release = 0.500 ,
178
- volume = 12000 / 65535 )
186
+ channels [0 ].volume (10000 / 65535 )
187
+ channels [1 ].volume (12000 / 65535 )
188
+ channels [2 ].volume (18000 / 65535 )
189
+ channels [3 ].volume (8000 / 65535 )
190
+ channels [4 ].volume (12000 / 65535 )
191
+ channels [5 ].volume (0 )
179
192
180
193
# If the synth is not already playing, init the first beat
181
194
if not synthing :
@@ -192,37 +205,12 @@ def tick(timer):
192
205
193
206
if gu .is_pressed (CosmicUnicorn .SWITCH_B ):
194
207
if not was_b_pressed :
195
- # Configure the synth to play our notes, but with only one channel audable
196
- channels [0 ].configure (waveforms = Channel .TRIANGLE + Channel .SQUARE ,
197
- attack = 0.016 ,
198
- decay = 0.168 ,
199
- sustain = 0 ,
200
- release = 0.168 ,
201
- volume = 0 )
202
- channels [1 ].configure (waveforms = Channel .SINE + Channel .SQUARE ,
203
- attack = 0.038 ,
204
- decay = 0.300 ,
205
- sustain = 0 ,
206
- release = 0 ,
207
- volume = 12000 / 65535 )
208
- channels [2 ].configure (waveforms = Channel .NOISE ,
209
- attack = 0.005 ,
210
- decay = 0.010 ,
211
- sustain = 16000 / 65535 ,
212
- release = 0.100 ,
213
- volume = 0 )
214
- channels [3 ].configure (waveforms = Channel .NOISE ,
215
- attack = 0.005 ,
216
- decay = 0.005 ,
217
- sustain = 8000 / 65535 ,
218
- release = 0.040 ,
219
- volume = 0 )
220
- channels [4 ].configure (waveforms = Channel .SQUARE ,
221
- attack = 0.010 ,
222
- decay = 0.100 ,
223
- sustain = 0 ,
224
- release = 0.500 ,
225
- volume = 0 )
208
+ channels [0 ].volume (0 )
209
+ channels [1 ].volume (12000 / 65535 )
210
+ channels [2 ].volume (0 )
211
+ channels [3 ].volume (0 )
212
+ channels [4 ].volume (0 )
213
+ channels [5 ].volume (0 )
226
214
227
215
# If the synth is not already playing, init the first beat
228
216
if not synthing :
@@ -242,7 +230,8 @@ def tick(timer):
242
230
# Stop synth (if running) and play Tone A
243
231
timer .deinit ()
244
232
tone_a = 400
245
- channels [0 ].play_tone (tone_a , 0.06 )
233
+ channels [5 ].play_tone (tone_a , 0.06 )
234
+ channels [5 ].volume (12000 / 65535 )
246
235
247
236
gu .play_synth ()
248
237
synthing = False
@@ -257,7 +246,8 @@ def tick(timer):
257
246
timer .deinit ()
258
247
tone_b = 600
259
248
260
- channels [1 ].play_tone (tone_b , 0.06 , attack = 0.5 )
249
+ channels [5 ].play_tone (tone_b , 0.06 , attack = 0.5 )
250
+ channels [5 ].volume (12000 / 65535 )
261
251
262
252
gu .play_synth ()
263
253
synthing = False
@@ -270,25 +260,25 @@ def tick(timer):
270
260
if tone_b > 0 : # Zero means tone not playing
271
261
# Increase Tone B
272
262
tone_b = min (tone_b + 10 , 20000 )
273
- channels [1 ].frequency (tone_b )
263
+ channels [5 ].frequency (tone_b )
274
264
275
265
if gu .is_pressed (CosmicUnicorn .SWITCH_BRIGHTNESS_DOWN ):
276
266
if tone_b > 0 : # Zero means tone not playing
277
267
# Decrease Tone B
278
268
tone_b = max (tone_b - 10 , 10 )
279
- channels [1 ].frequency (max (tone_b , 10 ))
269
+ channels [5 ].frequency (max (tone_b , 10 ))
280
270
281
271
if gu .is_pressed (CosmicUnicorn .SWITCH_VOLUME_UP ):
282
272
if tone_a > 0 : # Zero means tone not playing
283
273
# Increase Tone A
284
274
tone_a = min (tone_a + 10 , 20000 )
285
- channels [0 ].frequency (tone_a )
275
+ channels [5 ].frequency (tone_a )
286
276
287
277
if gu .is_pressed (CosmicUnicorn .SWITCH_VOLUME_DOWN ):
288
278
if tone_a > 0 : # Zero means tone not playing
289
279
# Decrease Tone A
290
280
tone_a = max (tone_a - 10 , 10 )
291
- channels [0 ].frequency (tone_a )
281
+ channels [5 ].frequency (tone_a )
292
282
293
283
if gu .is_pressed (CosmicUnicorn .SWITCH_SLEEP ):
294
284
if not was_z_pressed :
@@ -322,8 +312,6 @@ def tick(timer):
322
312
# print("white gradient")
323
313
gradient (255 , 255 , 255 )
324
314
325
- text = ""
326
-
327
315
if gu .is_pressed (CosmicUnicorn .SWITCH_A ):
328
316
text = "PlaySyn"
329
317
0 commit comments