diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index 91de090fb6..95345440cd 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -431,12 +431,13 @@ AudioRegionView::region_resized (const PropertyChange& what_changed) } } - /* hide transient lines that extend beyond the region end */ - + /* hide transient lines that extend beyond the region */ list >::iterator l; + framepos_t first = _region->first_frame(); + framepos_t last = _region->last_frame(); for (l = feature_lines.begin(); l != feature_lines.end(); ++l) { - if (l->first > _region->length() - 1) { + if (l->first < first || l->first >= last) { l->second->hide(); } else { l->second->show(); @@ -462,25 +463,34 @@ AudioRegionView::reset_width_dependent_items (double pixel_width) if (end_xfade_rect) { end_xfade_rect->set_outline (false); } } - AnalysisFeatureList analysis_features = _region->transients(); - AnalysisFeatureList::const_iterator i; + reset_fade_shapes (); - list >::iterator l; + /* Update feature lines */ + AnalysisFeatureList analysis_features; + _region->transients (analysis_features); - for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) { - - float x_pos = trackview.editor().sample_to_pixel (*i); - - (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0), - ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)); - - (*l).first = *i; - - (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0), - ArdourCanvas::Duple (x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)); + if (feature_lines.size () != analysis_features.size ()) { + cerr << "postponed freature line update.\n"; // XXX + // AudioRegionView::transients_changed () will pick up on this + return; } - reset_fade_shapes (); + framepos_t position = _region->position(); + + AnalysisFeatureList::const_iterator i; + list >::iterator l; + double y1; + if (_height >= NAME_HIGHLIGHT_THRESH) { + y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1; + } else { + y1 = _height - 1; + } + for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) { + float x_pos = trackview.editor().sample_to_pixel ((*i) - position); + (*l).first = *i; + (*l).second->set (ArdourCanvas::Duple (x_pos, 2.0), + ArdourCanvas::Duple (x_pos, y1)); + } } void @@ -557,20 +567,19 @@ AudioRegionView::set_height (gdouble height) reset_fade_shapes (); - /* Update hights for any active feature lines */ + /* Update heights for any feature lines */ + framepos_t position = _region->position(); list >::iterator l; - + double y1; + if (_height >= NAME_HIGHLIGHT_THRESH) { + y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1; + } else { + y1 = _height - 1; + } for (l = feature_lines.begin(); l != feature_lines.end(); ++l) { - - float pos_x = trackview.editor().sample_to_pixel((*l).first); - - if (height >= NAME_HIGHLIGHT_THRESH) { - (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0), - ArdourCanvas::Duple (pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)); - } else { - (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0), - ArdourCanvas::Duple (pos_x, _height - 1)); - } + float pos_x = trackview.editor().sample_to_pixel((*l).first - position); + (*l).second->set (ArdourCanvas::Duple (pos_x, 2.0), + ArdourCanvas::Duple (pos_x, y1)); } if (name_text) { @@ -1625,15 +1634,26 @@ AudioRegionView::show_region_editor () void AudioRegionView::transients_changed () { - AnalysisFeatureList analysis_features = _region->transients(); + AnalysisFeatureList analysis_features; + _region->transients (analysis_features); + framepos_t position = _region->position(); + framepos_t first = _region->first_frame(); + framepos_t last = _region->last_frame(); + + double y1; + if (_height >= NAME_HIGHLIGHT_THRESH) { + y1 = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1; + } else { + y1 = _height - 1; + } while (feature_lines.size() < analysis_features.size()) { - ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(group); CANVAS_DEBUG_NAME (canvas_item, string_compose ("transient group for %1", region()->name())); + canvas_item->set_outline_color (UIConfiguration::instance().color ("zero line")); // also in Editor::leave_handler() canvas_item->set (ArdourCanvas::Duple (-1.0, 2.0), - ArdourCanvas::Duple (1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1)); + ArdourCanvas::Duple (1.0, y1)); canvas_item->raise_to_top (); canvas_item->show (); @@ -1656,15 +1676,21 @@ AudioRegionView::transients_changed () for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) { float *pos = new float; - *pos = trackview.editor().sample_to_pixel (*i); + *pos = trackview.editor().sample_to_pixel (*i - position); (*l).second->set ( ArdourCanvas::Duple (*pos, 2.0), - ArdourCanvas::Duple (*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1) + ArdourCanvas::Duple (*pos, y1) ); - (*l).second->set_data ("position", pos); + (*l).second->set_data ("position", pos); // is this *modified* (drag?), if not use *i (*l).first = *i; + + if (l->first < first || l->first >= last) { + l->second->hide(); + } else { + l->second->show(); + } } } @@ -1681,28 +1707,27 @@ AudioRegionView::update_transient(float /*old_pos*/, float new_pos) float* pos = (float*) (*l).second->get_data ("position"); if (rint(new_pos) == rint(*pos)) { - + framepos_t position = _region->position(); framepos_t old_frame = (*l).first; - framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos); - + framepos_t new_frame = trackview.editor().pixel_to_sample (new_pos) + position; _region->update_transient (old_frame, new_frame); - break; } } } void -AudioRegionView::remove_transient(float pos) +AudioRegionView::remove_transient (float pos) { - /* Find frame at old pos, calulate new frame then update region transients*/ + /* this is called from Editor::remove_transient () with pos == get_data ("position") + * which is the item's x-coordinate inside the ARV. + * + * Find frame at old pos, calulate new frame then update region transients + */ list >::iterator l; for (l = feature_lines.begin(); l != feature_lines.end(); ++l) { - - /* Line has been updated in drag so we compare to new_pos */ float *line_pos = (float*) (*l).second->get_data ("position"); - if (rint(pos) == rint(*line_pos)) { _region->remove_transient ((*l).first); break; diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index d538652335..a2ded69bea 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -6581,7 +6581,8 @@ Editor::split_region_at_transients () boost::shared_ptr ar = boost::dynamic_pointer_cast ((*i)->region()); - if (ar && (ar->get_transients (positions) == 0)) { + if (ar) { + ar->transients (positions); split_region_at_points ((*i)->region(), positions, true); positions.clear (); } @@ -6610,7 +6611,6 @@ Editor::split_region_at_points (boost::shared_ptr r, AnalysisFeatureList return; } - if (positions.size() > 20 && can_ferret) { std::string 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, @@ -6663,27 +6663,28 @@ Editor::split_region_at_points (boost::shared_ptr r, AnalysisFeatureList framepos_t pos = 0; + framepos_t rstart = r->first_frame (); + framepos_t rend = r->last_frame (); + while (x != positions.end()) { /* deal with positons that are out of scope of present region bounds */ - if (*x <= 0 || *x > r->length()) { + if (*x <= rstart || *x > rend) { ++x; continue; } - /* file start = original start + how far we from the initial position ? - */ + /* file start = original start + how far we from the initial position ? */ framepos_t file_start = r->start() + pos; - /* length = next position - current position - */ + /* length = next position - current position */ - framepos_t len = (*x) - pos; + framepos_t len = (*x) - pos - rstart; /* XXX we do we really want to allow even single-sample regions? - shouldn't we have some kind of lower limit on region size? - */ + * shouldn't we have some kind of lower limit on region size? + */ if (len <= 0) { break; @@ -6703,14 +6704,15 @@ Editor::split_region_at_points (boost::shared_ptr r, AnalysisFeatureList plist.add (ARDOUR::Properties::length, len); plist.add (ARDOUR::Properties::name, new_name); plist.add (ARDOUR::Properties::layer, 0); + // TODO set transients_offset boost::shared_ptr nr = RegionFactory::create (r->sources(), plist, false); /* because we set annouce to false, manually add the new region to the - RegionFactory map - */ + * RegionFactory map + */ RegionFactory::map_add (nr); - pl->add_region (nr, r->position() + pos); + pl->add_region (nr, rstart + pos); if (select_new) { new_regions.push_front(nr); @@ -6780,8 +6782,7 @@ Editor::place_transient() begin_reversible_command (_("place transient")); for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) { - framepos_t position = (*r)->region()->position(); - (*r)->region()->add_transient(where - position); + (*r)->region()->add_transient(where); } commit_reversible_command (); diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc index 4386b22877..64d17f9ae5 100644 --- a/gtk2_ardour/editor_selection.cc +++ b/gtk2_ardour/editor_selection.cc @@ -1116,6 +1116,7 @@ Editor::sensitize_the_right_region_actions () bool have_inactive_fade_out = false; bool have_active_fade_in = false; bool have_active_fade_out = false; + bool have_transients = false; for (list::const_iterator i = rs.begin(); i != rs.end(); ++i) { @@ -1171,6 +1172,10 @@ Editor::sensitize_the_right_region_actions () have_not_at_natural_position = true; } + if (r->has_transients ()){ + have_transients = true; + } + if (ar) { if (ar->envelope_active()) { have_envelope_active = true; @@ -1196,6 +1201,8 @@ Editor::sensitize_the_right_region_actions () } } + _region_actions->get_action("split-region-at-transients")->set_sensitive (have_transients); + if (rs.size() > 1) { _region_actions->get_action("show-region-list-editor")->set_sensitive (false); _region_actions->get_action("show-region-properties")->set_sensitive (false); diff --git a/gtk2_ardour/rhythm_ferret.cc b/gtk2_ardour/rhythm_ferret.cc index 57e7632e21..7b1ba19782 100644 --- a/gtk2_ardour/rhythm_ferret.cc +++ b/gtk2_ardour/rhythm_ferret.cc @@ -225,7 +225,7 @@ RhythmFerret::run_analysis () break; } - (*i)->region()->set_transients (current_results); + (*i)->region()->set_onsets (current_results); current_results.clear(); } } @@ -360,7 +360,7 @@ RhythmFerret::do_split_action () for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) { AnalysisFeatureList features; - features = (*i)->region()->transients(); + (*i)->region()->transients(features); merged_features.insert (merged_features.end(), features.begin(), features.end()); } @@ -407,7 +407,7 @@ RhythmFerret::clear_transients () current_results.clear (); for (RegionSelection::iterator i = regions_with_transients.begin(); i != regions_with_transients.end(); ++i) { - (*i)->region()->set_transients (current_results); + (*i)->region()->set_onsets (current_results); } regions_with_transients.clear ();