From 87f6aeaae3c55c145876ce1ceb5233ab9680b08e Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 1 Feb 2012 21:30:00 +0000 Subject: provide full scroll-based editing in MIDI list editor git-svn-id: svn://localhost/ardour2/branches/3.0@11419 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/midi_list_editor.cc | 216 ++++++++++++++++++++++++++++++++++++++-- gtk2_ardour/midi_list_editor.h | 3 +- gtk2_ardour/note_player.cc | 2 +- 3 files changed, 207 insertions(+), 14 deletions(-) diff --git a/gtk2_ardour/midi_list_editor.cc b/gtk2_ardour/midi_list_editor.cc index b18b57bab7..53af17488c 100644 --- a/gtk2_ardour/midi_list_editor.cc +++ b/gtk2_ardour/midi_list_editor.cc @@ -42,6 +42,7 @@ using namespace std; using namespace Gtk; +using namespace Gtkmm2ext; using namespace Glib; using namespace ARDOUR; using Timecode::BBT_Time; @@ -97,6 +98,7 @@ MidiListEditor::MidiListEditor (Session* s, boost::shared_ptr r, boo 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); view.append_column (_("Start"), columns.start); view.append_column (_("Channel"), columns.channel); @@ -119,15 +121,18 @@ MidiListEditor::MidiListEditor (Session* s, boost::shared_ptr r, boo comboCell->property_has_entry() = false; view.append_column (*lenCol); - view.append_column (_("End"), columns.end); + view.set_headers_visible (true); view.set_rules_hint (true); view.get_selection()->set_mode (SELECTION_MULTIPLE); view.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &MidiListEditor::selection_changed)); - for (int i = 0; i < 7; ++i) { + for (int i = 0; i < 6; ++i) { CellRendererText* renderer = dynamic_cast(view.get_column_cell_renderer (i)); + TreeViewColumn* col = view.get_column (i); + col->set_data (X_("colnum"), GUINT_TO_POINTER(i)); + renderer->property_editable() = true; renderer->signal_editing_started().connect (sigc::bind (sigc::mem_fun (*this, &MidiListEditor::editing_started), i)); @@ -168,6 +173,203 @@ MidiListEditor::~MidiListEditor () { } +bool +MidiListEditor::scroll_event (GdkEventScroll* ev) +{ + TreeModel::Path path; + TreeViewColumn* col; + int cellx; + int celly; + int idelta; + double fdelta; + MidiModel::NoteDiffCommand::Property prop (MidiModel::NoteDiffCommand::NoteNumber); + bool apply = false; + bool was_selected = false; + char* opname; + + 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)) { + was_selected = true; + } else { + was_selected = false; + } + + int colnum = GPOINTER_TO_UINT (col->get_data (X_("colnum"))); + + switch (colnum) { + case 0: + if (Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier)) { + fdelta = 1/64.0; + } else { + fdelta = 1/4.0; + } + if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) { + fdelta = -fdelta; + } + 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::SecondaryModifier)) { + fdelta = 1/64.0; + } else { + fdelta = 1/4.0; + } + if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) { + fdelta = -fdelta; + } + prop = MidiModel::NoteDiffCommand::Length; + opname = _("edit note length"); + apply = true; + break; + + default: + break; + } + + + if (apply) { + + boost::shared_ptr m (region->midi_source(0)->model()); + MidiModel::NoteDiffCommand* cmd = m->new_note_diff_command (opname); + vector previous_selection; + + 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]; + + switch (prop) { + case MidiModel::NoteDiffCommand::StartTime: + if (note->time() + fdelta >= 0) { + cmd->change (note, prop, note->time() + fdelta); + } else { + cmd->change (note, prop, 0.0); + } + break; + case MidiModel::NoteDiffCommand::Velocity: + cmd->change (note, prop, (uint8_t) (note->velocity() + idelta)); + break; + case MidiModel::NoteDiffCommand::Length: + if (note->length() + fdelta >= 1.0/BBT_Time::ticks_per_beat) { + cmd->change (note, prop, note->length() + fdelta); + } else { + cmd->change (note, prop, 1.0/BBT_Time::ticks_per_beat); + } + 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; + } + } + } + + } else { + + /* just this row */ + + TreeModel::iterator iter; + iter = model->get_iter (path); + + previous_selection.push_back (path); + + 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, 0.0); + } + break; + case MidiModel::NoteDiffCommand::Velocity: + cmd->change (note, prop, (uint8_t) (note->velocity() + idelta)); + break; + case MidiModel::NoteDiffCommand::Length: + if (note->length() + fdelta >= 1.0/BBT_Time::ticks_per_beat) { + cmd->change (note, prop, note->length() + fdelta); + } else { + cmd->change (note, prop, 1.0/BBT_Time::ticks_per_beat); + } + 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; + } + } + } + + 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); + } + } + + return true; +} + bool MidiListEditor::key_press (GdkEventKey* ev) { @@ -184,7 +386,7 @@ MidiListEditor::key_press (GdkEventKey* ev) if (editing_editable) { editing_editable->editing_done (); } - if (colnum >= 6) { + if (colnum >= 5) { /* wrap to next line */ colnum = 0; path.next(); @@ -488,8 +690,6 @@ MidiListEditor::edited (const std::string& path, const std::string& text) } break; - case 6: // end - break; default: break; } @@ -587,12 +787,6 @@ MidiListEditor::redisplay_model () row[columns.length] = ss.str(); } - _session->tempo_map().bbt_time (conv.to ((*i)->end_time()), bbt); - - ss.str (""); - ss << bbt; - row[columns.end] = ss.str(); - row[columns._note] = (*i); } } diff --git a/gtk2_ardour/midi_list_editor.h b/gtk2_ardour/midi_list_editor.h index 6061f54db6..f8d2ce9432 100644 --- a/gtk2_ardour/midi_list_editor.h +++ b/gtk2_ardour/midi_list_editor.h @@ -60,7 +60,6 @@ class MidiListEditor : public ArdourWindow add (velocity); add (start); add (length); - add (end); add (_note); }; Gtk::TreeModelColumn channel; @@ -69,7 +68,6 @@ class MidiListEditor : public ArdourWindow Gtk::TreeModelColumn velocity; Gtk::TreeModelColumn start; Gtk::TreeModelColumn length; - Gtk::TreeModelColumn end; Gtk::TreeModelColumn > _note; }; @@ -111,6 +109,7 @@ class MidiListEditor : public ArdourWindow bool key_press (GdkEventKey* ev); bool key_release (GdkEventKey* ev); + bool scroll_event (GdkEventScroll*); void delete_selected_note (); void selection_changed (); diff --git a/gtk2_ardour/note_player.cc b/gtk2_ardour/note_player.cc index 6355cc522b..c9c9f9de0e 100644 --- a/gtk2_ardour/note_player.cc +++ b/gtk2_ardour/note_player.cc @@ -55,7 +55,7 @@ NotePlayer::play () /* note: if there is more than 1 note, we will silence them all at the same time */ - const uint32_t note_length_ms = 350; + const uint32_t note_length_ms = 100; Glib::signal_timeout().connect (sigc::bind (sigc::ptr_fun (&NotePlayer::_off), this), note_length_ms, G_PRIORITY_DEFAULT); -- cgit v1.2.3