add trim to loop/punch; fixup trim start/end to EP to work with new paradigm

git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2622 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2007-11-12 17:26:34 +00:00
parent 0901000abb
commit fd5ee963cc
5 changed files with 236 additions and 25 deletions

View file

@ -145,6 +145,14 @@
<menuitem action='align-regions-end-relative'/>
<menuitem action='align-regions-sync'/>
<menuitem action='align-regions-sync-relative'/>
<separator/>
<menuitem action='set-fade-in-length'/>
<menuitem action='set-fade-out-length'/>
<separator/>
<menuitem action='trim-from-start'/>
<menuitem action='trim-to-end'/>
<menuitem action='trim-region-to-loop'/>
<menuitem action='trim-region-to-punch'/>
</menu>
<menu name='View' action = 'View'>
<menu name='ZoomFocus' action='ZoomFocus'>

View file

@ -1820,6 +1820,8 @@ Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr<Region>
trim_items.push_back (MenuElem (_("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point)));
trim_items.push_back (MenuElem (_("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point)));
trim_items.push_back (MenuElem (_("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop)));
trim_items.push_back (MenuElem (_("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch)));
items.push_back (MenuElem (_("Trim"), *trim_menu));
items.push_back (SeparatorElem());
@ -4105,3 +4107,15 @@ Editor::get_regions_at (nframes64_t where, const TrackSelection& ts) const
return rs;
}
RegionSelection&
Editor::get_regions_for_action ()
{
if (!selection->regions.empty()) {
return selection->regions;
}
nframes64_t where = get_preferred_edit_position();
tmp_regions = get_regions_at (where, selection->tracks);
return tmp_regions;
}

View file

@ -1132,6 +1132,8 @@ class Editor : public PublicEditor
void set_fade_in_shape (ARDOUR::AudioRegion::FadeShape);
void set_fade_out_shape (ARDOUR::AudioRegion::FadeShape);
void set_fade_length (bool in);
void set_fade_in_active (bool);
void set_fade_out_active (bool);
@ -1626,6 +1628,9 @@ class Editor : public PublicEditor
void trim_region_to_edit_point ();
void trim_region_from_edit_point ();
void trim_region_to_loop ();
void trim_region_to_punch ();
void trim_region_to_location (const ARDOUR::Location&, const char* cmd);
bool show_gain_after_trim;
@ -1928,6 +1933,10 @@ class Editor : public PublicEditor
bool get_edit_op_range (nframes64_t& start, nframes64_t& end) const;
RegionSelection get_regions_at (nframes64_t where, const TrackSelection& ts) const;
RegionSelection tmp_regions;
RegionSelection& get_regions_for_action ();
};

View file

@ -199,6 +199,21 @@ Editor::register_actions ()
act = ActionManager::register_action (editor_actions, "edit-to-playhead", _("Edit to Playhead"), bind (mem_fun(*this, &Editor::cursor_align), false));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_action (editor_actions, "trim-from-start", _("Start to edit point"), mem_fun(*this, &Editor::trim_region_from_edit_point));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_action (editor_actions, "trim-to-end", _("Edit point to end"), mem_fun(*this, &Editor::trim_region_to_edit_point));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_action (editor_actions, "trim-region-to-loop", _("Trim To Loop"), mem_fun(*this, &Editor::trim_region_to_loop));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_action (editor_actions, "trim-region-to-punch", _("Trim To Punch"), mem_fun(*this, &Editor::trim_region_to_punch));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_action (editor_actions, "set-fade-in-length", _("Set Fade In Length"), bind (mem_fun(*this, &Editor::set_fade_length), true));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_action (editor_actions, "set-fade-out-length", _("Set Fade Out Length"), bind (mem_fun(*this, &Editor::set_fade_length), false));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_action (editor_actions, "align-regions-start", _("Align Regions Start"), bind (mem_fun(*this, &Editor::align), ARDOUR::Start));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_action (editor_actions, "align-regions-start-relative", _("Align Regions Start Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::Start));

View file

@ -2725,54 +2725,155 @@ Editor::align_region_internal (boost::shared_ptr<Region> region, RegionPoint poi
}
void
Editor::trim_region_to_edit_point ()
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"));
}
boost::shared_ptr<Region> region (clicked_regionview->region());
void
Editor::trim_region_to_punch ()
{
Location* loc = session->locations()->auto_punch_location();
if (!loc) {
return;
}
trim_region_to_location (*loc, _("trim to punch"));
}
float speed = 1.0f;
AudioTimeAxisView *atav;
void
Editor::trim_region_to_location (const Location& loc, const char* str)
{
RegionSelection& rs (get_regions_for_action ());
begin_reversible_command (str);
for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*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<AudioTimeAxisView*> (&arv->get_time_axis_view());
if (!atav) {
return;
}
float speed = 1.0;
nframes_t start;
nframes_t end;
if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
if (atav->get_diskstream() != 0) {
speed = atav->get_diskstream()->speed();
}
}
begin_reversible_command (_("trim to edit"));
XMLNode &before = region->playlist()->get_state();
region->trim_end( session_frame_to_track_frame(get_preferred_edit_position(), speed), this);
XMLNode &after = region->playlist()->get_state();
session->add_command(new MementoCommand<Playlist>(*(region->playlist()), &before, &after));
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<Playlist>(*(arv->region()->playlist()), &before, &after));
}
commit_reversible_command ();
}
void
Editor::trim_region_to_edit_point ()
{
RegionSelection& rs (get_regions_for_action ());
nframes64_t where = get_preferred_edit_position();
begin_reversible_command (_("trim region start to edit point"));
for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*x);
if (!arv) {
continue;
}
/* require region to cover trim */
if (!arv->region()->covers (where)) {
continue;
}
AudioTimeAxisView* atav = dynamic_cast<AudioTimeAxisView*> (&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_end( session_frame_to_track_frame(where, speed), this);
XMLNode &after = arv->region()->playlist()->get_state();
session->add_command(new MementoCommand<Playlist>(*(arv->region()->playlist()), &before, &after));
}
commit_reversible_command ();
}
void
Editor::trim_region_from_edit_point ()
{
if (clicked_regionview == 0) {
return;
}
RegionSelection& rs (get_regions_for_action ());
nframes64_t where = get_preferred_edit_position();
boost::shared_ptr<Region> region (clicked_regionview->region());
begin_reversible_command (_("trim region end to edit point"));
float speed = 1.0f;
AudioTimeAxisView *atav;
for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
AudioRegionView* arv = dynamic_cast<AudioRegionView*> (*x);
if (!arv) {
continue;
}
/* require region to cover trim */
if (!arv->region()->covers (where)) {
continue;
}
AudioTimeAxisView* atav = dynamic_cast<AudioTimeAxisView*> (&arv->get_time_axis_view());
if (!atav) {
return;
}
float speed = 1.0;
if ( clicked_trackview != 0 && (atav = dynamic_cast<AudioTimeAxisView*>(clicked_trackview)) != 0 ) {
if (atav->get_diskstream() != 0) {
speed = atav->get_diskstream()->speed();
}
}
begin_reversible_command (_("trim to edit"));
XMLNode &before = region->playlist()->get_state();
region->trim_front ( session_frame_to_track_frame(get_preferred_edit_position(), speed), this);
XMLNode &after = region->playlist()->get_state();
session->add_command(new MementoCommand<Playlist>(*(region->playlist()), &before, &after));
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<Playlist>(*(arv->region()->playlist()), &before, &after));
}
commit_reversible_command ();
}
@ -3740,6 +3841,70 @@ Editor::toggle_region_opaque ()
}
}
void
Editor::set_fade_length (bool in)
{
/* we need a region to measure the offset from the start */
RegionView* rv;
if (entered_regionview) {
rv = entered_regionview;
} else if (!selection->regions.empty()) {
rv = selection->regions.front();
} else {
return;
}
nframes64_t pos = get_preferred_edit_position();
nframes_t len;
char* cmd;
if (in) {
if (pos <= rv->region()->start()) {
/* can't do it */
return;
}
len = pos - rv->region()->start();
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);
cerr << "start " << cmd << " with len = " << len << endl;
RegionSelection& rs (get_regions_for_action());
for (RegionSelection::iterator x = rs.begin(); x != rs.end(); ++x) {
AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (*x);
if (!tmp) {
return;
}
AutomationList& alist = tmp->audio_region()->fade_in();
XMLNode &before = alist.get_state();
if (in) {
tmp->audio_region()->set_fade_in_length (len);
} else {
tmp->audio_region()->set_fade_out_length (len);
}
XMLNode &after = alist.get_state();
session->add_command(new MementoCommand<AutomationList>(alist, &before, &after));
}
commit_reversible_command ();
}
void
Editor::set_fade_in_shape (AudioRegion::FadeShape shape)
{