summaryrefslogtreecommitdiff
path: root/gtk2_ardour/edit_note_dialog.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2010-08-14 02:00:50 +0000
committerCarl Hetherington <carl@carlh.net>2010-08-14 02:00:50 +0000
commit439d13535ee7ae73b1e7d6b0cc99022739234a28 (patch)
tree56ba61561b3c84e1ebc62c766ff289d88dd707c2 /gtk2_ardour/edit_note_dialog.cc
parent4e2d805c9d60c493dbdd0683d14377f4cdc1960f (diff)
Add note edit dialog. Fixes #3346.
git-svn-id: svn://localhost/ardour2/branches/3.0@7625 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour/edit_note_dialog.cc')
-rw-r--r--gtk2_ardour/edit_note_dialog.cc156
1 files changed, 156 insertions, 0 deletions
diff --git a/gtk2_ardour/edit_note_dialog.cc b/gtk2_ardour/edit_note_dialog.cc
new file mode 100644
index 0000000000..fe45093057
--- /dev/null
+++ b/gtk2_ardour/edit_note_dialog.cc
@@ -0,0 +1,156 @@
+/*
+ Copyright (C) 2010 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 <gtkmm/table.h>
+#include "ardour/midi_model.h"
+#include "edit_note_dialog.h"
+#include "canvas-note-event.h"
+#include "midi_region_view.h"
+
+using namespace Gtk;
+
+/**
+ * EditNoteDialog constructor.
+ *
+ * @param n Note to edit.
+ */
+
+EditNoteDialog::EditNoteDialog (MidiRegionView* rv, Gnome::Canvas::CanvasNoteEvent* ev)
+ : ArdourDialog (_("Note"))
+ , _region_view (rv)
+ , _event (ev)
+ , _time_clock (X_("notetime"), true, X_("NoteTimeClock"), true, false)
+ , _length_clock (X_("notelength"), true, X_("NoteLengthClock"), true, false, true)
+{
+ Table* table = manage (new Table (4, 2));
+ table->set_spacings (6);
+
+ int r = 0;
+
+ Label* l = manage (new Label (_("Channel")));
+ l->set_alignment (0, 0.5);
+ table->attach (*l, 0, 1, r, r + 1);
+ table->attach (_channel, 1, 2, r, r + 1);
+ ++r;
+
+ _channel.set_range (1, 16);
+ _channel.set_increments (1, 2);
+ _channel.set_value (ev->note()->channel () + 1);
+
+ l = manage (new Label (_("Pitch")));
+ l->set_alignment (0, 0.5);
+ table->attach (*l, 0, 1, r, r + 1);
+ table->attach (_pitch, 1, 2, r, r + 1);
+ ++r;
+
+ _pitch.set_range (0, 127);
+ _pitch.set_increments (1, 10);
+ _pitch.set_value (ev->note()->note ());
+
+ l = manage (new Label (_("Velocity")));
+ l->set_alignment (0, 0.5);
+ table->attach (*l, 0, 1, r, r + 1);
+ table->attach (_velocity, 1, 2, r, r + 1);
+ ++r;
+
+ _velocity.set_range (0, 127);
+ _velocity.set_increments (1, 10);
+ _velocity.set_value (ev->note()->velocity ());
+
+ l = manage (new Label (_("Time")));
+ l->set_alignment (0, 0.5);
+ table->attach (*l, 0, 1, r, r + 1);
+ table->attach (_time_clock, 1, 2, r, r + 1);
+ ++r;
+
+ _time_clock.set_session (_region_view->get_trackview().session ());
+ _time_clock.set_mode (AudioClock::BBT);
+ _time_clock.set (_region_view->time_converter().to (ev->note()->time ()), true);
+
+ l = manage (new Label (_("Length")));
+ l->set_alignment (0, 0.5);
+ table->attach (*l, 0, 1, r, r + 1);
+ table->attach (_length_clock, 1, 2, r, r + 1);
+ ++r;
+
+ _length_clock.set_session (_region_view->get_trackview().session ());
+ _length_clock.set_mode (AudioClock::BBT);
+ _length_clock.set (_region_view->time_converter().to (ev->note()->length ()), true);
+
+ get_vbox()->pack_start (*table);
+
+ add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_ACCEPT);
+ set_default_response (Gtk::RESPONSE_ACCEPT);
+
+ show_all ();
+}
+
+int
+EditNoteDialog::run ()
+{
+ int const r = Dialog::run ();
+ if (r != RESPONSE_ACCEPT) {
+ return r;
+ }
+
+ _region_view->start_diff_command (_("edit note"));
+
+ bool had_change = false;
+
+ if (_channel.get_value_as_int() - 1 != _event->note()->channel()) {
+ _region_view->change_note_channel (_event, _channel.get_value_as_int () - 1);
+ had_change = true;
+ }
+
+ if (_pitch.get_value_as_int() != _event->note()->note()) {
+ _region_view->change_note_note (_event, _pitch.get_value_as_int (), false);
+ had_change = true;
+ }
+
+ if (_velocity.get_value_as_int() != _event->note()->velocity()) {
+ _region_view->change_note_velocity (_event, _velocity.get_value_as_int (), false);
+ had_change = true;
+ }
+
+ double const t = _region_view->time_converter().from (_time_clock.current_time ());
+
+ if (t != _event->note()->time()) {
+ _region_view->change_note_time (_event, t);
+ had_change = true;
+ }
+
+ double const d = _region_view->time_converter().from (_length_clock.current_duration ());
+
+ if (d != _event->note()->length()) {
+ _region_view->change_note_length (_event, d);
+ had_change = true;
+ }
+
+ if (!had_change) {
+ _region_view->abort_command ();
+ }
+
+ _region_view->apply_diff ();
+
+ _event->set_selected (_event->selected()); // change color
+
+ return r;
+}