2 Copyright (C) 2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/stock.h>
21 #include <gtkmm/table.h>
23 #include "gtkmm2ext/utils.h"
25 #include "edit_note_dialog.h"
26 #include "midi_region_view.h"
27 #include "note_base.h"
33 using namespace Gtkmm2ext;
36 * EditNoteDialog constructor.
38 * @param n Notes to edit.
41 EditNoteDialog::EditNoteDialog (MidiRegionView* rv, set<NoteBase*> n)
42 : ArdourDialog (_("Note"))
45 , _channel_all (_("Set selected notes to this channel"))
46 , _pitch_all (_("Set selected notes to this pitch"))
47 , _velocity_all (_("Set selected notes to this velocity"))
48 , _time_clock (X_("notetime"), true, "", true, false)
49 , _time_all (_("Set selected notes to this time"))
50 , _length_clock (X_("notelength"), true, "", true, false, true)
51 , _length_all (_("Set selected notes to this length"))
53 Table* table = manage (new Table (4, 2));
54 table->set_spacings (6);
58 Label* l = manage (left_aligned_label (_("Channel")));
59 table->attach (*l, 0, 1, r, r + 1);
60 table->attach (_channel, 1, 2, r, r + 1);
61 table->attach (_channel_all, 2, 3, r, r + 1);
64 _channel.set_range (1, 16);
65 _channel.set_increments (1, 2);
66 _channel.set_value ((*_events.begin())->note()->channel () + 1);
68 l = manage (left_aligned_label (_("Pitch")));
69 table->attach (*l, 0, 1, r, r + 1);
70 table->attach (_pitch, 1, 2, r, r + 1);
71 table->attach (_pitch_all, 2, 3, r, r + 1);
74 _pitch.set_range (0, 127);
75 _pitch.set_increments (1, 10);
76 _pitch.set_value ((*_events.begin())->note()->note());
78 l = manage (left_aligned_label (_("Velocity")));
79 table->attach (*l, 0, 1, r, r + 1);
80 table->attach (_velocity, 1, 2, r, r + 1);
81 table->attach (_velocity_all, 2, 3, r, r + 1);
84 _velocity.set_range (0, 127);
85 _velocity.set_increments (1, 10);
86 _velocity.set_value ((*_events.begin())->note()->velocity ());
88 l = manage (left_aligned_label (_("Time")));
89 table->attach (*l, 0, 1, r, r + 1);
90 table->attach (_time_clock, 1, 2, r, r + 1);
91 table->attach (_time_all, 2, 3, r, r + 1);
94 _time_clock.set_session (_region_view->get_time_axis_view().session ());
95 _time_clock.set_mode (AudioClock::BBT);
96 _time_clock.set (_region_view->source_relative_time_converter().to
97 ((*_events.begin())->note()->time()) + (_region_view->region()->position() - _region_view->region()->start()), true);
99 l = manage (left_aligned_label (_("Length")));
100 table->attach (*l, 0, 1, r, r + 1);
101 table->attach (_length_clock, 1, 2, r, r + 1);
102 table->attach (_length_all, 2, 3, r, r + 1);
105 _length_clock.set_session (_region_view->get_time_axis_view().session ());
106 _length_clock.set_mode (AudioClock::BBT);
108 _region_view->region_relative_time_converter().to ((*_events.begin())->note()->end_time ()) + _region_view->region()->position(),
110 _region_view->region_relative_time_converter().to ((*_events.begin())->note()->time ()) + _region_view->region()->position());
112 /* Set up `set all notes...' buttons' sensitivity */
114 _channel_all.set_sensitive (false);
115 _pitch_all.set_sensitive (false);
116 _velocity_all.set_sensitive (false);
117 _time_all.set_sensitive (false);
118 _length_all.set_sensitive (false);
120 int test_channel = (*_events.begin())->note()->channel ();
121 int test_pitch = (*_events.begin())->note()->note ();
122 int test_velocity = (*_events.begin())->note()->velocity ();
123 Evoral::Beats test_time = (*_events.begin())->note()->time ();
124 Evoral::Beats test_length = (*_events.begin())->note()->length ();
126 for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
127 if ((*i)->note()->channel() != test_channel) {
128 _channel_all.set_sensitive (true);
131 if ((*i)->note()->note() != test_pitch) {
132 _pitch_all.set_sensitive (true);
135 if ((*i)->note()->velocity() != test_velocity) {
136 _velocity_all.set_sensitive (true);
139 if ((*i)->note()->time () != test_time) {
140 _time_all.set_sensitive (true);
143 if ((*i)->note()->length () != test_length) {
144 _length_all.set_sensitive (true);
148 get_vbox()->pack_start (*table);
150 add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
151 add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_ACCEPT);
152 set_default_response (Gtk::RESPONSE_ACCEPT);
156 EditNoteDialog::done (int r)
158 if (r != RESPONSE_ACCEPT) {
162 /* These calls mean that if a value is entered using the keyboard
163 it will be returned by the get_value_as_int()s below.
169 _region_view->start_note_diff_command (_("edit note"));
171 bool had_change = false;
173 if (!_channel_all.get_sensitive() || _channel_all.get_active ()) {
174 for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
175 if (_channel.get_value_as_int() - 1 != (*i)->note()->channel()) {
176 _region_view->change_note_channel (*i, _channel.get_value_as_int () - 1);
182 if (!_pitch_all.get_sensitive() || _pitch_all.get_active ()) {
183 for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
184 if (_pitch.get_value_as_int() != (*i)->note()->note()) {
185 _region_view->change_note_note (*i, _pitch.get_value_as_int ());
191 if (!_velocity_all.get_sensitive() || _velocity_all.get_active ()) {
192 for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
193 if (_velocity.get_value_as_int() != (*i)->note()->velocity()) {
194 _region_view->change_note_velocity (*i, _velocity.get_value_as_int ());
200 framecnt_t const region_samples = _time_clock.current_time() - (_region_view->region()->position() - _region_view->region()->start());
201 Evoral::Beats const t = _region_view->source_relative_time_converter().from (region_samples);
203 if (!_time_all.get_sensitive() || _time_all.get_active ()) {
204 for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
205 if (t != (*i)->note()->time()) {
206 _region_view->change_note_time (*i, t);
212 if (!_length_all.get_sensitive() || _length_all.get_active ()) {
213 for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
214 framepos_t const note_end_sample = region_samples + _length_clock.current_duration (_time_clock.current_time());
215 Evoral::Beats const d = _region_view->source_relative_time_converter().from (note_end_sample) - (*i)->note()->time();
216 if (d != (*i)->note()->length()) {
217 _region_view->change_note_length (*i, d);
224 _region_view->abort_command ();
227 _region_view->apply_diff ();
229 list<Evoral::event_id_t> notes;
230 for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
231 notes.push_back ((*i)->note()->id());
234 _region_view->select_notes (notes);