packaging tweaks for OS X
[ardour.git] / gtk2_ardour / editor_rulers.cc
index 9d4ad2be66139cfc9309b5d54e048028211f8d87..ea5622e4c963c77404e3ea0a02c725f7a5e36c88 100644 (file)
@@ -32,7 +32,8 @@
 #include "ardour/session.h"
 #include "ardour/tempo.h"
 #include "ardour/profile.h"
-#include <gtkmm2ext/gtk_ui.h>
+
+#include "gtkmm2ext/gtk_ui.h"
 
 #include "editor.h"
 #include "editing.h"
@@ -223,8 +224,6 @@ Editor::ruler_button_press (GdkEventButton* ev)
                return false;
        }
 
-       // jlc: grab ev->window ?
-       //Gtk::Main::grab_add (*minsec_ruler);
        Widget * grab_widget = 0;
 
        if (timecode_ruler->is_realized() && ev->window == timecode_ruler->get_window()->gobj()) {
@@ -1149,7 +1148,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);
@@ -1221,23 +1221,31 @@ Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper)
                 bbt_beat_subdivision = 32;
                bbt_accent_modulo = 8;
                break;
+       case SnapToBeatDiv64:
+                bbt_beat_subdivision = 64;
+               bbt_accent_modulo = 8;
+               break;
+       case SnapToBeatDiv128:
+                bbt_beat_subdivision = 128;
+               bbt_accent_modulo = 8;
+               break;
        default:
                 bbt_beat_subdivision = 4;
                break;
        }
 
-       if (current_bbt_points == 0 || 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)) {
@@ -1262,7 +1270,7 @@ Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper)
                bbt_ruler_scale =  bbt_show_ticks_detail;
        }
 
-       if ((bbt_ruler_scale == bbt_show_ticks_detail) && (lower_beat.beats == upper_beat.beats) && (upper_beat.ticks - lower_beat.ticks <= Timecode::BBT_Time::ticks_per_bar_division / 4)) {
+       if ((bbt_ruler_scale == bbt_show_ticks_detail) && (lower_beat.beats == upper_beat.beats) && (upper_beat.ticks - lower_beat.ticks <= Timecode::BBT_Time::ticks_per_beat / 4)) {
                bbt_ruler_scale =  bbt_show_ticks_super_detail;
        }
 }
@@ -1274,7 +1282,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;
@@ -1293,14 +1301,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
        bool i_am_accented = false;
        bool helper_active = false;
 
