2010-08-13 22:00:50 -04:00
|
|
|
/*
|
|
|
|
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>
|
2012-05-24 02:09:29 -04:00
|
|
|
|
2012-06-04 21:03:36 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2010-08-13 22:00:50 -04:00
|
|
|
#include "canvas-note-event.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "edit_note_dialog.h"
|
2010-08-13 22:00:50 -04:00
|
|
|
#include "midi_region_view.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
|
2011-04-22 23:34:42 -04:00
|
|
|
#include "i18n.h"
|
2010-08-13 22:00:50 -04:00
|
|
|
|
|
|
|
using namespace Gtk;
|
2012-06-04 21:03:36 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2010-08-13 22:00:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* EditNoteDialog constructor.
|
|
|
|
*
|
|
|
|
* @param n Note to edit.
|
|
|
|
*/
|
|
|
|
|
|
|
|
EditNoteDialog::EditNoteDialog (MidiRegionView* rv, Gnome::Canvas::CanvasNoteEvent* ev)
|
|
|
|
: ArdourDialog (_("Note"))
|
|
|
|
, _region_view (rv)
|
|
|
|
, _event (ev)
|
2011-11-17 17:49:13 -05:00
|
|
|
, _time_clock (X_("notetime"), true, "", true, false)
|
|
|
|
, _length_clock (X_("notelength"), true, "", true, false, true)
|
2010-08-13 22:00:50 -04:00
|
|
|
{
|
|
|
|
Table* table = manage (new Table (4, 2));
|
|
|
|
table->set_spacings (6);
|
|
|
|
|
|
|
|
int r = 0;
|
|
|
|
|
2012-06-04 21:03:36 -04:00
|
|
|
Label* l = manage (left_aligned_label (_("Channel")));
|
2010-08-13 22:00:50 -04:00
|
|
|
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);
|
|
|
|
|
2012-06-04 21:03:36 -04:00
|
|
|
l = manage (left_aligned_label (_("Pitch")));
|
2010-08-13 22:00:50 -04:00
|
|
|
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 ());
|
|
|
|
|
2012-06-04 21:03:36 -04:00
|
|
|
l = manage (left_aligned_label (_("Velocity")));
|
2010-08-13 22:00:50 -04:00
|
|
|
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 ());
|
|
|
|
|
2012-06-04 21:03:36 -04:00
|
|
|
l = manage (left_aligned_label (_("Time")));
|
2010-08-13 22:00:50 -04:00
|
|
|
table->attach (*l, 0, 1, r, r + 1);
|
|
|
|
table->attach (_time_clock, 1, 2, r, r + 1);
|
|
|
|
++r;
|
|
|
|
|
2010-09-06 08:34:11 -04:00
|
|
|
_time_clock.set_session (_region_view->get_time_axis_view().session ());
|
2010-08-13 22:00:50 -04:00
|
|
|
_time_clock.set_mode (AudioClock::BBT);
|
2011-08-16 10:24:41 -04:00
|
|
|
_time_clock.set (_region_view->source_relative_time_converter().to (ev->note()->time ()), true);
|
2010-08-13 22:00:50 -04:00
|
|
|
|
2012-06-04 21:03:36 -04:00
|
|
|
l = manage (left_aligned_label (_("Length")));
|
2010-08-13 22:00:50 -04:00
|
|
|
table->attach (*l, 0, 1, r, r + 1);
|
|
|
|
table->attach (_length_clock, 1, 2, r, r + 1);
|
|
|
|
++r;
|
|
|
|
|
2010-09-06 08:34:11 -04:00
|
|
|
_length_clock.set_session (_region_view->get_time_axis_view().session ());
|
2010-08-13 22:00:50 -04:00
|
|
|
_length_clock.set_mode (AudioClock::BBT);
|
2011-08-16 10:24:41 -04:00
|
|
|
_length_clock.set (_region_view->region_relative_time_converter().to (ev->note()->length ()), true);
|
2010-08-13 22:00:50 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-11 18:59:34 -05:00
|
|
|
/* These calls mean that if a value is entered using the keyboard
|
|
|
|
it will be returned by the get_value_as_int()s below.
|
|
|
|
*/
|
|
|
|
_channel.update ();
|
|
|
|
_pitch.update ();
|
|
|
|
_velocity.update ();
|
|
|
|
|
2010-12-09 16:34:46 -05:00
|
|
|
_region_view->start_note_diff_command (_("edit note"));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-13 22:00:50 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-16 10:24:41 -04:00
|
|
|
double const t = _region_view->source_relative_time_converter().from (_time_clock.current_time ());
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-13 22:00:50 -04:00
|
|
|
if (t != _event->note()->time()) {
|
|
|
|
_region_view->change_note_time (_event, t);
|
|
|
|
had_change = true;
|
|
|
|
}
|
|
|
|
|
2011-08-16 10:24:41 -04:00
|
|
|
double const d = _region_view->region_relative_time_converter().from (_length_clock.current_duration ());
|
2010-08-13 22:00:50 -04:00
|
|
|
|
|
|
|
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 ();
|
|
|
|
|
2011-06-01 13:00:29 -04:00
|
|
|
_event->set_selected (_event->selected()); // change color
|
|
|
|
|
2010-08-13 22:00:50 -04:00
|
|
|
return r;
|
|
|
|
}
|