Merged with trunk R846
[ardour.git] / gtk2_ardour / editor_markers.cc
index 47982ff72897963d4cd0b01928ade70dd3fa3392..40f00c2e109be2e24c8621f4badc5a0dec96e8f4 100644 (file)
 #include <gtkmm2ext/gtk_ui.h>
 
 #include <ardour/location.h>
+#include <pbd/memento_command.h>
 
 #include "editor.h"
 #include "marker.h"
 #include "selection.h"
-#include "simplerect.h"
 #include "editing.h"
 #include "gui_thread.h"
 #include "simplerect.h"
+#include "actions.h"
+#include "prompter.h"
 
 #include "i18n.h"
 
 using namespace std;
 using namespace sigc;
 using namespace ARDOUR;
+using namespace PBD;
 using namespace Gtk;
 
 void
@@ -55,6 +58,8 @@ Editor::clear_marker_display ()
 void
 Editor::add_new_location (Location *location)
 {
+       ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::add_new_location), location));
+
        LocationMarkers *lam = new LocationMarkers;
        uint32_t color;
 
@@ -286,9 +291,10 @@ Editor::mouse_add_new_marker (jack_nframes_t where)
        if (session) {
                Location *location = new Location (where, where, "mark", Location::IsMark);
                session->begin_reversible_command (_("add marker"));
-               session->add_undo (session->locations()->get_memento());
+                XMLNode &before = session->locations()->get_state();
                session->locations()->add (location, true);
-               session->add_redo_no_execute (session->locations()->get_memento());
+                XMLNode &after = session->locations()->get_state();
+               session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
                session->commit_reversible_command ();
        }
 }
@@ -325,9 +331,10 @@ gint
 Editor::really_remove_marker (Location* loc)
 {
        session->begin_reversible_command (_("remove marker"));
-       session->add_undo (session->locations()->get_memento());
+       XMLNode &before = session->locations()->get_state();
        session->locations()->remove (loc);
-       session->add_redo_no_execute (session->locations()->get_memento());
+       XMLNode &after = session->locations()->get_state();
+       session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
        session->commit_reversible_command ();
        return FALSE;
 }
@@ -368,7 +375,6 @@ Editor::tm_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
 
 }
 
-
 void
 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
 {
@@ -386,11 +392,13 @@ Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
                }
                marker_menu_item = item;
                transport_marker_menu->popup (1, ev->time);
-       }
-       else {
-               if (marker_menu == 0) {
-                       build_marker_menu ();
-               }
+       } else {
+
+               if (loc->is_mark()) {
+                      if (marker_menu == 0) {
+                             build_marker_menu ();
+                      }
+
 
                // GTK2FIX use action group sensitivity
 #ifdef GTK2FIX
@@ -408,10 +416,18 @@ Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
 #endif         
                marker_menu_item = item;
                marker_menu->popup (1, ev->time);
+               }
+
+               if (loc->is_range_marker()) {
+                      if (range_marker_menu == 0){
+                             build_range_marker_menu ();
+                      }
+                      marker_menu_item = item;
+                      range_marker_menu->popup (1, ev->time);
+               }
        }
 }
 
