Use the frame corresponding to the current mouse position when zoom dragging
[ardour.git] / gtk2_ardour / editor_markers.cc
index 40bf2dc32513b17c2d090078ff6dcb04f08bdddb..6751f6424f70a9799c5a337fcb14db4599119bca 100644 (file)
@@ -40,7 +40,7 @@
 #include "prompter.h"
 #include "editor_drag.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -815,7 +815,7 @@ Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::It
                if (!tm->tempo().active()) {
                        return;
                }
-               can_remove = tm->tempo().movable ();
+               can_remove = tm->tempo().movable() && !tm->tempo().locked_to_meter();
                delete tempo_marker_menu;
                build_tempo_marker_menu (tm, can_remove);
                tempo_marker_menu->popup (1, ev->time);
@@ -982,19 +982,21 @@ Editor::build_tempo_marker_menu (TempoMarker* loc, bool can_remove)
        tempo_marker_menu = new Menu;
        MenuList& items = tempo_marker_menu->items();
        tempo_marker_menu->set_name ("ArdourContextMenu");
+
        if (loc->tempo().type() == TempoSection::Constant) {
-               items.push_back (MenuElem (_("Ramped"), sigc::mem_fun(*this, &Editor::toggle_tempo_type)));
+               items.push_back (MenuElem (_("Make Ramped"), sigc::mem_fun(*this, &Editor::toggle_tempo_type)));
        } else {
-               items.push_back (MenuElem (_("Constant"), sigc::mem_fun(*this, &Editor::toggle_tempo_type)));
+               items.push_back (MenuElem (_("Make Constant"), sigc::mem_fun(*this, &Editor::toggle_tempo_type)));
        }
-       if (loc->tempo().position_lock_style() == AudioTime) {
+
+       if (loc->tempo().position_lock_style() == AudioTime && can_remove) {
                items.push_back (MenuElem (_("Lock to Music"), sigc::mem_fun(*this, &Editor::toggle_marker_lock_style)));
-       } else {
+       } else if (can_remove) {
                items.push_back (MenuElem (_("Lock to Audio"), sigc::mem_fun(*this, &Editor::toggle_marker_lock_style)));
        }
+
        items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
        items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
-
        items.back().set_sensitive (can_remove);
 }
 
@@ -1006,11 +1008,13 @@ Editor::build_meter_marker_menu (MeterMarker* loc, bool can_remove)
        meter_marker_menu = new Menu;
        MenuList& items = meter_marker_menu->items();
        meter_marker_menu->set_name ("ArdourContextMenu");
-       if (loc->meter().position_lock_style() == AudioTime) {
+
+       if (loc->meter().position_lock_style() == AudioTime && can_remove) {
                items.push_back (MenuElem (_("Lock to Music"), sigc::mem_fun(*this, &Editor::toggle_marker_lock_style)));
-       } else {
+       } else if (can_remove) {
                items.push_back (MenuElem (_("Lock to Audio"), sigc::mem_fun(*this, &Editor::toggle_marker_lock_style)));
        }
+
        items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
        items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
 
@@ -1384,17 +1388,36 @@ Editor::toggle_marker_lock_style ()
        dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
 
        if (mm) {
-               if (mm->meter().position_lock_style() == AudioTime) {
-                       mm->meter().set_position_lock_style (MusicTime);
-               } else {
-                       mm->meter().set_position_lock_style (AudioTime);
-               }
+               begin_reversible_command (_("change meter lock style"));
+               XMLNode &before = _session->tempo_map().get_state();
+               MeterSection* msp = &mm->meter();
+
+               const Meter meter (msp->divisions_per_bar(), msp->note_divisor());
+               const Timecode::BBT_Time bbt (msp->bbt());
+               const PositionLockStyle pls = (msp->position_lock_style() == AudioTime) ? MusicTime : AudioTime;
+
+               _session->tempo_map().replace_meter (*msp, meter, bbt, pls);
+
+               XMLNode &after = _session->tempo_map().get_state();
+               _session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
+               commit_reversible_command ();
        } else if (tm) {
-               if (tm->tempo().position_lock_style() == AudioTime) {
-                       tm->tempo().set_position_lock_style (MusicTime);
-               } else {
-                       tm->tempo().set_position_lock_style (AudioTime);
-               }
+               TempoSection* tsp = &tm->tempo();
+
+               const Tempo tempo (tsp->note_types_per_minute(), tsp->note_type());
+               const double pulse = tsp->pulse();
+               const framepos_t frame = tsp->frame();
+               const TempoSection::Type type = tsp->type();
+               const PositionLockStyle pls = (tsp->position_lock_style() == AudioTime) ? MusicTime : AudioTime;
+
+               begin_reversible_command (_("change tempo lock style"));
+               XMLNode &before = _session->tempo_map().get_state();
+
+               _session->tempo_map().replace_tempo (*tsp, tempo, pulse, frame, type, pls);
+
+               XMLNode &after = _session->tempo_map().get_state();
+               _session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
+               commit_reversible_command ();
        }
 }
 
@@ -1406,11 +1429,22 @@ Editor::toggle_tempo_type ()
        dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
 
        if (tm) {
-               if (tm->tempo().type() == TempoSection::Constant) {
-                       tm->tempo().set_type (TempoSection::Ramp);
-               } else {
-                       tm->tempo().set_type (TempoSection::Constant);
-               }
+               TempoSection* tsp = &tm->tempo();
+
+               const Tempo tempo (tsp->note_types_per_minute(), tsp->note_type());
+               const double pulse = tsp->pulse();
+               const framepos_t frame = tsp->frame();
+               const TempoSection::Type type = (tsp->type() == TempoSection::Ramp) ? TempoSection::Constant : TempoSection::Ramp;
+               const PositionLockStyle pls = tsp->position_lock_style();
+
+               begin_reversible_command (_("change tempo type"));
+               XMLNode &before = _session->tempo_map().get_state();
+
+               _session->tempo_map().replace_tempo (*tsp, tempo, pulse, frame, type, pls);
+
+               XMLNode &after = _session->tempo_map().get_state();
+               _session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
+               commit_reversible_command ();
        }
 }