2009-10-14 12:10:01 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2009-2015 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
|
2023-09-24 08:08:05 -04:00
|
|
|
* Copyright (C) 2014-2023 Robin Gareus <robin@gareus.org>
|
2019-08-02 17:26:43 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-10-19 17:53:09 -04:00
|
|
|
|
2010-01-04 22:52:30 -05:00
|
|
|
#include <cmath>
|
2012-02-01 15:11:57 -05:00
|
|
|
#include <map>
|
2009-08-26 23:09:30 -04:00
|
|
|
|
2012-01-31 22:33:42 -05:00
|
|
|
#include <gtkmm/cellrenderercombo.h>
|
|
|
|
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/Note.h"
|
2023-09-24 08:25:14 -04:00
|
|
|
#include "evoral/midi_util.h"
|
2010-01-05 09:56:42 -05:00
|
|
|
|
2011-10-19 17:53:09 -04:00
|
|
|
#include "ardour/midi_model.h"
|
2009-08-26 23:09:30 -04:00
|
|
|
#include "ardour/midi_region.h"
|
2011-10-19 17:53:09 -04:00
|
|
|
#include "ardour/midi_source.h"
|
2009-09-03 08:39:50 -04:00
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/tempo.h"
|
2009-08-26 23:09:30 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
#include "gtkmm2ext/actions.h"
|
2012-01-30 22:03:13 -05:00
|
|
|
#include "gtkmm2ext/gui_thread.h"
|
|
|
|
#include "gtkmm2ext/keyboard.h"
|
|
|
|
|
2009-08-26 23:09:30 -04:00
|
|
|
#include "midi_list_editor.h"
|
2012-01-31 22:33:42 -05:00
|
|
|
#include "note_player.h"
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ui_config.h"
|
2009-08-26 23:09:30 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2009-08-26 23:09:30 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
2012-02-01 16:30:00 -05:00
|
|
|
using namespace Gtkmm2ext;
|
2009-08-26 23:09:30 -04:00
|
|
|
using namespace Glib;
|
|
|
|
using namespace ARDOUR;
|
2020-07-23 19:46:49 -04:00
|
|
|
using Temporal::BBT_Time;
|
2009-08-26 23:09:30 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
static map<int32_t, std::string> note_length_map;
|
2012-02-01 15:11:57 -05:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
static void
|
2012-02-01 15:11:57 -05:00
|
|
|
fill_note_length_map ()
|
|
|
|
{
|
2023-09-24 08:25:14 -04:00
|
|
|
note_length_map.insert (make_pair<int32_t, string> (Temporal::ticks_per_beat * 4, _("Whole")));
|
|
|
|
note_length_map.insert (make_pair<int32_t, string> (Temporal::ticks_per_beat * 2, _("Half")));
|
|
|
|
note_length_map.insert (make_pair<int32_t, string> (Temporal::ticks_per_beat * 2 / 3, _("Triplet")));
|
|
|
|
note_length_map.insert (make_pair<int32_t, string> (Temporal::ticks_per_beat / 1, _("Quarter")));
|
|
|
|
note_length_map.insert (make_pair<int32_t, string> (Temporal::ticks_per_beat / 2, _("Eighth")));
|
|
|
|
note_length_map.insert (make_pair<int32_t, string> (Temporal::ticks_per_beat / 4, _("Sixteenth")));
|
|
|
|
note_length_map.insert (make_pair<int32_t, string> (Temporal::ticks_per_beat / 8, _("Thirty-second")));
|
|
|
|
note_length_map.insert (make_pair<int32_t, string> (Temporal::ticks_per_beat / 16, _("Sixty-fourth")));
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
MidiListEditor::MidiListEditor (Session* s, std::shared_ptr<MidiRegion> r, std::shared_ptr<MidiTrack> tr)
|
2023-09-24 08:25:14 -04:00
|
|
|
: ArdourWindow (r->name ())
|
2012-02-01 15:11:57 -05:00
|
|
|
, buttons (1, 1)
|
2009-08-26 23:09:30 -04:00
|
|
|
, region (r)
|
2012-01-31 22:33:42 -05:00
|
|
|
, track (tr)
|
2009-08-26 23:09:30 -04:00
|
|
|
{
|
2023-09-24 08:25:14 -04:00
|
|
|
if (note_length_map.empty ()) {
|
2012-02-01 15:11:57 -05:00
|
|
|
fill_note_length_map ();
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-05-30 07:57:12 -04:00
|
|
|
/* We do not handle nested sources/regions. Caller should have tackled this */
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
if (r->max_source_level () > 0) {
|
|
|
|
throw failed_constructor ();
|
2011-05-30 07:57:12 -04:00
|
|
|
}
|
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
set_session (s);
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
edit_column = -1;
|
2012-01-31 22:33:42 -05:00
|
|
|
editing_renderer = 0;
|
2012-02-01 15:11:57 -05:00
|
|
|
editing_editable = 0;
|
2012-01-31 22:33:42 -05:00
|
|
|
|
2009-08-26 23:09:30 -04:00
|
|
|
model = ListStore::create (columns);
|
|
|
|
view.set_model (model);
|
|
|
|
|
2012-01-31 22:33:42 -05:00
|
|
|
note_length_model = ListStore::create (note_length_columns);
|
|
|
|
TreeModel::Row row;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (std::map<int, string>::iterator i = note_length_map.begin (); i != note_length_map.end (); ++i) {
|
|
|
|
row = *(note_length_model->append ());
|
2012-02-01 15:11:57 -05:00
|
|
|
row[note_length_columns.ticks] = i->first;
|
2023-09-24 08:25:14 -04:00
|
|
|
row[note_length_columns.name] = i->second;
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
2012-01-31 22:33:42 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
view.signal_key_press_event ().connect (sigc::mem_fun (*this, &MidiListEditor::key_press), false);
|
|
|
|
view.signal_key_release_event ().connect (sigc::mem_fun (*this, &MidiListEditor::key_release), false);
|
|
|
|
view.signal_scroll_event ().connect (sigc::mem_fun (*this, &MidiListEditor::scroll_event), false);
|
2010-01-04 22:52:30 -05:00
|
|
|
|
2009-09-03 08:39:50 -04:00
|
|
|
view.append_column (_("Start"), columns.start);
|
2009-08-26 23:09:30 -04:00
|
|
|
view.append_column (_("Channel"), columns.channel);
|
2009-09-03 08:39:50 -04:00
|
|
|
view.append_column (_("Num"), columns.note);
|
2009-08-26 23:09:30 -04:00
|
|
|
view.append_column (_("Name"), columns.note_name);
|
2009-09-03 08:39:50 -04:00
|
|
|
view.append_column (_("Vel"), columns.velocity);
|
2012-01-31 22:33:42 -05:00
|
|
|
|
|
|
|
/* use a combo renderer for length, so that we can offer a selection
|
2023-09-24 08:25:14 -04:00
|
|
|
* of pre-defined note lengths. we still allow edited values with
|
|
|
|
* arbitrary length (in ticks).
|
2012-01-31 22:33:42 -05:00
|
|
|
*/
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
Gtk::TreeViewColumn* lenCol = Gtk::manage (new Gtk::TreeViewColumn (_("Length")));
|
|
|
|
Gtk::CellRendererCombo* comboCell = Gtk::manage (new Gtk::CellRendererCombo);
|
|
|
|
lenCol->pack_start (*comboCell);
|
|
|
|
lenCol->add_attribute (comboCell->property_text (), columns.length);
|
2012-01-31 22:33:42 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
comboCell->property_model () = note_length_model;
|
|
|
|
comboCell->property_text_column () = 1;
|
|
|
|
comboCell->property_has_entry () = false;
|
2012-01-31 22:33:42 -05:00
|
|
|
|
|
|
|
view.append_column (*lenCol);
|
2012-02-01 16:30:00 -05:00
|
|
|
|
2009-08-26 23:09:30 -04:00
|
|
|
view.set_headers_visible (true);
|
|
|
|
view.set_rules_hint (true);
|
2023-09-24 08:25:14 -04:00
|
|
|
view.get_selection ()->set_mode (SELECTION_MULTIPLE);
|
|
|
|
view.get_selection ()->signal_changed ().connect (sigc::mem_fun (*this, &MidiListEditor::selection_changed));
|
2009-08-26 23:09:30 -04:00
|
|
|
|
2023-09-24 08:08:05 -04:00
|
|
|
/* Editing the first column (BBT) as text is currently not supported
|
|
|
|
* -> use editable AudioClock, implement parse_as_bbt */
|
|
|
|
for (int i = 1; i < 6; ++i) {
|
2023-09-24 08:25:14 -04:00
|
|
|
CellRendererText* renderer = dynamic_cast<CellRendererText*> (view.get_column_cell_renderer (i));
|
2012-01-31 22:33:42 -05:00
|
|
|
|
2012-02-01 16:30:00 -05:00
|
|
|
TreeViewColumn* col = view.get_column (i);
|
2023-09-24 08:25:14 -04:00
|
|
|
col->set_data (X_("colnum"), GUINT_TO_POINTER (i));
|
2012-02-01 16:30:00 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
renderer->property_editable () = true;
|
2010-01-05 09:56:42 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
renderer->signal_editing_started ().connect (sigc::bind (sigc::mem_fun (*this, &MidiListEditor::editing_started), i));
|
|
|
|
renderer->signal_editing_canceled ().connect (sigc::mem_fun (*this, &MidiListEditor::editing_canceled));
|
|
|
|
renderer->signal_edited ().connect (sigc::mem_fun (*this, &MidiListEditor::edited));
|
2009-08-26 23:09:30 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-08-26 23:09:30 -04:00
|
|
|
scroller.add (view);
|
|
|
|
scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
|
|
|
|
|
|
|
|
redisplay_model ();
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
region->midi_source (0)->model ()->ContentsChanged.connect (content_connections, invalidator (*this),
|
|
|
|
boost::bind (&MidiListEditor::redisplay_model, this), gui_context ());
|
2021-05-07 16:46:30 -04:00
|
|
|
region->PropertyChanged.connect (content_connections, invalidator (*this),
|
2023-09-24 08:25:14 -04:00
|
|
|
boost::bind (&MidiListEditor::redisplay_model, this), gui_context ());
|
2012-01-30 22:03:13 -05:00
|
|
|
|
2012-02-01 15:11:57 -05:00
|
|
|
buttons.attach (sound_notes_button, 0, 1, 0, 1);
|
|
|
|
Glib::RefPtr<Gtk::Action> act = ActionManager::get_action ("Editor", "sound-midi-notes");
|
|
|
|
if (act) {
|
2023-09-24 08:25:14 -04:00
|
|
|
gtk_activatable_set_related_action (GTK_ACTIVATABLE (sound_notes_button.gobj ()), act->gobj ());
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
|
|
|
|
2009-08-26 23:09:30 -04:00
|
|
|
view.show ();
|
|
|
|
scroller.show ();
|
2012-01-31 22:33:42 -05:00
|
|
|
buttons.show ();
|
|
|
|
vbox.show ();
|
2012-02-01 15:11:57 -05:00
|
|
|
sound_notes_button.show ();
|
2009-08-26 23:09:30 -04:00
|
|
|
|
2012-02-01 15:11:57 -05:00
|
|
|
vbox.set_spacing (6);
|
|
|
|
vbox.set_border_width (6);
|
2012-01-31 22:33:42 -05:00
|
|
|
vbox.pack_start (buttons, false, false);
|
|
|
|
vbox.pack_start (scroller, true, true);
|
|
|
|
|
|
|
|
add (vbox);
|
2012-01-30 22:03:13 -05:00
|
|
|
set_size_request (-1, 400);
|
2009-08-26 23:09:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MidiListEditor::~MidiListEditor ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-01 16:30:00 -05:00
|
|
|
bool
|
|
|
|
MidiListEditor::scroll_event (GdkEventScroll* ev)
|
|
|
|
{
|
|
|
|
TreeModel::Path path;
|
|
|
|
TreeViewColumn* col;
|
2023-09-24 08:25:14 -04:00
|
|
|
int cellx;
|
|
|
|
int celly;
|
|
|
|
int idelta = 0;
|
2020-12-18 15:07:48 -05:00
|
|
|
Temporal::Beats beat_delta;
|
2023-09-24 08:25:14 -04:00
|
|
|
bool apply = false;
|
|
|
|
bool was_selected = false;
|
|
|
|
char const* opname;
|
|
|
|
|
2012-02-01 16:30:00 -05:00
|
|
|
MidiModel::NoteDiffCommand::Property prop (MidiModel::NoteDiffCommand::NoteNumber);
|
|
|
|
|
|
|
|
if (!view.get_path_at_pos (ev->x, ev->y, path, col, cellx, celly)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
if (view.get_selection ()->count_selected_rows () == 0) {
|
2012-02-01 16:30:00 -05:00
|
|
|
was_selected = false;
|
2023-09-24 08:25:14 -04:00
|
|
|
} else if (view.get_selection ()->is_selected (path)) {
|
2012-02-01 16:30:00 -05:00
|
|
|
was_selected = true;
|
|
|
|
} else {
|
|
|
|
was_selected = false;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-02-01 16:30:00 -05:00
|
|
|
int colnum = GPOINTER_TO_UINT (col->get_data (X_("colnum")));
|
|
|
|
|
|
|
|
switch (colnum) {
|
2023-09-24 08:25:14 -04:00
|
|
|
case 0:
|
|
|
|
/* This is dangerous. Changing position with the mouse-wheel can reorder
|
|
|
|
* notes. The mouse-position does not change and then affect different notes.
|
|
|
|
*/
|
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::GainFineScaleModifier)) {
|
|
|
|
beat_delta = Temporal::Beats::ticks (Temporal::ticks_per_beat / 64);
|
|
|
|
} else {
|
|
|
|
beat_delta = Temporal::Beats (1, 0);
|
|
|
|
}
|
|
|
|
if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
|
|
|
|
beat_delta = -beat_delta;
|
|
|
|
}
|
|
|
|
prop = MidiModel::NoteDiffCommand::StartTime;
|
|
|
|
opname = _("edit note start");
|
|
|
|
apply = true;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
idelta = 1;
|
|
|
|
if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
|
|
|
|
idelta = -idelta;
|
|
|
|
}
|
|
|
|
prop = MidiModel::NoteDiffCommand::Channel;
|
|
|
|
opname = _("edit note channel");
|
|
|
|
apply = true;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
idelta = 1;
|
|
|
|
if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
|
|
|
|
idelta = -idelta;
|
|
|
|
}
|
|
|
|
prop = MidiModel::NoteDiffCommand::NoteNumber;
|
|
|
|
opname = _("edit note number");
|
|
|
|
apply = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
idelta = 1;
|
|
|
|
if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
|
|
|
|
idelta = -idelta;
|
|
|
|
}
|
|
|
|
prop = MidiModel::NoteDiffCommand::Velocity;
|
|
|
|
opname = _("edit note velocity");
|
|
|
|
apply = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::GainFineScaleModifier)) {
|
|
|
|
beat_delta = Temporal::Beats::ticks (Temporal::ticks_per_beat / 64);
|
|
|
|
} else {
|
|
|
|
beat_delta = Temporal::Beats (1, 0);
|
|
|
|
}
|
|
|
|
if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
|
|
|
|
beat_delta = -beat_delta;
|
|
|
|
}
|
|
|
|
prop = MidiModel::NoteDiffCommand::Length;
|
|
|
|
opname = _("edit note length");
|
|
|
|
apply = true;
|
|
|
|
break;
|
2012-02-01 16:30:00 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
default:
|
|
|
|
break;
|
2012-02-01 16:30:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (apply) {
|
2023-09-24 08:25:14 -04:00
|
|
|
std::shared_ptr<MidiModel> m (region->midi_source (0)->model ());
|
2012-02-01 16:30:00 -05:00
|
|
|
MidiModel::NoteDiffCommand* cmd = m->new_note_diff_command (opname);
|
2023-09-24 08:25:14 -04:00
|
|
|
vector<TreeModel::Path> previous_selection;
|
2012-02-01 16:30:00 -05:00
|
|
|
|
|
|
|
if (was_selected) {
|
|
|
|
/* use selection */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
TreeView::Selection::ListHandle_Path rows = view.get_selection ()->get_selected_rows ();
|
|
|
|
TreeModel::iterator iter;
|
|
|
|
std::shared_ptr<NoteType> note;
|
2012-02-01 16:30:00 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin (); i != rows.end (); ++i) {
|
2012-02-01 16:30:00 -05:00
|
|
|
previous_selection.push_back (*i);
|
|
|
|
|
2012-05-23 22:54:10 -04:00
|
|
|
if ((iter = model->get_iter (*i))) {
|
2015-10-05 10:17:49 -04:00
|
|
|
note = (*iter)[columns._note];
|
|
|
|
|
2012-02-01 16:30:00 -05:00
|
|
|
switch (prop) {
|
2023-09-24 08:25:14 -04:00
|
|
|
case MidiModel::NoteDiffCommand::StartTime:
|
|
|
|
if (note->time () + beat_delta >= Temporal::Beats ()) {
|
|
|
|
cmd->change (note, prop, note->time () + beat_delta);
|
|
|
|
} else {
|
|
|
|
cmd->change (note, prop, Temporal::Beats ());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::Velocity:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->velocity () + idelta));
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::Length:
|
|
|
|
if (note->length () <= Temporal::Beats::one_tick () && beat_delta.to_ticks () > 0) {
|
|
|
|
/* Special case increments starting at 1 tick.
|
|
|
|
* Next step up after 1 is 1920 (not 1921) - or fine grained 30 (not 31).
|
|
|
|
*/
|
|
|
|
cmd->change (note, prop, beat_delta);
|
|
|
|
} else if (note->length () + beat_delta >= Temporal::Beats::one_tick ()) {
|
|
|
|
cmd->change (note, prop, note->length () + beat_delta);
|
|
|
|
} else {
|
|
|
|
cmd->change (note, prop, Temporal::Beats::one_tick ());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::Channel:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->channel () + idelta));
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::NoteNumber:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->note () + idelta));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
2012-02-01 16:30:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* just this row */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-02-01 16:30:00 -05:00
|
|
|
TreeModel::iterator iter;
|
|
|
|
iter = model->get_iter (path);
|
|
|
|
|
|
|
|
previous_selection.push_back (path);
|
|
|
|
|
|
|
|
if (iter) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<NoteType> note = (*iter)[columns._note];
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-02-01 16:30:00 -05:00
|
|
|
switch (prop) {
|
2023-09-24 08:25:14 -04:00
|
|
|
case MidiModel::NoteDiffCommand::StartTime:
|
|
|
|
if (note->time () + beat_delta >= Temporal::Beats ()) {
|
|
|
|
cmd->change (note, prop, note->time () + beat_delta);
|
|
|
|
} else {
|
|
|
|
cmd->change (note, prop, Temporal::Beats ());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::Velocity:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->velocity () + idelta));
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::Length:
|
|
|
|
if (note->length () + beat_delta >= Temporal::Beats::one_tick ()) {
|
|
|
|
cmd->change (note, prop, note->length () + beat_delta);
|
|
|
|
} else {
|
|
|
|
cmd->change (note, prop, Temporal::Beats::one_tick ());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::Channel:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->channel () + idelta));
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::NoteNumber:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->note () + idelta));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-02-01 16:30:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-09 12:58:59 -04:00
|
|
|
m->apply_diff_command_as_commit (*_session, cmd);
|
2012-02-01 16:30:00 -05:00
|
|
|
|
|
|
|
/* reset selection to be as it was before we rebuilt */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (vector<TreeModel::Path>::iterator i = previous_selection.begin (); i != previous_selection.end (); ++i) {
|
|
|
|
view.get_selection ()->select (*i);
|
2012-02-01 16:30:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-04 22:52:30 -05:00
|
|
|
bool
|
|
|
|
MidiListEditor::key_press (GdkEventKey* ev)
|
|
|
|
{
|
2023-09-24 08:25:14 -04:00
|
|
|
bool ret = false;
|
2012-01-31 22:33:42 -05:00
|
|
|
TreeModel::Path path;
|
|
|
|
TreeViewColumn* col;
|
2023-09-24 08:25:14 -04:00
|
|
|
int colnum;
|
2010-01-05 09:56:42 -05:00
|
|
|
|
2012-01-31 22:33:42 -05:00
|
|
|
switch (ev->keyval) {
|
2023-09-24 08:25:14 -04:00
|
|
|
case GDK_Tab:
|
|
|
|
if (edit_column > 0) {
|
|
|
|
colnum = edit_column;
|
|
|
|
path = edit_path;
|
|
|
|
if (editing_editable) {
|
|
|
|
editing_editable->editing_done ();
|
|
|
|
}
|
|
|
|
if (colnum >= 5) {
|
|
|
|
/* wrap to next line */
|
|
|
|
/* XXX never reached. Editing Length shows a dropdown menu,
|
|
|
|
* which returns edit focus to the dialog.
|
|
|
|
*/
|
|
|
|
colnum = 0;
|
|
|
|
path.next ();
|
|
|
|
} else {
|
|
|
|
colnum++;
|
|
|
|
}
|
|
|
|
if (!path.empty ()) {
|
|
|
|
col = view.get_column (colnum);
|
|
|
|
view.set_cursor (path, *col, true);
|
|
|
|
}
|
|
|
|
ret = true;
|
2023-09-24 08:08:05 -04:00
|
|
|
}
|
2023-09-24 08:25:14 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Up:
|
|
|
|
case GDK_uparrow:
|
|
|
|
if (edit_column > 0) {
|
|
|
|
colnum = edit_column;
|
|
|
|
path = edit_path;
|
|
|
|
if (editing_editable) {
|
|
|
|
editing_editable->editing_done ();
|
|
|
|
}
|
|
|
|
path.prev ();
|
|
|
|
if (!path.empty ()) {
|
|
|
|
col = view.get_column (colnum);
|
|
|
|
view.set_cursor (path, *col, true);
|
|
|
|
}
|
|
|
|
ret = true;
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
2023-09-24 08:25:14 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Down:
|
|
|
|
case GDK_downarrow:
|
|
|
|
if (edit_column > 0) {
|
|
|
|
colnum = edit_column;
|
|
|
|
path = edit_path;
|
|
|
|
if (editing_editable) {
|
|
|
|
editing_editable->editing_done ();
|
|
|
|
}
|
|
|
|
path.next ();
|
|
|
|
if (!path.empty ()) {
|
|
|
|
col = view.get_column (colnum);
|
|
|
|
view.set_cursor (path, *col, true);
|
|
|
|
}
|
|
|
|
ret = true;
|
2023-09-24 08:08:05 -04:00
|
|
|
}
|
2023-09-24 08:25:14 -04:00
|
|
|
break;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
case GDK_Escape:
|
|
|
|
stop_editing (true);
|
|
|
|
break;
|
2010-01-05 09:56:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2010-01-04 22:52:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MidiListEditor::key_release (GdkEventKey* ev)
|
|
|
|
{
|
2023-09-24 08:25:14 -04:00
|
|
|
bool ret = false;
|
|
|
|
TreeModel::Path path;
|
|
|
|
TreeViewColumn* col;
|
|
|
|
TreeModel::iterator iter;
|
2012-01-31 22:33:42 -05:00
|
|
|
MidiModel::NoteDiffCommand* cmd;
|
2023-09-24 08:25:14 -04:00
|
|
|
std::shared_ptr<MidiModel> m (region->midi_source (0)->model ());
|
|
|
|
std::shared_ptr<NoteType> note;
|
|
|
|
std::shared_ptr<NoteType> copy;
|
2010-01-05 09:56:42 -05:00
|
|
|
|
2010-01-04 22:52:30 -05:00
|
|
|
switch (ev->keyval) {
|
2023-09-24 08:25:14 -04:00
|
|
|
case GDK_Insert:
|
|
|
|
/* add a new note to the model, based on the note at the cursor pos */
|
|
|
|
view.get_cursor (path, col);
|
|
|
|
iter = model->get_iter (path);
|
|
|
|
cmd = m->new_note_diff_command (_("insert new note"));
|
|
|
|
if (iter) {
|
|
|
|
note = (*iter)[columns._note];
|
|
|
|
copy.reset (new NoteType (*note.get ()));
|
|
|
|
} else {
|
|
|
|
Temporal::Beats pos = Temporal::TempoMap::use ()->quarters_at_sample (region->start ().samples ());
|
|
|
|
copy.reset (new NoteType (0, pos, Temporal::Beats (1, 0), 60, 100));
|
|
|
|
}
|
|
|
|
cmd->add (copy);
|
|
|
|
m->apply_diff_command_as_commit (*_session, cmd);
|
|
|
|
/* model has been redisplayed by now */
|
|
|
|
path.next ();
|
|
|
|
if (!path.empty ()) {
|
|
|
|
/* select, start editing column 2 (note) */
|
|
|
|
col = view.get_column (2);
|
|
|
|
view.set_cursor (path, *col, true);
|
|
|
|
}
|
|
|
|
break;
|
2012-01-31 22:33:42 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
case GDK_Delete:
|
|
|
|
case GDK_BackSpace:
|
|
|
|
if (edit_column < 0) {
|
|
|
|
delete_selected_note ();
|
|
|
|
}
|
2012-01-31 22:33:42 -05:00
|
|
|
ret = true;
|
2023-09-24 08:25:14 -04:00
|
|
|
break;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
case GDK_z:
|
|
|
|
if (_session && Gtkmm2ext::Keyboard::modifier_state_contains (ev->state, Gtkmm2ext::Keyboard::PrimaryModifier)) {
|
|
|
|
_session->undo (1);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_r:
|
|
|
|
if (_session && Gtkmm2ext::Keyboard::modifier_state_contains (ev->state, Gtkmm2ext::Keyboard::PrimaryModifier)) {
|
|
|
|
_session->redo (1);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
break;
|
2012-01-30 22:03:13 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
default:
|
|
|
|
break;
|
2010-01-04 22:52:30 -05:00
|
|
|
}
|
|
|
|
|
2010-01-05 09:56:42 -05:00
|
|
|
return ret;
|
2010-01-04 22:52:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiListEditor::delete_selected_note ()
|
|
|
|
{
|
2023-09-24 08:25:14 -04:00
|
|
|
Glib::RefPtr<TreeSelection> selection = view.get_selection ();
|
|
|
|
TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
|
2010-01-04 22:52:30 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
if (rows.empty ()) {
|
2010-01-04 22:52:30 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
typedef vector<std::shared_ptr<NoteType>> Notes;
|
|
|
|
Notes to_delete;
|
2012-01-30 22:03:13 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin (); i != rows.end (); ++i) {
|
2012-01-30 22:03:13 -05:00
|
|
|
TreeIter iter;
|
|
|
|
|
|
|
|
if ((iter = model->get_iter (*i))) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<NoteType> note = (*iter)[columns._note];
|
2012-01-30 22:03:13 -05:00
|
|
|
to_delete.push_back (note);
|
|
|
|
}
|
|
|
|
}
|
2010-01-04 22:52:30 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
std::shared_ptr<MidiModel> m (region->midi_source (0)->model ());
|
2012-01-30 22:03:13 -05:00
|
|
|
MidiModel::NoteDiffCommand* cmd = m->new_note_diff_command (_("delete notes (from list)"));
|
2010-01-04 22:52:30 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (Notes::iterator i = to_delete.begin (); i != to_delete.end (); ++i) {
|
2012-01-30 22:03:13 -05:00
|
|
|
cmd->remove (*i);
|
2010-01-04 22:52:30 -05:00
|
|
|
}
|
|
|
|
|
2022-05-09 12:58:59 -04:00
|
|
|
m->apply_diff_command_as_commit (*_session, cmd);
|
2010-01-04 22:52:30 -05:00
|
|
|
}
|
2010-01-05 09:56:42 -05:00
|
|
|
|
2012-01-31 22:33:42 -05:00
|
|
|
void
|
|
|
|
MidiListEditor::stop_editing (bool cancelled)
|
|
|
|
{
|
2012-02-01 15:11:57 -05:00
|
|
|
if (!cancelled) {
|
|
|
|
if (editing_editable) {
|
|
|
|
editing_editable->editing_done ();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (editing_renderer) {
|
|
|
|
editing_renderer->stop_editing (cancelled);
|
|
|
|
}
|
2012-01-31 22:33:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 09:56:42 -05:00
|
|
|
void
|
2012-02-01 15:11:57 -05:00
|
|
|
MidiListEditor::editing_started (CellEditable* ed, const string& path, int colno)
|
2010-01-05 09:56:42 -05:00
|
|
|
{
|
2023-09-24 08:25:14 -04:00
|
|
|
edit_path = TreePath (path);
|
|
|
|
edit_column = colno;
|
|
|
|
editing_renderer = dynamic_cast<CellRendererText*> (view.get_column_cell_renderer (colno));
|
2012-02-01 15:11:57 -05:00
|
|
|
editing_editable = ed;
|
|
|
|
|
|
|
|
if (ed) {
|
2023-09-24 08:25:14 -04:00
|
|
|
Gtk::Entry* e = dynamic_cast<Gtk::Entry*> (ed);
|
2012-02-01 15:11:57 -05:00
|
|
|
if (e) {
|
2023-09-24 08:25:14 -04:00
|
|
|
e->signal_key_press_event ().connect (sigc::mem_fun (*this, &MidiListEditor::key_press), false);
|
|
|
|
e->signal_key_release_event ().connect (sigc::mem_fun (*this, &MidiListEditor::key_release), false);
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
|
|
|
}
|
2010-01-05 09:56:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiListEditor::editing_canceled ()
|
|
|
|
{
|
2012-01-31 22:33:42 -05:00
|
|
|
edit_path.clear ();
|
2023-09-24 08:25:14 -04:00
|
|
|
edit_column = -1;
|
2012-01-31 22:33:42 -05:00
|
|
|
editing_renderer = 0;
|
2012-02-01 15:11:57 -05:00
|
|
|
editing_editable = 0;
|
2010-01-05 09:56:42 -05:00
|
|
|
}
|
|
|
|
|
2009-08-26 23:09:30 -04:00
|
|
|
void
|
2012-01-31 22:33:42 -05:00
|
|
|
MidiListEditor::edited (const std::string& path, const std::string& text)
|
2009-08-26 23:09:30 -04:00
|
|
|
{
|
2009-09-03 08:39:50 -04:00
|
|
|
TreeModel::iterator iter = model->get_iter (path);
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
if (!iter || text.empty ()) {
|
2009-09-03 08:39:50 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
std::shared_ptr<NoteType> note = (*iter)[columns._note];
|
2012-02-01 15:11:57 -05:00
|
|
|
MidiModel::NoteDiffCommand::Property prop (MidiModel::NoteDiffCommand::NoteNumber);
|
2009-09-03 08:39:50 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
Temporal::Beats bval;
|
|
|
|
int ival;
|
|
|
|
bool apply = false;
|
|
|
|
int idelta = 0;
|
2020-07-13 20:03:18 -04:00
|
|
|
Temporal::Beats delta;
|
2023-09-24 08:25:14 -04:00
|
|
|
char const* opname;
|
2012-01-31 22:33:42 -05:00
|
|
|
switch (edit_column) {
|
2023-09-24 08:25:14 -04:00
|
|
|
case 0: // start
|
|
|
|
break;
|
|
|
|
case 1: // channel
|
|
|
|
/* correct ival for zero-based counting after scan */
|
|
|
|
if (sscanf (text.c_str (), "%d", &ival) == 1 && --ival != note->channel ()) {
|
|
|
|
idelta = ival - note->channel ();
|
|
|
|
prop = MidiModel::NoteDiffCommand::Channel;
|
|
|
|
opname = _("change note channel");
|
|
|
|
apply = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: // note
|
|
|
|
if (sscanf (text.c_str (), "%d", &ival) == 1 && ival != note->note ()) {
|
|
|
|
idelta = ival - note->note ();
|
|
|
|
prop = MidiModel::NoteDiffCommand::NoteNumber;
|
|
|
|
opname = _("change note number");
|
|
|
|
apply = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: // name
|
|
|
|
ival = ParameterDescriptor::midi_note_num (text);
|
|
|
|
if (ival < 128) {
|
|
|
|
idelta = ival - note->note ();
|
|
|
|
prop = MidiModel::NoteDiffCommand::NoteNumber;
|
|
|
|
opname = _("change note number");
|
|
|
|
apply = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: // velocity
|
|
|
|
if (sscanf (text.c_str (), "%d", &ival) == 1 && ival != note->velocity ()) {
|
|
|
|
idelta = ival - note->velocity ();
|
|
|
|
prop = MidiModel::NoteDiffCommand::Velocity;
|
|
|
|
opname = _("change note velocity");
|
|
|
|
apply = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5: // length
|
2012-02-01 15:11:57 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
try {
|
|
|
|
stringstream ss (text);
|
|
|
|
ss >> bval;
|
2012-02-01 15:11:57 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
} catch (...) {
|
|
|
|
/* assume its text from the combo. look for the map
|
|
|
|
* entry for the actual note ticks
|
2012-02-01 15:11:57 -05:00
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
uint64_t len_ticks = note->length ().to_ticks ();
|
|
|
|
std::map<int, string>::iterator x = note_length_map.find (len_ticks);
|
2012-02-01 15:11:57 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
if (x == note_length_map.end ()) {
|
|
|
|
/* tick length not in map - was
|
|
|
|
* displaying numeric value ... use new value
|
|
|
|
* from note length map, and convert to beats.
|
2012-02-01 15:11:57 -05:00
|
|
|
*/
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (x = note_length_map.begin (); x != note_length_map.end (); ++x) {
|
2012-02-01 15:11:57 -05:00
|
|
|
if (x->second == text) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
if (x != note_length_map.end ()) {
|
2023-09-24 06:55:10 -04:00
|
|
|
bval = Temporal::Beats::ticks (x->first);
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
2023-09-24 08:25:14 -04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
bval = Temporal::Beats ();
|
|
|
|
|
|
|
|
if (text != x->second) {
|
|
|
|
/* get ticks for the newly selected
|
|
|
|
* note length
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (x = note_length_map.begin (); x != note_length_map.end (); ++x) {
|
|
|
|
if (x->second == text) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x != note_length_map.end ()) {
|
|
|
|
/* convert to beats */
|
|
|
|
bval = Temporal::Beats::ticks (x->first);
|
|
|
|
}
|
|
|
|
}
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
2012-01-31 22:33:42 -05:00
|
|
|
}
|
2012-02-01 15:11:57 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
if (bval) {
|
|
|
|
delta = bval - note->length ();
|
|
|
|
prop = MidiModel::NoteDiffCommand::Length;
|
|
|
|
opname = _("change note length");
|
|
|
|
apply = true;
|
|
|
|
}
|
|
|
|
break;
|
2012-02-01 15:11:57 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
default:
|
|
|
|
break;
|
2012-01-31 22:33:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (apply) {
|
2023-09-24 08:25:14 -04:00
|
|
|
std::shared_ptr<MidiModel> m (region->midi_source (0)->model ());
|
2012-02-01 15:11:57 -05:00
|
|
|
MidiModel::NoteDiffCommand* cmd = m->new_note_diff_command (opname);
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
TreeView::Selection::ListHandle_Path rows = view.get_selection ()->get_selected_rows ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin (); i != rows.end (); ++i) {
|
2012-05-23 22:54:10 -04:00
|
|
|
if ((iter = model->get_iter (*i))) {
|
2015-10-05 10:17:49 -04:00
|
|
|
note = (*iter)[columns._note];
|
|
|
|
|
2012-02-01 15:11:57 -05:00
|
|
|
switch (prop) {
|
2023-09-24 08:25:14 -04:00
|
|
|
case MidiModel::NoteDiffCommand::Velocity:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->velocity () + idelta));
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::Length:
|
|
|
|
cmd->change (note, prop, note->length () + delta);
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::Channel:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->channel () + idelta));
|
|
|
|
break;
|
|
|
|
case MidiModel::NoteDiffCommand::NoteNumber:
|
|
|
|
cmd->change (note, prop, (uint8_t) (note->note () + idelta));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-09 12:58:59 -04:00
|
|
|
m->apply_diff_command_as_commit (*_session, cmd);
|
2012-01-31 22:33:42 -05:00
|
|
|
|
2012-02-01 15:11:57 -05:00
|
|
|
/* model has been redisplayed by now */
|
|
|
|
/* keep selected row(s), move cursor there, don't continue editing */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-02-01 15:11:57 -05:00
|
|
|
TreeViewColumn* col = view.get_column (edit_column);
|
|
|
|
view.set_cursor (edit_path, *col, 0);
|
|
|
|
|
|
|
|
/* reset edit info, since we're done */
|
|
|
|
|
|
|
|
edit_path.clear ();
|
2023-09-24 08:25:14 -04:00
|
|
|
edit_column = -1;
|
2012-02-01 15:11:57 -05:00
|
|
|
editing_renderer = 0;
|
|
|
|
editing_editable = 0;
|
|
|
|
}
|
2009-08-26 23:09:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiListEditor::redisplay_model ()
|
|
|
|
{
|
2023-09-24 08:25:14 -04:00
|
|
|
view.set_model (Glib::RefPtr<Gtk::ListStore> (0));
|
2009-08-26 23:09:30 -04:00
|
|
|
model->clear ();
|
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
if (_session) {
|
2023-09-24 08:25:14 -04:00
|
|
|
std::shared_ptr<MidiModel> m (region->midi_source (0)->model ());
|
|
|
|
TreeModel::Row row;
|
|
|
|
stringstream ss;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
MidiModel::Notes::const_iterator i = m->note_lower_bound (region->start ().beats ());
|
|
|
|
Temporal::Beats end_time = (region->start () + region->length ()).beats ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (; i != m->notes ().end () && (*i)->time () < end_time; ++i) {
|
|
|
|
row = *(model->append ());
|
|
|
|
row[columns.channel] = (*i)->channel () + 1;
|
|
|
|
row[columns.note_name] = ParameterDescriptor::midi_note_name ((*i)->note ());
|
|
|
|
row[columns.note] = (*i)->note ();
|
|
|
|
row[columns.velocity] = (*i)->velocity ();
|
2020-10-15 01:09:22 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
Temporal::BBT_Time bbt = Temporal::TempoMap::use ()->bbt_at ((region->position () + timepos_t ((*i)->time ())).earlier (region->start ()));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-01-04 22:52:30 -05:00
|
|
|
ss.str ("");
|
2009-12-17 13:24:23 -05:00
|
|
|
ss << bbt;
|
2023-09-24 08:25:14 -04:00
|
|
|
row[columns.start] = ss.str ();
|
2010-01-04 22:52:30 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
bbt.bars = 0;
|
|
|
|
const Temporal::Beats dur = (*i)->end_time () - (*i)->time ();
|
|
|
|
bbt.beats = dur.get_beats ();
|
|
|
|
bbt.ticks = dur.get_ticks ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
uint64_t len_ticks = (*i)->length ().to_ticks ();
|
|
|
|
std::map<int, string>::iterator x = note_length_map.find (len_ticks);
|
2012-02-01 15:11:57 -05:00
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
if (x != note_length_map.end ()) {
|
2012-02-01 15:11:57 -05:00
|
|
|
row[columns.length] = x->second;
|
|
|
|
} else {
|
|
|
|
ss.str ("");
|
|
|
|
ss << len_ticks;
|
2023-09-24 08:25:14 -04:00
|
|
|
row[columns.length] = ss.str ();
|
2012-02-01 15:11:57 -05:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
row[columns._note] = (*i);
|
|
|
|
}
|
2009-08-26 23:09:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
view.set_model (model);
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2012-01-31 22:33:42 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
MidiListEditor::selection_changed ()
|
|
|
|
{
|
2023-09-24 08:25:14 -04:00
|
|
|
if (!UIConfiguration::instance ().get_sound_midi_notes ()) {
|
2012-01-31 22:33:42 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
TreeModel::Path path;
|
|
|
|
TreeModel::iterator iter;
|
|
|
|
std::shared_ptr<NoteType> note;
|
|
|
|
TreeView::Selection::ListHandle_Path rows = view.get_selection ()->get_selected_rows ();
|
2012-01-31 22:33:42 -05:00
|
|
|
|
|
|
|
NotePlayer* player = new NotePlayer (track);
|
|
|
|
|
2023-09-24 08:25:14 -04:00
|
|
|
for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin (); i != rows.end (); ++i) {
|
2012-05-23 22:54:10 -04:00
|
|
|
if ((iter = model->get_iter (*i))) {
|
2015-10-05 10:17:49 -04:00
|
|
|
note = (*iter)[columns._note];
|
2012-01-31 22:33:42 -05:00
|
|
|
player->add (note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player->play ();
|
|
|
|
}
|