-
 void
 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
 {
@@ -442,17 +458,44 @@ Editor::build_marker_menu ()
        MenuList& items = marker_menu->items();
        marker_menu->set_name ("ArdourContextMenu");
 
-       items.push_back (MenuElem (_("Locate to"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
-       items.push_back (MenuElem (_("Play from"), mem_fun(*this, &Editor::marker_menu_play_from)));
-       items.push_back (MenuElem (_("Loop range"), mem_fun(*this, &Editor::marker_menu_loop_range)));
-       items.push_back (MenuElem (_("Set from playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
-       items.push_back (MenuElem (_("Set from range"), mem_fun(*this, &Editor::marker_menu_set_from_selection)));
+       items.push_back (MenuElem (_("Locate to Mark"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
+       items.push_back (MenuElem (_("Play from Mark"), mem_fun(*this, &Editor::marker_menu_play_from)));
+       items.push_back (MenuElem (_("Set Mark from Playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
 
        items.push_back (SeparatorElem());
 
-       items.push_back (MenuElem (_("Rename"), mem_fun(*this, &Editor::marker_menu_rename)));
-       items.push_back (MenuElem (_("Hide"), mem_fun(*this, &Editor::marker_menu_hide)));
-       items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::marker_menu_remove)));
+       items.push_back (MenuElem (_("Rename Mark"), mem_fun(*this, &Editor::marker_menu_rename)));
+       items.push_back (MenuElem (_("Hide Mark"), mem_fun(*this, &Editor::marker_menu_hide)));
+       items.push_back (MenuElem (_("Remove Mark"), mem_fun(*this, &Editor::marker_menu_remove)));
+
+}
+
+void
+Editor::build_range_marker_menu ()
+{
+       using namespace Menu_Helpers;
+
+       range_marker_menu = new Menu;
+       MenuList& items = range_marker_menu->items();
+       range_marker_menu->set_name ("ArdourContextMenu");
+
+       items.push_back (MenuElem (_("Locate to Range Mark"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
+       items.push_back (MenuElem (_("Play from Range Mark"), mem_fun(*this, &Editor::marker_menu_play_from)));
+       items.push_back (MenuElem (_("Loop Range"), mem_fun(*this, &Editor::marker_menu_loop_range)));
+       items.push_back (MenuElem (_("Set Range Mark from Playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
+       items.push_back (MenuElem (_("Set Range from Range Selection"), mem_fun(*this, &Editor::marker_menu_set_from_selection)));
+
+       items.push_back (SeparatorElem());
+
+       items.push_back (MenuElem (_("Rename Range"), mem_fun(*this, &Editor::marker_menu_rename)));
+       items.push_back (MenuElem (_("Hide Range"), mem_fun(*this, &Editor::marker_menu_hide)));
+       items.push_back (MenuElem (_("Remove Range"), mem_fun(*this, &Editor::marker_menu_remove)));
+
+       items.push_back (SeparatorElem());
+
+       items.push_back (MenuElem (_("Separate Regions in Range"), mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
+       items.push_back (MenuElem (_("Select All in Range"), mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
+
 }
 
 void
@@ -492,12 +535,15 @@ Editor::build_transport_marker_menu ()
        MenuList& items = transport_marker_menu->items();
        transport_marker_menu->set_name ("ArdourContextMenu");
 
-       items.push_back (MenuElem (_("Locate to"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
-       items.push_back (MenuElem (_("Play from"), mem_fun(*this, &Editor::marker_menu_play_from)));
-       items.push_back (MenuElem (_("Set from playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
-       items.push_back (MenuElem (_("Set from range"), mem_fun(*this, &Editor::marker_menu_set_from_selection)));
+       items.push_back (MenuElem (_("Locate to Range Mark"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
+       items.push_back (MenuElem (_("Play from Range Mark"), mem_fun(*this, &Editor::marker_menu_play_from)));
+       items.push_back (MenuElem (_("Set Range Mark from Playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
+       items.push_back (MenuElem (_("Set Range from Range Selection"), mem_fun(*this, &Editor::marker_menu_set_from_selection)));
+       items.push_back (SeparatorElem());
+       items.push_back (MenuElem (_("Hide Range"), mem_fun(*this, &Editor::marker_menu_hide)));
        items.push_back (SeparatorElem());
-       items.push_back (MenuElem (_("Hide"), mem_fun(*this, &Editor::marker_menu_hide)));
+       items.push_back (MenuElem (_("Separate Regions in Range"), mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
+       items.push_back (MenuElem (_("Select All in Range"), mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
 }
 
 void
@@ -518,6 +564,44 @@ Editor::marker_menu_hide ()
        }
 }
 
+void
+Editor::marker_menu_select_all_selectables_using_range ()
+{
+       Marker* marker;
+
+       if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
+               fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
+               /*NOTREACHED*/
+       }
+
+       Location* l;
+       bool is_start;
+
+       if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
+               select_all_within (l->start(), l->end() - 1, 0,  DBL_MAX, Selection::Set);
+       }
+         
+}
+
+void
+Editor::marker_menu_separate_regions_using_location ()
+{
+       Marker* marker;
+
+       if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
+               fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
+               /*NOTREACHED*/
+       }
+
+       Location* l;
+       bool is_start;
+
+       if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
+               separate_regions_using_location (*l);
+       }
+         
+}
+
 void
 Editor::marker_menu_play_from ()
 {
@@ -633,9 +717,9 @@ Editor::marker_menu_set_from_selection ()
                                }
                        }
                        else {
-                               if (!selection->audio_regions.empty()) {
-                                       l->set_start (selection->audio_regions.start());
-                                       l->set_end (selection->audio_regions.end_frame());
+                               if (!selection->regions.empty()) {
+                                       l->set_start (selection->regions.start());
+                                       l->set_end (selection->regions.end_frame());
                                }
                        }
                }
@@ -728,10 +812,10 @@ Editor::marker_menu_rename ()
 
        if (!loc) return;
        
-       Dialog dialog;
-       Entry  entry;
-       Button ok_button (_("OK"));
-       Button cancel_button (_("Cancel"));
+       ArdourPrompter dialog (true);
+       string txt;
+
+       dialog.set_prompt (_("New Name:"));
        
        if (loc->is_mark()) {
                dialog.set_title (_("ardour: rename mark"));
@@ -740,39 +824,31 @@ Editor::marker_menu_rename ()
        }
 
        dialog.set_name ("MarkRenameWindow");
-       dialog.set_size_request (300, -1);
+       dialog.set_size_request (250, -1);
        dialog.set_position (Gtk::WIN_POS_MOUSE);
-       dialog.set_modal (true);
-
-       dialog.get_vbox()->set_border_width (10);
-       dialog.get_vbox()->pack_start (entry);
-       dialog.get_action_area()->pack_start (ok_button);
-       dialog.get_action_area()->pack_start (cancel_button);
 
-       entry.set_text (loc->name());
-       entry.set_name ("MarkerNameDisplay");
-       ok_button.set_name ("EditorGTKButton");
-       cancel_button.set_name ("EditorGTKButton");
+       dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
+       dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
+       dialog.set_initial_text (loc->name());
 
-       entry.signal_activate().connect (bind (mem_fun(*this, &Editor::finish_sub_event_loop), 1));
-       cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::finish_sub_event_loop), -1));
-       ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::finish_sub_event_loop), 1));
-       dialog.signal_delete_event().connect (bind (mem_fun(*this, &Editor::finish_sub_event_loop_on_delete), -1));
+       dialog.show ();
 
-       dialog.show_all ();
-       entry.grab_focus ();
-
-       run_sub_event_loop ();
-
-       if (sub_event_loop_status == 1) {
+       switch (dialog.run ()) {
+       case RESPONSE_ACCEPT:
+               break;
+       default:
+               return;
+       }
 
-               Location* l;
-               bool is_start;
+       begin_reversible_command ( _("rename marker") );
+        XMLNode &before = session->locations()->get_state();
 
-               if ((l = find_location_from_marker (marker, is_start)) != 0) {
-                       l->set_name (entry.get_text());
-               }
-       }
+       dialog.get_result(txt);
+       loc->set_name (txt);
+       
+        XMLNode &after = session->locations()->get_state();
+       session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
+       commit_reversible_command ();
 }
 
 gint
@@ -796,16 +872,18 @@ Editor::new_transport_marker_menu_set_loop ()
 
        if ((tll = transport_loop_location()) == 0) {
                Location* loc = new Location (temp_location->start(), temp_location->end(), _("Loop"),  Location::IsAutoLoop);
-               session->add_undo (session->locations()->get_memento());
+                XMLNode &before = session->locations()->get_state();
                session->locations()->add (loc, true);
                session->set_auto_loop_location (loc);
-               session->add_redo_no_execute (session->locations()->get_memento());
+                XMLNode &after = session->locations()->get_state();
+               session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
        }
        else {
-               session->add_undo (retype_return<void>(bind (mem_fun (*tll, &Location::set), tll->start(), tll->end())));
-               session->add_redo (retype_return<void>(bind (mem_fun (*tll, &Location::set), temp_location->start(), temp_location->end())));
+                XMLNode &before = tll->get_state();
                tll->set_hidden (false, this);
                tll->set (temp_location->start(), temp_location->end());
+                XMLNode &after = tll->get_state();
+                session->add_command (new MementoCommand<Location>(*tll, &before, &after));
        }
        
        commit_reversible_command ();
@@ -822,15 +900,17 @@ Editor::new_transport_marker_menu_set_punch ()
 
        if ((tpl = transport_punch_location()) == 0) {
                tpl = new Location (temp_location->start(), temp_location->end(), _("Punch"), Location::IsAutoPunch);
-               session->add_undo (session->locations()->get_memento());
+                XMLNode &before = session->locations()->get_state();
                session->locations()->add (tpl, true);
                session->set_auto_punch_location (tpl);
-               session->add_redo_no_execute (session->locations()->get_memento());
+                XMLNode &after = session->locations()->get_state();
+               session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
        } else {
-               session->add_undo (retype_return<void>(bind (mem_fun (*tpl, &Location::set), tpl->start(), tpl->end())));
-               session->add_redo (retype_return<void>(bind (mem_fun (*tpl, &Location::set), temp_location->start(), temp_location->end())));
+                XMLNode &before = tpl->get_state();
                tpl->set_hidden(false, this);
                tpl->set(temp_location->start(), temp_location->end());
+                XMLNode &after = tpl->get_state();
+                session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
        }
        
        commit_reversible_command ();