-
Notifications
You must be signed in to change notification settings - Fork 2
/
qtgui.py
345 lines (296 loc) · 10.7 KB
/
qtgui.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
from __future__ import print_function
from PyQt5 import QtCore, QtWidgets, QtWidgets
from functools import partial
import mirra
import os
app = None
qtwin = None
fileName = None
snapName = None
poolMenu = None
statusbar = None
sndfolders = []
snapshots = os.path.join( mirra.utilities.get_main_dir(), 'snapshots')
sessions = os.path.join( mirra.utilities.get_main_dir(), 'sessions')
def alert(msg):
# open an alert box with msg (but no alert sound")
box = QtWidgets.QMessageBox()
box.setText(msg)
box.exec_()
def status(st):
statusbar.showMessage(st)
def do(mainapp, win):
global app, statusbar, qtwin
app = mainapp
qtwin = win
statusbar = win.statusBar()
# MENUS ####################
# FILE
fm = win.menuBar().addMenu("&File")
fm.addAction(
QtWidgets.QAction("O&pen", win, shortcut="Ctrl+O", triggered=openFile)
)
fm.addAction(
QtWidgets.QAction("S&ave", win, shortcut="Ctrl+S", triggered=save)
)
fm.addAction(
QtWidgets.QAction("S&ave As", win, shortcut="Ctrl+SHIFT+S", triggered=saveAs)
)
fm.addSeparator() #---------
fm.addAction(
QtWidgets.QAction("D&raw waveform", win, shortcut="Ctrl+F", triggered=setDrawWave)
)
fm.addSeparator() #---------
fm.addAction(
QtWidgets.QAction("E&xit", win, shortcut="Ctrl+Q", triggered=app.end)
)
# SNAPSHOT
sm = win.menuBar().addMenu("&Snapshot")
sm.addAction(
QtWidgets.QAction("O&pen snapshot", win, triggered=openSnapFile)
)
sm.addAction(
QtWidgets.QAction("S&ave snapshot", win, triggered=saveSnap)
)
sm.addAction(
QtWidgets.QAction("S&ave snapshot As", win, triggered=saveSnapAs)
)
fm.addSeparator() #---------
sm.addAction(
QtWidgets.QAction("Toogle load snap mode", win, triggered=app.toogleLoadSnapMode)
)
sm.addSeparator() #---------
for i in range(10):
sm.addAction(
QtWidgets.QAction("L&OAD snapshot %i" %i, win, triggered=partial(setSnapshot, i))
)
sm.addSeparator() #---------
for i in range(10):
sm.addAction(
QtWidgets.QAction("S&TORE snapshot %i" %i, win, triggered=partial(app.storeSnapshot, i))
)
# SOUND POOl
doPoolMenu()
# VOLUME
vm = win.menuBar().addMenu("&Volume")
vm.addAction( # MUTE
QtWidgets.QAction("M&ute", win, shortcut="Ctrl+M", triggered= partial(volChange, 0) )
)
for i in range(1,11): # 1 to 10
n = i
if n == 10: n = 0 # 10 corresponds to key 0
vm.addAction(
QtWidgets.QAction("V&olume %s" %(i/10.), win, shortcut="Ctrl+%s" % n,
triggered= partial(volChange, i) )
)
# NOL
nm = win.menuBar().addMenu("&Num of Layers")
for i in range(1,9):
nm.addAction(
QtWidgets.QAction("%s&" % i, win, triggered = partial(app.nol, i))
)
# AUTO
am = win.menuBar().addMenu("&Auto")
am.addAction( # Auto movement
QtWidgets.QAction("A&utomove toggle", win, triggered=autoNodes )
)
am.addAction( # INCREASE Auto movement
QtWidgets.QAction("I&ncrease movement", win, shortcut="Ctrl++",
triggered=partial(changeAuto, 0.25) )
)
am.addAction( # DECRESE Auto movement
QtWidgets.QAction("D&ecrease movement", win, shortcut="Ctrl+-",
triggered=partial(changeAuto, -0.25) )
)
am.addAction( # Auto movement
QtWidgets.QAction("B&ounce toggle", win, triggered=bounce )
)
am.addSeparator() #---------
am.addAction( # Random
QtWidgets.QAction("R&andom situation", win, shortcut="Ctrl+R",
triggered=app.randomSituation )
)
am.addAction( # Random boxes
QtWidgets.QAction("R&andom Boxes", win, shortcut="Ctrl+B",
triggered=app.randomBoxes )
)
am.addAction( # Random boxes small
QtWidgets.QAction("R&andom step Boxes", win, shortcut="Ctrl+D",
triggered=app.randomBoxesSmall )
)
am.addAction( # Random all nodes
QtWidgets.QAction("R&andom ALL nodes", win, shortcut="Ctrl+N",
triggered=app.randomNodes )
)
am.addAction( # Random B/W NO Pitch!
QtWidgets.QAction("R&andom B/W nodes", win, shortcut="Ctrl+V",
triggered=partial(app.randomNodes, 1) )
)
am.addAction( # Random White
QtWidgets.QAction("R&andom White node", win, shortcut="Ctrl+X",
triggered=partial(app.randomSingleNode, 'white') )
)
am.addAction( # Random White small
QtWidgets.QAction("R&andom step White node", win, shortcut="Ctrl+Z",
triggered=partial(app.randomSingleNode, 'white', 1) )
)
am.addAction( # Random Black
QtWidgets.QAction("R&andom Black node", win, shortcut="Ctrl+C",
triggered=partial(app.randomSingleNode, 'black') )
)
am.addAction( # Random Grey
QtWidgets.QAction("R&andom Grey node", win,
triggered=partial(app.randomSingleNode, 'grey') )
)
# FREEDOMS
fm = win.menuBar().addMenu("&Freedom & control")
fm.addAction(
QtWidgets.QAction("I&nverse Panning", win, triggered=inversepan )
)
## fm.addAction(
## QtWidgets.QAction("T&oggle OSC remote control of handles", win, triggered=app.toggleOSCControl )
## )
## fm.addAction(
## QtWidgets.QAction("R&eset OSC connection", win, triggered=app.setOSC )
## )
fm.addSeparator() #---------
fm.addAction(
QtWidgets.QAction("T&oggle pitch block", win, triggered=partial(toggleFreedom, 'pitch') )
)
fm.addAction(
QtWidgets.QAction("T&oggle grainshift block", win, triggered=partial(toggleFreedom, 'grainshift') )
)
fm.addAction(
QtWidgets.QAction("T&oggle length block", win, triggered=partial(toggleFreedom, 'length') )
)
fm.addAction(
QtWidgets.QAction("T&oggle shift block", win, triggered=partial(toggleFreedom, 'shift') )
)
fm.addAction(
QtWidgets.QAction("T&oggle start block", win, triggered=partial(toggleFreedom, 'start') )
)
########################
def openFile():
global fileName
fileName = str( QtWidgets.QFileDialog.getOpenFileName(qtwin, 'OpenFile', sessions, "Session files (*.txt)")[0] )
if fileName == '' or not fileName: return -1
try :
rawdata = open(fileName, 'rU').read()
except IOError :
alert( "ERROR : file %s does not exist" % fileName )
return -1
app.setSession(rawdata)
def save():
print(fileName)
if fileName == None:
saveAs()
else:
app.saveSession(fileName)
def saveAs():
global fileName
fileName = str( QtWidgets.QFileDialog.getSaveFileName(qtwin, 'Save As', sessions)[0] )
app.saveSession(fileName)
def setDrawWave():
app.setDrawWave()
####################
def openSnapFile():
global snapName
snapName = str( QtWidgets.QFileDialog.getOpenFileName(qtwin, 'OpenFile', snapshots, "Snapshot files (*.txt)")[0] )
if snapName == '' or not snapName: return -1
try :
rawdata = open(snapName, 'rU').read()
except IOError :
alert( "ERROR : snap file %s does not exist" % snapName )
return -1
app.loadSnapshots(rawdata)
def saveSnap():
data = app.getSnapshotJSON()
print(snapName)
if snapName == None:
saveSnapAs()
else:
savedata = open(str(snapName), 'w')
savedata.write(str(data))
savedata.close()
def saveSnapAs():
global snapName
snapName = str( QtWidgets.QFileDialog.getSaveFileName(qtwin, 'Save As', snapshots)[0])
if snapName == '' or not snapName: return -1
saveSnap()
def setSnapshot(index):
try:
app.setSnapshot(index)
except KeyError:
alert( "snapshot %i not defined yet" % index )
#######################
def toggleFreedom(degree): app.freedom[ degree ] = not app.freedom[ degree ]
def volChange(i): app.vol = i/10.0
def autoNodes(): app.autoNodes = not app.autoNodes
def bounce(): app.bounce = not app.bounce
def inversepan(): app.inversepan = not app.inversepan
def changeAuto(i):
app.boxStep = app.boxStep + i
app.updateBoxDelta()
def addSnd():
init = os.path.basename(fileName)
sndfiles = QtWidgets.QFileDialog.getOpenFileNames( qtwin,'Open Sound File', init,
"WAV (*.wav);;FLAC (*.flac);;AIFF (*.aiff)")[0]
for fil in sndfiles:
fil = str(fil)
if fil == '' or not fil: return -1
name = os.path.basename(fil)
poolMenu.addAction(
QtWidgets.QAction("&%s" % name, qtwin,triggered=partial(app.loadSnd, fil))
)
## sndfolders
def addFolder(path=False):
if path == False:
init = os.path.basename(fileName)
path = QtWidgets.QFileDialog.getExistingDirectory(None, 'Select a folder:', init,
QtWidgets.QFileDialog.ShowDirsOnly)
# TO DO: THIS dialogue should allow to see the files. otherwise we dont know whats in the dirs
if os.path.isfile(path): # if selected a file
path = os.path.dirname(path)
for root, dirs, files in os.walk( str(path) ) :
for s in files :
fpath = os.path.join(root, s)
if '.wav' in s or '.flac' in s or '.aiff' in s: ## filter out no sounds
poolMenu.addAction(
QtWidgets.QAction("&%s" % s, qtwin,triggered=partial(app.loadSnd, fpath))
)
if not path in sndfolders:
sndfolders.append(str(path))
def doPoolMenu():
global poolMenu
print("rebuilding sound pool menu")
if not poolMenu:
poolMenu = qtwin.menuBar().addMenu("&SoundPool")
poolMenu.addAction(
QtWidgets.QAction("A&dd sound to pool", qtwin, triggered=addSnd)
)
poolMenu.addAction(
QtWidgets.QAction("A&dd folder to pool", qtwin, triggered=addFolder)
)
poolMenu.addAction(
QtWidgets.QAction("C&LEAR pool", qtwin, triggered=clearMenu)
)
poolMenu.addSeparator() #---------
filePool = doSndMenu()
for f in filePool :
poolMenu.addAction(
QtWidgets.QAction("&%s" % os.path.basename(f), qtwin, triggered=partial(app.loadSnd, f))
)
def clearMenu():
poolMenu.clear()
doPoolMenu()
####################
def doSndMenu() :
# in filename alphabetical order please!!
l = []
p = os.path.join( mirra.utilities.get_main_dir(), 'sounds')
for dirpath, dirnames, fname in os.walk(p) :
for f in fname :
if f[0] != '.' : # mac .DS_Store and other hidden files
## if dirname[0] != '.' : # SVN folders on linux and hidden folders in general
l.append( os.path.join(dirpath, f) )
return l