introduce the notion that note additions and property changes can cause the removal...
[ardour.git] / gtk2_ardour / editor_ops.cc
index a38998ba73a4ee7bf06a8260727a067be6627b41..9206f1516bfc1a2581d69237d028a346e5ec58d3 100644 (file)
@@ -170,11 +170,6 @@ Editor::split_regions_at (nframes64_t where, RegionSelection& regions)
                        pl->freeze();
                }
 
-               AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*a);
-               if (arv) {
-                       _new_regionviews_show_envelope = arv->envelope_visible();
-               }
-
                if (pl) {
                         pl->clear_history ();
                        pl->split_region ((*a)->region(), where);
@@ -191,7 +186,6 @@ Editor::split_regions_at (nframes64_t where, RegionSelection& regions)
        }
 
        commit_reversible_command ();
-       _new_regionviews_show_envelope = false;
 }
 
 boost::shared_ptr<Region>
@@ -637,8 +631,8 @@ Editor::build_region_boundary_cache ()
                        RouteTimeAxisView *rtav;
 
                        if (ontrack != 0 && (rtav = dynamic_cast<RouteTimeAxisView*>(ontrack)) != 0 ) {
-                               if (rtav->get_diskstream() != 0) {
-                                       speed = rtav->get_diskstream()->speed();
+                               if (rtav->track() != 0) {
+                                       speed = rtav->track()->speed();
                                }
                        }
 
@@ -692,8 +686,8 @@ Editor::find_next_region (nframes64_t frame, RegionPoint point, int32_t dir, Tra
 
                track_speed = 1.0f;
                if ( (rtav = dynamic_cast<RouteTimeAxisView*>(*i)) != 0 ) {
-                       if (rtav->get_diskstream()!=0)
-                               track_speed = rtav->get_diskstream()->speed();
+                       if (rtav->track()!=0)
+                               track_speed = rtav->track()->speed();
                }
 
                track_frame = session_frame_to_track_frame(frame, track_speed);
@@ -893,8 +887,8 @@ Editor::cursor_to_region_point (EditorCursor* cursor, RegionPoint point, int32_t
        RouteTimeAxisView *rtav;
 
        if ( ontrack != 0 && (rtav = dynamic_cast<RouteTimeAxisView*>(ontrack)) != 0 ) {
-               if (rtav->get_diskstream() != 0) {
-                       speed = rtav->get_diskstream()->speed();
+               if (rtav->track() != 0) {
+                       speed = rtav->track()->speed();
                }
        }
 
@@ -1090,8 +1084,8 @@ Editor::selected_marker_to_region_point (RegionPoint point, int32_t dir)
        RouteTimeAxisView *rtav;
 
        if (ontrack != 0 && (rtav = dynamic_cast<RouteTimeAxisView*>(ontrack)) != 0) {
-               if (rtav->get_diskstream() != 0) {
-                       speed = rtav->get_diskstream()->speed();
+               if (rtav->track() != 0) {
+                       speed = rtav->track()->speed();
                }
        }
 
@@ -1742,7 +1736,7 @@ Editor::temporal_zoom_region (bool both_axes)
 
                for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                        if (find (tracks.begin(), tracks.end(), (*i)) == tracks.end()) {
-                               hide_track_in_display (**i, true);
+                               hide_track_in_display (*i, true);
                        }
                }
 
@@ -1782,7 +1776,13 @@ Editor::temporal_zoom_session ()
        ENSURE_GUI_THREAD (*this, &Editor::temporal_zoom_session)
 
        if (_session) {
-               temporal_zoom_by_frame (_session->current_start_frame(), _session->current_end_frame(), "zoom to _session");
+               nframes_t const l = _session->current_end_frame() - _session->current_start_frame();
+               double s = _session->current_start_frame() - l * 0.01;
+               if (s < 0) {
+                       s = 0;
+               }
+               nframes_t const e = _session->current_end_frame() + l * 0.01;
+               temporal_zoom_by_frame (nframes_t (s), e, "zoom to _session");
        }
 }
 
@@ -2197,8 +2197,6 @@ Editor::insert_region_list_drag (boost::shared_ptr<Region> region, int x, int y)
        boost::shared_ptr<Playlist> playlist;
 
        track_canvas->window_to_world (x, y, wx, wy);
-       //wx += horizontal_adjustment.get_value();
-       //wy += vertical_adjustment.get_value();
 
        GdkEvent event;
        event.type = GDK_BUTTON_RELEASE;
@@ -2235,7 +2233,8 @@ Editor::insert_region_list_drag (boost::shared_ptr<Region> region, int x, int y)
 }
 
 void
-Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y) {
+Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y)
+{
        double wx, wy;
        double cx, cy;
        nframes_t where;
@@ -2243,7 +2242,7 @@ Editor::insert_route_list_drag (boost::shared_ptr<Route> route, int x, int y) {
        RouteTimeAxisView *source_rtv = 0;
 
        track_canvas->window_to_world (x, y, wx, wy);
-       wx += horizontal_adjustment.get_value();
+       wx += horizontal_position ();
        wy += vertical_adjustment.get_value();
 
        GdkEvent event;
@@ -2782,7 +2781,7 @@ Editor::separate_regions_between (const TimeSelection& ts)
 
                                /* no edits to destructive tracks */
 
-                               if (rtv->track()->diskstream()->destructive()) {
+                               if (rtv->track()->destructive()) {
                                        continue;
                                }
 
@@ -2792,7 +2791,7 @@ Editor::separate_regions_between (const TimeSelection& ts)
 
                                        /* XXX need to consider musical time selections here at some point */
 
-                                       double speed = rtv->get_diskstream()->speed();
+                                       double speed = rtv->track()->speed();
 
 
                                        for (list<AudioRange>::const_iterator t = ts.begin(); t != ts.end(); ++t) {
@@ -2939,7 +2938,7 @@ Editor::crop_region_to (nframes64_t start, nframes64_t end)
 
                        boost::shared_ptr<Track> t = rtv->track();
 
-                       if (t != 0 && ! t->diskstream()->destructive()) {
+                       if (t != 0 && ! t->destructive()) {
 
                                if ((playlist = rtv->playlist()) != 0) {
                                        playlists.push_back (playlist);
@@ -3411,8 +3410,8 @@ Editor::trim_region_to_location (const Location& loc, const char* str)
                nframes64_t start;
                nframes64_t end;
 
-               if (tav->get_diskstream() != 0) {
-                       speed = tav->get_diskstream()->speed();
+               if (tav->track() != 0) {
+                       speed = tav->track()->speed();
                }
 
                start = session_frame_to_track_frame (loc.start(), speed);
@@ -3452,8 +3451,8 @@ Editor::trim_region_to_edit_point ()
 
                float speed = 1.0;
 
-               if (tav->get_diskstream() != 0) {
-                       speed = tav->get_diskstream()->speed();
+               if (tav->track() != 0) {
+                       speed = tav->track()->speed();
                }
 
                 rv->region()->clear_history ();
@@ -3490,8 +3489,8 @@ Editor::trim_region_from_edit_point ()
 
                float speed = 1.0;
 
-               if (tav->get_diskstream() != 0) {
-                       speed = tav->get_diskstream()->speed();
+               if (tav->track() != 0) {
+                       speed = tav->track()->speed();
                }
 
                 rv->region()->clear_history ();
@@ -3541,8 +3540,8 @@ Editor::trim_to_region(bool forward)
 
                float speed = 1.0;
 
-               if (atav->get_diskstream() != 0) {
-                       speed = atav->get_diskstream()->speed();
+               if (atav->track() != 0) {
+                       speed = atav->track()->speed();
                }
 
 
@@ -3619,10 +3618,6 @@ Editor::freeze_route ()
 
        InterthreadProgressWindow ipw (current_interthread_info, _("Freeze"), _("Cancel Freeze"));
 
-       itt.done = false;
-       itt.cancel = false;
-       itt.progress = 0.0f;
-
        pthread_create_and_store (X_("freezer"), &itt.thread, _freeze_thread, this);
 
        track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
@@ -3666,11 +3661,9 @@ Editor::bounce_range_selection (bool replace, bool enable_processing)
 
                InterThreadInfo itt;
 
-               itt.done = false;
-               itt.cancel = false;
-               itt.progress = false;
-
                 playlist->clear_history ();
+               playlist->clear_owned_history ();
+               
                boost::shared_ptr<Region> r = rtv->track()->bounce_range (start, start+cnt, itt, enable_processing);
 
                if (replace) {
@@ -3680,7 +3673,13 @@ Editor::bounce_range_selection (bool replace, bool enable_processing)
                        playlist->add_region (r, start);
                }
 
-               _session->add_command (new StatefulDiffCommand (playlist));
+               vector<StatefulDiffCommand*> cmds;
+               playlist->rdiff (cmds);
+               for (vector<StatefulDiffCommand*>::iterator j = cmds.begin(); j != cmds.end(); ++j) {
+                       _session->add_command (*j);
+               }
+
+                _session->add_command (new StatefulDiffCommand (playlist));
        }
 
        commit_reversible_command ();
@@ -3774,7 +3773,7 @@ Editor::cut_copy (CutCopyOp op)
                        Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
                }
 
-               _drags->break_drag ();
+               _drags->abort ();
                return;
        }
 
@@ -3855,7 +3854,7 @@ Editor::cut_copy (CutCopyOp op)
        }
 
        if (op == Cut || op == Clear) {
-               _drags->break_drag ();
+               _drags->abort ();
        }
 }
 
@@ -4443,6 +4442,8 @@ Editor::normalize_region ()
 
        Dialog dialog (rs.size() > 1 ? _("Normalize regions") : _("Normalize region"));
        HBox hbox;
+       hbox.set_spacing (6);
+       hbox.set_border_width (6);
        hbox.pack_start (*manage (new Label (_("Normalize to:"))));
        SpinButton spin (0.2, 2);
        spin.set_range (-112, 0);
@@ -4452,6 +4453,7 @@ Editor::normalize_region ()
        spin.set_value (_last_normalization_value);
        hbox.pack_start (*manage (new Label (_("dbFS"))));
        hbox.show_all ();
+       dialog.get_vbox()->set_spacing (12);
        dialog.get_vbox()->pack_start (hbox);
        dialog.add_button (Stock::CANCEL, RESPONSE_CANCEL);
        dialog.add_button (_("Normalize"), RESPONSE_ACCEPT);
@@ -4611,7 +4613,7 @@ Command*
 Editor::apply_midi_note_edit_op_to_region (MidiOperator& op, MidiRegionView& mrv)
 {
        Evoral::Sequence<Evoral::MusicalTime>::Notes selected;
-       mrv.selection_as_notelist (selected);
+       mrv.selection_as_notelist (selected, true);
 
        vector<Evoral::Sequence<Evoral::MusicalTime>::Notes> v;
        v.push_back (selected);
@@ -4654,6 +4656,47 @@ Editor::apply_midi_note_edit_op (MidiOperator& op)
        rs.clear ();
 }
 
+void
+Editor::fork_region ()
+{
+       RegionSelection rs;
+
+       get_regions_for_action (rs);
+
+       if (rs.empty()) {
+               return;
+       }
+
+       begin_reversible_command (_("Fork Region(s)"));
+
+       track_canvas->get_window()->set_cursor (*wait_cursor);
+       gdk_flush ();
+
+       for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ) {
+               RegionSelection::iterator tmp = r;
+               ++tmp;
+
+               MidiRegionView* const mrv = dynamic_cast<MidiRegionView*>(*r);
+
+               if (mrv) {
+                       boost::shared_ptr<Playlist> playlist = mrv->region()->playlist();
+                        boost::shared_ptr<MidiRegion> newregion = mrv->midi_region()->clone ();
+                        
+                        playlist->clear_history ();
+                        cerr << "Replace region with " << newregion->name() << endl;
+                        playlist->replace_region (mrv->region(), newregion, mrv->region()->position());
+                        _session->add_command(new StatefulDiffCommand (playlist));
+               }
+
+               r = tmp;
+       }
+
+       commit_reversible_command ();
+       rs.clear ();
+
+       track_canvas->get_window()->set_cursor (*current_canvas_cursor);
+}
+
 void
 Editor::quantize_region ()
 {
@@ -4887,7 +4930,7 @@ Editor::toggle_region_lock ()
 }
 
 void
-Editor::set_region_lock_style (Region::PositionLockStyle ps)
+Editor::toggle_region_lock_style ()
 {
        RegionSelection rs = get_equivalent_regions (selection->regions, ARDOUR::Properties::edit.property_id);
 
@@ -4899,7 +4942,8 @@ Editor::set_region_lock_style (Region::PositionLockStyle ps)
 
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
                 (*i)->region()->clear_history ();
-               (*i)->region()->set_position_lock_style (ps);
+               Region::PositionLockStyle const ns = (*i)->region()->positional_lock_style() == Region::AudioTime ? Region::MusicTime : Region::AudioTime;
+               (*i)->region()->set_position_lock_style (ns);
                _session->add_command (new StatefulDiffCommand ((*i)->region()));
        }
 
@@ -4986,7 +5030,7 @@ Editor::set_fade_length (bool in)
 
        nframes64_t pos = get_preferred_edit_position();
        nframes64_t len;
-       char* cmd;
+       char const * cmd;
 
        if (pos > rv->region()->last_frame() || pos < rv->region()->first_frame()) {
                /* edit point is outside the relevant region */
@@ -5937,9 +5981,9 @@ Editor::tab_to_transient (bool forward)
                        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (*t);
 
                        if (rtv) {
-                               boost::shared_ptr<Diskstream> ds = rtv->get_diskstream();
-                               if (ds) {
-                                       boost::shared_ptr<Playlist> pl = rtv->get_diskstream()->playlist ();
+                               boost::shared_ptr<Track> tr = rtv->track();
+                               if (tr) {
+                                       boost::shared_ptr<Playlist> pl = tr->playlist ();
                                        if (pl) {
                                                nframes64_t result = pl->find_next_transient (pos, forward ? 1 : -1);
 
@@ -6021,7 +6065,7 @@ Editor::playhead_backward_to_grid ()
 }
 
 void
-Editor::set_track_height (uint32_t h)
+Editor::set_track_height (Height h)
 {
        TrackSelection& ts (selection->tracks);
 
@@ -6202,7 +6246,8 @@ Editor::do_insert_time ()
                return;
        }
 
-       InsertTimeOption opt;
+       /* only setting this to keep GCC quiet */
+       InsertTimeOption opt = LeaveIntersected;
 
        switch (intersected_combo.get_active_row_number ()) {
        case 0:
@@ -6329,7 +6374,7 @@ Editor::fit_tracks (TrackViewList & tracks)
        uint32_t h = (uint32_t) floor ((_canvas_height - child_heights - canvas_timebars_vsize) / tracks.size());
        double first_y_pos = DBL_MAX;
 
-       if (h < TimeAxisView::hSmall) {
+       if (h < TimeAxisView::preset_height (HeightSmall)) {
                MessageDialog msg (*this, _("There are too many tracks to fit in the current window"));
                /* too small to be displayed */
                return;
@@ -6361,7 +6406,7 @@ Editor::fit_tracks (TrackViewList & tracks)
                        first_y_pos = std::min ((*t)->y_position (), first_y_pos);
                } else {
                        if (prev_was_selected && next_is_selected) {
-                               hide_track_in_display (**t);
+                               hide_track_in_display (*t);
                        }
                }