This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
forked from forgery810/fl-studio-presonus-atom-sq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons.py
384 lines (309 loc) · 10.5 KB
/
buttons.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
import device
import ui
import channels
import mixer
import general
import playlist
import transport
import midi
import patterns
import data
import plugins
import config
from direction import Directions
from lights import Lights
from modes import Modes
from notes import Notes, Shifter
import _random
from midi import *
current_arrow = 0
arrow_index = 0
class Buttons:
scale = 0
scale_choice = 0
note = 0
root_note = 0
touchpad_value = 0
lower_limit = 0
upper_limit = 0
g_rotate = [2, 3, 4]
g_iter = 0
interval = 0
accu_steps = []
clear_toggle = False
six_options = ['Press A to clear accum steps...']
b_iter = 0
b_options = ['Enter', 'Copy Pattern', 'Copy Channel', 'Paste']
c_iter = 0
tempo_toggle = False
button_6_iter = 0
def __init__(self, event):
self.shift = Shifter()
self.push = Modes(event)
self.act_out(event)
def act_out(self, event):
"""handles button inputs and assigns function from fl studio api"""
if event.midiId == 144:
if event.data2 > 0:
if event.data1 == data.tsport["play"]:
transport.start()
print('Play')
event.handled = True
elif event.data1 == data.tsport["stop"]:
transport.stop()
print('Stop')
event.handled = True
elif event.data1 == data.tsport["record"]:
transport.record()
print('Toggle Record')
event.handled = True
elif event.data1 == data.buttons['zoom']:
event.handled = True
elif event.data1 == data.tsport["metronome"]:
print('Toggle Metronome')
transport.globalTransport(midi.FPT_Metronome, 110)
event.handled = True
elif event.data1 == data.tsport["shift_play"]:
transport.globalTransport(midi.FPT_LoopRecord, 113)
print('Toggle Loop')
event.handled = True
elif event.data1 == data.tsport["shift_stop"]:
transport.globalTransport(midi.FPT_Undo, 20)
print('Undo/Redo')
event.handled = True
elif event.data1 == data.tsport["shift_record"]:
transport.globalTransport(midi.FPT_Save, 92)
print('Save')
event.handled = True
elif event.data1 in data.buttons["solo"]:
if ui.getFocused(0):
mixer.soloTrack(mixer.trackNumber())
event.handled = True
elif ui.getFocused(1):
channels.soloChannel(channels.channelNumber())
event.handled = True
else:
event.handled = True
elif event.data1 in data.buttons["mute"]:
if ui.getFocused(0):
mixer.muteTrack(mixer.trackNumber())
event.handled = True
elif ui.getFocused(1):
channels.muteChannel(channels.channelNumber())
event.handled = True
else:
event.handled = True
elif event.data1 in data.buttons["arm"]:
if ui.getFocused(0):
mixer.armTrack(mixer.trackNumber())
event.handled = True
elif ui.getFocused(1):
mixer.linkTrackToChannel(0)
event.handled = True
else:
event.handled = True
# elif event.data1 == data.buttons["zoom"]:
elif event.data1 == data.pads['left_arrow']:
if ui.getFocused(5) and plugins.isValid(channels.selectedChannel()):
print('plugin')
plugins.prevPreset(channels.selectedChannel())
event.handled = True
elif ui.getFocused(1):
transport.globalTransport(midi.FPT_PatternJog, -1)
event.handled = True
else:
ui.left()
event.handled = True
elif event.data1 == data.pads['right_arrow']:
if ui.getFocused(5) and plugins.isValid(channels.selectedChannel()):
print('plugin')
plugins.nextPreset(channels.selectedChannel())
event.handled = True
elif ui.getFocused(1):
transport.globalTransport(midi.FPT_PatternJog, 1)
event.handled = True
else:
ui.right()
print('right')
event.handled = True
if event.midiId == 176 and event.data1 == data.pads['touch']: # this selects for touchpad and allows it to go to zero
Buttons.touchpad_value = event.data2
if event.midiId == 176 and event.data2 > 0:
if event.data1 == data.knobs["jog_wheel"]:
print('jogging')
if event.data2 == 1:
ui.next()
event.handled = True
elif ui.getFocused(0):
if event.data2 == 65 and mixer.trackNumber() > 0:
ui.previous()
event.handled = True
elif event.data2:
ui.previous()
event.handled = True
else:
event.handled = True
if event.midiChanEx == 130 and event.data2 > 0: # 1-6 buttons
if event.data1 == data.buttons["button_1"]:
print('quantize')
channels.quickQuantize(channels.channelNumber())
event.handled = True
elif event.data1 == data.buttons["button_4"]:
print("Random")
for i in range(patterns.getPatternLength(patterns.patternNumber())): # clear pattern
channels.setGridBit(channels.channelNumber(), i, 0)
for z in range(patterns.getPatternLength(patterns.patternNumber())):
y = num_gen()
if y > (Buttons.touchpad_value * 516):
channels.setGridBit(channels.channelNumber(), z, 1)
else:
channels.setGridBit(channels.channelNumber(), z, 0)
Modes.mode_init()
event.handled = True
elif event.data1 == data.buttons["button_5"]:
self.note_gen()
elif event.data1 == data.buttons["button_6"]:
print(Buttons.clear_toggle)
if Modes.sub_step_iter == 3: # if in accumulator mode
if Buttons.clear_toggle == False:
ui.setHintMsg(Buttons.six_options[0])
Buttons.clear_toggle = True
elif Buttons.clear_toggle == True:
Buttons.clear_toggle = False
ui.setHintMsg('Clear option off')
else:
print('Set Tempo...or something') # not used currently
if event.midiChanEx == 128: # A - H Buttons
if event.data1 == data.pads['a']:
if ui.getFocused(4):
ui.selectBrowserMenuItem()
if Modes.get_mode() == 3: # shifter mode
print('shifting')
self.shift.set_shift()
event.handled = True
elif Buttons.b_iter == 0:
if Modes.get_step_submode() == 3: # accumulator mode
if Buttons.clear_toggle == True:
# Notes.accum_step.clear()
Notes.reset_steps()
Buttons.clear_toggle = False
event.handled = True
elif Notes.accum_on == True and Buttons.clear_toggle == False:
Notes.accum_on = False
ui.setHintMsg("Accumulator Off")
elif Notes.accum_on == False and Buttons.clear_toggle == False:
Notes.accum_on = True
ui.setHintMsg("Accumulator On")
elif ui.getFocused(1) or ui.getFocused(5):
channels.showCSForm(channels.channelNumber(), -1)
else:
ui.enter()
event.handled = True
print('enter')
elif Buttons.b_iter != 0:
self.b_decide(Buttons.b_iter)
event.handled = True
elif event.data1 == data.pads["b"]:
Buttons.b_iter += 1
if Buttons.b_iter >= len(Buttons.b_options):
Buttons.b_iter = 0
ui.setHintMsg(Buttons.b_options[Buttons.b_iter])
# self.b_decide(Buttons.b_iter)
print('b')
elif event.data1 == data.pads['c']:
print(ui.getFocusedPluginName())
Modes.mult()
elif event.data1 == data.pads["d"]:
print('View Plugin Picker')
transport.globalTransport(midi.FPT_F8, 67)
event.handled = True
elif event.data1 == data.pads["e"]:
print('e')
self.push.mode_change()
elif event.data1 == data.pads["f"]:
print('sub-mode')
self.push.rotate_layout()
elif event.data1 == data.pads["g"]:
Buttons.g_iter += 1
if Buttons.g_iter >= len(config.options['g_button']):
Buttons.g_iter = 0
ui.setFocused(config.options['g_button'][Buttons.g_iter])
print(config.options['g_button'][Buttons.g_iter])
elif event.data1 == data.pads['h']:
if not ui.getFocused(1):
transport.globalTransport(midi.FPT_F6, 65)
else:
transport.globalTransport(midi.FPT_F9, 68)
event.handled = True
def b_decide(self, choice):
"""takes b_iter as input and calls appropriate function"""
if Buttons.b_options[choice] == 'Copy Pattern':
self.copy_all()
elif Buttons.b_options[choice] == 'Copy Channel':
self.copy_one()
elif Buttons.b_options[choice] == 'Paste':
self.paste()
def copy_all(self):
"""called by b_decide"""
channels.selectAll()
ui.copy()
def copy_one(self):
"""called by b_decide"""
ui.copy()
def paste(self):
"""called by b_decide"""
ui.paste()
def note_gen(self):
"""generates random notes. 0-65535 is the range of 16 bit numbers. note variable calls num_gen for random number which is mapped to index of note in chosen scale"""
for i in range(patterns.getPatternLength(patterns.patternNumber())):
note = data.scales[Buttons.scale][Buttons.root_note][int(mapvalues(num_gen(), 0 + Buttons.lower_limit,
len(data.scales[Buttons.scale][Buttons.root_note]) - Buttons.upper_limit, 0, 65535))]
print(note)
channels.setStepParameterByIndex(channels.selectedChannel(), patterns.patternNumber(), i, 0, note, 1)
Modes.mode_init()
def get_tempo_set_status():
return True
def num_gen():
"""seeds and returns 16 bit random number as int"""
rand_obj = _random.Random()
rand_obj.seed()
rand_int = rand_obj.getrandbits(16)
return rand_int
def mapvalues(value, tomin, tomax, frommin, frommax):
"""takes in value and range and returns value within another range"""
input_value = value
solution = tomin + (tomax-(tomin))*((input_value - frommin) / (frommax - (frommin)))
if -0.01 < solution < 0.01:
solution = 0
return solution
class PlusMinus:
zero_status = True
def __init__(self, event):
self.mode = Modes(event)
self.event = event
self.plus_status = False
self.minus_status = False
self.status_maker()
def status_maker(self):
"""reads plus minus button midi data and calls act_out when button is pushed and midi cc is no longer 0 but ignores continued cc
data as to not retrigger until it button is released and cc is reset to 0"""
if self.event.data2 > 64:
if self.plus_status != True and PlusMinus.zero_status == True:
self.plus_status = True
PlusMinus.zero_status = False
self.alter_something(1)
elif self.plus_status == True:
self.plus_status = False
elif self.event.data2 < 64:
if self.minus_status != True and PlusMinus.zero_status == True:
self.minus_status = True
PlusMinus.zero_status = False
self.alter_something(-1)
elif self.minus_status == True:
self.minus_status = False
elif self.event.data1 == 0 and self.event.data2 == 64:
PlusMinus.zero_status = True
self.plus_status = False
self.minus_status = False
def alter_something(self, increment):
self.mode.sub_mode(increment)