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.
23 #include <gtkmm2ext/gtk_ui.h>
25 #include "ardour/session.h"
26 #include "ardour/location.h"
27 #include "ardour/profile.h"
28 #include "pbd/memento_command.h"
30 #include "canvas/canvas.h"
31 #include "canvas/item.h"
32 #include "canvas/rectangle.h"
36 #include "selection.h"
38 #include "gui_thread.h"
41 #include "editor_drag.h"
46 using namespace ARDOUR;
49 using namespace Gtkmm2ext;
52 Editor::clear_marker_display ()
54 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
58 location_markers.clear ();
59 _sorted_marker_lists.clear ();
63 Editor::add_new_location (Location *location)
65 ENSURE_GUI_THREAD (*this, &Editor::add_new_location, location);
67 ArdourCanvas::Container* group = add_new_location_internal (location);
69 /* Do a full update of the markers in this group */
70 update_marker_labels (group);
72 if (location->is_auto_punch()) {
73 update_punch_range_view ();
76 if (location->is_auto_loop()) {
77 update_loop_range_view ();
81 /** Add a new location, without a time-consuming update of all marker labels;
82 * the caller must call update_marker_labels () after calling this.
83 * @return canvas group that the location's marker was added to.
85 ArdourCanvas::Container*
86 Editor::add_new_location_internal (Location* location)
88 LocationMarkers *lam = new LocationMarkers;
91 /* make a note here of which group this marker ends up in */
92 ArdourCanvas::Container* group = 0;
94 if (location->is_cd_marker()) {
95 color = location_cd_marker_color;
96 } else if (location->is_mark()) {
97 color = location_marker_color;
98 } else if (location->is_auto_loop()) {
99 color = location_loop_color;
100 } else if (location->is_auto_punch()) {
101 color = location_punch_color;
103 color = location_range_color;
106 if (location->is_mark()) {
108 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
109 lam->start = new ArdourMarker (*this, *cd_marker_group, color, location->name(), ArdourMarker::Mark, location->start());
110 group = cd_marker_group;
112 lam->start = new ArdourMarker (*this, *marker_group, color, location->name(), ArdourMarker::Mark, location->start());
113 group = marker_group;
118 } else if (location->is_auto_loop()) {
121 lam->start = new ArdourMarker (*this, *transport_marker_group, color,
122 location->name(), ArdourMarker::LoopStart, location->start());
123 lam->end = new ArdourMarker (*this, *transport_marker_group, color,
124 location->name(), ArdourMarker::LoopEnd, location->end());
125 group = transport_marker_group;
127 } else if (location->is_auto_punch()) {
130 lam->start = new ArdourMarker (*this, *transport_marker_group, color,
131 location->name(), ArdourMarker::PunchIn, location->start());
132 lam->end = new ArdourMarker (*this, *transport_marker_group, color,
133 location->name(), ArdourMarker::PunchOut, location->end());
134 group = transport_marker_group;
136 } else if (location->is_session_range()) {
139 lam->start = new ArdourMarker (*this, *marker_group, color, _("start"), ArdourMarker::SessionStart, location->start());
140 lam->end = new ArdourMarker (*this, *marker_group, color, _("end"), ArdourMarker::SessionEnd, location->end());
141 group = marker_group;
145 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
146 lam->start = new ArdourMarker (*this, *cd_marker_group, color,
147 location->name(), ArdourMarker::RangeStart, location->start());
148 lam->end = new ArdourMarker (*this, *cd_marker_group, color,
149 location->name(), ArdourMarker::RangeEnd, location->end());
150 group = cd_marker_group;
152 lam->start = new ArdourMarker (*this, *range_marker_group, color,
153 location->name(), ArdourMarker::RangeStart, location->start());
154 lam->end = new ArdourMarker (*this, *range_marker_group, color,
155 location->name(), ArdourMarker::RangeEnd, location->end());
156 group = range_marker_group;
160 if (location->is_hidden ()) {
166 location->name_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
167 location->FlagsChanged.connect (*this, invalidator (*this), boost::bind (&Editor::location_flags_changed, this, location), gui_context());
169 pair<Location*,LocationMarkers*> newpair;
171 newpair.first = location;
172 newpair.second = lam;
174 location_markers.insert (newpair);
176 if (select_new_marker && location->is_mark()) {
177 selection->set (lam->start);
178 select_new_marker = false;
181 lam->canvas_height_set (_visible_canvas_height);
182 lam->set_show_lines (_show_marker_lines);
184 /* Add these markers to the appropriate sorted marker lists, which will render
185 them unsorted until a call to update_marker_labels() sorts them out.
187 _sorted_marker_lists[group].push_back (lam->start);
189 _sorted_marker_lists[group].push_back (lam->end);
196 Editor::location_changed (Location *location)
198 ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
200 LocationMarkers *lam = find_location_markers (location);
203 /* a location that isn't "marked" with markers */
207 lam->set_name (location->name ());
208 lam->set_position (location->start(), location->end());
210 if (location->is_auto_loop()) {
211 update_loop_range_view ();
212 } else if (location->is_auto_punch()) {
213 update_punch_range_view ();
216 check_marker_label (lam->start);
218 check_marker_label (lam->end);
222 /** Look at a marker and check whether its label, and those of the previous and next markers,
223 * need to have their labels updated (in case those labels need to be shortened or can be
227 Editor::check_marker_label (ArdourMarker* m)
229 /* Get a time-ordered list of markers from the last time anything changed */
230 std::list<ArdourMarker*>& sorted = _sorted_marker_lists[m->get_parent()];
232 list<ArdourMarker*>::iterator i = find (sorted.begin(), sorted.end(), m);
234 list<ArdourMarker*>::iterator prev = sorted.end ();
235 list<ArdourMarker*>::iterator next = i;
238 /* Look to see if the previous marker is still behind `m' in time */
239 if (i != sorted.begin()) {
244 if ((*prev)->position() > m->position()) {
245 /* This marker is no longer in the correct order with the previous one, so
246 * update all the markers in this group.
248 update_marker_labels (m->get_parent ());
253 /* Look to see if the next marker is still ahead of `m' in time */
254 if (next != sorted.end() && (*next)->position() < m->position()) {
255 /* This marker is no longer in the correct order with the next one, so
256 * update all the markers in this group.
258 update_marker_labels (m->get_parent ());
262 if (prev != sorted.end()) {
264 /* Update just the available space between the previous marker and this one */
266 double const p = sample_to_pixel (m->position() - (*prev)->position());
268 if (m->label_on_left()) {
269 (*prev)->set_right_label_limit (p / 2);
271 (*prev)->set_right_label_limit (p);
274 if ((*prev)->label_on_left ()) {
275 m->set_left_label_limit (p);
277 m->set_left_label_limit (p / 2);
281 if (next != sorted.end()) {
283 /* Update just the available space between this marker and the next */
285 double const p = sample_to_pixel ((*next)->position() - m->position());
287 if ((*next)->label_on_left()) {
288 m->set_right_label_limit (p / 2);
290 m->set_right_label_limit (p);
293 if (m->label_on_left()) {
294 (*next)->set_left_label_limit (p);
296 (*next)->set_left_label_limit (p / 2);
301 struct MarkerComparator {
302 bool operator() (ArdourMarker const * a, ArdourMarker const * b) {
303 return a->position() < b->position();
307 /** Update all marker labels in all groups */
309 Editor::update_marker_labels ()
311 for (std::map<ArdourCanvas::Container *, std::list<ArdourMarker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
312 update_marker_labels (i->first);
316 /** Look at all markers in a group and update label widths */
318 Editor::update_marker_labels (ArdourCanvas::Container* group)
320 list<ArdourMarker*>& sorted = _sorted_marker_lists[group];
322 if (sorted.empty()) {
326 /* We sort the list of markers and then set up the space available between each one */
328 sorted.sort (MarkerComparator ());
330 list<ArdourMarker*>::iterator i = sorted.begin ();
332 list<ArdourMarker*>::iterator prev = sorted.end ();
333 list<ArdourMarker*>::iterator next = i;
335 if (next != sorted.end()) {
339 while (i != sorted.end()) {
341 if (prev != sorted.end()) {
342 double const p = sample_to_pixel ((*i)->position() - (*prev)->position());
344 if ((*prev)->label_on_left()) {
345 (*i)->set_left_label_limit (p);
347 (*i)->set_left_label_limit (p / 2);
352 if (next != sorted.end()) {
353 double const p = sample_to_pixel ((*next)->position() - (*i)->position());
355 if ((*next)->label_on_left()) {
356 (*i)->set_right_label_limit (p / 2);
358 (*i)->set_right_label_limit (p);
370 Editor::location_flags_changed (Location *location)
372 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
374 LocationMarkers *lam = find_location_markers (location);
377 /* a location that isn't "marked" with markers */
381 // move cd markers to/from cd marker bar as appropriate
382 ensure_cd_marker_updated (lam, location);
384 if (location->is_cd_marker()) {
385 lam->set_color_rgba (location_cd_marker_color);
386 } else if (location->is_mark()) {
387 lam->set_color_rgba (location_marker_color);
388 } else if (location->is_auto_punch()) {
389 lam->set_color_rgba (location_punch_color);
390 } else if (location->is_auto_loop()) {
391 lam->set_color_rgba (location_loop_color);
393 lam->set_color_rgba (location_range_color);
396 if (location->is_hidden()) {
403 void Editor::update_cd_marker_display ()
405 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
406 LocationMarkers * lam = i->second;
407 Location * location = i->first;
409 ensure_cd_marker_updated (lam, location);
413 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
415 if (location->is_cd_marker()
416 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
418 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
420 lam->start->reparent (*cd_marker_group);
423 lam->end->reparent (*cd_marker_group);
426 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
427 && (lam->start->get_parent() == cd_marker_group))
429 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
430 if (location->is_mark()) {
432 lam->start->reparent (*marker_group);
435 lam->end->reparent (*marker_group);
440 lam->start->reparent (*range_marker_group);
443 lam->end->reparent (*range_marker_group);
449 Editor::LocationMarkers::~LocationMarkers ()
455 Editor::LocationMarkers *
456 Editor::find_location_markers (Location *location) const
458 LocationMarkerMap::const_iterator i;
460 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
461 if ((*i).first == location) {
470 Editor::find_location_from_marker (ArdourMarker *marker, bool& is_start) const
472 LocationMarkerMap::const_iterator i;
474 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
475 LocationMarkers *lm = (*i).second;
476 if (lm->start == marker) {
479 } else if (lm->end == marker) {
489 Editor::refresh_location_display_internal (const Locations::LocationList& locations)
493 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
494 i->second->valid = false;
499 for (Locations::LocationList::const_iterator i = locations.begin(); i != locations.end(); ++i) {
501 LocationMarkerMap::iterator x;
503 if ((x = location_markers.find (*i)) != location_markers.end()) {
504 x->second->valid = true;
508 add_new_location_internal (*i);
511 /* remove dead ones */
513 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
515 LocationMarkerMap::iterator tmp;
520 if (!i->second->valid) {
522 remove_sorted_marker (i->second->start);
523 if (i->second->end) {
524 remove_sorted_marker (i->second->end);
527 LocationMarkers* m = i->second;
528 location_markers.erase (i);
535 update_punch_range_view ();
536 update_loop_range_view ();
540 Editor::refresh_location_display ()
542 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
545 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
548 update_marker_labels ();
552 Editor::LocationMarkers::hide()
561 Editor::LocationMarkers::show()
570 Editor::LocationMarkers::canvas_height_set (double h)
572 start->canvas_height_set (h);
574 end->canvas_height_set (h);
579 Editor::LocationMarkers::set_name (const string& str)
581 /* XXX: hack: don't change names of session start/end markers */
583 if (start->type() != ArdourMarker::SessionStart) {
584 start->set_name (str);
587 if (end && end->type() != ArdourMarker::SessionEnd) {
593 Editor::LocationMarkers::set_position (framepos_t startf,
596 start->set_position (startf);
598 end->set_position (endf);
603 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
605 start->set_color_rgba (rgba);
607 end->set_color_rgba (rgba);
612 Editor::LocationMarkers::set_show_lines (bool s)
614 start->set_show_line (s);
616 end->set_show_line (s);
621 Editor::LocationMarkers::set_selected (bool s)
623 start->set_selected (s);
625 end->set_selected (s);
630 Editor::LocationMarkers::setup_lines ()
632 start->setup_line ();
639 Editor::mouse_add_new_marker (framepos_t where, bool is_cd)
642 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
645 _session->locations()->next_available_name(markername, _("mark"));
646 if (!choose_new_marker_name(markername)) {
649 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
650 begin_reversible_command (_("add marker"));
652 XMLNode &before = _session->locations()->get_state();
653 _session->locations()->add (location, true);
654 XMLNode &after = _session->locations()->get_state();
655 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
657 /* find the marker we just added */
659 LocationMarkers *lam = find_location_markers (location);
661 /* make it the selected marker */
662 selection->set (lam->start);
665 commit_reversible_command ();
670 Editor::mouse_add_new_loop (framepos_t where)
676 /* Make this marker 1/8th of the visible area of the session so that
677 it's reasonably easy to manipulate after creation.
680 framepos_t const end = where + current_page_samples() / 8;
682 set_loop_range (where, end, _("set loop range"));
686 Editor::mouse_add_new_punch (framepos_t where)
692 /* Make this marker 1/8th of the visible area of the session so that
693 it's reasonably easy to manipulate after creation.
696 framepos_t const end = where + current_page_samples() / 8;
698 set_punch_range (where, end, _("set punch range"));
702 Editor::mouse_add_new_range (framepos_t where)
708 /* Make this marker 1/8th of the visible area of the session so that
709 it's reasonably easy to manipulate after creation.
712 framepos_t const end = where + current_page_samples() / 8;
715 _session->locations()->next_available_name (name, _("range"));
716 Location* loc = new Location (*_session, where, end, name, Location::IsRangeMarker);
718 begin_reversible_command (_("new range marker"));
719 XMLNode& before = _session->locations()->get_state ();
720 _session->locations()->add (loc, true);
721 XMLNode& after = _session->locations()->get_state ();
722 _session->add_command (new MementoCommand<Locations> (*_session->locations(), &before, &after));
723 commit_reversible_command ();
727 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
729 ArdourMarker* marker;
732 if ((marker = static_cast<ArdourMarker*> (item.get_data ("marker"))) == 0) {
733 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
734 abort(); /*NOTREACHED*/
737 if (entered_marker == marker) {
738 entered_marker = NULL;
741 Location* loc = find_location_from_marker (marker, is_start);
743 if (_session && loc) {
744 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
749 Editor::really_remove_marker (Location* loc)
751 begin_reversible_command (_("remove marker"));
752 XMLNode &before = _session->locations()->get_state();
753 _session->locations()->remove (loc);
754 XMLNode &after = _session->locations()->get_state();
755 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
756 commit_reversible_command ();
761 Editor::location_gone (Location *location)
763 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
765 LocationMarkerMap::iterator i;
767 if (location == transport_loop_location()) {
768 update_loop_range_view ();
771 if (location == transport_punch_location()) {
772 update_punch_range_view ();
775 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
776 if (i->first == location) {
778 remove_sorted_marker (i->second->start);
779 if (i->second->end) {
780 remove_sorted_marker (i->second->end);
783 LocationMarkers* m = i->second;
784 location_markers.erase (i);
787 /* Markers that visually overlap with this (removed) marker
788 * need to be re-displayed.
789 * But finding such cases is similarly expensive as simply
790 * re-displaying all.. so:
792 refresh_location_display ();
799 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
801 marker_menu_item = item;
805 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
807 bool can_remove = false;
810 can_remove = mm->meter().movable ();
811 delete meter_marker_menu;
812 build_meter_marker_menu (mm, can_remove);
813 meter_marker_menu->popup (1, ev->time);
815 if (!tm->tempo().active()) {
818 can_remove = tm->tempo().movable() && !tm->tempo().locked_to_meter();
819 delete tempo_marker_menu;
820 build_tempo_marker_menu (tm, can_remove);
821 tempo_marker_menu->popup (1, ev->time);
828 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
830 ArdourMarker * marker;
831 if ((marker = reinterpret_cast<ArdourMarker *> (item->get_data("marker"))) == 0) {
832 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
833 abort(); /*NOTREACHED*/
837 Location * loc = find_location_from_marker (marker, is_start);
839 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) {
841 if (transport_marker_menu == 0) {
842 build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range());
845 marker_menu_item = item;
846 transport_marker_menu->popup (1, ev->time);
848 } else if (loc->is_mark()) {
851 build_marker_menu (loc);
853 // GTK2FIX use action group sensitivity
855 if (children.size() >= 3) {
856 MenuItem * loopitem = &children[2];
858 if (loc->is_mark()) {
859 loopitem->set_sensitive(false);
862 loopitem->set_sensitive(true);
867 marker_menu_item = item;
868 marker_menu->popup (1, ev->time);
870 } else if (loc->is_range_marker()) {
871 if (range_marker_menu == 0) {
872 build_range_marker_menu (false, false);
874 marker_menu_item = item;
875 range_marker_menu->popup (1, ev->time);
880 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
882 if (new_transport_marker_menu == 0) {
883 build_new_transport_marker_menu ();
886 new_transport_marker_menu->popup (1, ev->time);
891 Editor::build_marker_menu (Location* loc)
893 using namespace Menu_Helpers;
895 marker_menu = new Menu;
896 MenuList& items = marker_menu->items();
897 marker_menu->set_name ("ArdourContextMenu");
899 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
900 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
901 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
903 items.push_back (SeparatorElem());
905 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
907 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
908 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
910 items.push_back (CheckMenuElem (_("Lock")));
911 Gtk::CheckMenuItem* lock_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
912 if (loc->locked ()) {
913 lock_item->set_active ();
915 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
917 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
918 Gtk::CheckMenuItem* glue_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
919 if (loc->position_lock_style() == MusicTime) {
920 glue_item->set_active ();
922 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
924 items.push_back (SeparatorElem());
926 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
930 Editor::build_range_marker_menu (bool loop_or_punch, bool session)
932 using namespace Menu_Helpers;
934 bool const loop_or_punch_or_session = loop_or_punch | session;
936 Menu *markerMenu = new Menu;
937 if (loop_or_punch_or_session) {
938 transport_marker_menu = markerMenu;
940 range_marker_menu = markerMenu;
942 MenuList& items = markerMenu->items();
943 markerMenu->set_name ("ArdourContextMenu");
945 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
946 items.push_back (MenuElem (_("Locate to Marker"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
947 items.push_back (MenuElem (_("Play from Marker"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
948 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
950 items.push_back (MenuElem (_("Set Marker from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
951 items.push_back (MenuElem (_("Set Range from Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection), false)));
953 items.push_back (MenuElem (_("Zoom to Range"), sigc::mem_fun (*this, &Editor::marker_menu_zoom_to_range)));
955 items.push_back (SeparatorElem());
956 items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_range)));
957 items.push_back (SeparatorElem());
959 if (!loop_or_punch_or_session) {
960 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
961 items.push_back (MenuElem (_("Rename Range..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
965 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
968 if (!loop_or_punch_or_session || !session) {
969 items.push_back (SeparatorElem());
972 items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
973 items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
974 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
978 Editor::build_tempo_marker_menu (TempoMarker* loc, bool can_remove)
980 using namespace Menu_Helpers;
982 tempo_marker_menu = new Menu;
983 MenuList& items = tempo_marker_menu->items();
984 tempo_marker_menu->set_name ("ArdourContextMenu");
986 if (loc->tempo().type() == TempoSection::Constant) {
987 items.push_back (MenuElem (_("Make Ramped"), sigc::mem_fun(*this, &Editor::toggle_tempo_type)));
989 items.push_back (MenuElem (_("Make Constant"), sigc::mem_fun(*this, &Editor::toggle_tempo_type)));
992 if (loc->tempo().position_lock_style() == AudioTime && can_remove) {
993 items.push_back (MenuElem (_("Lock to Music"), sigc::mem_fun(*this, &Editor::toggle_marker_lock_style)));
994 } else if (can_remove) {
995 items.push_back (MenuElem (_("Lock to Audio"), sigc::mem_fun(*this, &Editor::toggle_marker_lock_style)));
998 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
999 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
1000 items.back().set_sensitive (can_remove);
1004 Editor::build_meter_marker_menu (MeterMarker* loc, bool can_remove)
1006 using namespace Menu_Helpers;
1008 meter_marker_menu = new Menu;
1009 MenuList& items = meter_marker_menu->items();
1010 meter_marker_menu->set_name ("ArdourContextMenu");
1012 if (loc->meter().position_lock_style() == AudioTime && can_remove) {
1013 items.push_back (MenuElem (_("Lock to Music"), sigc::mem_fun(*this, &Editor::toggle_marker_lock_style)));
1014 } else if (can_remove) {
1015 items.push_back (MenuElem (_("Lock to Audio"), sigc::mem_fun(*this, &Editor::toggle_marker_lock_style)));
1018 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
1019 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
1021 items.back().set_sensitive (can_remove);
1025 Editor::build_new_transport_marker_menu ()
1027 using namespace Menu_Helpers;
1029 new_transport_marker_menu = new Menu;
1030 MenuList& items = new_transport_marker_menu->items();
1031 new_transport_marker_menu->set_name ("ArdourContextMenu");
1033 items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
1034 items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
1036 new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
1040 Editor::marker_menu_hide ()
1042 ArdourMarker* marker;
1044 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1045 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1046 abort(); /*NOTREACHED*/
1052 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1053 l->set_hidden (true, this);
1058 Editor::marker_menu_select_using_range ()
1060 ArdourMarker* marker;
1062 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1063 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1064 abort(); /*NOTREACHED*/
1070 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1071 set_selection_from_range (*l);
1076 Editor::marker_menu_select_all_selectables_using_range ()
1078 ArdourMarker* marker;
1080 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1081 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1082 abort(); /*NOTREACHED*/
1088 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1089 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, track_views, Selection::Set, false);
1095 Editor::marker_menu_separate_regions_using_location ()
1097 ArdourMarker* marker;
1099 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1100 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1101 abort(); /*NOTREACHED*/
1107 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1108 separate_regions_using_location (*l);
1114 Editor::marker_menu_play_from ()
1116 ArdourMarker* marker;
1118 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1119 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1120 abort(); /*NOTREACHED*/
1126 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1129 _session->request_locate (l->start(), true);
1132 //_session->request_bounded_roll (l->start(), l->end());
1135 _session->request_locate (l->start(), true);
1137 _session->request_locate (l->end(), true);
1144 Editor::marker_menu_set_playhead ()
1146 ArdourMarker* marker;
1148 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1149 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1150 abort(); /*NOTREACHED*/
1156 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1159 _session->request_locate (l->start(), false);
1163 _session->request_locate (l->start(), false);
1165 _session->request_locate (l->end(), false);
1172 Editor::marker_menu_range_to_next ()
1174 ArdourMarker* marker;
1179 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1180 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1181 abort(); /*NOTREACHED*/
1187 if ((l = find_location_from_marker (marker, is_start)) == 0) {
1193 _session->locations()->marks_either_side (marker->position(), start, end);
1195 if (end != max_framepos) {
1196 string range_name = l->name();
1197 range_name += "-range";
1199 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1200 _session->locations()->add (newrange);
1205 Editor::marker_menu_set_from_playhead ()
1207 ArdourMarker* marker;
1209 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1210 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1211 abort(); /*NOTREACHED*/
1217 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1220 l->set_start (_session->audible_frame ());
1224 l->set_start (_session->audible_frame ());
1226 l->set_end (_session->audible_frame ());
1233 Editor::marker_menu_set_from_selection (bool /*force_regions*/)
1235 ArdourMarker* marker;
1237 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1238 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1239 abort(); /*NOTREACHED*/
1245 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1253 if (!selection->time.empty()) {
1254 l->set (selection->time.start(), selection->time.end_frame());
1255 } else if (!selection->regions.empty()) {
1256 l->set (selection->regions.start(), selection->regions.end_frame());
1264 Editor::marker_menu_play_range ()
1266 ArdourMarker* marker;
1268 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1269 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1270 abort(); /*NOTREACHED*/
1276 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1279 _session->request_locate (l->start(), true);
1282 _session->request_bounded_roll (l->start(), l->end());
1289 Editor::marker_menu_loop_range ()
1291 ArdourMarker* marker;
1293 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1294 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1295 abort(); /*NOTREACHED*/
1301 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1303 if ((l2 = transport_loop_location()) != 0) {
1304 l2->set (l->start(), l->end());
1306 // enable looping, reposition and start rolling
1307 _session->request_locate (l2->start(), true);
1308 _session->request_play_loop(true);
1313 /** Temporal zoom to the range of the marker_menu_item (plus 5% either side) */
1315 Editor::marker_menu_zoom_to_range ()
1317 ArdourMarker* marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"));
1321 Location* l = find_location_from_marker (marker, is_start);
1326 framecnt_t const extra = l->length() * 0.05;
1327 framepos_t a = l->start ();
1332 framepos_t b = l->end ();
1333 if (b < (max_framepos - extra)) {
1337 temporal_zoom_by_frame (a, b);
1341 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1343 ArdourMarker* marker = reinterpret_cast<ArdourMarker*> (p);
1345 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1346 abort(); /*NOTREACHED*/
1349 *m = dynamic_cast<MeterMarker*> (marker);
1350 *t = dynamic_cast<TempoMarker*> (marker);
1354 Editor::marker_menu_edit ()
1358 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1361 edit_meter_section (&mm->meter());
1363 edit_tempo_section (&tm->tempo());
1368 Editor::marker_menu_remove ()
1372 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1375 remove_meter_marker (marker_menu_item);
1377 remove_tempo_marker (marker_menu_item);
1379 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1384 Editor::toggle_marker_lock_style ()
1388 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1391 begin_reversible_command (_("change meter lock style"));
1392 XMLNode &before = _session->tempo_map().get_state();
1393 MeterSection* msp = &mm->meter();
1394 if (mm->meter().position_lock_style() == AudioTime) {
1395 _session->tempo_map().replace_meter_bbt (*msp, Meter (msp->divisions_per_bar(), msp->note_divisor()), msp->bbt());
1397 _session->tempo_map().replace_meter_frame (*msp, Meter (msp->divisions_per_bar(), msp->note_divisor()), msp->frame());
1399 XMLNode &after = _session->tempo_map().get_state();
1400 _session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
1401 commit_reversible_command ();
1403 begin_reversible_command (_("change tempo lock style"));
1404 XMLNode &before = _session->tempo_map().get_state();
1405 TempoSection* tsp = &tm->tempo();
1406 const PositionLockStyle pls = (tsp->position_lock_style() == AudioTime) ? MusicTime : AudioTime;
1407 _session->tempo_map().replace_tempo (*tsp, Tempo (tsp->beats_per_minute(), tsp->note_type()), tsp->pulse(), tsp->frame(), tsp->type(), pls);
1409 XMLNode &after = _session->tempo_map().get_state();
1410 _session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
1411 commit_reversible_command ();
1416 Editor::toggle_tempo_type ()
1420 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1423 begin_reversible_command (_("change tempo type"));
1424 XMLNode &before = _session->tempo_map().get_state();
1425 TempoSection* tsp = &tm->tempo();
1426 const TempoSection::Type type = (tsp->type() == TempoSection::Ramp) ? TempoSection::Constant : TempoSection::Ramp;
1427 _session->tempo_map().replace_tempo (*tsp, Tempo (tsp->beats_per_minute(), tsp->note_type()), tsp->pulse(), tsp->frame()
1428 , type, tsp->position_lock_style());
1430 XMLNode &after = _session->tempo_map().get_state();
1431 _session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
1432 commit_reversible_command ();
1437 Editor::toggle_marker_menu_lock ()
1439 ArdourMarker* marker;
1441 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1442 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1443 abort(); /*NOTREACHED*/
1449 loc = find_location_from_marker (marker, ignored);
1455 if (loc->locked()) {
1463 Editor::marker_menu_rename ()
1465 ArdourMarker* marker;
1467 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1468 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1469 abort(); /*NOTREACHED*/
1473 rename_marker (marker);
1477 Editor::rename_marker(ArdourMarker *marker)
1482 loc = find_location_from_marker (marker, is_start);
1487 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range())
1490 ArdourPrompter dialog (true);
1493 dialog.set_prompt (_("New Name:"));
1495 if (loc->is_mark()) {
1496 dialog.set_title (_("Rename Mark"));
1498 dialog.set_title (_("Rename Range"));
1501 dialog.set_name ("MarkRenameWindow");
1502 dialog.set_size_request (250, -1);
1503 dialog.set_position (Gtk::WIN_POS_MOUSE);
1505 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1506 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1507 dialog.set_initial_text (loc->name());
1511 switch (dialog.run ()) {
1512 case RESPONSE_ACCEPT:
1518 begin_reversible_command ( _("rename marker") );
1519 XMLNode &before = _session->locations()->get_state();
1521 dialog.get_result(txt);
1522 loc->set_name (txt);
1523 _session->set_dirty ();
1525 XMLNode &after = _session->locations()->get_state();
1526 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1527 commit_reversible_command ();
1531 Editor::new_transport_marker_menu_popdown ()
1534 transport_bar_drag_rect->hide();
1540 Editor::new_transport_marker_menu_set_loop ()
1542 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1546 Editor::new_transport_marker_menu_set_punch ()
1548 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1552 Editor::update_loop_range_view ()
1554 if (_session == 0) {
1560 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1562 double x1 = sample_to_pixel (tll->start());
1563 double x2 = sample_to_pixel (tll->end());
1565 transport_loop_range_rect->set_x0 (x1);
1566 transport_loop_range_rect->set_x1 (x2);
1568 transport_loop_range_rect->show();
1571 transport_loop_range_rect->hide();
1576 Editor::update_punch_range_view ()
1578 if (_session == 0) {
1584 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1589 if (_session->config.get_punch_in()) {
1590 pixel_start = sample_to_pixel (tpl->start());
1594 if (_session->config.get_punch_out()) {
1595 pixel_end = sample_to_pixel (tpl->end());
1597 pixel_end = sample_to_pixel (max_framepos);
1600 transport_punch_range_rect->set_x0 (pixel_start);
1601 transport_punch_range_rect->set_x1 (pixel_end);
1602 transport_punch_range_rect->show();
1606 transport_punch_range_rect->hide();
1611 Editor::marker_selection_changed ()
1613 if (_session && _session->deletion_in_progress()) {
1617 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1618 i->second->set_selected (false);
1621 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1622 (*x)->set_selected (true);
1626 struct SortLocationsByPosition {
1627 bool operator() (Location* a, Location* b) {
1628 return a->start() < b->start();
1633 Editor::goto_nth_marker (int n)
1638 const Locations::LocationList& l (_session->locations()->list());
1639 Locations::LocationList ordered;
1642 SortLocationsByPosition cmp;
1645 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1646 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1648 _session->request_locate ((*i)->start(), _session->transport_rolling());
1657 Editor::toggle_marker_menu_glue ()
1659 ArdourMarker* marker;
1661 if ((marker = reinterpret_cast<ArdourMarker *> (marker_menu_item->get_data ("marker"))) == 0) {
1662 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1663 abort(); /*NOTREACHED*/
1669 loc = find_location_from_marker (marker, ignored);
1675 if (loc->position_lock_style() == MusicTime) {
1676 loc->set_position_lock_style (AudioTime);
1678 loc->set_position_lock_style (MusicTime);
1684 Editor::toggle_marker_lines ()
1686 _show_marker_lines = !_show_marker_lines;
1688 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1689 i->second->set_show_lines (_show_marker_lines);
1694 Editor::remove_sorted_marker (ArdourMarker* m)
1696 for (std::map<ArdourCanvas::Container *, std::list<ArdourMarker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1697 i->second.remove (m);
1702 Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
1704 for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1705 if (i->first->id() == id) {
1706 return is_start ? i->second->start : i->second->end;