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::Group* 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.
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::Group* 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 Marker (*this, *cd_marker_group, color, location->name(), Marker::Mark, location->start());
110 group = cd_marker_group;
112 lam->start = new Marker (*this, *marker_group, color, location->name(), Marker::Mark, location->start());
113 group = marker_group;
118 } else if (location->is_auto_loop()) {
121 lam->start = new Marker (*this, *transport_marker_group, color,
122 location->name(), Marker::LoopStart, location->start());
123 lam->end = new Marker (*this, *transport_marker_group, color,
124 location->name(), Marker::LoopEnd, location->end());
125 group = transport_marker_group;
127 } else if (location->is_auto_punch()) {
130 lam->start = new Marker (*this, *transport_marker_group, color,
131 location->name(), Marker::PunchIn, location->start());
132 lam->end = new Marker (*this, *transport_marker_group, color,
133 location->name(), Marker::PunchOut, location->end());
134 group = transport_marker_group;
136 } else if (location->is_session_range()) {
139 lam->start = new Marker (*this, *marker_group, color, _("start"), Marker::SessionStart, location->start());
140 lam->end = new Marker (*this, *marker_group, color, _("end"), Marker::SessionEnd, location->end());
141 group = marker_group;
145 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
146 lam->start = new Marker (*this, *cd_marker_group, color,
147 location->name(), Marker::RangeStart, location->start());
148 lam->end = new Marker (*this, *cd_marker_group, color,
149 location->name(), Marker::RangeEnd, location->end());
150 group = cd_marker_group;
152 lam->start = new Marker (*this, *range_marker_group, color,
153 location->name(), Marker::RangeStart, location->start());
154 lam->end = new Marker (*this, *range_marker_group, color,
155 location->name(), Marker::RangeEnd, location->end());
156 group = range_marker_group;
160 if (location->is_hidden ()) {
166 location->start_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
167 location->end_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
168 location->changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
169 location->name_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
170 location->FlagsChanged.connect (*this, invalidator (*this), boost::bind (&Editor::location_flags_changed, this, _1, _2), gui_context());
172 pair<Location*,LocationMarkers*> newpair;
174 newpair.first = location;
175 newpair.second = lam;
177 location_markers.insert (newpair);
179 if (select_new_marker && location->is_mark()) {
180 selection->set (lam->start);
181 select_new_marker = false;
184 lam->canvas_height_set (_visible_canvas_height);
185 lam->set_show_lines (_show_marker_lines);
187 /* Add these markers to the appropriate sorted marker lists, which will render
188 them unsorted until a call to update_marker_labels() sorts them out.
190 _sorted_marker_lists[group].push_back (lam->start);
192 _sorted_marker_lists[group].push_back (lam->end);
199 Editor::location_changed (Location *location)
201 ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
203 LocationMarkers *lam = find_location_markers (location);
206 /* a location that isn't "marked" with markers */
210 lam->set_name (location->name ());
211 lam->set_position (location->start(), location->end());
213 if (location->is_auto_loop()) {
214 update_loop_range_view ();
215 } else if (location->is_auto_punch()) {
216 update_punch_range_view ();
219 check_marker_label (lam->start);
221 check_marker_label (lam->end);
225 /** Look at a marker and check whether its label, and those of the previous and next markers,
226 * need to have their labels updated (in case those labels need to be shortened or can be
230 Editor::check_marker_label (Marker* m)
232 /* Get a time-ordered list of markers from the last time anything changed */
233 std::list<Marker*>& sorted = _sorted_marker_lists[m->get_parent()];
235 list<Marker*>::iterator i = find (sorted.begin(), sorted.end(), m);
237 list<Marker*>::iterator prev = sorted.end ();
238 list<Marker*>::iterator next = i;
241 /* Look to see if the previous marker is still behind `m' in time */
242 if (i != sorted.begin()) {
247 if ((*prev)->position() > m->position()) {
248 /* This marker is no longer in the correct order with the previous one, so
249 * update all the markers in this group.
251 update_marker_labels (m->get_parent ());
256 /* Look to see if the next marker is still ahead of `m' in time */
257 if (next != sorted.end() && (*next)->position() < m->position()) {
258 /* This marker is no longer in the correct order with the next one, so
259 * update all the markers in this group.
261 update_marker_labels (m->get_parent ());
265 if (prev != sorted.end()) {
267 /* Update just the available space between the previous marker and this one */
269 double const p = sample_to_pixel (m->position() - (*prev)->position());
271 if (m->label_on_left()) {
272 (*prev)->set_right_label_limit (p / 2);
274 (*prev)->set_right_label_limit (p);
277 if ((*prev)->label_on_left ()) {
278 m->set_left_label_limit (p);
280 m->set_left_label_limit (p / 2);
284 if (next != sorted.end()) {
286 /* Update just the available space between this marker and the next */
288 double const p = sample_to_pixel ((*next)->position() - m->position());
290 if ((*next)->label_on_left()) {
291 m->set_right_label_limit (p / 2);
293 m->set_right_label_limit (p);
296 if (m->label_on_left()) {
297 (*next)->set_left_label_limit (p);
299 (*next)->set_left_label_limit (p / 2);
304 struct MarkerComparator {
305 bool operator() (Marker const * a, Marker const * b) {
306 return a->position() < b->position();
310 /** Update all marker labels in all groups */
312 Editor::update_marker_labels ()
314 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
315 update_marker_labels (i->first);
319 /** Look at all markers in a group and update label widths */
321 Editor::update_marker_labels (ArdourCanvas::Group* group)
323 list<Marker*>& sorted = _sorted_marker_lists[group];
325 if (sorted.empty()) {
329 /* We sort the list of markers and then set up the space available between each one */
331 sorted.sort (MarkerComparator ());
333 list<Marker*>::iterator i = sorted.begin ();
335 list<Marker*>::iterator prev = sorted.end ();
336 list<Marker*>::iterator next = i;
338 if (next != sorted.end()) {
342 while (i != sorted.end()) {
344 if (prev != sorted.end()) {
345 double const p = sample_to_pixel ((*i)->position() - (*prev)->position());
347 if ((*prev)->label_on_left()) {
348 (*i)->set_left_label_limit (p);
350 (*i)->set_left_label_limit (p / 2);
355 if (next != sorted.end()) {
356 double const p = sample_to_pixel ((*next)->position() - (*i)->position());
358 if ((*next)->label_on_left()) {
359 (*i)->set_right_label_limit (p / 2);
361 (*i)->set_right_label_limit (p);
373 Editor::location_flags_changed (Location *location, void*)
375 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
377 LocationMarkers *lam = find_location_markers (location);
380 /* a location that isn't "marked" with markers */
384 // move cd markers to/from cd marker bar as appropriate
385 ensure_cd_marker_updated (lam, location);
387 if (location->is_cd_marker()) {
388 lam->set_color_rgba (location_cd_marker_color);
389 } else if (location->is_mark()) {
390 lam->set_color_rgba (location_marker_color);
391 } else if (location->is_auto_punch()) {
392 lam->set_color_rgba (location_punch_color);
393 } else if (location->is_auto_loop()) {
394 lam->set_color_rgba (location_loop_color);
396 lam->set_color_rgba (location_range_color);
399 if (location->is_hidden()) {
406 void Editor::update_cd_marker_display ()
408 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
409 LocationMarkers * lam = i->second;
410 Location * location = i->first;
412 ensure_cd_marker_updated (lam, location);
416 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
418 if (location->is_cd_marker()
419 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
421 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
423 lam->start->reparent (*cd_marker_group);
426 lam->end->reparent (*cd_marker_group);
429 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
430 && (lam->start->get_parent() == cd_marker_group))
432 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
433 if (location->is_mark()) {
435 lam->start->reparent (*marker_group);
438 lam->end->reparent (*marker_group);
443 lam->start->reparent (*range_marker_group);
446 lam->end->reparent (*range_marker_group);
452 Editor::LocationMarkers::~LocationMarkers ()
458 Editor::LocationMarkers *
459 Editor::find_location_markers (Location *location) const
461 LocationMarkerMap::const_iterator i;
463 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
464 if ((*i).first == location) {
473 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
475 LocationMarkerMap::const_iterator i;
477 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
478 LocationMarkers *lm = (*i).second;
479 if (lm->start == marker) {
482 } else if (lm->end == marker) {
492 Editor::refresh_location_display_internal (Locations::LocationList& locations)
496 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
497 i->second->valid = false;
502 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
504 LocationMarkerMap::iterator x;
506 if ((x = location_markers.find (*i)) != location_markers.end()) {
507 x->second->valid = true;
511 add_new_location_internal (*i);
514 /* remove dead ones */
516 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
518 LocationMarkerMap::iterator tmp;
523 if (!i->second->valid) {
525 remove_sorted_marker (i->second->start);
526 if (i->second->end) {
527 remove_sorted_marker (i->second->end);
530 LocationMarkers* m = i->second;
531 location_markers.erase (i);
538 update_punch_range_view ();
539 update_loop_range_view ();
543 Editor::refresh_location_display ()
545 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
548 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
551 update_marker_labels ();
555 Editor::LocationMarkers::hide()
564 Editor::LocationMarkers::show()
573 Editor::LocationMarkers::canvas_height_set (double h)
575 start->canvas_height_set (h);
577 end->canvas_height_set (h);
582 Editor::LocationMarkers::set_name (const string& str)
584 /* XXX: hack: don't change names of session start/end markers */
586 if (start->type() != Marker::SessionStart) {
587 start->set_name (str);
590 if (end && end->type() != Marker::SessionEnd) {
596 Editor::LocationMarkers::set_position (framepos_t startf,
599 start->set_position (startf);
601 end->set_position (endf);
606 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
608 start->set_color_rgba (rgba);
610 end->set_color_rgba (rgba);
615 Editor::LocationMarkers::set_show_lines (bool s)
617 start->set_show_line (s);
619 end->set_show_line (s);
624 Editor::LocationMarkers::set_selected (bool s)
626 start->set_selected (s);
628 end->set_selected (s);
633 Editor::LocationMarkers::setup_lines ()
635 start->setup_line ();
642 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
644 string markername, markerprefix;
645 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
648 markerprefix = "xrun";
649 flags = Location::IsMark;
651 markerprefix = "mark";
655 _session->locations()->next_available_name(markername, markerprefix);
656 if (!is_xrun && !choose_new_marker_name(markername)) {
659 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
660 _session->begin_reversible_command (_("add marker"));
661 XMLNode &before = _session->locations()->get_state();
662 _session->locations()->add (location, true);
663 XMLNode &after = _session->locations()->get_state();
664 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
665 _session->commit_reversible_command ();
667 /* find the marker we just added */
669 LocationMarkers *lam = find_location_markers (location);
671 /* make it the selected marker */
672 selection->set (lam->start);
678 Editor::mouse_add_new_range (framepos_t where)
684 /* Make this marker 1/8th of the visible area of the session so that
685 it's reasonably easy to manipulate after creation.
688 framepos_t const end = where + current_page_samples() / 8;
691 _session->locations()->next_available_name (name, _("range"));
692 Location* loc = new Location (*_session, where, end, name, Location::IsRangeMarker);
694 begin_reversible_command (_("new range marker"));
695 XMLNode& before = _session->locations()->get_state ();
696 _session->locations()->add (loc, true);
697 XMLNode& after = _session->locations()->get_state ();
698 _session->add_command (new MementoCommand<Locations> (*_session->locations(), &before, &after));
699 commit_reversible_command ();
703 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
708 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
709 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
713 if (entered_marker == marker) {
714 entered_marker = NULL;
717 Location* loc = find_location_from_marker (marker, is_start);
719 if (_session && loc) {
720 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
725 Editor::really_remove_marker (Location* loc)
727 _session->begin_reversible_command (_("remove marker"));
728 XMLNode &before = _session->locations()->get_state();
729 _session->locations()->remove (loc);
730 XMLNode &after = _session->locations()->get_state();
731 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
732 _session->commit_reversible_command ();
737 Editor::location_gone (Location *location)
739 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
741 LocationMarkerMap::iterator i;
743 if (location == transport_loop_location()) {
744 update_loop_range_view ();
747 if (location == transport_punch_location()) {
748 update_punch_range_view ();
751 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
752 if (i->first == location) {
754 remove_sorted_marker (i->second->start);
755 if (i->second->end) {
756 remove_sorted_marker (i->second->end);
759 LocationMarkers* m = i->second;
760 location_markers.erase (i);
768 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
770 marker_menu_item = item;
774 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
776 bool can_remove = false;
779 can_remove = mm->meter().movable ();
781 can_remove = tm->tempo().movable ();
786 delete tempo_or_meter_marker_menu;
787 build_tempo_or_meter_marker_menu (can_remove);
788 tempo_or_meter_marker_menu->popup (1, ev->time);
792 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
795 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
796 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
801 Location * loc = find_location_from_marker (marker, is_start);
803 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) {
805 if (transport_marker_menu == 0) {
806 build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range());
809 marker_menu_item = item;
810 transport_marker_menu->popup (1, ev->time);
812 } else if (loc->is_mark()) {
815 build_marker_menu (loc);
817 // GTK2FIX use action group sensitivity
819 if (children.size() >= 3) {
820 MenuItem * loopitem = &children[2];
822 if (loc->is_mark()) {
823 loopitem->set_sensitive(false);
826 loopitem->set_sensitive(true);
831 marker_menu_item = item;
832 marker_menu->popup (1, ev->time);
834 } else if (loc->is_range_marker()) {
835 if (range_marker_menu == 0) {
836 build_range_marker_menu (false, false);
838 marker_menu_item = item;
839 range_marker_menu->popup (1, ev->time);
844 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
846 if (new_transport_marker_menu == 0) {
847 build_new_transport_marker_menu ();
850 new_transport_marker_menu->popup (1, ev->time);
855 Editor::build_marker_menu (Location* loc)
857 using namespace Menu_Helpers;
859 marker_menu = new Menu;
860 MenuList& items = marker_menu->items();
861 marker_menu->set_name ("ArdourContextMenu");
863 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
864 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
865 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
867 items.push_back (SeparatorElem());
869 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
871 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
872 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
874 items.push_back (CheckMenuElem (_("Lock")));
875 Gtk::CheckMenuItem* lock_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
876 if (loc->locked ()) {
877 lock_item->set_active ();
879 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
881 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
882 Gtk::CheckMenuItem* glue_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
883 if (loc->position_lock_style() == MusicTime) {
884 glue_item->set_active ();
886 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
888 items.push_back (SeparatorElem());
890 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
894 Editor::build_range_marker_menu (bool loop_or_punch, bool session)
896 using namespace Menu_Helpers;
898 bool const loop_or_punch_or_session = loop_or_punch | session;
900 Menu *markerMenu = new Menu;
901 if (loop_or_punch_or_session) {
902 transport_marker_menu = markerMenu;
904 range_marker_menu = markerMenu;
906 MenuList& items = markerMenu->items();
907 markerMenu->set_name ("ArdourContextMenu");
909 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
910 items.push_back (MenuElem (_("Locate to Marker"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
911 items.push_back (MenuElem (_("Play from Marker"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
912 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
914 items.push_back (MenuElem (_("Set Marker from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
915 if (!Profile->get_sae()) {
916 items.push_back (MenuElem (_("Set Range from Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection), false)));
919 items.push_back (MenuElem (_("Zoom to Range"), sigc::mem_fun (*this, &Editor::marker_menu_zoom_to_range)));
921 items.push_back (SeparatorElem());
922 items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_range)));
923 items.push_back (SeparatorElem());
925 if (!loop_or_punch_or_session) {
926 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
927 items.push_back (MenuElem (_("Rename Range..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
931 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
934 if (!loop_or_punch_or_session || !session) {
935 items.push_back (SeparatorElem());
938 items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
939 items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
940 if (!Profile->get_sae()) {
941 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
946 Editor::build_tempo_or_meter_marker_menu (bool can_remove)
948 using namespace Menu_Helpers;
950 tempo_or_meter_marker_menu = new Menu;
951 MenuList& items = tempo_or_meter_marker_menu->items();
952 tempo_or_meter_marker_menu->set_name ("ArdourContextMenu");
954 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
955 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
957 items.back().set_sensitive (can_remove);
961 Editor::build_new_transport_marker_menu ()
963 using namespace Menu_Helpers;
965 new_transport_marker_menu = new Menu;
966 MenuList& items = new_transport_marker_menu->items();
967 new_transport_marker_menu->set_name ("ArdourContextMenu");
969 items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
970 items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
972 new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
976 Editor::marker_menu_hide ()
980 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
981 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
988 if ((l = find_location_from_marker (marker, is_start)) != 0) {
989 l->set_hidden (true, this);
994 Editor::marker_menu_select_using_range ()
998 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
999 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1006 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1007 set_selection_from_range (*l);
1012 Editor::marker_menu_select_all_selectables_using_range ()
1016 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1017 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1024 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1025 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, track_views, Selection::Set, false);
1031 Editor::marker_menu_separate_regions_using_location ()
1035 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1036 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1043 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1044 separate_regions_using_location (*l);
1050 Editor::marker_menu_play_from ()
1054 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1055 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1062 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1065 _session->request_locate (l->start(), true);
1068 //_session->request_bounded_roll (l->start(), l->end());
1071 _session->request_locate (l->start(), true);
1073 _session->request_locate (l->end(), true);
1080 Editor::marker_menu_set_playhead ()
1084 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1085 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1092 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1095 _session->request_locate (l->start(), false);
1099 _session->request_locate (l->start(), false);
1101 _session->request_locate (l->end(), false);
1108 Editor::marker_menu_range_to_next ()
1115 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1116 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1123 if ((l = find_location_from_marker (marker, is_start)) == 0) {
1129 _session->locations()->marks_either_side (marker->position(), start, end);
1131 if (end != max_framepos) {
1132 string range_name = l->name();
1133 range_name += "-range";
1135 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1136 _session->locations()->add (newrange);
1141 Editor::marker_menu_set_from_playhead ()
1145 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1146 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1153 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1156 l->set_start (_session->audible_frame ());
1160 l->set_start (_session->audible_frame ());
1162 l->set_end (_session->audible_frame ());
1169 Editor::marker_menu_set_from_selection (bool /*force_regions*/)
1173 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1174 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1181 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1189 if (!selection->time.empty()) {
1190 l->set (selection->time.start(), selection->time.end_frame());
1191 } else if (!selection->regions.empty()) {
1192 l->set (selection->regions.start(), selection->regions.end_frame());
1200 Editor::marker_menu_play_range ()
1204 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1205 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1212 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1215 _session->request_locate (l->start(), true);
1218 _session->request_bounded_roll (l->start(), l->end());
1225 Editor::marker_menu_loop_range ()
1229 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1230 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1237 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1239 if ((l2 = transport_loop_location()) != 0) {
1240 l2->set (l->start(), l->end());
1242 // enable looping, reposition and start rolling
1243 _session->request_play_loop(true);
1244 _session->request_locate (l2->start(), true);
1249 /** Temporal zoom to the range of the marker_menu_item (plus 5% either side) */
1251 Editor::marker_menu_zoom_to_range ()
1253 Marker* marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"));
1257 Location* l = find_location_from_marker (marker, is_start);
1262 framecnt_t const extra = l->length() * 0.05;
1263 framepos_t a = l->start ();
1268 framepos_t b = l->end ();
1269 if (b < (max_framepos - extra)) {
1273 temporal_zoom_by_frame (a, b);
1277 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1279 Marker* marker = reinterpret_cast<Marker*> (p);
1281 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1285 *m = dynamic_cast<MeterMarker*> (marker);
1286 *t = dynamic_cast<TempoMarker*> (marker);
1290 Editor::marker_menu_edit ()
1294 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1297 edit_meter_section (&mm->meter());
1299 edit_tempo_section (&tm->tempo());
1304 Editor::marker_menu_remove ()
1308 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1311 remove_meter_marker (marker_menu_item);
1313 remove_tempo_marker (marker_menu_item);
1315 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1320 Editor::toggle_marker_menu_lock ()
1324 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1325 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1332 loc = find_location_from_marker (marker, ignored);
1338 if (loc->locked()) {
1346 Editor::marker_menu_rename ()
1350 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1351 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1356 rename_marker (marker);
1360 Editor::rename_marker(Marker *marker)
1365 loc = find_location_from_marker (marker, is_start);
1370 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range())
1373 ArdourPrompter dialog (true);
1376 dialog.set_prompt (_("New Name:"));
1378 if (loc->is_mark()) {
1379 dialog.set_title (_("Rename Mark"));
1381 dialog.set_title (_("Rename Range"));
1384 dialog.set_name ("MarkRenameWindow");
1385 dialog.set_size_request (250, -1);
1386 dialog.set_position (Gtk::WIN_POS_MOUSE);
1388 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1389 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1390 dialog.set_initial_text (loc->name());
1394 switch (dialog.run ()) {
1395 case RESPONSE_ACCEPT:
1401 begin_reversible_command ( _("rename marker") );
1402 XMLNode &before = _session->locations()->get_state();
1404 dialog.get_result(txt);
1405 loc->set_name (txt);
1406 _session->set_dirty ();
1408 XMLNode &after = _session->locations()->get_state();
1409 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1410 commit_reversible_command ();
1414 Editor::new_transport_marker_menu_popdown ()
1417 transport_bar_drag_rect->hide();
1423 Editor::new_transport_marker_menu_set_loop ()
1425 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1429 Editor::new_transport_marker_menu_set_punch ()
1431 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1435 Editor::update_loop_range_view ()
1437 if (_session == 0) {
1443 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1445 double x1 = sample_to_pixel (tll->start());
1446 double x2 = sample_to_pixel (tll->end());
1448 transport_loop_range_rect->set_x0 (x1);
1449 transport_loop_range_rect->set_x1 (x2);
1451 transport_loop_range_rect->show();
1454 transport_loop_range_rect->hide();
1459 Editor::update_punch_range_view ()
1461 if (_session == 0) {
1467 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1468 ArdourCanvas::Rect const v = _track_canvas->visible_area ();
1470 if (_session->config.get_punch_in()) {
1471 transport_punch_range_rect->set_x0 (sample_to_pixel (tpl->start()));
1472 transport_punch_range_rect->set_x1 (_session->config.get_punch_out() ? sample_to_pixel (tpl->end()) : sample_to_pixel (max_framepos));
1474 transport_punch_range_rect->set_x0 (0);
1475 transport_punch_range_rect->set_x1 (_session->config.get_punch_out() ? sample_to_pixel (tpl->end()) : v.width ());
1478 transport_punch_range_rect->show();
1482 transport_punch_range_rect->hide();
1487 Editor::marker_selection_changed ()
1489 if (_session && _session->deletion_in_progress()) {
1493 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1494 i->second->set_selected (false);
1497 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1498 (*x)->set_selected (true);
1502 struct SortLocationsByPosition {
1503 bool operator() (Location* a, Location* b) {
1504 return a->start() < b->start();
1509 Editor::goto_nth_marker (int n)
1514 const Locations::LocationList& l (_session->locations()->list());
1515 Locations::LocationList ordered;
1518 SortLocationsByPosition cmp;
1521 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1522 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1524 _session->request_locate ((*i)->start(), _session->transport_rolling());
1533 Editor::toggle_marker_menu_glue ()
1537 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1538 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1545 loc = find_location_from_marker (marker, ignored);
1551 if (loc->position_lock_style() == MusicTime) {
1552 loc->set_position_lock_style (AudioTime);
1554 loc->set_position_lock_style (MusicTime);
1560 Editor::toggle_marker_lines ()
1562 _show_marker_lines = !_show_marker_lines;
1564 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1565 i->second->set_show_lines (_show_marker_lines);
1570 Editor::remove_sorted_marker (Marker* m)
1572 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1573 i->second.remove (m);
1578 Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
1580 for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1581 if (i->first->id() == id) {
1582 return is_start ? i->second->start : i->second->end;