-
Notifications
You must be signed in to change notification settings - Fork 2
/
kivy_sequencer.py
388 lines (321 loc) · 12.4 KB
/
kivy_sequencer.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
384
385
386
387
388
import os
# os.environ['KIVY_WINDOW'] = 'sdl2'
# os.environ['KIVY_GL_BACKEND'] = 'sdl2'
# USES KIVYTEST36 VENV
# 1. install system dependencies for kivy
# 2. pip install Cython==0.27.3
# 3. pip install git+https://github.com/kivy/kivy.git@master
import kivy
#kivy.require("1.10.0")
import time
from pyo import *
from random import sample
from random import uniform
from string import ascii_lowercase
from kivy.app import App
from kivy.utils import get_color_from_hex
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
# this is so seqgridwidget can be resized without crashing
# this does not affect the filebrowser scrolling when loading/saving a file
from scrollview_edit import ScrollView
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.slider import Slider
from kivy.uix.togglebutton import ToggleButton
from kivy.core.window import Window
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.recyclelayout import RecycleLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.togglebutton import ToggleButton
from kivy.animation import Animation
from kivy.uix.popup import Popup
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelHeader, TabbedPanelItem
from kivy.properties import ObjectProperty, StringProperty, NumericProperty, ListProperty
from kivy.uix.behaviors import DragBehavior
from kivy.graphics import Color
from kivy.graphics import (Rectangle, Ellipse, Line)
from kivy.config import Config
Config.set('graphics', 'width', '1920')
Config.set('graphics', 'height', '1080')
Config.write()
from kivy.core.window import Window
Window.size = (2000, 1500)
from kivy.clock import Clock
from functools import partial
# from aengine import AudioEngine, AudioMixer, AudioItem
from file_dialog import *
from file_save_loader import FileSystem
from aengine_thread import AudioEngine, AudioMixer, AudioItem
# for x in range(120000):
# print("change back to aengine_thread")
import theme
from seq_widget_edit import SeqGridWidget
# for x in range(120000):
# print("switched to seq_widget_edit")
APPNAME = "Sequencer"
BASE_DIR = "sounds/"
class TimingBar(GridLayout):
# step = StringProperty()
pass
INF = float('inf')
class NumericInput(GridLayout):
value = NumericProperty(0)
min = NumericProperty(-INF)
max = NumericProperty(INF)
step = NumericProperty(1)
# text = StringProperty()
def valchange(self, id, value):
print("value change type: {}, value: {}".format(id, value))
app = App.get_running_app()
if id == 'BPB':
app.root.sgr.grid.set_beats_per_bar(value)
class SequencerLayout(BoxLayout):
def __init__(self, **kwargs):
super(SequencerLayout, self).__init__(**kwargs)
self.ae = AudioEngine()
self.am = AudioMixer()
self.ae.start()
# self.ae.run()
self.bpm = 120
self.ticks = 4
self.metro_val = (60000 / self.bpm / self.ticks) * 0.001
print(self.metro_val, "bpm")
self.sgr = SeqGridWidget()
self.timingbar = TimingBar()
self.timingbar.ids.step.text="hey"
# print(item)
self.loop = False
self.current_sound=""
self.tracks = [] # PUT THIS IN AENGINE CLASS
# self.m = Metro(self.metro_val).play()
# for x in range(100):
# print("METRO IS DISABLED")
# self.tf = TrigFunc(self.m, self.trigged)
self.file_loader = FileLoader()
self.file_system = FileSystem()
self.inc = 0
self.sample_filename_list = []
# print("Current dir", os.getcwd())
path = os.path.dirname(os.path.abspath(__file__))
for file in os.listdir(path+"\\sounds\\"):
if file.endswith(".wav"):
self.sample_filename_list.append(file)
# self.am.addTrack("sounds/" + file)
print(self.sample_filename_list)
# self.ae.record()
# TrigFunc(self.ae.m, self.trigged)
def trigged(self):
# print('trigged')
app = App.get_running_app()
self.ae.playsound("sounds/kick2.wav")
# self.ae.run()
# app.root.Seqdget.move_playhead()
self.sgr.move_playhead()
# SeqGridWidget.move_playhead()
class LoadDialog(FloatLayout):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
class SaveDialog(FloatLayout):
save = ObjectProperty(None)
text_input = ObjectProperty(None)
cancel = ObjectProperty(None)
class Transport(BoxLayout):
def button_about(self):
print("about pressed")
cont = GridLayout(cols=1)
about_txt = "{appname}\n" \
"Created on 6/23/18 \nby Sam H." \
"".format(appname=APPNAME)
cont.add_widget(Label(text=about_txt))
popup = Popup(title='About {}'.format(APPNAME),
content=cont,
size_hint=(None, None), size=(400, 400))
popup.open()
# Options audio output selector callback
# this handles the dynamic buttons
def audio_opts_button_callback(self, instance):
print("but was clicked", instance.text)
app = App.get_running_app()
app.root.ae.set_output(4)
def bpm_text(self, instance):
print("text was entered")
print(instance.text)
app = App.get_running_app()
app.root.m.setTime((60000 / int(instance.text) / 4) * 0.001)
def button_loop(self, button):
print("loop")
app = App.get_running_app()
# app.root.sgr.loop = True
if button.state == "down":
print("down")
# app.root.sgr.loop = True
app.root.sgr.loop_bars.loop_func(True)
else:
# app.root.sgr.loop = False
app.root.sgr.loop_bars.loop_func(False)
print("up")
def button_open_project(self):
print("project opened")
app = App.get_running_app()
app.root.file_loader.show_load()
def button_save_project(self):
print("project saved")
app = App.get_running_app()
app.root.file_loader.show_save()
def button_options(self):
print("options pressed")
app = App.get_running_app()
cont = GridLayout(cols=1)
# retrieve audio outputs / soundcards from audioengine class
out_list = app.root.ae.get_outputs()
print(out_list)
# combine out_list, add to output selector
for x, y in zip(*out_list):
# intentional error to remember where left off
b = Button(id="{}".format(y), text="{} {}".format(x,y))
b.bind(on_press=self.audio_opts_button_callback)
cont.add_widget(b)
for x in self.children:
print(x)
tp = TabbedPanel(do_default_tab=False)
# audio tab
th_audio = TabbedPanelItem(text="Audio")
th_audio.content = GridLayout()
th_audio.add_widget(cont)
# files tab
th_files = TabbedPanelItem(text="Files")
th_files.add_widget(Button(text="files tab content"))
tp.add_widget(th_audio)
tp.add_widget(th_files)
popup = Popup(title='Options',
content=tp,
size_hint=(None, None), size=(800, 800))
popup.open()
def button_play(self):
print("play pressed")
app = App.get_running_app()
app.root.m.play()
def button_stop(self):
print("stop pressed")
app = App.get_running_app()
app.root.m.stop()
# Filename lister on left
class Row(Button):
# button pressed
def button_pressed(self):
app = App.get_running_app()
print(self.text)
selectedsound = self.text
print("sel", selectedsound)
path = "sounds/" + selectedsound
app.root.ae.playsound(path)
print("Selected sound is: ", BASE_DIR + selectedsound)
app.root.sgr.current_sound = BASE_DIR + selectedsound
app.root.current_sound = BASE_DIR + selectedsound
class FilenameLister(RecycleView):
pass
class StepPanelScroll(ScrollView):
pass
class StepPanel_grid_base(GridLayout):
def button_pressed(self, *args):
print("buttonpressed")
class StepRowPanel(GridLayout):
pass
class PlayheadControlBar(GridLayout):
pass
class SequencerApp(App):
def __init__(self, **kwargs):
super(SequencerApp, self).__init__(**kwargs)
def build(self):
TRACK_COUNT = 26
STEP_COUNT = 16
self.title = APPNAME
sequencer_layout = SequencerLayout()
sequencer_layout_grid = GridLayout(cols=1, id="rowcontainer")
transport = Transport()
transport.size=(200,80)
timingbar = sequencer_layout.timingbar
timingbar.size_hint_x = .2
timingbar.ids.step.text="arstrsts"
transport.add_widget(timingbar)
playhead_control_bar = PlayheadControlBar()
# mixer_panel_grid
mixer_panel_grid = GridLayout(
rows=1, padding=10, spacing=10, size_hint=(None, 1))
mixer_panel_grid.bind(minimum_width=mixer_panel_grid.setter('width'))
# Effects box
effects_box = BoxLayout(orientation='vertical')
effects_box.add_widget(Label(text="Reverb"))
effects_box.add_widget(Label(text="Echo"))
effects_box.add_widget(Label(text="Delay"))
effects_box.add_widget(Label(text="Distortion"))
# Vertical buttons in mixer_panel_grid
anothergrid = GridLayout(cols=1,size_hint_x=None, width=200)
anothergrid.canvas.add(Color(*theme.about_button))
anothergrid.canvas.add(Rectangle(pos=anothergrid.pos,size=anothergrid.size))
anothergrid.bind(minimum_width=anothergrid.setter('width'))
# for x in range(10):
# anothergrid.add_widget(Button(text="anothergrid", size_hint_x=1))
# anothergrid.add_widget(Label(text="anothergrid", size_hint_y=2))
anothergrid.add_widget(Slider(orientation='vertical'))
anothergrid.add_widget(effects_box)
# anothergrid.add_widget(Label(text="anothergrid", size_hint_x=1))
# add anothergrid to mixer_panel_grid
mixer_panel_grid.add_widget(anothergrid)
# mixer_base holds mixer_panel_grid
mixer_base = ScrollView(
size_hint=(1, None),
size=(200, 400),
do_scroll_y=False,
do_scroll_x=True)
# Add mixer_panel_grid to mixer_base (Scrollview)
mixer_base.add_widget(mixer_panel_grid)
# use this later for sizing / hiding / showing the panel
# mixer_base.size_hint_y = None
# mixer_base.height = 0
step_base = ScrollView(
size_hint=(1,1),
do_scroll_y=True,
do_scroll_x=True)
step_base.bar_width=20
step_base.scroll_type = ['bars']
# Sequencer widget (seq_widget.py)
# SeqWidgetObject = SeqGridWidget()
SeqWidgetObject = sequencer_layout.sgr
# side_panel = sequencer_layout.side_panel
# Add sequencer widget to main panel (step_base)
step_base.add_widget(SeqWidgetObject)
# File name lister on left
file_list = FilenameLister()
file_list.size_hint_x = .13
sample_filename_list = []
path = os.path.dirname(os.path.abspath(__file__))
for file in os.listdir(path+"/sounds"):
if file.endswith(".wav"):
sample_filename_list.append(file)
file_list.data.insert(0, {'value': file})
sequencer_layout.add_widget(file_list)
sequencer_layout_grid.add_widget(transport)
# sequencer_layout_grid.add_widget()
# sequencer_layout_grid.add_widget(playhead_control_bar)
sequencer_layout_grid.add_widget(step_base)
app = App.get_running_app()
for i in range(TRACK_COUNT):
# Add number of mixer panels per track added
# mixer_panel_grid.add_widget(anothergrid)
mixer_panel_grid.add_widget(
Label(
text="Mix Panel \n" + str(sample_filename_list[i]),
height=220,
width=150,
size_hint_x=None))
# mixer_panel_grid.add_widget(effects_box)
# mixer_panel_grid.add_widget(BoxLayout())
sequencer_layout_grid.add_widget(mixer_base)
sequencer_layout.add_widget(sequencer_layout_grid)
return sequencer_layout
seq_app = SequencerApp()
seq_app.run()