2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <sigc++/retype.h>
24 #include <libgnomecanvas/libgnomecanvas.h>
25 #include <gtkmm2ext/gtk_ui.h>
27 #include <ardour/location.h>
28 #include <pbd/memento_command.h>
32 #include "selection.h"
34 #include "gui_thread.h"
35 #include "simplerect.h"
43 using namespace ARDOUR;
48 Editor::clear_marker_display ()
50 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
54 location_markers.clear ();
58 Editor::add_new_location (Location *location)
60 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::add_new_location), location));
62 LocationMarkers *lam = new LocationMarkers;
65 if (location->is_cd_marker()) {
66 color = location_cd_marker_color;
67 } else if (location->is_mark()) {
68 color = location_marker_color;
69 } else if (location->is_auto_loop()) {
70 color = location_loop_color;
71 } else if (location->is_auto_punch()) {
72 color = location_punch_color;
74 color = location_range_color;
77 if (location->is_mark()) {
78 lam->start = new Marker (*this, *marker_group, color, location->name(), Marker::Mark, location->start());
81 } else if (location->is_auto_loop()) {
83 lam->start = new Marker (*this, *transport_marker_group, color,
84 location->name(), Marker::LoopStart, location->start());
85 lam->end = new Marker (*this, *transport_marker_group, color,
86 location->name(), Marker::LoopEnd, location->end());
88 } else if (location->is_auto_punch()) {
90 lam->start = new Marker (*this, *transport_marker_group, color,
91 location->name(), Marker::PunchIn, location->start());
92 lam->end = new Marker (*this, *transport_marker_group, color,
93 location->name(), Marker::PunchOut, location->end());
98 lam->start = new Marker (*this, *range_marker_group, color,
99 location->name(), Marker::Start, location->start());
100 lam->end = new Marker (*this, *range_marker_group, color,
101 location->name(), Marker::End, location->end());
104 if (location->is_hidden ()) {
110 location->start_changed.connect (mem_fun(*this, &Editor::location_changed));
111 location->end_changed.connect (mem_fun(*this, &Editor::location_changed));
112 location->changed.connect (mem_fun(*this, &Editor::location_changed));
113 location->name_changed.connect (mem_fun(*this, &Editor::location_changed));
114 location->FlagsChanged.connect (mem_fun(*this, &Editor::location_flags_changed));
116 pair<Location*,LocationMarkers*> newpair;
118 newpair.first = location;
119 newpair.second = lam;
121 location_markers.insert (newpair);
125 Editor::location_changed (Location *location)
127 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::location_changed), location));
129 LocationMarkers *lam = find_location_markers (location);
132 /* a location that isn't "marked" with markers */
136 lam->set_name (location->name());
137 lam->set_position (location->start(), location->end());
139 if (location->is_auto_loop()) {
140 update_loop_range_view ();
141 } else if (location->is_auto_punch()) {
142 update_punch_range_view ();
147 Editor::location_flags_changed (Location *location, void *src)
149 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::location_flags_changed), location, src));
151 LocationMarkers *lam = find_location_markers (location);
154 /* a location that isn't "marked" with markers */
158 if (location->is_cd_marker()) {
159 lam->set_color_rgba (location_cd_marker_color);
160 } else if (location->is_mark()) {
161 lam->set_color_rgba (location_marker_color);
162 } else if (location->is_auto_punch()) {
163 lam->set_color_rgba (location_punch_color);
164 } else if (location->is_auto_loop()) {
165 lam->set_color_rgba (location_loop_color);
167 lam->set_color_rgba (location_range_color);
170 if (location->is_hidden()) {
177 Editor::LocationMarkers::~LocationMarkers ()
188 Editor::LocationMarkers *
189 Editor::find_location_markers (Location *location)
191 LocationMarkerMap::iterator i;
193 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
194 if ((*i).first == location) {
203 Editor::find_location_from_marker (Marker *marker, bool& is_start)
205 LocationMarkerMap::iterator i;
207 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
208 LocationMarkers *lm = (*i).second;
209 if (lm->start == marker) {
212 } else if (lm->end == marker) {
222 Editor::refresh_location_display_internal (Locations::LocationList& locations)
224 clear_marker_display ();
226 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
227 add_new_location (*i);
232 Editor::refresh_location_display ()
234 ENSURE_GUI_THREAD(mem_fun(*this, &Editor::refresh_location_display));
237 session->locations()->apply (*this, &Editor::refresh_location_display_internal);
242 Editor::refresh_location_display_s (Change ignored)
244 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::refresh_location_display_s), ignored));
247 session->locations()->apply (*this, &Editor::refresh_location_display_internal);
252 Editor::LocationMarkers::hide()
255 if (end) { end->hide(); }
259 Editor::LocationMarkers::show()
262 if (end) { end->show(); }
266 Editor::LocationMarkers::set_name (const string& str)
268 start->set_name (str);
269 if (end) { end->set_name (str); }
273 Editor::LocationMarkers::set_position (nframes_t startf,
276 start->set_position (startf);
277 if (end) { end->set_position (endf); }
281 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
283 start->set_color_rgba (rgba);
284 if (end) { end->set_color_rgba (rgba); }
288 Editor::mouse_add_new_marker (nframes_t where)
292 session->locations()->next_available_name(markername,"mark");
293 Location *location = new Location (where, where, markername, Location::IsMark);
294 session->begin_reversible_command (_("add marker"));
295 XMLNode &before = session->locations()->get_state();
296 session->locations()->add (location, true);
297 XMLNode &after = session->locations()->get_state();
298 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
299 session->commit_reversible_command ();
304 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent* event)
309 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
310 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
314 Location* loc = find_location_from_marker (marker, is_start);
316 if (session && loc) {
317 Glib::signal_idle().connect (bind (mem_fun(*this, &Editor::really_remove_marker), loc));
322 Editor::really_remove_marker (Location* loc)
324 session->begin_reversible_command (_("remove marker"));
325 XMLNode &before = session->locations()->get_state();
326 session->locations()->remove (loc);
327 XMLNode &after = session->locations()->get_state();
328 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
329 session->commit_reversible_command ();
334 Editor::location_gone (Location *location)
336 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::location_gone), location));
338 LocationMarkerMap::iterator i;
340 if (location == transport_loop_location()) {
341 update_loop_range_view (true);
344 if (location == transport_punch_location()) {
345 update_punch_range_view (true);
348 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
349 if ((*i).first == location) {
351 location_markers.erase (i);
358 Editor::tm_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
360 if (tm_marker_menu == 0) {
361 build_tm_marker_menu ();
364 marker_menu_item = item;
365 tm_marker_menu->popup (1, ev->time);
370 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
373 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
374 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
379 Location * loc = find_location_from_marker (marker, is_start);
380 if (loc == transport_loop_location() || loc == transport_punch_location()) {
381 if (transport_marker_menu == 0) {
382 build_range_marker_menu (true);
384 marker_menu_item = item;
385 transport_marker_menu->popup (1, ev->time);
388 if (loc->is_mark()) {
389 bool start_or_end = loc->is_start() || loc->is_end();
392 if (start_end_marker_menu == 0)
393 build_marker_menu (true);
394 markerMenu = start_end_marker_menu;
396 if (marker_menu == 0)
397 build_marker_menu (false);
398 markerMenu = marker_menu;
402 // GTK2FIX use action group sensitivity
404 if (children.size() >= 3) {
405 MenuItem * loopitem = &children[2];
407 if (loc->is_mark()) {
408 loopitem->set_sensitive(false);
411 loopitem->set_sensitive(true);
416 marker_menu_item = item;
417 markerMenu->popup (1, ev->time);
420 if (loc->is_range_marker()) {
421 if (range_marker_menu == 0){
422 build_range_marker_menu (false);
424 marker_menu_item = item;
425 range_marker_menu->popup (1, ev->time);
431 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
433 if (new_transport_marker_menu == 0) {
434 build_new_transport_marker_menu ();
437 new_transport_marker_menu->popup (1, ev->time);
442 Editor::transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
444 if (transport_marker_menu == 0) {
445 build_range_marker_menu (true);
448 transport_marker_menu->popup (1, ev->time);
452 Editor::build_marker_menu (bool start_or_end)
454 using namespace Menu_Helpers;
456 Menu *markerMenu = new Menu;
458 start_end_marker_menu = markerMenu;
460 marker_menu = markerMenu;
462 MenuList& items = markerMenu->items();
463 markerMenu->set_name ("ArdourContextMenu");
465 items.push_back (MenuElem (_("Locate to Mark"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
466 items.push_back (MenuElem (_("Play from Mark"), mem_fun(*this, &Editor::marker_menu_play_from)));
467 items.push_back (MenuElem (_("Set Mark from Playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
469 items.push_back (SeparatorElem());
471 items.push_back (MenuElem (_("Hide Mark"), mem_fun(*this, &Editor::marker_menu_hide)));
472 if (start_or_end) return;
473 items.push_back (MenuElem (_("Rename Mark"), mem_fun(*this, &Editor::marker_menu_rename)));
474 items.push_back (MenuElem (_("Remove Mark"), mem_fun(*this, &Editor::marker_menu_remove)));
479 Editor::build_range_marker_menu (bool loop_or_punch)
481 using namespace Menu_Helpers;
483 Menu *markerMenu = new Menu;
485 transport_marker_menu = markerMenu;
487 range_marker_menu = markerMenu;
489 MenuList& items = markerMenu->items();
490 markerMenu->set_name ("ArdourContextMenu");
492 items.push_back (MenuElem (_("Locate to Range Mark"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
493 items.push_back (MenuElem (_("Play from Range Mark"), mem_fun(*this, &Editor::marker_menu_play_from)));
494 if (! loop_or_punch) {
495 items.push_back (MenuElem (_("Play Range"), mem_fun(*this, &Editor::marker_menu_play_range)));
496 items.push_back (MenuElem (_("Loop Range"), mem_fun(*this, &Editor::marker_menu_loop_range)));
498 items.push_back (MenuElem (_("Set Range Mark from Playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
499 items.push_back (MenuElem (_("Set Range from Range Selection"), mem_fun(*this, &Editor::marker_menu_set_from_selection)));
501 items.push_back (SeparatorElem());
503 items.push_back (MenuElem (_("Hide Range"), mem_fun(*this, &Editor::marker_menu_hide)));
504 if (! loop_or_punch) {
505 items.push_back (MenuElem (_("Rename Range"), mem_fun(*this, &Editor::marker_menu_rename)));
506 items.push_back (MenuElem (_("Remove Range"), mem_fun(*this, &Editor::marker_menu_remove)));
509 items.push_back (SeparatorElem());
511 items.push_back (MenuElem (_("Separate Regions in Range"), mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
512 items.push_back (MenuElem (_("Select All in Range"), mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
517 Editor::build_tm_marker_menu ()
519 using namespace Menu_Helpers;
521 tm_marker_menu = new Menu;
522 MenuList& items = tm_marker_menu->items();
523 tm_marker_menu->set_name ("ArdourContextMenu");
525 items.push_back (MenuElem (_("Edit"), mem_fun(*this, &Editor::marker_menu_edit)));
526 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::marker_menu_remove)));
530 Editor::build_new_transport_marker_menu ()
532 using namespace Menu_Helpers;
534 new_transport_marker_menu = new Menu;
535 MenuList& items = new_transport_marker_menu->items();
536 new_transport_marker_menu->set_name ("ArdourContextMenu");
538 items.push_back (MenuElem (_("Set Loop Range"), mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
539 items.push_back (MenuElem (_("Set Punch Range"), mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
541 new_transport_marker_menu->signal_unmap_event().connect ( mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
545 Editor::marker_menu_hide ()
549 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
550 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
557 if ((l = find_location_from_marker (marker, is_start)) != 0) {
558 l->set_hidden (true, this);
563 Editor::marker_menu_select_all_selectables_using_range ()
567 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
568 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
575 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
576 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, Selection::Set);
582 Editor::marker_menu_separate_regions_using_location ()
586 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
587 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
594 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
595 separate_regions_using_location (*l);
601 Editor::marker_menu_play_from ()
605 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
606 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
613 if ((l = find_location_from_marker (marker, is_start)) != 0) {
616 session->request_locate (l->start(), true);
619 //session->request_bounded_roll (l->start(), l->end());
622 session->request_locate (l->start(), true);
624 session->request_locate (l->end(), true);
631 Editor::marker_menu_set_playhead ()
635 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
636 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
643 if ((l = find_location_from_marker (marker, is_start)) != 0) {
646 session->request_locate (l->start(), false);
650 session->request_locate (l->start(), false);
652 session->request_locate (l->end(), false);
659 Editor::marker_menu_set_from_playhead ()
663 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
664 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
671 if ((l = find_location_from_marker (marker, is_start)) != 0) {
674 l->set_start (session->transport_frame ());
678 l->set_start (session->transport_frame ());
680 l->set_end (session->transport_frame ());
687 Editor::marker_menu_set_from_selection ()
691 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
692 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
699 if ((l = find_location_from_marker (marker, is_start)) != 0) {
706 /* if range selection use first to last */
708 if (mouse_mode == Editing::MouseRange) {
709 if (!selection->time.empty()) {
710 l->set_start (selection->time.start());
711 l->set_end (selection->time.end_frame());
715 if (!selection->regions.empty()) {
716 l->set_start (selection->regions.start());
717 l->set_end (selection->regions.end_frame());
726 Editor::marker_menu_play_range ()
730 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
731 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
738 if ((l = find_location_from_marker (marker, is_start)) != 0) {
741 session->request_locate (l->start(), true);
744 session->request_bounded_roll (l->start(), l->end());
751 Editor::marker_menu_loop_range ()
755 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
756 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
763 if ((l = find_location_from_marker (marker, is_start)) != 0) {
765 if ((l2 = transport_loop_location()) != 0) {
766 l2->set (l->start(), l->end());
768 // enable looping, reposition and start rolling
769 session->request_play_loop(true);
770 session->request_locate (l2->start(), true);
776 Editor::marker_menu_edit ()
782 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
783 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
787 if ((mm = dynamic_cast<MeterMarker*> (marker)) != 0) {
788 edit_meter_section (&mm->meter());
789 } else if ((tm = dynamic_cast<TempoMarker*> (marker)) != 0) {
790 edit_tempo_section (&tm->tempo());
792 fatal << X_("programming erorr: unhandled marker type in Editor::marker_menu_edit")
799 Editor::marker_menu_remove ()
805 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
806 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
810 if ((mm = dynamic_cast<MeterMarker*> (marker)) != 0) {
811 remove_meter_marker (marker_menu_item);
812 } else if ((tm = dynamic_cast<TempoMarker*> (marker)) != 0) {
813 remove_tempo_marker (marker_menu_item);
815 remove_marker (*marker_menu_item, (GdkEvent*) 0);
820 Editor::marker_menu_rename ()
824 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
825 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
832 loc = find_location_from_marker (marker, is_start);
836 ArdourPrompter dialog (true);
839 dialog.set_prompt (_("New Name:"));
841 if (loc->is_mark()) {
842 dialog.set_title (_("ardour: rename mark"));
844 dialog.set_title (_("ardour: rename range"));
847 dialog.set_name ("MarkRenameWindow");
848 dialog.set_size_request (250, -1);
849 dialog.set_position (Gtk::WIN_POS_MOUSE);
851 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
852 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
853 dialog.set_initial_text (loc->name());
857 switch (dialog.run ()) {
858 case RESPONSE_ACCEPT:
864 begin_reversible_command ( _("rename marker") );
865 XMLNode &before = session->locations()->get_state();
867 dialog.get_result(txt);
870 XMLNode &after = session->locations()->get_state();
871 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
872 commit_reversible_command ();
876 Editor::new_transport_marker_menu_popdown (GdkEventAny *ev)
879 transport_bar_drag_rect->hide();
880 range_marker_drag_rect->hide();
886 Editor::new_transport_marker_menu_set_loop ()
888 if (!session) return;
890 begin_reversible_command (_("set loop range"));
894 if ((tll = transport_loop_location()) == 0) {
895 Location* loc = new Location (temp_location->start(), temp_location->end(), _("Loop"), Location::IsAutoLoop);
896 XMLNode &before = session->locations()->get_state();
897 session->locations()->add (loc, true);
898 session->set_auto_loop_location (loc);
899 XMLNode &after = session->locations()->get_state();
900 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
903 XMLNode &before = tll->get_state();
904 tll->set_hidden (false, this);
905 tll->set (temp_location->start(), temp_location->end());
906 XMLNode &after = tll->get_state();
907 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
910 commit_reversible_command ();
914 Editor::new_transport_marker_menu_set_punch ()
916 if (!session) return;
918 begin_reversible_command (_("set punch range"));
922 if ((tpl = transport_punch_location()) == 0) {
923 tpl = new Location (temp_location->start(), temp_location->end(), _("Punch"), Location::IsAutoPunch);
924 XMLNode &before = session->locations()->get_state();
925 session->locations()->add (tpl, true);
926 session->set_auto_punch_location (tpl);
927 XMLNode &after = session->locations()->get_state();
928 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
930 XMLNode &before = tpl->get_state();
931 tpl->set_hidden(false, this);
932 tpl->set(temp_location->start(), temp_location->end());
933 XMLNode &after = tpl->get_state();
934 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
937 commit_reversible_command ();
941 Editor::update_loop_range_view (bool visibility)
949 if (session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
951 double x1 = frame_to_pixel (tll->start());
952 double x2 = frame_to_pixel (tll->end());
954 transport_loop_range_rect->property_x1() = x1;
955 transport_loop_range_rect->property_x2() = x2;
958 transport_loop_range_rect->show();
961 else if (visibility) {
962 transport_loop_range_rect->hide();
967 Editor::update_punch_range_view (bool visibility)
975 if ((Config->get_punch_in() || Config->get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
977 double x1 = frame_to_pixel (tpl->start());
978 double x2 = frame_to_pixel (tpl->end());
980 transport_punch_range_rect->property_x1() = x1;
981 transport_punch_range_rect->property_x2() = x2;
984 transport_punch_range_rect->show();
987 else if (visibility) {
988 transport_punch_range_rect->hide();
991 // if (session->get_punch_in()) {
992 // double x = frame_to_pixel (transport_punch_location->start());
993 // gnome_canvas_item_set (transport_punchin_line, "x1", x, "x2", x, NULL);
996 // gnome_canvas_item_show (transport_punchin_line);
999 // else if (visibility) {
1000 // gnome_canvas_item_hide (transport_punchin_line);
1003 // if (session->get_punch_out()) {
1004 // double x = frame_to_pixel (transport_punch_location->end());
1006 // gnome_canvas_item_set (transport_punchout_line, "x1", x, "x2", x, NULL);
1008 // if (visibility) {
1009 // gnome_canvas_item_show (transport_punchout_line);
1012 // else if (visibility) {
1013 // gnome_canvas_item_hide (transport_punchout_line);