Initial stab at tempo ramps.
[ardour.git] / gtk2_ardour / editor_tempodisplay.cc
index 6afa8e71a816b8e89a9e08b126e8885a8d33e2ec..2d5a3e47d5d94295d47b7265a46b5080f0626d85 100644 (file)
@@ -48,8 +48,8 @@
 #include "rgb_macros.h"
 #include "gui_thread.h"
 #include "time_axis_view.h"
-#include "ardour_ui.h"
 #include "tempo_lines.h"
+#include "ui_config.h"
 
 #include "i18n.h"
 
@@ -85,15 +85,15 @@ Editor::draw_metric_marks (const Metrics& metrics)
 
                if ((ms = dynamic_cast<const MeterSection*>(*i)) != 0) {
                        snprintf (buf, sizeof(buf), "%g/%g", ms->divisions_per_bar(), ms->note_divisor ());
-                       metric_marks.push_back (new MeterMarker (*this, *meter_group, ARDOUR_UI::config()->color ("meter marker"), buf,
+                       metric_marks.push_back (new MeterMarker (*this, *meter_group, UIConfiguration::instance().color ("meter marker"), buf,
                                                                 *(const_cast<MeterSection*>(ms))));
                } else if ((ts = dynamic_cast<const TempoSection*>(*i)) != 0) {
-                       if (Config->get_allow_non_quarter_pulse()) {
+                       if (UIConfiguration::instance().get_allow_non_quarter_pulse()) {
                                snprintf (buf, sizeof (buf), "%.2f/%.0f", ts->beats_per_minute(), ts->note_type());
                        } else {
                                snprintf (buf, sizeof (buf), "%.2f", ts->beats_per_minute());
                        }
-                       metric_marks.push_back (new TempoMarker (*this, *tempo_group, ARDOUR_UI::config()->color ("tempo marker"), buf,
+                       metric_marks.push_back (new TempoMarker (*this, *tempo_group, UIConfiguration::instance().color ("tempo marker"), buf,
                                                                 *(const_cast<TempoSection*>(ts))));
                }
 
@@ -114,13 +114,12 @@ Editor::tempo_map_changed (const PropertyChange& /*ignored*/)
                tempo_lines->tempo_map_changed();
        }
 
-       ARDOUR::TempoMap::BBTPointList::const_iterator begin;
-       ARDOUR::TempoMap::BBTPointList::const_iterator end;
+       std::vector<TempoMap::BBTPoint> grid;
 
-       compute_current_bbt_points (leftmost_frame, leftmost_frame + current_page_samples(), begin, end);
+       compute_current_bbt_points (grid, leftmost_frame, leftmost_frame + current_page_samples());
        _session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
-       draw_measures (begin, end);
-       update_tempo_based_rulers (begin, end);
+       draw_measures (grid);
+       update_tempo_based_rulers (grid);
 }
 
 void
@@ -131,32 +130,31 @@ Editor::redisplay_tempo (bool immediate_redraw)
        }
 
        if (immediate_redraw) {
-               ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_begin;
-               ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_end;
-               
-               compute_current_bbt_points (leftmost_frame, leftmost_frame + current_page_samples(),
-                                           current_bbt_points_begin, current_bbt_points_end);
-               draw_measures (current_bbt_points_begin, current_bbt_points_end);
-               update_tempo_based_rulers (current_bbt_points_begin, current_bbt_points_end); // redraw rulers and measures
-       
+               std::vector<TempoMap::BBTPoint> grid;
+
+               compute_current_bbt_points (grid, leftmost_frame, leftmost_frame + current_page_samples());
+               draw_measures (grid);
+               update_tempo_based_rulers (grid); // redraw rulers and measure lines
+
        } else {
                Glib::signal_idle().connect (sigc::bind_return (sigc::bind (sigc::mem_fun (*this, &Editor::redisplay_tempo), true), false));
        }
 }
 
+/* computes a grid starting a beat before and ending a beat after leftmost and rightmost respectively */
 void
-Editor::compute_current_bbt_points (framepos_t leftmost, framepos_t rightmost,
-                                   ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
-                                   ARDOUR::TempoMap::BBTPointList::const_iterator& end)
+Editor::compute_current_bbt_points (std::vector<TempoMap::BBTPoint>& grid, framepos_t leftmost, framepos_t rightmost)
 {
        if (!_session) {
                return;
        }
 
+       framecnt_t beat_before_lower_pos = _session->tempo_map().frame_at_beat (floor(_session->tempo_map().beat_at_frame (leftmost)));
+       framecnt_t beat_after_upper_pos = _session->tempo_map().frame_at_beat (floor (_session->tempo_map().beat_at_frame (rightmost)) + 1.0);
+
        /* prevent negative values of leftmost from creeping into tempomap
         */
-
-       _session->tempo_map().get_grid (begin, end, max (leftmost, (framepos_t) 0), rightmost);
+       _session->tempo_map().get_grid (grid, max (beat_before_lower_pos, (framepos_t) 0), beat_after_upper_pos);
 }
 
 void
@@ -168,18 +166,18 @@ Editor::hide_measures ()
 }
 
 void
