X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gtk2_ardour%2Fmidi_list_editor.cc;h=bc17c7aee02bdd730f04cdbd7958a45d1bb7f963;hb=30553a267551405712f3b2a3ef1f612630be6477;hp=0a87823f8e577845060f9e2c34a3edd97d1a3f5f;hpb=57c1b6e261076cae9b61e74aa0aff47a9f296c0f;p=ardour.git diff --git a/gtk2_ardour/midi_list_editor.cc b/gtk2_ardour/midi_list_editor.cc index 0a87823f8e..bc17c7aee0 100644 --- a/gtk2_ardour/midi_list_editor.cc +++ b/gtk2_ardour/midi_list_editor.cc @@ -1,20 +1,22 @@ /* - Copyright (C) 2009 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. -*/ + * Copyright (C) 2009-2015 David Robillard + * Copyright (C) 2009-2017 Paul Davis + * Copyright (C) 2014-2016 Robin Gareus + * + * 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. + */ #include #include @@ -22,9 +24,9 @@ #include #include "evoral/midi_util.h" -#include "evoral/Note.hpp" +#include "evoral/Note.h" -#include "ardour/beats_frames_converter.h" +#include "ardour/beats_samples_converter.h" #include "ardour/midi_model.h" #include "ardour/midi_region.h" #include "ardour/midi_source.h" @@ -37,8 +39,9 @@ #include "midi_list_editor.h" #include "note_player.h" +#include "ui_config.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace Gtk; @@ -49,7 +52,7 @@ using Timecode::BBT_Time; static map note_length_map; -static void +static void fill_note_length_map () { note_length_map.insert (make_pair (BBT_Time::ticks_per_beat, _("Whole"))); @@ -71,7 +74,7 @@ MidiListEditor::MidiListEditor (Session* s, boost::shared_ptr r, boo if (note_length_map.empty()) { fill_note_length_map (); } - + /* We do not handle nested sources/regions. Caller should have tackled this */ if (r->max_source_level() > 0) { @@ -89,7 +92,7 @@ MidiListEditor::MidiListEditor (Session* s, boost::shared_ptr r, boo note_length_model = ListStore::create (note_length_columns); TreeModel::Row row; - + for (std::map::iterator i = note_length_map.begin(); i != note_length_map.end(); ++i) { row = *(note_length_model->append()); row[note_length_columns.ticks] = i->first; @@ -145,13 +148,13 @@ MidiListEditor::MidiListEditor (Session* s, boost::shared_ptr r, boo redisplay_model (); - region->midi_source(0)->model()->ContentsChanged.connect (content_connection, invalidator (*this), + region->midi_source(0)->model()->ContentsChanged.connect (content_connection, invalidator (*this), boost::bind (&MidiListEditor::redisplay_model, this), gui_context()); buttons.attach (sound_notes_button, 0, 1, 0, 1); Glib::RefPtr act = ActionManager::get_action ("Editor", "sound-midi-notes"); if (act) { - gtk_activatable_set_related_action (GTK_ACTIVATABLE (sound_notes_button.gobj()), act->gobj()); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (sound_notes_button.gobj()), act->gobj()); } view.show (); @@ -190,7 +193,7 @@ MidiListEditor::scroll_event (GdkEventScroll* ev) if (!view.get_path_at_pos (ev->x, ev->y, path, col, cellx, celly)) { return false; } - + if (view.get_selection()->count_selected_rows() == 0) { was_selected = false; } else if (view.get_selection()->is_selected (path)) { @@ -198,7 +201,7 @@ MidiListEditor::scroll_event (GdkEventScroll* ev) } else { was_selected = false; } - + int colnum = GPOINTER_TO_UINT (col->get_data (X_("colnum"))); switch (colnum) { @@ -273,25 +276,25 @@ MidiListEditor::scroll_event (GdkEventScroll* ev) if (was_selected) { /* use selection */ - + TreeView::Selection::ListHandle_Path rows = view.get_selection()->get_selected_rows (); TreeModel::iterator iter; boost::shared_ptr note; - + for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) { previous_selection.push_back (*i); if ((iter = model->get_iter (*i))) { - - note = (*iter)[columns._note]; - + + note = (*iter)[columns._note]; + switch (prop) { case MidiModel::NoteDiffCommand::StartTime: if (note->time() + fdelta >= 0) { cmd->change (note, prop, note->time() + fdelta); } else { - cmd->change (note, prop, Evoral::MusicalTime()); + cmd->change (note, prop, Temporal::Beats()); } break; case MidiModel::NoteDiffCommand::Velocity: @@ -299,10 +302,10 @@ MidiListEditor::scroll_event (GdkEventScroll* ev) break; case MidiModel::NoteDiffCommand::Length: if (note->length().to_double() + fdelta >= - Evoral::MusicalTime::tick().to_double()) { + Temporal::Beats::tick().to_double()) { cmd->change (note, prop, note->length() + fdelta); } else { - cmd->change (note, prop, Evoral::MusicalTime::tick()); + cmd->change (note, prop, Temporal::Beats::tick()); } break; case MidiModel::NoteDiffCommand::Channel: @@ -320,7 +323,7 @@ MidiListEditor::scroll_event (GdkEventScroll* ev) } else { /* just this row */ - + TreeModel::iterator iter; iter = model->get_iter (path); @@ -328,13 +331,13 @@ MidiListEditor::scroll_event (GdkEventScroll* ev) if (iter) { boost::shared_ptr note = (*iter)[columns._note]; - + switch (prop) { case MidiModel::NoteDiffCommand::StartTime: if (note->time() + fdelta >= 0) { cmd->change (note, prop, note->time() + fdelta); } else { - cmd->change (note, prop, Evoral::MusicalTime()); + cmd->change (note, prop, Temporal::Beats()); } break; case MidiModel::NoteDiffCommand::Velocity: @@ -342,10 +345,10 @@ MidiListEditor::scroll_event (GdkEventScroll* ev) break; case MidiModel::NoteDiffCommand::Length: if (note->length() + fdelta >= - Evoral::MusicalTime::tick().to_double()) { + Temporal::Beats::tick().to_double()) { cmd->change (note, prop, note->length() + fdelta); } else { - cmd->change (note, prop, Evoral::MusicalTime::tick()); + cmd->change (note, prop, Temporal::Beats::tick()); } break; case MidiModel::NoteDiffCommand::Channel: @@ -363,7 +366,7 @@ MidiListEditor::scroll_event (GdkEventScroll* ev) m->apply_command (*_session, cmd); /* reset selection to be as it was before we rebuilt */ - + for (vector::iterator i = previous_selection.begin(); i != previous_selection.end(); ++i) { view.get_selection()->select (*i); } @@ -400,7 +403,7 @@ MidiListEditor::key_press (GdkEventKey* ev) ret = true; } break; - + case GDK_Up: case GDK_uparrow: if (edit_column > 0) { @@ -434,7 +437,7 @@ MidiListEditor::key_press (GdkEventKey* ev) case GDK_Escape: stop_editing (true); break; - + } return ret; @@ -485,7 +488,7 @@ MidiListEditor::key_release (GdkEventKey* ev) ret = true; } break; - + case GDK_r: if (_session && Gtkmm2ext::Keyboard::modifier_state_contains (ev->state, Gtkmm2ext::Keyboard::PrimaryModifier)) { _session->redo (1); @@ -611,6 +614,13 @@ MidiListEditor::edited (const std::string& path, const std::string& text) } 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()) { @@ -625,7 +635,7 @@ MidiListEditor::edited (const std::string& path, const std::string& text) if (sscanf (text.c_str(), "%lf", &fval) == 1) { /* numeric value entered */ - + if (text.find ('.') == string::npos && text.find (',') == string::npos) { /* integral => units are ticks */ fval = fval / BBT_Time::ticks_per_beat; @@ -648,13 +658,13 @@ MidiListEditor::edited (const std::string& path, const std::string& text) * displaying numeric value ... use new value * from note length map, and convert to beats. */ - + for (x = note_length_map.begin(); x != note_length_map.end(); ++x) { if (x->second == text) { break; } } - + if (x != note_length_map.end()) { fval = x->first / BBT_Time::ticks_per_beat; } @@ -664,7 +674,7 @@ MidiListEditor::edited (const std::string& path, const std::string& text) fval = -1.0; if (text != x->second) { - + /* get ticks for the newly selected * note length */ @@ -674,7 +684,7 @@ MidiListEditor::edited (const std::string& path, const std::string& text) break; } } - + if (x != note_length_map.end()) { /* convert to beats */ fval = (double) x->first / BBT_Time::ticks_per_beat; @@ -701,12 +711,12 @@ MidiListEditor::edited (const std::string& path, const std::string& text) MidiModel::NoteDiffCommand* cmd = m->new_note_diff_command (opname); TreeView::Selection::ListHandle_Path rows = view.get_selection()->get_selected_rows (); - + for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) { if ((iter = model->get_iter (*i))) { - note = (*iter)[columns._note]; - + note = (*iter)[columns._note]; + switch (prop) { case MidiModel::NoteDiffCommand::Velocity: cmd->change (note, prop, (uint8_t) (note->velocity() + idelta)); @@ -730,7 +740,7 @@ MidiListEditor::edited (const std::string& path, const std::string& text) /* model has been redisplayed by now */ /* keep selected row(s), move cursor there, don't continue editing */ - + TreeViewColumn* col = view.get_column (edit_column); view.set_cursor (edit_path, *col, 0); @@ -751,7 +761,7 @@ MidiListEditor::redisplay_model () if (_session) { - BeatsFramesConverter conv (_session->tempo_map(), region->position()); + BeatsSamplesConverter conv (_session->tempo_map(), region->position()); MidiModel::Notes notes = region->midi_source(0)->model()->notes(); TreeModel::Row row; stringstream ss; @@ -759,24 +769,22 @@ MidiListEditor::redisplay_model () for (MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) { row = *(model->append()); row[columns.channel] = (*i)->channel() + 1; - row[columns.note_name] = Evoral::midi_note_name ((*i)->note()); + row[columns.note_name] = ParameterDescriptor::midi_note_name ((*i)->note()); row[columns.note] = (*i)->note(); row[columns.velocity] = (*i)->velocity(); - Timecode::BBT_Time bbt; - - _session->tempo_map().bbt_time (conv.to ((*i)->time()), bbt); + Timecode::BBT_Time bbt (_session->tempo_map().bbt_at_sample (region->position() + conv.to ((*i)->time()))); ss.str (""); ss << bbt; row[columns.start] = ss.str(); bbt.bars = 0; - const Evoral::MusicalTime dur = (*i)->end_time() - (*i)->time(); + const Temporal::Beats dur = (*i)->end_time() - (*i)->time(); bbt.beats = dur.get_beats (); bbt.ticks = dur.get_ticks (); - - int len_ticks = (*i)->length().to_ticks(); + + uint64_t len_ticks = (*i)->length().to_ticks(); std::map::iterator x = note_length_map.find (len_ticks); if (x != note_length_map.end()) { @@ -797,7 +805,7 @@ MidiListEditor::redisplay_model () void MidiListEditor::selection_changed () { - if (!Config->get_sound_midi_notes()) { + if (!UIConfiguration::instance().get_sound_midi_notes()) { return; } @@ -810,7 +818,7 @@ MidiListEditor::selection_changed () for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) { if ((iter = model->get_iter (*i))) { - note = (*iter)[columns._note]; + note = (*iter)[columns._note]; player->add (note); } }