Add menu option to insert program changes.
authorCarl Hetherington <carl@carlh.net>
Wed, 22 Dec 2010 23:45:04 +0000 (23:45 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 22 Dec 2010 23:45:04 +0000 (23:45 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@8330 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour.menus.in
gtk2_ardour/editor.h
gtk2_ardour/editor_actions.cc
gtk2_ardour/editor_drag.cc
gtk2_ardour/editor_ops.cc
gtk2_ardour/midi_region_view.cc
gtk2_ardour/midi_region_view.h
gtk2_ardour/program_change_dialog.cc [new file with mode: 0644]
gtk2_ardour/program_change_dialog.h [new file with mode: 0644]
gtk2_ardour/wscript

index e7d8eff8f18f60761a68218e375c5ef90fb39e1c..ffbdfcc131e470a36614ee3fdd72a64c7b802474 100644 (file)
                      <menuitem action='lower-region-to-bottom'/>
               </menu>
              <menu action='RegionMenuMIDI'>
+                     <menuitem action='insert-program-change'/>
                      <menuitem action='quantize-region'/>
                      <menuitem action='fork-region'/>
                      <menuitem action='show-region-list-editor'/>
                      <menuitem action='lower-region-to-bottom'/>
               </menu>
              <menu action='RegionMenuMIDI'>
+                     <menuitem action='insert-program-change'/>
                      <menuitem action='quantize-region'/>
                      <menuitem action='fork-region'/>
                      <menuitem action='show-region-list-editor'/>
index 0b90c16e0de5171915b7bcc60dec14d64100d70d..57bfd5205b647a2422cad7531defd475390b7b3b 100644 (file)
@@ -1090,6 +1090,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void reset_region_scale_amplitude ();
        void adjust_region_gain (bool up);
        void quantize_region ();
+       void insert_program_change ();
        void fork_region ();
 
        void do_insert_time ();
index 2458e0234eb501de0e701df1276f79b9288b0c4d..e88f5c9c319a4e288351cd1532e3a93afa1e6167 100644 (file)
@@ -1469,6 +1469,7 @@ Editor::register_region_actions ()
                );
 
        reg_sens (_region_actions, "quantize-region", _("Quantize"), sigc::mem_fun (*this, &Editor::quantize_region));
+       reg_sens (_region_actions, "insert-program-change", _("Insert Program Change..."), sigc::mem_fun (*this, &Editor::insert_program_change));
        reg_sens (_region_actions, "fork-region", _("Fork"), sigc::mem_fun (*this, &Editor::fork_region));
        reg_sens (_region_actions, "strip-region-silence", _("Strip Silence..."), sigc::mem_fun (*this, &Editor::strip_region_silence));
        reg_sens (_region_actions, "set-selection-from-region", _("Set Range Selection"), sigc::mem_fun (*this, &Editor::set_selection_from_region));
index 7f87ae0273ba643af848e4d386a8735b0dcfb7f2..67367e8b65f6279b86f27437c99a0a443823ef1e 100644 (file)
@@ -1776,6 +1776,8 @@ TrimDrag::setup_pointer_frame_offset ()
        case EndTrim:
                _pointer_frame_offset = raw_grab_frame() - i->initial_end;
                break;
+       case ContentsTrim:
+               break;
        }
 }
 
index fa096dc42b0b9572e870281cab7f00522a97480a..6c5c250fa34ebf6f8cc0b1406d8d8b640a64756c 100644 (file)
@@ -84,6 +84,7 @@
 #include "normalize_dialog.h"
 #include "editor_cursors.h"
 #include "mouse_cursors.h"
+#include "program_change_dialog.h"
 
 #include "i18n.h"
 
@@ -4704,6 +4705,31 @@ Editor::quantize_region ()
        }
 }
 
+void
+Editor::insert_program_change ()
+{
+       RegionSelection rs = get_regions_from_selection_and_entered ();
+       if (rs.empty ()) {
+               return;
+       }
+
+       ProgramChangeDialog d;
+       if (d.run() == RESPONSE_CANCEL) {
+               return;
+       }
+
+       framepos_t const p = get_preferred_edit_position (false);
+
+       for (RegionSelection::iterator i = rs.begin (); i != rs.end(); ++i) {
+               MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (*i);
+               if (mrv) {
+                       if (p >= mrv->region()->first_frame() && p <= mrv->region()->last_frame()) {
+                               mrv->add_program_change (p - mrv->region()->position(), d.channel (), d.program ());
+                       }
+               }
+       }
+}
+
 void
 Editor::apply_filter (Filter& filter, string command, ProgressReporter* progress)
 {
index 8ceb31afc938374478fc1bd6a363b6f1f9806308..227587d5a0793c849fc787effd9d78baf38c6b6b 100644 (file)
@@ -1111,12 +1111,12 @@ MidiRegionView::display_program_changes_on_channel(uint8_t channel)
                PCEvent program_change(event_time, uint8_t(program_number), channel);
 
                if (patch != 0) {
-                       add_pgm_change(program_change, patch->name());
+                       add_canvas_program_change (program_change, patch->name());
                } else {
                        char buf[4];
                         // program_number is zero-based: convert to one-based
                        snprintf(buf, 4, "%d", int(program_number+1));
-                       add_pgm_change(program_change, buf);
+                       add_canvas_program_change (program_change, buf);
                }
        }
 }
@@ -1583,7 +1583,7 @@ MidiRegionView::step_sustain (Evoral::MusicalTime beats)
 }
 
 void
