]> git.0d.be Git - jack_mixer.git/commitdiff
Allow drag n drop to change channel positions
authorDaniel Sheeler <dsheeler@pobox.com>
Fri, 17 Jul 2020 04:52:15 +0000 (23:52 -0500)
committerDaniel Sheeler <dsheeler@pobox.com>
Fri, 17 Jul 2020 04:52:15 +0000 (23:52 -0500)
channel.py
jack_mixer.py

index b92ca1596b090bf33016c6f569716a1df9e10921..3ce02b0a490cc5773925fe4efc77b1e11b41860c 100644 (file)
@@ -456,6 +456,14 @@ class InputChannel(Channel):
         self.label_name_event_box = Gtk.EventBox()
         self.label_name_event_box.connect("button-press-event", self.on_label_mouse)
         self.label_name_event_box.add(self.label_name)
+
+        entries = [Gtk.TargetEntry.new("INPUT_CHANNEL", Gtk.TargetFlags.SAME_APP, 0)]
+        self.label_name_event_box.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, entries,
+                Gdk.DragAction.MOVE)
+        self.label_name_event_box.connect("drag-data-get", self.on_drag_data_get)
+        self.drag_dest_set(Gtk.DestDefaults.ALL, entries, Gdk.DragAction.MOVE)
+        self.connect_after("drag-data-received", self.on_drag_data_received)
+
         self.vbox.pack_start(self.label_name_event_box, True, True, 0)
 #         self.label_stereo = Gtk.Label()
 #         if self.stereo:
@@ -509,6 +517,16 @@ class InputChannel(Channel):
         self.monitor_button.connect('toggled', self.on_monitor_button_toggled)
         self.pack_start(self.monitor_button, False, False, 0)
 
+    def on_drag_data_get(self, widget, drag_context, data, info, time):
+        channel = widget.get_parent().get_parent()
+        data.set(data.get_target(), 8, channel._channel_name.encode('utf-8'))
+
+    def on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
+        source_name = data.get_data().decode('utf-8')
+        if source_name == self._channel_name:
+            return
+        self.emit("input-channel-order-changed", source_name, self._channel_name)
+
     def add_control_group(self, channel):
         control_group = ControlGroup(channel, self)
         control_group.show_all()
@@ -613,6 +631,10 @@ class InputChannel(Channel):
                 return True
         return Channel.unserialize_property(self, name, value)
 
+GObject.signal_new("input-channel-order-changed", InputChannel,
+                GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION,
+                None, [GObject.TYPE_STRING, GObject.TYPE_STRING])
+
 class OutputChannel(Channel):
     _display_solo_buttons = False
 
@@ -660,6 +682,14 @@ class OutputChannel(Channel):
         self.label_name_event_box = Gtk.EventBox()
         self.label_name_event_box.connect('button-press-event', self.on_label_mouse)
         self.label_name_event_box.add(self.label_name)
+
+        entries = [Gtk.TargetEntry.new("OUTPUT_CHANNEL", Gtk.TargetFlags.SAME_APP, 0)]
+        self.label_name_event_box.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, entries,
+                Gdk.DragAction.MOVE)
+        self.label_name_event_box.connect("drag-data-get", self.on_drag_data_get)
+        self.drag_dest_set(Gtk.DestDefaults.ALL, entries, Gdk.DragAction.MOVE)
+        self.connect_after("drag-data-received", self.on_drag_data_received)
+
         if not hasattr(self, 'color'):
             self.color = random_color()
         set_background_color(self.label_name_event_box, self.css_name,
@@ -716,6 +746,17 @@ class OutputChannel(Channel):
         self._init_prefader_channels = None
 
     channel_properties_dialog = None
+
+    def on_drag_data_get(self, widget, drag_context, data, info, time):
+        channel = widget.get_parent().get_parent()
+        data.set(data.get_target(), 8, channel._channel_name.encode('utf-8'))
+
+    def on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
+        source_name = data.get_data().decode('utf-8')
+        if source_name == self._channel_name:
+            return
+        self.emit("output-channel-order-changed", source_name, self._channel_name)
+
     def on_channel_properties(self):
         if not self.channel_properties_dialog:
             self.channel_properties_dialog = OutputChannelPropertiesDialog(self, self.app)
@@ -988,6 +1029,10 @@ class ChannelPropertiesDialog(Gtk.Dialog):
                 sensitive = True
         self.ok_button.set_sensitive(sensitive)
 
+GObject.signal_new("output-channel-order-changed", OutputChannel,
+                GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION,
+                None, [GObject.TYPE_STRING, GObject.TYPE_STRING])
+
 
 class NewChannelDialog(ChannelPropertiesDialog):
     def create_ui(self):
index bc6c7991e416948009b8d68b71b66ea122f162fe..e8eb74d9bab23c1e18c6670c2747efe63b475a5b 100755 (executable)
@@ -50,7 +50,6 @@ from preferences import PreferencesDialog
 sys.path = old_path
 log = logging.getLogger("jack_mixer")
 
-
 class JackMixer(SerializedObject):
 
     # scales suitable as meter scales
@@ -483,6 +482,7 @@ class JackMixer(SerializedObject):
             channel.channel.solo_midi_cc = solo_cc
         else:
             channel.channel.autoset_solo_midi_cc()
+
         return channel
 
     def add_channel_precreated(self, channel):
@@ -512,6 +512,31 @@ class JackMixer(SerializedObject):
         channel.post_fader_output_channel.volume = 0
         channel.post_fader_output_channel.set_solo(channel.channel, True)
 
+        channel.connect('input-channel-order-changed', self.on_input_channel_order_changed)
+
+    def on_input_channel_order_changed(self, widget, source_name, dest_name):
+        self.channels.clear()
+
+        channel_box = self.hbox_inputs
+        frames = channel_box.get_children()
+
+        for f in frames:
+            c = f.get_child()
+            if source_name == c._channel_name:
+                source_frame = f
+                break
+
+        for f in frames:
+            c = f.get_child()
+            if (dest_name == c._channel_name):
+                pos = frames.index(f)
+                channel_box.reorder_child(source_frame, pos)
+                break
+
+        for frame in self.hbox_inputs.get_children():
+            c = frame.get_child()
+            self.channels.append(c)
+
     def read_meters(self):
         for channel in self.channels:
             channel.read_meter()
@@ -568,6 +593,30 @@ class JackMixer(SerializedObject):
         self.channel_remove_output_menu_item.set_sensitive(True)
 
         self.output_channels.append(channel)
+        channel.connect('output-channel-order-changed', self.on_output_channel_order_changed)
+
+    def on_output_channel_order_changed(self, widget, source_name, dest_name):
+        self.output_channels.clear()
+        channel_box = self.hbox_outputs
+
+        frames = channel_box.get_children()
+
+        for f in frames:
+            c = f.get_child()
+            if source_name == c._channel_name:
+                 source_frame = f
+                 break
+
+        for f in frames:
+            c = f.get_child()
+            if (dest_name == c._channel_name):
+                pos = len(frames) - 1 - frames.index(f)
+                channel_box.reorder_child(source_frame, pos)
+                break
+
+        for frame in self.hbox_outputs.get_children():
+            c = frame.get_child()
+            self.output_channels.append(c)
 
     _monitored_channel = None
     def get_monitored_channel(self):