fix whitespace/indentation and compiler warnings
[ardour.git] / gtk2_ardour / editor_ops.cc
index d965eb2384382f4e142248817ca5f142bf2302d2..2d26a90a86ce5362886b06cff6c1a450dc38860a 100644 (file)
@@ -76,7 +76,7 @@
 #include "editor_regions.h"
 #include "editor_routes.h"
 #include "gui_thread.h"
-#include "insert_time_dialog.h"
+#include "insert_remove_time_dialog.h"
 #include "interthread_progress_window.h"
 #include "item_counts.h"
 #include "keyboard.h"
@@ -5182,16 +5182,22 @@ Editor::quantize_regions (const RegionSelection& rs)
                return;
        }
 
-       QuantizeDialog* qd = new QuantizeDialog (*this);
+       if (!quantize_dialog) {
+               quantize_dialog = new QuantizeDialog (*this);
+       }
 
-       qd->present ();
-       const int r = qd->run ();
-       qd->hide ();
+       quantize_dialog->present ();
+       const int r = quantize_dialog->run ();
+       quantize_dialog->hide ();
 
        if (r == Gtk::RESPONSE_OK) {
-               Quantize quant (qd->snap_start(), qd->snap_end(),
-                               qd->start_grid_size(), qd->end_grid_size(),
-                               qd->strength(), qd->swing(), qd->threshold());
+               Quantize quant (quantize_dialog->snap_start(),
+                               quantize_dialog->snap_end(),
+                               quantize_dialog->start_grid_size(),
+                               quantize_dialog->end_grid_size(),
+                               quantize_dialog->strength(),
+                               quantize_dialog->swing(),
+                               quantize_dialog->threshold());
 
                apply_midi_note_edit_op (quant, rs);
        }
@@ -6926,7 +6932,7 @@ Editor::do_insert_time ()
                return;
        }
 
-       InsertTimeDialog d (*this);
+       InsertRemoveTimeDialog d (*this);
        int response = d.run ();
 
        if (response != RESPONSE_OK) {
@@ -7065,15 +7071,16 @@ Editor::insert_time (
                commit_reversible_command ();
        }
 }
+
 void
-Editor::do_cut_time ()
+Editor::do_remove_time ()
 {
        if (selection->tracks.empty()) {
                return;
        }
 
        framepos_t pos = get_preferred_edit_position (EDIT_IGNORE_MOUSE);
-       InsertTimeDialog d (*this, true);
+       InsertRemoveTimeDialog d (*this, true);
 
        int response = d.run ();
 
@@ -7087,19 +7094,21 @@ Editor::do_cut_time ()
                return;
        }
 
-       cut_time (
+       remove_time (
                pos,
                distance,
                SplitIntersected,
                d.move_glued(),
                d.move_markers(),
+               d.move_glued_markers(),
+               d.move_locked_markers(),
                d.move_tempos()
        );
 }
 
 void