-       if (current_bbt_points == 0 || 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);
@@ -1308,18 +1316,16 @@ 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).type != TempoMap::Beat) {
-                               continue;
-                       }
                        if ((*i).frame < lower && (bbt_bar_helper_on)) {
                                snprintf (buf, sizeof(buf), "<%" PRIu32 "|%" PRIu32, (*i).bar, (*i).beat);
                                (*marks)[0].label = g_strdup (buf);
                                helper_active = true;
                        } else {
 
-                               if ((*i).beat == 1) {
+                               if ((*i).is_bar()) {
                                        (*marks)[n].style = GtkCustomRulerMarkMajor;
                                        snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
                                } else if (((*i).beat % 2 == 1)) {
@@ -1338,7 +1344,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 ());
@@ -1348,17 +1354,15 @@ 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) {
-                       if  ((*i).type != TempoMap::Beat) {
-                               continue;
-                       }
+               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);
                                (*marks)[0].label = g_strdup (buf);
                                helper_active = true;
                        } else {
 
-                               if ((*i).beat == 1) {
+                               if ((*i).is_bar()) {
                                        (*marks)[n].style = GtkCustomRulerMarkMajor;
                                        snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
                                } else {
@@ -1391,14 +1395,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
 
                        frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() *  60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
                        frame_skip_error -= frame_skip;
-                       skip = (uint32_t) (Timecode::BBT_Time::ticks_per_bar_division / bbt_beat_subdivision);
+                       skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
 
                        pos = (*i).frame + frame_skip;
                        accumulated_error = frame_skip_error;
 
                        tick = skip;
 
-                       for (t = 0; (tick < Timecode::BBT_Time::ticks_per_bar_division) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
+                       for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
 
                                if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
                                        i_am_accented = true;
@@ -1430,7 +1434,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 ());
@@ -1440,17 +1444,15 @@ 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) {
-                       if  ((*i).type != TempoMap::Beat) {
-                               continue;
-                       }
+               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);
                                (*marks)[0].label = g_strdup (buf);
                                helper_active = true;
                        } else {
 
-                               if ((*i).beat == 1) {
+                               if ((*i).is_bar()) {
                                        (*marks)[n].style = GtkCustomRulerMarkMajor;
                                        snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
                                } else {
@@ -1483,14 +1485,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
 
                        frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() *  60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
                        frame_skip_error -= frame_skip;
-                       skip = (uint32_t) (Timecode::BBT_Time::ticks_per_bar_division / bbt_beat_subdivision);
+                       skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
 
                        pos = (*i).frame + frame_skip;
                        accumulated_error = frame_skip_error;
 
                        tick = skip;
 
-                       for (t = 0; (tick < Timecode::BBT_Time::ticks_per_bar_division) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
+                       for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
 
                                if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
                                        i_am_accented = true;
@@ -1527,7 +1529,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 ());
@@ -1537,17 +1539,15 @@ 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) {
-                       if  ((*i).type != TempoMap::Beat) {
-                                 continue;
-                       }
+               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);
                                  (*marks)[0].label = g_strdup (buf);
                                  helper_active = true;
                        } else {
 
-                                 if ((*i).beat == 1) {
+                                 if ((*i).is_bar()) {
                                          (*marks)[n].style = GtkCustomRulerMarkMajor;
                                          snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
                                  } else {
@@ -1580,14 +1580,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
 
                        frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() *  60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
                        frame_skip_error -= frame_skip;
-                       skip = (uint32_t) (Timecode::BBT_Time::ticks_per_bar_division / bbt_beat_subdivision);
+                       skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision);
 
                        pos = (*i).frame + frame_skip;
                        accumulated_error = frame_skip_error;
 
                        tick = skip;
 
-                       for (t = 0; (tick < Timecode::BBT_Time::ticks_per_bar_division) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
+                       for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
 
                                  if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
                                          i_am_accented = true;
@@ -1636,8 +1636,8 @@ 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++) {
-                               if ((*i).type == TempoMap::Bar)  {
+                       for (n = 0,   i = current_bbt_points_begin; i != current_bbt_points_end && n < bbt_nmarks; i++) {
+                               if ((*i).is_bar()) {
                                        if ((*i).bar % 64 == 1) {
                                                if ((*i).bar % 256 == 1) {
                                                        snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
@@ -1661,8 +1661,8 @@ 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++) {
-                       if ((*i).type == TempoMap::Bar)  {
+               for (n = 0,  i = current_bbt_points_begin; i != current_bbt_points_end && n < bbt_nmarks; i++) {
+                       if ((*i).is_bar()) {
                          if ((*i).bar % 16 == 1) {
                                if ((*i).bar % 64 == 1) {
                                        snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
@@ -1686,8 +1686,8 @@ 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) {
-                       if ((*i).type == TempoMap::Bar)  {
+               for (n = 0,   i = current_bbt_points_begin; i != current_bbt_points_end && n < bbt_nmarks; ++i) {
+                       if ((*i).is_bar()) {
                          if ((*i).bar % 4 == 1) {
                                if ((*i).bar % 16 == 1) {
                                        snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
@@ -1712,8 +1712,8 @@ 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++) {
-                       if ((*i).type == TempoMap::Bar)  {
+               for (n = 0,  i = current_bbt_points_begin; i != current_bbt_points_end && n < bbt_nmarks; i++) {
+                       if ((*i).is_bar()) {
                          if ((*i).bar % 4 == 1) {
                                        snprintf (buf, sizeof(buf), "%" PRIu32, (*i).bar);
                                        (*marks)[n].style = GtkCustomRulerMarkMajor;