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;
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);
369 Editor::location_flags_changed (Location *location, void*)
371 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
373 LocationMarkers *lam = find_location_markers (location);
376 /* a location that isn't "marked" with markers */
380 // move cd markers to/from cd marker bar as appropriate
381 ensure_cd_marker_updated (lam, location);
383 if (location->is_cd_marker()) {
384 lam->set_color_rgba (location_cd_marker_color);
385 } else if (location->is_mark()) {
386 lam->set_color_rgba (location_marker_color);
387 } else if (location->is_auto_punch()) {
388 lam->set_color_rgba (location_punch_color);
389 } else if (location->is_auto_loop()) {
390 lam->set_color_rgba (location_loop_color);
392 lam->set_color_rgba (location_range_color);
395 if (location->is_hidden()) {
402 void Editor::update_cd_marker_display ()
404 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
405 LocationMarkers * lam = i->second;
406 Location * location = i->first;
408 ensure_cd_marker_updated (lam, location);
412 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
414 if (location->is_cd_marker()
415 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
417 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
419 lam->start->reparent (*cd_marker_group);
422 lam->end->reparent (*cd_marker_group);
425 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
426 && (lam->start->get_parent() == cd_marker_group))
428 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
429 if (location->is_mark()) {
431 lam->start->reparent (*marker_group);
434 lam->end->reparent (*marker_group);
439 lam->start->reparent (*range_marker_group);
442 lam->end->reparent (*range_marker_group);
448 Editor::LocationMarkers::~LocationMarkers ()
454 Editor::LocationMarkers *
455 Editor::find_location_markers (Location *location) const
457 LocationMarkerMap::const_iterator i;
459 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
460 if ((*i).first == location) {
469 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
471 LocationMarkerMap::const_iterator i;
473 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
474 LocationMarkers *lm = (*i).second;
475 if (lm->start == marker) {
478 } else if (lm->end == marker) {
488 Editor::refresh_location_display_internal (Locations::LocationList& locations)
492 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
493 i->second->valid = false;
498 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
500 LocationMarkerMap::iterator x;
502 if ((x = location_markers.find (*i)) != location_markers.end()) {
503 x->second->valid = true;
507 add_new_location_internal (*i);
510 /* remove dead ones */
512 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
514 LocationMarkerMap::iterator tmp;
519 if (!i->second->valid) {
521 remove_sorted_marker (i->second->start);
522 if (i->second->end) {
523 remove_sorted_marker (i->second->end);
526 LocationMarkers* m = i->second;
527 location_markers.erase (i);
534 update_punch_range_view ();
535 update_loop_range_view ();
539 Editor::refresh_location_display ()
541 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
544 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
547 update_marker_labels ();
551 Editor::LocationMarkers::hide()
560 Editor::LocationMarkers::show()
569 Editor::LocationMarkers::canvas_height_set (double h)
571 start->canvas_height_set (h);
573 end->canvas_height_set (h);
578 Editor::LocationMarkers::set_name (const string& str)
580 /* XXX: hack: don't change names of session start/end markers */
582 if (start->type() != Marker::SessionStart) {
583 start->set_name (str);
586 if (end && end->type() != Marker::SessionEnd) {
592 Editor::LocationMarkers::set_position (framepos_t startf,
595 start->set_position (startf);
597 end->set_position (endf);
602 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
604 start->set_color_rgba (rgba);
606 end->set_color_rgba (rgba);
611 Editor::LocationMarkers::set_show_lines (bool s)
613 start->set_show_line (s);
615 end->set_show_line (s);
620 Editor::LocationMarkers::set_selected (bool s)
622 start->set_selected (s);
624 end->set_selected (s);
629 Editor::LocationMarkers::setup_lines ()
631 start->setup_line ();
638 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
640 string markername, markerprefix;
641 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
644 markerprefix = "xrun";
645 flags = Location::IsMark;
647 markerprefix = "mark";
651 _session->locations()->next_available_name(markername, markerprefix);
652 if (!is_xrun && !choose_new_marker_name(markername)) {
655 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
656 _session->begin_reversible_command (_("add marker"));
657 XMLNode &before = _session->locations()->get_state();
658 _session->locations()->add (location, true);
659 XMLNode &after = _session->locations()->get_state();
660 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
661 _session->commit_reversible_command ();
663 /* find the marker we just added */
665 LocationMarkers *lam = find_location_markers (location);
667 /* make it the selected marker */
668 selection->set (lam->start);
674 Editor::mouse_add_new_range (framepos_t where)
680 /* Make this marker 1/8th of the visible area of the session so that
681 it's reasonably easy to manipulate after creation.
684 framepos_t const end = where + current_page_samples() / 8;
687 _session->locations()->next_available_name (name, _("range"));
688 Location* loc = new Location (*_session, where, end, name, Location::IsRangeMarker);
690 begin_reversible_command (_("new range marker"));
691 XMLNode& before = _session->locations()->get_state ();
692 _session->locations()->add (loc, true);
693 XMLNode& after = _session->locations()->get_state ();
694 _session->add_command (new MementoCommand<Locations> (*_session->locations(), &before, &after));
695 commit_reversible_command ();
699 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
704 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
705 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
709 if (entered_marker == marker) {
710 entered_marker = NULL;
713 Location* loc = find_location_from_marker (marker, is_start);
715 if (_session && loc) {
716 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
721 Editor::really_remove_marker (Location* loc)
723 _session->begin_reversible_command (_("remove marker"));
724 XMLNode &before = _session->locations()->get_state();
725 _session->locations()->remove (loc);
726 XMLNode &after = _session->locations()->get_state();
727 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
728 _session->commit_reversible_command ();
733 Editor::location_gone (Location *location)
735 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
737 LocationMarkerMap::iterator i;
739 if (location == transport_loop_location()) {
740 update_loop_range_view ();
743 if (location == transport_punch_location()) {
744 update_punch_range_view ();
747 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
748 if (i->first == location) {
750 remove_sorted_marker (i->second->start);
751 if (i->second->end) {
752 remove_sorted_marker (i->second->end);
755 LocationMarkers* m = i->second;
756 location_markers.erase (i);
764 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
766 marker_menu_item = item;
770 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
772 bool can_remove = false;
775 can_remove = mm->meter().movable ();
777 can_remove = tm->tempo().movable ();
782 delete tempo_or_meter_marker_menu;
783 build_tempo_or_meter_marker_menu (can_remove);
784 tempo_or_meter_marker_menu->popup (1, ev->time);
788 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
791 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
792 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
797 Location * loc = find_location_from_marker (marker, is_start);
799 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) {
801 if (transport_marker_menu == 0) {
802 build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range());
805 marker_menu_item = item;
806 transport_marker_menu->popup (1, ev->time);
808 } else if (loc->is_mark()) {
811 build_marker_menu (loc);
813 // GTK2FIX use action group sensitivity
815 if (children.size() >= 3) {
816 MenuItem * loopitem = &children[2];
818 if (loc->is_mark()) {
819 loopitem->set_sensitive(false);
822 loopitem->set_sensitive(true);
827 marker_menu_item = item;
828 marker_menu->popup (1, ev->time);
830 } else if (loc->is_range_marker()) {
831 if (range_marker_menu == 0) {
832 build_range_marker_menu (false, false);
834 marker_menu_item = item;
835 range_marker_menu->popup (1, ev->time);
840 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
842 if (new_transport_marker_menu == 0) {
843 build_new_transport_marker_menu ();
846 new_transport_marker_menu->popup (1, ev->time);
851 Editor::build_marker_menu (Location* loc)
853 using namespace Menu_Helpers;
855 marker_menu = new Menu;
856 MenuList& items = marker_menu->items();
857 marker_menu->set_name ("ArdourContextMenu");
859 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
860 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
861 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
863 items.push_back (SeparatorElem());
865 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
867 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
868 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
870 items.push_back (CheckMenuElem (_("Lock")));
871 Gtk::CheckMenuItem* lock_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
872 if (loc->locked ()) {
873 lock_item->set_active ();
875 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
877 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
878 Gtk::CheckMenuItem* glue_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
879 if (loc->position_lock_style() == MusicTime) {
880 glue_item->set_active ();
882 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
884 items.push_back (SeparatorElem());
886 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
890 Editor::build_range_marker_menu (bool loop_or_punch, bool session)
892 using namespace Menu_Helpers;
894 bool const loop_or_punch_or_session = loop_or_punch | session;
896 Menu *markerMenu = new Menu;
897 if (loop_or_punch_or_session) {
898 transport_marker_menu = markerMenu;
900 range_marker_menu = markerMenu;
902 MenuList& items = markerMenu->items();
903 markerMenu->set_name ("ArdourContextMenu");
905 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
906 items.push_back (MenuElem (_("Locate to Marker"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
907 items.push_back (MenuElem (_("Play from Marker"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
908 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
910 items.push_back (MenuElem (_("Set Marker from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
911 if (!Profile->get_sae()) {
912 items.push_back (MenuElem (_("Set Range from Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection), false)));
915 items.push_back (MenuElem (_("Zoom to Range"), sigc::mem_fun (*this, &Editor::marker_menu_zoom_to_range)));
917 items.push_back (SeparatorElem());
918 items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_range)));
919 items.push_back (SeparatorElem());
921 if (!loop_or_punch_or_session) {
922 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
923 items.push_back (MenuElem (_("Rename Range..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
927 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
930 if (!loop_or_punch_or_session || !session) {
931 items.push_back (SeparatorElem());
934 items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
935 items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
936 if (!Profile->get_sae()) {
937 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
942 Editor::build_tempo_or_meter_marker_menu (bool can_remove)
944 using namespace Menu_Helpers;
946 tempo_or_meter_marker_menu = new Menu;
947 MenuList& items = tempo_or_meter_marker_menu->items();
948 tempo_or_meter_marker_menu->set_name ("ArdourContextMenu");
950 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
951 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
953 items.back().set_sensitive (can_remove);
957 Editor::build_new_transport_marker_menu ()
959 using namespace Menu_Helpers;
961 new_transport_marker_menu = new Menu;
962 MenuList& items = new_transport_marker_menu->items();
963 new_transport_marker_menu->set_name ("ArdourContextMenu");
965 items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
966 items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
968 new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
972 Editor::marker_menu_hide ()
976 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
977 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
984 if ((l = find_location_from_marker (marker, is_start)) != 0) {
985 l->set_hidden (true, this);
990 Editor::marker_menu_select_using_range ()
994 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
995 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1002 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1003 set_selection_from_range (*l);
1008 Editor::marker_menu_select_all_selectables_using_range ()
1012 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1013 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1020 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1021 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, track_views, Selection::Set, false);
1027 Editor::marker_menu_separate_regions_using_location ()
1031 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1032 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1039 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1040 separate_regions_using_location (*l);
1046 Editor::marker_menu_play_from ()
1050 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1051 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1058 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1061 _session->request_locate (l->start(), true);
1064 //_session->request_bounded_roll (l->start(), l->end());
1067 _session->request_locate (l->start(), true);
1069 _session->request_locate (l->end(), true);
1076 Editor::marker_menu_set_playhead ()
1080 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1081 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1088 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1091 _session->request_locate (l->start(), false);
1095 _session->request_locate (l->start(), false);
1097 _session->request_locate (l->end(), false);
1104 Editor::marker_menu_range_to_next ()
1111 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1112 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1119 if ((l = find_location_from_marker (marker, is_start)) == 0) {
1125 _session->locations()->marks_either_side (marker->position(), start, end);
1127 if (end != max_framepos) {
1128 string range_name = l->name();
1129 range_name += "-range";
1131 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1132 _session->locations()->add (newrange);
1137 Editor::marker_menu_set_from_playhead ()
1141 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1142 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1149 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1152 l->set_start (_session->audible_frame ());
1156 l->set_start (_session->audible_frame ());
1158 l->set_end (_session->audible_frame ());
1165 Editor::marker_menu_set_from_selection (bool /*force_regions*/)
1169 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1170 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1177 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1185 if (!selection->time.empty()) {
1186 l->set (selection->time.start(), selection->time.end_frame());
1187 } else if (!selection->regions.empty()) {
1188 l->set (selection->regions.start(), selection->regions.end_frame());
1196 Editor::marker_menu_play_range ()
1200 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1201 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1208 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1211 _session->request_locate (l->start(), true);
1214 _session->request_bounded_roll (l->start(), l->end());
1221 Editor::marker_menu_loop_range ()
1225 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1226 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1233 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1235 if ((l2 = transport_loop_location()) != 0) {
1236 l2->set (l->start(), l->end());
1238 // enable looping, reposition and start rolling
1239 _session->request_play_loop(true);
1240 _session->request_locate (l2->start(), true);
1245 /** Temporal zoom to the range of the marker_menu_item (plus 5% either side) */
1247 Editor::marker_menu_zoom_to_range ()
1249 Marker* marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"));
1253 Location* l = find_location_from_marker (marker, is_start);
1258 framecnt_t const extra = l->length() * 0.05;
1259 framepos_t a = l->start ();
1264 framepos_t b = l->end ();
1265 if (b < (max_framepos - extra)) {
1269 temporal_zoom_by_frame (a, b);
1273 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1275 Marker* marker = reinterpret_cast<Marker*> (p);
1277 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1281 *m = dynamic_cast<MeterMarker*> (marker);
1282 *t = dynamic_cast<TempoMarker*> (marker);
1286 Editor::marker_menu_edit ()
1290 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1293 edit_meter_section (&mm->meter());
1295 edit_tempo_section (&tm->tempo());
1300 Editor::marker_menu_remove ()
1304 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1307 remove_meter_marker (marker_menu_item);
1309 remove_tempo_marker (marker_menu_item);
1311 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1316 Editor::toggle_marker_menu_lock ()
1320 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1321 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1328 loc = find_location_from_marker (marker, ignored);
1334 if (loc->locked()) {
1342 Editor::marker_menu_rename ()
1346 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1347 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1352 rename_marker (marker);
1356 Editor::rename_marker(Marker *marker)
1361 loc = find_location_from_marker (marker, is_start);
1366 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range())
1369 ArdourPrompter dialog (true);
1372 dialog.set_prompt (_("New Name:"));
1374 if (loc->is_mark()) {
1375 dialog.set_title (_("Rename Mark"));
1377 dialog.set_title (_("Rename Range"));
1380 dialog.set_name ("MarkRenameWindow");
1381 dialog.set_size_request (250, -1);
1382 dialog.set_position (Gtk::WIN_POS_MOUSE);
1384 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1385 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1386 dialog.set_initial_text (loc->name());
1390 switch (dialog.run ()) {
1391 case RESPONSE_ACCEPT:
1397 begin_reversible_command ( _("rename marker") );
1398 XMLNode &before = _session->locations()->get_state();
1400 dialog.get_result(txt);
1401 loc->set_name (txt);
1402 _session->set_dirty ();
1404 XMLNode &after = _session->locations()->get_state();
1405 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1406 commit_reversible_command ();
1410 Editor::new_transport_marker_menu_popdown ()
1413 transport_bar_drag_rect->hide();
1419 Editor::new_transport_marker_menu_set_loop ()
1421 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1425 Editor::new_transport_marker_menu_set_punch ()
1427 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1431 Editor::update_loop_range_view ()
1433 if (_session == 0) {
1439 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1441 double x1 = sample_to_pixel (tll->start());
1442 double x2 = sample_to_pixel (tll->end());
1444 transport_loop_range_rect->set_x0 (x1);
1445 transport_loop_range_rect->set_x1 (x2);
1447 transport_loop_range_rect->show();
1450 transport_loop_range_rect->hide();
1455 Editor::update_punch_range_view ()
1457 if (_session == 0) {
1463 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1464 ArdourCanvas::Rect const v = _track_canvas->visible_area ();
1466 if (_session->config.get_punch_in()) {
1467 transport_punch_range_rect->set_x0 (sample_to_pixel (tpl->start()));
1468 transport_punch_range_rect->set_x1 (_session->config.get_punch_out() ? sample_to_pixel (tpl->end()) : sample_to_pixel (JACK_MAX_FRAMES));
1470 transport_punch_range_rect->set_x0 (0);
1471 transport_punch_range_rect->set_x1 (_session->config.get_punch_out() ? sample_to_pixel (tpl->end()) : v.width ());
1474 transport_punch_range_rect->show();
1478 transport_punch_range_rect->hide();
1483 Editor::marker_selection_changed ()
1485 if (_session && _session->deletion_in_progress()) {
1489 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1490 i->second->set_selected (false);
1493 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1494 (*x)->set_selected (true);
1498 struct SortLocationsByPosition {
1499 bool operator() (Location* a, Location* b) {
1500 return a->start() < b->start();
1505 Editor::goto_nth_marker (int n)
1510 const Locations::LocationList& l (_session->locations()->list());
1511 Locations::LocationList ordered;
1514 SortLocationsByPosition cmp;
1517 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1518 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1520 _session->request_locate ((*i)->start(), _session->transport_rolling());
1529 Editor::toggle_marker_menu_glue ()
1533 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1534 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1541 loc = find_location_from_marker (marker, ignored);
1547 if (loc->position_lock_style() == MusicTime) {
1548 loc->set_position_lock_style (AudioTime);
1550 loc->set_position_lock_style (MusicTime);
1556 Editor::toggle_marker_lines ()
1558 _show_marker_lines = !_show_marker_lines;
1560 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1561 i->second->set_show_lines (_show_marker_lines);
1566 Editor::remove_sorted_marker (Marker* m)
1568 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1569 i->second.remove (m);
1574 Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
1576 for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1577 if (i->first->id() == id) {
1578 return is_start ? i->second->start : i->second->end;