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
|
#!/usr/bin/env python
import pygtk
pygtk.require( '2.0' )
import gtk
import Config
from Util.ThemeWidgets import *
Tooltips = Config.Tooltips
class InstrumentPanel( gtk.EventBox ):
def __init__(self,setInstrument = None, playInstrument = None, enterMode = False, micRec = None, synthRec = None, rowLen = 8, _instDic = None ):
gtk.EventBox.__init__(self)
color = gtk.gdk.color_parse(Config.PANEL_BCK_COLOR)
self.modify_bg(gtk.STATE_NORMAL, color)
self.tooltips = gtk.Tooltips()
self.setInstrument = setInstrument
self.playInstrument = playInstrument
self.micRec = micRec
self.synthRec = synthRec
self.rowLen = rowLen
self.enterMode = enterMode
self.instrumentBox = None
self.recstate = False
self.instDic = {}
self.mainVBox = gtk.VBox()
self.draw_toolbar()
if _instDic == None:
self.instDic = self.getInstDic()
else:
self.instDic = _instDic
self.draw_instruments_panel()
self.add(self.mainVBox)
self.show_all()
def draw_toolbar(self):
toolbarBox = gtk.HBox()
self.firstTbBtn = None
for category in Config.CATEGORIES:
btnBox = RoundVBox(fillcolor = '#6F947B', bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS)
btnBox.set_border_width(Config.PANEL_SPACING)
btn = ImageRadioButton(self.firstTbBtn,Config.IMAGE_ROOT + category + '.png', Config.IMAGE_ROOT + category + 'sel.png', Config.IMAGE_ROOT + category + 'sel.png')
if self.firstTbBtn == None:
self.firstTbBtn = btn
btn.connect('clicked',self.handleToolbarBtnPress,category)
btnBox.add(btn)
toolbarBox.pack_start(btnBox,True,True)
self.mainVBox.pack_start(toolbarBox,False,False)
def selectFirstCat(self):
self.firstTbBtn.set_active(True)
def handleToolbarBtnPress(self, widget, category):
self.draw_instruments_panel(category)
def draw_instruments_panel(self,category = 'all'):
if self.instrumentBox != None:
for child in self.instTable.get_children():
self.instTable.remove(child)
for child in self.scrollWin.get_children():
self.scrollWin.remove(child)
for child in self.instrumentBox.get_children():
self.instrumentBox.remove(child)
self.instrumentBox.destroy()
self.instrumentBox = RoundHBox(fillcolor = Config.PANEL_COLOR, bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS)
instrumentNum = len(self.getInstrumentList(category))
instruments = self.getInstrumentList(category)
cols = self.rowLen
if instrumentNum < cols:
cols = instrumentNum
rows = (instrumentNum // cols)
if instrumentNum % cols is not 0: #S'il y a un reste
rows = rows + 1
self.scrollWin = gtk.ScrolledWindow()
self.scrollWin.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC)
self.instTable = gtk.Table(rows,cols,True)
self.instTable.set_row_spacings(0)
self.instTable.set_col_spacings(0)
for row in range(rows):
for col in range(cols):
if row*cols+col >= instrumentNum:
break
instBox = self.instDic[instruments[row*cols+col]]
self.instTable.attach(instBox, col, col+1, row, row+1, gtk.SHRINK, gtk.SHRINK, 0, 0)
tableEventBox = gtk.EventBox()
color = gtk.gdk.color_parse(Config.PANEL_COLOR)
tableEventBox.modify_bg(gtk.STATE_NORMAL, color)
tableEventBox.add(self.instTable)
self.scrollWin.add_with_viewport(tableEventBox)
self.instrumentBox.pack_start(self.scrollWin,True,True,0)
self.mainVBox.pack_start(self.instrumentBox)
self.show_all()
def handleInstrumentButtonClick(self,widget,instrument):
if widget.get_active() is True and self.recstate == False:
if self.setInstrument: self.setInstrument(instrument)
if self.playInstrument: self.playInstrument(instrument)
if self.enterMode:
pass #Close the window
def handleInstrumentButtonEnter(self,widget,instrument):
if self.playInstrument: self.playInstrument(instrument)
def handleMicRecButtonClick(self,widget,mic):
self.recstate = False
self.setInstrument(mic)
if self.micRec: self.micRec(mic)
def handleSynthRecButtonClick(self,widget,lab):
self.recstate = False
self.setInstrument(lab)
if self.synthRec: self.synthRec(lab)
def handleRecButtonPress(self,widget,btn):
self.recstate = True
btn.set_active(True)
def getInstDic(self):
instDic = {}
self.firstInstButton = None
for instrument in self.getInstrumentList('all'):
if instrument[0:3] == 'lab' or instrument[0:3] == 'mic':
vbox = RoundVBox(fillcolor = Config.INST_BCK_COLOR, bordercolor = Config.PANEL_COLOR, radius = Config.PANEL_RADIUS)
vbox.set_border_width(Config.PANEL_SPACING)
Btn = ImageRadioButton(self.firstInstButton, Config.IMAGE_ROOT + instrument + '.png' , Config.IMAGE_ROOT + instrument + 'sel.png', Config.IMAGE_ROOT + instrument + 'sel.png')
if self.firstInstButton == None:
self.firstInstButton = Btn
RecBtn = ImageButton(Config.IMAGE_ROOT + 'record.png' , Config.IMAGE_ROOT + 'recordsel.png', Config.IMAGE_ROOT + 'recordhi.png')
self.tooltips.set_tip(RecBtn,Tooltips.RECMIC)
if instrument[0:3] == 'lab':
self.tooltips.set_tip(RecBtn,Tooltips.RECLAB)
Btn.connect('clicked', self.handleInstrumentButtonClick, instrument)
if instrument[0:3] == 'mic':
RecBtn.connect('clicked', self.handleMicRecButtonClick, instrument)
if instrument[0:3] == 'lab':
RecBtn.connect('clicked', self.handleSynthRecButtonClick, instrument)
RecBtn.connect('pressed', self.handleRecButtonPress, Btn)
vbox.pack_start(RecBtn,False,False,1)
vbox.pack_start(Btn,False,False,2)
instDic[instrument] = vbox
else:
instBox = RoundVBox(fillcolor = Config.INST_BCK_COLOR, bordercolor = Config.PANEL_COLOR, radius = Config.PANEL_RADIUS)
instBox.set_border_width(Config.PANEL_SPACING)
instButton = ImageRadioButton(self.firstInstButton, Config.IMAGE_ROOT + instrument + '.png' , Config.IMAGE_ROOT + instrument + 'sel.png', Config.IMAGE_ROOT + instrument + 'sel.png')
instButton.connect('clicked',self.handleInstrumentButtonClick, instrument)
if self.enterMode:
instButton.connect('enter',self.handleInstrumentButtonEnter, instrument)
instBox.pack_start(instButton,False,False)
instDic[instrument] = instBox
if self.firstInstButton == None:
self.firstInstButton = instButton
return instDic
def set_activeInstrument(self,instrument, state):
if len(self.instDic) > 0:
for key in self.instDic:
if key == instrument:
self.instDic[key].get_children()[0].set_active(state)
def getInstrumentList(self,category = 'all'):
instrumentList = [instrument for instrument in Config.INSTRUMENTS.keys() if instrument[0:4] != 'drum' and instrument[0:4] != 'guid' and instrument[0:3] != 'mic' and instrument[0:3] != 'lab'] + Config.DRUMKITS + ['mic1', 'mic2', 'mic3', 'mic4', 'lab1', 'lab2', 'lab3', 'lab4']
if self.enterMode:
instrumentList = [instrument for instrument in Config.INSTRUMENTS.keys() if instrument[0:4] != 'drum' and instrument[0:4] != 'guid' and instrument[0:3] != 'mic' and instrument[0:3] != 'lab'] + ['mic1', 'mic2', 'mic3', 'mic4', 'lab1', 'lab2', 'lab3', 'lab4']
if category != 'all':
instrumentList = [instrument for instrument in Config.INSTRUMENTS.keys() if instrument[0:4] != 'drum' and instrument[0:4] != 'guid' and Config.INSTRUMENTS[instrument].category == category]
if category == 'percussions' and not self.enterMode:
instrumentList = Config.DRUMKITS + instrumentList
if category == 'people':
instrumentList = instrumentList + ['mic1', 'mic2', 'mic3', 'mic4']
if category == 'electronic':
instrumentList = instrumentList + ['lab1', 'lab2', 'lab3', 'lab4']
#instrumentList = instrumentList.sort(lambda g,l: cmp(Config.INSTRUMENTS[g].category, Config.INSTRUMENTS[l].category) )
return instrumentList
class DrumPanel( gtk.EventBox ):
def __init__(self, setDrum = None):
gtk.EventBox.__init__(self)
color = gtk.gdk.color_parse(Config.PANEL_BCK_COLOR)
self.modify_bg(gtk.STATE_NORMAL, color)
self.setDrum = setDrum
self.drawDrums()
def drawDrums(self):
firstBtn = None
btnBox = RoundHBox(fillcolor = '#6F947B', bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS)
btnBox.set_border_width(Config.PANEL_SPACING)
self.drums = {}
for drumkit in Config.DRUMKITS:
instBox = RoundVBox(fillcolor = Config.INST_BCK_COLOR, bordercolor = Config.PANEL_COLOR, radius = Config.PANEL_RADIUS)
instBox.set_border_width(Config.PANEL_SPACING)
self.drums[drumkit] = ImageRadioButton(firstBtn, Config.IMAGE_ROOT + drumkit + '.png' , Config.IMAGE_ROOT + drumkit + 'sel.png', Config.IMAGE_ROOT + drumkit + 'sel.png')
self.drums[drumkit].connect('clicked',self.setDrums,drumkit)
if firstBtn == None:
firstBtn = self.drums[drumkit]
instBox.pack_start(self.drums[drumkit], False, False, 0)
btnBox.pack_start(instBox, False, False, 0)
self.add(btnBox)
self.show_all()
def setDrums(self,widget,data):
if widget.get_active():
if self.setDrum: self.setDrum(data)
if __name__ == "__main__":
win = gtk.Window()
wc = DrumPanel(None)
win.add(wc)
win.show()
#start the gtk event loop
gtk.main()
|