2010-08-13 22:00:50 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2010-2015 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2011-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2010-08-13 22:00:50 -04:00
|
|
|
|
|
|
|
#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"
|
|
|
|
|
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"
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "note_base.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2010-08-13 22:00:50 -04:00
|
|
|
|
2012-06-08 21:51:34 -04:00
|
|
|
using namespace std;
|
2020-10-05 00:52:17 -04:00
|
|
|
using namespace Temporal;
|
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.
|
|
|
|
*
|
2012-06-08 21:51:34 -04:00
|
|
|
* @param n Notes to edit.
|
2010-08-13 22:00:50 -04:00
|
|
|
*/
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
EditNoteDialog::EditNoteDialog (MidiRegionView* rv, set<NoteBase*> n)
|
2010-08-13 22:00:50 -04:00
|
|
|
: ArdourDialog (_("Note"))
|
|
|
|
, _region_view (rv)
|
2012-06-08 21:51:34 -04:00
|
|
|
, _events (n)
|
|
|
|
, _channel_all (_("Set selected notes to this channel"))
|
|
|
|
, _pitch_all (_("Set selected notes to this pitch"))
|
|
|
|
, _velocity_all (_("Set selected notes to this velocity"))
|
2011-11-17 17:49:13 -05:00
|
|
|
, _time_clock (X_("notetime"), true, "", true, false)
|
2012-06-08 21:51:34 -04:00
|
|
|
, _time_all (_("Set selected notes to this time"))
|
2011-11-17 17:49:13 -05:00
|
|
|
, _length_clock (X_("notelength"), true, "", true, false, true)
|
2012-06-08 21:51:34 -04:00
|
|
|
, _length_all (_("Set selected notes to this length"))
|
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);
|
2012-06-08 21:51:34 -04:00
|
|
|
table->attach (_channel_all, 2, 3, r, r + 1);
|
2010-08-13 22:00:50 -04:00
|
|
|
++r;
|
|
|
|
|
|
|
|
_channel.set_range (1, 16);
|
|
|
|
_channel.set_increments (1, 2);
|
2012-06-08 21:51:34 -04:00
|
|
|
_channel.set_value ((*_events.begin())->note()->channel () + 1);
|
2010-08-13 22:00:50 -04:00
|
|
|
|
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);
|
2012-06-08 21:51:34 -04:00
|
|
|
table->attach (_pitch_all, 2, 3, r, r + 1);
|
2010-08-13 22:00:50 -04:00
|
|
|
++r;
|
|
|
|
|
|
|
|
_pitch.set_range (0, 127);
|
|
|
|
_pitch.set_increments (1, 10);
|
2012-06-08 21:51:34 -04:00
|
|
|
_pitch.set_value ((*_events.begin())->note()->note());
|
2010-08-13 22:00:50 -04:00
|
|
|
|
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);
|
2012-06-08 21:51:34 -04:00
|
|
|
table->attach (_velocity_all, 2, 3, r, r + 1);
|
2010-08-13 22:00:50 -04:00
|
|
|
++r;
|
|
|
|
|
|
|
|
_velocity.set_range (0, 127);
|
|
|
|
_velocity.set_increments (1, 10);
|
2012-06-08 21:51:34 -04:00
|
|
|
_velocity.set_value ((*_events.begin())->note()->velocity ());
|
2010-08-13 22:00:50 -04:00
|
|
|
|
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);
|
2012-06-08 21:51:34 -04:00
|
|
|
table->attach (_time_all, 2, 3, r, r + 1);
|
2010-08-13 22:00:50 -04:00
|
|
|
++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);
|
2020-10-05 00:52:17 -04:00
|
|
|
|
2022-10-30 11:02:44 -04:00
|
|
|
/* Calculate absolute position of the event on time timeline */
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::Region> region (_region_view->region ());
|
2022-10-30 11:02:44 -04:00
|
|
|
timepos_t const pos = region->source_position() + timecnt_t ((*_events.begin())->note()->time ());
|
|
|
|
|
2020-10-05 00:52:17 -04:00
|
|
|
_time_clock.set (pos, 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);
|
2012-06-08 21:51:34 -04:00
|
|
|
table->attach (_length_all, 2, 3, r, r + 1);
|
2010-08-13 22:00:50 -04:00
|
|
|
++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);
|
2022-10-07 18:12:27 -04:00
|
|
|
_length_clock.set_duration (timecnt_t ((*_events.begin())->note()->length()), true);
|
2012-06-08 21:51:34 -04:00
|
|
|
|
|
|
|
/* Set up `set all notes...' buttons' sensitivity */
|
|
|
|
|
|
|
|
_channel_all.set_sensitive (false);
|
|
|
|
_pitch_all.set_sensitive (false);
|
|
|
|
_velocity_all.set_sensitive (false);
|
|
|
|
_time_all.set_sensitive (false);
|
|
|
|
_length_all.set_sensitive (false);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-08 21:51:34 -04:00
|
|
|
int test_channel = (*_events.begin())->note()->channel ();
|
|
|
|
int test_pitch = (*_events.begin())->note()->note ();
|
|
|
|
int test_velocity = (*_events.begin())->note()->velocity ();
|
2017-09-24 12:03:54 -04:00
|
|
|
Temporal::Beats test_time = (*_events.begin())->note()->time ();
|
|
|
|
Temporal::Beats test_length = (*_events.begin())->note()->length ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
|
2012-06-08 21:51:34 -04:00
|
|
|
if ((*i)->note()->channel() != test_channel) {
|
|
|
|
_channel_all.set_sensitive (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*i)->note()->note() != test_pitch) {
|
|
|
|
_pitch_all.set_sensitive (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*i)->note()->velocity() != test_velocity) {
|
|
|
|
_velocity_all.set_sensitive (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*i)->note()->time () != test_time) {
|
|
|
|
_time_all.set_sensitive (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*i)->note()->length () != test_length) {
|
|
|
|
_length_all.set_sensitive (true);
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-02 18:13:35 -04:00
|
|
|
void
|
|
|
|
EditNoteDialog::done (int r)
|
2010-08-13 22:00:50 -04:00
|
|
|
{
|
|
|
|
if (r != RESPONSE_ACCEPT) {
|
2017-07-01 12:42:24 -04:00
|
|
|
return;
|
2010-08-13 22:00:50 -04:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2012-06-08 21:51:34 -04:00
|
|
|
if (!_channel_all.get_sensitive() || _channel_all.get_active ()) {
|
2013-04-04 18:45:27 -04:00
|
|
|
for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
|
2012-06-08 21:51:34 -04:00
|
|
|
if (_channel.get_value_as_int() - 1 != (*i)->note()->channel()) {
|
|
|
|
_region_view->change_note_channel (*i, _channel.get_value_as_int () - 1);
|
|
|
|
had_change = true;
|
|
|
|
}
|
|
|
|
}
|
2010-08-13 22:00:50 -04:00
|
|
|
}
|
|
|
|
|
2012-06-08 21:51:34 -04:00
|
|
|
if (!_pitch_all.get_sensitive() || _pitch_all.get_active ()) {
|
2013-04-04 18:45:27 -04:00
|
|
|
for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
|
2012-06-08 21:51:34 -04:00
|
|
|
if (_pitch.get_value_as_int() != (*i)->note()->note()) {
|
|
|
|
_region_view->change_note_note (*i, _pitch.get_value_as_int ());
|
|
|
|
had_change = true;
|
|
|
|
}
|
|
|
|
}
|
2010-08-13 22:00:50 -04:00
|
|
|
}
|
|
|
|
|
2012-06-08 21:51:34 -04:00
|
|
|
if (!_velocity_all.get_sensitive() || _velocity_all.get_active ()) {
|
2013-04-04 18:45:27 -04:00
|
|
|
for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
|
2012-06-08 21:51:34 -04:00
|
|
|
if (_velocity.get_value_as_int() != (*i)->note()->velocity()) {
|
|
|
|
_region_view->change_note_velocity (*i, _velocity.get_value_as_int ());
|
|
|
|
had_change = true;
|
|
|
|
}
|
|
|
|
}
|
2010-08-13 22:00:50 -04:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::Region> region (_region_view->region ());
|
2020-10-05 00:52:17 -04:00
|
|
|
|
|
|
|
/* convert current clock time into an offset from the start of the source */
|
2022-11-14 09:52:15 -05:00
|
|
|
timecnt_t const time_clock_source_relative = region->source_position ().distance (_time_clock.last_when ());
|
2020-10-05 00:52:17 -04:00
|
|
|
|
|
|
|
/* convert that into a position in Beats - this will be the new note time (as an offset inside the source) */
|
|
|
|
Beats const new_note_time_source_relative_beats = time_clock_source_relative.beats ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2012-06-08 21:51:34 -04:00
|
|
|
if (!_time_all.get_sensitive() || _time_all.get_active ()) {
|
2013-04-04 18:45:27 -04:00
|
|
|
for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
|
2020-10-05 00:52:17 -04:00
|
|
|
if (new_note_time_source_relative_beats != (*i)->note()->time()) {
|
|
|
|
_region_view->change_note_time (*i, new_note_time_source_relative_beats);
|
2012-06-08 21:51:34 -04:00
|
|
|
had_change = true;
|
|
|
|
}
|
|
|
|
}
|
2010-08-13 22:00:50 -04:00
|
|
|
}
|
2020-10-05 00:52:17 -04:00
|
|
|
|
2022-06-03 22:58:31 -04:00
|
|
|
if (!_length_all.get_sensitive() || _length_all.get_active ()) {
|
|
|
|
Beats const new_note_length_beats = _length_clock.current_duration ().beats ();
|
2013-04-04 18:45:27 -04:00
|
|
|
for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
|
2020-10-05 00:52:17 -04:00
|
|
|
if (new_note_length_beats != (*i)->note()->length()) {
|
|
|
|
_region_view->change_note_length (*i, new_note_length_beats);
|
2012-06-08 21:51:34 -04:00
|
|
|
had_change = true;
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 00:52:17 -04:00
|
|
|
|
2010-08-13 22:00:50 -04:00
|
|
|
}
|
|
|
|
|
2022-05-09 15:42:07 -04:00
|
|
|
if (had_change) {
|
|
|
|
_region_view->apply_note_diff ();
|
|
|
|
} else {
|
|
|
|
_region_view->abort_note_diff ();
|
2010-08-13 22:00:50 -04:00
|
|
|
}
|
|
|
|
|
2016-11-22 12:55:56 -05:00
|
|
|
list<Evoral::event_id_t> notes;
|
2013-04-04 18:45:27 -04:00
|
|
|
for (set<NoteBase*>::iterator i = _events.begin(); i != _events.end(); ++i) {
|
2016-11-22 12:55:56 -05:00
|
|
|
notes.push_back ((*i)->note()->id());
|
2012-06-08 21:51:34 -04:00
|
|
|
}
|
2016-11-22 12:55:56 -05:00
|
|
|
|
2020-08-09 14:34:12 -04:00
|
|
|
_region_view->select_notes (notes, true);
|
2010-08-13 22:00:50 -04:00
|
|
|
}
|