-MidiRegionView::add_pgm_change(PCEvent& program, const string& displaytext)
+MidiRegionView::add_canvas_program_change (PCEvent& program, const string& displaytext)
 {
        assert(program.time >= 0);
 
@@ -1668,8 +1668,26 @@ MidiRegionView::alter_program_change(PCEvent& old_program, const MIDI::Name::Pat
         display_program_changes (); // XXX would be nice to limit to just old_program.channel
 }
 
+/** @param t Time in frames relative to region position */
 void
-MidiRegionView::move_program_change (PCEvent pc, double t)
+MidiRegionView::add_program_change (framecnt_t t, uint8_t channel, uint8_t value)
+{
+       boost::shared_ptr<Evoral::Control> control = midi_region()->model()->control (
+               Evoral::Parameter (MidiPgmChangeAutomation, channel, 0), true
+               );
+       
+       assert (control);
+
+       Evoral::MusicalTime const b = frames_to_beats (t + midi_region()->start());
+
+       control->list()->add (b, value);
+
+       _pgm_changes.clear ();
+       display_program_changes ();
+}
+
+void
+MidiRegionView::move_program_change (PCEvent pc, Evoral::MusicalTime t)
 {
        boost::shared_ptr<Evoral::Control> control = _model->control (Evoral::Parameter (MidiPgmChangeAutomation, pc.channel, 0));
        assert (control);
index 781ef35036917ef28d8555fd1f3f904642431484..4bfaebbf1303273133ea17c3c1da4bf6dd1c8efa 100644 (file)
@@ -133,7 +133,7 @@ class MidiRegionView : public RegionView
         * @param program the MidiRegionView::PCEvent to add
         * @param the text to display in the flag
         */
-       void add_pgm_change(PCEvent& program, const std::string& displaytext);
+       void add_canvas_program_change (PCEvent& program, const std::string& displaytext);
 
        /** Look up the given time and channel in the 'automation' and set keys accordingly.
         * @param time the time of the program change event
@@ -149,7 +149,8 @@ class MidiRegionView : public RegionView
         */
        void alter_program_change(PCEvent& old_program, const MIDI::Name::PatchPrimaryKey& new_patch);
 
-       void move_program_change (PCEvent, double);
+       void add_program_change (framecnt_t, uint8_t, uint8_t);
+       void move_program_change (PCEvent, Evoral::MusicalTime);
        void delete_program_change (ArdourCanvas::CanvasProgramChange *);
 
        /** Alter a given program to the new given one.
diff --git a/gtk2_ardour/program_change_dialog.cc b/gtk2_ardour/program_change_dialog.cc
new file mode 100644 (file)
index 0000000..75bb8ae
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+    Copyright (C) 2010 Paul Davis
+    Author: Carl Hetherington <cth@carlh.net>
+
+    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 <gtkmm/table.h>
+#include "program_change_dialog.h"
+
+using namespace Gtk;
+
+ProgramChangeDialog::ProgramChangeDialog ()
+       : ArdourDialog (_("Add Program Change"), true)
+       , _channel (*manage (new Adjustment (1, 1, 16, 1, 2)))
+       , _program (*manage (new Adjustment (1, 1, 128, 1, 16)))
+{
+       Table* t = manage (new Table (2, 2));
+       t->set_spacings (6);
+
+       Label* l = manage (new Label (_("Channel")));
+       l->set_alignment (0, 0.5);
+       t->attach (*l, 0, 1, 0, 1);
+
+       t->attach (_channel, 1, 2, 0, 1);
+
+       l = manage (new Label (_("Program")));
+       l->set_alignment (0, 0.5);
+       t->attach (*l, 0, 1, 1, 2);
+       t->attach (_program, 1, 2, 1, 2);
+
+       get_vbox()->add (*t);
+
+       add_button (Stock::CANCEL, RESPONSE_CANCEL);
+       add_button (Stock::ADD, RESPONSE_ACCEPT);
+       set_default_response (RESPONSE_ACCEPT);
+
+       show_all ();
+}
+
+/** @return Channel, counted from 0 */
+uint8_t
+ProgramChangeDialog::channel () const
+{
+       return _channel.get_value_as_int () - 1;
+}
+
+/** @return Program change number, counted from 0 */
+uint8_t
+ProgramChangeDialog::program () const
+{
+       return _program.get_value_as_int () - 1;
+}
diff --git a/gtk2_ardour/program_change_dialog.h b/gtk2_ardour/program_change_dialog.h
new file mode 100644 (file)
index 0000000..05345e0
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+    Copyright (C) 2010 Paul Davis
+    Author: Carl Hetherington <cth@carlh.net>
+
+    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/spinbutton.h>
+#include "ardour_dialog.h"
+
+class ProgramChangeDialog : public ArdourDialog
+{
+public:
+       ProgramChangeDialog ();
+
+       uint8_t channel () const;
+       uint8_t program () const;
+
+private:
+       Gtk::SpinButton _channel;
+       Gtk::SpinButton _program;
+};
index ae673f06d6eca8408224b7a4ae4c6f041c53663b..8b71a1fdd2e4163d9775df1096dab7e08e8cfa47 100644 (file)
@@ -173,6 +173,7 @@ gtk2_ardour_sources = [
        'port_matrix_labels.cc',
        'port_matrix_row_labels.cc',
        'processor_box.cc',
+       'program_change_dialog.cc',
        'progress_reporter.cc',
        'prompter.cc',
        'public_editor.cc',