add MIDI channel editing for current note selection, bound to "c" by default
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 13 Jun 2011 14:48:48 +0000 (14:48 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 13 Jun 2011 14:48:48 +0000 (14:48 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@9718 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/midi_channel_dialog.cc [new file with mode: 0644]
gtk2_ardour/midi_channel_dialog.h [new file with mode: 0644]
gtk2_ardour/midi_channel_selector.h
gtk2_ardour/midi_region_view.cc
gtk2_ardour/midi_region_view.h
gtk2_ardour/wscript

diff --git a/gtk2_ardour/midi_channel_dialog.cc b/gtk2_ardour/midi_channel_dialog.cc
new file mode 100644 (file)
index 0000000..f827037
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+    Copyright (C) 2011 Paul Davis
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <gtkmm/stock.h>
+
+#include "midi_channel_dialog.h"
+
+#include "i18n.h"
+
+using namespace Gtk;
+
+MidiChannelDialog::MidiChannelDialog (uint8_t active_channel)
+       : ArdourDialog (X_("MIDI Channel Chooser"), true)
+       , selector (active_channel)
+{
+       selector.show_all ();
+       get_vbox()->pack_start (selector);
+       add_button (Stock::CANCEL, RESPONSE_CANCEL);
+       add_button (Stock::OK, RESPONSE_OK);
+}
+
+uint8_t 
+MidiChannelDialog::active_channel () const
+{
+       return selector.get_active_channel();
+}
diff --git a/gtk2_ardour/midi_channel_dialog.h b/gtk2_ardour/midi_channel_dialog.h
new file mode 100644 (file)
index 0000000..fcf2392
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+    Copyright (C) 2011 Paul Davis
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __gtk2_ardour_midi_channel_dialog_h__
+#define __gtk2_ardour_midi_channel_dialog_h__
+
+#include <stdint.h>
+
+#include "ardour_dialog.h"
+#include "midi_channel_selector.h"
+
+class MidiChannelDialog : public ArdourDialog
+{
+  public:
+       MidiChannelDialog (uint8_t active_channel = 0);
+       uint8_t active_channel() const;
+
+  private:
+       SingleMidiChannelSelector selector;
+};
+
+#endif /* __gtk2_ardour_midi_channel_dialog_h__ */
index 8bcf704ca47561bf2833fed741a84cf30c6c0f9c..c5e6a5a3783d0d81eee10fb1107367d7539081ae 100644 (file)
 #include <set>
 #include "boost/shared_ptr.hpp"
 #include "sigc++/trackable.h"
+
 #include "gtkmm/table.h"
 #include "gtkmm/button.h"
 #include "gtkmm/label.h"
 #include "gtkmm2ext/stateful_button.h"
-#include "ardour/types.h"
 
+#include "ardour/types.h"
 
 class MidiChannelSelector : public Gtk::Table
 {
index 8553900278306b0fe3508b555d07c90794800cf8..54f6a2c59a2e2428963d8f0e6e72053d8252fe92 100644 (file)
@@ -54,6 +54,7 @@
 #include "ghostregion.h"
 #include "gui_thread.h"
 #include "keyboard.h"
+#include "midi_channel_dialog.h"
 #include "midi_cut_buffer.h"
 #include "midi_list_editor.h"
 #include "midi_region_view.h"
@@ -769,6 +770,9 @@ MidiRegionView::key_press (GdkEventKey* ev)
        } else if (ev->keyval == GDK_Control_L) {
                return true;
 
+       } else if (ev->keyval == GDK_c) {
+               channel_edit ();
+               return true;
        }
 
        return false;
@@ -784,6 +788,53 @@ MidiRegionView::key_release (GdkEventKey* ev)
        return false;
 }
 
+void
+MidiRegionView::channel_edit ()
+{
+       bool first = true;
+       bool mixed = false;
+       uint8_t current_channel;
+
+       if (_selection.empty()) {
+               return;
+       }
+       
+       for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
+               Selection::iterator next = i;
+               if (first) {
+                       current_channel = (*i)->note()->channel ();
+                       first = false;
+               } else {
+                       if (current_channel != (*i)->note()->channel()) {
+                               mixed = true;
+                       }
+               }
+       }
+
+       MidiChannelDialog channel_dialog (current_channel);
+       int ret = channel_dialog.run ();
+
+       switch (ret) {
+       case Gtk::RESPONSE_OK:
+               break;
+       default:
+               return;
+       }
+
+       uint8_t new_channel = channel_dialog.active_channel ();
+
+       start_note_diff_command (_("channel edit"));
+
+       for (Selection::iterator i = _selection.begin(); i != _selection.end(); ) {
+               Selection::iterator next = i;
+               ++next;
+               change_note_channel (*i, new_channel);
+               i = next;
+       }
+
+       apply_diff ();
+}
+
 void
 MidiRegionView::show_list_editor ()
 {
@@ -2469,12 +2520,6 @@ MidiRegionView::commit_resizing (ArdourCanvas::CanvasNoteEvent* primary, bool at
        apply_diff();
 }
 
-void
-MidiRegionView::change_note_channel (CanvasNoteEvent* event, int8_t channel)
-{
-       note_diff_add_change (event, MidiModel::NoteDiffCommand::Channel, (uint8_t) channel);
-}
-
 void
 MidiRegionView::change_note_velocity(CanvasNoteEvent* event, int8_t velocity, bool relative)
 {
@@ -2579,6 +2624,28 @@ MidiRegionView::trim_note (CanvasNoteEvent* event, Evoral::MusicalTime front_del
        }
 }
 
+void
+MidiRegionView::change_note_channel (CanvasNoteEvent* event, int8_t chn, bool relative)
+{
+       uint8_t new_channel;
+
+       if (relative) {
+               if (chn < 0.0) {
+                       if (event->note()->channel() < -chn) {
+                               new_channel = 0;
+                       } else {
+                               new_channel = event->note()->channel() + chn;
+                       }
+               } else {
+                       new_channel = event->note()->channel() + chn;
+               }
+       } else {
+               new_channel = (uint8_t) chn;
+       }
+
+       note_diff_add_change (event, MidiModel::NoteDiffCommand::Channel, new_channel);
+}
+
 void
 MidiRegionView::change_note_time (CanvasNoteEvent* event, Evoral::MusicalTime delta, bool relative)
 {
index 2da45a7ce362b3fb809bb28882c0db0477b78eda..116f210ee15e9aabcdd99c0f3a45e5830523fbd8 100644 (file)
@@ -264,6 +264,7 @@ public:
        void change_velocities (bool up, bool fine, bool allow_smush);
        void transpose (bool up, bool fine, bool allow_smush);
        void nudge_notes (bool forward);
+       void channel_edit ();
 
        void show_list_editor ();
 
@@ -318,7 +319,7 @@ private:
        void midi_channel_mode_changed(ARDOUR::ChannelMode mode, uint16_t mask);
        void midi_patch_settings_changed(std::string model, std::string custom_device_mode);
 
-       void change_note_channel (ArdourCanvas::CanvasNoteEvent *, int8_t);
+       void change_note_channel (ArdourCanvas::CanvasNoteEvent *, int8_t, bool relative=false);
        void change_note_velocity(ArdourCanvas::CanvasNoteEvent* ev, int8_t vel, bool relative=false);
        void change_note_note(ArdourCanvas::CanvasNoteEvent* ev, int8_t note, bool relative=false);
        void change_note_time(ArdourCanvas::CanvasNoteEvent* ev, ARDOUR::MidiModel::TimeType, bool relative=false);
index d357d1e27707e9efd2f0a034b2dc074e583d985e..616bcd66df7a40f598902cfe67d6f06d21bc5450 100644 (file)
@@ -133,6 +133,7 @@ gtk2_ardour_sources = [
         'main.cc',
         'marker.cc',
         'midi_automation_line.cc',
+        'midi_channel_dialog.cc',
         'midi_channel_selector.cc',
         'midi_cut_buffer.cc',
         'midi_list_editor.cc',