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.
20 #include <sigc++/retype.h>
24 #include <libgnomecanvas/libgnomecanvas.h>
25 #include <gtkmm2ext/gtk_ui.h>
27 #include "ardour/session.h"
28 #include "ardour/location.h"
29 #include "ardour/profile.h"
30 #include "pbd/memento_command.h"
34 #include "selection.h"
36 #include "gui_thread.h"
37 #include "simplerect.h"
40 #include "editor_drag.h"
45 using namespace ARDOUR;
48 using namespace Gtkmm2ext;
51 Editor::clear_marker_display ()
53 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
57 location_markers.clear ();
58 _sorted_marker_lists.clear ();
62 Editor::add_new_location (Location *location)
64 ENSURE_GUI_THREAD (*this, &Editor::add_new_location, location);
66 ArdourCanvas::Group* group = add_new_location_internal (location);
68 /* Do a full update of the markers in this group */
69 update_marker_labels (group);
72 /** Add a new location, without a time-consuming update of all marker labels;
73 * the caller must call update_marker_labels () after calling this.
74 * @return canvas group that the location's marker was added to.
77 Editor::add_new_location_internal (Location* location)
79 LocationMarkers *lam = new LocationMarkers;
82 /* make a note here of which group this marker ends up in */
83 ArdourCanvas::Group* group = 0;
85 if (location->is_cd_marker()) {
86 color = location_cd_marker_color;
87 } else if (location->is_mark()) {
88 color = location_marker_color;
89 } else if (location->is_auto_loop()) {
90 color = location_loop_color;
91 } else if (location->is_auto_punch()) {
92 color = location_punch_color;
94 color = location_range_color;
97 if (location->is_mark()) {
99 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
100 lam->start = new Marker (*this, *cd_marker_group, color, location->name(), Marker::Mark, location->start());
101 group = cd_marker_group;
103 lam->start = new Marker (*this, *marker_group, color, location->name(), Marker::Mark, location->start());
104 group = marker_group;
109 } else if (location->is_auto_loop()) {
112 lam->start = new Marker (*this, *transport_marker_group, color,
113 location->name(), Marker::LoopStart, location->start());
114 lam->end = new Marker (*this, *transport_marker_group, color,
115 location->name(), Marker::LoopEnd, location->end());
116 group = transport_marker_group;
118 } else if (location->is_auto_punch()) {
121 lam->start = new Marker (*this, *transport_marker_group, color,
122 location->name(), Marker::PunchIn, location->start());
123 lam->end = new Marker (*this, *transport_marker_group, color,
124 location->name(), Marker::PunchOut, location->end());
125 group = transport_marker_group;
127 } else if (location->is_session_range()) {
130 lam->start = new Marker (*this, *marker_group, color, _("start"), Marker::SessionStart, location->start());
131 lam->end = new Marker (*this, *marker_group, color, _("end"), Marker::SessionEnd, location->end());
132 group = marker_group;
136 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
137 lam->start = new Marker (*this, *cd_marker_group, color,
138 location->name(), Marker::RangeStart, location->start());
139 lam->end = new Marker (*this, *cd_marker_group, color,
140 location->name(), Marker::RangeEnd, location->end());
141 group = cd_marker_group;
143 lam->start = new Marker (*this, *range_marker_group, color,
144 location->name(), Marker::RangeStart, location->start());
145 lam->end = new Marker (*this, *range_marker_group, color,
146 location->name(), Marker::RangeEnd, location->end());
147 group = range_marker_group;
151 if (location->is_hidden ()) {
157 location->start_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
158 location->end_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
159 location->changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
160 location->name_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
161 location->FlagsChanged.connect (*this, invalidator (*this), boost::bind (&Editor::location_flags_changed, this, _1, _2), gui_context());
163 pair<Location*,LocationMarkers*> newpair;
165 newpair.first = location;
166 newpair.second = lam;
168 location_markers.insert (newpair);
170 if (select_new_marker && location->is_mark()) {
171 selection->set (lam->start);
172 select_new_marker = false;
175 lam->canvas_height_set (_canvas_height);
176 lam->set_show_lines (_show_marker_lines);
178 /* Add these markers to the appropriate sorted marker lists, which will render
179 them unsorted until a call to update_marker_labels() sorts them out.
181 _sorted_marker_lists[group].push_back (lam->start);
183 _sorted_marker_lists[group].push_back (lam->end);
190 Editor::location_changed (Location *location)
192 ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
194 LocationMarkers *lam = find_location_markers (location);
197 /* a location that isn't "marked" with markers */
201 lam->set_name (location->name ());
202 lam->set_position (location->start(), location->end());
204 if (location->is_auto_loop()) {
205 update_loop_range_view ();
206 } else if (location->is_auto_punch()) {
207 update_punch_range_view ();
210 check_marker_label (lam->start);
212 check_marker_label (lam->end);
216 /** Look at a marker and check whether its label, and those of the previous and next markers,
217 * need to have their labels updated (in case those labels need to be shortened or can be
221 Editor::check_marker_label (Marker* m)
223 /* Get a time-ordered list of markers from the last time anything changed */
224 std::list<Marker*>& sorted = _sorted_marker_lists[m->get_parent()];
226 list<Marker*>::iterator i = find (sorted.begin(), sorted.end(), m);
228 list<Marker*>::iterator prev = sorted.end ();
229 list<Marker*>::iterator next = i;
232 /* Look to see if the previous marker is still behind `m' in time */
233 if (i != sorted.begin()) {
238 if ((*prev)->position() > m->position()) {
239 /* This marker is no longer in the correct order with the previous one, so
240 * update all the markers in this group.
242 update_marker_labels (m->get_parent ());
247 /* Look to see if the next marker is still ahead of `m' in time */
248 if (next != sorted.end() && (*next)->position() < m->position()) {
249 /* This marker is no longer in the correct order with the next one, so
250 * update all the markers in this group.
252 update_marker_labels (m->get_parent ());
256 if (prev != sorted.end()) {
258 /* Update just the available space between the previous marker and this one */
260 double const p = frame_to_pixel (m->position() - (*prev)->position());
262 if (m->label_on_left()) {
263 (*prev)->set_right_label_limit (p / 2);
265 (*prev)->set_right_label_limit (p);
268 if ((*prev)->label_on_left ()) {
269 m->set_left_label_limit (p);
271 m->set_left_label_limit (p / 2);
275 if (next != sorted.end()) {
277 /* Update just the available space between this marker and the next */
279 double const p = frame_to_pixel ((*next)->position() - m->position());
281 if ((*next)->label_on_left()) {
282 m->set_right_label_limit (p / 2);
284 m->set_right_label_limit (p);
287 if (m->label_on_left()) {
288 (*next)->set_left_label_limit (p);
290 (*next)->set_left_label_limit (p / 2);
295 struct MarkerComparator {
296 bool operator() (Marker const * a, Marker const * b) {
297 return a->position() < b->position();
301 /** Update all marker labels in all groups */
303 Editor::update_marker_labels ()
305 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
306 update_marker_labels (i->first);
310 /** Look at all markers in a group and update label widths */
312 Editor::update_marker_labels (ArdourCanvas::Group* group)
314 list<Marker*>& sorted = _sorted_marker_lists[group];
316 if (sorted.empty()) {
320 /* We sort the list of markers and then set up the space available between each one */
322 sorted.sort (MarkerComparator ());
324 list<Marker*>::iterator i = sorted.begin ();
326 list<Marker*>::iterator prev = sorted.end ();
327 list<Marker*>::iterator next = i;
330 while (i != sorted.end()) {
332 if (prev != sorted.end()) {
333 double const p = frame_to_pixel ((*i)->position() - (*prev)->position());
335 if ((*prev)->label_on_left()) {
336 (*i)->set_left_label_limit (p);
338 (*i)->set_left_label_limit (p / 2);
343 if (next != sorted.end()) {
344 double const p = frame_to_pixel ((*next)->position() - (*i)->position());
346 if ((*next)->label_on_left()) {
347 (*i)->set_right_label_limit (p / 2);
349 (*i)->set_right_label_limit (p);
360 Editor::location_flags_changed (Location *location, void*)
362 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
364 LocationMarkers *lam = find_location_markers (location);
367 /* a location that isn't "marked" with markers */
371 // move cd markers to/from cd marker bar as appropriate
372 ensure_cd_marker_updated (lam, location);
374 if (location->is_cd_marker()) {
375 lam->set_color_rgba (location_cd_marker_color);
376 } else if (location->is_mark()) {
377 lam->set_color_rgba (location_marker_color);
378 } else if (location->is_auto_punch()) {
379 lam->set_color_rgba (location_punch_color);
380 } else if (location->is_auto_loop()) {
381 lam->set_color_rgba (location_loop_color);
383 lam->set_color_rgba (location_range_color);
386 if (location->is_hidden()) {
393 void Editor::update_cd_marker_display ()
395 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
396 LocationMarkers * lam = i->second;
397 Location * location = i->first;
399 ensure_cd_marker_updated (lam, location);
403 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
405 if (location->is_cd_marker()
406 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
408 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
410 lam->start->reparent (*cd_marker_group);
413 lam->end->reparent (*cd_marker_group);
416 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
417 && (lam->start->get_parent() == cd_marker_group))
419 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
420 if (location->is_mark()) {
422 lam->start->reparent (*marker_group);
425 lam->end->reparent (*marker_group);
430 lam->start->reparent (*range_marker_group);
433 lam->end->reparent (*range_marker_group);
439 Editor::LocationMarkers::~LocationMarkers ()
445 Editor::LocationMarkers *
446 Editor::find_location_markers (Location *location) const
448 LocationMarkerMap::const_iterator i;
450 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
451 if ((*i).first == location) {
460 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
462 LocationMarkerMap::const_iterator i;
464 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
465 LocationMarkers *lm = (*i).second;
466 if (lm->start == marker) {
469 } else if (lm->end == marker) {
479 Editor::refresh_location_display_internal (Locations::LocationList& locations)
483 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
484 i->second->valid = false;
489 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
491 LocationMarkerMap::iterator x;
493 if ((x = location_markers.find (*i)) != location_markers.end()) {
494 x->second->valid = true;
498 add_new_location_internal (*i);
501 /* remove dead ones */
503 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
505 LocationMarkerMap::iterator tmp;
510 if (!i->second->valid) {
512 remove_sorted_marker (i->second->start);
513 if (i->second->end) {
514 remove_sorted_marker (i->second->end);
517 LocationMarkers* m = i->second;
518 location_markers.erase (i);
525 update_punch_range_view (false);
526 update_loop_range_view (false);
530 Editor::refresh_location_display ()
532 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
535 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
538 update_marker_labels ();
542 Editor::LocationMarkers::hide()
551 Editor::LocationMarkers::show()
560 Editor::LocationMarkers::canvas_height_set (double h)
562 start->canvas_height_set (h);
564 end->canvas_height_set (h);
569 Editor::LocationMarkers::set_name (const string& str)
571 /* XXX: hack: don't change names of session start/end markers */
573 if (start->type() != Marker::SessionStart) {
574 start->set_name (str);
577 if (end && end->type() != Marker::SessionEnd) {
583 Editor::LocationMarkers::set_position (framepos_t startf,
586 start->set_position (startf);
588 end->set_position (endf);
593 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
595 start->set_color_rgba (rgba);
597 end->set_color_rgba (rgba);
602 Editor::LocationMarkers::set_show_lines (bool s)
604 start->set_show_line (s);
606 end->set_show_line (s);
611 Editor::LocationMarkers::set_selected (bool s)
613 start->set_selected (s);
615 end->set_selected (s);
620 Editor::LocationMarkers::setup_lines ()
622 start->setup_line ();
629 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
631 string markername, markerprefix;
632 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
635 markerprefix = "xrun";
636 flags = Location::IsMark;
638 markerprefix = "mark";
642 _session->locations()->next_available_name(markername, markerprefix);
643 if (!is_xrun && !choose_new_marker_name(markername)) {
646 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
647 _session->begin_reversible_command (_("add marker"));
648 XMLNode &before = _session->locations()->get_state();
649 _session->locations()->add (location, true);
650 XMLNode &after = _session->locations()->get_state();
651 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
652 _session->commit_reversible_command ();
654 /* find the marker we just added */
656 LocationMarkers *lam = find_location_markers (location);
658 /* make it the selected marker */
659 selection->set (lam->start);
665 Editor::mouse_add_new_range (framepos_t where)
671 /* Make this marker 1/8th of the visible area of the session so that
672 it's reasonably easy to manipulate after creation.
675 framepos_t const end = where + current_page_frames() / 8;
678 _session->locations()->next_available_name (name, _("range"));
679 Location* loc = new Location (*_session, where, end, name, Location::IsRangeMarker);
681 begin_reversible_command (_("new range marker"));
682 XMLNode& before = _session->locations()->get_state ();
683 _session->locations()->add (loc, true);
684 XMLNode& after = _session->locations()->get_state ();
685 _session->add_command (new MementoCommand<Locations> (*_session->locations(), &before, &after));
686 commit_reversible_command ();
690 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
695 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
696 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
700 if (entered_marker == marker) {
701 entered_marker = NULL;
704 Location* loc = find_location_from_marker (marker, is_start);
706 if (_session && loc) {
707 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
712 Editor::really_remove_marker (Location* loc)
714 _session->begin_reversible_command (_("remove marker"));
715 XMLNode &before = _session->locations()->get_state();
716 _session->locations()->remove (loc);
717 XMLNode &after = _session->locations()->get_state();
718 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
719 _session->commit_reversible_command ();
724 Editor::location_gone (Location *location)
726 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
728 LocationMarkerMap::iterator i;
730 if (location == transport_loop_location()) {
731 update_loop_range_view (true);
734 if (location == transport_punch_location()) {
735 update_punch_range_view (true);
738 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
739 if (i->first == location) {
741 remove_sorted_marker (i->second->start);
742 if (i->second->end) {
743 remove_sorted_marker (i->second->end);
746 LocationMarkers* m = i->second;
747 location_markers.erase (i);
755 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
757 marker_menu_item = item;
761 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
763 bool can_remove = false;
766 can_remove = mm->meter().movable ();
768 can_remove = tm->tempo().movable ();
773 delete tempo_or_meter_marker_menu;
774 build_tempo_or_meter_marker_menu (can_remove);
775 tempo_or_meter_marker_menu->popup (1, ev->time);
779 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
782 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
783 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
788 Location * loc = find_location_from_marker (marker, is_start);
790 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) {
792 if (transport_marker_menu == 0) {
793 build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range());
796 marker_menu_item = item;
797 transport_marker_menu->popup (1, ev->time);
799 } else if (loc->is_mark()) {
802 build_marker_menu (loc);
804 // GTK2FIX use action group sensitivity
806 if (children.size() >= 3) {
807 MenuItem * loopitem = &children[2];
809 if (loc->is_mark()) {
810 loopitem->set_sensitive(false);
813 loopitem->set_sensitive(true);
818 marker_menu_item = item;
819 marker_menu->popup (1, ev->time);
821 } else if (loc->is_range_marker()) {
822 if (range_marker_menu == 0) {
823 build_range_marker_menu (false, false);
825 marker_menu_item = item;
826 range_marker_menu->popup (1, ev->time);
831 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
833 if (new_transport_marker_menu == 0) {
834 build_new_transport_marker_menu ();
837 new_transport_marker_menu->popup (1, ev->time);
842 Editor::build_marker_menu (Location* loc)
844 using namespace Menu_Helpers;
846 marker_menu = new Menu;
847 MenuList& items = marker_menu->items();
848 marker_menu->set_name ("ArdourContextMenu");
850 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
851 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
852 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
854 items.push_back (SeparatorElem());
856 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
858 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
859 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
861 items.push_back (CheckMenuElem (_("Lock")));
862 CheckMenuItem* lock_item = static_cast<CheckMenuItem*> (&items.back());
863 if (loc->locked ()) {
864 lock_item->set_active ();
866 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
868 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
869 CheckMenuItem* glue_item = static_cast<CheckMenuItem*> (&items.back());
870 if (loc->position_lock_style() == MusicTime) {
871 glue_item->set_active ();
873 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
875 items.push_back (SeparatorElem());
877 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
881 Editor::build_range_marker_menu (bool loop_or_punch, bool session)
883 using namespace Menu_Helpers;
885 bool const loop_or_punch_or_session = loop_or_punch | session;
887 Menu *markerMenu = new Menu;
888 if (loop_or_punch_or_session) {
889 transport_marker_menu = markerMenu;
891 range_marker_menu = markerMenu;
893 MenuList& items = markerMenu->items();
894 markerMenu->set_name ("ArdourContextMenu");
896 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
897 items.push_back (MenuElem (_("Locate to Range Mark"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
898 items.push_back (MenuElem (_("Play from Range Mark"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
899 if (!loop_or_punch_or_session) {
900 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
902 items.push_back (MenuElem (_("Set Range Mark 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 Range Selection"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection)));
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 ()
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) {
1176 /* if range selection use first to last */
1178 if (!selection->time.empty()) {
1179 l->set_start (selection->time.start());
1180 l->set_end (selection->time.end_frame());
1183 if (!selection->regions.empty()) {
1184 l->set_start (selection->regions.start());
1185 l->set_end (selection->regions.end_frame());
1194 Editor::marker_menu_play_range ()
1198 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1199 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1206 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1209 _session->request_locate (l->start(), true);
1212 _session->request_bounded_roll (l->start(), l->end());
1219 Editor::marker_menu_loop_range ()
1223 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1224 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1231 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1233 if ((l2 = transport_loop_location()) != 0) {
1234 l2->set (l->start(), l->end());
1236 // enable looping, reposition and start rolling
1237 _session->request_play_loop(true);
1238 _session->request_locate (l2->start(), true);
1243 /** Temporal zoom to the range of the marker_menu_item (plus 5% either side) */
1245 Editor::marker_menu_zoom_to_range ()
1247 Marker* marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"));
1251 Location* l = find_location_from_marker (marker, is_start);
1256 framecnt_t const extra = l->length() * 0.05;
1257 framepos_t a = l->start ();
1262 framepos_t b = l->end ();
1263 if (b < (max_framepos - extra)) {
1267 temporal_zoom_by_frame (a, b);
1271 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1273 Marker* marker = reinterpret_cast<Marker*> (p);
1275 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1279 *m = dynamic_cast<MeterMarker*> (marker);
1280 *t = dynamic_cast<TempoMarker*> (marker);
1284 Editor::marker_menu_edit ()
1288 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1291 edit_meter_section (&mm->meter());
1293 edit_tempo_section (&tm->tempo());
1298 Editor::marker_menu_remove ()
1302 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1305 remove_meter_marker (marker_menu_item);
1307 remove_tempo_marker (marker_menu_item);
1309 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1314 Editor::toggle_marker_menu_lock ()
1318 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1319 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1326 loc = find_location_from_marker (marker, ignored);
1332 if (loc->locked()) {
1340 Editor::marker_menu_rename ()
1344 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1345 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1352 loc = find_location_from_marker (marker, is_start);
1356 ArdourPrompter dialog (true);
1359 dialog.set_prompt (_("New Name:"));
1361 if (loc->is_mark()) {
1362 dialog.set_title (_("Rename Mark"));
1364 dialog.set_title (_("Rename Range"));
1367 dialog.set_name ("MarkRenameWindow");
1368 dialog.set_size_request (250, -1);
1369 dialog.set_position (Gtk::WIN_POS_MOUSE);
1371 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1372 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1373 dialog.set_initial_text (loc->name());
1377 switch (dialog.run ()) {
1378 case RESPONSE_ACCEPT:
1384 begin_reversible_command ( _("rename marker") );
1385 XMLNode &before = _session->locations()->get_state();
1387 dialog.get_result(txt);
1388 loc->set_name (txt);
1390 XMLNode &after = _session->locations()->get_state();
1391 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1392 commit_reversible_command ();
1396 Editor::new_transport_marker_menu_popdown ()
1399 transport_bar_drag_rect->hide();
1405 Editor::new_transport_marker_menu_set_loop ()
1407 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1411 Editor::new_transport_marker_menu_set_punch ()
1413 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1417 Editor::update_loop_range_view (bool visibility)
1419 if (_session == 0) {
1425 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1427 double x1 = frame_to_pixel (tll->start());
1428 double x2 = frame_to_pixel (tll->end());
1430 transport_loop_range_rect->property_x1() = x1;
1431 transport_loop_range_rect->property_x2() = x2;
1434 transport_loop_range_rect->show();
1437 } else if (visibility) {
1438 transport_loop_range_rect->hide();
1443 Editor::update_punch_range_view (bool visibility)
1445 if (_session == 0) {
1451 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1452 guint track_canvas_width,track_canvas_height;
1453 track_canvas->get_size(track_canvas_width,track_canvas_height);
1454 if (_session->config.get_punch_in()) {
1455 transport_punch_range_rect->property_x1() = frame_to_pixel (tpl->start());
1456 transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : frame_to_pixel (JACK_MAX_FRAMES));
1458 transport_punch_range_rect->property_x1() = 0;
1459 transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : track_canvas_width);
1463 transport_punch_range_rect->show();
1465 } else if (visibility) {
1466 transport_punch_range_rect->hide();
1471 Editor::marker_selection_changed ()
1473 if (_session && _session->deletion_in_progress()) {
1477 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1478 i->second->set_selected (false);
1481 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1482 (*x)->set_selected (true);
1486 struct SortLocationsByPosition {
1487 bool operator() (Location* a, Location* b) {
1488 return a->start() < b->start();
1493 Editor::goto_nth_marker (int n)
1498 const Locations::LocationList& l (_session->locations()->list());
1499 Locations::LocationList ordered;
1502 SortLocationsByPosition cmp;
1505 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1506 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1508 _session->request_locate ((*i)->start(), _session->transport_rolling());
1517 Editor::toggle_marker_menu_glue ()
1521 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1522 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1529 loc = find_location_from_marker (marker, ignored);
1535 if (loc->position_lock_style() == MusicTime) {
1536 loc->set_position_lock_style (AudioTime);
1538 loc->set_position_lock_style (MusicTime);
1544 Editor::toggle_marker_lines ()
1546 _show_marker_lines = !_show_marker_lines;
1548 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1549 i->second->set_show_lines (_show_marker_lines);
1554 Editor::remove_sorted_marker (Marker* m)
1556 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1557 i->second.remove (m);
1562 Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
1564 for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1565 if (i->first->id() == id) {
1566 return is_start ? i->second->start : i->second->end;