diff --git a/gtk2_ardour/cue_editor.h b/gtk2_ardour/cue_editor.h index 46706c57ab..6218786a88 100644 --- a/gtk2_ardour/cue_editor.h +++ b/gtk2_ardour/cue_editor.h @@ -92,8 +92,6 @@ class CueEditor : public EditingContext } VerboseCursor* verbose_cursor () const; - - void set_snapped_cursor_position (Temporal::timepos_t const & pos); std::vector filter_to_unique_midi_region_views (RegionSelection const & ms) const; diff --git a/gtk2_ardour/edit_note_dialog.cc b/gtk2_ardour/edit_note_dialog.cc index 80240bc220..117408a2b1 100644 --- a/gtk2_ardour/edit_note_dialog.cc +++ b/gtk2_ardour/edit_note_dialog.cc @@ -25,7 +25,7 @@ #include "gtkmm2ext/utils.h" #include "edit_note_dialog.h" -#include "midi_region_view.h" +#include "midi_view.h" #include "note_base.h" #include "pbd/i18n.h" @@ -41,7 +41,7 @@ using namespace Gtkmm2ext; * @param n Notes to edit. */ -EditNoteDialog::EditNoteDialog (MidiRegionView* rv, set n) +EditNoteDialog::EditNoteDialog (MidiView* rv, set n) : ArdourDialog (_("Note")) , _region_view (rv) , _events (n) @@ -94,12 +94,11 @@ EditNoteDialog::EditNoteDialog (MidiRegionView* rv, set n) table->attach (_time_all, 2, 3, r, r + 1); ++r; - _time_clock.set_session (_region_view->get_time_axis_view().session ()); + // XXXX _time_clock.set_session (_region_view->get_time_axis_view().session ()); _time_clock.set_mode (AudioClock::BBT); /* Calculate absolute position of the event on time timeline */ - std::shared_ptr region (_region_view->region ()); - timepos_t const pos = region->source_position() + timecnt_t ((*_events.begin())->note()->time ()); + timepos_t const pos = _region_view->current_slice().source_position() + timecnt_t ((*_events.begin())->note()->time ()); _time_clock.set (pos, true); @@ -109,7 +108,7 @@ EditNoteDialog::EditNoteDialog (MidiRegionView* rv, set n) table->attach (_length_all, 2, 3, r, r + 1); ++r; - _length_clock.set_session (_region_view->get_time_axis_view().session ()); + // XXXX _length_clock.set_session (_region_view->get_time_axis_view().session ()); _length_clock.set_mode (AudioClock::BBT); _length_clock.set_duration (timecnt_t ((*_events.begin())->note()->length()), true); @@ -201,10 +200,8 @@ EditNoteDialog::done (int r) } } - std::shared_ptr region (_region_view->region ()); - /* convert current clock time into an offset from the start of the source */ - timecnt_t const time_clock_source_relative = region->source_position ().distance (_time_clock.last_when ()); + timecnt_t const time_clock_source_relative = _region_view->current_slice().source_position ().distance (_time_clock.last_when ()); /* 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 (); diff --git a/gtk2_ardour/edit_note_dialog.h b/gtk2_ardour/edit_note_dialog.h index a98b0ba098..4c53798811 100644 --- a/gtk2_ardour/edit_note_dialog.h +++ b/gtk2_ardour/edit_note_dialog.h @@ -22,18 +22,18 @@ #include "ardour_dialog.h" #include "audio_clock.h" -class MidiRegionView; +class MidiView; class NoteBase; class EditNoteDialog : public ArdourDialog { public: - EditNoteDialog (MidiRegionView* rv, std::set n); + EditNoteDialog (MidiView* rv, std::set n); void done (int); private: - MidiRegionView* _region_view; + MidiView* _region_view; std::set _events; Gtk::SpinButton _channel; Gtk::CheckButton _channel_all; diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 1682d96767..2ce6731eb6 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -137,6 +137,7 @@ #include "marker.h" #include "midi_region_view.h" #include "midi_time_axis.h" +#include "midi_view.h" #include "mixer_strip.h" #include "mixer_ui.h" #include "mouse_cursors.h" @@ -6281,7 +6282,7 @@ Editor::popup_note_context_menu (ArdourCanvas::Item* item, GdkEvent* event) popping up the menu will cause a region leave event which clears entered_regionview. */ - MidiRegionView& mrv = note->region_view(); + MidiView& mrv = note->region_view(); const RegionSelection rs = get_regions_from_selection_and_entered (); const uint32_t sel_size = mrv.selection_size (); @@ -6290,7 +6291,7 @@ Editor::popup_note_context_menu (ArdourCanvas::Item* item, GdkEvent* event) if (sel_size > 0) { items.push_back(MenuElem(_("Delete"), - sigc::mem_fun(mrv, &MidiRegionView::delete_selection))); + sigc::mem_fun(mrv, &MidiView::delete_selection))); } items.push_back(MenuElem(_("Edit..."), @@ -6508,7 +6509,7 @@ Editor::track_dragging() const } void -Editor::snap_to_internal (timepos_t& start, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap) +Editor::snap_to_internal (timepos_t& start, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap) const { UIConfiguration const& uic (UIConfiguration::instance ()); const timepos_t presnap = start; @@ -6545,8 +6546,8 @@ Editor::snap_to_internal (timepos_t& start, Temporal::RoundMode direction, SnapP if (!region_boundary_cache.empty ()) { - vector::iterator prev = region_boundary_cache.begin (); - vector::iterator next = std::upper_bound (region_boundary_cache.begin (), region_boundary_cache.end (), presnap); + auto prev = region_boundary_cache.begin (); + auto next = std::upper_bound (region_boundary_cache.begin (), region_boundary_cache.end (), presnap); if (next != region_boundary_cache.begin ()) { prev = next; prev--; diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 59dbf39e04..578f93efb2 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -130,6 +130,7 @@ class EditorSummary; class GUIObjectState; class ArdourMarker; class MidiRegionView; +class MidiView; class MidiExportDialog; class MixerStrip; class MouseCursors; @@ -1726,7 +1727,7 @@ private: void edit_meter_marker (MeterMarker&); void edit_bbt_marker (BBTMarker&); void edit_control_point (ArdourCanvas::Item*); - void edit_notes (MidiRegionView*); + void edit_notes (MidiView*); void edit_region (RegionView*); void edit_current_meter (); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index fa30a0c9f6..8a494fdf4d 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -72,6 +72,7 @@ #include "midi_region_view.h" #include "midi_selection.h" #include "midi_time_axis.h" +#include "midi_view.h" #include "mouse_cursors.h" #include "note_base.h" #include "patch_change.h" @@ -2384,12 +2385,14 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/) Drag::start_grab (event, cursor); +#warning paul fix me MRV/MV +#if 0 region = &cnote->region_view (); double temp; temp = region->snap_to_pixel (cnote->x0 (), true); _snap_delta = temp - cnote->x0 (); - +#endif _item->grab (); if (event->motion.state & ArdourKeyboard::note_size_relative_modifier ()) { @@ -6157,13 +6160,13 @@ NoteDrag::NoteDrag (EditingContext& ec, ArdourCanvas::Item* i) _primary = reinterpret_cast (_item->get_data ("notebase")); assert (_primary); _region = &_primary->region_view (); - _note_height = _region->midi_stream_view ()->note_height (); + _note_height = _region->midi_context().note_height (); } void NoteDrag::setup_pointer_offset () { - _pointer_offset = _region->region ()->source_beats_to_absolute_time (_primary->note ()->time ()).distance (raw_grab_time ()); + _pointer_offset = _region->current_slice().source_beats_to_absolute_time (_primary->note ()->time ()).distance (raw_grab_time ()); } void @@ -6177,7 +6180,7 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor*) _copy = false; } - setup_snap_delta (_region->region ()->source_beats_to_absolute_time (_primary->note ()->time ())); + setup_snap_delta (_region->current_slice().source_beats_to_absolute_time (_primary->note ()->time ())); if (!(_was_selected = _primary->selected ())) { /* tertiary-click means extend selection - we'll do that on button release, @@ -6216,7 +6219,7 @@ NoteDrag::total_dx (GdkEvent* event) const timecnt_t dx = t2.distance (t1); /* primary note time in quarter notes */ - timepos_t const n_qn = _region->region ()->source_beats_to_absolute_time (_primary->note ()->time ()); + timepos_t const n_qn = _region->current_slice().source_beats_to_absolute_time (_primary->note ()->time ()); /* prevent (n_qn + dx) from becoming negative */ if (-dx.distance() > timecnt_t(n_qn).distance ()) { @@ -6241,8 +6244,8 @@ NoteDrag::total_dx (GdkEvent* event) const timecnt_t ret (snap.earlier (n_qn).earlier (snap_delta (event->button.state)), n_qn); /* prevent the earliest note being dragged earlier than the region's start position */ - if (_earliest + ret < _region->region ()->start ()) { - ret -= (ret + _earliest) - _region->region ()->start (); + if (_earliest + ret < _region->current_slice().start ()) { + ret -= (ret + _earliest) - _region->current_slice().start (); } return ret; @@ -6256,13 +6259,13 @@ NoteDrag::total_dy () const return 0; } - double const y = _region->midi_view ()->y_position (); + double const y = _region->midi_context().y_position (); /* new current note */ uint8_t n = _region->y_to_note (current_pointer_y () - y); /* clamp */ - MidiStreamView* msv = _region->midi_stream_view (); - n = max (msv->lowest_note (), n); - n = min (msv->highest_note (), n); + MidiViewBackground& mvb = _region->midi_context (); + n = max (mvb.lowest_note (), n); + n = min (mvb.highest_note (), n); /* and work out delta */ return n - _region->y_to_note (grab_y () - y); } @@ -6308,7 +6311,7 @@ NoteDrag::motion (GdkEvent* event, bool first_move) _region->show_verbose_cursor_for_new_note_value (_primary->note (), new_note); - editing_context.set_snapped_cursor_position (_region->region ()->region_beats_to_absolute_time (_primary->note ()->time ()) + dx_qn); + editing_context.set_snapped_cursor_position (_region->current_slice().region_beats_to_absolute_time (_primary->note ()->time ()) + dx_qn); } } @@ -6675,21 +6678,21 @@ DraggingView::DraggingView (RegionView* v, RegionDrag* parent, TimeAxisView* ita initial_end = v->region ()->position () + v->region ()->length (); } -PatchChangeDrag::PatchChangeDrag (EditingContext& ec, PatchChange* i, MidiRegionView* r) +PatchChangeDrag::PatchChangeDrag (EditingContext& ec, PatchChange* i, MidiView* r) : Drag (ec, i->canvas_item (), Temporal::BeatTime, true, false) , _region_view (r) , _patch_change (i) , _cumulative_dx (0) { DEBUG_TRACE (DEBUG::Drags, string_compose ("New PatchChangeDrag, patch @ %1, grab @ %2\n", - _region_view->region ()->source_beats_to_absolute_time (_patch_change->patch ()->time ()), + _region_view->current_slice().source_beats_to_absolute_time (_patch_change->patch ()->time ()), grab_time ())); } void PatchChangeDrag::motion (GdkEvent* ev, bool) { - std::shared_ptr r = _region_view->region (); + std::shared_ptr r = _region_view->midi_region (); timepos_t f = adjusted_current_time (ev); f = max (f, r->position ()); @@ -6713,13 +6716,13 @@ PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred) return; } - std::shared_ptr r (_region_view->region ()); + std::shared_ptr r (_region_view->midi_region ()); timepos_t f = adjusted_current_time (ev); f = max (f, r->position ()); f = min (f, r->nt_last ()); - _region_view->move_patch_change (*_patch_change, _region_view->region ()->absolute_time_to_source_beats (f)); + _region_view->move_patch_change (*_patch_change, r->absolute_time_to_source_beats (f)); } void @@ -6731,8 +6734,7 @@ PatchChangeDrag::aborted (bool) void PatchChangeDrag::setup_pointer_offset () { - std::shared_ptr region = _region_view->region (); - _pointer_offset = region->source_beats_to_absolute_time (_patch_change->patch ()->time ()).distance (raw_grab_time ()); + _pointer_offset = _region_view->current_slice().source_beats_to_absolute_time (_patch_change->patch ()->time ()).distance (raw_grab_time ()); } MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (EditingContext& ec, MidiRegionView* rv) diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index 642f485a71..dd2577f006 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -77,6 +77,7 @@ class TimeAxisView; class RouteTimeAxisView; class RegionSelection; class MidiRegionView; +class MidiView; class MeterMarker; class ArdourMarker; class TempoMarker; @@ -643,7 +644,7 @@ private: Temporal::timecnt_t total_dx (GdkEvent * event) const; // total movement in quarter notes int8_t total_dy () const; - MidiRegionView* _region; + MidiView* _region; NoteBase* _primary; Temporal::timecnt_t _cumulative_dx; double _cumulative_dy; @@ -727,7 +728,7 @@ private: class PatchChangeDrag : public Drag { public: - PatchChangeDrag (EditingContext&, PatchChange *, MidiRegionView *); + PatchChangeDrag (EditingContext&, PatchChange *, MidiView *); void motion (GdkEvent *, bool); void finished (GdkEvent *, bool); @@ -744,7 +745,7 @@ public: void setup_pointer_offset (); private: - MidiRegionView* _region_view; + MidiView* _region_view; PatchChange* _patch_change; double _cumulative_dx; }; diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 1101457c59..730c7333c4 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -65,6 +65,7 @@ #include "audio_time_axis.h" #include "audio_region_view.h" #include "midi_region_view.h" +#include "midi_view.h" #include "marker.h" #include "streamview.h" #include "region_gain_line.h" @@ -2323,9 +2324,9 @@ Editor::edit_control_point (ArdourCanvas::Item* item) } void -Editor::edit_notes (MidiRegionView* mrv) +Editor::edit_notes (MidiView* mrv) { - MidiRegionView::Selection const & s = mrv->selection(); + MidiView::Selection const & s = mrv->selection(); if (s.empty ()) { return; diff --git a/gtk2_ardour/hit.cc b/gtk2_ardour/hit.cc index 32a027f89d..da6fcece21 100644 --- a/gtk2_ardour/hit.cc +++ b/gtk2_ardour/hit.cc @@ -29,7 +29,7 @@ using namespace ARDOUR; using namespace ArdourCanvas; -Hit::Hit (MidiRegionView& region, Item* parent, double size, const std::shared_ptr note, bool with_events) +Hit::Hit (MidiView& region, Item* parent, double size, const std::shared_ptr note, bool with_events) : NoteBase (region, with_events, note) { _polygon = new ArdourCanvas::Polygon (parent); diff --git a/gtk2_ardour/hit.h b/gtk2_ardour/hit.h index ec24794a06..c9f83e9d87 100644 --- a/gtk2_ardour/hit.h +++ b/gtk2_ardour/hit.h @@ -32,7 +32,7 @@ class Hit : public NoteBase public: typedef Evoral::Note NoteType; - Hit (MidiRegionView& region, + Hit (MidiView& region, ArdourCanvas::Item* parent, double size, const std::shared_ptr note = std::shared_ptr(), diff --git a/gtk2_ardour/midi_cue_editor.cc b/gtk2_ardour/midi_cue_editor.cc index c643fcef9a..7ce1e81591 100644 --- a/gtk2_ardour/midi_cue_editor.cc +++ b/gtk2_ardour/midi_cue_editor.cc @@ -168,3 +168,9 @@ MidiCueEditor::apply_midi_note_edit_op_to_region (ARDOUR::MidiOperator& op, Midi return nullptr; } + +bool +MidiCueEditor::canvas_note_event (GdkEvent* event, ArdourCanvas::Item*) +{ + return false; +} diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index 6edc545d18..3c2249a66c 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -110,11 +110,11 @@ MidiStreamView::create_region_view (std::shared_ptr r, bool /*wfd*/, boo if (recording) { region_view = new MidiRegionView ( _region_group, _trackview.editor(), _trackview, region, - _samples_per_pixel, region_color, recording, + _samples_per_pixel, MidiViewBackground::region_color(), recording, TimeAxisViewItem::Visibility(TimeAxisViewItem::ShowFrame)); } else { region_view = new MidiRegionView (_region_group, _trackview.editor(), _trackview, region, - _samples_per_pixel, region_color); + _samples_per_pixel, MidiViewBackground::region_color()); } region_view->init (false); @@ -494,3 +494,20 @@ MidiStreamView::get_regions_with_selected_data (RegionSelection& rs) } } +void +MidiStreamView::set_note_highlight (bool yn) +{ + dynamic_cast (&_trackview)->set_note_highlight (yn); +} + +uint8_t +MidiStreamView::get_preferred_midi_channel () const +{ + return dynamic_cast (&_trackview)->get_preferred_midi_channel(); +} + +void +MidiStreamView::record_layer_check (std::shared_ptr r, samplepos_t t) +{ + check_record_layers (r, t); +} diff --git a/gtk2_ardour/midi_streamview.h b/gtk2_ardour/midi_streamview.h index 87b62ef5f6..32fc47b1cd 100644 --- a/gtk2_ardour/midi_streamview.h +++ b/gtk2_ardour/midi_streamview.h @@ -85,6 +85,9 @@ public: ArdourCanvas::Container* region_canvas () const { return _region_group; } void parameter_changed (std::string const &); + uint8_t get_preferred_midi_channel () const; + void record_layer_check (std::shared_ptr, samplepos_t); + void set_note_highlight (bool); protected: void setup_rec_box (); diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 6c324b5c7a..2413fa931b 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -106,22 +106,23 @@ using Gtkmm2ext::Keyboard; #define MIDI_BP_ZERO ((Config->get_first_midi_bank_is_zero())?0:1) MidiView::MidiView (std::shared_ptr mt, - ArdourCanvas::Container* p, + ArdourCanvas::Container& parent, EditingContext& ec, MidiViewBackground& bg, uint32_t basic_color) : _midi_track (mt) - , editing_context (ec) - , _background (bg) - , _current_range_min(0) - , _current_range_max(0) + , _editing_context (ec) + , _midi_context (bg) + , _current_slice (timepos_t (Temporal::BeatTime), timecnt_t (Temporal::BeatTime)) , _active_notes(0) - , _note_group (new ArdourCanvas::Container (group)) + , _note_group (new ArdourCanvas::Container (&parent)) , _note_diff_command (0) , _ghost_note(0) , _step_edit_cursor (0) , _step_edit_cursor_width (1, 0) , _channel_selection_scoped_note (0) + , _current_range_min(0) + , _current_range_max(0) , _mouse_state(None) , _pressed_button(0) , _optimization_iterator (_events.end()) @@ -143,7 +144,7 @@ MidiView::MidiView (std::shared_ptr mt, void MidiView::init () { - CANVAS_DEBUG_NAME (_note_group, string_compose ("note group for %1", get_item_name())); + // CANVAS_DEBUG_NAME (_note_group, string_compose ("note group for %1", get_item_name())); _patch_change_outline = UIConfiguration::instance().color ("midi patch change outline"); _patch_change_fill = UIConfiguration::instance().color_mod ("midi patch change fill", "midi patch change fill"); @@ -151,18 +152,19 @@ MidiView::init () _note_group->raise_to_top(); EditingContext::DropDownKeys.connect (sigc::mem_fun (*this, &MidiView::drop_down_keys)); - Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&MidiView::parameter_changed, this, _1), gui_context()); + // XXXX Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&MidiView::parameter_changed, this, _1), gui_context()); EditingContext::DropDownKeys.connect (sigc::mem_fun (*this, &MidiView::drop_down_keys)); } void -MidiView::set_model () +MidiView::set_model (std::shared_ptr m) { - _model = midi_region()->midi_source(0)->model(); + _model = m; assert (_model); //set_height (trackview.current_height()); +/* XXXX region_muted (); region_sync_changed (); region_resized (ARDOUR::bounds_change); @@ -170,60 +172,30 @@ MidiView::set_model () set_colors (); reset_width_dependent_items (_pixel_width); - - group->raise_to_top(); +*/ + // XXX group->raise_to_top(); _midi_track->playback_filter().ChannelModeChanged.connect (_channel_mode_changed_connection, invalidator (*this), boost::bind (&MidiView::midi_channel_mode_changed, this), gui_context ()); - instrument_info().Changed.connect (_instrument_changed_connection, invalidator (*this), + _midi_track->instrument_info().Changed.connect (_instrument_changed_connection, invalidator (*this), boost::bind (&MidiView::instrument_settings_changed, this), gui_context()); - editing_context.SnapChanged.connect(snap_changed_connection, invalidator(*this), + _editing_context.SnapChanged.connect(snap_changed_connection, invalidator(*this), boost::bind (&MidiView::snap_changed, this), gui_context()); - editing_context.MouseModeChanged.connect(_mouse_mode_connection, invalidator (*this), + _editing_context.MouseModeChanged.connect(_mouse_mode_connection, invalidator (*this), boost::bind (&MidiView::mouse_mode_changed, this), gui_context ()); - - Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&MidiView::parameter_changed, this, _1), gui_context()); -} - -InstrumentInfo& -MidiView::instrument_info () const -{ - return _midi_track->instrument_info(); -} - -void -MidiView::parameter_changed (std::string const & p) -{ - RegionView::parameter_changed (p); - if (p == "display-first-midi-bank-as-zero") { - if (display_enabled()) { - view_changed (); - } - } else if (p == "use-note-color-for-velocity") { - color_handler (); - } } bool MidiView::canvas_group_event(GdkEvent* ev) { - if (in_destructor || _recregion) { - return false; - } - - if (!editing_context.internal_editing()) { - // not in internal edit mode, so just act like a normal region - return RegionView::canvas_group_event (ev); - } - //For now, move the snapped cursor aside so it doesn't bother you during internal editing - //editing_context.set_snapped_cursor_position(_region->position()); + //_editing_context.set_snapped_cursor_position(_region->position()); bool r; @@ -233,14 +205,14 @@ MidiView::canvas_group_event(GdkEvent* ev) _last_event_y = ev->crossing.y; enter_notify(&ev->crossing); // set entered_regionview (among other things) - return RegionView::canvas_group_event (ev); + return true; case GDK_LEAVE_NOTIFY: _last_event_x = ev->crossing.x; _last_event_y = ev->crossing.y; leave_notify(&ev->crossing); // reset entered_regionview (among other things) - return RegionView::canvas_group_event (ev); + return true; case GDK_SCROLL: if (scroll (&ev->scroll)) { @@ -270,7 +242,7 @@ MidiView::canvas_group_event(GdkEvent* ev) break; } - return RegionView::canvas_group_event (ev); + return false; } bool @@ -295,9 +267,9 @@ void MidiView::mouse_mode_changed () { // Adjust frame colour (become more transparent for internal tools) - set_frame_color(); + // XXX set_frame_color(); - if (!editing_context.internal_editing()) { + if (!_editing_context.internal_editing()) { /* Switched out of internal editing mode while entered. Only necessary for leave as a mouse_mode_change over a region @@ -310,7 +282,7 @@ MidiView::mouse_mode_changed () it->second->set_hide_selection (true); } - } else if (editing_context.current_mouse_mode() == MouseContent) { + } else if (_editing_context.current_mouse_mode() == MouseContent) { // hide cursor and ghost note after changing to internal edit mode @@ -337,19 +309,10 @@ MidiView::mouse_mode_changed () void MidiView::enter_internal (uint32_t state) { - if (editing_context.current_mouse_mode() == MouseDraw && _mouse_state != AddDragging) { + if (_editing_context.current_mouse_mode() == MouseDraw && _mouse_state != AddDragging) { // Show ghost note under pencil create_ghost_note(_last_event_x, _last_event_y, state); } - - // Lower frame handles below notes so they don't steal events - - if (frame_handle_start) { - frame_handle_start->lower_to_bottom(); - } - if (frame_handle_end) { - frame_handle_end->lower_to_bottom(); - } } void @@ -358,15 +321,6 @@ MidiView::leave_internal() hide_verbose_cursor (); remove_ghost_note (); _entered_note = 0; - - // Raise frame handles above notes so they catch events - if (frame_handle_start) { - frame_handle_start->raise_to_top(); - } - - if (frame_handle_end) { - frame_handle_end->raise_to_top(); - } } bool @@ -376,10 +330,10 @@ MidiView::button_press (GdkEventButton* ev) return false; } - MouseMode m = editing_context.current_mouse_mode(); + MouseMode m = _editing_context.current_mouse_mode(); if (m == MouseContent && Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier())) { - _press_cursor_ctx = CursorContext::create(editing_context, editing_context.cursors()->midi_pencil); + _press_cursor_ctx = CursorContext::create(_editing_context, _editing_context.cursors()->midi_pencil); } if (_mouse_state != SelectTouchDragging) { @@ -388,10 +342,10 @@ MidiView::button_press (GdkEventButton* ev) if (m == MouseDraw || (m == MouseContent && Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier()))) { - if (midi_view()->note_mode() == Percussive) { - editing_context.drags()->set (new HitCreateDrag (editing_context, group, this), (GdkEvent *) ev); + if (_midi_context.note_mode() == Percussive) { + // XXX _editing_context.drags()->set (new HitCreateDrag (_editing_context, _note_group->parent(), this), (GdkEvent *) ev); } else { - editing_context.drags()->set (new NoteCreateDrag (editing_context, group, this), (GdkEvent *) ev); + // XXX _editing_context.drags()->set (new NoteCreateDrag (_editing_context, _note_group->parent(), this), (GdkEvent *) ev); } _mouse_state = AddDragging; @@ -422,15 +376,15 @@ MidiView::button_release (GdkEventButton* ev) event_x = ev->x; event_y = ev->y; - group->canvas_to_item (event_x, event_y); - group->ungrab (); + _note_group->parent()->canvas_to_item (event_x, event_y); + _note_group->parent()->ungrab (); _press_cursor_ctx.reset(); switch (_mouse_state) { case Pressed: // Clicked - switch (editing_context.current_mouse_mode()) { + switch (_editing_context.current_mouse_mode()) { case MouseRange: /* no motion occurred - simple click */ clear_selection_internal (); @@ -438,14 +392,11 @@ MidiView::button_release (GdkEventButton* ev) break; case MouseContent: - editing_context.get_selection().set (this); - /* fallthru */ case MouseTimeFX: _mouse_changed_selection = true; clear_selection_internal (); break; case MouseDraw: - editing_context.get_selection().set (this); break; default: @@ -459,7 +410,7 @@ MidiView::button_release (GdkEventButton* ev) /* Don't a ghost note when we added a note - wait until motion to avoid visual confusion. we don't want one when we were drag-selecting either. */ case SelectRectDragging: - editing_context.drags()->end_grab ((GdkEvent *) ev); + _editing_context.drags()->end_grab ((GdkEvent *) ev); _mouse_state = None; break; @@ -469,13 +420,13 @@ MidiView::button_release (GdkEventButton* ev) } if (_mouse_changed_selection) { - editing_context.begin_reversible_selection_op (X_("Mouse Selection Change")); - editing_context.commit_reversible_selection_op (); + _editing_context.begin_reversible_selection_op (X_("Mouse Selection Change")); + _editing_context.commit_reversible_selection_op (); } return false; } - + bool MidiView::motion (GdkEventMotion* ev) { @@ -486,23 +437,23 @@ MidiView::motion (GdkEventMotion* ev) remove_ghost_note (); } - } else if (!_ghost_note && editing_context.current_mouse_mode() == MouseContent && + } else if (!_ghost_note && _editing_context.current_mouse_mode() == MouseContent && Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier()) && _mouse_state != AddDragging) { create_ghost_note (ev->x, ev->y, ev->state); - } else if (_ghost_note && editing_context.current_mouse_mode() == MouseContent && + } else if (_ghost_note && _editing_context.current_mouse_mode() == MouseContent && Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier())) { update_ghost_note (ev->x, ev->y, ev->state); - } else if (_ghost_note && editing_context.current_mouse_mode() == MouseContent) { + } else if (_ghost_note && _editing_context.current_mouse_mode() == MouseContent) { remove_ghost_note (); hide_verbose_cursor (); - } else if (editing_context.current_mouse_mode() == MouseDraw) { + } else if (_editing_context.current_mouse_mode() == MouseDraw) { if (_ghost_note) { update_ghost_note (ev->x, ev->y, ev->state); @@ -523,10 +474,10 @@ MidiView::motion (GdkEventMotion* ev) if (_pressed_button == 1) { - MouseMode m = editing_context.current_mouse_mode(); + MouseMode m = _editing_context.current_mouse_mode(); if (m == MouseContent && !Keyboard::modifier_state_contains (ev->state, Keyboard::insert_note_modifier())) { - editing_context.drags()->set (new MidiRubberbandSelectDrag (editing_context, this), (GdkEvent *) ev); + // XXX _editing_context.drags()->set (new MidiRubberbandSelectDrag (_editing_context, this), (GdkEvent *) ev); if (!Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) { clear_selection_internal (); _mouse_changed_selection = true; @@ -534,7 +485,7 @@ MidiView::motion (GdkEventMotion* ev) _mouse_state = SelectRectDragging; return true; } else if (m == MouseRange) { - editing_context.drags()->set (new MidiVerticalSelectDrag (editing_context, this), (GdkEvent *) ev); + // XXX _editing_context.drags()->set (new MidiVerticalSelectDrag (_editing_context, this), (GdkEvent *) ev); _mouse_state = SelectVerticalDragging; return true; } @@ -545,7 +496,7 @@ MidiView::motion (GdkEventMotion* ev) case SelectRectDragging: case SelectVerticalDragging: case AddDragging: - editing_context.drags()->motion_handler ((GdkEvent *) ev, false); + _editing_context.drags()->motion_handler ((GdkEvent *) ev, false); break; case SelectTouchDragging: @@ -556,19 +507,14 @@ MidiView::motion (GdkEventMotion* ev) } - //let RegionView do it's thing. drags are handled in here - return RegionView::canvas_group_event ((GdkEvent *) ev); + return false; } bool MidiView::scroll (GdkEventScroll* ev) { - if (editing_context.drags()->active()) { - return false; - } - - if (!editing_context.get_selection().selected (this)) { + if (_editing_context.drags()->active()) { return false; } @@ -589,26 +535,26 @@ MidiView::scroll (GdkEventScroll* ev) case GDK_SCROLL_UP: if (just_one_edge) { /* make higher notes visible aka expand higher pitch range */ - apply_note_range (midi_stream_view()->lowest_note(), min (127, midi_stream_view()->highest_note() + step), true); + apply_note_range (_midi_context.lowest_note(), min (127, _midi_context.highest_note() + step), true); } else if (zoom) { /* zoom out to show more higher and lower pitches */ - apply_note_range (max (0, midi_stream_view()->lowest_note() - step), min (127, midi_stream_view()->highest_note() + step), true); + apply_note_range (max (0, _midi_context.lowest_note() - step), min (127, _midi_context.highest_note() + step), true); } else { /* scroll towards higher pitches */ - apply_note_range (max (0, midi_stream_view()->lowest_note() + step), min (127, midi_stream_view()->highest_note() + step), true); + apply_note_range (max (0, _midi_context.lowest_note() + step), min (127, _midi_context.highest_note() + step), true); } return true; case GDK_SCROLL_DOWN: if (just_one_edge) { /* make lower notes visible aka expand lower pitch range */ - apply_note_range (max (0, midi_stream_view()->lowest_note() - step), midi_stream_view()->highest_note(), true); + apply_note_range (max (0, _midi_context.lowest_note() - step), _midi_context.highest_note(), true); } else if (zoom) { /* zoom in to show less higher and lower pitches */ - apply_note_range (min (127, midi_stream_view()->lowest_note() + step), max (0, midi_stream_view()->highest_note() - step), true); + apply_note_range (min (127, _midi_context.lowest_note() + step), max (0, _midi_context.highest_note() - step), true); } else { /* scroll towards lower pitches */ - apply_note_range (min (127, midi_stream_view()->lowest_note() - step), max (0, midi_stream_view()->highest_note() - step), true); + apply_note_range (min (127, _midi_context.lowest_note() - step), max (0, _midi_context.highest_note() - step), true); } return true; @@ -747,7 +693,7 @@ void MidiView::show_list_editor () { if (!_list_editor) { - _list_editor = new MidiListEditor (editing_context.session(), midi_region(), _midi_track); + _list_editor = new MidiListEditor (_editing_context.session(), midi_region(), _midi_track); } _list_editor->present (); } @@ -766,14 +712,6 @@ MidiView::create_note_at (timepos_t const & t, double y, Temporal::Beats length, return; } - MidiTimeAxisView* const mtv = dynamic_cast(&trackview); - MidiStreamView* const view = mtv->midi_view(); - std::shared_ptr mr = std::dynamic_pointer_cast (_region); - - if (!mr) { - return; - } - /* assume time is already region-relative and snapped */ Temporal::Beats region_start = t.beats(); @@ -788,13 +726,13 @@ MidiView::create_note_at (timepos_t const & t, double y, Temporal::Beats length, return; } - view->update_note_range(new_note->note()); + _midi_context.update_note_range(new_note->note()); start_note_diff_command(_("add note")); note_diff_add_note (new_note, true, false); apply_note_diff(); - editing_context.set_selected_midi_region_view (*this); + // XXX _editing_context.set_selected_midi_region_view (*this); list to_be_selected; to_be_selected.push_back (new_note->id()); select_notes (to_be_selected, true); @@ -808,12 +746,7 @@ MidiView::clear_events () // clear selection without signaling or trying to change state of event objects _selection.clear (); - MidiGhostRegion* gr; - for (std::vector::iterator g = ghosts.begin(); g != ghosts.end(); ++g) { - if ((gr = dynamic_cast(*g)) != 0) { - gr->clear_events(); - } - } + clear_ghost_events (); _note_group->clear (true); @@ -839,7 +772,7 @@ void MidiView::start_note_diff_command (string name) { if (!_note_diff_command) { - editing_context.begin_reversible_command (name); + _editing_context.begin_reversible_command (name); _note_diff_command = _model->new_note_diff_command (name); } else { std::cerr << "ERROR: start_note_diff_command command called, but a note_diff_command was already underway" << std::endl; @@ -907,11 +840,11 @@ MidiView::apply_note_diff (bool as_subcommand, bool was_copy) { PBD::Unwinder puw (_select_all_notes_after_add, true); /*note that we don't use as_commit here, because that would BEGIN a new undo record; we already have one underway*/ - _model->apply_diff_command_as_subcommand (*editing_context.session(), _note_diff_command); + _model->apply_diff_command_as_subcommand (*_editing_context.session(), _note_diff_command); } if (!as_subcommand) { - editing_context.commit_reversible_command (); /*instead, we can explicitly commit the command in progress */ + _editing_context.commit_reversible_command (); /*instead, we can explicitly commit the command in progress */ } _note_diff_command = nullptr; @@ -928,7 +861,7 @@ MidiView::abort_note_diff() { delete _note_diff_command; _note_diff_command = 0; - editing_context.abort_reversible_command(); + _editing_context.abort_reversible_command(); clear_selection_internal (); } @@ -1037,7 +970,7 @@ MidiView::model_changed() if (_active_notes) { // Currently recording - const samplecnt_t zoom = editing_context.get_current_zoom(); + const samplecnt_t zoom = _editing_context.get_current_zoom(); if (zoom != _last_display_zoom) { /* Update resolved canvas notes to reflect changes in zoom without touching model. Leave active notes (with length max) alone since @@ -1099,12 +1032,7 @@ MidiView::model_changed() /* remove note items that are no longer valid */ if (!cne->valid()) { - for (vector::iterator j = ghosts.begin(); j != ghosts.end(); ++j) { - MidiGhostRegion* gr = dynamic_cast (*j); - if (gr) { - gr->remove_note (cne); - } - } + ghost_remove_note (cne); delete cne; i = _events.erase (i); @@ -1156,12 +1084,7 @@ MidiView::model_changed() } } - for (vector::iterator j = ghosts.begin(); j != ghosts.end(); ++j) { - MidiGhostRegion* gr = dynamic_cast (*j); - if (gr && !gr->trackview.hidden()) { - gr->model_changed (); - } - } + ghosts_model_changed (); display_sysexes(); display_patch_changes (); @@ -1180,7 +1103,7 @@ MidiView::view_changed() if (_active_notes) { // Currently recording - const samplecnt_t zoom = editing_context.get_current_zoom(); + const samplecnt_t zoom = _editing_context.get_current_zoom(); if (zoom != _last_display_zoom) { /* Update resolved canvas notes to reflect changes in zoom without touching model. Leave active notes (with length max) alone since @@ -1229,12 +1152,7 @@ MidiView::view_changed() ++i; } - for (vector::iterator j = ghosts.begin(); j != ghosts.end(); ++j) { - MidiGhostRegion* gr = dynamic_cast (*j); - if (gr && !gr->trackview.hidden()) { - gr->view_changed (); - } - } + ghosts_view_changed (); update_sysexes(); update_patch_changes (); @@ -1265,14 +1183,14 @@ MidiView::display_patch_changes_on_channel (uint8_t channel, bool active_channel if ((p = find_canvas_patch_change (*i)) != 0) { - const timepos_t region_time = _region->source_beats_to_region_time ((*i)->time()); - if (region_time < timepos_t() || region_time >= _region->length()) { + const timepos_t region_time = _current_slice.source_beats_to_region_time ((*i)->time()); + if (region_time < timepos_t() || region_time >= _current_slice.length()) { p->hide(); } else { - const timepos_t flag_time = _region->source_beats_to_absolute_time ((*i)->time()); - const double flag_x = editing_context.time_to_pixel (flag_time); + const timepos_t flag_time = _current_slice.source_beats_to_absolute_time ((*i)->time()); + const double flag_x = _editing_context.time_to_pixel (flag_time); - const double region_x = editing_context.time_to_pixel (_region->position()); + const double region_x = _editing_context.time_to_pixel (_current_slice.position()); p->canvas_item()->set_position (ArdourCanvas::Duple (flag_x-region_x, 1.0)); p->update_name (); @@ -1293,15 +1211,15 @@ MidiView::update_patch_changes () std::shared_ptr pc (p->second); - const timepos_t region_time = _region->source_beats_to_region_time (p->first->time()); + const timepos_t region_time (_current_slice.source_beats_to_region_time (p->first->time())); - if (region_time < timepos_t() || region_time >= _region->length()) { + if (region_time < timepos_t() || region_time >= _current_slice.length()) { pc->hide(); } else { - const timepos_t flag_time = _region->source_beats_to_absolute_time (p->first->time()); - const double flag_x = editing_context.time_to_pixel (flag_time); + const timepos_t flag_time = _current_slice.source_beats_to_absolute_time (p->first->time()); + const double flag_x = _editing_context.time_to_pixel (flag_time); - const double region_x = editing_context.time_to_pixel (_region->position()); + const double region_x = _editing_context.time_to_pixel (_current_slice.position()); pc->canvas_item()->set_position (ArdourCanvas::Duple (flag_x-region_x, 1.0)); pc->update_name (); @@ -1326,11 +1244,11 @@ MidiView::display_sysexes() } if (have_periodic_system_messages) { - double zoom = editing_context.get_current_zoom (); // samples per pixel + double zoom = _editing_context.get_current_zoom (); // samples per pixel /* get an approximate value for the number of samples per video frame */ - double video_frame = editing_context.session()->sample_rate() * (1.0/30); + double video_frame = _editing_context.session()->sample_rate() * (1.0/30); /* if we are zoomed out beyond than the cutoff (i.e. more * samples per pixel than samples per 4 video frames), don't @@ -1367,17 +1285,16 @@ MidiView::display_sysexes() } string text = str.str(); - const double x = editing_context.time_to_pixel (_region->source_beats_to_region_time (time.beats())); + const double x = _editing_context.time_to_pixel (_current_slice.source_beats_to_region_time (time.beats())); - double height = midi_stream_view()->contents_height(); + double height = _midi_context.contents_height(); // CAIROCANVAS: no longer passing *i (the sysex event) to the // SysEx canvas object!!! std::shared_ptr sysex = find_canvas_sys_ex (sysex_ptr); if (!sysex) { - sysex = std::shared_ptr( - new SysEx (*this, _note_group, text, height, x, 1.0, sysex_ptr)); + sysex = std::shared_ptr(new SysEx (_note_group, text, height, x, 1.0, sysex_ptr)); _sys_exes.insert (make_pair (sysex_ptr, sysex)); } else { sysex->set_height (height); @@ -1385,7 +1302,7 @@ MidiView::display_sysexes() } // Show unless message is beyond the region bounds - if (_region->source_relative_position (time) >= _region->length() || time < _region->start()) { + if (_current_slice.source_relative_position (time) >= _current_slice.length() || time < _current_slice.start()) { sysex->hide(); } else { sysex->show(); @@ -1396,7 +1313,7 @@ MidiView::display_sysexes() void MidiView::update_sysexes () { - double height = midi_stream_view()->contents_height(); + double height = _midi_context.contents_height(); for (SysExes::iterator s = _sys_exes.begin(); s != _sys_exes.end(); ++s) { @@ -1404,14 +1321,14 @@ MidiView::update_sysexes () std::shared_ptr sysex (s->second); // Show unless message is beyond the region bounds - if (_region->source_relative_position (time) >= _region->length() || time < _region->start()) { + if (_current_slice.source_relative_position (time) >= _current_slice.length() || time < _current_slice.start()) { sysex->hide(); continue; } else { sysex->show(); } - const double x = editing_context.time_to_pixel (_region->source_beats_to_region_time (time.beats())); + const double x = _editing_context.time_to_pixel (_current_slice.source_beats_to_region_time (time.beats())); sysex->set_height (height); sysex->item().set_position (ArdourCanvas::Duple (x, 1.0)); @@ -1420,14 +1337,10 @@ MidiView::update_sysexes () MidiView::~MidiView () { - in_destructor = true; - hide_verbose_cursor (); delete _list_editor; - RegionViewGoingAway (this); /* EMIT_SIGNAL */ - if (_active_notes) { end_write(); } @@ -1442,20 +1355,18 @@ MidiView::~MidiView () void MidiView::region_resized (const PropertyChange& what_changed) { - RegionView::region_resized(what_changed); // calls RegionView::set_duration() + // XXX RegionView::region_resized(what_changed); // calls RegionView::set_duration() } void MidiView::reset_width_dependent_items (double pixel_width) { - RegionView::reset_width_dependent_items(pixel_width); - view_changed (); bool hide_all = false; PatchChanges::iterator x = _patch_changes.begin(); if (x != _patch_changes.end()) { - hide_all = x->second->width() >= _pixel_width; + hide_all = x->second->width() >= pixel_width; } if (hide_all) { @@ -1469,25 +1380,20 @@ MidiView::reset_width_dependent_items (double pixel_width) } void -MidiView::set_height (double height) +MidiView::set_height (double ht) { - double old_height = _height; - RegionView::set_height(height); + double old_height = height(); - apply_note_range (midi_stream_view()->lowest_note(), - midi_stream_view()->highest_note(), - height != old_height); - - if (name_text) { - name_text->raise_to_top(); - } + apply_note_range (_midi_context.lowest_note(), + _midi_context.highest_note(), + ht != old_height); for (PatchChanges::iterator x = _patch_changes.begin(); x != _patch_changes.end(); ++x) { - (*x).second->set_height (midi_stream_view()->contents_height()); + (*x).second->set_height (_midi_context.contents_height()); } if (_step_edit_cursor) { - _step_edit_cursor->set_y1 (midi_stream_view()->contents_height()); + _step_edit_cursor->set_y1 (_midi_context.contents_height()); } } @@ -1545,7 +1451,7 @@ MidiView::extend_active_notes() for (unsigned i = 0; i < 128; ++i) { if (_active_notes[i]) { - _active_notes[i]->set_x1 (editing_context.duration_to_pixels (_region->length())); + _active_notes[i]->set_x1 (_editing_context.duration_to_pixels (_current_slice.length())); } } } @@ -1591,7 +1497,7 @@ bool MidiView::note_in_region_time_range (const std::shared_ptr note) const { const std::shared_ptr midi_reg = midi_region(); - return (timepos_t (note->time()) >= _region->start()) && (timepos_t (note->time()) < _region->start() + _region->length()); + return (timepos_t (note->time()) >= _current_slice.start()) && (timepos_t (note->time()) < _current_slice.start() + _current_slice.length()); } bool @@ -1638,16 +1544,16 @@ MidiView::update_sustained (Note* ev, bool update_ghost_regions) /* compute absolute time where the start of the source is */ - const timepos_t session_source_start = _region->source_position(); + const timepos_t session_source_start = _current_slice.source_position(); /* this computes the number of samples from the start of the region of the start of the * note. We add the source start to get to the absolute time of the * note, then subtract the start of the region */ - const samplepos_t note_start_samples = _region->position().distance ((note_start + session_source_start)).samples(); + const samplepos_t note_start_samples = _current_slice.position().distance ((note_start + session_source_start)).samples(); - const double x0 = editing_context.sample_to_pixel (note_start_samples); + const double x0 = _editing_context.sample_to_pixel (note_start_samples); double x1; const double y0 = 1 + floor(note_to_y(note->note())); @@ -1663,21 +1569,21 @@ MidiView::update_sustained (Note* ev, bool update_ghost_regions) /* normal note */ - const Temporal::Beats source_end ((_region->start() + _region->length()).beats()); + const Temporal::Beats source_end ((_current_slice.start() + _current_slice.length()).beats()); if (note->end_time() > source_end) { note_end = timepos_t (source_end); } - const samplepos_t note_end_samples = _region->position().distance ((note_end + session_source_start)).samples(); + const samplepos_t note_end_samples = _current_slice.position().distance ((note_end + session_source_start)).samples(); - x1 = std::max(1., editing_context.sample_to_pixel (note_end_samples)); + x1 = std::max(1., _editing_context.sample_to_pixel (note_end_samples)); } else { /* nascent note currently being recorded, noteOff has not yet arrived */ - x1 = std::max(1., editing_context.duration_to_pixels (_region->length())); + x1 = std::max(1., _editing_context.duration_to_pixels (_current_slice.length())); } y1 = y0 + std::max(1., floor(note_height()) - 1); @@ -1716,14 +1622,14 @@ void MidiView::update_hit (Hit* ev, bool update_ghost_regions) { std::shared_ptr note = ev->note(); - const timepos_t note_time = _region->source_beats_to_absolute_time (note->time()); + const timepos_t note_time = _current_slice.source_beats_to_absolute_time (note->time()); - const double x = editing_context.time_to_pixel(note_time) - editing_context.time_to_pixel (_region->position()); + const double x = _editing_context.time_to_pixel(note_time) - _editing_context.time_to_pixel (_current_slice.position()); const double diamond_size = std::max(1., floor(note_height()) - 2.); const double y = 1.5 + floor(note_to_y(note->note())) + diamond_size * .5; // see DnD note in MidiView::apply_note_range() above - if (y <= 0 || y >= _height) { + if (y <= 0 || y >= height()) { ev->hide(); } else { ev->show(); @@ -1749,7 +1655,7 @@ MidiView::add_note(const std::shared_ptr note, bool visible) { NoteBase* event = 0; - if (midi_view()->note_mode() == Sustained) { + if (_midi_context.note_mode() == Sustained) { Note* ev_rect = new Note (*this, _note_group, note); // XXX may leak @@ -1757,7 +1663,7 @@ MidiView::add_note(const std::shared_ptr note, bool visible) event = ev_rect; - } else if (midi_view()->note_mode() == Percussive) { + } else if (_midi_context.note_mode() == Percussive) { const double diamond_size = std::max(1., floor(note_height()) - 2.); @@ -1772,13 +1678,7 @@ MidiView::add_note(const std::shared_ptr note, bool visible) } if (event) { - MidiGhostRegion* gr; - - for (std::vector::iterator g = ghosts.begin(); g != ghosts.end(); ++g) { - if ((gr = dynamic_cast(*g)) != 0) { - gr->add_note(event); - } - } + ghost_add_note (event); if (_select_all_notes_after_add) { note_selected (event, true); @@ -1802,10 +1702,7 @@ MidiView::add_note(const std::shared_ptr note, bool visible) } } - MidiTimeAxisView* const mtv = dynamic_cast(&trackview); - MidiStreamView* const view = mtv->midi_view(); - - view->update_note_range (note->note()); + _midi_context.update_note_range (note->note()); return event; } @@ -1817,17 +1714,14 @@ MidiView::step_add_note (uint8_t channel, uint8_t number, uint8_t velocity, /* potentially extend region to hold new note */ - timepos_t note_end = _region->source_beats_to_absolute_time (new_note->end_time()); - timepos_t region_end = _region->nt_last(); + timepos_t note_end = _current_slice.source_beats_to_absolute_time (new_note->end_time()); + timepos_t region_end = _current_slice.nt_last(); if (note_end > region_end) { - _region->set_length (timecnt_t (note_end.earlier (_region->position()), timepos_t())); + _current_slice.set_length (timecnt_t (note_end.earlier (_current_slice.position()), timepos_t())); } - MidiTimeAxisView* const mtv = dynamic_cast(&trackview); - MidiStreamView* const view = mtv->midi_view(); - - view->update_note_range(new_note->note()); + _midi_context.update_note_range(new_note->note()); _marked_for_selection.clear (); @@ -1855,18 +1749,18 @@ MidiView::step_sustain (Temporal::Beats beats) void MidiView::add_canvas_patch_change (MidiModel::PatchChangePtr patch) { - timecnt_t off (_region->source_beats_to_region_time (patch->time()), _region->position()); - const double x = editing_context.duration_to_pixels (off); - double const height = midi_stream_view()->contents_height(); + timecnt_t off (_current_slice.source_beats_to_region_time (patch->time()), _current_slice.position()); + const double x = _editing_context.duration_to_pixels (off); + double const height = _midi_context.contents_height(); // CAIROCANVAS: active_channel info removed from PatcChange constructor // so we need to do something more sophisticated to keep its color // appearance (MidiPatchChangeFill/MidiPatchChangeInactiveChannelFill) // up to date. std::shared_ptr patch_change = std::shared_ptr( - new PatchChange(*this, group, + new PatchChange(*this, _note_group->parent(), height, x, 1.0, - instrument_info(), + _midi_track->instrument_info(), patch, _patch_change_outline, _patch_change_fill) @@ -1938,7 +1832,7 @@ MidiView::change_patch_change (PatchChange& pc, const MIDI::Name::PatchPrimaryKe c->change_bank (pc.patch (), new_bank); } - _model->apply_diff_command_as_commit (*editing_context.session(), c); + _model->apply_diff_command_as_commit (*_editing_context.session(), c); remove_canvas_patch_change (&pc); display_patch_changes (); @@ -1967,7 +1861,7 @@ MidiView::change_patch_change (MidiModel::PatchChangePtr old_change, const Evora c->change_bank (old_change, new_change.bank()); } - _model->apply_diff_command_as_commit (*editing_context.session(), c); + _model->apply_diff_command_as_commit (*_editing_context.session(), c); for (PatchChanges::iterator x = _patch_changes.begin(); x != _patch_changes.end(); ++x) { if (x->second->patch() == old_change) { @@ -1993,10 +1887,10 @@ MidiView::add_patch_change (timecnt_t const & t, Evoral::PatchChangeadd (MidiModel::PatchChangePtr ( new Evoral::PatchChange - (_region->source_relative_position (_region->position() + t).beats(), + (_current_slice.source_relative_position (_current_slice.position() + t).beats(), patch.channel(), patch.program(), patch.bank()))); - _model->apply_diff_command_as_commit (*editing_context.session(), c); + _model->apply_diff_command_as_commit (*_editing_context.session(), c); display_patch_changes (); } @@ -2006,8 +1900,8 @@ MidiView::move_patch_change (PatchChange& pc, Temporal::Beats t) { MidiModel::PatchChangeDiffCommand* c = _model->new_patch_change_diff_command (_("move patch change")); c->change_time (pc.patch (), t); - _model->apply_diff_command_as_commit (*editing_context.session(), c); -i + _model->apply_diff_command_as_commit (*_editing_context.session(), c); + display_patch_changes (); } @@ -2016,7 +1910,7 @@ MidiView::delete_patch_change (PatchChange* pc) { MidiModel::PatchChangeDiffCommand* c = _model->new_patch_change_diff_command (_("delete patch change")); c->remove (pc->patch ()); - _model->apply_diff_command_as_commit (*editing_context.session(), c); + _model->apply_diff_command_as_commit (*_editing_context.session(), c); remove_canvas_patch_change (pc); display_patch_changes (); @@ -2055,7 +1949,7 @@ MidiView::delete_selection() return; } - if (editing_context.drags()->active()) { + if (_editing_context.drags()->active()) { return; } @@ -2100,7 +1994,7 @@ MidiView::clear_selection_internal () for (auto & sel : _selection) { sel->set_selected(false); sel->hide_velocity(); - sync_ghost_selection (sel); + ghost_sync_selection (sel); } _selection.clear(); } @@ -2109,7 +2003,7 @@ void MidiView::clear_note_selection () { clear_selection_internal (); - editing_context.get_selection().remove (this); + // XXXX _editing_context.get_selection().remove (this); } void @@ -2133,7 +2027,7 @@ MidiView::select_range (timepos_t const & start, timepos_t const & end) { PBD::Unwinder uw (_no_sound_notes, true); for (Events::iterator i = _events.begin(); i != _events.end(); ++i) { - timepos_t t = _region->source_beats_to_absolute_time (i->first->time()); + timepos_t t = _current_slice.source_beats_to_absolute_time (i->first->time()); if (t >= start && t <= end) { add_to_selection (i->second); } @@ -2154,14 +2048,14 @@ MidiView::extend_selection () timepos_t first_note_start = timepos_t::max (BeatTime); for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) { - timepos_t e (_region->source_beats_to_absolute_beats ((*i)->note()->time())); + timepos_t e (_current_slice.source_beats_to_absolute_beats ((*i)->note()->time())); if (e < first_note_start) { first_note_start = e; } } for (Events::iterator i = _events.begin(); i != _events.end(); ++i) { - timepos_t t (_region->source_beats_to_absolute_beats(i->first->time())); + timepos_t t (_current_slice.source_beats_to_absolute_beats(i->first->time())); if (i->second->selected()) { continue; @@ -2359,9 +2253,9 @@ void MidiView::update_drag_selection(timepos_t const & start, timepos_t const & end, double gy0, double gy1, bool extend) { // Convert to local coordinates - const double y = midi_view()->y_position(); - const double x0 = editing_context.sample_to_pixel_unrounded (max(0, _region->region_relative_position (start).samples())); - const double x1 = editing_context.sample_to_pixel_unrounded (max(0, _region->region_relative_position (end).samples())); + const double y = _midi_context.y_position(); + const double x0 = _editing_context.sample_to_pixel_unrounded (max(0, _current_slice.region_relative_position (start).samples())); + const double x1 = _editing_context.sample_to_pixel_unrounded (max(0, _current_slice.region_relative_position (end).samples())); const double y0 = max(0.0, gy0 - y); const double y1 = max(0.0, gy1 - y); @@ -2384,10 +2278,13 @@ MidiView::update_drag_selection(timepos_t const & start, timepos_t const & end, typedef RouteTimeAxisView::AutomationTracks ATracks; typedef std::list Selectables; - /* Add control points to selection. */ + +#warning paul fix me MRV/MV +#if 0 +/* Add control points to selection. */ const ATracks& atracks = midi_view()->automation_tracks(); Selectables selectables; - editing_context.get_selection().clear_points(); + _editing_context.get_selection().clear_points(); timepos_t st (start); timepos_t et (end); @@ -2397,11 +2294,12 @@ MidiView::update_drag_selection(timepos_t const & start, timepos_t const & end, for (Selectables::const_iterator s = selectables.begin(); s != selectables.end(); ++s) { ControlPoint* cp = dynamic_cast(*s); if (cp) { - editing_context.get_selection().add(cp); + _editing_context.get_selection().add(cp); } } - a->second->set_selected_points(editing_context.get_selection().points); + a->second->set_selected_points(_editing_context.get_selection().points); } +#endif } void @@ -2439,23 +2337,13 @@ MidiView::remove_from_selection (NoteBase* ev) ev->set_selected (false); ev->hide_velocity (); - sync_ghost_selection (ev); + ghost_sync_selection (ev); if (_selection.empty()) { - editing_context.get_selection().remove (this); + // XXXX _editing_context.get_selection().remove (this); } } -void -MidiView::set_selected (bool selected) -{ - if (!selected) { - clear_selection_internal (); - } - - RegionView::set_selected (selected); -} - void MidiView::add_to_selection (NoteBase* ev) { @@ -2465,7 +2353,7 @@ MidiView::add_to_selection (NoteBase* ev) * 1 thing can be selected by clearing any current selection */ - editing_context.get_selection().clear (); + _editing_context.get_selection().clear (); /* first note selected in this region, force Editor region * selection to this region. @@ -2477,26 +2365,13 @@ MidiView::add_to_selection (NoteBase* ev) * only apply to notes anyway, not regions. */ - editing_context.set_selected_midi_region_view (*this); + // XXX _editing_context.set_selected_midi_region_view (*this); } if (_selection.insert (ev).second == true) { ev->set_selected (true); start_playing_midi_note ((ev)->note()); - sync_ghost_selection (ev); - } -} - -void -MidiView::sync_ghost_selection (NoteBase* ev) -{ - for (auto & ghost : ghosts) { - - MidiGhostRegion* gr; - - if ((gr = dynamic_cast(ghost)) != 0) { - gr->note_selected (ev); - } + ghost_sync_selection (ev); } } @@ -2526,17 +2401,17 @@ MidiView::move_selection(timecnt_t const & dx_qn, double dy, double cumulative_d if (n->note()->time() == earliest) { to_play.push_back (n->note()); } - Temporal::Beats const note_time_qn = _region->source_beats_to_absolute_beats (n->note()->time()); + Temporal::Beats const note_time_qn = _current_slice.source_beats_to_absolute_beats (n->note()->time()); double dx = 0.0; - if (midi_view()->note_mode() == Sustained) { - dx = editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn + dx_qn.beats())) + if (_midi_context.note_mode() == Sustained) { + dx = _editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn + dx_qn.beats())) - n->item()->item_to_canvas (ArdourCanvas::Duple (n->x0(), 0)).x; } else { /* Hit::x0() is offset by _position.x, unlike Note::x0() */ Hit* hit = dynamic_cast(n); if (hit) { - dx = editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn + dx_qn.beats())) + dx = _editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn + dx_qn.beats())) - n->item()->item_to_canvas (ArdourCanvas::Duple (((hit->x0() + hit->x1()) / 2.0) - hit->position().x, 0)).x; } } @@ -2544,9 +2419,9 @@ MidiView::move_selection(timecnt_t const & dx_qn, double dy, double cumulative_d (*i)->move_event(dx, dy); /* update length */ - if (midi_view()->note_mode() == Sustained) { + if (_midi_context.note_mode() == Sustained) { Note* sus = dynamic_cast (*i); - double const len_dx = editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn) + dx_qn + timecnt_t (n->note()->length())); + double const len_dx = _editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn) + dx_qn + timecnt_t (n->note()->length())); sus->set_x1 (n->item()->canvas_to_item (ArdourCanvas::Duple (len_dx, 0)).x); } @@ -2589,7 +2464,7 @@ MidiView::copy_selection (NoteBase* primary) for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) { std::shared_ptr g (new NoteType (*((*i)->note()))); - if (midi_view()->note_mode() == Sustained) { + if (_midi_context.note_mode() == Sustained) { Note* n = new Note (*this, _note_group, g); update_sustained (n, false); note = n; @@ -2622,25 +2497,25 @@ MidiView::move_copies (timecnt_t const & dx_qn, double dy, double cumulative_dy) to_play.push_back (n->note()); } - timepos_t const note_time_qn = _region->source_beats_to_absolute_time (n->note()->time()); + timepos_t const note_time_qn = _current_slice.source_beats_to_absolute_time (n->note()->time()); double_t dx = 0; - if (midi_view()->note_mode() == Sustained) { - dx = editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn) + dx_qn) + if (_midi_context.note_mode() == Sustained) { + dx = _editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn) + dx_qn) - n->item()->item_to_canvas (ArdourCanvas::Duple (n->x0(), 0)).x; } else { Hit* hit = dynamic_cast(n); if (hit) { - dx = editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn) + dx_qn) + dx = _editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn) + dx_qn) - n->item()->item_to_canvas (ArdourCanvas::Duple (((hit->x0() + hit->x1()) / 2.0) - hit->position().x, 0)).x; } } (*i)->move_event(dx, dy); - if (midi_view()->note_mode() == Sustained) { + if (_midi_context.note_mode() == Sustained) { Note* sus = dynamic_cast (*i); - double const len_dx = editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn) + dx_qn + timecnt_t (n->note()->length())); + double const len_dx = _editing_context.time_to_pixel_unrounded (timepos_t (note_time_qn) + dx_qn + timecnt_t (n->note()->length())); sus->set_x1 (n->item()->canvas_to_item (ArdourCanvas::Duple (len_dx, 0)).x); } @@ -2687,8 +2562,8 @@ MidiView::note_dropped(NoteBase *, timecnt_t const & d_qn, int8_t dnote, bool co /* cerr << "dnote: " << (int) dnote << endl; - cerr << "lowest note (streamview): " << int(midi_stream_view()->lowest_note()) - << " highest note (streamview): " << int(midi_stream_view()->highest_note()) << endl; + cerr << "lowest note (streamview): " << int(_midi_context.lowest_note()) + << " highest note (streamview): " << int(_midi_context.highest_note()) << endl; cerr << "lowest note (selection): " << int(lowest_note_in_selection) << " highest note(selection): " << int(highest_note_in_selection) << endl; cerr << "selection size: " << _selection.size() << endl; @@ -2773,12 +2648,12 @@ MidiView::note_dropped(NoteBase *, timecnt_t const & d_qn, int8_t dnote, bool co } apply_note_diff (true /*subcommand, we don't want this to start a new commit*/, copy); - editing_context.commit_reversible_command (); + _editing_context.commit_reversible_command (); // care about notes being moved beyond the upper/lower bounds on the canvas - if (lowest_note_in_selection < midi_stream_view()->lowest_note() || - highest_note_in_selection > midi_stream_view()->highest_note()) { - midi_stream_view()->set_note_range (MidiStreamView::ContentsRange); + if (lowest_note_in_selection < _midi_context.lowest_note() || + highest_note_in_selection > _midi_context.highest_note()) { + _midi_context.set_note_range (MidiStreamView::ContentsRange); } } @@ -2790,7 +2665,7 @@ MidiView::note_dropped(NoteBase *, timecnt_t const & d_qn, int8_t dnote, bool co timecnt_t MidiView::snap_pixel_to_time (double x, bool ensure_snap) { - return snap_region_time_to_region_time (timecnt_t (editing_context.pixel_to_sample (x)), ensure_snap); + return _editing_context.snap_relative_time_to_relative_time (_current_slice.position(), timecnt_t (_editing_context.pixel_to_sample (x)), ensure_snap); } /** @param x Pixel relative to the region position. @@ -2800,20 +2675,19 @@ MidiView::snap_pixel_to_time (double x, bool ensure_snap) double MidiView::snap_to_pixel(double x, bool ensure_snap) { - return (double) editing_context.sample_to_pixel (snap_pixel_to_time(x, ensure_snap).samples()); + return (double) _editing_context.sample_to_pixel (snap_pixel_to_time(x, ensure_snap).samples()); } double MidiView::get_position_pixels() { - return editing_context.time_to_pixel(get_position()); + return _editing_context.time_to_pixel(_current_slice.position()); } double MidiView::get_end_position_pixels() { - const timepos_t end = get_position() + get_duration (); - return editing_context.time_to_pixel (end); + return _editing_context.time_to_pixel (_current_slice.end()); } void @@ -2869,7 +2743,7 @@ void MidiView::update_resizing (NoteBase* primary, bool at_front, double delta_x, bool relative, double snap_delta, bool with_snap) { bool cursor_set = false; - bool const ensure_snap = editing_context.snap_mode () != SnapMagnetic; + bool const ensure_snap = _editing_context.snap_mode () != SnapMagnetic; for (std::vector::iterator i = _resize_data.begin(); i != _resize_data.end(); ++i) { ArdourCanvas::Rectangle* resize_rect = (*i)->resize_rect; @@ -2896,8 +2770,8 @@ MidiView::update_resizing (NoteBase* primary, bool at_front, double delta_x, boo */ current_x = 0; } - if (current_x > editing_context.duration_to_pixels (_region->length())) { - current_x = editing_context.duration_to_pixels (_region->length()); + if (current_x > _editing_context.duration_to_pixels (_current_slice.length())) { + current_x = _editing_context.duration_to_pixels (_current_slice.length()); } if (at_front) { @@ -2919,16 +2793,16 @@ MidiView::update_resizing (NoteBase* primary, bool at_front, double delta_x, boo if (!cursor_set) { /* Convert snap delta from pixels to beats. */ - timepos_t snap_delta_time = timepos_t (editing_context.pixel_to_sample (snap_delta)); + timepos_t snap_delta_time = timepos_t (_editing_context.pixel_to_sample (snap_delta)); Beats snap_delta_beats; int sign = 1; /* negative beat offsets aren't allowed */ if (snap_delta_time > 0) { - snap_delta_beats = _region->region_distance_to_region_beats (timecnt_t (snap_delta_time, _region->position())); + snap_delta_beats = _current_slice.region_distance_to_region_beats (timecnt_t (snap_delta_time, _current_slice.position())); } else if (snap_delta_time < 0) { - snap_delta_beats = _region->region_distance_to_region_beats (timecnt_t (-snap_delta_time, _region->position())); + snap_delta_beats = _current_slice.region_distance_to_region_beats (timecnt_t (-snap_delta_time, _current_slice.position())); sign = -1; } @@ -2937,12 +2811,12 @@ MidiView::update_resizing (NoteBase* primary, bool at_front, double delta_x, boo if (with_snap) { snapped_x = snap_pixel_to_time (current_x, ensure_snap); /* units depend on snap settings */ } else { - snapped_x = timepos_t (editing_context.pixel_to_sample (current_x)); /* probably samples */ + snapped_x = timepos_t (_editing_context.pixel_to_sample (current_x)); /* probably samples */ } Temporal::TempoMap::SharedPtr tmap (Temporal::TempoMap::use()); const timepos_t abs_beats (tmap->quarters_at (snapped_x)); - const Temporal::Beats src_beats = _region->absolute_time_to_source_beats (abs_beats); + const Temporal::Beats src_beats = _current_slice.absolute_time_to_source_beats (abs_beats); Temporal::Beats len = Temporal::Beats(); if (at_front) { @@ -2970,7 +2844,7 @@ MidiView::update_resizing (NoteBase* primary, bool at_front, double delta_x, boo cursor_set = true; - editing_context.set_snapped_cursor_position (snapped_x + midi_region()->position()); + _editing_context.set_snapped_cursor_position (snapped_x + midi_region()->position()); } } @@ -2986,7 +2860,7 @@ MidiView::finish_resizing (NoteBase* primary, bool at_front, double delta_x, boo _note_diff_command = _model->new_note_diff_command (_("resize notes")); /* we are a subcommand, so we don't want to use start_note_diff() which begins a new command */ /* XX why doesn't snap_pixel_to_sample() handle this properly? */ - bool const ensure_snap = editing_context.snap_mode () != SnapMagnetic; + bool const ensure_snap = _editing_context.snap_mode () != SnapMagnetic; for (std::vector::iterator i = _resize_data.begin(); i != _resize_data.end(); ++i) { Note* canvas_note = (*i)->note; @@ -3016,19 +2890,19 @@ MidiView::finish_resizing (NoteBase* primary, bool at_front, double delta_x, boo current_x = 0; } - if (current_x > editing_context.duration_to_pixels (_region->length())) { - current_x = editing_context.duration_to_pixels (_region->length()); + if (current_x > _editing_context.duration_to_pixels (_current_slice.length())) { + current_x = _editing_context.duration_to_pixels (_current_slice.length()); } /* Convert snap delta from pixels to beats with sign. */ - timepos_t snap_delta_time (editing_context.pixel_to_sample (snap_delta)); + timepos_t snap_delta_time (_editing_context.pixel_to_sample (snap_delta)); Temporal::Beats snap_delta_beats; int sign = 1; if (snap_delta_time.is_positive()) { - snap_delta_beats = _region->region_distance_to_region_beats (timecnt_t (snap_delta_time, _region->position())); + snap_delta_beats = _current_slice.region_distance_to_region_beats (timecnt_t (snap_delta_time, _current_slice.position())); } else if (snap_delta_time.is_negative()) { - snap_delta_beats = _region->region_distance_to_region_beats (timecnt_t (-snap_delta_time, _region->position())); + snap_delta_beats = _current_slice.region_distance_to_region_beats (timecnt_t (-snap_delta_time, _current_slice.position())); sign = -1; } @@ -3037,11 +2911,11 @@ MidiView::finish_resizing (NoteBase* primary, bool at_front, double delta_x, boo if (with_snap) { current_time = snap_pixel_to_time (current_x, ensure_snap); } else { - current_time = timecnt_t (editing_context.pixel_to_sample (current_x)); + current_time = timecnt_t (_editing_context.pixel_to_sample (current_x)); } /* and then to beats */ - const Temporal::Beats src_beats = _region->absolute_time_to_source_beats (_region->position() + current_time); + const Temporal::Beats src_beats = _current_slice.absolute_time_to_source_beats (_current_slice.position() + current_time); if (at_front && src_beats < canvas_note->note()->end_time()) { note_diff_add_change (canvas_note, MidiModel::NoteDiffCommand::StartTime, src_beats - (snap_delta_beats * sign)); @@ -3236,7 +3110,7 @@ MidiView::change_note_length (NoteBase* event, Temporal::Beats t) void MidiView::begin_drag_edit (std::string const & why) { - editing_context.get_selection().set (this, true); + // XXXX _editing_context.get_selection().set (this, true); start_note_diff_command (why); } @@ -3273,7 +3147,7 @@ MidiView::set_velocities_for_notes (std::vector& notes, std::vectorlowest_note(); - uint8_t highest = midi_stream_view()->highest_note(); + uint8_t lowest = _midi_context.lowest_note(); + uint8_t highest = _midi_context.highest_note(); for (Selection::iterator i = _selection.begin(); i != _selection.end(); ) { Selection::iterator next = i; @@ -3440,9 +3314,9 @@ MidiView::transpose (bool up, bool fine, bool allow_smush) apply_note_diff (); - if (lowest < _lowest_note || highest > _highest_note) { - update_note_range (lowest); - update_note_range (highest); + if (lowest < _midi_context.lowest_note() || highest > _midi_context.highest_note()) { + _midi_context.update_note_range (lowest); + _midi_context.update_note_range (highest); apply_note_range (lowest, highest, true); } } @@ -3455,7 +3329,7 @@ MidiView::change_note_lengths (bool fine, bool shorter, Temporal::Beats delta, b delta = Temporal::Beats::ticks (Temporal::ticks_per_beat / 128); } else { /* grab the current grid distance */ - delta = get_draw_length_beats (_region->position()); + delta = get_draw_length_beats (_current_slice.position()); } } @@ -3493,17 +3367,17 @@ MidiView::nudge_notes (bool forward, bool fine) into a vector and sort before using the first one. */ - const timepos_t ref_point = _region->source_beats_to_absolute_time ((*(_selection.begin()))->note()->time()); + const timepos_t ref_point = _current_slice.source_beats_to_absolute_time ((*(_selection.begin()))->note()->time()); Temporal::Beats delta; timecnt_t unused; - const timecnt_t distance = editing_context.get_nudge_distance (ref_point, unused); + const timecnt_t distance = _editing_context.get_nudge_distance (ref_point, unused); - if (!distance.is_zero() || editing_context.snap_mode() == Editing::SnapOff) { + if (!distance.is_zero() || _editing_context.snap_mode() == Editing::SnapOff) { /* grid is off - use nudge distance */ - delta = _region->region_distance_to_region_beats (timecnt_t (distance.beats(), _region->position())); + delta = _current_slice.region_distance_to_region_beats (timecnt_t (distance.beats(), _current_slice.position())); } else { @@ -3511,7 +3385,7 @@ MidiView::nudge_notes (bool forward, bool fine) bool success; - delta = editing_context.get_grid_type_as_beats (success, ref_point); + delta = _editing_context.get_grid_type_as_beats (success, ref_point); if (!success) { delta = Temporal::Beats (1, 0); @@ -3563,12 +3437,12 @@ MidiView::note_entered(NoteBase* ev) note_selected (ev, true); - } else if (editing_context.current_mouse_mode() == MouseContent) { + } else if (_editing_context.current_mouse_mode() == MouseContent) { remove_ghost_note (); show_verbose_cursor (ev->note ()); - } else if (editing_context.current_mouse_mode() == MouseDraw) { + } else if (_editing_context.current_mouse_mode() == MouseDraw) { remove_ghost_note (); show_verbose_cursor (ev->note ()); @@ -3592,7 +3466,7 @@ MidiView::patch_entered (PatchChange* p) { ostringstream s; s << _("Bank ") << (p->patch()->bank() + MIDI_BP_ZERO) << '\n' - << instrument_info().get_patch_name_without (p->patch()->bank(), p->patch()->program(), p->patch()->channel()) << '\n' + << _midi_track->instrument_info().get_patch_name_without (p->patch()->bank(), p->patch()->program(), p->patch()->channel()) << '\n' << _("Channel ") << ((int) p->patch()->channel() + 1); show_verbose_cursor (s.str(), 10, 20); //p->item().grab_focus(); @@ -3630,17 +3504,17 @@ MidiView::sysex_left (SysEx *) void MidiView::note_mouse_position (float x_fraction, float /*y_fraction*/, bool can_set_cursor) { - Editing::MouseMode mm = editing_context.current_mouse_mode(); + Editing::MouseMode mm = _editing_context.current_mouse_mode(); bool trimmable = (mm == MouseContent || mm == MouseTimeFX || mm == MouseDraw); - Editor::EnterContext* ctx = editing_context.get_enter_context(NoteItem); + EditingContext::EnterContext* ctx = _editing_context.get_enter_context(NoteItem); if (can_set_cursor && ctx) { if (trimmable && x_fraction > 0.0 && x_fraction < 0.2) { - ctx->cursor_ctx->change(editing_context.cursors()->left_side_trim); + ctx->cursor_ctx->change(_editing_context.cursors()->left_side_trim); } else if (trimmable && x_fraction >= 0.8 && x_fraction < 1.0) { - ctx->cursor_ctx->change(editing_context.cursors()->right_side_trim); + ctx->cursor_ctx->change(_editing_context.cursors()->right_side_trim); } else { - ctx->cursor_ctx->change(editing_context.cursors()->grabber_note); + ctx->cursor_ctx->change(_editing_context.cursors()->grabber_note); } } } @@ -3654,35 +3528,12 @@ MidiView::get_modifier_name () const uint32_t MidiView::get_fill_color() const { - const bool opaque = opaque() || trackview.layer_display () == Stacked; - std::string mod_name = get_modifier_name(); - if (_dragging) { - mod_name = "dragging region"; - } else if (editing_context.internal_editing()) { - if (!opaque || _region->muted ()) { - mod_name = "editable region"; - } - } else { - if (!opaque || _region->muted ()) { - mod_name = "transparent region base"; - } - } - - Gtkmm2ext::Color c; - if (_selected) { - c = UIConfiguration::instance().color ("selected region base"); - } else if ((!UIConfiguration::instance().get_show_name_highlight() || high_enough_for_name) && !UIConfiguration::instance().get_color_regions_using_track_color()) { - c = UIConfiguration::instance().color (fill_color_name); - } else { - c = fill_color; - } - if (mod_name.empty ()) { - return c; + return get_fill_color(); } else { - return UIConfiguration::instance().color_mod (c, mod_name); + return UIConfiguration::instance().color_mod (get_fill_color(), mod_name); } } @@ -3726,7 +3577,7 @@ MidiView::cut_copy_clear (Editing::CutCopyOp op) break; case Cut: case Copy: - editing_context.get_cut_buffer().add (selection_as_cut_buffer()); + _editing_context.get_cut_buffer().add (selection_as_cut_buffer()); break; default: break; @@ -3762,7 +3613,7 @@ MidiView::selection_as_cut_buffer () const notes.insert (std::shared_ptr (new NoteType (*n))); } - MidiCutBuffer* cb = new MidiCutBuffer (editing_context.session()); + MidiCutBuffer* cb = new MidiCutBuffer (_editing_context.session()); cb->set (notes); return cb; @@ -3771,7 +3622,7 @@ MidiView::selection_as_cut_buffer () const void MidiView::duplicate_selection () { - editing_context.begin_reversible_command (_("duplicate notes")); + _editing_context.begin_reversible_command (_("duplicate notes")); if (_selection.empty()) { return; @@ -3781,7 +3632,7 @@ MidiView::duplicate_selection () timepos_t dup_pos = timepos_t (Temporal::BeatTime); for (Selection::const_iterator s = _selection.begin(); s != _selection.end(); ++s) { - dup_pos = std::max (dup_pos, _region->source_beats_to_absolute_time ((*s)->note()->end_time())); + dup_pos = std::max (dup_pos, _current_slice.source_beats_to_absolute_time ((*s)->note()->end_time())); } /* Use a local Selection object that will not affect the global @@ -3789,7 +3640,7 @@ MidiView::duplicate_selection () * object but that would conflict with the Editor API. */ - ::Selection local_selection (dynamic_cast (&editing_context), false); + ::Selection local_selection (dynamic_cast (&_editing_context), false); MidiNoteSelection note_selection; note_selection.push_back (selection_as_cut_buffer()); @@ -3799,9 +3650,9 @@ MidiView::duplicate_selection () PasteContext ctxt (0, 1, ItemCounts(), false); bool commit = paste (dup_pos, local_selection, ctxt); if (commit) { - editing_context.commit_reversible_command (); + _editing_context.commit_reversible_command (); } else { - editing_context.abort_reversible_command (); + _editing_context.abort_reversible_command (); } } @@ -3827,13 +3678,15 @@ MidiView::paste (timepos_t const & pos, const ::Selection& selection, PasteConte paste_internal (pos, ctx.count, ctx.times, **m); } +#warning paul fix MRV/MV +#if 0 // Paste control points to automation children, if available for (auto & at : midi_view()->automation_tracks()) { if (at.second->paste(pos, selection, ctx)) { commit = true; } } - +#endif return commit; } @@ -3855,13 +3708,13 @@ MidiView::paste_internal (timepos_t const & pos, unsigned paste_count, float tim const Temporal::Beats duration = last_time - first_time; const Temporal::Beats snap_duration = duration.round_to_multiple (snap_beats); const Temporal::Beats paste_offset = snap_duration * int32_t (paste_count); - const Temporal::Beats quarter_note = _region->absolute_time_to_source_beats (pos) + paste_offset; + const Temporal::Beats quarter_note = _current_slice.absolute_time_to_source_beats (pos) + paste_offset; Temporal::Beats end_point; DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("Paste data spans from %1 to %2 (%3) ; paste pos beats = %4 (based on %5 - %6)\n", first_time, last_time, - duration, pos, _region->position(), + duration, pos, _current_slice.position(), quarter_note)); for (int n = 0; n < (int) times; ++n) { @@ -3881,23 +3734,23 @@ MidiView::paste_internal (timepos_t const & pos, unsigned paste_count, float tim /* if we pasted past the current end of the region, extend the region */ - timepos_t end = _region->source_beats_to_absolute_time (end_point); - timepos_t region_end = _region->nt_last(); + timepos_t end = _current_slice.source_beats_to_absolute_time (end_point); + timepos_t region_end = _current_slice.nt_last(); if (end > region_end) { DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("Paste extended region from %1 to %2\n", region_end, end)); - _region->clear_changes (); + // XXXX _region->clear_changes (); /* we probably need to get the snap modifier somehow to make this correct for non-musical use */ - _region->set_length (_region->position().distance (end)); - editing_context.session()->add_command (new StatefulDiffCommand (_region)); + _current_slice.set_length (_current_slice.position().distance (end)); + _editing_context.session()->add_command (new StatefulDiffCommand (_region)); } _marked_for_selection.clear (); _pending_note_selection.clear (); - _model->apply_diff_command_as_subcommand (*editing_context.session(), _note_diff_command); + _model->apply_diff_command_as_subcommand (*_editing_context.session(), _note_diff_command); _note_diff_command = nullptr; } @@ -3922,7 +3775,7 @@ MidiView::goto_next_note (bool add_to_selection) return; } - editing_context.begin_reversible_selection_op (X_("Select Adjacent Note")); + _editing_context.begin_reversible_selection_op (X_("Select Adjacent Note")); for (MidiModel::Notes::iterator n = notes.begin(); n != notes.end(); ++n) { NoteBase* cne = 0; @@ -3956,7 +3809,7 @@ MidiView::goto_next_note (bool add_to_selection) } - editing_context.commit_reversible_selection_op(); + _editing_context.commit_reversible_selection_op(); } void @@ -3974,7 +3827,7 @@ MidiView::goto_previous_note (bool add_to_selection) return; } - editing_context.begin_reversible_selection_op (X_("Select Adjacent Note")); + _editing_context.begin_reversible_selection_op (X_("Select Adjacent Note")); for (MidiModel::Notes::reverse_iterator n = notes.rbegin(); n != notes.rend(); ++n) { NoteBase* cne = 0; @@ -4008,7 +3861,7 @@ MidiView::goto_previous_note (bool add_to_selection) unique_select (last_note); } - editing_context.commit_reversible_selection_op(); + _editing_context.commit_reversible_selection_op(); } void @@ -4040,22 +3893,20 @@ MidiView::update_ghost_note (double x, double y, uint32_t state) const double global_x (x); - MidiTimeAxisView* const mtv = dynamic_cast(&trackview); - _last_ghost_x = x; _last_ghost_y = y; /* we need the y value only */ _note_group->canvas_to_item (x, y); - samplepos_t const unsnapped_sample = editing_context.pixel_to_sample (global_x); + samplepos_t const unsnapped_sample = _editing_context.pixel_to_sample (global_x); Temporal::timepos_t snapped_pos = timepos_t (unsnapped_sample); - editing_context.snap_to (snapped_pos, RoundNearest, SnapToGrid_Scaled); + _editing_context.snap_to (snapped_pos, RoundNearest, SnapToGrid_Scaled); - const Temporal::Beats snapped_beats = _region->absolute_time_to_region_beats(snapped_pos); + const Temporal::Beats snapped_beats = _current_slice.absolute_time_to_region_beats(snapped_pos); /* prevent Percussive mode from displaying a ghost hit at region end */ - if ((midi_view()->note_mode() == Percussive) && (snapped_beats >= _region->length().beats())) { + if ((_midi_context.note_mode() == Percussive) && (snapped_beats >= _current_slice.length().beats())) { _ghost_note->hide(); hide_verbose_cursor (); return; @@ -4071,12 +3922,12 @@ MidiView::update_ghost_note (double x, double y, uint32_t state) _ghost_note->show(); /* calculate time in of a single grid units worth of beats, at the start of source */ - const Temporal::Beats length = get_draw_length_beats (_region->source_position() + timecnt_t (snapped_beats)); + const Temporal::Beats length = get_draw_length_beats (_current_slice.source_position() + timecnt_t (snapped_beats)); _ghost_note->note()->set_time (snapped_beats); _ghost_note->note()->set_length (length); _ghost_note->note()->set_note (y_to_note (y)); - _ghost_note->note()->set_channel (mtv->get_preferred_midi_channel ()); + _ghost_note->note()->set_channel (_midi_context.get_preferred_midi_channel ()); _ghost_note->note()->set_velocity (get_velocity_for_add (snapped_beats)); update_note (_ghost_note, false); @@ -4090,7 +3941,7 @@ MidiView::create_ghost_note (double x, double y, uint32_t state) remove_ghost_note (); std::shared_ptr g (new NoteType); - if (midi_view()->note_mode() == Sustained) { + if (_midi_context.note_mode() == Sustained) { _ghost_note = new Note (*this, _note_group, g); } else { _ghost_note = new Hit (*this, _note_group, 10, g); @@ -4113,11 +3964,8 @@ MidiView::remove_ghost_note () void MidiView::hide_verbose_cursor () { - editing_context.verbose_cursor()->hide (); - MidiTimeAxisView* mtv = dynamic_cast(&trackview); - if (mtv) { - mtv->set_note_highlight (NO_MIDI_NOTE); - } + _editing_context.verbose_cursor()->hide (); + _midi_context.set_note_highlight (NO_MIDI_NOTE); } void @@ -4163,26 +4011,24 @@ MidiView::maybe_select_by_position (GdkEventButton* ev, double /*x*/, double y) for (Events::iterator i = e.begin(); i != e.end(); ++i) { if (_selection.insert (i->second).second) { i->second->set_selected (true); - sync_ghost_selection (i->second); + ghost_sync_selection (i->second); } } if (add_mrv_selection) { - editing_context.get_selection().add (this); + // XXXXX _editing_context.get_selection().add (this); } } void MidiView::color_handler () { - RegionView::color_handler (); - _patch_change_outline = UIConfiguration::instance().color ("midi patch change outline"); _patch_change_fill = UIConfiguration::instance().color_mod ("midi patch change fill", "midi patch change fill"); for (Events::iterator i = _events.begin(); i != _events.end(); ++i) { i->second->set_selected (i->second->selected()); // will change color - sync_ghost_selection (i->second); + ghost_sync_selection (i->second); } /* XXX probably more to do here */ @@ -4192,11 +4038,9 @@ void MidiView::show_step_edit_cursor (Temporal::Beats pos) { if (_step_edit_cursor == 0) { - ArdourCanvas::Item* const group = get_canvas_group(); - - _step_edit_cursor = new ArdourCanvas::Rectangle (group); + _step_edit_cursor = new ArdourCanvas::Rectangle (_note_group->parent()); _step_edit_cursor->set_y0 (0); - _step_edit_cursor->set_y1 (midi_stream_view()->contents_height()); + _step_edit_cursor->set_y1 (_midi_context.contents_height()); _step_edit_cursor->set_fill_color (RGBA_TO_UINT (45,0,0,90)); _step_edit_cursor->set_outline_color (RGBA_TO_UINT (85,0,0,90)); } @@ -4211,7 +4055,7 @@ MidiView::move_step_edit_cursor (Temporal::Beats pos) _step_edit_cursor_position = pos; if (_step_edit_cursor) { - double pixel = editing_context.time_to_pixel (_region->region_beats_to_region_time (pos)); + double pixel = _editing_context.time_to_pixel (_current_slice.region_beats_to_region_time (pos)); _step_edit_cursor->set_x0 (pixel); set_step_edit_cursor_width (_step_edit_cursor_width); } @@ -4231,9 +4075,9 @@ MidiView::set_step_edit_cursor_width (Temporal::Beats beats) _step_edit_cursor_width = beats; if (_step_edit_cursor) { - _step_edit_cursor->set_x1 (_step_edit_cursor->x0() + editing_context.duration_to_pixels ( - _region->region_beats_to_region_time (_step_edit_cursor_position).distance - (_region->region_beats_to_region_time (_step_edit_cursor_position + beats)))); + _step_edit_cursor->set_x1 (_step_edit_cursor->x0() + _editing_context.duration_to_pixels ( + _current_slice.region_beats_to_region_time (_step_edit_cursor_position).distance + (_current_slice.region_beats_to_region_time (_step_edit_cursor_position + beats)))); } } @@ -4313,7 +4157,7 @@ MidiView::data_recorded (std::weak_ptr w) // - and then take the samples() value of that and convert it to pixels // // Much simpler to just use ev.time() which is already the absolute position (in sample-time) - _active_notes[note]->set_x1 (editing_context.sample_to_pixel ((src->time_since_capture_start (timepos_t (ev.time ()))).samples())); + _active_notes[note]->set_x1 (_editing_context.sample_to_pixel ((src->time_since_capture_start (timepos_t (ev.time ()))).samples())); _active_notes[note]->set_outline_all (); _active_notes[note] = 0; } @@ -4322,7 +4166,7 @@ MidiView::data_recorded (std::weak_ptr w) back = ev.time (); } - midi_stream_view()->check_record_layers (region(), back); + _midi_context.record_layer_check (_region, back); } void @@ -4336,7 +4180,7 @@ MidiView::trim_front_starting () void MidiView::trim_front_ending () { - if (_region->start().is_negative()) { + if (_current_slice.start().is_negative()) { /* Trim drag made start time -ve; fix this */ midi_region()->fix_negative_start (); } @@ -4345,7 +4189,7 @@ MidiView::trim_front_ending () void MidiView::edit_patch_change (PatchChange* pc) { - PatchChangeDialog d (editing_context.session(), *pc->patch (), instrument_info(), Gtk::Stock::APPLY, true, true, _region); + PatchChangeDialog d (_editing_context.session(), *pc->patch (), _midi_track->instrument_info(), Gtk::Stock::APPLY, true, true, _region); int response = d.run(); @@ -4381,12 +4225,9 @@ MidiView::get_note_name (std::shared_ptr n, uint8_t note_value) const using namespace MIDI::Name; std::string name; - MidiTimeAxisView* mtv = dynamic_cast(&trackview); - if (mtv) { - MIDI::Name::PatchPrimaryKey patch_key; - get_patch_key_at (n->time(), n->channel(), patch_key); - name = instrument_info ().get_note_name (patch_key.bank(), patch_key.program(), n->channel(), note_value); - } + MIDI::Name::PatchPrimaryKey patch_key; + get_patch_key_at (n->time(), n->channel(), patch_key); + name = _midi_track->instrument_info ().get_note_name (patch_key.bank(), patch_key.program(), n->channel(), note_value); char buf[128]; snprintf (buf, sizeof (buf), "%s #%d\nCh %d Vel %d\n%.3f beats", @@ -4403,11 +4244,7 @@ void MidiView::show_verbose_cursor_for_new_note_value(std::shared_ptr current_note, uint8_t new_value) const { - MidiTimeAxisView* mtv = dynamic_cast(&trackview); - if (mtv) { - mtv->set_note_highlight (new_value); - } - + _midi_context.set_note_highlight (new_value); show_verbose_cursor(get_note_name(current_note, new_value), 10, 20); } @@ -4420,9 +4257,9 @@ MidiView::show_verbose_cursor (std::shared_ptr n) const void MidiView::show_verbose_cursor (string const & text, double xoffset, double yoffset) const { - editing_context.verbose_cursor()->set (text); - editing_context.verbose_cursor()->show (); - editing_context.verbose_cursor()->set_offset (ArdourCanvas::Duple (xoffset, yoffset)); + _editing_context.verbose_cursor()->set (text); + _editing_context.verbose_cursor()->show (); + _editing_context.verbose_cursor()->set_offset (ArdourCanvas::Duple (xoffset, yoffset)); } @@ -4430,8 +4267,8 @@ uint8_t MidiView::get_channel_for_add (MidiModel::TimeType time) const { /* first, use the user-specified channel in the editor */ - if (editing_context.draw_channel() != Editing::DRAW_CHAN_AUTO) { - return editing_context.draw_channel(); + if (_editing_context.draw_channel() != Editing::DRAW_CHAN_AUTO) { + return _editing_context.draw_channel(); } /* second, use the nearest note in the region-view (consistent with get_velocity_for_add behavior) */ @@ -4449,20 +4286,14 @@ MidiView::get_channel_for_add (MidiModel::TimeType time) const } /* lastly: query the track's channel filter */ - MidiTimeAxisView* const mtv = dynamic_cast(&trackview); - if (mtv) { - return mtv->get_preferred_midi_channel(); - } - - /* fallback: ch0 */ - return 0; + return _midi_context.get_preferred_midi_channel(); } uint8_t MidiView::get_velocity_for_add (MidiModel::TimeType time) const { - if (editing_context.draw_velocity() != Editing::DRAW_VEL_AUTO) { - return editing_context.draw_velocity(); + if (_editing_context.draw_velocity() != Editing::DRAW_VEL_AUTO) { + return _editing_context.draw_velocity(); } if (_model->notes().size() < 2) { @@ -4503,23 +4334,20 @@ MidiView::get_velocity_for_add (MidiModel::TimeType time) const ChannelMode MidiView::get_channel_mode () const { - RouteTimeAxisView* rtav = dynamic_cast (&trackview); return _midi_track->get_playback_channel_mode(); } uint16_t MidiView::get_selected_channels () const { - RouteTimeAxisView* rtav = dynamic_cast (&trackview); return _midi_track->get_playback_channel_mask(); } - Temporal::Beats MidiView::get_grid_beats (timepos_t const & pos) const { bool success = false; - Temporal::Beats beats = editing_context.get_grid_type_as_beats (success, pos); + Temporal::Beats beats = _editing_context.get_grid_type_as_beats (success, pos); if (!success) { beats = Temporal::Beats (1, 0); @@ -4531,12 +4359,12 @@ MidiView::get_grid_beats (timepos_t const & pos) const Temporal::Beats MidiView::get_draw_length_beats (timepos_t const & pos) const { - if (midi_view()->note_mode() == Percussive) { + if (_midi_context.note_mode() == Percussive) { return Temporal::Beats (0, 1); } bool success = false; - Temporal::Beats beats = editing_context.get_draw_length_as_beats (success, pos); + Temporal::Beats beats = _editing_context.get_draw_length_as_beats (success, pos); if (!success) { beats = Temporal::Beats (1, 0); @@ -4570,20 +4398,23 @@ MidiView::note_to_y(uint8_t note) const void MidiView::quantize_selected_notes () { +#warning paul fix this MRV/MV +#if 0 std::cerr << "QSN!\n"; RegionSelection rs; rs.push_back (this); - Quantize* quant = editing_context.get_quantize_op (); + Quantize* quant = _editing_context.get_quantize_op (); if (!quant) { return; } - editing_context.apply_midi_note_edit_op (*quant, rs); + _editing_context.apply_midi_note_edit_op (*quant, rs); delete quant; +#endif } void @@ -4632,7 +4463,7 @@ MidiView::split_notes_grid () /* XXX need to adjust pos to be global */ bool success; - Temporal::Beats grid = editing_context.get_grid_type_as_beats (success, timepos_t (split_info.front().time)); + Temporal::Beats grid = _editing_context.get_grid_type_as_beats (success, timepos_t (split_info.front().time)); if (!success) { /* No grid => use quarters */ diff --git a/gtk2_ardour/midi_view.h b/gtk2_ardour/midi_view.h index f9e0cc054f..baefb48c3d 100644 --- a/gtk2_ardour/midi_view.h +++ b/gtk2_ardour/midi_view.h @@ -29,9 +29,14 @@ #include #include +#include + +#include + #include "pbd/signals.h" #include "ardour/midi_model.h" +#include "ardour/slice.h" #include "ardour/types.h" #include "editing.h" @@ -44,6 +49,7 @@ namespace ARDOUR { class MidiRegion; class MidiModel; + class MidiTrack; class Filter; }; @@ -69,15 +75,16 @@ class ItemCounts; class CursorContext; class VelocityGhostRegion; class EditingContext; +class PasteContext; -class MidiView +class MidiView : public virtual sigc::trackable { public: typedef Evoral::Note NoteType; typedef Evoral::Sequence::Notes Notes; MidiView (std::shared_ptr mt, - ArdourCanvas::Container* parent, + ArdourCanvas::Container& parent, EditingContext& ec, MidiViewBackground& bg, uint32_t basic_color); @@ -85,11 +92,12 @@ class MidiView virtual ~MidiView (); void init (bool wfd); + virtual bool display_enabled() const { return true; } void step_add_note (uint8_t channel, uint8_t number, uint8_t velocity, Temporal::Beats pos, Temporal::Beats len); void step_sustain (Temporal::Beats beats); - void set_height (double); + virtual void set_height (double); void apply_note_range(uint8_t lowest, uint8_t highest, bool force=false); // inline ARDOUR::ColorMode color_mode() const { return _background->color_mode(); } @@ -102,9 +110,11 @@ class MidiView void hide_step_edit_cursor (); void set_step_edit_cursor_width (Temporal::Beats beats); - virtual GhostRegion* add_ghost (TimeAxisView&) {} + virtual GhostRegion* add_ghost (TimeAxisView&) { return nullptr; } virtual std::string get_modifier_name() const; + void set_model (std::shared_ptr); + NoteBase* add_note(const std::shared_ptr note, bool visible); void cut_copy_clear (Editing::CutCopyOp); @@ -310,22 +320,25 @@ class MidiView */ void clear_selection (); - ARDOUR::InstrumentInfo& instrument_info() const; - void note_deleted (NoteBase*); void clear_note_selection (); void show_verbose_cursor_for_new_note_value(std::shared_ptr current_note, uint8_t new_note) const; + std::shared_ptr midi_region() const { return _region; } + EditingContext& editing_context() const { return _editing_context; } + MidiViewBackground& midi_context() const { return _midi_context; } + virtual ARDOUR::Slice const & current_slice() const { return _current_slice; } + protected: + void init (); void region_resized (const PBD::PropertyChange&); void set_flags (XMLNode *); void store_flags (); - void reset_width_dependent_items (double pixel_width); + virtual void reset_width_dependent_items (double pixel_width); - void parameter_changed (std::string const & p); void _redisplay (bool view_only); protected: @@ -406,6 +419,12 @@ class MidiView void clear_selection_internal (); void clear_events (); + virtual void clear_ghost_events() {} + virtual void ghosts_model_changed() {} + virtual void ghosts_view_changed() {} + virtual void ghost_remove_note (NoteBase*) {} + virtual void ghost_add_note (NoteBase*) {} + virtual void ghost_sync_selection (NoteBase*) {} bool canvas_group_event(GdkEvent* ev); bool note_canvas_event(GdkEvent* ev); @@ -443,9 +462,11 @@ class MidiView typedef std::vector CopyDragEvents; std::shared_ptr _midi_track; - EditingContext& editing_context; + EditingContext& _editing_context; + MidiViewBackground& _midi_context; std::shared_ptr _model; - MidiViewBackground& _background; + std::shared_ptr _region; + ARDOUR::Slice _current_slice; Events _events; CopyDragEvents _copy_drag_events; PatchChanges _patch_changes; @@ -461,6 +482,9 @@ class MidiView Temporal::Beats _step_edit_cursor_position; NoteBase* _channel_selection_scoped_note; + uint8_t _current_range_min; + uint8_t _current_range_max; + MouseState _mouse_state; int _pressed_button; @@ -508,14 +532,14 @@ class MidiView void snap_changed (); PBD::ScopedConnection snap_changed_connection; - bool motion (GdkEventMotion*); - bool scroll (GdkEventScroll*); - bool key_press (GdkEventKey*); - bool key_release (GdkEventKey*); - bool button_press (GdkEventButton*); - bool button_release (GdkEventButton*); - bool enter_notify (GdkEventCrossing*); - bool leave_notify (GdkEventCrossing*); + virtual bool motion (GdkEventMotion*); + virtual bool scroll (GdkEventScroll*); + virtual bool key_press (GdkEventKey*); + virtual bool key_release (GdkEventKey*); + virtual bool button_press (GdkEventButton*); + virtual bool button_release (GdkEventButton*); + virtual bool enter_notify (GdkEventCrossing*); + virtual bool leave_notify (GdkEventCrossing*); void drop_down_keys (); void maybe_select_by_position (GdkEventButton* ev, double x, double y); @@ -533,8 +557,8 @@ class MidiView void remove_ghost_note (); void mouse_mode_changed (); - void enter_internal (uint32_t state); - void leave_internal (); + virtual void enter_internal (uint32_t state); + virtual void leave_internal (); void hide_verbose_cursor (); samplecnt_t _last_display_zoom; @@ -557,7 +581,9 @@ class MidiView ARDOUR::ChannelMode get_channel_mode() const; uint16_t get_selected_channels () const; - inline double contents_height() const { return _height - 2; } + virtual double height() const = 0; + + virtual double contents_height() const { return height() - 2; } inline double contents_note_range () const { return (double)(_current_range_max - _current_range_min + 1); } inline double note_height() const { return contents_height() / contents_note_range(); } diff --git a/gtk2_ardour/midi_view_background.cc b/gtk2_ardour/midi_view_background.cc index a1394409ba..0436891642 100644 --- a/gtk2_ardour/midi_view_background.cc +++ b/gtk2_ardour/midi_view_background.cc @@ -40,6 +40,8 @@ MidiViewBackground::MidiViewBackground (ArdourCanvas::Item* parent) , _data_note_min (60) , _data_note_max (71) , _note_lines (new ArdourCanvas::LineSet (parent, ArdourCanvas::LineSet::Horizontal)) + , _note_mode (ARDOUR::Sustained) + , _color_mode (ARDOUR::MeterColors) { _note_lines->lower_to_bottom(); diff --git a/gtk2_ardour/midi_view_background.h b/gtk2_ardour/midi_view_background.h index 15314a4948..9c79422287 100644 --- a/gtk2_ardour/midi_view_background.h +++ b/gtk2_ardour/midi_view_background.h @@ -27,13 +27,13 @@ #include +#include "ardour/types.h" + namespace ArdourCanvas { -class Item; -class LineSet; + class Item; + class LineSet; } - - class MidiViewBackground { public: @@ -47,6 +47,14 @@ class MidiViewBackground ContentsRange }; + ARDOUR::NoteMode note_mode() const { return _note_mode; } + void set_note_mode (ARDOUR::NoteMode nm); + + ARDOUR::ColorMode color_mode() const { return _color_mode; } + void set_color_mode (ARDOUR::ColorMode); + + Gtkmm2ext::Color region_color() const { return _region_color; } + void set_note_range (VisibleNoteRange r); inline uint8_t lowest_note() const { return _lowest_note; } @@ -73,6 +81,13 @@ class MidiViewBackground sigc::signal NoteRangeChanged; void apply_note_range (uint8_t lowest, uint8_t highest, bool to_children); + /** @return y position, or -1 if hidden */ + virtual double y_position () const { return 0.; } + + virtual uint8_t get_preferred_midi_channel () const = 0; + virtual void set_note_highlight (bool) = 0; + virtual void record_layer_check (std::shared_ptr, samplepos_t) = 0; + protected: bool _range_dirty; double _range_sum_cache; @@ -81,6 +96,9 @@ class MidiViewBackground uint8_t _data_note_min; ///< in data uint8_t _data_note_max; ///< in data ArdourCanvas::LineSet* _note_lines; + ARDOUR::NoteMode _note_mode; + Gtkmm2ext::Color _region_color; + ARDOUR::ColorMode _color_mode; void color_handler (); void parameter_changed (std::string const &); diff --git a/gtk2_ardour/note.cc b/gtk2_ardour/note.cc index 0d179b9cf0..7ccba8b808 100644 --- a/gtk2_ardour/note.cc +++ b/gtk2_ardour/note.cc @@ -29,8 +29,7 @@ using namespace ARDOUR; using ArdourCanvas::Coord; using ArdourCanvas::Duple; -Note::Note ( - MidiRegionView& region, ArdourCanvas::Item* parent, const std::shared_ptr note, bool with_events) +Note::Note (MidiView& region, ArdourCanvas::Item* parent, const std::shared_ptr note, bool with_events) : NoteBase (region, with_events, note) , _visual_note (new ArdourCanvas::Note (parent)) { diff --git a/gtk2_ardour/note.h b/gtk2_ardour/note.h index 5fa15d75e0..af70520172 100644 --- a/gtk2_ardour/note.h +++ b/gtk2_ardour/note.h @@ -33,7 +33,7 @@ class Note : public NoteBase public: typedef Evoral::Note NoteType; - Note (MidiRegionView& region, + Note (MidiView& region, ArdourCanvas::Item* parent, const std::shared_ptr note = std::shared_ptr(), bool with_events = true); diff --git a/gtk2_ardour/note_base.cc b/gtk2_ardour/note_base.cc index bf75c1a4a7..d50d8a9953 100644 --- a/gtk2_ardour/note_base.cc +++ b/gtk2_ardour/note_base.cc @@ -28,9 +28,10 @@ #include "canvas/text.h" #include "note_base.h" -#include "public_editor.h" +#include "editing_context.h" +#include "editing_syms.h" #include "keyboard.h" -#include "midi_region_view.h" +#include "midi_view.h" /* clang-format off */ // Include last, when GRIDTYPE has been defined by editing.h via midi_region_view.h @@ -65,7 +66,7 @@ NoteBase::set_colors () color_modifier = UIConfiguration::instance().modifier ("midi note"); } -NoteBase::NoteBase(MidiRegionView& region, bool with_events, const std::shared_ptr note) +NoteBase::NoteBase(MidiView& region, bool with_events, const std::shared_ptr note) : _region(region) , _item (0) , _text(0) @@ -187,7 +188,7 @@ NoteBase::set_selected(bool selected) uint32_t NoteBase::base_color () { - return base_color (_note->velocity(), _region.color_mode(), _region.midi_stream_view()->get_region_color(), _note->channel(), selected()); + return base_color (_note->velocity(), _region.midi_context().color_mode(), _region.midi_context().region_color(), _note->channel(), selected()); } uint32_t @@ -292,7 +293,7 @@ NoteBase::set_mouse_fractions (GdkEvent* ev) bool NoteBase::event_handler (GdkEvent* ev) { - PublicEditor& editor = _region.get_time_axis_view().editor(); + EditingContext& editor = _region.editing_context(); if (!editor.internal_editing()) { return false; } diff --git a/gtk2_ardour/note_base.h b/gtk2_ardour/note_base.h index ee2d677ba5..b548fb80d8 100644 --- a/gtk2_ardour/note_base.h +++ b/gtk2_ardour/note_base.h @@ -33,7 +33,7 @@ #include "ui_config.h" class Editor; -class MidiRegionView; +class MidiView; namespace Evoral { template class Note; @@ -67,7 +67,7 @@ class NoteBase : public sigc::trackable public: typedef Evoral::Note NoteType; - NoteBase (MidiRegionView& region, bool, const std::shared_ptr note = std::shared_ptr()); + NoteBase (MidiView& region, bool, const std::shared_ptr note = std::shared_ptr()); virtual ~NoteBase (); void set_item (ArdourCanvas::Item *); @@ -115,7 +115,7 @@ class NoteBase : public sigc::trackable float mouse_y_fraction() const { return _mouse_y_fraction; } const std::shared_ptr note() const { return _note; } - MidiRegionView& region_view() const { return _region; } + MidiView& region_view() const { return _region; } static void set_colors (); @@ -139,7 +139,7 @@ class NoteBase : public sigc::trackable protected: enum State { None, Pressed, Dragging }; - MidiRegionView& _region; + MidiView& _region; ArdourCanvas::Item* _item; ArdourCanvas::Text* _text; State _state; diff --git a/gtk2_ardour/patch_change.cc b/gtk2_ardour/patch_change.cc index 4d1d979b4a..91d2853682 100644 --- a/gtk2_ardour/patch_change.cc +++ b/gtk2_ardour/patch_change.cc @@ -34,7 +34,7 @@ #include "editor.h" #include "editor_drag.h" -#include "midi_region_view.h" +#include "midi_view.h" #include "patch_change.h" #include "ui_config.h" @@ -44,8 +44,8 @@ using Gtkmm2ext::Keyboard; /** @param x x position in pixels. */ -PatchChange::PatchChange (MidiRegionView& region, - ArdourCanvas::Container* parent, +PatchChange::PatchChange (MidiView& region, + ArdourCanvas::Item* parent, double height, double x, double y, @@ -153,15 +153,15 @@ bool PatchChange::event_handler (GdkEvent* ev) { /* XXX: icky dcast */ - Editor* e = dynamic_cast (&_region.get_time_axis_view ().editor ()); + EditingContext& e = _region.editing_context(); - if (!e->internal_editing ()) { + if (!e.internal_editing ()) { return false; } switch (ev->type) { case GDK_BUTTON_PRESS: - if (e->current_mouse_mode () == Editing::MouseContent) { + if (e.current_mouse_mode () == Editing::MouseContent) { if (Gtkmm2ext::Keyboard::is_delete_event (&ev->button)) { _region.delete_patch_change (this); return true; @@ -171,7 +171,7 @@ PatchChange::event_handler (GdkEvent* ev) return true; } else if (ev->button.button == 1) { - e->drags ()->set (new PatchChangeDrag (*e, this, &_region), ev); + e.drags ()->set (new PatchChangeDrag (e, this, &_region), ev); return true; } } diff --git a/gtk2_ardour/patch_change.h b/gtk2_ardour/patch_change.h index 3e41f8ac86..c436a92cbe 100644 --- a/gtk2_ardour/patch_change.h +++ b/gtk2_ardour/patch_change.h @@ -34,8 +34,8 @@ namespace MIDI { class PatchChange { public: - PatchChange (MidiRegionView& region, - ArdourCanvas::Container* parent, + PatchChange (MidiView& region, + ArdourCanvas::Item* parent, double height, double x, double y, @@ -65,7 +65,7 @@ public: private: bool event_handler (GdkEvent*); - MidiRegionView& _region; + MidiView& _region; ARDOUR::InstrumentInfo& _info; ARDOUR::MidiModel::PatchChangePtr _patch; Gtk::Menu _popup; diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index dafb10b274..3780eee848 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -96,6 +96,7 @@ class MeterMarker; class MixerStrip; class MouseCursors; class RegionView; +class MidiView; class RouteTimeAxisView; class Selection; class SimpleExport; @@ -329,7 +330,7 @@ public: virtual void add_to_idle_resize (TimeAxisView*, int32_t) = 0; virtual Temporal::timecnt_t get_paste_offset (Temporal::timepos_t const & pos, unsigned paste_count, Temporal::timecnt_t const & duration) = 0; - virtual void edit_notes (MidiRegionView*) = 0; + virtual void edit_notes (MidiView*) = 0; virtual void queue_visual_videotimeline_update () = 0; virtual void set_close_video_sensitive (bool) = 0; @@ -405,8 +406,6 @@ public: virtual bool canvas_bbt_marker_event (GdkEvent* event, ArdourCanvas::Item*, BBTMarker*) = 0; virtual bool canvas_automation_track_event(GdkEvent* event, ArdourCanvas::Item*, AutomationTimeAxisView*) = 0; - virtual bool canvas_note_event (GdkEvent* event, ArdourCanvas::Item*) = 0; - static const int window_border_width; static const int container_border_width; static const int vertical_spacing;