-Editor::draw_measures (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
-                      ARDOUR::TempoMap::BBTPointList::const_iterator& end)
+Editor::draw_measures (std::vector<ARDOUR::TempoMap::BBTPoint>& grid)
 {
-       if (_session == 0 || _show_measures == false || distance (begin, end) == 0) {
+       if (_session == 0 || _show_measures == false || distance (grid.begin(), grid.end()) == 0) {
                return;
        }
 
        if (tempo_lines == 0) {
                tempo_lines = new TempoLines (time_line_group, ArdourCanvas::LineSet::Vertical);
        }
-       
-       tempo_lines->draw (begin, end);
+
+       const unsigned divisions = get_grid_beat_divisions(leftmost_frame);
+       tempo_lines->draw (grid, divisions, leftmost_frame, _session->frame_rate());
 }
 
 void
@@ -195,8 +193,6 @@ Editor::mouse_add_new_tempo_event (framepos_t frame)
        //this causes compiz to display no border.
        //tempo_dialog.signal_realize().connect (sigc::bind (sigc::ptr_fun (set_decoration), &tempo_dialog, Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH)));
 
-       ensure_float (tempo_dialog);
-
        switch (tempo_dialog.run()) {
        case RESPONSE_ACCEPT:
                break;
@@ -215,7 +211,7 @@ Editor::mouse_add_new_tempo_event (framepos_t frame)
 
        begin_reversible_command (_("add tempo mark"));
         XMLNode &before = map.get_state();
-       map.add_tempo (Tempo (bpm,nt), requested);
+       map.add_tempo (Tempo (bpm,nt), requested, tempo_dialog.get_tempo_type());
         XMLNode &after = map.get_state();
        _session->add_command(new MementoCommand<TempoMap>(map, &before, &after));
        commit_reversible_command ();
@@ -237,8 +233,6 @@ Editor::mouse_add_new_meter_event (framepos_t frame)
        //this causes compiz to display no border..
        //meter_dialog.signal_realize().connect (sigc::bind (sigc::ptr_fun (set_decoration), &meter_dialog, Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH)));
 
-       ensure_float (meter_dialog);
-
        switch (meter_dialog.run ()) {
        case RESPONSE_ACCEPT:
                break;
@@ -266,10 +260,10 @@ Editor::mouse_add_new_meter_event (framepos_t frame)
 void
 Editor::remove_tempo_marker (ArdourCanvas::Item* item)
 {
-       Marker* marker;
+       ArdourMarker* marker;
        TempoMarker* tempo_marker;
 
-       if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
+       if ((marker = reinterpret_cast<ArdourMarker *> (item->get_data ("marker"))) == 0) {
                fatal << _("programming error: tempo marker canvas item has no marker object pointer!") << endmsg;
                abort(); /*NOTREACHED*/
        }
@@ -289,8 +283,6 @@ Editor::edit_meter_section (MeterSection* section)
 {
        MeterDialog meter_dialog (*section, _("done"));
 
-       ensure_float (meter_dialog);
-
        switch (meter_dialog.run()) {
        case RESPONSE_ACCEPT:
                break;
@@ -319,8 +311,6 @@ Editor::edit_tempo_section (TempoSection* section)
 {
        TempoDialog tempo_dialog (*section, _("done"));
 
-       ensure_float (tempo_dialog);
-
        switch (tempo_dialog.run ()) {
        case RESPONSE_ACCEPT:
                break;
@@ -336,7 +326,7 @@ Editor::edit_tempo_section (TempoSection* section)
 
        begin_reversible_command (_("replace tempo mark"));
        XMLNode &before = _session->tempo_map().get_state();
-       _session->tempo_map().replace_tempo (*section, Tempo (bpm, nt), when);
+       _session->tempo_map().replace_tempo (*section, Tempo (bpm, nt), when, tempo_dialog.get_tempo_type());
        XMLNode &after = _session->tempo_map().get_state();
        _session->add_command (new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
        commit_reversible_command ();
@@ -370,10 +360,10 @@ Editor::real_remove_tempo_marker (TempoSection *section)
 void
 Editor::remove_meter_marker (ArdourCanvas::Item* item)
 {
-       Marker* marker;
+       ArdourMarker* marker;
        MeterMarker* meter_marker;
 
-       if ((marker = reinterpret_cast<Marker *> (item->get_data ("marker"))) == 0) {
+       if ((marker = reinterpret_cast<ArdourMarker *> (item->get_data ("marker"))) == 0) {
                fatal << _("programming error: meter marker canvas item has no marker object pointer!") << endmsg;
                abort(); /*NOTREACHED*/
        }