return two iterators into the Bars|Beats list of the tempo map rather than making...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 3 Jan 2012 18:43:58 +0000 (18:43 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 3 Jan 2012 18:43:58 +0000 (18:43 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11146 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_rulers.cc
gtk2_ardour/editor_tempodisplay.cc
gtk2_ardour/tempo_lines.cc
gtk2_ardour/tempo_lines.h
libs/ardour/ardour/tempo.h
libs/ardour/session_click.cc
libs/ardour/tempo.cc

index 6e2c311704af734ef0048aaa0c37962cae6a9a9f..dff3ae3e15ffa525ba64ac31eba9f87cf72c66be 100644 (file)
@@ -5334,7 +5334,7 @@ Editor::session_going_away ()
        hide_measures ();
        clear_marker_display ();
 
-       current_bbt_points.clear ();
+       current_bbt_points_begin = current_bbt_points_end;
 
        /* get rid of any existing editor mixer strip */
 
index 6c099899d8b960ba45fa448c7f238f69a51861ce..926baae64134a9a198dbb11993f27784385c7e15 100644 (file)
@@ -1451,7 +1451,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        /// true if we scroll the tracks rather than the playhead
        bool _stationary_playhead;
 
-       ARDOUR::TempoMap::BBTPointList current_bbt_points;
+       ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_begin;
+       ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_end;
 
        TempoLines* tempo_lines;
 
index 36eb84797fc746d0ab963caf89a7be4c7adb4aa3..1d5dac091bbc14c0d18d16004a3eda2d8ad18af0 100644 (file)
@@ -1147,7 +1147,8 @@ Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper)
        if (_session == 0) {
                return;
        }
-       TempoMap::BBTPointList::iterator i;
+
+       TempoMap::BBTPointList::const_iterator i;
        Timecode::BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
 
        _session->bbt_time (lower, lower_beat);
@@ -1224,18 +1225,18 @@ Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper)
                break;
        }
 
