Exemple #1
0
    def __init__(self, track, sequencer):
        gtk.VBox.__init__(self)

        self.grid = MsqNoteGridWidget(track, sequencer)
        self.setting = self.grid.setting

        track_info = get_track_info(track)
        self.setting.chan_num = track_info.channels[0] if len(track_info.channels) else 0

        self.hbar = MsqHBarTimeWidget(self.grid)

        self.vbar = MsqVBarNoteWidget(self.setting)
        self.setting.vadj.connect("value-changed", self.vadj_value_cb)

        self.grid.connect("motion_notify_event", self.handle_motion, self.hbar, self.vbar)
        self.grid.set_tooltip_text("""\
* Left button to select notes
* Right button to enter in edit mode
  then in edit mode press left button to write notes
  (do not release the button to increase size)
* Middle button to change note size
* Suppr to delete selected notes
* Ctrl-a Select all notes
* Ctrl-c Copy selected
* Ctrl-v Paste copied notes""")
        self.grid.get_settings().set_long_property("gtk-tooltip-timeout", 3000, "midilooper:gridvp")
        self.grid.connect("leave-notify-event", self.handle_leave_notify, self.hbar, self.vbar)

        hsb = gtk.HScrollbar(self.setting.hadj)
        vsb = gtk.VScrollbar(self.setting.vadj)

        table = gtk.Table(3, 2)
        table.attach(self.hbar, 1, 2, 0, 1, gtk.FILL,            0)
        table.attach(self.vbar, 0, 1, 1, 2, 0,                   gtk.FILL)
        table.attach(self.grid, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
        table.attach(vsb,       2, 3, 1, 2, 0,                   gtk.FILL)

        self.val_list = gtk.ListStore(int, str)
        chan_key = "%i" % self.setting.chan_num
        if track_info.ctrl_chan.has_key(chan_key):
            ctrl_list = track_info.ctrl_chan[chan_key]
        else:
            ctrl_list = []

        if track_info.note_chan.has_key(chan_key):
            self.val_list.append([9, "Note on *"])
        else:
            self.val_list.append([9, "Note on"])
        if track_info.pitch_chan.has_key(chan_key):
            self.val_list.append([14, "Pitch Bend *"])
        else:
            self.val_list.append([14, "Pitch Bend"])
        for idx in range(128):
            self.val_list.append([idx,
                                  "Ctrl %i *" % idx if idx in ctrl_list else "Ctrl %i" % idx])
        valuetype_cbbox = gtk.ComboBox(self.val_list)
        valuetype_cbbox.set_active(0)
        cell = gtk.CellRendererText()
        valuetype_cbbox.pack_start(cell, True)
        valuetype_cbbox.add_attribute(cell, 'text', 1)
        valuetype_cbbox.connect("changed", self.valuetype_changed)

        value_adjwgt = gtk.VScale()
        value_adjwgt.set_inverted(True)
        value_adjwgt.set_draw_value(False)

        value_box = gtk.HBox()
        value_box.pack_start(valuetype_cbbox)
        value_box.pack_start(value_adjwgt, expand=False, fill=False)

        value_box.set_size_request(self.vbar.width, -1)

        self.value_wgt = MsqValueWidget(self.setting, value_adjwgt)
        self.value_wgt.connect("leave-notify-event", self.handle_leave_notify, self.hbar, self.vbar)

        self.grid.value_wgt = self.value_wgt
        self.value_wgt.grid = self.grid

        self.zx_adj = gtk.Adjustment(15.0, 1.0, 25.0, 1.0)
        self.zx_adj.connect("value_changed", self.handle_zoom_x)
        zoom_x = gtk.HScale(self.zx_adj)
        zoom_x.set_draw_value(False)
        zoom_x.set_update_policy(gtk.UPDATE_DISCONTINUOUS)

        table2 = gtk.Table(2, 2)
        table2.attach(value_box,      0, 1, 0, 1, gtk.FILL,            gtk.EXPAND|gtk.FILL)
        table2.attach(self.value_wgt, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
        table2.attach(zoom_x,         0, 1, 1, 2, gtk.FILL,            0)
        table2.attach(hsb,            1, 2, 1, 2, gtk.FILL,            0)

        self.hbar.connect("scroll-event", self.scroll_adj_cb, self.setting)
        self.vbar.connect("scroll-event", self.scroll_adj_cb, self.setting)
        self.grid.connect("scroll-event", self.scroll_adj_cb, self.setting)

        paned_tables = gtk.VPaned()
        paned_tables.pack1(table, resize=False, shrink=False)
        paned_tables.pack2(table2, resize=False, shrink=False)

        grid_setting_frame = gtk.Frame("Grid setting")
        grid_setting_frame.add(GridSettingTable(self, track_info.channels))

        setting_box = gtk.HBox()
        setting_box.pack_start(grid_setting_frame, expand=False)

        self.pack_start(setting_box, expand=False)
        self.pack_start(paned_tables)

        debug_hbox = gtk.HBox()

        button_misc = gtk.Button("Redraw")
        button_misc.connect("clicked", self.debug_grid1, self.setting.track)
        debug_hbox.pack_start(button_misc)

        button_misc = gtk.Button("Dump track")
        button_misc.connect("clicked", self.debug_grid2, self.setting.track)
        debug_hbox.pack_start(button_misc)

        debug_frame = gtk.Frame("Note grid debug")
        debug_frame.add(debug_hbox)
        self.pack_end(debug_frame, expand=False)

        self.draw_all()
Exemple #2
0
class ChannelEditor(gtk.VBox):
    def vadj_value_cb(self, adj):
        self.vbar.draw_all()
        self.grid.draw_all()

    def vadj_value_cb(self, adj):
        self.hbar.draw_all()
        self.grid.draw_all()
        self.value_wgt.draw_all()

    def scroll_adj_cb(self, widget, event, setting):
        if is_mask_to_bypass(event.state):
            return
        inc_mult = 4
        if event.direction == gdk.SCROLL_DOWN:
            if event.state & gtk.gdk.SHIFT_MASK:
                xinc = setting.qnxsz * inc_mult
                inc_adj(setting.hadj, xinc)
            elif event.state & gtk.gdk.CONTROL_MASK:
                step = self.zx_adj.get_step_increment()
                val = self.zx_adj.get_value() - step
                if val >= self.zx_adj.get_lower():
                    self.zx_adj.set_value(val)
            else:
                yinc = setting.noteysz * inc_mult
                inc_adj(setting.vadj, yinc)
        elif event.direction == gdk.SCROLL_UP:
            if event.state & gtk.gdk.SHIFT_MASK:
                xinc = setting.qnxsz * inc_mult
                dec_adj(setting.hadj, xinc)
            elif event.state & gtk.gdk.CONTROL_MASK:
                step = self.zx_adj.get_step_increment()
                val = self.zx_adj.get_value() + step
                if val <= self.zx_adj.get_upper():
                    self.zx_adj.set_value(val)
            else:
                yinc = setting.noteysz * inc_mult
                dec_adj(setting.vadj, yinc)
        elif event.direction == gdk.SCROLL_RIGHT:
            xinc = setting.qnxsz * inc_mult
            inc_adj(setting.hadj, xinc)

        elif event.direction == gdk.SCROLL_LEFT:
            xinc = setting.qnxsz * inc_mult
            dec_adj(setting.hadj, xinc)

    def draw_all(self):
        self.hbar.draw_all()
        self.grid.draw_all()
        self.value_wgt.draw_all()

    def debug_grid1(self, button, track):
        self.draw_all()

    def debug_grid2(self, button, track):
        track._dump()

    def handle_motion(self, widget, event, hbar, vbar):
        # tick = self.grid.xpos2tick(event.x)
        note = vbar.ypos2note(int(event.y))
        # hbar.show_tick(tick)
        vbar.show_note(note)

    def handle_leave_notify(self, widget, event, hbar, vbar):
        vbar.clear_note()

    def handle_zoom_x(self, adj):
        zval = adj.get_value()
        old_qnxsz = self.setting.qnxsz
        old_pos = self.setting.hadj.get_value()
        if zval <= 16.0:
            self.setting.qnxsz = int(MIN_QNOTE_XSZ + ((DEFAULT_QNOTE_XSZ - MIN_QNOTE_XSZ) * zval / 16.0))
        else:
            self.setting.qnxsz = int(DEFAULT_QNOTE_XSZ + ((MAX_QNOTE_XSZ - DEFAULT_QNOTE_XSZ) * (zval - 16) / 16.0))
        self.setting.hadj.set_upper(self.setting.getmaxwidth())
        pos = old_pos * self.setting.qnxsz / old_qnxsz
        self.setting.hadj.set_value(pos)
        self.draw_all()

    def valuetype_changed(self, combobox):
        value_list = combobox.get_model()

        # Refreshing midivalue type list
        track_info = get_track_info(self.setting.track)
        update_value_list(value_list, track_info, self.setting.chan_num)

        # Updating "Value widget" mode and window
        list_idx   = combobox.get_active()
        if list_idx >= 0:
            value = value_list[list_idx][0]
            if list_idx == 0:
                self.value_wgt.set_note_mode()
            elif list_idx == 1:
                self.value_wgt.set_pitch_mode()
            else:
                if list_idx > 1:
                    self.value_wgt.set_ctrl_mode(list_idx - 2)
            self.value_wgt.draw_all()

    def __init__(self, track, sequencer):
        gtk.VBox.__init__(self)

        self.grid = MsqNoteGridWidget(track, sequencer)
        self.setting = self.grid.setting

        track_info = get_track_info(track)
        self.setting.chan_num = track_info.channels[0] if len(track_info.channels) else 0

        self.hbar = MsqHBarTimeWidget(self.grid)

        self.vbar = MsqVBarNoteWidget(self.setting)
        self.setting.vadj.connect("value-changed", self.vadj_value_cb)

        self.grid.connect("motion_notify_event", self.handle_motion, self.hbar, self.vbar)
        self.grid.set_tooltip_text("""\
* Left button to select notes
* Right button to enter in edit mode
  then in edit mode press left button to write notes
  (do not release the button to increase size)
* Middle button to change note size
* Suppr to delete selected notes
* Ctrl-a Select all notes
* Ctrl-c Copy selected
* Ctrl-v Paste copied notes""")
        self.grid.get_settings().set_long_property("gtk-tooltip-timeout", 3000, "midilooper:gridvp")
        self.grid.connect("leave-notify-event", self.handle_leave_notify, self.hbar, self.vbar)

        hsb = gtk.HScrollbar(self.setting.hadj)
        vsb = gtk.VScrollbar(self.setting.vadj)

        table = gtk.Table(3, 2)
        table.attach(self.hbar, 1, 2, 0, 1, gtk.FILL,            0)
        table.attach(self.vbar, 0, 1, 1, 2, 0,                   gtk.FILL)
        table.attach(self.grid, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
        table.attach(vsb,       2, 3, 1, 2, 0,                   gtk.FILL)

        self.val_list = gtk.ListStore(int, str)
        chan_key = "%i" % self.setting.chan_num
        if track_info.ctrl_chan.has_key(chan_key):
            ctrl_list = track_info.ctrl_chan[chan_key]
        else:
            ctrl_list = []

        if track_info.note_chan.has_key(chan_key):
            self.val_list.append([9, "Note on *"])
        else:
            self.val_list.append([9, "Note on"])
        if track_info.pitch_chan.has_key(chan_key):
            self.val_list.append([14, "Pitch Bend *"])
        else:
            self.val_list.append([14, "Pitch Bend"])
        for idx in range(128):
            self.val_list.append([idx,
                                  "Ctrl %i *" % idx if idx in ctrl_list else "Ctrl %i" % idx])
        valuetype_cbbox = gtk.ComboBox(self.val_list)
        valuetype_cbbox.set_active(0)
        cell = gtk.CellRendererText()
        valuetype_cbbox.pack_start(cell, True)
        valuetype_cbbox.add_attribute(cell, 'text', 1)
        valuetype_cbbox.connect("changed", self.valuetype_changed)

        value_adjwgt = gtk.VScale()
        value_adjwgt.set_inverted(True)
        value_adjwgt.set_draw_value(False)

        value_box = gtk.HBox()
        value_box.pack_start(valuetype_cbbox)
        value_box.pack_start(value_adjwgt, expand=False, fill=False)

        value_box.set_size_request(self.vbar.width, -1)

        self.value_wgt = MsqValueWidget(self.setting, value_adjwgt)
        self.value_wgt.connect("leave-notify-event", self.handle_leave_notify, self.hbar, self.vbar)

        self.grid.value_wgt = self.value_wgt
        self.value_wgt.grid = self.grid

        self.zx_adj = gtk.Adjustment(15.0, 1.0, 25.0, 1.0)
        self.zx_adj.connect("value_changed", self.handle_zoom_x)
        zoom_x = gtk.HScale(self.zx_adj)
        zoom_x.set_draw_value(False)
        zoom_x.set_update_policy(gtk.UPDATE_DISCONTINUOUS)

        table2 = gtk.Table(2, 2)
        table2.attach(value_box,      0, 1, 0, 1, gtk.FILL,            gtk.EXPAND|gtk.FILL)
        table2.attach(self.value_wgt, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL)
        table2.attach(zoom_x,         0, 1, 1, 2, gtk.FILL,            0)
        table2.attach(hsb,            1, 2, 1, 2, gtk.FILL,            0)

        self.hbar.connect("scroll-event", self.scroll_adj_cb, self.setting)
        self.vbar.connect("scroll-event", self.scroll_adj_cb, self.setting)
        self.grid.connect("scroll-event", self.scroll_adj_cb, self.setting)

        paned_tables = gtk.VPaned()
        paned_tables.pack1(table, resize=False, shrink=False)
        paned_tables.pack2(table2, resize=False, shrink=False)

        grid_setting_frame = gtk.Frame("Grid setting")
        grid_setting_frame.add(GridSettingTable(self, track_info.channels))

        setting_box = gtk.HBox()
        setting_box.pack_start(grid_setting_frame, expand=False)

        self.pack_start(setting_box, expand=False)
        self.pack_start(paned_tables)

        debug_hbox = gtk.HBox()

        button_misc = gtk.Button("Redraw")
        button_misc.connect("clicked", self.debug_grid1, self.setting.track)
        debug_hbox.pack_start(button_misc)

        button_misc = gtk.Button("Dump track")
        button_misc.connect("clicked", self.debug_grid2, self.setting.track)
        debug_hbox.pack_start(button_misc)

        debug_frame = gtk.Frame("Note grid debug")
        debug_frame.add(debug_hbox)
        self.pack_end(debug_frame, expand=False)

        self.draw_all()