X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_ops.cc;h=f974792d50d59503e1335764b519713c56fb0047;hb=41c892802f75e62e452399f0b1c7319fee61e677;hp=ec2435c67b9ff7be74201900e994d32f905c8dd2;hpb=7eba21ca19897c7e7c89d676527d774dd2d95721;p=ardour.git diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index ec2435c67b..f974792d50 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -15,23 +15,29 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ +/* Note: public Editor methods are documented in public_editor.h */ + #include #include #include #include #include +#include #include #include #include #include +#include #include #include +#include +#include + #include #include @@ -42,24 +48,33 @@ #include #include #include +#include #include #include +#include #include +#include +#include +#include #include "ardour_ui.h" #include "editor.h" #include "time_axis_view.h" +#include "route_time_axis.h" #include "audio_time_axis.h" #include "automation_time_axis.h" #include "streamview.h" +#include "audio_streamview.h" #include "audio_region_view.h" +#include "midi_region_view.h" #include "rgb_macros.h" #include "selection_templates.h" #include "selection.h" -#include "sfdb_ui.h" #include "editing.h" #include "gtk-custom-hruler.h" #include "gui_thread.h" +#include "keyboard.h" +#include "utils.h" #include "i18n.h" @@ -68,6 +83,7 @@ using namespace ARDOUR; using namespace PBD; using namespace sigc; using namespace Gtk; +using namespace Gtkmm2ext; using namespace Editing; /*********************************************************************** @@ -90,43 +106,81 @@ Editor::redo (uint32_t n) } } -int -Editor::ensure_cursor (nframes_t *pos) -{ - *pos = edit_cursor->current_frame; - return 0; -} - void Editor::split_region () { - split_region_at (edit_cursor->current_frame); + split_region_at (get_preferred_edit_position()); } void -Editor::split_region_at (nframes_t where) +Editor::split_region_at (nframes64_t where) { + RegionSelection rs; + + get_regions_for_action (rs); split_regions_at (where, selection->regions); } void -Editor::split_regions_at (nframes_t where, RegionSelection& regions) +Editor::split_regions_at (nframes64_t where, RegionSelection& regions) { + list > used_playlists; + + if (regions.empty()) { + return; + } + begin_reversible_command (_("split")); - snap_to (where); + // if splitting a single region, and snap-to is using + // region boundaries, don't pay attention to them + + if (regions.size() == 1) { + switch (snap_type) { + case SnapToRegionStart: + case SnapToRegionSync: + case SnapToRegionEnd: + break; + default: + snap_to (where); + } + } else { + snap_to (where); + } + + cerr << "Split " << regions.size() << " at " << where << endl; + for (RegionSelection::iterator a = regions.begin(); a != regions.end(); ) { RegionSelection::iterator tmp; + + /* XXX this test needs to be more complicated, to make sure we really + have something to split. + */ + if (!(*a)->region()->covers (where)) { + ++a; + continue; + } + tmp = a; ++tmp; - Playlist* pl = (*a)->region()->playlist(); + boost::shared_ptr pl = (*a)->region()->playlist(); + + if (! pl->frozen()) { + /* we haven't seen this playlist before */ + + /* remember used playlists so we can thaw them later */ + used_playlists.push_back(pl); + pl->freeze(); + } AudioRegionView* const arv = dynamic_cast(*a); - if (arv) + + if (arv) { _new_regionviews_show_envelope = arv->envelope_visible(); + } if (pl) { XMLNode &before = pl->get_state(); @@ -136,20 +190,27 @@ Editor::split_regions_at (nframes_t where, RegionSelection& regions) } a = tmp; - } + } + while (used_playlists.size() > 0) { + list >::iterator i = used_playlists.begin(); + (*i)->thaw(); + used_playlists.pop_front(); + } commit_reversible_command (); _new_regionviews_show_envelope = false; } + +/** Remove `clicked_regionview' */ void Editor::remove_clicked_region () { - if (clicked_audio_trackview == 0 || clicked_regionview == 0) { + if (clicked_routeview == 0 || clicked_regionview == 0) { return; } - Playlist* playlist = clicked_audio_trackview->playlist(); + boost::shared_ptr playlist = clicked_routeview->playlist(); begin_reversible_command (_("remove region")); XMLNode &before = playlist->get_state(); @@ -159,50 +220,53 @@ Editor::remove_clicked_region () commit_reversible_command (); } + +/** Remove the selected regions */ void -Editor::destroy_clicked_region () +Editor::remove_selected_regions () { - int32_t selected = selection->regions.size(); + RegionSelection rs; + get_regions_for_action (rs); + + if (!session) { + return; + } - if (!session || clicked_regionview == 0 && selected == 0) { + if (rs.empty()) { return; } - vector choices; - string prompt; - - prompt = string_compose (_(" This is destructive, will possibly delete audio files\n\ -It cannot be undone\n\ -Do you really want to destroy %1 ?"), - (selected > 1 ? - _("these regions") : _("this region"))); + begin_reversible_command (_("remove region")); - choices.push_back (_("No, do nothing.")); + list > regions_to_remove; - if (selected > 1) { - choices.push_back (_("Yes, destroy them.")); - } else { - choices.push_back (_("Yes, destroy it.")); - } + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + // we can't just remove the region(s) in this loop because + // this removes them from the RegionSelection, and they thus + // disappear from underneath the iterator, and the ++i above + // SEGVs in a puzzling fashion. - Gtkmm2ext::Choice prompter (prompt, choices); - - if (prompter.run() == 0) { /* first choice */ - return; + // so, first iterate over the regions to be removed from rs and + // add them to the regions_to_remove list, and then + // iterate over the list to actually remove them. + + regions_to_remove.push_back ((*i)->region()); } + + for (list >::iterator rl = regions_to_remove.begin(); rl != regions_to_remove.end(); ++rl) { + boost::shared_ptr playlist = (*rl)->playlist(); + if (!playlist) { + // is this check necessary? + continue; + } - if (selected > 0) { - list > r; - - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - r.push_back ((*i)->region()); - } - - session->destroy_regions (r); + XMLNode &before = playlist->get_state(); + playlist->remove_region (*rl); + XMLNode &after = playlist->get_state(); + session->add_command(new MementoCommand(*playlist, &before, &after)); + } - } else if (clicked_regionview) { - session->destroy_region (clicked_regionview->region()); - } + commit_reversible_command (); } boost::shared_ptr @@ -210,7 +274,7 @@ Editor::select_region_for_operation (int dir, TimeAxisView **tv) { RegionView* rv; boost::shared_ptr region; - nframes_t start = 0; + nframes64_t start = 0; if (selection->time.start () == selection->time.end_frame ()) { @@ -235,7 +299,7 @@ Editor::select_region_for_operation (int dir, TimeAxisView **tv) RouteTimeAxisView* rtv; if ((rtv = dynamic_cast (*tv)) != 0) { - Playlist *pl; + boost::shared_ptr pl; if ((pl = rtv->playlist()) == 0) { return region; @@ -253,7 +317,7 @@ Editor::extend_selection_to_end_of_region (bool next) { TimeAxisView *tv; boost::shared_ptr region; - nframes_t start; + nframes64_t start; if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) { return; @@ -281,7 +345,7 @@ Editor::extend_selection_to_start_of_region (bool previous) { TimeAxisView *tv; boost::shared_ptr region; - nframes_t end; + nframes64_t end; if ((region = select_region_for_operation (previous ? -1 : 0, &tv)) == 0) { return; @@ -304,20 +368,45 @@ Editor::extend_selection_to_start_of_region (bool previous) commit_reversible_command (); } +bool +Editor::nudge_forward_release (GdkEventButton* ev) +{ + if (ev->state & Keyboard::PrimaryModifier) { + nudge_forward (false, true); + } else { + nudge_forward (false, false); + } + return false; +} + +bool +Editor::nudge_backward_release (GdkEventButton* ev) +{ + if (ev->state & Keyboard::PrimaryModifier) { + nudge_backward (false, true); + } else { + nudge_backward (false, false); + } + return false; +} + void -Editor::nudge_forward (bool next) +Editor::nudge_forward (bool next, bool force_playhead) { - nframes_t distance; - nframes_t next_distance; + nframes64_t distance; + nframes64_t next_distance; + RegionSelection rs; + + get_regions_for_action (rs); if (!session) return; - if (!selection->regions.empty()) { + if (!force_playhead && !rs.empty()) { - begin_reversible_command (_("nudge forward")); + begin_reversible_command (_("nudge regions forward")); - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { boost::shared_ptr r ((*i)->region()); distance = get_nudge_distance (r->position(), next_distance); @@ -334,6 +423,49 @@ Editor::nudge_forward (bool next) commit_reversible_command (); + + } else if (!force_playhead && !selection->markers.empty()) { + + bool is_start; + + begin_reversible_command (_("nudge location forward")); + + for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) { + + Location* loc = find_location_from_marker ((*i), is_start); + + if (loc) { + + XMLNode& before (loc->get_state()); + + if (is_start) { + distance = get_nudge_distance (loc->start(), next_distance); + if (next) { + distance = next_distance; + } + if (max_frames - distance > loc->start() + loc->length()) { + loc->set_start (loc->start() + distance); + } else { + loc->set_start (max_frames - loc->length()); + } + } else { + distance = get_nudge_distance (loc->end(), next_distance); + if (next) { + distance = next_distance; + } + if (max_frames - distance > loc->end()) { + loc->set_end (loc->end() + distance); + } else { + loc->set_end (max_frames); + } + } + XMLNode& after (loc->get_state()); + session->add_command (new MementoCommand(*loc, &before, &after)); + } + } + + commit_reversible_command (); + } else { distance = get_nudge_distance (playhead_cursor->current_frame, next_distance); session->request_locate (playhead_cursor->current_frame + distance); @@ -341,18 +473,21 @@ Editor::nudge_forward (bool next) } void -Editor::nudge_backward (bool next) +Editor::nudge_backward (bool next, bool force_playhead) { - nframes_t distance; - nframes_t next_distance; + nframes64_t distance; + nframes64_t next_distance; + RegionSelection rs; + + get_regions_for_action (rs); if (!session) return; - if (!selection->regions.empty()) { + if (!force_playhead && !rs.empty()) { - begin_reversible_command (_("nudge forward")); + begin_reversible_command (_("nudge regions backward")); - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { boost::shared_ptr r ((*i)->region()); distance = get_nudge_distance (r->position(), next_distance); @@ -374,6 +509,51 @@ Editor::nudge_backward (bool next) commit_reversible_command (); + } else if (!force_playhead && !selection->markers.empty()) { + + bool is_start; + + begin_reversible_command (_("nudge location forward")); + + for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) { + + Location* loc = find_location_from_marker ((*i), is_start); + + if (loc) { + + XMLNode& before (loc->get_state()); + + if (is_start) { + distance = get_nudge_distance (loc->start(), next_distance); + if (next) { + distance = next_distance; + } + if (distance < loc->start()) { + loc->set_start (loc->start() - distance); + } else { + loc->set_start (0); + } + } else { + distance = get_nudge_distance (loc->end(), next_distance); + + if (next) { + distance = next_distance; + } + + if (distance < loc->end() - loc->length()) { + loc->set_end (loc->end() - distance); + } else { + loc->set_end (loc->length()); + } + } + + XMLNode& after (loc->get_state()); + session->add_command (new MementoCommand(*loc, &before, &after)); + } + } + + commit_reversible_command (); + } else { distance = get_nudge_distance (playhead_cursor->current_frame, next_distance); @@ -389,17 +569,20 @@ Editor::nudge_backward (bool next) void Editor::nudge_forward_capture_offset () { - nframes_t distance; + nframes64_t distance; + RegionSelection rs; + + get_regions_for_action (rs); if (!session) return; - if (!selection->regions.empty()) { + if (!rs.empty()) { begin_reversible_command (_("nudge forward")); distance = session->worst_output_latency(); - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { boost::shared_ptr r ((*i)->region()); XMLNode &before = r->playlist()->get_state(); @@ -416,17 +599,20 @@ Editor::nudge_forward_capture_offset () void Editor::nudge_backward_capture_offset () { - nframes_t distance; + nframes64_t distance; + RegionSelection rs; + + get_regions_for_action (rs); if (!session) return; - if (!selection->regions.empty()) { + if (!rs.empty()) { begin_reversible_command (_("nudge forward")); distance = session->worst_output_latency(); - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { boost::shared_ptr r ((*i)->region()); XMLNode &before = r->playlist()->get_state(); @@ -462,10 +648,11 @@ Editor::move_to_end () void Editor::build_region_boundary_cache () { - nframes_t pos = 0; - RegionPoint point; + nframes64_t pos = 0; + vector interesting_points; boost::shared_ptr r; TrackViewList tracks; + bool at_end = false; region_boundary_cache.clear (); @@ -475,16 +662,17 @@ Editor::build_region_boundary_cache () switch (snap_type) { case SnapToRegionStart: - point = Start; + interesting_points.push_back (Start); break; case SnapToRegionEnd: - point = End; + interesting_points.push_back (End); break; case SnapToRegionSync: - point = SyncPoint; + interesting_points.push_back (SyncPoint); break; case SnapToRegionBoundary: - point = Start; + interesting_points.push_back (Start); + interesting_points.push_back (End); break; default: fatal << string_compose (_("build_region_boundary_cache called with snap_type = %1"), snap_type) << endmsg; @@ -493,94 +681,107 @@ Editor::build_region_boundary_cache () } TimeAxisView *ontrack = 0; + TrackViewList tlist; - while (pos < session->current_end_frame()) { + if (!selection->tracks.empty()) { + tlist = selection->tracks; + } else { + tlist = track_views; + } - if (!selection->tracks.empty()) { + while (pos < session->current_end_frame() && !at_end) { - if ((r = find_next_region (pos, point, 1, selection->tracks, &ontrack)) == 0) { - break; - } + nframes64_t rpos; + nframes64_t lpos = max_frames; - } else if (clicked_trackview) { + for (vector::iterator p = interesting_points.begin(); p != interesting_points.end(); ++p) { - TrackViewList t; - t.push_back (clicked_trackview); + if ((r = find_next_region (pos, *p, 1, tlist, &ontrack)) == 0) { + if (*p == interesting_points.back()) { + at_end = true; + } + /* move to next point type */ + continue; + } - if ((r = find_next_region (pos, point, 1, t, &ontrack)) == 0) { + switch (*p) { + case Start: + rpos = r->first_frame(); break; - } - } else { + case End: + rpos = r->last_frame(); + break; + + case SyncPoint: + rpos = r->adjust_to_sync (r->first_frame()); + break; - if ((r = find_next_region (pos, point, 1, track_views, &ontrack)) == 0) { + default: break; } - } + + float speed = 1.0f; + RouteTimeAxisView *rtav; + + if (ontrack != 0 && (rtav = dynamic_cast(ontrack)) != 0 ) { + if (rtav->get_diskstream() != 0) { + speed = rtav->get_diskstream()->speed(); + } + } + + rpos = track_frame_to_session_frame (rpos, speed); - nframes_t rpos; - - switch (snap_type) { - case SnapToRegionStart: - rpos = r->first_frame(); - break; - case SnapToRegionEnd: - rpos = r->last_frame(); - break; - case SnapToRegionSync: - rpos = r->adjust_to_sync (r->first_frame()); - break; + if (rpos < lpos) { + lpos = rpos; + } - case SnapToRegionBoundary: - rpos = r->last_frame(); - break; - default: - break; - } - - float speed = 1.0f; - AudioTimeAxisView *atav; + /* prevent duplicates, but we don't use set<> because we want to be able + to sort later. + */ - if ( ontrack != 0 && (atav = dynamic_cast(ontrack)) != 0 ) { - if (atav->get_diskstream() != 0) { - speed = atav->get_diskstream()->speed(); + vector::iterator ri; + + for (ri = region_boundary_cache.begin(); ri != region_boundary_cache.end(); ++ri) { + if (*ri == rpos) { + break; + } } - } - - rpos = track_frame_to_session_frame(rpos, speed); - if (region_boundary_cache.empty() || rpos != region_boundary_cache.back()) { - if (snap_type == SnapToRegionBoundary) { - region_boundary_cache.push_back (r->first_frame()); + if (ri == region_boundary_cache.end()) { + region_boundary_cache.push_back (rpos); } - region_boundary_cache.push_back (rpos); } - pos = rpos + 1; + pos = lpos + 1; } + + /* finally sort to be sure that the order is correct */ + + sort (region_boundary_cache.begin(), region_boundary_cache.end()); } boost::shared_ptr -Editor::find_next_region (nframes_t frame, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack) +Editor::find_next_region (nframes64_t frame, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack) { TrackViewList::iterator i; - nframes_t closest = max_frames; + nframes64_t closest = max_frames; boost::shared_ptr ret; - nframes_t rpos = 0; + nframes64_t rpos = 0; float track_speed; - nframes_t track_frame; - AudioTimeAxisView *atav; + nframes64_t track_frame; + RouteTimeAxisView *rtav; for (i = tracks.begin(); i != tracks.end(); ++i) { - nframes_t distance; + nframes64_t distance; boost::shared_ptr r; track_speed = 1.0f; - if ( (atav = dynamic_cast(*i)) != 0 ) { - if (atav->get_diskstream()!=0) - track_speed = atav->get_diskstream()->speed(); + if ( (rtav = dynamic_cast(*i)) != 0 ) { + if (rtav->get_diskstream()!=0) + track_speed = rtav->get_diskstream()->speed(); } track_frame = session_frame_to_track_frame(frame, track_speed); @@ -602,6 +803,7 @@ Editor::find_next_region (nframes_t frame, RegionPoint point, int32_t dir, Track rpos = r->adjust_to_sync (r->first_frame()); break; } + // rpos is a "track frame", converting it to "session frame" rpos = track_frame_to_session_frame(rpos, track_speed); @@ -622,11 +824,90 @@ Editor::find_next_region (nframes_t frame, RegionPoint point, int32_t dir, Track return ret; } +nframes64_t +Editor::find_next_region_boundary (nframes64_t pos, int32_t dir, const TrackViewList& tracks) +{ + nframes64_t distance = max_frames; + nframes64_t current_nearest = -1; + + for (TrackViewList::const_iterator i = tracks.begin(); i != tracks.end(); ++i) { + nframes64_t contender; + nframes64_t d; + + RouteTimeAxisView* rtv = dynamic_cast (*i); + + if (!rtv) { + continue; + } + + if ((contender = rtv->find_next_region_boundary (pos, dir)) < 0) { + continue; + } + + d = ::llabs (pos - contender); + + if (d < distance) { + current_nearest = contender; + distance = d; + } + } + + return current_nearest; +} + +void +Editor::cursor_to_region_boundary (Cursor* cursor, int32_t dir) +{ + nframes64_t pos = cursor->current_frame; + nframes64_t target; + + if (!session) { + return; + } + + // so we don't find the current region again.. + if (dir > 0 || pos > 0) { + pos += dir; + } + + if (!selection->tracks.empty()) { + + target = find_next_region_boundary (pos, dir, selection->tracks); + + } else { + + target = find_next_region_boundary (pos, dir, track_views); + } + + if (target < 0) { + return; + } + + + if (cursor == playhead_cursor) { + session->request_locate (target); + } else { + cursor->set_position (target); + } +} + +void +Editor::cursor_to_next_region_boundary (Cursor* cursor) +{ + cursor_to_region_boundary (cursor, 1); +} + +void +Editor::cursor_to_previous_region_boundary (Cursor* cursor) +{ + cursor_to_region_boundary (cursor, -1); +} + void Editor::cursor_to_region_point (Cursor* cursor, RegionPoint point, int32_t dir) { boost::shared_ptr r; - nframes_t pos = cursor->current_frame; + nframes64_t pos = cursor->current_frame; if (!session) { return; @@ -642,10 +923,10 @@ Editor::cursor_to_region_point (Cursor* cursor, RegionPoint point, int32_t dir) r = find_next_region (pos, point, dir, selection->tracks, &ontrack); - } else if (clicked_trackview) { + } else if (clicked_axisview) { TrackViewList t; - t.push_back (clicked_trackview); + t.push_back (clicked_axisview); r = find_next_region (pos, point, dir, t, &ontrack); @@ -673,11 +954,11 @@ Editor::cursor_to_region_point (Cursor* cursor, RegionPoint point, int32_t dir) } float speed = 1.0f; - AudioTimeAxisView *atav; + RouteTimeAxisView *rtav; - if ( ontrack != 0 && (atav = dynamic_cast(ontrack)) != 0 ) { - if (atav->get_diskstream() != 0) { - speed = atav->get_diskstream()->speed(); + if ( ontrack != 0 && (rtav = dynamic_cast(ontrack)) != 0 ) { + if (rtav->get_diskstream() != 0) { + speed = rtav->get_diskstream()->speed(); } } @@ -705,11 +986,15 @@ Editor::cursor_to_previous_region_point (Cursor* cursor, RegionPoint point) void Editor::cursor_to_selection_start (Cursor *cursor) { - nframes_t pos = 0; + nframes64_t pos = 0; + RegionSelection rs; + + get_regions_for_action (rs); + switch (mouse_mode) { case MouseObject: - if (!selection->regions.empty()) { - pos = selection->regions.start(); + if (!rs.empty()) { + pos = rs.start(); } break; @@ -733,12 +1018,15 @@ Editor::cursor_to_selection_start (Cursor *cursor) void Editor::cursor_to_selection_end (Cursor *cursor) { - nframes_t pos = 0; + nframes64_t pos = 0; + RegionSelection rs; + + get_regions_for_action (rs); switch (mouse_mode) { case MouseObject: - if (!selection->regions.empty()) { - pos = selection->regions.end_frame(); + if (!rs.empty()) { + pos = rs.end_frame(); } break; @@ -760,54 +1048,303 @@ Editor::cursor_to_selection_end (Cursor *cursor) } void -Editor::playhead_backward () +Editor::selected_marker_to_region_boundary (int32_t dir) { - nframes_t pos; - nframes_t cnt; - float prefix; - bool was_floating; + nframes64_t target; + Location* loc; + bool ignored; - if (get_prefix (prefix, was_floating)) { - cnt = 1; - } else { - if (was_floating) { - cnt = (nframes_t) floor (prefix * session->frame_rate ()); - } else { - cnt = (nframes_t) prefix; + if (!session) { + return; + } + + if (selection->markers.empty()) { + nframes64_t mouse; + bool ignored; + + if (!mouse_frame (mouse, ignored)) { + return; } + + add_location_mark (mouse); } - pos = playhead_cursor->current_frame; + if ((loc = find_location_from_marker (selection->markers.front(), ignored)) == 0) { + return; + } - if ((nframes_t) pos < cnt) { - pos = 0; + nframes64_t pos = loc->start(); + + // so we don't find the current region again.. + if (dir > 0 || pos > 0) { + pos += dir; + } + + if (!selection->tracks.empty()) { + + target = find_next_region_boundary (pos, dir, selection->tracks); + } else { - pos -= cnt; + + target = find_next_region_boundary (pos, dir, track_views); } - /* XXX this is completely insane. with the current buffering - design, we'll force a complete track buffer flush and - reload, just to move 1 sample !!! - */ + if (target < 0) { + return; + } - session->request_locate (pos); + loc->move_to (target); } void -Editor::playhead_forward () +Editor::selected_marker_to_next_region_boundary () { - nframes_t pos; - nframes_t cnt; - bool was_floating; - float prefix; + selected_marker_to_region_boundary (1); +} + +void +Editor::selected_marker_to_previous_region_boundary () +{ + selected_marker_to_region_boundary (-1); +} + +void +Editor::selected_marker_to_region_point (RegionPoint point, int32_t dir) +{ + boost::shared_ptr r; + nframes64_t pos; + Location* loc; + bool ignored; + + if (!session || selection->markers.empty()) { + return; + } + + if ((loc = find_location_from_marker (selection->markers.front(), ignored)) == 0) { + return; + } + + TimeAxisView *ontrack = 0; + + pos = loc->start(); + + // so we don't find the current region again.. + if (dir>0 || pos>0) + pos+=dir; + + if (!selection->tracks.empty()) { + + r = find_next_region (pos, point, dir, selection->tracks, &ontrack); + + } else { + + r = find_next_region (pos, point, dir, track_views, &ontrack); + } + + if (r == 0) { + return; + } + + switch (point){ + case Start: + pos = r->first_frame (); + break; + + case End: + pos = r->last_frame (); + break; + + case SyncPoint: + pos = r->adjust_to_sync (r->first_frame()); + break; + } + + float speed = 1.0f; + AudioTimeAxisView *atav; + + if ( ontrack != 0 && (atav = dynamic_cast(ontrack)) != 0 ) { + if (atav->get_diskstream() != 0) { + speed = atav->get_diskstream()->speed(); + } + } + + pos = track_frame_to_session_frame(pos, speed); + + loc->move_to (pos); +} + +void +Editor::selected_marker_to_next_region_point (RegionPoint point) +{ + selected_marker_to_region_point (point, 1); +} + +void +Editor::selected_marker_to_previous_region_point (RegionPoint point) +{ + selected_marker_to_region_point (point, -1); +} + +void +Editor::selected_marker_to_selection_start () +{ + nframes64_t pos = 0; + Location* loc; + bool ignored; + + if (!session || selection->markers.empty()) { + return; + } + + if ((loc = find_location_from_marker (selection->markers.front(), ignored)) == 0) { + return; + } + + RegionSelection rs; + + get_regions_for_action (rs); + + switch (mouse_mode) { + case MouseObject: + if (!rs.empty()) { + pos = rs.start(); + } + break; + + case MouseRange: + if (!selection->time.empty()) { + pos = selection->time.start (); + } + break; + + default: + return; + } + + loc->move_to (pos); +} + +void +Editor::selected_marker_to_selection_end () +{ + nframes64_t pos = 0; + Location* loc; + bool ignored; + + if (!session || selection->markers.empty()) { + return; + } + + if ((loc = find_location_from_marker (selection->markers.front(), ignored)) == 0) { + return; + } + + RegionSelection rs; + + get_regions_for_action (rs); + + switch (mouse_mode) { + case MouseObject: + if (!rs.empty()) { + pos = rs.end_frame(); + } + break; + + case MouseRange: + if (!selection->time.empty()) { + pos = selection->time.end_frame (); + } + break; + + default: + return; + } + + loc->move_to (pos); +} + +void +Editor::scroll_playhead (bool forward) +{ + nframes64_t pos = playhead_cursor->current_frame; + nframes64_t delta = (nframes64_t) floor (current_page_frames() / 0.8); + + if (forward) { + if (pos == max_frames) { + return; + } + + if (pos < max_frames - delta) { + pos += delta ; + } else { + pos = max_frames; + } + + } else { + + if (pos == 0) { + return; + } + + if (pos > delta) { + pos -= delta; + } else { + pos = 0; + } + } + + session->request_locate (pos); +} + +void +Editor::playhead_backward () +{ + nframes64_t pos; + nframes64_t cnt; + float prefix; + bool was_floating; + + if (get_prefix (prefix, was_floating)) { + cnt = 1; + } else { + if (was_floating) { + cnt = (nframes64_t) floor (prefix * session->frame_rate ()); + } else { + cnt = (nframes64_t) prefix; + } + } + + pos = playhead_cursor->current_frame; + + if ((nframes64_t) pos < cnt) { + pos = 0; + } else { + pos -= cnt; + } + + /* XXX this is completely insane. with the current buffering + design, we'll force a complete track buffer flush and + reload, just to move 1 sample !!! + */ + + session->request_locate (pos); +} + +void +Editor::playhead_forward () +{ + nframes64_t pos; + nframes64_t cnt; + bool was_floating; + float prefix; if (get_prefix (prefix, was_floating)) { cnt = 1; } else { if (was_floating) { - cnt = (nframes_t) floor (prefix * session->frame_rate ()); + cnt = (nframes64_t) floor (prefix * session->frame_rate ()); } else { - cnt = (nframes_t) floor (prefix); + cnt = (nframes64_t) floor (prefix); } } @@ -824,20 +1361,41 @@ Editor::playhead_forward () void Editor::cursor_align (bool playhead_to_edit) { + if (!session) { + return; + } + if (playhead_to_edit) { - if (session) { - session->request_locate (edit_cursor->current_frame); + + if (selection->markers.empty()) { + return; } + + session->request_locate (selection->markers.front()->position(), session->transport_rolling()); + } else { - edit_cursor->set_position (playhead_cursor->current_frame); + /* move selected markers to playhead */ + + for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) { + bool ignored; + + Location* loc = find_location_from_marker (*i, ignored); + + if (loc->is_mark()) { + loc->set_start (playhead_cursor->current_frame); + } else { + loc->set (playhead_cursor->current_frame, + playhead_cursor->current_frame + loc->length()); + } + } } } void Editor::edit_cursor_backward () { - nframes_t pos; - nframes_t cnt; + nframes64_t pos; + nframes64_t cnt; float prefix; bool was_floating; @@ -845,28 +1403,30 @@ Editor::edit_cursor_backward () cnt = 1; } else { if (was_floating) { - cnt = (nframes_t) floor (prefix * session->frame_rate ()); + cnt = (nframes64_t) floor (prefix * session->frame_rate ()); } else { - cnt = (nframes_t) prefix; + cnt = (nframes64_t) prefix; } } - pos = edit_cursor->current_frame; + if ((pos = get_preferred_edit_position()) < 0) { + return; + } - if ((nframes_t) pos < cnt) { + if (pos < cnt) { pos = 0; } else { pos -= cnt; } - edit_cursor->set_position (pos); + // EDIT CURSOR edit_cursor->set_position (pos); } void Editor::edit_cursor_forward () { - nframes_t pos; - nframes_t cnt; + //nframes64_t pos; + nframes64_t cnt; bool was_floating; float prefix; @@ -874,14 +1434,14 @@ Editor::edit_cursor_forward () cnt = 1; } else { if (was_floating) { - cnt = (nframes_t) floor (prefix * session->frame_rate ()); + cnt = (nframes64_t) floor (prefix * session->frame_rate ()); } else { - cnt = (nframes_t) floor (prefix); + cnt = (nframes64_t) floor (prefix); } } - pos = edit_cursor->current_frame; - edit_cursor->set_position (pos+cnt); + // pos = edit_cursor->current_frame; + // EDIT CURSOR edit_cursor->set_position (pos+cnt); } void @@ -889,16 +1449,16 @@ Editor::goto_frame () { float prefix; bool was_floating; - nframes_t frame; + nframes64_t frame; if (get_prefix (prefix, was_floating)) { return; } if (was_floating) { - frame = (nframes_t) floor (prefix * session->frame_rate()); + frame = (nframes64_t) floor (prefix * session->frame_rate()); } else { - frame = (nframes_t) floor (prefix); + frame = (nframes64_t) floor (prefix); } session->request_locate (frame); @@ -907,19 +1467,19 @@ Editor::goto_frame () void Editor::scroll_backward (float pages) { - nframes_t frame; - nframes_t one_page = (nframes_t) rint (canvas_width * frames_per_unit); + nframes64_t frame; + nframes64_t one_page = (nframes64_t) rint (canvas_width * frames_per_unit); bool was_floating; float prefix; - nframes_t cnt; + nframes64_t cnt; if (get_prefix (prefix, was_floating)) { - cnt = (nframes_t) floor (pages * one_page); + cnt = (nframes64_t) floor (pages * one_page); } else { if (was_floating) { - cnt = (nframes_t) floor (prefix * session->frame_rate()); + cnt = (nframes64_t) floor (prefix * session->frame_rate()); } else { - cnt = (nframes_t) floor (prefix * one_page); + cnt = (nframes64_t) floor (prefix * one_page); } } @@ -929,25 +1489,25 @@ Editor::scroll_backward (float pages) frame = leftmost_frame - cnt; } - reposition_x_origin (frame); + reset_x_origin (frame); } void Editor::scroll_forward (float pages) { - nframes_t frame; - nframes_t one_page = (nframes_t) rint (canvas_width * frames_per_unit); + nframes64_t frame; + nframes64_t one_page = (nframes64_t) rint (canvas_width * frames_per_unit); bool was_floating; float prefix; - nframes_t cnt; + nframes64_t cnt; if (get_prefix (prefix, was_floating)) { - cnt = (nframes_t) floor (pages * one_page); + cnt = (nframes64_t) floor (pages * one_page); } else { if (was_floating) { - cnt = (nframes_t) floor (prefix * session->frame_rate()); + cnt = (nframes64_t) floor (prefix * session->frame_rate()); } else { - cnt = (nframes_t) floor (prefix * one_page); + cnt = (nframes64_t) floor (prefix * one_page); } } @@ -957,7 +1517,7 @@ Editor::scroll_forward (float pages) frame = leftmost_frame + cnt; } - reposition_x_origin (frame); + reset_x_origin (frame); } void @@ -1002,7 +1562,7 @@ Editor::scroll_tracks_down_line () { Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment(); - double vert_value = adj->get_value() + 20; + double vert_value = adj->get_value() + 60; if (vert_value>adj->get_upper() - canvas_height) { vert_value = adj->get_upper() - canvas_height; @@ -1014,7 +1574,7 @@ void Editor::scroll_tracks_up_line () { Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment(); - adj->set_value (adj->get_value() - 20); + adj->set_value (adj->get_value() - 60); } /* ZOOM */ @@ -1042,17 +1602,28 @@ Editor::temporal_zoom (gdouble fpu) { if (!session) return; - nframes_t current_page = current_page_frames(); - nframes_t current_leftmost = leftmost_frame; - nframes_t current_rightmost; - nframes_t current_center; - nframes_t new_page; - nframes_t leftmost_after_zoom = 0; + nframes64_t current_page = current_page_frames(); + nframes64_t current_leftmost = leftmost_frame; + nframes64_t current_rightmost; + nframes64_t current_center; + nframes64_t new_page_size; + nframes64_t half_page_size; + nframes64_t leftmost_after_zoom = 0; + nframes64_t where; + bool in_track_canvas; double nfpu; + double l; + + /* XXX this limit is also in ::set_frames_per_unit() */ + + if (frames_per_unit <= 2.0 && fpu <= frames_per_unit) { + return; + } nfpu = fpu; - new_page = (nframes_t) floor (canvas_width * nfpu); + new_page_size = (nframes64_t) floor (canvas_width * nfpu); + half_page_size = new_page_size / 2; switch (zoom_focus) { case ZoomFocusLeft: @@ -1061,37 +1632,85 @@ Editor::temporal_zoom (gdouble fpu) case ZoomFocusRight: current_rightmost = leftmost_frame + current_page; - if (current_rightmost > new_page) { - leftmost_after_zoom = current_rightmost - new_page; - } else { + if (current_rightmost < new_page_size) { leftmost_after_zoom = 0; + } else { + leftmost_after_zoom = current_rightmost - new_page_size; } break; case ZoomFocusCenter: current_center = current_leftmost + (current_page/2); - if (current_center > (new_page/2)) { - leftmost_after_zoom = current_center - (new_page / 2); - } else { + if (current_center < half_page_size) { leftmost_after_zoom = 0; + } else { + leftmost_after_zoom = current_center - half_page_size; } break; case ZoomFocusPlayhead: - /* try to keep the playhead in the center */ - if (playhead_cursor->current_frame > new_page/2) { - leftmost_after_zoom = playhead_cursor->current_frame - (new_page/2); - } else { + /* try to keep the playhead in the same place */ + + where = playhead_cursor->current_frame; + + l = - ((new_page_size * ((where - current_leftmost)/(double)current_page)) - where); + + if (l < 0) { leftmost_after_zoom = 0; + } else if (l > max_frames) { + leftmost_after_zoom = max_frames - new_page_size; + } else { + leftmost_after_zoom = (nframes64_t) l; + } + break; + + case ZoomFocusMouse: + /* try to keep the mouse over the same point in the display */ + + if (!mouse_frame (where, in_track_canvas)) { + /* use playhead instead */ + where = playhead_cursor->current_frame; + + if (where < half_page_size) { + leftmost_after_zoom = 0; + } else { + leftmost_after_zoom = where - half_page_size; + } + + } else { + + l = - ((new_page_size * ((where - current_leftmost)/(double)current_page)) - where); + + if (l < 0) { + leftmost_after_zoom = 0; + } else if (l > max_frames) { + leftmost_after_zoom = max_frames - new_page_size; + } else { + leftmost_after_zoom = (nframes64_t) l; + } } + break; case ZoomFocusEdit: - /* try to keep the edit cursor in the center */ - if (edit_cursor->current_frame > leftmost_frame + (new_page/2)) { - leftmost_after_zoom = edit_cursor->current_frame - (new_page/2); + /* try to keep the edit point in the same place */ + where = get_preferred_edit_position (); + + if (where > 0) { + + double l = - ((new_page_size * ((where - current_leftmost)/(double)current_page)) - where); + + if (l < 0) { + leftmost_after_zoom = 0; + } else if (l > max_frames) { + leftmost_after_zoom = max_frames - new_page_size; + } else { + leftmost_after_zoom = (nframes64_t) l; + } + } else { - leftmost_after_zoom = 0; + /* edit point not defined */ + return; } break; @@ -1099,459 +1718,323 @@ Editor::temporal_zoom (gdouble fpu) // leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame()); -// begin_reversible_command (_("zoom")); -// session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit)); -// session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu)); -// commit_reversible_command (); - reposition_and_zoom (leftmost_after_zoom, nfpu); } void -Editor::temporal_zoom_selection () +Editor::temporal_zoom_region (bool both_axes) { - if (!selection) return; - - if (selection->time.empty()) { + + nframes64_t start = max_frames; + nframes64_t end = 0; + RegionSelection rs; + set tracks; + double top_y_position = DBL_MAX; + + get_regions_for_action (rs); + + if (rs.empty()) { return; } - nframes_t start = selection->time[clicked_selection].start; - nframes_t end = selection->time[clicked_selection].end; + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { - temporal_zoom_by_frame (start, end, "zoom to selection"); -} + if ((*i)->region()->position() < start) { + start = (*i)->region()->position(); + } -void -Editor::temporal_zoom_session () -{ - ENSURE_GUI_THREAD (mem_fun (*this, &Editor::temporal_zoom_session)); + if ((*i)->region()->last_frame() + 1 > end) { + end = (*i)->region()->last_frame() + 1; + } - if (session) { - temporal_zoom_by_frame (session->current_start_frame(), session->current_end_frame(), "zoom to session"); + tracks.insert (&((*i)->get_time_axis_view())); + + if ((*i)->get_time_axis_view().y_position < top_y_position) { + top_y_position = (*i)->get_time_axis_view().y_position; + } } -} -void -Editor::temporal_zoom_by_frame (nframes_t start, nframes_t end, const string & op) -{ - if (!session) return; + /* now comes an "interesting" hack ... make sure we leave a little space + at each end of the editor so that the zoom doesn't fit the region + precisely to the screen. + */ + + GdkScreen* screen = gdk_screen_get_default (); + gint pixwidth = gdk_screen_get_width (screen); + gint mmwidth = gdk_screen_get_width_mm (screen); + double pix_per_mm = (double) pixwidth/ (double) mmwidth; + double one_centimeter_in_pixels = pix_per_mm * 10.0; if ((start == 0 && end == 0) || end < start) { return; } - nframes_t range = end - start; - + nframes64_t range = end - start; double new_fpu = (double)range / (double)canvas_width; -// double p2 = 1.0; - -// while (p2 < new_fpu) { -// p2 *= 2.0; -// } -// new_fpu = p2; - - nframes_t new_page = (nframes_t) floor (canvas_width * new_fpu); - nframes_t middle = (nframes_t) floor( (double)start + ((double)range / 2.0f )); - nframes_t new_leftmost = (nframes_t) floor( (double)middle - ((double)new_page/2.0f)); - - if (new_leftmost > middle) new_leftmost = 0; + nframes64_t extra_samples = (nframes64_t) floor (one_centimeter_in_pixels * new_fpu); -// begin_reversible_command (op); -// session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit)); -// session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu)); -// commit_reversible_command (); - - reposition_and_zoom (new_leftmost, new_fpu); -} + if (start > extra_samples) { + start -= extra_samples; + } else { + start = 0; + } -void -Editor::temporal_zoom_to_frame (bool coarser, nframes_t frame) -{ - if (!session) return; - - double range_before = frame - leftmost_frame; - double new_fpu; - - new_fpu = frames_per_unit; - - if (coarser) { - new_fpu *= 1.61803399; - range_before *= 1.61803399; - } else { - new_fpu = max(1.0,(new_fpu/1.61803399)); - range_before /= 1.61803399; + if (max_frames - extra_samples > end) { + end += extra_samples; + } else { + end = max_frames; } - if (new_fpu == frames_per_unit) return; - - nframes_t new_leftmost = frame - (nframes_t)range_before; + if (both_axes) { + /* save visual state with track states included, and prevent + set_frames_per_unit() from doing it again. + */ + undo_visual_stack.push_back (current_visual_state(true)); + no_save_visual = true; + } - if (new_leftmost > frame) new_leftmost = 0; + temporal_zoom_by_frame (start, end, "zoom to region"); -// begin_reversible_command (_("zoom to frame")); -// session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit)); -// session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu)); -// commit_reversible_command (); + if (both_axes) { + uint32_t per_track_height = (uint32_t) floor ((canvas_height - 10.0) / tracks.size()); + + /* set visible track heights appropriately */ + + for (set::iterator t = tracks.begin(); t != tracks.end(); ++t) { + (*t)->set_height (per_track_height); + } + + /* hide irrelevant tracks */ + + no_route_list_redisplay = true; - reposition_and_zoom (new_leftmost, new_fpu); -} + 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); + } + } -void -Editor::add_location_from_selection () -{ - if (selection->time.empty()) { - return; - } + no_route_list_redisplay = false; + redisplay_route_list (); - if (session == 0 || clicked_trackview == 0) { - return; + vertical_adjustment.set_value (std::max (top_y_position - 5.0, 0.0)); + no_save_visual = false; } - nframes_t start = selection->time[clicked_selection].start; - nframes_t end = selection->time[clicked_selection].end; - - Location *location = new Location (start, end, "selection"); - - session->begin_reversible_command (_("add marker")); - XMLNode &before = session->locations()->get_state(); - session->locations()->add (location, true); - XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), &before, &after)); - session->commit_reversible_command (); -} - -void -Editor::add_location_from_playhead_cursor () -{ - nframes_t where = session->audible_frame(); - - Location *location = new Location (where, where, "mark", Location::IsMark); - session->begin_reversible_command (_("add marker")); - XMLNode &before = session->locations()->get_state(); - session->locations()->add (location, true); - XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), &before, &after)); - session->commit_reversible_command (); + zoomed_to_region = true; + redo_visual_stack.push_back (current_visual_state()); } void -Editor::add_location_from_audio_region () +Editor::toggle_zoom_region (bool both_axes) { - if (selection->regions.empty()) { - return; + if (zoomed_to_region) { + swap_visual_state (); + } else { + temporal_zoom_region (both_axes); } - - RegionView* rv = *(selection->regions.begin()); - boost::shared_ptr region = rv->region(); - - Location *location = new Location (region->position(), region->last_frame(), region->name()); - session->begin_reversible_command (_("add marker")); - XMLNode &before = session->locations()->get_state(); - session->locations()->add (location, true); - XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), &before, &after)); - session->commit_reversible_command (); } void -Editor::select_all_in_track (Selection::Operation op) +Editor::temporal_zoom_selection () { - list touched; - - if (!clicked_trackview) { + if (!selection) return; + + if (selection->time.empty()) { return; } - - clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched); - switch (op) { - case Selection::Toggle: - selection->add (touched); - break; - case Selection::Set: - selection->set (touched); - break; - case Selection::Extend: - /* not defined yet */ - break; - } -} + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; -void -Editor::select_all (Selection::Operation op) -{ - list touched; - - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { - if ((*iter)->hidden()) { - continue; - } - (*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched); - } - begin_reversible_command (_("select all")); - switch (op) { - case Selection::Toggle: - selection->add (touched); - break; - case Selection::Set: - selection->set (touched); - break; - case Selection::Extend: - /* not defined yet */ - break; - } - commit_reversible_command (); + temporal_zoom_by_frame (start, end, "zoom to selection"); } void -Editor::invert_selection_in_track () +Editor::temporal_zoom_session () { - list touched; + ENSURE_GUI_THREAD (mem_fun (*this, &Editor::temporal_zoom_session)); - if (!clicked_trackview) { - return; + if (session) { + last_canvas_frame = ((session->current_end_frame() - session->current_start_frame()) + (current_page_frames() / 24)); + temporal_zoom_by_frame (session->current_start_frame(), session->current_end_frame(), "zoom to session"); } - - clicked_trackview->get_inverted_selectables (*selection, touched); - selection->set (touched); } void -Editor::invert_selection () +Editor::temporal_zoom_by_frame (nframes64_t start, nframes64_t end, const string & op) { - list touched; - - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { - if ((*iter)->hidden()) { - continue; - } - (*iter)->get_inverted_selectables (*selection, touched); + if (!session) return; + + if ((start == 0 && end == 0) || end < start) { + return; } - selection->set (touched); -} + nframes64_t range = end - start; -bool -Editor::select_all_within (nframes_t start, nframes_t end, double top, double bot, Selection::Operation op) -{ - list touched; + double new_fpu = (double)range / (double)canvas_width; - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { - if ((*iter)->hidden()) { - continue; - } - (*iter)->get_selectables (start, end, top, bot, touched); - } + nframes64_t new_page = (nframes64_t) floor (canvas_width * new_fpu); + nframes64_t middle = (nframes64_t) floor( (double)start + ((double)range / 2.0f )); + nframes64_t new_leftmost = (nframes64_t) floor( (double)middle - ((double)new_page/2.0f)); - cerr << "select all within found " << touched.size() << endl; - - begin_reversible_command (_("select all within")); - switch (op) { - case Selection::Toggle: - cerr << "toggle\n"; - selection->add (touched); - break; - case Selection::Set: - cerr << "set\n"; - selection->set (touched); - break; - case Selection::Extend: - cerr << "extend\n"; - /* not defined yet */ - break; + if (new_leftmost > middle) { + new_leftmost = 0; } - cerr << "selection now has " << selection->points.size() << endl; - - commit_reversible_command (); - return !touched.empty(); + reposition_and_zoom (new_leftmost, new_fpu); } -void -Editor::set_selection_from_audio_region () +void +Editor::temporal_zoom_to_frame (bool coarser, nframes64_t frame) { - if (selection->regions.empty()) { + if (!session) { return; } - - RegionView* rv = *(selection->regions.begin()); - boost::shared_ptr region = rv->region(); + double range_before = frame - leftmost_frame; + double new_fpu; - begin_reversible_command (_("set selection from region")); - selection->set (0, region->position(), region->last_frame()); - commit_reversible_command (); + new_fpu = frames_per_unit; + + if (coarser) { + new_fpu *= 1.61803399; + range_before *= 1.61803399; + } else { + new_fpu = max(1.0,(new_fpu/1.61803399)); + range_before /= 1.61803399; + } - set_mouse_mode (Editing::MouseRange, false); -} + if (new_fpu == frames_per_unit) { + return; + } -void -Editor::set_selection_from_punch() -{ - Location* location; + nframes64_t new_leftmost = frame - (nframes64_t)range_before; - if ((location = session->locations()->auto_punch_location()) == 0) { - return; + if (new_leftmost > frame) { + new_leftmost = 0; } +// begin_reversible_command (_("zoom to frame")); +// session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit)); +// session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu)); +// commit_reversible_command (); - set_selection_from_range (*location); + reposition_and_zoom (new_leftmost, new_fpu); } -void -Editor::set_selection_from_loop() -{ - Location* location; - if ((location = session->locations()->auto_loop_location()) == 0) { - return; +bool +Editor::choose_new_marker_name(string &name) { + + if (!Config->get_name_new_markers()) { + /* don't prompt user for a new name */ + return true; } - set_selection_from_range (*location); -} -void -Editor::set_selection_from_range (Location& loc) -{ - begin_reversible_command (_("set selection from range")); - selection->set (0, loc.start(), loc.end()); - commit_reversible_command (); + ArdourPrompter dialog (true); - set_mouse_mode (Editing::MouseRange, false); -} + dialog.set_prompt (_("New Name:")); -void -Editor::select_all_selectables_using_time_selection () -{ - list touched; + WindowTitle title(Glib::get_application_name()); + title += _("Name New Location Marker"); - if (selection->time.empty()) { - return; - } + dialog.set_title(title.get_string()); + + dialog.set_name ("MarkNameWindow"); + dialog.set_size_request (250, -1); + dialog.set_position (Gtk::WIN_POS_MOUSE); - nframes_t start = selection->time[clicked_selection].start; - nframes_t end = selection->time[clicked_selection].end; + dialog.add_button (Stock::OK, RESPONSE_ACCEPT); + dialog.set_initial_text (name); - if (end - start < 1) { - return; - } + dialog.show (); - for (TrackViewList::iterator iter = selection->tracks.begin(); iter != selection->tracks.end(); ++iter) { - if ((*iter)->hidden()) { - continue; - } - (*iter)->get_selectables (start, end - 1, 0, DBL_MAX, touched); + switch (dialog.run ()) { + case RESPONSE_ACCEPT: + break; + default: + return false; } + + dialog.get_result(name); + return true; - begin_reversible_command (_("select all from range")); - selection->set (touched); - commit_reversible_command (); } void -Editor::select_all_selectables_using_punch() +Editor::add_location_from_selection () { - Location* location = session->locations()->auto_punch_location(); - list touched; + string rangename; - if (location == 0 || (location->end() - location->start() <= 1)) { + if (selection->time.empty()) { return; } - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { - if ((*iter)->hidden()) { - continue; - } - (*iter)->get_selectables (location->start(), location->end() - 1, 0, DBL_MAX, touched); + if (session == 0 || clicked_axisview == 0) { + return; } - begin_reversible_command (_("select all from punch")); - selection->set (touched); - commit_reversible_command (); + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; + + session->locations()->next_available_name(rangename,"selection"); + Location *location = new Location (start, end, rangename, Location::IsRangeMarker); + + session->begin_reversible_command (_("add marker")); + XMLNode &before = session->locations()->get_state(); + session->locations()->add (location, true); + XMLNode &after = session->locations()->get_state(); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); + session->commit_reversible_command (); } void -Editor::select_all_selectables_using_loop() +Editor::add_location_mark (nframes64_t where) { - Location* location = session->locations()->auto_loop_location(); - list touched; + string markername; - if (location == 0 || (location->end() - location->start() <= 1)) { - return; - } + select_new_marker = true; - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { - if ((*iter)->hidden()) { - continue; - } - (*iter)->get_selectables (location->start(), location->end() - 1, 0, DBL_MAX, touched); + session->locations()->next_available_name(markername,"mark"); + if (!choose_new_marker_name(markername)) { + return; } - begin_reversible_command (_("select all from loop")); - selection->set (touched); - commit_reversible_command (); - + Location *location = new Location (where, where, markername, Location::IsMark); + session->begin_reversible_command (_("add marker")); + XMLNode &before = session->locations()->get_state(); + session->locations()->add (location, true); + XMLNode &after = session->locations()->get_state(); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); + session->commit_reversible_command (); } void -Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after) +Editor::add_location_from_playhead_cursor () { - nframes_t start; - nframes_t end; - list touched; - - if (after) { - begin_reversible_command (_("select all after cursor")); - start = cursor->current_frame ; - end = session->current_end_frame(); - } else { - if (cursor->current_frame > 0) { - begin_reversible_command (_("select all before cursor")); - start = 0; - end = cursor->current_frame - 1; - } else { - return; - } - } - - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { - if ((*iter)->hidden()) { - continue; - } - (*iter)->get_selectables (start, end, 0, DBL_MAX, touched); - } - selection->set (touched); - commit_reversible_command (); + add_location_mark (session->audible_frame()); } void -Editor::select_all_selectables_between_cursors (Cursor *cursor, Cursor *other_cursor) +Editor::add_location_from_audio_region () { - nframes_t start; - nframes_t end; - list touched; - bool other_cursor_is_first = cursor->current_frame > other_cursor->current_frame; + RegionSelection rs; + + get_regions_for_action (rs); - if (cursor->current_frame == other_cursor->current_frame) { + if (rs.empty()) { return; } - begin_reversible_command (_("select all between cursors")); - if (other_cursor_is_first) { - start = other_cursor->current_frame; - end = cursor->current_frame - 1; - - } else { - start = cursor->current_frame; - end = other_cursor->current_frame - 1; - } + RegionView* rv = *(rs.begin()); + boost::shared_ptr region = rv->region(); - for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) { - if ((*iter)->hidden()) { - continue; - } - (*iter)->get_selectables (start, end, 0, DBL_MAX, touched); - } - selection->set (touched); - commit_reversible_command (); + Location *location = new Location (region->position(), region->last_frame(), region->name(), Location::IsRangeMarker); + session->begin_reversible_command (_("add marker")); + XMLNode &before = session->locations()->get_state(); + session->locations()->add (location, true); + XMLNode &after = session->locations()->get_state(); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); + session->commit_reversible_command (); } void @@ -1644,21 +2127,26 @@ Editor::jump_backward_to_mark () void Editor::set_mark () { - nframes_t pos; + nframes64_t pos; float prefix; bool was_floating; + string markername; if (get_prefix (prefix, was_floating)) { pos = session->audible_frame (); } else { if (was_floating) { - pos = (nframes_t) floor (prefix * session->frame_rate ()); + pos = (nframes64_t) floor (prefix * session->frame_rate ()); } else { - pos = (nframes_t) floor (prefix); + pos = (nframes64_t) floor (prefix); } } - session->locations()->add (new Location (pos, 0, "mark", Location::IsMark), true); + session->locations()->next_available_name(markername,"mark"); + if (!choose_new_marker_name(markername)) { + return; + } + session->locations()->add (new Location (pos, 0, markername, Location::IsMark), true); } void @@ -1707,21 +2195,43 @@ Editor::clear_locations () session->locations()->clear (); } -/* INSERT/REPLACE */ +void +Editor::unhide_markers () +{ + for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) { + Location *l = (*i).first; + if (l->is_hidden() && l->is_mark()) { + l->set_hidden(false, this); + } + } +} void -Editor::insert_region_list_drag (boost::shared_ptr region, int x, int y) +Editor::unhide_ranges () +{ + for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) { + Location *l = (*i).first; + if (l->is_hidden() && l->is_range_marker()) { + l->set_hidden(false, this); + } + } +} + +/* INSERT/REPLACE */ + +void +Editor::insert_region_list_drag (boost::shared_ptr region, int x, int y) { double wx, wy; double cx, cy; TimeAxisView *tv; - nframes_t where; - AudioTimeAxisView *atv = 0; - Playlist *playlist; + nframes64_t where; + RouteTimeAxisView *rtv = 0; + boost::shared_ptr playlist; - track_canvas.window_to_world (x, y, wx, wy); - wx += horizontal_adjustment.get_value(); - wy += vertical_adjustment.get_value(); + 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; @@ -1739,11 +2249,11 @@ Editor::insert_region_list_drag (boost::shared_ptr region, int x, i return; } - if ((atv = dynamic_cast(tv)) == 0) { + if ((rtv = dynamic_cast(tv)) == 0) { return; } - if ((playlist = atv->playlist()) == 0) { + if ((playlist = rtv->playlist()) == 0) { return; } @@ -1756,18 +2266,64 @@ Editor::insert_region_list_drag (boost::shared_ptr region, int x, i commit_reversible_command (); } +void +Editor::insert_route_list_drag (boost::shared_ptr route, int x, int y) { + double wx, wy; + double cx, cy; + TimeAxisView *tv; + nframes_t where; + RouteTimeAxisView *dest_rtv = 0; + RouteTimeAxisView *source_rtv = 0; + + 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; + event.button.x = wx; + event.button.y = wy; + + where = event_frame (&event, &cx, &cy); + + if ((tv = trackview_by_y_position (cy)) == 0) { + return; + } + + if ((dest_rtv = dynamic_cast(tv)) == 0) { + return; + } + + /* use this drag source to add underlay to a track. But we really don't care + about the Route, only the view of the route, so find it first */ + for(TrackViewList::iterator it = track_views.begin(); it != track_views.end(); ++it) { + if((source_rtv = dynamic_cast(*it)) == 0) { + continue; + } + + if(source_rtv->route() == route && source_rtv != dest_rtv) { + dest_rtv->add_underlay(source_rtv->view()); + break; + } + } +} + void Editor::insert_region_list_selection (float times) { RouteTimeAxisView *tv = 0; - Playlist *playlist; + boost::shared_ptr playlist; - if (clicked_audio_trackview != 0) { - tv = clicked_audio_trackview; + if (clicked_routeview != 0) { + tv = clicked_routeview; } else if (!selection->tracks.empty()) { if ((tv = dynamic_cast(selection->tracks.front())) == 0) { return; } + } else if (entered_track != 0) { + if ((tv = dynamic_cast(entered_track)) == 0) { + return; + } } else { return; } @@ -1794,7 +2350,7 @@ Editor::insert_region_list_selection (float times) begin_reversible_command (_("insert region")); XMLNode &before = playlist->get_state(); - playlist->add_region ((RegionFactory::create (region)), edit_cursor->current_frame, times); + playlist->add_region ((RegionFactory::create (region)), get_preferred_edit_position(), times); session->add_command(new MementoCommand(*playlist, &before, &playlist->get_state())); commit_reversible_command (); } @@ -1817,6 +2373,30 @@ Editor::edit_envelope () /* PLAYBACK */ +void +Editor::transition_to_rolling (bool fwd) +{ + if (!session) { + return; + } + + switch (Config->get_slave_source()) { + case None: + case JACK: + break; + default: + /* transport controlled by the master */ + return; + } + + if (session->is_auditioning()) { + session->cancel_audition (); + return; + } + + session->request_transport_speed (fwd ? 1.0f : -1.0f); +} + void Editor::toggle_playback (bool with_abort) { @@ -1855,30 +2435,54 @@ Editor::play_from_start () } void -Editor::play_selection () +Editor::play_from_edit_point () { - if (selection->time.empty()) { + session->request_locate (get_preferred_edit_position(), true); +} + +void +Editor::play_from_edit_point_and_return () +{ + nframes64_t start_frame; + nframes64_t return_frame; + + start_frame = get_preferred_edit_position (true); + + if (session->transport_rolling()) { + session->request_locate (start_frame, false); return; } - session->request_play_range (true); + /* don't reset the return frame if its already set */ + + if ((return_frame = session->requested_return_frame()) < 0) { + return_frame = session->audible_frame(); + } + + if (start_frame >= 0) { + session->request_roll_at_and_return (start_frame, return_frame); + } } void -Editor::play_selected_region () +Editor::play_selection () { - if (!selection->regions.empty()) { - RegionView *rv = *(selection->regions.begin()); - - session->request_bounded_roll (rv->region()->position(), rv->region()->last_frame()); + if (selection->time.empty()) { + return; } + + session->request_play_range (true); } void Editor::loop_selected_region () { - if (!selection->regions.empty()) { - RegionView *rv = *(selection->regions.begin()); + RegionSelection rs; + + get_regions_for_action (rs); + + if (!rs.empty()) { + RegionView *rv = *(rs.begin()); Location* tll; if ((tll = transport_loop_location()) != 0) { @@ -1922,28 +2526,6 @@ Editor::loop_location (Location& location) } } -void -Editor::toggle_region_mute () -{ - if (clicked_regionview) { - clicked_regionview->region()->set_muted (!clicked_regionview->region()->muted()); - } else if (!selection->regions.empty()) { - bool yn = ! (*selection->regions.begin())->region()->muted(); - selection->foreach_region (&Region::set_muted, yn); - } -} - -void -Editor::toggle_region_opaque () -{ - if (clicked_regionview) { - clicked_regionview->region()->set_opaque (!clicked_regionview->region()->opaque()); - } else if (!selection->regions.empty()) { - bool yn = ! (*selection->regions.begin())->region()->opaque(); - selection->foreach_region (&Region::set_opaque, yn); - } -} - void Editor::raise_region () { @@ -1968,66 +2550,66 @@ Editor::lower_region_to_bottom () selection->foreach_region (&Region::lower_to_bottom); } +/** Show the region editor for the selected regions */ void Editor::edit_region () { - if (clicked_regionview == 0) { - return; - } - - clicked_regionview->show_region_editor (); + selection->foreach_regionview (&RegionView::show_region_editor); } void -Editor::rename_region () +Editor::rename_region() { - Dialog dialog; - Entry entry; - Button ok_button (_("OK")); - Button cancel_button (_("Cancel")); + RegionSelection rs; - if (selection->regions.empty()) { + get_regions_for_action (rs); + + if (rs.empty()) { return; } - dialog.set_title (_("ardour: rename region")); - dialog.set_name ("RegionRenameWindow"); - dialog.set_size_request (300, -1); - dialog.set_position (Gtk::WIN_POS_MOUSE); - dialog.set_modal (true); + WindowTitle title (Glib::get_application_name()); + title += _("Rename Region"); - dialog.get_vbox()->set_border_width (10); - dialog.get_vbox()->pack_start (entry); - dialog.get_action_area()->pack_start (ok_button); - dialog.get_action_area()->pack_start (cancel_button); + ArdourDialog d (*this, title.get_string(), true, false); + Entry entry; + Label label (_("New name:")); + HBox hbox; - entry.set_name ("RegionNameDisplay"); - ok_button.set_name ("EditorGTKButton"); - cancel_button.set_name ("EditorGTKButton"); + hbox.set_spacing (6); + hbox.pack_start (label, false, false); + hbox.pack_start (entry, true, true); - region_renamed = false; + d.get_vbox()->set_border_width (12); + d.get_vbox()->pack_start (hbox, false, false); - entry.signal_activate().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true)); - ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true)); - cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false)); + d.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); + d.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - /* recurse */ + d.set_size_request (300, -1); + d.set_position (Gtk::WIN_POS_MOUSE); - dialog.show_all (); - Main::run (); + entry.set_text (rs.front()->region()->name()); + entry.select_region (0, -1); - if (region_renamed) { - (*selection->regions.begin())->region()->set_name (entry.get_text()); - redisplay_regions (); - } -} + entry.signal_activate().connect (bind (mem_fun (d, &Dialog::response), RESPONSE_OK)); + + d.show_all (); + + entry.grab_focus(); -void -Editor::rename_region_finished (bool status) + int ret = d.run(); -{ - region_renamed = status; - Main::quit (); + d.hide (); + + if (ret == RESPONSE_OK) { + std::string str = entry.get_text(); + strip_whitespace_edges (str); + if (!str.empty()) { + rs.front()->region()->set_name (str); + redisplay_regions (); + } + } } void @@ -2049,13 +2631,41 @@ Editor::audition_playlist_region_via_route (boost::shared_ptr region, Ro /* XXX how to unset the solo state ? */ } +/** Start an audition of the first selected region */ void -Editor::audition_selected_region () +Editor::play_edit_range () { - if (!selection->regions.empty()) { - RegionView* rv = *(selection->regions.begin()); - session->audition_region (rv->region()); + nframes64_t start, end; + + if (get_edit_op_range (start, end)) { + session->request_bounded_roll (start, end); + } +} + +void +Editor::play_selected_region () +{ + nframes64_t start = max_frames; + nframes64_t end = 0; + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + if ((*i)->region()->position() < start) { + start = (*i)->region()->position(); + } + if ((*i)->region()->last_frame() + 1 > end) { + end = (*i)->region()->last_frame() + 1; + } } + + session->request_stop (); + session->request_bounded_roll (start, end); } void @@ -2071,6 +2681,11 @@ Editor::build_interthread_progress_window () interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT); + interthread_progress_window->set_border_width (12); + interthread_progress_window->get_vbox()->set_spacing (6); + + interthread_progress_label.set_alignment (0.5, 0.5); + interthread_progress_window->get_vbox()->pack_start (interthread_progress_label, false, false); interthread_progress_window->get_vbox()->pack_start (interthread_progress_bar,false, false); @@ -2095,7 +2710,7 @@ Editor::interthread_cancel_clicked () void Editor::region_from_selection () { - if (clicked_trackview == 0) { + if (clicked_axisview == 0) { return; } @@ -2103,17 +2718,17 @@ Editor::region_from_selection () return; } - nframes_t start = selection->time[clicked_selection].start; - nframes_t end = selection->time[clicked_selection].end; + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; - nframes_t selection_cnt = end - start + 1; + nframes64_t selection_cnt = end - start + 1; for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { boost::shared_ptr current; boost::shared_ptr current_r; - Playlist *pl; + boost::shared_ptr pl; - nframes_t internal_start; + nframes64_t internal_start; string new_name; if ((pl = (*i)->playlist()) == 0) { @@ -2125,7 +2740,7 @@ Editor::region_from_selection () } current = boost::dynamic_pointer_cast (current_r); - // FIXME: audio only + assert(current); // FIXME if (current != 0) { internal_start = start - current->position(); session->region_name (new_name, current->name(), true); @@ -2135,21 +2750,23 @@ Editor::region_from_selection () } void -Editor::create_region_from_selection (vector >& new_regions) +Editor::create_region_from_selection (vector >& new_regions) { if (selection->time.empty() || selection->tracks.empty()) { return; } - nframes_t start = selection->time[clicked_selection].start; - nframes_t end = selection->time[clicked_selection].end; + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; + sort_track_selection (); + for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { boost::shared_ptr current; boost::shared_ptr current_r; - Playlist* playlist; - nframes_t internal_start; + boost::shared_ptr playlist; + nframes64_t internal_start; string new_name; if ((playlist = (*i)->playlist()) == 0) { @@ -2174,17 +2791,26 @@ Editor::create_region_from_selection (vector >& n void Editor::split_multichannel_region () { - vector v; + RegionSelection rs; - AudioRegionView* clicked_arv = dynamic_cast(clicked_regionview); - - if (!clicked_arv || clicked_arv->audio_region()->n_channels() < 2) { + get_regions_for_action (rs); + + if (rs.empty()) { return; } - clicked_arv->audio_region()->separate_by_channel (*session, v); + vector > v; + + for (list::iterator x = rs.begin(); x != rs.end(); ++x) { + + AudioRegionView* arv = dynamic_cast(*x); + + if (!arv || arv->audio_region()->n_channels() < 2) { + continue; + } - /* nothing else to do, really */ + (arv)->audio_region()->separate_by_channel (*session, v); + } } void @@ -2194,221 +2820,326 @@ Editor::new_region_from_selection () cancel_selection (); } -void -Editor::separate_region_from_selection () +static void +add_if_covered (RegionView* rv, const AudioRange* ar, RegionSelection* rs) { - bool doing_undo = false; - - if (selection->time.empty()) { - return; + switch (rv->region()->coverage (ar->start, ar->end - 1)) { + case OverlapNone: + break; + default: + rs->push_back (rv); } +} - Playlist *playlist; - - for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { - - AudioTimeAxisView* atv; +void +Editor::separate_regions_between (const TimeSelection& ts) +{ + bool in_command = false; + boost::shared_ptr playlist; + RegionSelection new_selection; + TrackSelection tmptracks; - if ((atv = dynamic_cast ((*i))) != 0) { + if (selection->tracks.empty()) { + + /* use tracks with selected regions */ - if (atv->is_audio_track()) { - - if ((playlist = atv->playlist()) != 0) { - if (!doing_undo) { - begin_reversible_command (_("separate")); - doing_undo = true; - } - XMLNode *before; - if (doing_undo) - before = &(playlist->get_state()); - - /* XXX need to consider musical time selections here at some point */ + RegionSelection rs; - double speed = atv->get_diskstream()->speed(); + get_regions_for_action (rs); - for (list::iterator t = selection->time.begin(); t != selection->time.end(); ++t) { - playlist->partition ((nframes_t)((*t).start * speed), (nframes_t)((*t).end * speed), true); - } + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + TimeAxisView* tv = &(*i)->get_time_axis_view(); - if (doing_undo) - session->add_command(new MementoCommand(*playlist, before, &playlist->get_state())); - } + if (find (tmptracks.begin(), tmptracks.end(), tv) == tmptracks.end()) { + tmptracks.push_back (tv); } } - } - if (doing_undo) commit_reversible_command (); -} + if (tmptracks.empty()) { + /* no regions selected: do nothing */ + return; + } -void -Editor::separate_regions_using_location (Location& loc) -{ - bool doing_undo = false; + } else { + + tmptracks = selection->tracks; - if (loc.is_mark()) { - return; } - Playlist *playlist; + sort_track_selection (&tmptracks); - /* XXX i'm unsure as to whether this should operate on selected tracks only - or the entire enchillada. uncomment the below line to correct the behaviour - (currently set for all tracks) - */ - for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { - //for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { - AudioTimeAxisView* atv; - if ((atv = dynamic_cast ((*i))) != 0) { + for (TrackSelection::iterator i = tmptracks.begin(); i != tmptracks.end(); ++i) { - if (atv->is_audio_track()) { - - if ((playlist = atv->playlist()) != 0) { - XMLNode *before; - if (!doing_undo) { - begin_reversible_command (_("separate")); - doing_undo = true; - } - if (doing_undo) - before = &(playlist->get_state()); - - - /* XXX need to consider musical time selections here at some point */ + RouteTimeAxisView* rtv; + + if ((rtv = dynamic_cast ((*i))) != 0) { - double speed = atv->get_diskstream()->speed(); + if (rtv->is_track()) { + /* no edits to destructive tracks */ - playlist->partition ((nframes_t)(loc.start() * speed), (nframes_t)(loc.end() * speed), true); - if (doing_undo) - session->add_command(new MementoCommand(*playlist, before, &playlist->get_state())); + if (rtv->track()->diskstream()->destructive()) { + continue; } - } - } - } + + if ((playlist = rtv->playlist()) != 0) { - if (doing_undo) commit_reversible_command (); -} + XMLNode *before; + bool got_some; -void -Editor::crop_region_to_selection () -{ - if (selection->time.empty()) { - return; - } + before = &(playlist->get_state()); + got_some = false; - vector playlists; - Playlist *playlist; + /* XXX need to consider musical time selections here at some point */ - if (clicked_trackview != 0) { + double speed = rtv->get_diskstream()->speed(); - if ((playlist = clicked_trackview->playlist()) == 0) { - return; - } - playlists.push_back (playlist); + for (list::const_iterator t = ts.begin(); t != ts.end(); ++t) { - } else { - - for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { + sigc::connection c = rtv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); + latest_regionviews.clear (); - AudioTimeAxisView* atv; + playlist->partition ((nframes64_t)((*t).start * speed), (nframes64_t)((*t).end * speed), true); - if ((atv = dynamic_cast ((*i))) != 0) { + c.disconnect (); - if (atv->is_audio_track()) { - - if ((playlist = atv->playlist()) != 0) { - playlists.push_back (playlist); + if (!latest_regionviews.empty()) { + + got_some = true; + + rtv->view()->foreach_regionview (bind (sigc::ptr_fun (add_if_covered), &(*t), &new_selection)); + + if (!in_command) { + begin_reversible_command (_("separate")); + in_command = true; + } + + session->add_command(new MementoCommand(*playlist, before, &playlist->get_state())); + + } + } + + if (!got_some) { + delete before; } } } } } - if (!playlists.empty()) { + if (in_command) { + selection->set (new_selection); + set_mouse_mode (MouseObject); + + commit_reversible_command (); + } +} + +void +Editor::separate_region_from_selection () +{ + /* preferentially use *all* ranges in the time selection if we're in range mode + to allow discontiguous operation, since get_edit_op_range() currently + returns a single range. + */ - nframes_t start; - nframes_t end; - nframes_t cnt; + if (mouse_mode == MouseRange && !selection->time.empty()) { - begin_reversible_command (_("trim to selection")); + separate_regions_between (selection->time); - for (vector::iterator i = playlists.begin(); i != playlists.end(); ++i) { - - boost::shared_ptr region; - - start = selection->time.start(); + } else { - if ((region = (*i)->top_region_at(start)) == 0) { - continue; - } - - /* now adjust lengths to that we do the right thing - if the selection extends beyond the region - */ + nframes64_t start; + nframes64_t end; + + if (get_edit_op_range (start, end)) { - start = max (start, region->position()); - end = min (selection->time.end_frame(), start + region->length() - 1); - cnt = end - start + 1; + AudioRange ar (start, end, 1); + TimeSelection ts; + ts.push_back (ar); - XMLNode &before = (*i)->get_state(); - region->trim_to (start, cnt, this); - XMLNode &after = (*i)->get_state(); - session->add_command (new MementoCommand(*(*i), &before, &after)); + separate_regions_between (ts); } + } +} - commit_reversible_command (); +void +Editor::separate_region_from_punch () +{ + Location* loc = session->locations()->auto_punch_location(); + if (loc) { + separate_regions_using_location (*loc); } -} +} void -Editor::region_fill_track () +Editor::separate_region_from_loop () { - nframes_t end; + Location* loc = session->locations()->auto_loop_location(); + if (loc) { + separate_regions_using_location (*loc); + } +} - if (!session || selection->regions.empty()) { +void +Editor::separate_regions_using_location (Location& loc) +{ + if (loc.is_mark()) { return; } - end = session->current_end_frame (); + AudioRange ar (loc.start(), loc.end(), 1); + TimeSelection ts; - begin_reversible_command (_("region fill")); + ts.push_back (ar); - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + separate_regions_between (ts); +} - boost::shared_ptr region ((*i)->region()); - - // FIXME - boost::shared_ptr ar = boost::dynamic_pointer_cast(region); - if (!ar) - continue; +void +Editor::crop_region_to_selection () +{ + if (!selection->time.empty()) { - Playlist* pl = region->playlist(); + crop_region_to (selection->time.start(), selection->time.end_frame()); - if (end <= region->last_frame()) { - return; - } + } else { - double times = (double) (end - region->last_frame()) / (double) region->length(); + nframes64_t start; + nframes64_t end; - if (times == 0) { - return; + if (get_edit_op_range (start, end)) { + crop_region_to (start, end); } - - XMLNode &before = pl->get_state(); - pl->add_region (RegionFactory::create (ar), ar->last_frame(), times); - session->add_command (new MementoCommand(*pl, &before, &pl->get_state())); } - + +} + +void +Editor::crop_region_to (nframes64_t start, nframes64_t end) +{ + vector > playlists; + boost::shared_ptr playlist; + TrackSelection* ts; + + if (selection->tracks.empty()) { + ts = &track_views; + } else { + sort_track_selection (); + ts = &selection->tracks; + } + + for (TrackSelection::iterator i = ts->begin(); i != ts->end(); ++i) { + + RouteTimeAxisView* rtv; + + if ((rtv = dynamic_cast ((*i))) != 0) { + + boost::shared_ptr t = rtv->track(); + + if (t != 0 && ! t->diskstream()->destructive()) { + + if ((playlist = rtv->playlist()) != 0) { + playlists.push_back (playlist); + } + } + } + } + + if (playlists.empty()) { + return; + } + + nframes64_t the_start; + nframes64_t the_end; + nframes64_t cnt; + + begin_reversible_command (_("trim to selection")); + + for (vector >::iterator i = playlists.begin(); i != playlists.end(); ++i) { + + boost::shared_ptr region; + + the_start = start; + + if ((region = (*i)->top_region_at(the_start)) == 0) { + continue; + } + + /* now adjust lengths to that we do the right thing + if the selection extends beyond the region + */ + + the_start = max (the_start, (nframes64_t) region->position()); + if (max_frames - the_start < region->length()) { + the_end = the_start + region->length() - 1; + } else { + the_end = max_frames; + } + the_end = min (end, the_end); + cnt = the_end - the_start + 1; + + XMLNode &before = (*i)->get_state(); + region->trim_to (the_start, cnt, this); + XMLNode &after = (*i)->get_state(); + session->add_command (new MementoCommand(*(*i), &before, &after)); + } + + commit_reversible_command (); +} + +void +Editor::region_fill_track () +{ + nframes64_t end; + RegionSelection rs; + + get_regions_for_action (rs); + + if (!session || rs.empty()) { + return; + } + + end = session->current_end_frame (); + + begin_reversible_command (_("region fill")); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + + boost::shared_ptr region ((*i)->region()); + + // FIXME + boost::shared_ptr ar = boost::dynamic_pointer_cast(region); + assert(ar); + + boost::shared_ptr pl = region->playlist(); + + if (end <= region->last_frame()) { + return; + } + + double times = (double) (end - region->last_frame()) / (double) region->length(); + + if (times == 0) { + return; + } + + XMLNode &before = pl->get_state(); + pl->add_region (RegionFactory::create (ar), ar->last_frame(), times); + session->add_command (new MementoCommand(*pl, &before, &pl->get_state())); + } + commit_reversible_command (); } void Editor::region_fill_selection () { - if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) { + if (clicked_routeview == 0 || !clicked_routeview->is_audio_track()) { return; } @@ -2426,16 +3157,16 @@ Editor::region_fill_selection () TreeModel::iterator i = region_list_display.get_selection()->get_selected(); boost::shared_ptr region = (*i)[region_list_columns.region]; - nframes_t start = selection->time[clicked_selection].start; - nframes_t end = selection->time[clicked_selection].end; + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; - Playlist *playlist; + boost::shared_ptr playlist; if (selection->tracks.empty()) { return; } - nframes_t selection_length = end - start; + nframes64_t selection_length = end - start; float times = (float)selection_length / region->length(); begin_reversible_command (_("fill selection")); @@ -2455,64 +3186,79 @@ Editor::region_fill_selection () } void -Editor::set_a_regions_sync_position (boost::shared_ptr region, nframes_t position) +Editor::set_region_sync_from_edit_point () { - - if (!region->covers (position)) { - error << _("Programming error. that region doesn't cover that position") << __FILE__ << " +" << __LINE__ << endmsg; - return; - } - begin_reversible_command (_("set region sync position")); - XMLNode &before = region->playlist()->get_state(); - region->set_sync_position (position); - XMLNode &after = region->playlist()->get_state(); - session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); - commit_reversible_command (); + nframes64_t where = get_preferred_edit_position (); + RegionSelection rs; + get_regions_for_action (rs); + set_sync_point (where, rs); } void -Editor::set_region_sync_from_edit_cursor () +Editor::set_sync_point (nframes64_t where, const RegionSelection& rs) { - if (clicked_regionview == 0) { - return; - } + bool in_command = false; - if (!clicked_regionview->region()->covers (edit_cursor->current_frame)) { - error << _("Place the edit cursor at the desired sync point") << endmsg; - return; + for (RegionSelection::const_iterator r = rs.begin(); r != rs.end(); ++r) { + + if (!(*r)->region()->covers (where)) { + continue; + } + + boost::shared_ptr region ((*r)->region()); + + if (!in_command) { + begin_reversible_command (_("set sync point")); + in_command = true; + } + + XMLNode &before = region->playlist()->get_state(); + region->set_sync_position (get_preferred_edit_position()); + XMLNode &after = region->playlist()->get_state(); + session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); } - boost::shared_ptr region (clicked_regionview->region()); - begin_reversible_command (_("set sync from edit cursor")); - XMLNode &before = region->playlist()->get_state(); - region->set_sync_position (edit_cursor->current_frame); - XMLNode &after = region->playlist()->get_state(); - session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); - commit_reversible_command (); + if (in_command) { + commit_reversible_command (); + } } +/** Remove the sync positions of the selection */ void Editor::remove_region_sync () { - if (clicked_regionview) { - boost::shared_ptr region (clicked_regionview->region()); - begin_reversible_command (_("remove sync")); - XMLNode &before = region->playlist()->get_state(); - region->clear_sync_position (); - XMLNode &after = region->playlist()->get_state(); - session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); - commit_reversible_command (); + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + begin_reversible_command (_("remove sync")); + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + + XMLNode &before = (*i)->region()->playlist()->get_state(); + (*i)->region()->clear_sync_position (); + XMLNode &after = (*i)->region()->playlist()->get_state(); + session->add_command(new MementoCommand(*((*i)->region()->playlist()), &before, &after)); } + commit_reversible_command (); } void Editor::naturalize () { - if (selection->regions.empty()) { + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { return; } + begin_reversible_command (_("naturalize")); - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { XMLNode &before = (*i)->region()->get_state(); (*i)->region()->move_to_natural_position (this); XMLNode &after = (*i)->region()->get_state(); @@ -2524,61 +3270,107 @@ Editor::naturalize () void Editor::align (RegionPoint what) { - align_selection (what, edit_cursor->current_frame); + RegionSelection rs; + + get_regions_for_action (rs); + nframes64_t where = get_preferred_edit_position(); + + if (!rs.empty()) { + align_selection (what, where, rs); + } else { + + RegionSelection rs; + get_regions_at (rs, where, selection->tracks); + align_selection (what, where, rs); + } } void Editor::align_relative (RegionPoint what) { - align_selection_relative (what, edit_cursor->current_frame); + nframes64_t where = get_preferred_edit_position(); + RegionSelection rs; + + get_regions_for_action (rs); + + if (!rs.empty()) { + align_selection_relative (what, where, rs); + } } struct RegionSortByTime { - bool operator() (const AudioRegionView* a, const AudioRegionView* b) { + bool operator() (const RegionView* a, const RegionView* b) { return a->region()->position() < b->region()->position(); } }; void -Editor::align_selection_relative (RegionPoint point, nframes_t position) +Editor::align_selection_relative (RegionPoint point, nframes64_t position, const RegionSelection& rs) { - if (selection->regions.empty()) { + if (rs.empty()) { return; } - nframes_t distance; - nframes_t pos = 0; - int dir; + nframes64_t distance = 0; + nframes64_t pos = 0; + int dir = 1; list sorted; - selection->regions.by_position (sorted); + rs.by_position (sorted); + boost::shared_ptr r ((*sorted.begin())->region()); switch (point) { case Start: - pos = r->first_frame (); + pos = position; + if (position > r->position()) { + distance = position - r->position(); + } else { + distance = r->position() - position; + dir = -1; + } break; - + case End: - pos = r->last_frame(); + if (position > r->last_frame()) { + distance = position - r->last_frame(); + pos = r->position() + distance; + } else { + distance = r->last_frame() - position; + pos = r->position() - distance; + dir = -1; + } break; case SyncPoint: - pos = r->adjust_to_sync (r->first_frame()); + pos = r->adjust_to_sync (position); + if (pos > r->position()) { + distance = pos - r->position(); + } else { + distance = r->position() - pos; + dir = -1; + } break; } - if (pos > position) { - distance = pos - position; - dir = -1; - } else { - distance = position - pos; - dir = 1; + if (pos == r->position()) { + return; } begin_reversible_command (_("align selection (relative)")); - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + /* move first one specially */ + + XMLNode &before = r->playlist()->get_state(); + r->set_position (pos, this); + XMLNode &after = r->playlist()->get_state(); + session->add_command(new MementoCommand(*(r->playlist()), &before, &after)); + + /* move rest by the same amount */ + + sorted.pop_front(); + + for (list::iterator i = sorted.begin(); i != sorted.end(); ++i) { boost::shared_ptr region ((*i)->region()); @@ -2599,15 +3391,15 @@ Editor::align_selection_relative (RegionPoint point, nframes_t position) } void -Editor::align_selection (RegionPoint point, nframes_t position) +Editor::align_selection (RegionPoint point, nframes64_t position, const RegionSelection& rs) { - if (selection->regions.empty()) { + if (rs.empty()) { return; } begin_reversible_command (_("align selection")); - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) { align_region_internal ((*i)->region(), point, position); } @@ -2615,7 +3407,7 @@ Editor::align_selection (RegionPoint point, nframes_t position) } void -Editor::align_region (boost::shared_ptr region, RegionPoint point, nframes_t position) +Editor::align_region (boost::shared_ptr region, RegionPoint point, nframes64_t position) { begin_reversible_command (_("align region")); align_region_internal (region, point, position); @@ -2623,7 +3415,7 @@ Editor::align_region (boost::shared_ptr region, RegionPoint point, nfram } void -Editor::align_region_internal (boost::shared_ptr region, RegionPoint point, nframes_t position) +Editor::align_region_internal (boost::shared_ptr region, RegionPoint point, nframes64_t position) { XMLNode &before = region->playlist()->get_state(); @@ -2647,66 +3439,175 @@ Editor::align_region_internal (boost::shared_ptr region, RegionPoint poi session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); } +/** Trim the end of the selected regions to the position of the edit cursor */ void -Editor::trim_region_to_edit_cursor () +Editor::trim_region_to_loop () { - if (clicked_regionview == 0) { + Location* loc = session->locations()->auto_loop_location(); + if (!loc) { return; } + trim_region_to_location (*loc, _("trim to loop")); +} + +void +Editor::trim_region_to_punch () +{ + Location* loc = session->locations()->auto_punch_location(); + if (!loc) { + return; + } + trim_region_to_location (*loc, _("trim to punch")); +} +void +Editor::trim_region_to_location (const Location& loc, const char* str) +{ + RegionSelection rs; - boost::shared_ptr region (clicked_regionview->region()); + get_regions_for_action (rs); - float speed = 1.0f; - AudioTimeAxisView *atav; + begin_reversible_command (str); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* arv = dynamic_cast (*x); + + if (!arv) { + continue; + } + + /* require region to span proposed trim */ + + switch (arv->region()->coverage (loc.start(), loc.end())) { + case OverlapInternal: + break; + default: + continue; + } + + AudioTimeAxisView* atav = dynamic_cast (&arv->get_time_axis_view()); + + if (!atav) { + return; + } + + float speed = 1.0; + nframes64_t start; + nframes64_t end; - if ( clicked_trackview != 0 && (atav = dynamic_cast(clicked_trackview)) != 0 ) { if (atav->get_diskstream() != 0) { speed = atav->get_diskstream()->speed(); } + + start = session_frame_to_track_frame (loc.start(), speed); + end = session_frame_to_track_frame (loc.end(), speed); + + XMLNode &before = arv->region()->playlist()->get_state(); + arv->region()->trim_to (start, (end - start), this); + XMLNode &after = arv->region()->playlist()->get_state(); + session->add_command(new MementoCommand(*(arv->region()->playlist()), &before, &after)); } - begin_reversible_command (_("trim to edit")); - XMLNode &before = region->playlist()->get_state(); - region->trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this); - XMLNode &after = region->playlist()->get_state(); - session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); commit_reversible_command (); } void -Editor::trim_region_from_edit_cursor () +Editor::trim_region_to_edit_point () { - if (clicked_regionview == 0) { - return; - } + RegionSelection rs; + + get_regions_for_action (rs); - boost::shared_ptr region (clicked_regionview->region()); + nframes64_t where = get_preferred_edit_position(); - float speed = 1.0f; - AudioTimeAxisView *atav; + begin_reversible_command (_("trim region start to edit point")); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* arv = dynamic_cast (*x); + + if (!arv) { + continue; + } + + /* require region to cover trim */ + + if (!arv->region()->covers (where)) { + continue; + } + + AudioTimeAxisView* atav = dynamic_cast (&arv->get_time_axis_view()); + + if (!atav) { + return; + } + + float speed = 1.0; - if ( clicked_trackview != 0 && (atav = dynamic_cast(clicked_trackview)) != 0 ) { if (atav->get_diskstream() != 0) { speed = atav->get_diskstream()->speed(); } + + XMLNode &before = arv->region()->playlist()->get_state(); + arv->region()->trim_end( session_frame_to_track_frame(where, speed), this); + XMLNode &after = arv->region()->playlist()->get_state(); + session->add_command(new MementoCommand(*(arv->region()->playlist()), &before, &after)); } + + commit_reversible_command (); +} - begin_reversible_command (_("trim to edit")); - XMLNode &before = region->playlist()->get_state(); - region->trim_front ( session_frame_to_track_frame(edit_cursor->current_frame, speed), this); - XMLNode &after = region->playlist()->get_state(); - session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); +void +Editor::trim_region_from_edit_point () +{ + RegionSelection rs; + + get_regions_for_action (rs); + + nframes64_t where = get_preferred_edit_position(); + + begin_reversible_command (_("trim region end to edit point")); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* arv = dynamic_cast (*x); + + if (!arv) { + continue; + } + + /* require region to cover trim */ + + if (!arv->region()->covers (where)) { + continue; + } + + AudioTimeAxisView* atav = dynamic_cast (&arv->get_time_axis_view()); + + if (!atav) { + return; + } + + float speed = 1.0; + + if (atav->get_diskstream() != 0) { + speed = atav->get_diskstream()->speed(); + } + + XMLNode &before = arv->region()->playlist()->get_state(); + arv->region()->trim_front ( session_frame_to_track_frame(where, speed), this); + XMLNode &after = arv->region()->playlist()->get_state(); + session->add_command(new MementoCommand(*(arv->region()->playlist()), &before, &after)); + } + commit_reversible_command (); } void Editor::unfreeze_route () { - if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) { + if (clicked_routeview == 0 || !clicked_routeview->is_audio_track()) { return; } - clicked_audio_trackview->audio_track()->unfreeze (); + clicked_routeview->audio_track()->unfreeze (); } void* @@ -2719,7 +3620,7 @@ Editor::_freeze_thread (void* arg) void* Editor::freeze_thread () { - clicked_audio_trackview->audio_track()->freeze (*current_interthread_info); + clicked_routeview->audio_track()->freeze (*current_interthread_info); return 0; } @@ -2733,7 +3634,7 @@ Editor::freeze_progress_timeout (void *arg) void Editor::freeze_route () { - if (clicked_audio_trackview == 0 || !clicked_audio_trackview->is_audio_track()) { + if (clicked_routeview == 0 || !clicked_routeview->is_audio_track()) { return; } @@ -2742,8 +3643,10 @@ Editor::freeze_route () if (interthread_progress_window == 0) { build_interthread_progress_window (); } - - interthread_progress_window->set_title (_("ardour: freeze")); + + WindowTitle title(Glib::get_application_name()); + title += _("Freeze"); + interthread_progress_window->set_title (title.get_string()); interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE); interthread_progress_window->show_all (); interthread_progress_bar.set_fraction (0.0f); @@ -2757,10 +3660,16 @@ Editor::freeze_route () itt.done = false; itt.cancel = false; itt.progress = 0.0f; + + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 500000); - pthread_create (&itt.thread, 0, _freeze_thread, this); + pthread_create (&itt.thread, &attr, _freeze_thread, this); - track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH)); + pthread_attr_destroy(&attr); + + track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH)); while (!itt.done && !itt.cancel) { gtk_main_iteration (); @@ -2769,35 +3678,35 @@ Editor::freeze_route () interthread_progress_connection.disconnect (); interthread_progress_window->hide_all (); current_interthread_info = 0; - track_canvas.get_window()->set_cursor (*current_canvas_cursor); + track_canvas->get_window()->set_cursor (*current_canvas_cursor); } void -Editor::bounce_range_selection () +Editor::bounce_range_selection (bool replace) { if (selection->time.empty()) { return; } - TrackViewList *views = get_valid_views (selection->time.track, selection->time.group); + TrackSelection views = selection->tracks; + + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; + nframes64_t cnt = end - start + 1; - nframes_t start = selection->time[clicked_selection].start; - nframes_t end = selection->time[clicked_selection].end; - nframes_t cnt = end - start + 1; - begin_reversible_command (_("bounce range")); - for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) { + for (TrackViewList::iterator i = views.begin(); i != views.end(); ++i) { - AudioTimeAxisView* atv; + RouteTimeAxisView* rtv; - if ((atv = dynamic_cast (*i)) == 0) { + if ((rtv = dynamic_cast (*i)) == 0) { continue; } - Playlist* playlist; + boost::shared_ptr playlist; - if ((playlist = atv->playlist()) == 0) { + if ((playlist = rtv->playlist()) == 0) { return; } @@ -2806,30 +3715,68 @@ Editor::bounce_range_selection () itt.done = false; itt.cancel = false; itt.progress = false; - + XMLNode &before = playlist->get_state(); - atv->audio_track()->bounce_range (start, cnt, itt); + boost::shared_ptr r = rtv->track()->bounce_range (start, start+cnt, itt); + + if (replace) { + list ranges; + ranges.push_back (AudioRange (start, start+cnt, 0)); + playlist->cut (ranges); // discard result + playlist->add_region (r, start); + } + XMLNode &after = playlist->get_state(); session->add_command (new MementoCommand (*playlist, &before, &after)); } commit_reversible_command (); - - delete views; } +/** Cut selected regions, automation points or a time range */ void Editor::cut () { cut_copy (Cut); } +/** Copy selected regions, automation points or a time range */ void Editor::copy () { cut_copy (Copy); } + +/** @return true if a Cut, Copy or Clear is possible */ +bool +Editor::can_cut_copy () const +{ + switch (current_mouse_mode()) { + + case MouseObject: + if (!selection->regions.empty() || !selection->points.empty()) { + return true; + } + break; + + case MouseRange: + if (!selection->time.empty()) { + return true; + } + break; + + default: + break; + } + + return false; +} + + +/** Cut, copy or clear selected regions, automation points or a time range. + * @param op Operation (Cut, Copy or Clear) + */ void Editor::cut_copy (CutCopyOp op) { @@ -2848,18 +3795,54 @@ Editor::cut_copy (CutCopyOp op) opname = _("clear"); break; } + + /* if we're deleting something, and the mouse is still pressed, + the thing we started a drag for will be gone when we release + the mouse button(s). avoid this. see part 2 at the end of + this function. + */ + + if (op == Cut || op == Clear) { + if (drag_info.item) { + drag_info.item->ungrab (0); + drag_info.item = 0; + } + } cut_buffer->clear (); - switch (current_mouse_mode()) { - case MouseObject: - if (!selection->regions.empty() || !selection->points.empty()) { + if (entered_marker) { + + /* cut/delete op while pointing at a marker */ + + bool ignored; + Location* loc = find_location_from_marker (entered_marker, ignored); + + if (session && loc) { + Glib::signal_idle().connect (bind (mem_fun(*this, &Editor::really_remove_marker), loc)); + } + + break_drag (); + + return; + } + + RegionSelection rs; + + /* we only want to cut regions if some are selected */ + + if (!selection->regions.empty()) { + get_regions_for_action (rs); + } + + switch (current_mouse_mode()) { + case MouseObject: + if (!rs.empty() || !selection->points.empty()) { begin_reversible_command (opname + _(" objects")); - if (!selection->regions.empty()) { - - cut_copy_regions (op); + if (!rs.empty()) { + cut_copy_regions (op, rs); if (op == Cut) { selection->clear_regions (); @@ -2875,28 +3858,46 @@ Editor::cut_copy (CutCopyOp op) } commit_reversible_command (); + break; // terminate case statement here + } + if (!selection->time.empty()) { + /* don't cause suprises */ + break; } - break; + // fall thru if there was nothing selected case MouseRange: - if (!selection->time.empty()) { - - begin_reversible_command (opname + _(" range")); - cut_copy_ranges (op); - commit_reversible_command (); - - if (op == Cut) { - selection->clear_time (); + if (selection->time.empty()) { + nframes64_t start, end; + if (!get_edit_op_range (start, end)) { + return; } + selection->set ((TimeAxisView*) 0, start, end); + } + begin_reversible_command (opname + _(" range")); + cut_copy_ranges (op); + commit_reversible_command (); + + if (op == Cut) { + selection->clear_time (); } + break; default: break; } + + + if (op == Cut || op == Clear) { + break_drag (); + } } +/** Cut, copy or clear selected automation points. + * @param op Operation (Cut, Copy or Clear) + */ void Editor::cut_copy_points (CutCopyOp op) { @@ -2911,7 +3912,7 @@ Editor::cut_copy_points (CutCopyOp op) } struct PlaylistState { - Playlist* playlist; + boost::shared_ptr playlist; XMLNode* before; }; @@ -2921,21 +3922,42 @@ struct lt_playlist { } }; +struct PlaylistMapping { + TimeAxisView* tv; + boost::shared_ptr pl; + + PlaylistMapping (TimeAxisView* tvp) : tv (tvp) {} +}; + + +/** Cut, copy or clear selected regions. + * @param op Operation (Cut, Copy or Clear) + */ void -Editor::cut_copy_regions (CutCopyOp op) -{ - typedef std::map PlaylistMapping; - PlaylistMapping pmap; - nframes_t first_position = max_frames; +Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs) +{ + /* we can't use a std::map here because the ordering is important, and we can't trivially sort + a map when we want ordered access to both elements. i think. + */ + + vector pmap; + nframes64_t first_position = max_frames; + set freezelist; pair::iterator,bool> insert_result; + + /* get ordering correct before we cut/copy */ + + rs.sort_by_position_and_track (); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { - for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) { - first_position = min ((*x)->region()->position(), first_position); + first_position = min ((nframes64_t) (*x)->region()->position(), first_position); if (op == Cut || op == Clear) { - AudioPlaylist *pl = dynamic_cast((*x)->region()->playlist()); + boost::shared_ptr pl = (*x)->region()->playlist(); + if (pl) { PlaylistState before; @@ -2943,70 +3965,100 @@ Editor::cut_copy_regions (CutCopyOp op) before.before = &pl->get_state(); insert_result = freezelist.insert (before); - + if (insert_result.second) { pl->freeze (); } } } + + TimeAxisView* tv = &(*x)->get_trackview(); + vector::iterator z; + + for (z = pmap.begin(); z != pmap.end(); ++z) { + if ((*z).tv == tv) { + break; + } + } + + if (z == pmap.end()) { + pmap.push_back (PlaylistMapping (tv)); + } } - for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ) { + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ) { + + boost::shared_ptr pl = (*x)->region()->playlist(); + + if (!pl) { + /* impossible, but this handles it for the future */ + continue; + } - AudioPlaylist *pl = dynamic_cast((*x)->region()->playlist()); - AudioPlaylist* npl; + TimeAxisView& tv = (*x)->get_trackview(); + boost::shared_ptr npl; RegionSelection::iterator tmp; tmp = x; ++tmp; - if (pl) { - - PlaylistMapping::iterator pi = pmap.find (pl); - - if (pi == pmap.end()) { - npl = new AudioPlaylist (*session, "cutlist", true); - npl->freeze(); - pmap[pl] = npl; - } else { - npl = pi->second; - } - - // FIXME - boost::shared_ptr ar = boost::dynamic_pointer_cast((*x)->region()); - switch (op) { - case Cut: - if (!ar) break; - - npl->add_region (RegionFactory::create (ar), (*x)->region()->position() - first_position); - pl->remove_region (((*x)->region())); + vector::iterator z; + + for (z = pmap.begin(); z != pmap.end(); ++z) { + if ((*z).tv == &tv) { break; + } + } + + assert (z != pmap.end()); + + if (!(*z).pl) { + npl = PlaylistFactory::create (pl->data_type(), *session, "cutlist", true); + npl->freeze(); + (*z).pl = npl; + } else { + npl = (*z).pl; + } + + boost::shared_ptr r = (*x)->region(); + boost::shared_ptr _xx; - case Copy: - if (!ar) break; - - npl->add_region (RegionFactory::create (ar), (*x)->region()->position() - first_position); - break; + assert (r != 0); - case Clear: - pl->remove_region (((*x)->region())); - break; - } + switch (op) { + case Cut: + _xx = RegionFactory::create (r); + npl->add_region (_xx, r->position() - first_position); + pl->remove_region (r); + break; + + case Copy: + /* copy region before adding, so we're not putting same object into two different playlists */ + npl->add_region (RegionFactory::create (r), r->position() - first_position); + break; + + case Clear: + pl->remove_region (r); + break; } x = tmp; } - - list foo; - - for (PlaylistMapping::iterator i = pmap.begin(); i != pmap.end(); ++i) { - foo.push_back (i->second); + + list > foo; + + /* the pmap is in the same order as the tracks in which selected regions occured */ + + for (vector::iterator i = pmap.begin(); i != pmap.end(); ++i) { + (*i).pl->thaw(); + foo.push_back ((*i).pl); } + if (!foo.empty()) { cut_buffer->set (foo); } - + for (set::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) { (*pl).playlist->thaw (); session->add_command (new MementoCommand(*(*pl).playlist, (*pl).before, &(*pl).playlist->get_state())); @@ -3016,7 +4068,20 @@ Editor::cut_copy_regions (CutCopyOp op) void Editor::cut_copy_ranges (CutCopyOp op) { - for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { + TrackSelection* ts; + TrackSelection entered; + + if (selection->tracks.empty()) { + if (!entered_track) { + return; + } + entered.push_back (entered_track); + ts = &entered; + } else { + ts = &selection->tracks; + } + + for (TrackSelection::iterator i = ts->begin(); i != ts->end(); ++i) { (*i)->cut_copy_clear (*selection, op); } } @@ -3024,57 +4089,61 @@ Editor::cut_copy_ranges (CutCopyOp op) void Editor::paste (float times) { - paste_internal (edit_cursor->current_frame, times); + paste_internal (get_preferred_edit_position(), times); } void Editor::mouse_paste () { - int x, y; - double wx, wy; + nframes64_t where; + bool ignored; - track_canvas.get_pointer (x, y); - track_canvas.window_to_world (x, y, wx, wy); - wx += horizontal_adjustment.get_value(); - wy += vertical_adjustment.get_value(); + if (!mouse_frame (where, ignored)) { + return; + } - GdkEvent event; - event.type = GDK_BUTTON_RELEASE; - event.button.x = wx; - event.button.y = wy; - - nframes_t where = event_frame (&event, 0, 0); snap_to (where); paste_internal (where, 1); } void -Editor::paste_internal (nframes_t position, float times) +Editor::paste_internal (nframes64_t position, float times) { bool commit = false; - if (cut_buffer->empty() || selection->tracks.empty()) { + if (cut_buffer->empty()) { return; } if (position == max_frames) { - position = edit_cursor->current_frame; + position = get_preferred_edit_position(); } begin_reversible_command (_("paste")); + TrackSelection ts; TrackSelection::iterator i; size_t nth; - for (nth = 0, i = selection->tracks.begin(); i != selection->tracks.end(); ++i, ++nth) { - + /* get everything in the correct order */ + + + if (!selection->tracks.empty()) { + sort_track_selection (); + ts = selection->tracks; + } else if (entered_track) { + ts.push_back (entered_track); + } + + for (nth = 0, i = ts.begin(); i != ts.end(); ++i, ++nth) { + /* undo/redo is handled by individual tracks */ if ((*i)->paste (position, times, *cut_buffer, nth)) { commit = true; } } - + if (commit) { commit_reversible_command (); } @@ -3094,36 +4163,38 @@ Editor::paste_named_selection (float times) TreeModel::iterator i = selected->get_selected(); NamedSelection* ns = (*i)[named_selection_columns.selection]; - list::iterator chunk; - list::iterator tmp; + list >::iterator chunk; + list >::iterator tmp; chunk = ns->playlists.begin(); begin_reversible_command (_("paste chunk")); + + sort_track_selection (); for (t = selection->tracks.begin(); t != selection->tracks.end(); ++t) { - AudioTimeAxisView* atv; - Playlist* pl; - AudioPlaylist* apl; + RouteTimeAxisView* rtv; + boost::shared_ptr pl; + boost::shared_ptr apl; - if ((atv = dynamic_cast (*t)) == 0) { + if ((rtv = dynamic_cast (*t)) == 0) { continue; } - if ((pl = atv->playlist()) == 0) { + if ((pl = rtv->playlist()) == 0) { continue; } - - if ((apl = dynamic_cast (pl)) == 0) { + + if ((apl = boost::dynamic_pointer_cast (pl)) == 0) { continue; } tmp = chunk; ++tmp; - XMLNode &before = apl->get_state(); - apl->paste (**chunk, edit_cursor->current_frame, times); + XMLNode &before = apl->get_state(); + apl->paste (*chunk, get_preferred_edit_position(), times); session->add_command(new MementoCommand(*apl, &before, &apl->get_state())); if (tmp != ns->playlists.end()) { @@ -3137,9 +4208,10 @@ Editor::paste_named_selection (float times) void Editor::duplicate_some_regions (RegionSelection& regions, float times) { - Playlist *playlist; - RegionSelection sel = regions; // clear (below) will clear the argument list - + boost::shared_ptr playlist; + RegionSelection sel = regions; // clear (below) may clear the argument list if its the current region selection + RegionSelection foo; + begin_reversible_command (_("duplicate region")); selection->clear_regions (); @@ -3149,8 +4221,9 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) boost::shared_ptr r ((*i)->region()); TimeAxisView& tv = (*i)->get_time_axis_view(); - AudioTimeAxisView* atv = dynamic_cast (&tv); - sigc::connection c = atv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); + RouteTimeAxisView* rtv = dynamic_cast (&tv); + latest_regionviews.clear (); + sigc::connection c = rtv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); playlist = (*i)->region()->playlist(); XMLNode &before = playlist->get_state(); @@ -3158,14 +4231,15 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) session->add_command(new MementoCommand(*playlist, &before, &playlist->get_state())); c.disconnect (); - - if (latest_regionview) { - selection->add (latest_regionview); - } - } + foo.insert (foo.end(), latest_regionviews.begin(), latest_regionviews.end()); + } commit_reversible_command (); + + if (!foo.empty()) { + selection->set (foo); + } } void @@ -3175,9 +4249,9 @@ Editor::duplicate_selection (float times) return; } - Playlist *playlist; - vector > new_regions; - vector >::iterator ri; + boost::shared_ptr playlist; + vector > new_regions; + vector >::iterator ri; create_region_from_selection (new_regions); @@ -3193,9 +4267,9 @@ Editor::duplicate_selection (float times) if ((playlist = (*i)->playlist()) == 0) { continue; } - XMLNode &before = playlist->get_state(); + XMLNode &before = playlist->get_state(); playlist->duplicate (*ri, selection->time[clicked_selection].end, times); - XMLNode &after = playlist->get_state(); + XMLNode &after = playlist->get_state(); session->add_command (new MementoCommand(*playlist, &before, &after)); ++ri; @@ -3212,8 +4286,6 @@ Editor::reset_point_selection () { /* reset all selected points to the relevant default value */ - cerr << "point selection has " << selection->points.size() << " entries\n"; - for (PointSelection::iterator i = selection->points.begin(); i != selection->points.end(); ++i) { AutomationTimeAxisView* atv = dynamic_cast(&(*i).track); @@ -3228,39 +4300,37 @@ void Editor::center_playhead () { float page = canvas_width * frames_per_unit; - center_screen_internal (playhead_cursor->current_frame, page); } void -Editor::center_edit_cursor () +Editor::center_edit_point () { float page = canvas_width * frames_per_unit; - - center_screen_internal (edit_cursor->current_frame, page); + center_screen_internal (get_preferred_edit_position(), page); } void -Editor::clear_playlist (Playlist& playlist) +Editor::clear_playlist (boost::shared_ptr playlist) { begin_reversible_command (_("clear playlist")); - XMLNode &before = playlist.get_state(); - playlist.clear (); - XMLNode &after = playlist.get_state(); - session->add_command (new MementoCommand(playlist, &before, &after)); + XMLNode &before = playlist->get_state(); + playlist->clear (); + XMLNode &after = playlist->get_state(); + session->add_command (new MementoCommand(*playlist.get(), &before, &after)); commit_reversible_command (); } void -Editor::nudge_track (bool use_edit_cursor, bool forwards) +Editor::nudge_track (bool use_edit, bool forwards) { - Playlist *playlist; - nframes_t distance; - nframes_t next_distance; - nframes_t start; + boost::shared_ptr playlist; + nframes64_t distance; + nframes64_t next_distance; + nframes64_t start; - if (use_edit_cursor) { - start = edit_cursor->current_frame; + if (use_edit) { + start = get_preferred_edit_position(); } else { start = 0; } @@ -3321,20 +4391,24 @@ Editor::remove_last_capture () void Editor::normalize_region () { + RegionSelection rs; + + get_regions_for_action (rs); + if (!session) { return; } - if (selection->regions.empty()) { + if (rs.empty()) { return; } begin_reversible_command (_("normalize")); - track_canvas.get_window()->set_cursor (*wait_cursor); + track_canvas->get_window()->set_cursor (*wait_cursor); gdk_flush (); - for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ++r) { + for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) { AudioRegionView* const arv = dynamic_cast(*r); if (!arv) continue; @@ -3344,7 +4418,7 @@ Editor::normalize_region () } commit_reversible_command (); - track_canvas.get_window()->set_cursor (*current_canvas_cursor); + track_canvas->get_window()->set_cursor (*current_canvas_cursor); } @@ -3355,13 +4429,17 @@ Editor::denormalize_region () return; } - if (selection->regions.empty()) { + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { return; } begin_reversible_command ("denormalize"); - for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ++r) { + for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) { AudioRegionView* const arv = dynamic_cast(*r); if (!arv) continue; @@ -3373,6 +4451,58 @@ Editor::denormalize_region () commit_reversible_command (); } +void +Editor::adjust_region_scale_amplitude (bool up) +{ + if (!session) { + return; + } + + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + begin_reversible_command ("denormalize"); + + for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) { + AudioRegionView* const arv = dynamic_cast(*r); + if (!arv) + continue; + XMLNode &before = arv->region()->get_state(); + + double fraction = gain_to_slider_position (arv->audio_region()->scale_amplitude ()); + + if (up) { + fraction += 0.05; + fraction = min (fraction, 1.0); + } else { + fraction -= 0.05; + fraction = max (fraction, 0.0); + } + + if (!up && fraction <= 0) { + continue; + } + + fraction = slider_position_to_gain (fraction); + fraction = coefficient_to_dB (fraction); + fraction = dB_to_coefficient (fraction); + + if (up && fraction >= 2.0) { + continue; + } + + arv->audio_region()->set_scale_amplitude (fraction); + session->add_command (new MementoCommand(*(arv->region().get()), &before, &arv->region()->get_state())); + } + + commit_reversible_command (); +} + void Editor::reverse_region () @@ -3385,48 +4515,69 @@ Editor::reverse_region () apply_filter (rev, _("reverse regions")); } + +void +Editor::quantize_region () +{ + if (!session) { + return; + } + + // FIXME: varying meter? + Quantize quant (*session, snap_length_beats(0)); + apply_filter (quant, _("quantize regions")); +} + void -Editor::apply_filter (AudioFilter& filter, string command) +Editor::apply_filter (Filter& filter, string command) { - if (selection->regions.empty()) { + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { return; } begin_reversible_command (command); - track_canvas.get_window()->set_cursor (*wait_cursor); + track_canvas->get_window()->set_cursor (*wait_cursor); gdk_flush (); - for (RegionSelection::iterator r = selection->regions.begin(); r != selection->regions.end(); ) { - AudioRegionView* const arv = dynamic_cast(*r); - if (!arv) - continue; + for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ) { + RegionSelection::iterator tmp = r; + ++tmp; - Playlist* playlist = arv->region()->playlist(); + MidiRegionView* const mrv = dynamic_cast(*r); + if (mrv) { + if (mrv->midi_region()->apply(filter) == 0) { + mrv->redisplay_model(); + } + } - RegionSelection::iterator tmp; - - tmp = r; - ++tmp; + AudioRegionView* const arv = dynamic_cast(*r); + if (arv) { + boost::shared_ptr playlist = arv->region()->playlist(); - if (arv->audio_region()->apply (filter) == 0) { + if (arv->audio_region()->apply (filter) == 0) { - XMLNode &before = playlist->get_state(); - playlist->replace_region (arv->region(), filter.results.front(), arv->region()->position()); - XMLNode &after = playlist->get_state(); - session->add_command(new MementoCommand(*playlist, &before, &after)); - } else { - goto out; + XMLNode &before = playlist->get_state(); + playlist->replace_region (arv->region(), filter.results.front(), arv->region()->position()); + XMLNode &after = playlist->get_state(); + session->add_command(new MementoCommand(*playlist, &before, &after)); + } else { + goto out; + } } r = tmp; } commit_reversible_command (); - selection->regions.clear (); + rs.clear (); out: - track_canvas.get_window()->set_cursor (*current_canvas_cursor); + track_canvas->get_window()->set_cursor (*current_canvas_cursor); } void @@ -3460,50 +4611,1577 @@ Editor::region_selection_op (void (Region::*pmf)(bool), bool yn) void Editor::external_edit_region () { - if (!clicked_regionview) { - return; - } - /* more to come */ } void -Editor::brush (nframes_t pos) +Editor::brush (nframes64_t pos) { RegionSelection sel; + RegionSelection rs; + + get_regions_for_action (rs); + snap_to (pos); - if (selection->regions.empty()) { - /* XXX get selection from region list */ - } else { - sel = selection->regions; + if (rs.empty()) { + return; + } + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + mouse_brush_insert_region ((*i), pos); } +} + +void +Editor::reset_region_gain_envelopes () +{ + RegionSelection rs; + + get_regions_for_action (rs); - if (sel.empty()) { + if (!session || rs.empty()) { return; } - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - mouse_brush_insert_region ((*i), pos); + session->begin_reversible_command (_("reset region gain")); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + AudioRegionView* const arv = dynamic_cast(*i); + if (arv) { + boost::shared_ptr alist (arv->audio_region()->envelope()); + XMLNode& before (alist->get_state()); + + arv->audio_region()->set_default_envelope (); + session->add_command (new MementoCommand(*arv->audio_region()->envelope().get(), &before, &alist->get_state())); + } } + + session->commit_reversible_command (); } void Editor::toggle_gain_envelope_visibility () { - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + RegionSelection rs; + + get_regions_for_action (rs); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { AudioRegionView* const arv = dynamic_cast(*i); - if (arv) + if (arv) { arv->set_envelope_visible (!arv->envelope_visible()); + } } } void Editor::toggle_gain_envelope_active () { - for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + RegionSelection rs; + + get_regions_for_action (rs); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { AudioRegionView* const arv = dynamic_cast(*i); - if (arv) - arv->audio_region()->set_envelope_active (true); + if (arv) { + arv->audio_region()->set_envelope_active (!arv->audio_region()->envelope_active()); + } + } +} + +void +Editor::toggle_region_lock () +{ + RegionSelection rs; + + get_regions_for_action (rs); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + (*i)->region()->set_locked (!(*i)->region()->locked()); + } +} + +void +Editor::set_region_lock_style (Region::PositionLockStyle ps) +{ + RegionSelection rs; + + get_regions_for_action (rs); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + (*i)->region()->set_position_lock_style (ps); + } +} + + +void +Editor::toggle_region_mute () +{ + RegionSelection rs; + + get_regions_for_action (rs); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + (*i)->region()->set_muted (!(*i)->region()->muted()); } } + +void +Editor::toggle_region_opaque () +{ + RegionSelection rs; + + get_regions_for_action (rs); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + (*i)->region()->set_opaque (!(*i)->region()->opaque()); + } +} + +void +Editor::set_fade_length (bool in) +{ + RegionSelection rs; + + get_regions_for_action (rs); + + /* we need a region to measure the offset from the start */ + + RegionView* rv; + + if (!rs.empty()) { + rv = rs.front(); + } else if (entered_regionview) { + rv = entered_regionview; + } else { + return; + } + + nframes64_t pos = get_preferred_edit_position(); + nframes64_t len; + char* cmd; + + if (pos > rv->region()->last_frame() || pos < rv->region()->first_frame()) { + /* edit point is outside the relevant region */ + return; + } + + if (in) { + if (pos <= rv->region()->position()) { + /* can't do it */ + return; + } + len = pos - rv->region()->position(); + cmd = _("set fade in length"); + } else { + if (pos >= rv->region()->last_frame()) { + /* can't do it */ + return; + } + len = rv->region()->last_frame() - pos; + cmd = _("set fade out length"); + } + + begin_reversible_command (cmd); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* tmp = dynamic_cast (*x); + + if (!tmp) { + return; + } + + boost::shared_ptr alist; + if (in) { + alist = tmp->audio_region()->fade_in(); + } else { + alist = tmp->audio_region()->fade_out(); + } + + XMLNode &before = alist->get_state(); + + if (in) { + tmp->audio_region()->set_fade_in_length (len); + tmp->audio_region()->set_fade_in_active (true); + } else { + tmp->audio_region()->set_fade_out_length (len); + tmp->audio_region()->set_fade_out_active (true); + } + + XMLNode &after = alist->get_state(); + session->add_command(new MementoCommand(*alist, &before, &after)); + } + + commit_reversible_command (); +} + +void +Editor::toggle_fade_active (bool in) +{ + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + const char* cmd = (in ? _("toggle fade in active") : _("toggle fade out active")); + bool have_switch = false; + bool yn = false; + + begin_reversible_command (cmd); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* tmp = dynamic_cast (*x); + + if (!tmp) { + return; + } + + boost::shared_ptr region (tmp->audio_region()); + + /* make the behaviour consistent across all regions */ + + if (!have_switch) { + if (in) { + yn = region->fade_in_active(); + } else { + yn = region->fade_out_active(); + } + have_switch = true; + } + + XMLNode &before = region->get_state(); + if (in) { + region->set_fade_in_active (!yn); + } else { + region->set_fade_out_active (!yn); + } + XMLNode &after = region->get_state(); + session->add_command(new MementoCommand(*region.get(), &before, &after)); + } + + commit_reversible_command (); +} + +void +Editor::set_fade_in_shape (AudioRegion::FadeShape shape) +{ + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + begin_reversible_command (_("set fade in shape")); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* tmp = dynamic_cast (*x); + + if (!tmp) { + return; + } + + boost::shared_ptr alist = tmp->audio_region()->fade_in(); + XMLNode &before = alist->get_state(); + + tmp->audio_region()->set_fade_in_shape (shape); + + XMLNode &after = alist->get_state(); + session->add_command(new MementoCommand(*alist.get(), &before, &after)); + } + + commit_reversible_command (); + +} + +void +Editor::set_fade_out_shape (AudioRegion::FadeShape shape) +{ + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + begin_reversible_command (_("set fade out shape")); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* tmp = dynamic_cast (*x); + + if (!tmp) { + return; + } + + boost::shared_ptr alist = tmp->audio_region()->fade_out(); + XMLNode &before = alist->get_state(); + + tmp->audio_region()->set_fade_out_shape (shape); + + XMLNode &after = alist->get_state(); + session->add_command(new MementoCommand(*alist.get(), &before, &after)); + } + + commit_reversible_command (); +} + +void +Editor::set_fade_in_active (bool yn) +{ + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + begin_reversible_command (_("set fade in active")); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* tmp = dynamic_cast (*x); + + if (!tmp) { + return; + } + + + boost::shared_ptr ar (tmp->audio_region()); + + XMLNode &before = ar->get_state(); + + ar->set_fade_in_active (yn); + + XMLNode &after = ar->get_state(); + session->add_command(new MementoCommand(*ar, &before, &after)); + } + + commit_reversible_command (); +} + +void +Editor::set_fade_out_active (bool yn) +{ + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + begin_reversible_command (_("set fade out active")); + + for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) { + AudioRegionView* tmp = dynamic_cast (*x); + + if (!tmp) { + return; + } + + boost::shared_ptr ar (tmp->audio_region()); + + XMLNode &before = ar->get_state(); + + ar->set_fade_out_active (yn); + + XMLNode &after = ar->get_state(); + session->add_command(new MementoCommand(*ar, &before, &after)); + } + + commit_reversible_command (); +} + +void +Editor::toggle_selected_region_fades (int dir) +{ + RegionSelection rs; + RegionSelection::iterator i; + boost::shared_ptr ar; + bool yn; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + for (i = rs.begin(); i != rs.end(); ++i) { + if ((ar = boost::dynamic_pointer_cast((*i)->region())) != 0) { + if (dir == -1) { + yn = ar->fade_out_active (); + } else { + yn = ar->fade_in_active (); + } + break; + } + } + + if (i == rs.end()) { + return; + } + + /* XXX should this undo-able? */ + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + if ((ar = boost::dynamic_pointer_cast((*i)->region())) == 0) { + continue; + } + if (dir == 1 || dir == 0) { + ar->set_fade_in_active (!yn); + } + + if (dir == -1 || dir == 0) { + ar->set_fade_out_active (!yn); + } + } +} + + +/** Update region fade visibility after its configuration has been changed */ +void +Editor::update_region_fade_visibility () +{ + bool _fade_visibility = Config->get_show_region_fades (); + + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + AudioTimeAxisView* v = dynamic_cast(*i); + if (v) { + if (_fade_visibility) { + v->audio_view()->show_all_fades (); + } else { + v->audio_view()->hide_all_fades (); + } + } + } +} + +/** Update crossfade visibility after its configuration has been changed */ +void +Editor::update_xfade_visibility () +{ + _xfade_visibility = Config->get_xfades_visible (); + + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + AudioTimeAxisView* v = dynamic_cast(*i); + if (v) { + if (_xfade_visibility) { + v->show_all_xfades (); + } else { + v->hide_all_xfades (); + } + } + } +} + +void +Editor::set_edit_point () +{ + nframes64_t where; + bool ignored; + + if (!mouse_frame (where, ignored)) { + return; + } + + snap_to (where); + + if (selection->markers.empty()) { + + mouse_add_new_marker (where); + + } else { + bool ignored; + + Location* loc = find_location_from_marker (selection->markers.front(), ignored); + + if (loc) { + loc->move_to (where); + } + } +} + +void +Editor::set_playhead_cursor () +{ + if (entered_marker) { + session->request_locate (entered_marker->position(), session->transport_rolling()); + } else { + nframes64_t where; + bool ignored; + + if (!mouse_frame (where, ignored)) { + return; + } + + snap_to (where); + + if (session) { + session->request_locate (where, session->transport_rolling()); + } + } +} + +void +Editor::split () +{ + RegionSelection rs; + + get_regions_for_action (rs); + + nframes64_t where = get_preferred_edit_position(); + + if (rs.empty()) { + return; + } + + split_regions_at (where, rs); +} + +void +Editor::ensure_entered_track_selected (bool op_really_wants_one_track_if_none_are_selected) +{ + if (entered_track && mouse_mode == MouseObject) { + if (!selection->tracks.empty()) { + if (!selection->selected (entered_track)) { + selection->add (entered_track); + } + } else { + /* there is no selection, but this operation requires/prefers selected objects */ + + if (op_really_wants_one_track_if_none_are_selected) { + selection->set (entered_track); + } + } + } +} + +void +Editor::trim_region_front () +{ + trim_region (true); +} + +void +Editor::trim_region_back () +{ + trim_region (false); +} + +void +Editor::trim_region (bool front) +{ + nframes64_t where = get_preferred_edit_position(); + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + begin_reversible_command (front ? _("trim front") : _("trim back")); + + for (list::const_iterator i = rs.by_layer().begin(); i != rs.by_layer().end(); ++i) { + if (!(*i)->region()->locked()) { + boost::shared_ptr pl = (*i)->region()->playlist(); + XMLNode &before = pl->get_state(); + if (front) { + (*i)->region()->trim_front (where, this); + } else { + (*i)->region()->trim_end (where, this); + } + XMLNode &after = pl->get_state(); + session->add_command(new MementoCommand(*pl.get(), &before, &after)); + } + } + + commit_reversible_command (); +} + +struct EditorOrderRouteSorter { + bool operator() (boost::shared_ptr a, boost::shared_ptr b) { + /* use of ">" forces the correct sort order */ + return a->order_key ("editor") < b->order_key ("editor"); + } +}; + +void +Editor::select_next_route() +{ + if (selection->tracks.empty()) { + selection->set (track_views.front()); + return; + } + + TimeAxisView* current = selection->tracks.front(); + + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + if (*i == current) { + ++i; + if (i != track_views.end()) { + selection->set (*i); + } else { + selection->set (*(track_views.begin())); + } + break; + } + } +} + +void +Editor::select_prev_route() +{ + if (selection->tracks.empty()) { + selection->set (track_views.front()); + return; + } + + TimeAxisView* current = selection->tracks.front(); + + for (TrackViewList::reverse_iterator i = track_views.rbegin(); i != track_views.rend(); ++i) { + if (*i == current) { + ++i; + if (i != track_views.rend()) { + selection->set (*i); + } else { + selection->set (*(track_views.rbegin())); + } + break; + } + } +} + +void +Editor::set_loop_from_selection (bool play) +{ + if (session == 0 || selection->time.empty()) { + return; + } + + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; + + set_loop_range (start, end, _("set loop range from selection")); + + if (play) { + session->request_play_loop (true); + session->request_locate (start, true); + } +} + +void +Editor::set_loop_from_edit_range (bool play) +{ + if (session == 0) { + return; + } + + nframes64_t start; + nframes64_t end; + + if (!get_edit_op_range (start, end)) { + return; + } + + set_loop_range (start, end, _("set loop range from edit range")); + + if (play) { + session->request_play_loop (true); + session->request_locate (start, true); + } +} + +void +Editor::set_loop_from_region (bool play) +{ + nframes64_t start = max_frames; + nframes64_t end = 0; + + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + if ((*i)->region()->position() < start) { + start = (*i)->region()->position(); + } + if ((*i)->region()->last_frame() + 1 > end) { + end = (*i)->region()->last_frame() + 1; + } + } + + set_loop_range (start, end, _("set loop range from region")); + + if (play) { + session->request_play_loop (true); + session->request_locate (start, true); + } +} + +void +Editor::set_punch_from_selection () +{ + if (session == 0 || selection->time.empty()) { + return; + } + + nframes64_t start = selection->time[clicked_selection].start; + nframes64_t end = selection->time[clicked_selection].end; + + set_punch_range (start, end, _("set punch range from selection")); +} + +void +Editor::set_punch_from_edit_range () +{ + if (session == 0) { + return; + } + + nframes64_t start; + nframes64_t end; + + if (!get_edit_op_range (start, end)) { + return; + } + + set_punch_range (start, end, _("set punch range from edit range")); +} + +void +Editor::set_punch_from_region () +{ + nframes64_t start = max_frames; + nframes64_t end = 0; + + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + if ((*i)->region()->position() < start) { + start = (*i)->region()->position(); + } + if ((*i)->region()->last_frame() + 1 > end) { + end = (*i)->region()->last_frame() + 1; + } + } + + set_punch_range (start, end, _("set punch range from region")); +} + +void +Editor::pitch_shift_regions () +{ + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + pitch_shift (rs, 1.2); +} + +void +Editor::use_region_as_bar () +{ + if (!session) { + return; + } + + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + RegionView* rv = rs.front(); + + define_one_bar (rv->region()->position(), rv->region()->last_frame() + 1); +} + +void +Editor::use_range_as_bar () +{ + nframes64_t start, end; + if (get_edit_op_range (start, end)) { + define_one_bar (start, end); + } +} + +void +Editor::define_one_bar (nframes64_t start, nframes64_t end) +{ + nframes64_t length = end - start; + + const Meter& m (session->tempo_map().meter_at (start)); + + /* length = 1 bar */ + + /* now we want frames per beat. + we have frames per bar, and beats per bar, so ... + */ + + double frames_per_beat = length / m.beats_per_bar(); + + /* beats per minute = */ + + double beats_per_minute = (session->frame_rate() * 60.0) / frames_per_beat; + + /* now decide whether to: + + (a) set global tempo + (b) add a new tempo marker + + */ + + const TempoSection& t (session->tempo_map().tempo_section_at (start)); + + bool do_global = false; + + if ((session->tempo_map().n_tempos() == 1) && (session->tempo_map().n_meters() == 1)) { + + /* only 1 tempo & 1 meter: ask if the user wants to set the tempo + at the start, or create a new marker + */ + + vector options; + options.push_back (_("Cancel")); + options.push_back (_("Add new marker")); + options.push_back (_("Set global tempo")); + Choice c (_("Do you want to set the global tempo or add new tempo marker?"), + options); + c.set_default_response (2); + + switch (c.run()) { + case 0: + return; + + case 2: + do_global = true; + break; + + default: + do_global = false; + } + + } else { + + /* more than 1 tempo and/or meter section already, go ahead do the "usual": + if the marker is at the region starter, change it, otherwise add + a new tempo marker + */ + } + + begin_reversible_command (_("set tempo from region")); + XMLNode& before (session->tempo_map().get_state()); + + if (do_global) { + session->tempo_map().change_initial_tempo (beats_per_minute, t.note_type()); + } else if (t.frame() == start) { + session->tempo_map().change_existing_tempo_at (start, beats_per_minute, t.note_type()); + } else { + session->tempo_map().add_tempo (Tempo (beats_per_minute, t.note_type()), start); + } + + XMLNode& after (session->tempo_map().get_state()); + + session->add_command (new MementoCommand(session->tempo_map(), &before, &after)); + commit_reversible_command (); +} + +void +Editor::split_region_at_transients () +{ + AnalysisFeatureList positions; + + if (!session) { + return; + } + + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + session->begin_reversible_command (_("split regions")); + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ) { + + RegionSelection::iterator tmp; + + tmp = i; + ++tmp; + + boost::shared_ptr ar = boost::dynamic_pointer_cast ((*i)->region()); + + if (ar && (ar->get_transients (positions) == 0)) { + split_region_at_points ((*i)->region(), positions, true); + positions.clear (); + } + + i = tmp; + } + + session->commit_reversible_command (); + +} + +void +Editor::split_region_at_points (boost::shared_ptr r, AnalysisFeatureList& positions, bool can_ferret) +{ + bool use_rhythmic_rodent = false; + + boost::shared_ptr pl = r->playlist(); + + if (!pl) { + return; + } + + if (positions.empty()) { + return; + } + + + if (positions.size() > 20) { + Glib::ustring msgstr = string_compose (_("You are about to split\n%1\ninto %2 pieces.\nThis could take a long time."), r->name(), positions.size() + 1); + MessageDialog msg (msgstr, + false, + Gtk::MESSAGE_INFO, + Gtk::BUTTONS_OK_CANCEL); + + if (can_ferret) { + msg.add_button (_("Call for the Ferret!"), RESPONSE_APPLY); + msg.set_secondary_text (_("Press OK to continue with this split operation\nor ask the Ferret dialog to tune the analysis")); + } else { + msg.set_secondary_text (_("Press OK to continue with this split operation")); + } + + msg.set_title (_("Excessive split?")); + msg.present (); + + int response = msg.run(); + msg.hide (); + switch (response) { + case RESPONSE_OK: + break; + case RESPONSE_APPLY: + use_rhythmic_rodent = true; + break; + default: + return; + } + } + + if (use_rhythmic_rodent) { + show_rhythm_ferret (); + return; + } + + AnalysisFeatureList::const_iterator x; + + nframes64_t pos = r->position(); + + XMLNode& before (pl->get_state()); + + x = positions.begin(); + + while (x != positions.end()) { + if ((*x) > pos) { + break; + } + ++x; + } + + if (x == positions.end()) { + return; + } + + pl->freeze (); + pl->remove_region (r); + + while (x != positions.end()) { + + /* file start = original start + how far we from the initial position ? + */ + + nframes64_t file_start = r->start() + (pos - r->position()); + + /* length = next position - current position + */ + + nframes64_t len = (*x) - pos; + + /* XXX we do we really want to allow even single-sample regions? + shouldn't we have some kind of lower limit on region size? + */ + + if (len <= 0) { + break; + } + + string new_name; + + if (session->region_name (new_name, r->name())) { + break; + } + + /* do NOT announce new regions 1 by one, just wait till they are all done */ + + boost::shared_ptr nr = RegionFactory::create (r->sources(), file_start, len, new_name, 0, Region::DefaultFlags, false); + pl->add_region (nr, pos); + + pos += len; + ++x; + + if (*x > r->last_frame()) { + + /* add final fragment */ + + file_start = r->start() + (pos - r->position()); + len = r->last_frame() - pos; + + nr = RegionFactory::create (r->sources(), file_start, len, new_name, 0, Region::DefaultFlags); + pl->add_region (nr, pos); + + break; + } + } + + pl->thaw (); + + XMLNode& after (pl->get_state()); + + session->add_command (new MementoCommand(*pl, &before, &after)); +} + +void +Editor::tab_to_transient (bool forward) +{ + AnalysisFeatureList positions; + + if (!session) { + return; + } + + nframes64_t pos = session->audible_frame (); + + if (!selection->tracks.empty()) { + + for (TrackSelection::iterator t = selection->tracks.begin(); t != selection->tracks.end(); ++t) { + + RouteTimeAxisView* rtv = dynamic_cast (*t); + + if (rtv) { + boost::shared_ptr ds = rtv->get_diskstream(); + if (ds) { + boost::shared_ptr pl = rtv->get_diskstream()->playlist (); + if (pl) { + nframes64_t result = pl->find_next_transient (pos, forward ? 1 : -1); + + if (result >= 0) { + positions.push_back (result); + } + } + } + } + } + + } else { + + RegionSelection rs; + + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) { + (*r)->region()->get_transients (positions); + } + } + + TransientDetector::cleanup_transients (positions, session->frame_rate(), 3.0); + + if (forward) { + AnalysisFeatureList::iterator x; + + for (x = positions.begin(); x != positions.end(); ++x) { + if ((*x) > pos) { + break; + } + } + + if (x != positions.end ()) { + session->request_locate (*x); + } + + } else { + AnalysisFeatureList::reverse_iterator x; + + for (x = positions.rbegin(); x != positions.rend(); ++x) { + if ((*x) < pos) { + break; + } + } + + if (x != positions.rend ()) { + session->request_locate (*x); + } + } +} +void +Editor::playhead_forward_to_grid () +{ + if (!session) return; + nframes64_t pos = playhead_cursor->current_frame; + if (pos < max_frames - 1) { + pos += 2; + snap_to_internal (pos, 1, false); + session->request_locate (pos); + } +} + + +void +Editor::playhead_backward_to_grid () +{ + if (!session) return; + nframes64_t pos = playhead_cursor->current_frame; + if (pos > 2) { + pos -= 2; + snap_to_internal (pos, -1, false); + session->request_locate (pos); + } +} + +void +Editor::set_track_height (uint32_t h) +{ + TrackSelection& ts (selection->tracks); + + if (ts.empty()) { + return; + } + + for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) { + (*x)->set_height (h); + } +} + +void +Editor::set_track_height_largest () +{ + set_track_height (TimeAxisView::hLargest); +} +void +Editor::set_track_height_large () +{ + set_track_height (TimeAxisView::hLarge); +} +void +Editor::set_track_height_larger () +{ + set_track_height (TimeAxisView::hLarger); +} +void +Editor::set_track_height_normal () +{ + set_track_height (TimeAxisView::hNormal); +} +void +Editor::set_track_height_smaller () +{ + set_track_height (TimeAxisView::hSmaller); +} +void +Editor::set_track_height_small () +{ + set_track_height (TimeAxisView::hSmall); +} + +void +Editor::toggle_tracks_active () +{ + TrackSelection& ts (selection->tracks); + bool first = true; + bool target = false; + + if (ts.empty()) { + return; + } + + for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) { + RouteTimeAxisView* rtv = dynamic_cast(*x); + + if (rtv) { + if (first) { + target = !rtv->_route->active(); + first = false; + } + rtv->_route->set_active (target); + } + } +} + +void +Editor::remove_tracks () +{ + TrackSelection& ts (selection->tracks); + + if (ts.empty()) { + return; + } + + vector choices; + string prompt; + int ntracks = 0; + int nbusses = 0; + const char* trackstr; + const char* busstr; + vector > routes; + + for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) { + RouteTimeAxisView* rtv = dynamic_cast (*x); + if (rtv) { + if (rtv->is_track()) { + ntracks++; + } else { + nbusses++; + } + } + routes.push_back (rtv->_route); + } + + if (ntracks + nbusses == 0) { + return; + } + + if (ntracks > 1) { + trackstr = _("tracks"); + } else { + trackstr = _("track"); + } + + if (nbusses > 1) { + busstr = _("busses"); + } else { + busstr = _("bus"); + } + + if (ntracks) { + if (nbusses) { + prompt = string_compose (_("Do you really want to remove %1 %2 and %3 %4?\n" + "(You may also lose the playlists associated with the %2)\n\n" + "This action cannot be undone!"), + ntracks, trackstr, nbusses, busstr); + } else { + prompt = string_compose (_("Do you really want to remove %1 %2?\n" + "(You may also lose the playlists associated with the %2)\n\n" + "This action cannot be undone!"), + ntracks, trackstr); + } + } else if (nbusses) { + prompt = string_compose (_("Do you really want to remove %1 %2?"), + nbusses, busstr); + } + + choices.push_back (_("No, do nothing.")); + if (ntracks + nbusses > 1) { + choices.push_back (_("Yes, remove them.")); + } else { + choices.push_back (_("Yes, remove it.")); + } + + Choice prompter (prompt, choices); + + if (prompter.run () != 1) { + return; + } + + for (vector >::iterator x = routes.begin(); x != routes.end(); ++x) { + session->remove_route (*x); + } +} + +void +Editor::set_waveform_scale (WaveformScale ws) +{ + TrackSelection& ts (selection->tracks); + + if (ts.empty()) { + return; + } + + for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) { + AudioTimeAxisView* atv = dynamic_cast (*x); + if (atv) { + atv->set_waveform_scale (ws); + } + } +} + +void +Editor::do_insert_time () +{ + if (selection->tracks.empty()) { + return; + } + + nframes64_t pos = get_preferred_edit_position (); + ArdourDialog d (*this, _("Insert Time")); + VButtonBox button_box; + VBox option_box; + RadioButtonGroup group; + RadioButton leave_button (group, _("Stay in position")); + RadioButton move_button (group, _("Move")); + RadioButton split_button (group, _("Split & Later Section Moves")); + Label intersect_option_label (_("Intersected regions should:")); + CheckButton glue_button (_("Move Glued Regions")); + CheckButton marker_button (_("Move Markers")); + AudioClock clock ("insertTimeClock", true, X_("InsertTimeClock"), true, true, true); + HBox clock_box; + + clock.set (0); + clock.set_session (session); + clock.set_bbt_reference (pos); + + clock_box.pack_start (clock, false, true); + + option_box.set_spacing (6); + option_box.pack_start (intersect_option_label, false, false); + option_box.pack_start (button_box, false, false); + option_box.pack_start (glue_button, false, false); + option_box.pack_start (marker_button, false, false); + + button_box.pack_start (leave_button, false, false); + button_box.pack_start (move_button, false, false); + button_box.pack_start (split_button, false, false); + + d.get_vbox()->set_border_width (12); + d.get_vbox()->pack_start (clock_box, false, false); + d.get_vbox()->pack_start (option_box, false, false); + + leave_button.show (); + move_button.show (); + split_button.show (); + intersect_option_label.show (); + option_box.show (); + button_box.show (); + glue_button.show (); + clock.show_all(); + clock_box.show (); + marker_button.show (); + + d.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + d.add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK); + d.show (); + + int response = d.run (); + + if (response != RESPONSE_OK) { + return; + } + + nframes64_t distance = clock.current_duration (pos); + + if (distance == 0) { + return; + } + + InsertTimeOption opt; + + if (leave_button.get_active()) { + opt = LeaveIntersected; + } else if (move_button.get_active()) { + opt = MoveIntersected; + } else { + opt = SplitIntersected; + } + + insert_time (pos, distance, opt, glue_button.get_active(), marker_button.get_active()); +} + +void +Editor::insert_time (nframes64_t pos, nframes64_t frames, InsertTimeOption opt, + bool ignore_music_glue, bool markers_too) +{ + bool commit = false; + + if (Config->get_edit_mode() == Lock) { + return; + } + + begin_reversible_command (_("insert time")); + + for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) { + boost::shared_ptr pl = (*x)->playlist(); + + if (!pl) { + continue; + } + + XMLNode &before = pl->get_state(); + + if (opt == SplitIntersected) { + pl->split (pos); + } + + pl->shift (pos, frames, (opt == MoveIntersected), ignore_music_glue); + + XMLNode &after = pl->get_state(); + + session->add_command (new MementoCommand (*pl, &before, &after)); + commit = true; + } + + if (markers_too) { + bool moved = false; + XMLNode& before (session->locations()->get_state()); + Locations::LocationList copy (session->locations()->list()); + + for (Locations::LocationList::iterator i = copy.begin(); i != copy.end(); ++i) { + + Locations::LocationList::const_iterator tmp; + + if ((*i)->start() >= pos) { + (*i)->set_start ((*i)->start() + frames); + if (!(*i)->is_mark()) { + (*i)->set_end ((*i)->end() + frames); + } + moved = true; + } + } + + if (moved) { + XMLNode& after (session->locations()->get_state()); + session->add_command (new MementoCommand(*session->locations(), &before, &after)); + } + } + + if (commit) { + commit_reversible_command (); + } +} + +void +Editor::fit_tracks () +{ + if (selection->tracks.empty()) { + return; + } + + uint32_t child_heights = 0; + + for (TrackSelection::iterator t = selection->tracks.begin(); t != selection->tracks.end(); ++t) { + + if (!(*t)->marked_for_display()) { + continue; + } + + child_heights += ((*t)->effective_height - (*t)->current_height()); + } + + uint32_t h = (uint32_t) floor ((canvas_height - child_heights)/selection->tracks.size()); + double first_y_pos = DBL_MAX; + + undo_visual_stack.push_back (current_visual_state()); + + for (TrackSelection::iterator t = selection->tracks.begin(); t != selection->tracks.end(); ++t) { + (*t)->set_height (h); + first_y_pos = std::min ((*t)->y_position, first_y_pos); + } + + vertical_adjustment.set_value (first_y_pos); + + redo_visual_stack.push_back (current_visual_state()); +} + +void +Editor::save_visual_state (uint32_t n) +{ + while (visual_states.size() <= n) { + visual_states.push_back (0); + } + + if (visual_states[n] != 0) { + delete visual_states[n]; + } + + visual_states[n] = current_visual_state (true); + gdk_beep (); +} + +void +Editor::goto_visual_state (uint32_t n) +{ + if (visual_states.size() <= n) { + return; + } + + if (visual_states[n] == 0) { + return; + } + + use_visual_state (*visual_states[n]); +} + +void +Editor::start_visual_state_op (uint32_t n) +{ + cerr << "Start\n"; + if (visual_state_op_connection.empty()) { + cerr << "\tqueue\n"; + visual_state_op_connection = Glib::signal_timeout().connect (bind (mem_fun (*this, &Editor::end_visual_state_op), n), 1000); + } +} + +void +Editor::cancel_visual_state_op (uint32_t n) +{ + cerr << "Cancel\n"; + if (!visual_state_op_connection.empty()) { + cerr << "\tgoto\n"; + visual_state_op_connection.disconnect(); + goto_visual_state (n); + } +} + +bool +Editor::end_visual_state_op (uint32_t n) +{ + visual_state_op_connection.disconnect(); + save_visual_state (n); + + PopUp* pup = new PopUp (WIN_POS_MOUSE, 1000, true); + char buf[32]; + snprintf (buf, sizeof (buf), _("Saved view %u"), n+1); + pup->set_text (buf); + pup->touch(); + + return false; // do not call again +} +