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);
73 /** Add a new location, without a time-consuming update of all marker labels;
74 * the caller must call update_marker_labels () after calling this.
75 * @return canvas group that the location's marker was added to.
78 Editor::add_new_location_internal (Location* location)
80 LocationMarkers *lam = new LocationMarkers;
83 /* make a note here of which group this marker ends up in */
84 ArdourCanvas::Group* group = 0;
86 if (location->is_cd_marker()) {
87 color = location_cd_marker_color;
88 } else if (location->is_mark()) {
89 color = location_marker_color;
90 } else if (location->is_auto_loop()) {
91 color = location_loop_color;
92 } else if (location->is_auto_punch()) {
93 color = location_punch_color;
95 color = location_range_color;
98 if (location->is_mark()) {
100 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
101 lam->start = new Marker (*this, *cd_marker_group, color, location->name(), Marker::Mark, location->start());
102 group = cd_marker_group;
104 lam->start = new Marker (*this, *marker_group, color, location->name(), Marker::Mark, location->start());
105 group = marker_group;
110 } else if (location->is_auto_loop()) {
113 lam->start = new Marker (*this, *transport_marker_group, color,
114 location->name(), Marker::LoopStart, location->start());
115 lam->end = new Marker (*this, *transport_marker_group, color,
116 location->name(), Marker::LoopEnd, location->end());
117 group = transport_marker_group;
119 } else if (location->is_auto_punch()) {
122 lam->start = new Marker (*this, *transport_marker_group, color,
123 location->name(), Marker::PunchIn, location->start());
124 lam->end = new Marker (*this, *transport_marker_group, color,
125 location->name(), Marker::PunchOut, location->end());
126 group = transport_marker_group;
128 } else if (location->is_session_range()) {
131 lam->start = new Marker (*this, *marker_group, color, _("start"), Marker::SessionStart, location->start());
132 lam->end = new Marker (*this, *marker_group, color, _("end"), Marker::SessionEnd, location->end());
133 group = marker_group;
137 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
138 lam->start = new Marker (*this, *cd_marker_group, color,
139 location->name(), Marker::RangeStart, location->start());
140 lam->end = new Marker (*this, *cd_marker_group, color,
141 location->name(), Marker::RangeEnd, location->end());
142 group = cd_marker_group;
144 lam->start = new Marker (*this, *range_marker_group, color,
145 location->name(), Marker::RangeStart, location->start());
146 lam->end = new Marker (*this, *range_marker_group, color,
147 location->name(), Marker::RangeEnd, location->end());
148 group = range_marker_group;
152 if (location->is_hidden ()) {
158 location->start_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
159 location->end_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
160 location->changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
161 location->name_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
162 location->FlagsChanged.connect (*this, invalidator (*this), boost::bind (&Editor::location_flags_changed, this, _1, _2), gui_context());
164 pair<Location*,LocationMarkers*> newpair;
166 newpair.first = location;
167 newpair.second = lam;
169 location_markers.insert (newpair);
171 if (select_new_marker && location->is_mark()) {
172 selection->set (lam->start);
173 select_new_marker = false;
176 lam->canvas_height_set (_visible_canvas_height);
177 lam->set_show_lines (_show_marker_lines);
179 /* Add these markers to the appropriate sorted marker lists, which will render
180 them unsorted until a call to update_marker_labels() sorts them out.
182 _sorted_marker_lists[group].push_back (lam->start);
184 _sorted_marker_lists[group].push_back (lam->end);
191 Editor::location_changed (Location *location)
193 ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
195 LocationMarkers *lam = find_location_markers (location);
198 /* a location that isn't "marked" with markers */
202 lam->set_name (location->name ());
203 lam->set_position (location->start(), location->end());
205 if (location->is_auto_loop()) {
206 update_loop_range_view ();
207 } else if (location->is_auto_punch()) {
208 update_punch_range_view ();
211 check_marker_label (lam->start);
213 check_marker_label (lam->end);
217 /** Look at a marker and check whether its label, and those of the previous and next markers,
218 * need to have their labels updated (in case those labels need to be shortened or can be
222 Editor::check_marker_label (Marker* m)
224 /* Get a time-ordered list of markers from the last time anything changed */
225 std::list<Marker*>& sorted = _sorted_marker_lists[m->get_parent()];
227 list<Marker*>::iterator i = find (sorted.begin(), sorted.end(), m);
229 list<Marker*>::iterator prev = sorted.end ();
230 list<Marker*>::iterator next = i;
233 /* Look to see if the previous marker is still behind `m' in time */
234 if (i != sorted.begin()) {
239 if ((*prev)->position() > m->position()) {
240 /* This marker is no longer in the correct order with the previous one, so
241 * update all the markers in this group.
243 update_marker_labels (m->get_parent ());
248 /* Look to see if the next marker is still ahead of `m' in time */
249 if (next != sorted.end() && (*next)->position() < m->position()) {
250 /* This marker is no longer in the correct order with the next one, so
251 * update all the markers in this group.
253 update_marker_labels (m->get_parent ());
257 if (prev != sorted.end()) {
259 /* Update just the available space between the previous marker and this one */
261 double const p = sample_to_pixel (m->position() - (*prev)->position());
263 if (m->label_on_left()) {
264 (*prev)->set_right_label_limit (p / 2);
266 (*prev)->set_right_label_limit (p);
269 if ((*prev)->label_on_left ()) {
270 m->set_left_label_limit (p);
272 m->set_left_label_limit (p / 2);
276 if (next != sorted.end()) {
278 /* Update just the available space between this marker and the next */
280 double const p = sample_to_pixel ((*next)->position() - m->position());
282 if ((*next)->label_on_left()) {
283 m->set_right_label_limit (p / 2);
285 m->set_right_label_limit (p);
288 if (m->label_on_left()) {
289 (*next)->set_left_label_limit (p);
291 (*next)->set_left_label_limit (p / 2);
296 struct MarkerComparator {
297 bool operator() (Marker const * a, Marker const * b) {
298 return a->position() < b->position();
302 /** Update all marker labels in all groups */
304 Editor::update_marker_labels ()
306 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
307 update_marker_labels (i->first);
311 /** Look at all markers in a group and update label widths */
313 Editor::update_marker_labels (ArdourCanvas::Group* group)
315 list<Marker*>& sorted = _sorted_marker_lists[group];
317 if (sorted.empty()) {
321 /* We sort the list of markers and then set up the space available between each one */
323 sorted.sort (MarkerComparator ());
325 list<Marker*>::iterator i = sorted.begin ();
327 list<Marker*>::iterator prev = sorted.end ();
328 list<Marker*>::iterator next = i;
331 while (i != sorted.end()) {
333 if (prev != sorted.end()) {
334 double const p = sample_to_pixel ((*i)->position() - (*prev)->position());
336 if ((*prev)->label_on_left()) {
337 (*i)->set_left_label_limit (p);
339 (*i)->set_left_label_limit (p / 2);
344 if (next != sorted.end()) {
345 double const p = sample_to_pixel ((*next)->position() - (*i)->position());
347 if ((*next)->label_on_left()) {
348 (*i)->set_right_label_limit (p / 2);
350 (*i)->set_right_label_limit (p);
361 Editor::location_flags_changed (Location *location, void*)
363 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
365 LocationMarkers *lam = find_location_markers (location);
368 /* a location that isn't "marked" with markers */
372 // move cd markers to/from cd marker bar as appropriate
373 ensure_cd_marker_updated (lam, location);
375 if (location->is_cd_marker()) {
376 lam->set_color_rgba (location_cd_marker_color);
377 } else if (location->is_mark()) {
378 lam->set_color_rgba (location_marker_color);
379 } else if (location->is_auto_punch()) {
380 lam->set_color_rgba (location_punch_color);
381 } else if (location->is_auto_loop()) {
382 lam->set_color_rgba (location_loop_color);
384 lam->set_color_rgba (location_range_color);
387 if (location->is_hidden()) {
394 void Editor::update_cd_marker_display ()
396 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
397 LocationMarkers * lam = i->second;
398 Location * location = i->first;
400 ensure_cd_marker_updated (lam, location);
404 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
406 if (location->is_cd_marker()
407 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
409 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
411 lam->start->reparent (*cd_marker_group);
414 lam->end->reparent (*cd_marker_group);
417 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
418 && (lam->start->get_parent() == cd_marker_group))
420 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
421 if (location->is_mark()) {
423 lam->start->reparent (*marker_group);
426 lam->end->reparent (*marker_group);
431 lam->start->reparent (*range_marker_group);
434 lam->end->reparent (*range_marker_group);
440 Editor::LocationMarkers::~LocationMarkers ()
446 Editor::LocationMarkers *
447 Editor::find_location_markers (Location *location) const
449 LocationMarkerMap::const_iterator i;
451 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
452 if ((*i).first == location) {
461 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
463 LocationMarkerMap::const_iterator i;
465 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
466 LocationMarkers *lm = (*i).second;
467 if (lm->start == marker) {
470 } else if (lm->end == marker) {
480 Editor::refresh_location_display_internal (Locations::LocationList& locations)
484 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
485 i->second->valid = false;
490 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
492 LocationMarkerMap::iterator x;
494 if ((x = location_markers.find (*i)) != location_markers.end()) {
495 x->second->valid = true;
499 add_new_location_internal (*i);
502 /* remove dead ones */
504 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
506 LocationMarkerMap::iterator tmp;
511 if (!i->second->valid) {
513 remove_sorted_marker (i->second->start);
514 if (i->second->end) {
515 remove_sorted_marker (i->second->end);
518 LocationMarkers* m = i->second;
519 location_markers.erase (i);
526 update_punch_range_view (false);
527 update_loop_range_view (false);
531 Editor::refresh_location_display ()
533 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
536 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
539 update_marker_labels ();
543 Editor::LocationMarkers::hide()
552 Editor::LocationMarkers::show()
561 Editor::LocationMarkers::canvas_height_set (double h)
563 start->canvas_height_set (h);
565 end->canvas_height_set (h);
570 Editor::LocationMarkers::set_name (const string& str)
572 /* XXX: hack: don't change names of session start/end markers */
574 if (start->type() != Marker::SessionStart) {
575 start->set_name (str);
578 if (end && end->type() != Marker::SessionEnd) {
584 Editor::LocationMarkers::set_position (framepos_t startf,
587 start->set_position (startf);
589 end->set_position (endf);
594 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
596 start->set_color_rgba (rgba);
598 end->set_color_rgba (rgba);
603 Editor::LocationMarkers::set_show_lines (bool s)
605 start->set_show_line (s);
607 end->set_show_line (s);
612 Editor::LocationMarkers::set_selected (bool s)
614 start->set_selected (s);
616 end->set_selected (s);
621 Editor::LocationMarkers::setup_lines ()
623 start->setup_line ();
630 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
632 string markername, markerprefix;
633 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
636 markerprefix = "xrun";
637 flags = Location::IsMark;
639 markerprefix = "mark";
643 _session->locations()->next_available_name(markername, markerprefix);
644 if (!is_xrun && !choose_new_marker_name(markername)) {
647 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
648 _session->begin_reversible_command (_("add marker"));
649 XMLNode &before = _session->locations()->get_state();
650 _session->locations()->add (location, true);
651 XMLNode &after = _session->locations()->get_state();
652 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
653 _session->commit_reversible_command ();
655 /* find the marker we just added */
657 LocationMarkers *lam = find_location_markers (location);
659 /* make it the selected marker */
660 selection->set (lam->start);
666 Editor::mouse_add_new_range (framepos_t where)
672 /* Make this marker 1/8th of the visible area of the session so that
673 it's reasonably easy to manipulate after creation.
676 framepos_t const end = where + current_page_samples() / 8;
679 _session->locations()->next_available_name (name, _("range"));
680 Location* loc = new Location (*_session, where, end, name, Location::IsRangeMarker);
682 begin_reversible_command (_("new range marker"));
683 XMLNode& before = _session->locations()->get_state ();
684 _session->locations()->add (loc, true);
685 XMLNode& after = _session->locations()->get_state ();
686 _session->add_command (new MementoCommand<Locations> (*_session->locations(), &before, &after));
687 commit_reversible_command ();
691 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
696 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
697 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
701 if (entered_marker == marker) {
702 entered_marker = NULL;
705 Location* loc = find_location_from_marker (marker, is_start);
707 if (_session && loc) {
708 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
713 Editor::really_remove_marker (Location* loc)
715 _session->begin_reversible_command (_("remove marker"));
716 XMLNode &before = _session->locations()->get_state();
717 _session->locations()->remove (loc);
718 XMLNode &after = _session->locations()->get_state();
719 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
720 _session->commit_reversible_command ();
725 Editor::location_gone (Location *location)
727 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
729 LocationMarkerMap::iterator i;
731 if (location == transport_loop_location()) {
732 update_loop_range_view (true);
735 if (location == transport_punch_location()) {
736 update_punch_range_view (true);
739 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
740 if (i->first == location) {
742 remove_sorted_marker (i->second->start);
743 if (i->second->end) {
744 remove_sorted_marker (i->second->end);
747 LocationMarkers* m = i->second;
748 location_markers.erase (i);
756 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
758 marker_menu_item = item;
762 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
764 bool can_remove = false;
767 can_remove = mm->meter().movable ();
769 can_remove = tm->tempo().movable ();
774 delete tempo_or_meter_marker_menu;
775 build_tempo_or_meter_marker_menu (can_remove);
776 tempo_or_meter_marker_menu->popup (1, ev->time);
780 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
783 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
784 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
789 Location * loc = find_location_from_marker (marker, is_start);
791 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) {
793 if (transport_marker_menu == 0) {
794 build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range());
797 marker_menu_item = item;
798 transport_marker_menu->popup (1, ev->time);
800 } else if (loc->is_mark()) {
803 build_marker_menu (loc);
805 // GTK2FIX use action group sensitivity
807 if (children.size() >= 3) {
808 MenuItem * loopitem = &children[2];
810 if (loc->is_mark()) {
811 loopitem->set_sensitive(false);
814 loopitem->set_sensitive(true);
819 marker_menu_item = item;
820 marker_menu->popup (1, ev->time);
822 } else if (loc->is_range_marker()) {
823 if (range_marker_menu == 0) {
824 build_range_marker_menu (false, false);
826 marker_menu_item = item;
827 range_marker_menu->popup (1, ev->time);
832 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
834 if (new_transport_marker_menu == 0) {
835 build_new_transport_marker_menu ();
838 new_transport_marker_menu->popup (1, ev->time);
843 Editor::build_marker_menu (Location* loc)
845 using namespace Menu_Helpers;
847 marker_menu = new Menu;
848 MenuList& items = marker_menu->items();
849 marker_menu->set_name ("ArdourContextMenu");
851 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
852 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
853 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
855 items.push_back (SeparatorElem());
857 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
859 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
860 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
862 items.push_back (CheckMenuElem (_("Lock")));
863 Gtk::CheckMenuItem* lock_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
864 if (loc->locked ()) {
865 lock_item->set_active ();
867 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
869 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
870 Gtk::CheckMenuItem* glue_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
871 if (loc->position_lock_style() == MusicTime) {
872 glue_item->set_active ();
874 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
876 items.push_back (SeparatorElem());
878 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
882 Editor::build_range_marker_menu (bool loop_or_punch, bool session)
884 using namespace Menu_Helpers;
886 bool const loop_or_punch_or_session = loop_or_punch | session;
888 Menu *markerMenu = new Menu;
889 if (loop_or_punch_or_session) {
890 transport_marker_menu = markerMenu;
892 range_marker_menu = markerMenu;
894 MenuList& items = markerMenu->items();
895 markerMenu->set_name ("ArdourContextMenu");
897 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
898 items.push_back (MenuElem (_("Locate to Marker"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
899 items.push_back (MenuElem (_("Play from Marker"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
900 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
902 items.push_back (MenuElem (_("Set Marker from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
903 if (!Profile->get_sae()) {
904 items.push_back (MenuElem (_("Set Range from Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection), false)));
907 items.push_back (MenuElem (_("Zoom to Range"), sigc::mem_fun (*this, &Editor::marker_menu_zoom_to_range)));
909 items.push_back (SeparatorElem());
910 items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_range)));
911 items.push_back (SeparatorElem());
913 if (!loop_or_punch_or_session) {
914 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
915 items.push_back (MenuElem (_("Rename Range..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
919 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
922 if (!loop_or_punch_or_session || !session) {
923 items.push_back (SeparatorElem());
926 items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
927 items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
928 if (!Profile->get_sae()) {
929 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
934 Editor::build_tempo_or_meter_marker_menu (bool can_remove)
936 using namespace Menu_Helpers;
938 tempo_or_meter_marker_menu = new Menu;
939 MenuList& items = tempo_or_meter_marker_menu->items();
940 tempo_or_meter_marker_menu->set_name ("ArdourContextMenu");
942 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
943 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
945 items.back().set_sensitive (can_remove);
949 Editor::build_new_transport_marker_menu ()
951 using namespace Menu_Helpers;
953 new_transport_marker_menu = new Menu;
954 MenuList& items = new_transport_marker_menu->items();
955 new_transport_marker_menu->set_name ("ArdourContextMenu");
957 items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
958 items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
960 new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
964 Editor::marker_menu_hide ()
968 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
969 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
976 if ((l = find_location_from_marker (marker, is_start)) != 0) {
977 l->set_hidden (true, this);
982 Editor::marker_menu_select_using_range ()
986 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
987 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
994 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
995 set_selection_from_range (*l);
1000 Editor::marker_menu_select_all_selectables_using_range ()
1004 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1005 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1012 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1013 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, track_views, Selection::Set, false);
1019 Editor::marker_menu_separate_regions_using_location ()
1023 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1024 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1031 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1032 separate_regions_using_location (*l);
1038 Editor::marker_menu_play_from ()
1042 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1043 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1050 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1053 _session->request_locate (l->start(), true);
1056 //_session->request_bounded_roll (l->start(), l->end());
1059 _session->request_locate (l->start(), true);
1061 _session->request_locate (l->end(), true);
1068 Editor::marker_menu_set_playhead ()
1072 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1073 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1080 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1083 _session->request_locate (l->start(), false);
1087 _session->request_locate (l->start(), false);
1089 _session->request_locate (l->end(), false);
1096 Editor::marker_menu_range_to_next ()
1103 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1104 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1111 if ((l = find_location_from_marker (marker, is_start)) == 0) {
1117 _session->locations()->marks_either_side (marker->position(), start, end);
1119 if (end != max_framepos) {
1120 string range_name = l->name();
1121 range_name += "-range";
1123 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1124 _session->locations()->add (newrange);
1129 Editor::marker_menu_set_from_playhead ()
1133 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1134 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1141 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1144 l->set_start (_session->audible_frame ());
1148 l->set_start (_session->audible_frame ());
1150 l->set_end (_session->audible_frame ());
1157 Editor::marker_menu_set_from_selection (bool /*force_regions*/)
1161 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1162 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1169 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1177 if (!selection->time.empty()) {
1178 l->set (selection->time.start(), selection->time.end_frame());
1179 } else if (!selection->regions.empty()) {
1180 l->set (selection->regions.start(), selection->regions.end_frame());
1188 Editor::marker_menu_play_range ()
1192 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1193 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1200 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1203 _session->request_locate (l->start(), true);
1206 _session->request_bounded_roll (l->start(), l->end());
1213 Editor::marker_menu_loop_range ()
1217 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1218 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1225 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1227 if ((l2 = transport_loop_location()) != 0) {
1228 l2->set (l->start(), l->end());
1230 // enable looping, reposition and start rolling
1231 _session->request_play_loop(true);
1232 _session->request_locate (l2->start(), true);
1237 /** Temporal zoom to the range of the marker_menu_item (plus 5% either side) */
1239 Editor::marker_menu_zoom_to_range ()
1241 Marker* marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"));
1245 Location* l = find_location_from_marker (marker, is_start);
1250 framecnt_t const extra = l->length() * 0.05;
1251 framepos_t a = l->start ();
1256 framepos_t b = l->end ();
1257 if (b < (max_framepos - extra)) {
1261 temporal_zoom_by_frame (a, b);
1265 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1267 Marker* marker = reinterpret_cast<Marker*> (p);
1269 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1273 *m = dynamic_cast<MeterMarker*> (marker);
1274 *t = dynamic_cast<TempoMarker*> (marker);
1278 Editor::marker_menu_edit ()
1282 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1285 edit_meter_section (&mm->meter());
1287 edit_tempo_section (&tm->tempo());
1292 Editor::marker_menu_remove ()
1296 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1299 remove_meter_marker (marker_menu_item);
1301 remove_tempo_marker (marker_menu_item);
1303 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1308 Editor::toggle_marker_menu_lock ()
1312 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1313 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1320 loc = find_location_from_marker (marker, ignored);
1326 if (loc->locked()) {
1334 Editor::marker_menu_rename ()
1338 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1339 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1344 rename_marker (marker);
1348 Editor::rename_marker(Marker *marker)
1353 loc = find_location_from_marker (marker, is_start);
1358 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range())
1361 ArdourPrompter dialog (true);
1364 dialog.set_prompt (_("New Name:"));
1366 if (loc->is_mark()) {
1367 dialog.set_title (_("Rename Mark"));
1369 dialog.set_title (_("Rename Range"));
1372 dialog.set_name ("MarkRenameWindow");
1373 dialog.set_size_request (250, -1);
1374 dialog.set_position (Gtk::WIN_POS_MOUSE);
1376 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1377 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1378 dialog.set_initial_text (loc->name());
1382 switch (dialog.run ()) {
1383 case RESPONSE_ACCEPT:
1389 begin_reversible_command ( _("rename marker") );
1390 XMLNode &before = _session->locations()->get_state();
1392 dialog.get_result(txt);
1393 loc->set_name (txt);
1394 _session->set_dirty ();
1396 XMLNode &after = _session->locations()->get_state();
1397 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1398 commit_reversible_command ();
1402 Editor::new_transport_marker_menu_popdown ()
1405 transport_bar_drag_rect->hide();
1411 Editor::new_transport_marker_menu_set_loop ()
1413 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1417 Editor::new_transport_marker_menu_set_punch ()
1419 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1423 Editor::update_loop_range_view (bool visibility)
1425 if (_session == 0) {
1431 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1433 double x1 = sample_to_pixel (tll->start());
1434 double x2 = sample_to_pixel (tll->end());
1436 transport_loop_range_rect->set_x0 (x1);
1437 transport_loop_range_rect->set_x1 (x2);
1440 transport_loop_range_rect->show();
1443 } else if (visibility) {
1444 transport_loop_range_rect->hide();
1449 Editor::update_punch_range_view (bool visibility)
1451 if (_session == 0) {
1457 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1458 ArdourCanvas::Rect const v = _track_canvas->visible_area ();
1459 if (_session->config.get_punch_in()) {
1460 transport_punch_range_rect->set_x0 (sample_to_pixel (tpl->start()));
1461 transport_punch_range_rect->set_x1 (_session->config.get_punch_out() ? sample_to_pixel (tpl->end()) : sample_to_pixel (JACK_MAX_FRAMES));
1463 transport_punch_range_rect->set_x0 (0);
1464 transport_punch_range_rect->set_x1 (_session->config.get_punch_out() ? sample_to_pixel (tpl->end()) : v.width ());
1468 transport_punch_range_rect->show();
1470 } else if (visibility) {
1471 transport_punch_range_rect->hide();
1476 Editor::marker_selection_changed ()
1478 if (_session && _session->deletion_in_progress()) {
1482 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1483 i->second->set_selected (false);
1486 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1487 (*x)->set_selected (true);
1491 struct SortLocationsByPosition {
1492 bool operator() (Location* a, Location* b) {
1493 return a->start() < b->start();
1498 Editor::goto_nth_marker (int n)
1503 const Locations::LocationList& l (_session->locations()->list());
1504 Locations::LocationList ordered;
1507 SortLocationsByPosition cmp;
1510 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1511 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1513 _session->request_locate ((*i)->start(), _session->transport_rolling());
1522 Editor::toggle_marker_menu_glue ()
1526 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1527 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1534 loc = find_location_from_marker (marker, ignored);
1540 if (loc->position_lock_style() == MusicTime) {
1541 loc->set_position_lock_style (AudioTime);
1543 loc->set_position_lock_style (MusicTime);
1549 Editor::toggle_marker_lines ()
1551 _show_marker_lines = !_show_marker_lines;
1553 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1554 i->second->set_show_lines (_show_marker_lines);
1559 Editor::remove_sorted_marker (Marker* m)
1561 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1562 i->second.remove (m);
1567 Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
1569 for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1570 if (i->first->id() == id) {
1571 return is_start ? i->second->start : i->second->end;