-Editor::cut_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt, 
-                    bool ignore_music_glue, bool markers_too, bool tempo_too)
+Editor::remove_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt, 
+                    bool ignore_music_glue, bool markers_too, bool glued_markers_too, bool locked_markers_too, bool tempo_too)
 {
        bool commit = false;
        
@@ -7147,36 +7156,54 @@ Editor::cut_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
                Locations::LocationList copy (_session->locations()->list());
 
                for (Locations::LocationList::iterator i = copy.begin(); i != copy.end(); ++i) {
-                       
-                       if (!(*i)->is_mark()) {  //range;  have to handle both start and end
+                       if ((*i)->position_lock_style() == AudioTime || glued_markers_too) {
+
+                               bool const was_locked = (*i)->locked ();
+                               if (locked_markers_too) {
+                                       (*i)->unlock ();
+                               }
+
+                               if (!(*i)->is_mark()) {  // it's a range;  have to handle both start and end
                                        if ((*i)->end() >= pos
                                        && (*i)->end() < pos+frames
                                        && (*i)->start() >= pos
-                                       && (*i)->end() < pos+frames) {  //range is completely enclosed;  kill it
+                                       && (*i)->end() < pos+frames) {  // range is completely enclosed;  kill it
                                                moved = true;
                                                loc_kill_list.push_back(*i);
-                                       } else {  //ony start or end is included, try to do the right thing
-                                               if ((*i)->end() >= pos && (*i)->end() < pos+frames) {
-                                                       (*i)->set_end (pos);  //bring the end to the cut
+                                       } else {  // only start or end is included, try to do the right thing
+                                               // move start before moving end, to avoid trying to move the end to before the start
+                                               // if we're removing more time than the length of the range
+                                               if ((*i)->start() >= pos && (*i)->start() < pos+frames) {
+                                                       // start is within cut
+                                                       (*i)->set_start (pos);  // bring the start marker to the beginning of the cut
                                                        moved = true;
-                                               } else if ((*i)->end() >= pos) {
-                                                       (*i)->set_end ((*i)->end()-frames); //slip the end marker back
+                                               } else if ((*i)->start() >= pos+frames) {
+                                                       // start (and thus entire range) lies beyond end of cut
+                                                       (*i)->set_start ((*i)->start() - frames); // slip the start marker back
                                                        moved = true;
                                                }
-                                               if ((*i)->start() >= pos && (*i)->start() < pos+frames) {
-                                                       (*i)->set_start (pos);  //bring the start marker to the beginning of the cut
+                                               if ((*i)->end() >= pos && (*i)->end() < pos+frames) {
+                                                       // end is inside cut
+                                                       (*i)->set_end (pos);  // bring the end to the cut
                                                        moved = true;
-                                               } else if ((*i)->start() >= pos) {
-                                                       (*i)->set_start ((*i)->start() -frames); //slip the end marker back
+                                               } else if ((*i)->end() >= pos+frames) {
+                                                       // end is beyond end of cut
+                                                       (*i)->set_end ((*i)->end() - frames); // slip the end marker back
                                                        moved = true;
                                                }
+
                                        }
-                       } else if ((*i)->start() >= pos && (*i)->start() < pos+frames ) {
-                               loc_kill_list.push_back(*i);
-                               moved = true;
-                       } else if ((*i)->start() >= pos) {
-                               (*i)->set_start ((*i)->start() -frames);
-                               moved = true;
+                               } else if ((*i)->start() >= pos && (*i)->start() < pos+frames ) {
+                                       loc_kill_list.push_back(*i);
+                                       moved = true;
+                               } else if ((*i)->start() >= pos) {
+                                       (*i)->set_start ((*i)->start() -frames);
+                                       moved = true;
+                               }
+
+                               if (was_locked) {
+                                       (*i)->lock ();
+                               }
                        }
                }
 
@@ -7194,7 +7221,7 @@ Editor::cut_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
        if (tempo_too) {
                XMLNode& before (_session->tempo_map().get_state());
 
-               if (_session->tempo_map().cut_time (pos, frames) ) {
+               if (_session->tempo_map().remove_time (pos, frames) ) {
                        XMLNode& after (_session->tempo_map().get_state());
                        _session->add_command (new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
                        commit = true;
@@ -7520,15 +7547,10 @@ Editor::lock ()
                lock_dialog->get_vbox()->show_all ();
                lock_dialog->set_size_request (200, 200);
        }
+
+       delete _main_menu_disabler;
+       _main_menu_disabler = new MainMenuDisabler;
        
-#ifdef __APPLE__
-       /* The global menu bar continues to be accessible to applications
-          with modal dialogs, which means that we need to desensitize
-          all items in the menu bar. Since those items are really just
-          proxies for actions, that means disabling all actions.
-       */
-       ActionManager::disable_all_actions ();
-#endif
        lock_dialog->present ();
 }
 
@@ -7537,9 +7559,7 @@ Editor::unlock ()
 {
        lock_dialog->hide ();
        
-#ifdef __APPLE__
-       ActionManager::pop_action_state ();
-#endif 
+       delete _main_menu_disabler;
 
        if (ARDOUR_UI::config()->get_lock_gui_after_seconds()) {
                start_lock_event_timing ();