@@ -96,6 +96,34 @@ def reset(self):
96
96
self .lanes = []
97
97
self .ccs = {}
98
98
self .dev = 0
99
+
100
+ # pitch wheel oscillation
101
+ self .vibrato_enabled = False # don't set this directly, call vibrato()
102
+ self .vibrato_amp = 0.0
103
+ self .vibrato_freq = 0.0
104
+ # self.vibrato_offset = 0.0 # value that gets added to pitch
105
+
106
+ def vibrato (self , b , amp = 0.0 , freq = 0.0 ):
107
+ self .vibrato_amp = amp
108
+ self .vibrato_freq = freq
109
+ self .vibrato_t = 0.0
110
+ if b == self .vibrato_enabled :
111
+ return
112
+ if b :
113
+ try :
114
+ self .ctx .vibrato_tracks .remove (self )
115
+ except KeyError :
116
+ pass
117
+ else :
118
+ self .ctx .vibrato_tracks .add (self )
119
+ self .pitch (self .pitchval )
120
+ self .vibrato_enabled = b
121
+
122
+ def vibrato_logic (self , t ):
123
+ # TODO: test this
124
+ self .vibrato_t += t
125
+ v = math .sin (self .vibrato_t * self .vibrato_freq * math .tau ) * self .vibrato_amp
126
+ self .pitch (self .pitchval + v , False ) # don't save new pitchval on call
99
127
100
128
# def _lazychannelfunc(self):
101
129
# # get active channel numbers
@@ -263,27 +291,27 @@ def midi_channel(self, midich, stackidx=-1):
263
291
self .channels = [(0 ,midich )]
264
292
elif midich not in self .channels :
265
293
self .channels .append (midich )
266
- def pitch (self , val ): # [-1.0,1.0]
294
+ def write_short (self , ch , status , val , val2 ):
295
+ if self .ctx .midifile :
296
+ self .midifile_write (ch ,mido .UnknownMetaMessage (status ,data = [val ,val2 ], time = self .us ()))
297
+ else :
298
+ self .midi [ch ].write_short (status ,val ,val2 )
299
+ def pitch (self , val , save = True ): # [-1.0,1.0]
300
+ if save :
301
+ self .pitchval = val
267
302
val = min (max (0 ,int ((1.0 + val )* 0x2000 )),16384 )
268
- self .pitchval = val
269
303
val2 = (val >> 0x7f )
270
304
val = val & 0x7f
271
305
for ch in self .channels :
272
306
status = (MIDI_PITCH << 4 ) + ch [1 ]
273
307
if self .ctx .showmidi : log (FG .YELLOW + 'MIDI: PITCH (%s, %s)' % (val ,val2 ))
274
- if self .ctx .midifile :
275
- self .midifile_write (ch [0 ],mido .UnknownMetaMessage (status ,data = [val1 ,val2 ], time = self .us ()))
276
- else :
277
- self .midi [ch [0 ]].write_short (status ,val ,val2 )
308
+ self .write_short (ch [0 ], status , val , val2 )
278
309
def cc (self , cc , val ): # control change
279
310
if type (val ) == type (bool ): val = 127 if val else 0 # allow cc bool switches
280
311
for ch in self .channels :
281
312
status = (MIDI_CC << 4 ) + ch [1 ]
282
313
if self .ctx .showmidi : log (FG .YELLOW + 'MIDI: CC (%s, %s, %s)' % (status , cc ,val ))
283
- if self .ctx .midifile :
284
- self .midifile_write (ch [0 ], mido .UnknownMetaMessage (status ,data = [cc ,val ],time = self .us ()))
285
- else :
286
- self .midi [ch [0 ]].write_short (status ,cc ,val )
314
+ self .write_short (ch [0 ], status , cc , val )
287
315
self .ccs [cc ] = v
288
316
if cc == 1 :
289
317
self .modval = val
0 commit comments