Remove internal edit mode and add "content" tool.
[ardour.git] / gtk2_ardour / midi_region_view.cc
index e072d7c7ceee884c0d8cd292e99eb94baf9f6524..8533cefdc07cbcdb24a34310672b79448703bbc9 100644 (file)
@@ -351,7 +351,6 @@ MidiRegionView::canvas_group_event(GdkEvent* ev)
                return RegionView::canvas_group_event (ev);
        }
 
-       const MouseMode m = trackview.editor().current_mouse_mode();
        bool r;
 
        switch (ev->type) {
@@ -369,15 +368,6 @@ MidiRegionView::canvas_group_event(GdkEvent* ev)
                // reset entered_regionview (among other things)
                return RegionView::canvas_group_event (ev);
 
-       case GDK_2BUTTON_PRESS:
-               // cannot use double-click to exit internal mode if single-click is being used
-               if ((m != MouseDraw) &&
-                   (m != MouseObject ||
-                    !Keyboard::modifier_state_contains (ev->button.state, Keyboard::insert_note_modifier()))) {
-                       return trackview.editor().toggle_internal_editing_from_double_click (ev);
-               }
-               break;
-
        case GDK_SCROLL:
                if (scroll (&ev->scroll)) {
                        return true;
@@ -484,7 +474,7 @@ MidiRegionView::button_press (GdkEventButton* ev)
        Editor* editor = dynamic_cast<Editor *> (&trackview.editor());
        MouseMode m = editor->current_mouse_mode();
 
-       if (m == MouseObject && Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier())) {
+       if (m == MouseContent && Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier())) {
                pre_press_cursor = editor->get_canvas_cursor ();
                editor->set_canvas_cursor (editor->cursors()->midi_pencil);
        }
@@ -533,7 +523,7 @@ MidiRegionView::button_release (GdkEventButton* ev)
                        clear_selection ();
                        break;
 
-               case MouseObject:
+               case MouseContent:
                case MouseTimeFX:
                        {
                                clear_selection();
@@ -598,18 +588,18 @@ MidiRegionView::motion (GdkEventMotion* ev)
 {
        PublicEditor& editor = trackview.editor ();
 
-       if (!_ghost_note && editor.current_mouse_mode() == MouseObject &&
+       if (!_ghost_note && editor.current_mouse_mode() == MouseContent &&
            Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier()) &&
            _mouse_state != AddDragging) {
 
                create_ghost_note (ev->x, ev->y);
 
-       } else if (_ghost_note && editor.current_mouse_mode() == MouseObject &&
+       } else if (_ghost_note && editor.current_mouse_mode() == MouseContent &&
                   Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier())) {
 
                update_ghost_note (ev->x, ev->y);
 
-       } else if (_ghost_note && editor.current_mouse_mode() == MouseObject) {
+       } else if (_ghost_note && editor.current_mouse_mode() == MouseContent) {
 
                remove_ghost_note ();
                editor.verbose_cursor()->hide ();
@@ -632,13 +622,13 @@ MidiRegionView::motion (GdkEventMotion* ev)
                        
                        MouseMode m = editor.current_mouse_mode();
                        
-                       if (m == MouseDraw || (m == MouseObject && Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier()))) {
+                       if (m == MouseDraw || (m == MouseContent && Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier()))) {
                                editor.drags()->set (new NoteCreateDrag (dynamic_cast<Editor *> (&editor), group, this), (GdkEvent *) ev);
                                _mouse_state = AddDragging;
                                remove_ghost_note ();
                                editor.verbose_cursor()->hide ();
                                return true;
-                       } else if (m == MouseObject) {
+                       } else if (m == MouseContent) {
                                editor.drags()->set (new MidiRubberbandSelectDrag (dynamic_cast<Editor *> (&editor), this), (GdkEvent *) ev);
                                if (!Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
                                        clear_selection ();
@@ -1559,7 +1549,8 @@ MidiRegionView::extend_active_notes()
 
        for (unsigned i=0; i < 128; ++i) {
                if (_active_notes[i]) {
-                       _active_notes[i]->set_x1 (trackview.editor().sample_to_pixel(_region->length()));
+                       _active_notes[i]->set_x1(
+                               trackview.editor().sample_to_pixel(_region->position() + _region->length()));
                }
        }
 }
@@ -1880,15 +1871,11 @@ MidiRegionView::get_patch_key_at (Evoral::MusicalTime time, uint8_t channel, MID
        }
 
        if (i != _model->patch_changes().end() && patch_applies(*i, time, channel)) {
-               key.bank_number    = (*i)->bank();
-               key.program_number = (*i)->program ();
+               key.set_bank((*i)->bank());
+               key.set_program((*i)->program ());
        } else {
-               key.bank_number = key.program_number = 0;
-       }
-
-       if (!key.is_sane()) {
-               error << string_compose(_("insane MIDI patch key %1:%2"),
-                                       key.bank_number, key.program_number) << endmsg;
+               key.set_bank(0);
+               key.set_program(0);
        }
 }
 
@@ -1897,11 +1884,11 @@ MidiRegionView::change_patch_change (PatchChange& pc, const MIDI::Name::PatchPri
 {
        MidiModel::PatchChangeDiffCommand* c = _model->new_patch_change_diff_command (_("alter patch change"));
 
-       if (pc.patch()->program() != new_patch.program_number) {
-               c->change_program (pc.patch (), new_patch.program_number);
+       if (pc.patch()->program() != new_patch.program()) {
+               c->change_program (pc.patch (), new_patch.program());
        }
 
-       int const new_bank = new_patch.bank_number;
+       int const new_bank = new_patch.bank();
        if (pc.patch()->bank() != new_bank) {
                c->change_bank (pc.patch (), new_bank);
        }
@@ -1987,47 +1974,15 @@ MidiRegionView::delete_patch_change (PatchChange* pc)
 }
 
 void
-MidiRegionView::previous_patch (PatchChange& patch)
-{
-       if (patch.patch()->program() < 127) {
-               MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch());
-               key.program_number++;
-               change_patch_change (patch, key);
-       }
-}
-
-void
-MidiRegionView::next_patch (PatchChange& patch)
-{
-       if (patch.patch()->program() > 0) {
-               MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch());
-               key.program_number--;
-               change_patch_change (patch, key);
-       }
-}
-
-void
-MidiRegionView::next_bank (PatchChange& patch)
+MidiRegionView::step_patch (PatchChange& patch, bool bank, int delta)
 {
-       if (patch.patch()->program() < 127) {
-               MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch());
-               if (key.bank_number > 0) {
-                       key.bank_number--;
-                       change_patch_change (patch, key);
-               }
-       }
-}
-
-void
-MidiRegionView::previous_bank (PatchChange& patch)
-{
-       if (patch.patch()->program() > 0) {
-               MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch());
-               if (key.bank_number < 127) {
-                       key.bank_number++;
-                       change_patch_change (patch, key);
-               }
+       MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key(patch.patch());
+       if (bank) {
+               key.set_bank(key.bank() + delta);
+       } else {
+               key.set_program(key.program() + delta);
        }
+       change_patch_change(patch, key);
 }
 
 void
@@ -3259,7 +3214,7 @@ MidiRegionView::note_mouse_position (float x_fraction, float /*y_fraction*/, boo
 {
        Editor* editor = dynamic_cast<Editor*>(&trackview.editor());
        Editing::MouseMode mm = editor->current_mouse_mode();
-       bool trimmable = (mm == MouseObject || mm == MouseTimeFX || mm == MouseDraw);
+       bool trimmable = (mm == MouseContent || mm == MouseTimeFX || mm == MouseDraw);
 
        if (can_set_cursor) {
                if (trimmable && x_fraction > 0.0 && x_fraction < 0.2) {
@@ -3385,7 +3340,7 @@ MidiRegionView::selection_as_cut_buffer () const
 bool
 MidiRegionView::paste (framepos_t pos, const ::Selection& selection, PasteContext& ctx)
 {
-       trackview.session()->begin_reversible_command (Operations::paste);
+       trackview.editor().begin_reversible_command (Operations::paste);
 
        // Paste notes, if available
        MidiNoteSelection::const_iterator m = selection.midi_notes.get_nth(ctx.counts.n_notes());
@@ -3401,7 +3356,7 @@ MidiRegionView::paste (framepos_t pos, const ::Selection& selection, PasteContex
                a->second->paste(pos, selection, ctx);
        }
 
-       trackview.session()->commit_reversible_command ();
+       trackview.editor().commit_reversible_command ();
 
        return true;
 }
@@ -3781,8 +3736,6 @@ MidiRegionView::data_recorded (boost::weak_ptr<MidiSource> w)
 
        boost::shared_ptr<MidiBuffer> buf = mtv->midi_track()->get_gui_feed_buffer ();
 
-       BeatsFramesConverter converter (trackview.session()->tempo_map(), mtv->midi_track()->get_capture_start_frame (0));
-
        framepos_t back = max_framepos;
 
        for (MidiBuffer::iterator i = buf->begin(); i != buf->end(); ++i) {
@@ -3796,12 +3749,8 @@ MidiRegionView::data_recorded (boost::weak_ptr<MidiSource> w)
                        }
                }
 
-               /* ev.time() is in session frames, so (ev.time() - converter.origin_b()) is
-                  frames from the start of the source, and so time_beats is in terms of the
-                  source.
-               */
-
-               Evoral::MusicalTime const time_beats = converter.from (ev.time () - converter.origin_b ());
+               /* convert from session frames to source beats */
+               Evoral::MusicalTime const time_beats = _source_relative_time_converter.from(ev.time());
 
                if (ev.type() == MIDI_CMD_NOTE_ON) {
                        boost::shared_ptr<NoteType> note (
@@ -3898,8 +3847,8 @@ MidiRegionView::show_verbose_cursor (boost::shared_ptr<NoteType> n) const
                        get_patch_key_at(n->time(), n->channel(), patch_key);
                        name = device_names->note_name(mtv->gui_property(X_("midnam-custom-device-mode")),
                                                       n->channel(),
-                                                      patch_key.bank_number,
-                                                      patch_key.program_number,
+                                                      patch_key.bank(),
+                                                      patch_key.program(),
                                                       n->note());
                }
        }