Attempt at implementing per-channel output setting in the sampler.
[calfbox.git] / example.py
bloba95bddf65495c46c791273d98fe69825f4d98e19
1 import sys
2 sys.argv = []
3 from gi.repository import GObject, Gdk, Gtk
4 import math
6 sys.path = ["./py"] + sys.path
8 import cbox
9 from gui_tools import *
10 import fx_gui
11 import instr_gui
12 import drumkit_editor
13 #import drum_pattern_editor
15 class SceneDialog(SelectObjectDialog):
16 title = "Select a scene"
17 def __init__(self, parent):
18 SelectObjectDialog.__init__(self, parent)
19 def update_model(self, model):
20 for s in cbox.Config.sections("scene:"):
21 title = s["title"]
22 model.append((s.name[6:], "Scene", s.name, title))
23 for s in cbox.Config.sections("instrument:"):
24 title = s["title"]
25 model.append((s.name[11:], "Instrument", s.name, title))
26 for s in cbox.Config.sections("layer:"):
27 title = s["title"]
28 model.append((s.name[6:], "Layer", s.name, title))
30 class NewLayerDialog(SelectObjectDialog):
31 title = "Create a layer"
32 def __init__(self, parent):
33 SelectObjectDialog.__init__(self, parent)
34 def update_model(self, model):
35 for engine_name, wclass in instr_gui.instrument_window_map.items():
36 model.append((engine_name, "Engine", engine_name, ""))
38 class LoadLayerDialog(SelectObjectDialog):
39 title = "Load a layer"
40 def __init__(self, parent):
41 SelectObjectDialog.__init__(self, parent)
42 def update_model(self, model):
43 for s in cbox.Config.sections("instrument:"):
44 title = s["title"]
45 model.append((s.name[11:], "Instrument", s.name, title))
46 for s in cbox.Config.sections("layer:"):
47 title = s["title"]
48 model.append((s.name[6:], "Layer", s.name, title))
50 class PlayPatternDialog(SelectObjectDialog):
51 title = "Play a drum pattern"
52 def __init__(self, parent):
53 SelectObjectDialog.__init__(self, parent)
54 def update_model(self, model):
55 model.append((None, "Stop", "", ""))
56 for s in cbox.Config.sections("drumpattern:"):
57 title = s["title"]
58 model.append((s.name[12:], "Pattern", s.name, title))
59 for s in cbox.Config.sections("drumtrack:"):
60 title = s["title"]
61 model.append((s.name[10:], "Track", s.name, title))
63 in_channels_ls = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING)
64 in_channels_ls.append((0, "All"))
65 out_channels_ls = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING)
66 out_channels_ls.append((0, "Same"))
67 for i in range(1, 17):
68 in_channels_ls.append((i, str(i)))
69 out_channels_ls.append((i, str(i)))
70 notes_ls = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING)
71 opt_notes_ls = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING)
72 opt_notes_ls.append((-1, "N/A"))
73 for i in range(0, 128):
74 notes_ls.append((i, note_to_name(i)))
75 opt_notes_ls.append((i, note_to_name(i)))
76 transpose_ls = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING)
77 for i in range(-60, 61):
78 transpose_ls.append((i, str(i)))
80 class SceneLayersModel(Gtk.ListStore):
81 def __init__(self):
82 Gtk.ListStore.__init__(self, GObject.TYPE_STRING, GObject.TYPE_BOOLEAN,
83 GObject.TYPE_INT, GObject.TYPE_INT, GObject.TYPE_BOOLEAN,
84 GObject.TYPE_INT, GObject.TYPE_INT, GObject.TYPE_INT, GObject.TYPE_INT, GObject.TYPE_STRING)
85 #def make_row_item(self, opath, tree_path):
86 # return opath % self[(1 + int(tree_path))]
87 def make_row_item(self, opath, tree_path):
88 return cbox.Document.uuid_cmd(self[int(tree_path)][-1], opath)
89 def refresh(self, scene_status):
90 self.clear()
91 for layer in scene_status.layers:
92 ls = layer.status()
93 self.append((ls.instrument_name, ls.enable != 0, ls.in_channel, ls.out_channel, ls.consume != 0, ls.low_note, ls.high_note, ls.fixed_note, ls.transpose, layer.uuid))
95 class SceneLayersView(Gtk.TreeView):
96 def __init__(self, model):
97 Gtk.TreeView.__init__(self, model)
98 self.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, [("text/plain", 0, 1)], Gdk.DragAction.MOVE)
99 self.enable_model_drag_dest([("text/plain", Gtk.TargetFlags.SAME_APP | Gtk.TargetFlags.SAME_WIDGET, 1)], Gdk.DragAction.MOVE)
100 self.connect('drag_data_get', self.drag_data_get)
101 self.connect('drag_data_received', self.drag_data_received)
102 self.insert_column_with_attributes(0, "On?", standard_toggle_renderer(model, "/enable", 1), active=1)
103 self.insert_column_with_attributes(1, "Name", Gtk.CellRendererText(), text=0)
104 self.insert_column_with_data_func(2, "In Ch#", standard_combo_renderer(model, in_channels_ls, "/in_channel", 2), lambda column, cell, model, iter, data: cell.set_property('text', "%s" % model[iter][2] if model[iter][2] != 0 else 'All'), None)
105 self.insert_column_with_data_func(3, "Out Ch#", standard_combo_renderer(model, out_channels_ls, "/out_channel", 3), lambda column, cell, model, iter, data: cell.set_property('text', "%s" % model[iter][3] if model[iter][3] != 0 else 'Same'), None)
106 self.insert_column_with_attributes(4, "Eat?", standard_toggle_renderer(model, "/consume", 4), active=4)
107 self.insert_column_with_data_func(5, "Lo N#", standard_combo_renderer(model, notes_ls, "/low_note", 5), lambda column, cell, model, iter, data: cell.set_property('text', note_to_name(model[iter][5])), None)
108 self.insert_column_with_data_func(6, "Hi N#", standard_combo_renderer(model, notes_ls, "/high_note", 6), lambda column, cell, model, iter, data: cell.set_property('text', note_to_name(model[iter][6])), None)
109 self.insert_column_with_data_func(7, "Fix N#", standard_combo_renderer(model, opt_notes_ls, "/fixed_note", 7), lambda column, cell, model, iter, data: cell.set_property('text', note_to_name(model[iter][7])), None)
110 self.insert_column_with_attributes(8, "Transpose", standard_combo_renderer(model, transpose_ls, "/transpose", 8), text=8)
111 def drag_data_get(self, treeview, context, selection, target_id, etime):
112 cursor = treeview.get_cursor()
113 if cursor is not None:
114 selection.set('text/plain', 8, str(cursor[0][0]))
115 def drag_data_received(self, treeview, context, x, y, selection, info, etime):
116 src_row = int(selection.data)
117 dest_row_info = treeview.get_dest_row_at_pos(x, y)
118 if dest_row_info is not None:
119 dest_row = dest_row_info[0][0]
120 #print src_row, dest_row, dest_row_info[1]
121 scene = cbox.Document.get_scene()
122 scene.move_layer(src_row, dest_row)
123 self.get_model().refresh(scene.status())
125 class SceneAuxBusesModel(Gtk.ListStore):
126 def __init__(self):
127 Gtk.ListStore.__init__(self, GObject.TYPE_STRING, GObject.TYPE_STRING)
128 def refresh(self, scene_status):
129 self.clear()
130 for aux_name, aux_obj in scene_status.auxes.items():
131 slot = aux_obj.slot.status()
132 self.append((slot.insert_preset, slot.insert_engine))
134 class SceneAuxBusesView(Gtk.TreeView):
135 def __init__(self, model):
136 Gtk.TreeView.__init__(self, model)
137 self.insert_column_with_attributes(0, "Name", Gtk.CellRendererText(), text=0)
138 self.insert_column_with_attributes(1, "Engine", Gtk.CellRendererText(), text=1)
139 def get_current_row(self):
140 if self.get_cursor()[0] is None:
141 return None, None
142 row = self.get_cursor()[0][0]
143 return row + 1, self.get_model()[row]
145 class StatusBar(Gtk.Statusbar):
146 def __init__(self):
147 Gtk.Statusbar.__init__(self)
148 self.sample_rate_label = Gtk.Label("")
149 self.pack_start(self.sample_rate_label, False, False, 2)
150 self.status = self.get_context_id("Status")
151 self.sample_rate = self.get_context_id("Sample rate")
152 self.push(self.status, "")
153 self.push(self.sample_rate, "-")
154 def update(self, status, sample_rate):
155 self.pop(self.status)
156 self.push(self.status, status)
157 self.sample_rate_label.set_text("%s Hz" % sample_rate)
159 class MainWindow(Gtk.Window):
160 def __init__(self):
161 Gtk.Window.__init__(self, Gtk.WindowType.TOPLEVEL)
162 self.vbox = Gtk.VBox(spacing = 5)
163 self.add(self.vbox)
164 self.create()
165 set_timer(self, 30, self.update)
166 #self.drum_pattern_editor = None
167 self.drumkit_editor = None
169 def create(self):
170 self.menu_bar = Gtk.MenuBar()
172 self.menu_bar.append(create_menu("_Scene", [
173 ("_Load", self.load_scene),
174 ("_Quit", self.quit),
176 self.menu_bar.append(create_menu("_Layer", [
177 ("_New", self.layer_new),
178 ("_Load", self.layer_load),
179 ("_Remove", self.layer_remove),
181 self.menu_bar.append(create_menu("_AuxBus", [
182 ("_Add", self.aux_bus_add),
183 ("_Edit", self.aux_bus_edit),
184 ("_Remove", self.aux_bus_remove),
186 self.menu_bar.append(create_menu("_Tools", [
187 ("_Drum Kit Editor", self.tools_drumkit_editor),
188 ("_Play Drum Pattern", self.tools_play_drum_pattern),
189 #("_Edit Drum Pattern", self.tools_drum_pattern_editor),
190 ("_Un-zombify", self.tools_unzombify),
191 ("_Object list", self.tools_object_list),
192 ("_Wave bank dump", self.tools_wave_bank_dump),
195 self.vbox.pack_start(self.menu_bar, False, False, 0)
196 rt_status = cbox.Document.get_rt().status()
197 scene = cbox.Document.get_scene()
198 self.nb = Gtk.Notebook()
199 self.vbox.add(self.nb)
200 self.nb.append_page(self.create_master(scene), Gtk.Label("Master"))
201 self.status_bar = StatusBar()
202 self.vbox.pack_start(self.status_bar, False, False, 0)
203 self.create_instrument_pages(scene.status(), rt_status)
205 def create_master(self, scene):
206 scene_status = scene.status()
207 self.master_info = left_label("")
208 self.timesig_info = left_label("")
210 t = Gtk.Table(3, 8)
211 t.set_col_spacings(5)
212 t.set_row_spacings(5)
214 t.attach(bold_label("Scene"), 0, 1, 0, 1, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
215 self.scene_label = left_label(scene_status.name)
216 t.attach(self.scene_label, 1, 3, 0, 1, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
218 self.title_label = left_label(scene_status.title)
219 t.attach(bold_label("Title"), 0, 1, 1, 2, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
220 t.attach(self.title_label, 1, 3, 1, 2, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
222 t.attach(bold_label("Play pos"), 0, 1, 2, 3, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
223 t.attach(self.master_info, 1, 3, 2, 3, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
225 t.attach(bold_label("Time sig"), 0, 1, 3, 4, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
226 t.attach(self.timesig_info, 1, 2, 3, 4, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
227 hb = Gtk.HButtonBox()
228 b = Gtk.Button("Play")
229 b.connect('clicked', lambda w: cbox.Transport.play())
230 hb.pack_start(b, False, False, 5)
231 b = Gtk.Button("Stop")
232 b.connect('clicked', lambda w: cbox.Transport.stop())
233 hb.pack_start(b, False, False, 5)
234 b = Gtk.Button("Rewind")
235 b.connect('clicked', lambda w: cbox.Transport.seek_ppqn(0))
236 hb.pack_start(b, False, False, 5)
237 b = Gtk.Button("Panic")
238 b.connect('clicked', lambda w: cbox.Transport.panic())
239 hb.pack_start(b, False, False, 5)
240 t.attach(hb, 2, 3, 3, 4, Gtk.AttachOptions.EXPAND, Gtk.AttachOptions.SHRINK)
242 t.attach(bold_label("Tempo"), 0, 1, 4, 5, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
243 self.tempo_adj = Gtk.Adjustment(40, 40, 300, 1, 5, 0)
244 self.tempo_adj.connect('value_changed', adjustment_changed_float, cbox.VarPath("/master/set_tempo"))
245 t.attach(standard_hslider(self.tempo_adj), 1, 3, 4, 5, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
247 t.attach(bold_label("Transpose"), 0, 1, 5, 6, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
248 self.transpose_adj = Gtk.Adjustment(scene_status.transpose, -24, 24, 1, 5, 0)
249 self.transpose_adj.connect('value_changed', adjustment_changed_int, cbox.VarPath('/scene/transpose'))
250 t.attach(standard_align(Gtk.SpinButton(adjustment = self.transpose_adj), 0, 0, 0, 0), 1, 3, 5, 6, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
252 self.layers_model = SceneLayersModel()
253 self.layers_view = SceneLayersView(self.layers_model)
254 t.attach(standard_vscroll_window(-1, 160, self.layers_view), 0, 3, 6, 7, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
256 self.auxes_model = SceneAuxBusesModel()
257 self.auxes_view = SceneAuxBusesView(self.auxes_model)
258 t.attach(standard_vscroll_window(-1, 120, self.auxes_view), 0, 3, 7, 8, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
260 self.layers_model.refresh(scene_status)
261 self.auxes_model.refresh(scene_status)
263 return t
265 def quit(self, w):
266 self.destroy()
268 def load_scene(self, w):
269 d = SceneDialog(self)
270 response = d.run()
271 try:
272 if response == Gtk.ResponseType.OK:
273 scene = cbox.Document.get_scene()
274 item_name, item_type, item_key, item_label = d.get_selected_object()
275 if item_type == 'Scene':
276 scene.load(item_name)
277 elif item_type == 'Layer':
278 scene.clear()
279 scene.add_layer(item_name)
280 elif item_type == 'Instrument':
281 scene.clear()
282 scene.add_instrument_layer(item_name)
283 scene_status = scene.status()
284 self.scene_label.set_text(scene_status.name)
285 self.title_label.set_text(scene_status.title)
286 self.refresh_instrument_pages(scene_status)
287 finally:
288 d.destroy()
290 def layer_load(self, w):
291 d = LoadLayerDialog(self)
292 response = d.run()
293 try:
294 if response == Gtk.ResponseType.OK:
295 scene = cbox.Document.get_scene()
296 item_name, item_type, item_key, item_label = d.get_selected_object()
297 if item_type == 'Layer':
298 scene.add_layer(item_name)
299 elif item_type == 'Instrument':
300 scene.add_instrument_layer(item_name)
301 self.refresh_instrument_pages()
302 finally:
303 d.destroy()
305 def layer_new(self, w):
306 d = NewLayerDialog(self)
307 response = d.run()
308 try:
309 if response == Gtk.ResponseType.OK:
310 scene = cbox.Document.get_scene()
311 keys = scene.status().instruments.keys()
312 engine_name = d.get_selected_object()[0]
313 for i in range(1, 1001):
314 name = "%s%s" % (engine_name, i)
315 if name not in keys:
316 break
317 scene.add_new_instrument_layer(name, engine_name)
318 self.refresh_instrument_pages()
319 finally:
320 d.destroy()
322 def layer_remove(self, w):
323 if self.layers_view.get_cursor()[0] is not None:
324 pos = self.layers_view.get_cursor()[0][0]
325 cbox.Document.get_scene().delete_layer(pos)
326 self.refresh_instrument_pages()
328 def aux_bus_add(self, w):
329 d = fx_gui.LoadEffectDialog(self)
330 response = d.run()
331 try:
332 cbox.do_cmd("/scene/load_aux", None, [d.get_selected_object()[0]])
333 self.refresh_instrument_pages()
334 finally:
335 d.destroy()
336 def aux_bus_remove(self, w):
337 rowid, row = self.auxes_view.get_current_row()
338 if rowid is None:
339 return
340 cbox.do_cmd("/scene/delete_aux", None, [row[0]])
341 self.refresh_instrument_pages()
343 def aux_bus_edit(self, w):
344 rowid, row = self.auxes_view.get_current_row()
345 if rowid is None:
346 return
347 wclass = fx_gui.effect_window_map[row[1]]
348 popup = wclass("Aux: %s" % row[0], self, "/scene/aux/%s/slot/engine" % row[0])
349 popup.show_all()
350 popup.present()
352 def tools_unzombify(self, w):
353 cbox.do_cmd("/rt/cycle", None, [])
355 def tools_drumkit_editor(self, w):
356 if self.drumkit_editor is None:
357 self.drumkit_editor = drumkit_editor.EditorDialog(self)
358 self.refresh_instrument_pages()
359 self.drumkit_editor.connect('destroy', self.on_drumkit_editor_destroy)
360 self.drumkit_editor.show_all()
361 self.drumkit_editor.present()
363 def on_drumkit_editor_destroy(self, w):
364 self.drumkit_editor = None
366 def tools_object_list(self, w):
367 cbox.Document.dump()
369 def tools_wave_bank_dump(self, w):
370 for w in cbox.get_thing('/waves/list', '/waveform', [str]):
371 info = cbox.GetThings("/waves/info", ["filename", "name", "bytes", "loop"], [w])
372 print("%s: %d bytes, loop = %s" % (info.filename, info.bytes, info.loop))
374 def tools_play_drum_pattern(self, w):
375 d = PlayPatternDialog(self)
376 response = d.run()
377 try:
378 if response == Gtk.ResponseType.OK:
379 row = d.get_selected_object()
380 if row[1] == 'Pattern':
381 song = cbox.Document().get_song()
382 song.loop_single_pattern(lambda: song.load_drum_pattern(row[0]))
383 elif row[1] == 'Track':
384 song = cbox.Document().get_song()
385 song.loop_single_pattern(lambda: song.load_drum_track(row[0]))
386 elif row[1] == 'Stop':
387 song = cbox.Document().get_song()
388 song.clear()
389 song.update_playback()
390 tracks = song.status().tracks
391 if len(tracks):
392 for track_item in tracks:
393 track_item.track.set_external_output(cbox.Document.get_scene().uuid)
394 song.update_playback()
396 finally:
397 d.destroy()
399 def tools_drum_pattern_editor(self, w):
400 if self.drum_pattern_editor is None:
401 length = drum_pattern_editor.PPQN * 4
402 pat_data = cbox.Pattern.get_pattern()
403 if pat_data is not None:
404 pat_data, length = pat_data
405 self.drum_pattern_editor = drum_pattern_editor.DrumSeqWindow(length, pat_data)
406 self.drum_pattern_editor.set_title("Drum pattern editor")
407 self.drum_pattern_editor.show_all()
408 self.drum_pattern_editor.connect('destroy', self.on_drum_pattern_editor_destroy)
409 self.drum_pattern_editor.pattern.connect('changed', self.on_drum_pattern_changed)
410 self.drum_pattern_editor.pattern.changed()
411 self.drum_pattern_editor.present()
413 def on_drum_pattern_changed(self, pattern):
414 data = bytearray()
415 for i in pattern.items():
416 ch = i.channel - 1
417 data += cbox.Pattern.serialize_event(int(i.pos), 0x90 + ch, int(i.row), int(i.vel))
418 if i.len > 1:
419 data += cbox.Pattern.serialize_event(int(i.pos + i.len - 1), 0x80 + ch, int(i.row), int(i.vel))
420 else:
421 data += cbox.Pattern.serialize_event(int(i.pos + 1), 0x80 + ch, int(i.row), int(i.vel))
423 length = pattern.get_length()
425 song = cbox.Document().get_song()
426 song.loop_single_pattern(lambda: song.pattern_from_blob(data, length))
428 def on_drum_pattern_editor_destroy(self, w):
429 self.drum_pattern_editor = None
431 def refresh_instrument_pages(self, scene_status = None):
432 self.delete_instrument_pages()
433 rt_status = cbox.Document.get_rt().status()
434 if scene_status is None:
435 scene_status = cbox.Document.get_scene().status()
436 self.layers_model.refresh(scene_status)
437 self.auxes_model.refresh(scene_status)
438 self.create_instrument_pages(scene_status, rt_status)
439 self.nb.show_all()
440 self.title_label.set_text(scene_status.title)
442 def create_instrument_pages(self, scene_status, rt_status):
443 self.path_widgets = {}
444 self.path_popups = {}
445 self.fx_choosers = {}
447 outputs_ls = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_INT)
448 for out in range(0, rt_status.audio_channels[1]//2):
449 outputs_ls.append(("Out %s/%s" % (out * 2 + 1, out * 2 + 2), out))
451 auxbus_ls = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
452 auxbus_ls.append(("", ""))
453 for bus_name in scene_status.auxes.keys():
454 auxbus_ls.append(("Aux: %s" % bus_name, bus_name))
456 for iname, (iengine, iobj) in scene_status.instruments.items():
457 ipath = "/scene/instr/%s" % iname
458 idata = iobj.status()
459 #attribs = cbox.GetThings("/scene/instr_info", ['engine', 'name'], [i])
460 #markup += '<b>Instrument %d:</b> engine %s, name %s\n' % (i, attribs.engine, attribs.name)
461 b = Gtk.VBox(spacing = 5)
462 b.set_border_width(5)
463 b.pack_start(Gtk.Label("Engine: %s" % iengine), False, False, 5)
464 b.pack_start(Gtk.HSeparator(), False, False, 5)
465 t = Gtk.Table(1 + idata.outputs, 7)
466 t.set_col_spacings(5)
467 t.attach(bold_label("Instr. output", 0.5), 0, 1, 0, 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK)
468 t.attach(bold_label("Send to", 0.5), 1, 2, 0, 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK)
469 t.attach(bold_label("Gain [dB]", 0.5), 2, 3, 0, 1, 0, Gtk.AttachOptions.SHRINK)
470 t.attach(bold_label("Effect", 0.5), 3, 4, 0, 1, 0, Gtk.AttachOptions.SHRINK)
471 t.attach(bold_label("Preset", 0.5), 4, 7, 0, 1, 0, Gtk.AttachOptions.SHRINK)
472 b.pack_start(t, False, False, 5)
474 y = 1
475 for o in range(1, idata.outputs + 1):
476 is_aux = o >= idata.aux_offset
477 if not is_aux:
478 opath = "%s/output/%s" % (ipath, o)
479 output_name = "Out %s" % o
480 else:
481 opath = "%s/aux/%s" % (ipath, o - idata.aux_offset + 1)
482 output_name = "Aux %s" % (o - idata.aux_offset + 1)
483 odata = cbox.GetThings(opath + "/status", ['gain', 'output', 'bus', 'insert_engine', 'insert_preset', 'bypass'], [])
484 engine = odata.insert_engine
485 preset = odata.insert_preset
486 bypass = odata.bypass
488 t.attach(Gtk.Label(output_name), 0, 1, y, y + 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK)
490 if not is_aux:
491 cb = standard_combo(outputs_ls, odata.output - 1)
492 cb.connect('changed', combo_value_changed, cbox.VarPath(opath + '/output'), 1)
493 else:
494 cb = standard_combo(auxbus_ls, ls_index(auxbus_ls, odata.bus, 1))
495 cb.connect('changed', combo_value_changed_use_column, cbox.VarPath(opath + '/bus'), 1)
496 t.attach(cb, 1, 2, y, y + 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK)
498 adj = Gtk.Adjustment(odata.gain, -96, 24, 1, 6, 0)
499 adj.connect('value_changed', adjustment_changed_float, cbox.VarPath(opath + '/gain'))
500 t.attach(standard_hslider(adj), 2, 3, y, y + 1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK)
502 chooser = fx_gui.InsertEffectChooser(opath, "%s: %s" % (iname, output_name), engine, preset, bypass, self)
503 self.fx_choosers[opath] = chooser
504 t.attach(chooser.fx_engine, 3, 4, y, y + 1, 0, Gtk.AttachOptions.SHRINK)
505 t.attach(chooser.fx_preset, 4, 5, y, y + 1, 0, Gtk.AttachOptions.SHRINK)
506 t.attach(chooser.fx_edit, 5, 6, y, y + 1, 0, Gtk.AttachOptions.SHRINK)
507 t.attach(chooser.fx_bypass, 6, 7, y, y + 1, 0, Gtk.AttachOptions.SHRINK)
508 y += 1
509 if iengine in instr_gui.instrument_window_map:
510 b.pack_start(Gtk.HSeparator(), False, False, 5)
511 b.pack_start(instr_gui.instrument_window_map[iengine](iname, iobj), True, True, 5)
512 self.nb.append_page(b, Gtk.Label(iname))
513 self.update()
515 def delete_instrument_pages(self):
516 while self.nb.get_n_pages() > 1:
517 self.nb.remove_page(self.nb.get_n_pages() - 1)
519 def update(self):
520 cbox.call_on_idle()
521 master = cbox.Transport.status()
522 if master.tempo is not None:
523 self.master_info.set_markup('%s (%s)' % (master.pos, master.pos_ppqn))
524 self.timesig_info.set_markup("%s/%s" % tuple(master.timesig))
525 self.tempo_adj.set_value(master.tempo)
526 state = cbox.Document.get_rt().status().state
527 self.status_bar.update(state[1], master.sample_rate)
528 return True
530 def do_quit(window):
531 Gtk.main_quit()
533 w = MainWindow()
534 w.set_title("My UI")
535 w.show_all()
536 w.connect('destroy', do_quit)
538 Gtk.main()