-       if (current_bbt_points.empty()) {
+       if (distance (current_bbt_points_begin, current_bbt_points_end) == 0) {
                return;
        }
 
-       i = current_bbt_points.end();
+       i = current_bbt_points_end;
        i--;
-       if ((*i).beat >= (*current_bbt_points.begin()).beat) {
-               bbt_bars = (*i).bar - (*current_bbt_points.begin()).bar;
+       if ((*i).beat >= (*current_bbt_points_begin).beat) {
+               bbt_bars = (*i).bar - (*current_bbt_points_begin).bar;
        } else {
-               bbt_bars = (*i).bar - (*current_bbt_points.begin()).bar - 1;
+               bbt_bars = (*i).bar - (*current_bbt_points_begin).bar - 1;
        }
-       beats = current_bbt_points.size() - bbt_bars;
+       beats = distance (current_bbt_points_begin, current_bbt_points_end) - bbt_bars;
 
        /* Only show the bar helper if there aren't many bars on the screen */
        if ((bbt_bars < 2) || (beats < 5)) {
@@ -1272,7 +1273,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
                return 0;
        }
 
-       TempoMap::BBTPointList::iterator i;
+       TempoMap::BBTPointList::const_iterator i;
 
        char buf[64];
        gint  n = 0;
@@ -1291,14 +1292,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
        bool i_am_accented = false;
        bool helper_active = false;
 
-       if (current_bbt_points.empty()) {
+       if (distance (current_bbt_points_begin, current_bbt_points_end) == 0) {
                return 0;
        }
 
        switch (bbt_ruler_scale) {
 
        case bbt_show_beats:
-               beats = current_bbt_points.size();
+               beats = distance (current_bbt_points_begin, current_bbt_points_end);
                bbt_nmarks = beats + 2;
 
                *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
@@ -1306,8 +1307,8 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
                (*marks)[0].label = g_strdup(" ");
                (*marks)[0].position = lower;
                (*marks)[0].style = GtkCustomRulerMarkMicro;
-
-               for (n = 1,   i = current_bbt_points.begin(); n < bbt_nmarks && i != current_bbt_points.end(); ++i) {
+               
+               for (n = 1, i = current_bbt_points_begin; n < bbt_nmarks && i != current_bbt_points_end; ++i) {
 
                        if ((*i).frame < lower && (bbt_bar_helper_on)) {
                                snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
@@ -1334,7 +1335,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
 
        case bbt_show_ticks:
 
-               beats = current_bbt_points.size();
+               beats = distance (current_bbt_points_begin, current_bbt_points_end);
                bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
 
                bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
@@ -1344,7 +1345,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
                (*marks)[0].position = lower;
                (*marks)[0].style = GtkCustomRulerMarkMicro;
 
-               for (n = 1,   i = current_bbt_points.begin(); n < bbt_nmarks && i != current_bbt_points.end(); ++i) {
+               for (n = 1, i = current_bbt_points_begin; n < bbt_nmarks && i != current_bbt_points_end; ++i) {
 
                        if ((*i).frame < lower && (bbt_bar_helper_on)) {
                                snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
@@ -1424,7 +1425,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
 
        case bbt_show_ticks_detail:
 
-               beats = current_bbt_points.size();
+               beats = distance (current_bbt_points_begin, current_bbt_points_end);
                bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
 
                bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
@@ -1434,7 +1435,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
                (*marks)[0].position = lower;
                (*marks)[0].style = GtkCustomRulerMarkMicro;
 
-               for (n = 1,   i = current_bbt_points.begin(); n < bbt_nmarks && i != current_bbt_points.end(); ++i) {
+               for (n = 1,   i = current_bbt_points_begin; n < bbt_nmarks && i != current_bbt_points_end; ++i) {
 
                        if ((*i).frame < lower && (bbt_bar_helper_on)) {
                                snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
@@ -1519,7 +1520,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
 
        case bbt_show_ticks_super_detail:
 
-               beats = current_bbt_points.size();
+               beats = distance (current_bbt_points_begin, current_bbt_points_end);
                bbt_nmarks = (beats + 2) * bbt_beat_subdivision;
 
                bbt_position_of_helper = lower + (30 * Editor::get_current_zoom ());
@@ -1529,7 +1530,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
                (*marks)[0].position = lower;
                (*marks)[0].style = GtkCustomRulerMarkMicro;
 
-               for (n = 1,   i = current_bbt_points.begin(); n < bbt_nmarks && i != current_bbt_points.end(); ++i) {
+               for (n = 1,   i = current_bbt_points_begin; n < bbt_nmarks && i != current_bbt_points_end; ++i) {
 
                        if ((*i).frame < lower && (bbt_bar_helper_on)) {
                                  snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
@@ -1626,7 +1627,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
        case bbt_show_64:
                        bbt_nmarks = (gint) (bbt_bars / 64) + 1;
                        *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
-                       for (n = 0,   i = current_bbt_points.begin(); i != current_bbt_points.end() && n < bbt_nmarks; i++) {
+                       for (n = 0,   i = current_bbt_points_begin; i != current_bbt_points_end && n < bbt_nmarks; i++) {
                                if ((*i).type == TempoMap::Bar)  {
                                        if ((*i).bar % 64 == 1) {
                                                if ((*i).bar % 256 == 1) {
@@ -1651,7 +1652,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
        case bbt_show_16:
                        bbt_nmarks = (bbt_bars / 16) + 1;
                *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
-               for (n = 0,  i = current_bbt_points.begin(); i != current_bbt_points.end() && n < bbt_nmarks; i++) {
+               for (n = 0,  i = current_bbt_points_begin; i != current_bbt_points_end && n < bbt_nmarks; i++) {
                        if ((*i).type == TempoMap::Bar)  {
                          if ((*i).bar % 16 == 1) {
                                if ((*i).bar % 64 == 1) {
@@ -1676,7 +1677,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
        case bbt_show_4:
                bbt_nmarks = (bbt_bars / 4) + 1;
                *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks);
-               for (n = 0,   i = current_bbt_points.begin(); i != current_bbt_points.end() && n < bbt_nmarks; ++i) {
+               for (n = 0,   i = current_bbt_points_begin; i != current_bbt_points_end && n < bbt_nmarks; ++i) {
                        if ((*i).type == TempoMap::Bar)  {
                          if ((*i).bar % 4 == 1) {
                                if ((*i).bar % 16 == 1) {
@@ -1702,7 +1703,7 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
   //   default:
                bbt_nmarks = bbt_bars + 2;
                *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * bbt_nmarks );
-               for (n = 0,  i = current_bbt_points.begin(); i != current_bbt_points.end() && n < bbt_nmarks; i++) {
+               for (n = 0,  i = current_bbt_points_begin; i != current_bbt_points_end && n < bbt_nmarks; i++) {
                        if ((*i).type == TempoMap::Bar)  {
                          if ((*i).bar % 4 == 1) {
                                        snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
index 79f5caf82bb1853e3549f48cb3b5c3bdb153ba20..25fb5acbe76a298005be230989334e9ff9441468 100644 (file)
@@ -169,8 +169,7 @@ Editor::compute_current_bbt_points (framepos_t leftmost, framepos_t rightmost)
        }
        next_beat.ticks = 0;
 
-       current_bbt_points.clear();
-       _session->tempo_map().map (current_bbt_points, _session->tempo_map().frame_time (previous_beat), _session->tempo_map().frame_time (next_beat) + 1);
+       _session->tempo_map().map (current_bbt_points_begin, current_bbt_points_end, _session->tempo_map().frame_time (previous_beat), _session->tempo_map().frame_time (next_beat) + 1);
 }
 
 void
@@ -190,7 +189,7 @@ Editor::redraw_measures ()
 void
 Editor::draw_measures ()
 {
-       if (_session == 0 || _show_measures == false || current_bbt_points.empty()) {
+       if (_session == 0 || _show_measures == false || distance (current_bbt_points_begin, current_bbt_points_end) == 0) {
                return;
        }
 
@@ -198,7 +197,7 @@ Editor::draw_measures ()
                tempo_lines = new TempoLines(*track_canvas, time_line_group, physical_screen_height(get_window()));
        }
 
-       tempo_lines->draw (current_bbt_points, frames_per_unit);
+       tempo_lines->draw (current_bbt_points_begin, current_bbt_points_end, frames_per_unit);
 }
 
 void
index cab185026f997e177c2bb8c666daeca360893cbb..1ee73c72809c1d5872c9aae6f33eafbd97bf88a2 100644 (file)
@@ -71,9 +71,11 @@ TempoLines::hide ()
 }
 
 void
-TempoLines::draw (ARDOUR::TempoMap::BBTPointList& points, double frames_per_unit)
+TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin, 
+                 const ARDOUR::TempoMap::BBTPointList::const_iterator& end, 
+                 double frames_per_unit)
 {
-       ARDOUR::TempoMap::BBTPointList::iterator i;
+       ARDOUR::TempoMap::BBTPointList::const_iterator i;
        ArdourCanvas::SimpleLine *line = NULL;
        gdouble xpos;
        double who_cares;
@@ -83,16 +85,16 @@ TempoLines::draw (ARDOUR::TempoMap::BBTPointList& points, double frames_per_unit
        uint32_t bars = 0;
        uint32_t color;
 
-       const size_t needed = points.size();
+       const size_t needed = distance (begin, end);
 
        _canvas.get_scroll_region (x1, y1, x2, who_cares);
 
        /* get the first bar spacing */
 
-       i = points.end();
+       i = end;
        i--;
-       bars = (*i).bar - (*points.begin()).bar;
-       beats = points.size() - bars;
+       bars = (*i).bar - (*begin).bar;
+       beats = distance (begin, end) - bars;
 
        beat_density = (beats * 10.0f) / _canvas.get_width ();
 
@@ -105,7 +107,7 @@ TempoLines::draw (ARDOUR::TempoMap::BBTPointList& points, double frames_per_unit
        xpos = rint(((framepos_t)(*i).frame) / (double)frames_per_unit);
        const double needed_right = xpos;
 
-       i = points.begin();
+       i = begin;
 
        xpos = rint(((framepos_t)(*i).frame) / (double)frames_per_unit);
        const double needed_left = xpos;
@@ -129,7 +131,7 @@ TempoLines::draw (ARDOUR::TempoMap::BBTPointList& points, double frames_per_unit
        bool inserted_last_time = true;
        bool invalidated = false;
 
-       for (i = points.begin(); i != points.end(); ++i) {
+       for (i = begin; i != end; ++i) {
 
                if ((*i).type == ARDOUR::TempoMap::Bar) {
                        color = ARDOUR_UI::config()->canvasvar_MeasureLineBar.get();
index 0991ba7559c9078e9a073737235e6f1241077943..1ab71e0681e1194e42ca85f0dbc080935b1a1b0c 100644 (file)
@@ -39,7 +39,9 @@ public:
 
        void tempo_map_changed();
 
-       void draw(ARDOUR::TempoMap::BBTPointList& points, double frames_per_unit);
+       void draw(const ARDOUR::TempoMap::BBTPointList::const_iterator& begin, 
+                 const ARDOUR::TempoMap::BBTPointList::const_iterator& end, 
+                 double frames_per_unit);
 
        void show();
        void hide();
index 8b1cfe690912283531fad8f687e5cf0a8ac68f10..ff21d880f23c2305bf61cfc2f8d8abbbbb9a10d6 100644 (file)
@@ -227,7 +227,9 @@ class TempoMap : public PBD::StatefulDestructible
        }
 
        const BBTPointList& map() const { return _map ; }
-       void map (BBTPointList&, framepos_t start, framepos_t end);
+
+       void map (BBTPointList::const_iterator&, BBTPointList::const_iterator&, 
+                 framepos_t start, framepos_t end);
        
        void      bbt_time (framepos_t when, Timecode::BBT_Time&);
         framecnt_t frame_time (const Timecode::BBT_Time&);
index 86a5d4ad788d9bf26b441557457fc2df4f39cb70..083f8055f952e20fed5eb96c8af1d461a7905a19 100644 (file)
@@ -41,7 +41,8 @@ Pool Click::pool ("click", sizeof (Click), 128);
 void
 Session::click (framepos_t start, framecnt_t nframes)
 {
-       TempoMap::BBTPointList points;
+       TempoMap::BBTPointList::const_iterator points_begin;
+       TempoMap::BBTPointList::const_iterator points_end;
        Sample *buf;
 
        if (_click_io == 0) {
@@ -59,13 +60,13 @@ Session::click (framepos_t start, framecnt_t nframes)
 
        BufferSet& bufs = get_scratch_buffers(ChanCount(DataType::AUDIO, 1));
        buf = bufs.get_audio(0).data();
-       _tempo_map->map (points, start, end);
+       _tempo_map->map (points_begin, points_end, start, end);
 
-       if (points.empty()) {
+       if (distance (points_begin, points_end) == 0) {
                goto run_clicks;
        }
 
-       for (TempoMap::BBTPointList::iterator i = points.begin(); i != points.end(); ++i) {
+       for (TempoMap::BBTPointList::const_iterator i = points_begin; i != points_end; ++i) {
                switch ((*i).type) {
                case TempoMap::Beat:
                        if (click_emphasis_data == 0 || (click_emphasis_data && (*i).beat != 1)) {
index 457e324c73115fea16917bff3833b2f92af2ffe2..0dd5634f952472e61b03d07ebaca19143d8b2643 100644 (file)
@@ -1409,21 +1409,16 @@ TempoMap::round_to_type (framepos_t frame, int dir, BBTPointType type)
 }
 
 void
-TempoMap::map (TempoMap::BBTPointList& points, framepos_t lower, framepos_t upper) 
+TempoMap::map (TempoMap::BBTPointList::const_iterator& begin, 
+              TempoMap::BBTPointList::const_iterator& end, 
+              framepos_t lower, framepos_t upper) 
 {
        if (_map.empty() || upper >= _map.back().frame) {
                recompute_map (false, upper);
        }
 
-       for (BBTPointList::const_iterator i = _map.begin(); i != _map.end(); ++i) {
-               if ((*i).frame < lower) {
-                       continue;
-               }
-               if ((*i).frame >= upper) {
-                       break;
-               }
-               points.push_back (*i);
-       }
+       begin = lower_bound (_map.begin(), _map.end(), lower);
+       end = upper_bound (_map.begin(), _map.end(), upper);
 }
 
 const TempoSection&