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.
21 #include <sigc++/retype.h>
25 #include <libgnomecanvas/libgnomecanvas.h>
26 #include <gtkmm2ext/gtk_ui.h>
28 #include <ardour/location.h>
29 #include <pbd/memento_command.h>
33 #include "selection.h"
35 #include "gui_thread.h"
36 #include "simplerect.h"
44 using namespace ARDOUR;
49 Editor::clear_marker_display ()
51 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
55 location_markers.clear ();
59 Editor::add_new_location (Location *location)
61 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::add_new_location), location));
63 LocationMarkers *lam = new LocationMarkers;
66 if (location->is_cd_marker()) {
67 color = location_cd_marker_color;
68 } else if (location->is_mark()) {
69 color = location_marker_color;
70 } else if (location->is_auto_loop()) {
71 color = location_loop_color;
72 } else if (location->is_auto_punch()) {
73 color = location_punch_color;
75 color = location_range_color;
78 if (location->is_mark()) {
79 lam->start = new Marker (*this, *marker_group, color, location->name(), Marker::Mark, location->start());
82 } else if (location->is_auto_loop()) {
84 lam->start = new Marker (*this, *transport_marker_group, color,
85 location->name(), Marker::LoopStart, location->start());
86 lam->end = new Marker (*this, *transport_marker_group, color,
87 location->name(), Marker::LoopEnd, location->end());
89 } else if (location->is_auto_punch()) {
91 lam->start = new Marker (*this, *transport_marker_group, color,
92 location->name(), Marker::PunchIn, location->start());
93 lam->end = new Marker (*this, *transport_marker_group, color,
94 location->name(), Marker::PunchOut, location->end());
99 lam->start = new Marker (*this, *range_marker_group, color,
100 location->name(), Marker::Start, location->start());
101 lam->end = new Marker (*this, *range_marker_group, color,
102 location->name(), Marker::End, location->end());
105 if (location->is_hidden ()) {
111 location->start_changed.connect (mem_fun(*this, &Editor::location_changed));
112 location->end_changed.connect (mem_fun(*this, &Editor::location_changed));
113 location->changed.connect (mem_fun(*this, &Editor::location_changed));
114 location->name_changed.connect (mem_fun(*this, &Editor::location_changed));
115 location->FlagsChanged.connect (mem_fun(*this, &Editor::location_flags_changed));
117 pair<Location*,LocationMarkers*> newpair;
119 newpair.first = location;
120 newpair.second = lam;
122 location_markers.insert (newpair);
126 Editor::location_changed (Location *location)
128 ENSURE_GUI_THREAD (bind (mem_fun(*this, &Editor::location_changed), location));
130 LocationMarkers *lam = find_location_markers (location);
133 /* a location that isn't "marked" with markers */
137 lam->set_name (location->name());
138 lam->set_position (location->start(), location->end());
140 if (location->is_auto_loop()) {
141 update_loop_range_view ();
142 } else if (location->is_auto_punch()) {
143 update_punch_range_view ();
148 Editor::location_flags_changed (Location *location, void *src)
150 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::location_flags_changed), location, src));
152 LocationMarkers *lam = find_location_markers (location);
155 /* a location that isn't "marked" with markers */
159 if (location->is_cd_marker()) {
160 lam->set_color_rgba (location_cd_marker_color);
161 } else if (location->is_mark()) {
162 lam->set_color_rgba (location_marker_color);
163 } else if (location->is_auto_punch()) {
164 lam->set_color_rgba (location_punch_color);
165 } else if (location->is_auto_loop()) {
166 lam->set_color_rgba (location_loop_color);
168 lam->set_color_rgba (location_range_color);
171 if (location->is_hidden()) {
178 Editor::LocationMarkers::~LocationMarkers ()
189 Editor::LocationMarkers *
190 Editor::find_location_markers (Location *location)
192 LocationMarkerMap::iterator i;
194 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
195 if ((*i).first == location) {
204 Editor::find_location_from_marker (Marker *marker, bool& is_start)
206 LocationMarkerMap::iterator i;
208 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
209 LocationMarkers *lm = (*i).second;
210 if (lm->start == marker) {
213 } else if (lm->end == marker) {
223 Editor::refresh_location_display_internal (Locations::LocationList& locations)
225 clear_marker_display ();
227 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
228 add_new_location (*i);
233 Editor::refresh_location_display ()
235 ENSURE_GUI_THREAD(mem_fun(*this, &Editor::refresh_location_display));
238 session->locations()->apply (*this, &Editor::refresh_location_display_internal);
243 Editor::refresh_location_display_s (Change ignored)
245 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::refresh_location_display_s), ignored));
248 session->locations()->apply (*this, &Editor::refresh_location_display_internal);
253 Editor::LocationMarkers::hide()
256 if (end) { end->hide(); }
260 Editor::LocationMarkers::show()
263 if (end) { end->show(); }
267 Editor::LocationMarkers::set_name (const string& str)
269 start->set_name (str);
270 if (end) { end->set_name (str); }
274 Editor::LocationMarkers::set_position (nframes_t startf,
277 start->set_position (startf);
278 if (end) { end->set_position (endf); }
282 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
284 start->set_color_rgba (rgba);
285 if (end) { end->set_color_rgba (rgba); }
289 Editor::mouse_add_new_marker (nframes_t where)
293 session->locations()->next_available_name(markername,"mark");
294 Location *location = new Location (where, where, markername, Location::IsMark);
295 session->begin_reversible_command (_("add marker"));
296 XMLNode &before = session->locations()->get_state();
297 session->locations()->add (location, true);
298 XMLNode &after = session->locations()->get_state();
299 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
300 session->commit_reversible_command ();
305 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent* event)
310 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
311 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
315 Location* loc = find_location_from_marker (marker, is_start);
317 if (session && loc) {
318 Glib::signal_idle().connect (bind (mem_fun(*this, &Editor::really_remove_marker), loc));
323 Editor::really_remove_marker (Location* loc)
325 session->begin_reversible_command (_("remove marker"));
326 XMLNode &before = session->locations()->get_state();
327 session->locations()->remove (loc);
328 XMLNode &after = session->locations()->get_state();
329 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
330 session->commit_reversible_command ();
335 Editor::location_gone (Location *location)
337 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::location_gone), location));
339 LocationMarkerMap::iterator i;
341 if (location == transport_loop_location()) {
342 update_loop_range_view (true);
345 if (location == transport_punch_location()) {
346 update_punch_range_view (true);
349 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
350 if ((*i).first == location) {
352 location_markers.erase (i);
359 Editor::tm_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
361 if (tm_marker_menu == 0) {
362 build_tm_marker_menu ();
365 marker_menu_item = item;
366 tm_marker_menu->popup (1, ev->time);
371 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
374 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
375 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
380 Location * loc = find_location_from_marker (marker, is_start);
381 if (loc == transport_loop_location() || loc == transport_punch_location()) {
382 if (transport_marker_menu == 0) {
383 build_range_marker_menu (true);
385 marker_menu_item = item;
386 transport_marker_menu->popup (1, ev->time);
389 if (loc->is_mark()) {
390 bool start_or_end = loc->is_start() || loc->is_end();
393 if (start_end_marker_menu == 0)
394 build_marker_menu (true);
395 markerMenu = start_end_marker_menu;
397 if (marker_menu == 0)
398 build_marker_menu (false);
399 markerMenu = marker_menu;
403 // GTK2FIX use action group sensitivity
405 if (children.size() >= 3) {
406 MenuItem * loopitem = &children[2];
408 if (loc->is_mark()) {
409 loopitem->set_sensitive(false);
412 loopitem->set_sensitive(true);
417 marker_menu_item = item;
418 markerMenu->popup (1, ev->time);
421 if (loc->is_range_marker()) {
422 if (range_marker_menu == 0){
423 build_range_marker_menu (false);
425 marker_menu_item = item;
426 range_marker_menu->popup (1, ev->time);
432 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
434 if (new_transport_marker_menu == 0) {
435 build_new_transport_marker_menu ();
438 new_transport_marker_menu->popup (1, ev->time);
443 Editor::transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
445 if (transport_marker_menu == 0) {
446 build_range_marker_menu (true);
449 transport_marker_menu->popup (1, ev->time);
453 Editor::build_marker_menu (bool start_or_end)
455 using namespace Menu_Helpers;
457 Menu *markerMenu = new Menu;
459 start_end_marker_menu = markerMenu;
461 marker_menu = markerMenu;
463 MenuList& items = markerMenu->items();
464 markerMenu->set_name ("ArdourContextMenu");
466 items.push_back (MenuElem (_("Locate to Mark"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
467 items.push_back (MenuElem (_("Play from Mark"), mem_fun(*this, &Editor::marker_menu_play_from)));
468 items.push_back (MenuElem (_("Set Mark from Playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
470 items.push_back (SeparatorElem());
472 items.push_back (MenuElem (_("Hide Mark"), mem_fun(*this, &Editor::marker_menu_hide)));
473 if (start_or_end) return;
474 items.push_back (MenuElem (_("Rename Mark"), mem_fun(*this, &Editor::marker_menu_rename)));
475 items.push_back (MenuElem (_("Remove Mark"), mem_fun(*this, &Editor::marker_menu_remove)));
480 Editor::build_range_marker_menu (bool loop_or_punch)
482 using namespace Menu_Helpers;
484 Menu *markerMenu = new Menu;
486 transport_marker_menu = markerMenu;
488 range_marker_menu = markerMenu;
490 MenuList& items = markerMenu->items();
491 markerMenu->set_name ("ArdourContextMenu");
493 items.push_back (MenuElem (_("Locate to Range Mark"), mem_fun(*this, &Editor::marker_menu_set_playhead)));
494 items.push_back (MenuElem (_("Play from Range Mark"), mem_fun(*this, &Editor::marker_menu_play_from)));
495 if (! loop_or_punch) {
496 items.push_back (MenuElem (_("Play Range"), mem_fun(*this, &Editor::marker_menu_play_range)));
497 items.push_back (MenuElem (_("Loop Range"), mem_fun(*this, &Editor::marker_menu_loop_range)));
499 items.push_back (MenuElem (_("Set Range Mark from Playhead"), mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
500 items.push_back (MenuElem (_("Set Range from Range Selection"), mem_fun(*this, &Editor::marker_menu_set_from_selection)));
502 items.push_back (SeparatorElem());
504 items.push_back (MenuElem (_("Hide Range"), mem_fun(*this, &Editor::marker_menu_hide)));
505 if (! loop_or_punch) {
506 items.push_back (MenuElem (_("Rename Range"), mem_fun(*this, &Editor::marker_menu_rename)));
507 items.push_back (MenuElem (_("Remove Range"), mem_fun(*this, &Editor::marker_menu_remove)));
510 items.push_back (SeparatorElem());
512 items.push_back (MenuElem (_("Separate Regions in Range"), mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
513 items.push_back (MenuElem (_("Select All in Range"), mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
518 Editor::build_tm_marker_menu ()
520 using namespace Menu_Helpers;
522 tm_marker_menu = new Menu;
523 MenuList& items = tm_marker_menu->items();
524 tm_marker_menu->set_name ("ArdourContextMenu");
526 items.push_back (MenuElem (_("Edit"), mem_fun(*this, &Editor::marker_menu_edit)));
527 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &Editor::marker_menu_remove)));
531 Editor::build_new_transport_marker_menu ()
533 using namespace Menu_Helpers;
535 new_transport_marker_menu = new Menu;
536 MenuList& items = new_transport_marker_menu->items();
537 new_transport_marker_menu->set_name ("ArdourContextMenu");
539 items.push_back (MenuElem (_("Set Loop Range"), mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
540 items.push_back (MenuElem (_("Set Punch Range"), mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
542 new_transport_marker_menu->signal_unmap_event().connect ( mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
546 Editor::marker_menu_hide ()
550 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
551 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
558 if ((l = find_location_from_marker (marker, is_start)) != 0) {
559 l->set_hidden (true, this);
564 Editor::marker_menu_select_all_selectables_using_range ()
568 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
569 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
576 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
577 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, Selection::Set);
583 Editor::marker_menu_separate_regions_using_location ()
587 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
588 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
595 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
596 separate_regions_using_location (*l);
602 Editor::marker_menu_play_from ()
606 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
607 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
614 if ((l = find_location_from_marker (marker, is_start)) != 0) {
617 session->request_locate (l->start(), true);
620 //session->request_bounded_roll (l->start(), l->end());
623 session->request_locate (l->start(), true);
625 session->request_locate (l->end(), true);
632 Editor::marker_menu_set_playhead ()
636 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
637 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
644 if ((l = find_location_from_marker (marker, is_start)) != 0) {
647 session->request_locate (l->start(), false);
651 session->request_locate (l->start(), false);
653 session->request_locate (l->end(), false);
660 Editor::marker_menu_set_from_playhead ()
664 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
665 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
672 if ((l = find_location_from_marker (marker, is_start)) != 0) {
675 l->set_start (session->transport_frame ());
679 l->set_start (session->transport_frame ());
681 l->set_end (session->transport_frame ());
688 Editor::marker_menu_set_from_selection ()
692 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
693 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
700 if ((l = find_location_from_marker (marker, is_start)) != 0) {
707 /* if range selection use first to last */
709 if (mouse_mode == Editing::MouseRange) {
710 if (!selection->time.empty()) {
711 l->set_start (selection->time.start());
712 l->set_end (selection->time.end_frame());
716 if (!selection->regions.empty()) {
717 l->set_start (selection->regions.start());
718 l->set_end (selection->regions.end_frame());
727 Editor::marker_menu_play_range ()
731 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
732 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
739 if ((l = find_location_from_marker (marker, is_start)) != 0) {
742 session->request_locate (l->start(), true);
745 session->request_bounded_roll (l->start(), l->end());
752 Editor::marker_menu_loop_range ()
756 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
757 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
764 if ((l = find_location_from_marker (marker, is_start)) != 0) {
766 if ((l2 = transport_loop_location()) != 0) {
767 l2->set (l->start(), l->end());
769 // enable looping, reposition and start rolling
770 session->request_play_loop(true);
771 session->request_locate (l2->start(), true);
777 Editor::marker_menu_edit ()
783 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
784 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
788 if ((mm = dynamic_cast<MeterMarker*> (marker)) != 0) {
789 edit_meter_section (&mm->meter());
790 } else if ((tm = dynamic_cast<TempoMarker*> (marker)) != 0) {
791 edit_tempo_section (&tm->tempo());
793 fatal << X_("programming erorr: unhandled marker type in Editor::marker_menu_edit")
800 Editor::marker_menu_remove ()
806 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
807 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
811 if ((mm = dynamic_cast<MeterMarker*> (marker)) != 0) {
812 remove_meter_marker (marker_menu_item);
813 } else if ((tm = dynamic_cast<TempoMarker*> (marker)) != 0) {
814 remove_tempo_marker (marker_menu_item);
816 remove_marker (*marker_menu_item, (GdkEvent*) 0);
821 Editor::marker_menu_rename ()
825 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
826 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
833 loc = find_location_from_marker (marker, is_start);
837 ArdourPrompter dialog (true);
840 dialog.set_prompt (_("New Name:"));
842 if (loc->is_mark()) {
843 dialog.set_title (_("ardour: rename mark"));
845 dialog.set_title (_("ardour: rename range"));
848 dialog.set_name ("MarkRenameWindow");
849 dialog.set_size_request (250, -1);
850 dialog.set_position (Gtk::WIN_POS_MOUSE);
852 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
853 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
854 dialog.set_initial_text (loc->name());
858 switch (dialog.run ()) {
859 case RESPONSE_ACCEPT:
865 begin_reversible_command ( _("rename marker") );
866 XMLNode &before = session->locations()->get_state();
868 dialog.get_result(txt);
871 XMLNode &after = session->locations()->get_state();
872 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
873 commit_reversible_command ();
877 Editor::new_transport_marker_menu_popdown (GdkEventAny *ev)
880 transport_bar_drag_rect->hide();
881 range_marker_drag_rect->hide();
887 Editor::new_transport_marker_menu_set_loop ()
889 if (!session) return;
891 begin_reversible_command (_("set loop range"));
895 if ((tll = transport_loop_location()) == 0) {
896 Location* loc = new Location (temp_location->start(), temp_location->end(), _("Loop"), Location::IsAutoLoop);
897 XMLNode &before = session->locations()->get_state();
898 session->locations()->add (loc, true);
899 session->set_auto_loop_location (loc);
900 XMLNode &after = session->locations()->get_state();
901 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
904 XMLNode &before = tll->get_state();
905 tll->set_hidden (false, this);
906 tll->set (temp_location->start(), temp_location->end());
907 XMLNode &after = tll->get_state();
908 session->add_command (new MementoCommand<Location>(*tll, &before, &after));
911 commit_reversible_command ();
915 Editor::new_transport_marker_menu_set_punch ()
917 if (!session) return;
919 begin_reversible_command (_("set punch range"));
923 if ((tpl = transport_punch_location()) == 0) {
924 tpl = new Location (temp_location->start(), temp_location->end(), _("Punch"), Location::IsAutoPunch);
925 XMLNode &before = session->locations()->get_state();
926 session->locations()->add (tpl, true);
927 session->set_auto_punch_location (tpl);
928 XMLNode &after = session->locations()->get_state();
929 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
931 XMLNode &before = tpl->get_state();
932 tpl->set_hidden(false, this);
933 tpl->set(temp_location->start(), temp_location->end());
934 XMLNode &after = tpl->get_state();
935 session->add_command (new MementoCommand<Location>(*tpl, &before, &after));
938 commit_reversible_command ();
942 Editor::update_loop_range_view (bool visibility)
950 if (session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
952 double x1 = frame_to_pixel (tll->start());
953 double x2 = frame_to_pixel (tll->end());
955 transport_loop_range_rect->property_x1() = x1;
956 transport_loop_range_rect->property_x2() = x2;
959 transport_loop_range_rect->show();
962 else if (visibility) {
963 transport_loop_range_rect->hide();
968 Editor::update_punch_range_view (bool visibility)
976 if ((Config->get_punch_in() || Config->get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
978 double x1 = frame_to_pixel (tpl->start());
979 double x2 = frame_to_pixel (tpl->end());
981 transport_punch_range_rect->property_x1() = x1;
982 transport_punch_range_rect->property_x2() = x2;
985 transport_punch_range_rect->show();
988 else if (visibility) {
989 transport_punch_range_rect->hide();
992 // if (session->get_punch_in()) {
993 // double x = frame_to_pixel (transport_punch_location->start());
994 // gnome_canvas_item_set (transport_punchin_line, "x1", x, "x2", x, NULL);
997 // gnome_canvas_item_show (transport_punchin_line);
1000 // else if (visibility) {
1001 // gnome_canvas_item_hide (transport_punchin_line);
1004 // if (session->get_punch_out()) {
1005 // double x = frame_to_pixel (transport_punch_location->end());
1007 // gnome_canvas_item_set (transport_punchout_line, "x1", x, "x2", x, NULL);
1009 // if (visibility) {
1010 // gnome_canvas_item_show (transport_punchout_line);
1013 // else if (visibility) {
1014 // gnome_canvas_item_hide (transport_punchout_line);