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 <libgnomecanvas/libgnomecanvas.h>
24 #include <gtkmm2ext/gtk_ui.h>
26 #include "ardour/session.h"
27 #include "ardour/location.h"
28 #include "ardour/profile.h"
29 #include "pbd/memento_command.h"
33 #include "selection.h"
35 #include "gui_thread.h"
36 #include "simplerect.h"
39 #include "editor_drag.h"
44 using namespace ARDOUR;
47 using namespace Gtkmm2ext;
50 Editor::clear_marker_display ()
52 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
56 location_markers.clear ();
57 _sorted_marker_lists.clear ();
61 Editor::add_new_location (Location *location)
63 ENSURE_GUI_THREAD (*this, &Editor::add_new_location, location);
65 ArdourCanvas::Group* group = add_new_location_internal (location);
67 /* Do a full update of the markers in this group */
68 update_marker_labels (group);
71 /** Add a new location, without a time-consuming update of all marker labels;
72 * the caller must call update_marker_labels () after calling this.
73 * @return canvas group that the location's marker was added to.
76 Editor::add_new_location_internal (Location* location)
78 LocationMarkers *lam = new LocationMarkers;
81 /* make a note here of which group this marker ends up in */
82 ArdourCanvas::Group* group = 0;
84 if (location->is_cd_marker()) {
85 color = location_cd_marker_color;
86 } else if (location->is_mark()) {
87 color = location_marker_color;
88 } else if (location->is_auto_loop()) {
89 color = location_loop_color;
90 } else if (location->is_auto_punch()) {
91 color = location_punch_color;
93 color = location_range_color;
96 if (location->is_mark()) {
98 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
99 lam->start = new Marker (*this, *cd_marker_group, color, location->name(), Marker::Mark, location->start());
100 group = cd_marker_group;
102 lam->start = new Marker (*this, *marker_group, color, location->name(), Marker::Mark, location->start());
103 group = marker_group;
108 } else if (location->is_auto_loop()) {
111 lam->start = new Marker (*this, *transport_marker_group, color,
112 location->name(), Marker::LoopStart, location->start());
113 lam->end = new Marker (*this, *transport_marker_group, color,
114 location->name(), Marker::LoopEnd, location->end());
115 group = transport_marker_group;
117 } else if (location->is_auto_punch()) {
120 lam->start = new Marker (*this, *transport_marker_group, color,
121 location->name(), Marker::PunchIn, location->start());
122 lam->end = new Marker (*this, *transport_marker_group, color,
123 location->name(), Marker::PunchOut, location->end());
124 group = transport_marker_group;
126 } else if (location->is_session_range()) {
129 lam->start = new Marker (*this, *marker_group, color, _("start"), Marker::SessionStart, location->start());
130 lam->end = new Marker (*this, *marker_group, color, _("end"), Marker::SessionEnd, location->end());
131 group = marker_group;
135 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
136 lam->start = new Marker (*this, *cd_marker_group, color,
137 location->name(), Marker::RangeStart, location->start());
138 lam->end = new Marker (*this, *cd_marker_group, color,
139 location->name(), Marker::RangeEnd, location->end());
140 group = cd_marker_group;
142 lam->start = new Marker (*this, *range_marker_group, color,
143 location->name(), Marker::RangeStart, location->start());
144 lam->end = new Marker (*this, *range_marker_group, color,
145 location->name(), Marker::RangeEnd, location->end());
146 group = range_marker_group;
150 if (location->is_hidden ()) {
156 location->start_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
157 location->end_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
158 location->changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
159 location->name_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
160 location->FlagsChanged.connect (*this, invalidator (*this), boost::bind (&Editor::location_flags_changed, this, _1, _2), gui_context());
162 pair<Location*,LocationMarkers*> newpair;
164 newpair.first = location;
165 newpair.second = lam;
167 location_markers.insert (newpair);
169 if (select_new_marker && location->is_mark()) {
170 selection->set (lam->start);
171 select_new_marker = false;
174 lam->canvas_height_set (_canvas_height);
175 lam->set_show_lines (_show_marker_lines);
177 /* Add these markers to the appropriate sorted marker lists, which will render
178 them unsorted until a call to update_marker_labels() sorts them out.
180 _sorted_marker_lists[group].push_back (lam->start);
182 _sorted_marker_lists[group].push_back (lam->end);
189 Editor::location_changed (Location *location)
191 ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
193 LocationMarkers *lam = find_location_markers (location);
196 /* a location that isn't "marked" with markers */
200 lam->set_name (location->name ());
201 lam->set_position (location->start(), location->end());
203 if (location->is_auto_loop()) {
204 update_loop_range_view ();
205 } else if (location->is_auto_punch()) {
206 update_punch_range_view ();
209 check_marker_label (lam->start);
211 check_marker_label (lam->end);
215 /** Look at a marker and check whether its label, and those of the previous and next markers,
216 * need to have their labels updated (in case those labels need to be shortened or can be
220 Editor::check_marker_label (Marker* m)
222 /* Get a time-ordered list of markers from the last time anything changed */
223 std::list<Marker*>& sorted = _sorted_marker_lists[m->get_parent()];
225 list<Marker*>::iterator i = find (sorted.begin(), sorted.end(), m);
227 list<Marker*>::iterator prev = sorted.end ();
228 list<Marker*>::iterator next = i;
231 /* Look to see if the previous marker is still behind `m' in time */
232 if (i != sorted.begin()) {
237 if ((*prev)->position() > m->position()) {
238 /* This marker is no longer in the correct order with the previous one, so
239 * update all the markers in this group.
241 update_marker_labels (m->get_parent ());
246 /* Look to see if the next marker is still ahead of `m' in time */
247 if (next != sorted.end() && (*next)->position() < m->position()) {
248 /* This marker is no longer in the correct order with the next one, so
249 * update all the markers in this group.
251 update_marker_labels (m->get_parent ());
255 if (prev != sorted.end()) {
257 /* Update just the available space between the previous marker and this one */
259 double const p = frame_to_pixel (m->position() - (*prev)->position());
261 if (m->label_on_left()) {
262 (*prev)->set_right_label_limit (p / 2);
264 (*prev)->set_right_label_limit (p);
267 if ((*prev)->label_on_left ()) {
268 m->set_left_label_limit (p);
270 m->set_left_label_limit (p / 2);
274 if (next != sorted.end()) {
276 /* Update just the available space between this marker and the next */
278 double const p = frame_to_pixel ((*next)->position() - m->position());
280 if ((*next)->label_on_left()) {
281 m->set_right_label_limit (p / 2);
283 m->set_right_label_limit (p);
286 if (m->label_on_left()) {
287 (*next)->set_left_label_limit (p);
289 (*next)->set_left_label_limit (p / 2);
294 struct MarkerComparator {
295 bool operator() (Marker const * a, Marker const * b) {
296 return a->position() < b->position();
300 /** Update all marker labels in all groups */
302 Editor::update_marker_labels ()
304 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
305 update_marker_labels (i->first);
309 /** Look at all markers in a group and update label widths */
311 Editor::update_marker_labels (ArdourCanvas::Group* group)
313 list<Marker*>& sorted = _sorted_marker_lists[group];
315 if (sorted.empty()) {
319 /* We sort the list of markers and then set up the space available between each one */
321 sorted.sort (MarkerComparator ());
323 list<Marker*>::iterator i = sorted.begin ();
325 list<Marker*>::iterator prev = sorted.end ();
326 list<Marker*>::iterator next = i;
329 while (i != sorted.end()) {
331 if (prev != sorted.end()) {
332 double const p = frame_to_pixel ((*i)->position() - (*prev)->position());
334 if ((*prev)->label_on_left()) {
335 (*i)->set_left_label_limit (p);
337 (*i)->set_left_label_limit (p / 2);
342 if (next != sorted.end()) {
343 double const p = frame_to_pixel ((*next)->position() - (*i)->position());
345 if ((*next)->label_on_left()) {
346 (*i)->set_right_label_limit (p / 2);
348 (*i)->set_right_label_limit (p);
359 Editor::location_flags_changed (Location *location, void*)
361 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
363 LocationMarkers *lam = find_location_markers (location);
366 /* a location that isn't "marked" with markers */
370 // move cd markers to/from cd marker bar as appropriate
371 ensure_cd_marker_updated (lam, location);
373 if (location->is_cd_marker()) {
374 lam->set_color_rgba (location_cd_marker_color);
375 } else if (location->is_mark()) {
376 lam->set_color_rgba (location_marker_color);
377 } else if (location->is_auto_punch()) {
378 lam->set_color_rgba (location_punch_color);
379 } else if (location->is_auto_loop()) {
380 lam->set_color_rgba (location_loop_color);
382 lam->set_color_rgba (location_range_color);
385 if (location->is_hidden()) {
392 void Editor::update_cd_marker_display ()
394 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
395 LocationMarkers * lam = i->second;
396 Location * location = i->first;
398 ensure_cd_marker_updated (lam, location);
402 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
404 if (location->is_cd_marker()
405 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
407 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
409 lam->start->reparent (*cd_marker_group);
412 lam->end->reparent (*cd_marker_group);
415 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
416 && (lam->start->get_parent() == cd_marker_group))
418 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
419 if (location->is_mark()) {
421 lam->start->reparent (*marker_group);
424 lam->end->reparent (*marker_group);
429 lam->start->reparent (*range_marker_group);
432 lam->end->reparent (*range_marker_group);
438 Editor::LocationMarkers::~LocationMarkers ()
444 Editor::LocationMarkers *
445 Editor::find_location_markers (Location *location) const
447 LocationMarkerMap::const_iterator i;
449 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
450 if ((*i).first == location) {
459 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
461 LocationMarkerMap::const_iterator i;
463 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
464 LocationMarkers *lm = (*i).second;
465 if (lm->start == marker) {
468 } else if (lm->end == marker) {
478 Editor::refresh_location_display_internal (Locations::LocationList& locations)
482 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
483 i->second->valid = false;
488 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
490 LocationMarkerMap::iterator x;
492 if ((x = location_markers.find (*i)) != location_markers.end()) {
493 x->second->valid = true;
497 add_new_location_internal (*i);
500 /* remove dead ones */
502 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
504 LocationMarkerMap::iterator tmp;
509 if (!i->second->valid) {
511 remove_sorted_marker (i->second->start);
512 if (i->second->end) {
513 remove_sorted_marker (i->second->end);
516 LocationMarkers* m = i->second;
517 location_markers.erase (i);
524 update_punch_range_view (false);
525 update_loop_range_view (false);
529 Editor::refresh_location_display ()
531 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
534 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
537 update_marker_labels ();
541 Editor::LocationMarkers::hide()
550 Editor::LocationMarkers::show()
559 Editor::LocationMarkers::canvas_height_set (double h)
561 start->canvas_height_set (h);
563 end->canvas_height_set (h);
568 Editor::LocationMarkers::set_name (const string& str)
570 /* XXX: hack: don't change names of session start/end markers */
572 if (start->type() != Marker::SessionStart) {
573 start->set_name (str);
576 if (end && end->type() != Marker::SessionEnd) {
582 Editor::LocationMarkers::set_position (framepos_t startf,
585 start->set_position (startf);
587 end->set_position (endf);
592 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
594 start->set_color_rgba (rgba);
596 end->set_color_rgba (rgba);
601 Editor::LocationMarkers::set_show_lines (bool s)
603 start->set_show_line (s);
605 end->set_show_line (s);
610 Editor::LocationMarkers::set_selected (bool s)
612 start->set_selected (s);
614 end->set_selected (s);
619 Editor::LocationMarkers::setup_lines ()
621 start->setup_line ();
628 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
630 string markername, markerprefix;
631 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
634 markerprefix = "xrun";
635 flags = Location::IsMark;
637 markerprefix = "mark";
641 _session->locations()->next_available_name(markername, markerprefix);
642 if (!is_xrun && !choose_new_marker_name(markername)) {
645 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
646 _session->begin_reversible_command (_("add marker"));
647 XMLNode &before = _session->locations()->get_state();
648 _session->locations()->add (location, true);
649 XMLNode &after = _session->locations()->get_state();
650 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
651 _session->commit_reversible_command ();
653 /* find the marker we just added */
655 LocationMarkers *lam = find_location_markers (location);
657 /* make it the selected marker */
658 selection->set (lam->start);
664 Editor::mouse_add_new_range (framepos_t where)
670 /* Make this marker 1/8th of the visible area of the session so that
671 it's reasonably easy to manipulate after creation.
674 framepos_t const end = where + current_page_frames() / 8;
677 _session->locations()->next_available_name (name, _("range"));
678 Location* loc = new Location (*_session, where, end, name, Location::IsRangeMarker);
680 begin_reversible_command (_("new range marker"));
681 XMLNode& before = _session->locations()->get_state ();
682 _session->locations()->add (loc, true);
683 XMLNode& after = _session->locations()->get_state ();
684 _session->add_command (new MementoCommand<Locations> (*_session->locations(), &before, &after));
685 commit_reversible_command ();
689 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
694 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
695 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
699 if (entered_marker == marker) {
700 entered_marker = NULL;
703 Location* loc = find_location_from_marker (marker, is_start);
705 if (_session && loc) {
706 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
711 Editor::really_remove_marker (Location* loc)
713 _session->begin_reversible_command (_("remove marker"));
714 XMLNode &before = _session->locations()->get_state();
715 _session->locations()->remove (loc);
716 XMLNode &after = _session->locations()->get_state();
717 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
718 _session->commit_reversible_command ();
723 Editor::location_gone (Location *location)
725 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
727 LocationMarkerMap::iterator i;
729 if (location == transport_loop_location()) {
730 update_loop_range_view (true);
733 if (location == transport_punch_location()) {
734 update_punch_range_view (true);
737 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
738 if (i->first == location) {
740 remove_sorted_marker (i->second->start);
741 if (i->second->end) {
742 remove_sorted_marker (i->second->end);
745 LocationMarkers* m = i->second;
746 location_markers.erase (i);
754 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
756 marker_menu_item = item;
760 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
762 bool can_remove = false;
765 can_remove = mm->meter().movable ();
767 can_remove = tm->tempo().movable ();
772 delete tempo_or_meter_marker_menu;
773 build_tempo_or_meter_marker_menu (can_remove);
774 tempo_or_meter_marker_menu->popup (1, ev->time);
778 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
781 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
782 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
787 Location * loc = find_location_from_marker (marker, is_start);
789 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) {
791 if (transport_marker_menu == 0) {
792 build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range());
795 marker_menu_item = item;
796 transport_marker_menu->popup (1, ev->time);
798 } else if (loc->is_mark()) {
801 build_marker_menu (loc);
803 // GTK2FIX use action group sensitivity
805 if (children.size() >= 3) {
806 MenuItem * loopitem = &children[2];
808 if (loc->is_mark()) {
809 loopitem->set_sensitive(false);
812 loopitem->set_sensitive(true);
817 marker_menu_item = item;
818 marker_menu->popup (1, ev->time);
820 } else if (loc->is_range_marker()) {
821 if (range_marker_menu == 0) {
822 build_range_marker_menu (false, false);
824 marker_menu_item = item;
825 range_marker_menu->popup (1, ev->time);
830 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
832 if (new_transport_marker_menu == 0) {
833 build_new_transport_marker_menu ();
836 new_transport_marker_menu->popup (1, ev->time);
841 Editor::build_marker_menu (Location* loc)
843 using namespace Menu_Helpers;
845 marker_menu = new Menu;
846 MenuList& items = marker_menu->items();
847 marker_menu->set_name ("ArdourContextMenu");
849 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
850 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
851 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
853 items.push_back (SeparatorElem());
855 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
857 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
858 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
860 items.push_back (CheckMenuElem (_("Lock")));
861 CheckMenuItem* lock_item = static_cast<CheckMenuItem*> (&items.back());
862 if (loc->locked ()) {
863 lock_item->set_active ();
865 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
867 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
868 CheckMenuItem* glue_item = static_cast<CheckMenuItem*> (&items.back());
869 if (loc->position_lock_style() == MusicTime) {
870 glue_item->set_active ();
872 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
874 items.push_back (SeparatorElem());
876 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
880 Editor::build_range_marker_menu (bool loop_or_punch, bool session)
882 using namespace Menu_Helpers;
884 bool const loop_or_punch_or_session = loop_or_punch | session;
886 Menu *markerMenu = new Menu;
887 if (loop_or_punch_or_session) {
888 transport_marker_menu = markerMenu;
890 range_marker_menu = markerMenu;
892 MenuList& items = markerMenu->items();
893 markerMenu->set_name ("ArdourContextMenu");
895 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
896 items.push_back (MenuElem (_("Locate to Marker"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
897 items.push_back (MenuElem (_("Play from Marker"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
898 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
900 items.push_back (MenuElem (_("Set Marker from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
901 if (!Profile->get_sae()) {
902 items.push_back (MenuElem (_("Set Range from Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection), false)));
905 items.push_back (MenuElem (_("Zoom to Range"), sigc::mem_fun (*this, &Editor::marker_menu_zoom_to_range)));
907 items.push_back (SeparatorElem());
908 items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_range)));
909 items.push_back (SeparatorElem());
911 if (!loop_or_punch_or_session) {
912 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
913 items.push_back (MenuElem (_("Rename Range..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
917 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
920 if (!loop_or_punch_or_session || !session) {
921 items.push_back (SeparatorElem());
924 items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
925 items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
926 if (!Profile->get_sae()) {
927 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
932 Editor::build_tempo_or_meter_marker_menu (bool can_remove)
934 using namespace Menu_Helpers;
936 tempo_or_meter_marker_menu = new Menu;
937 MenuList& items = tempo_or_meter_marker_menu->items();
938 tempo_or_meter_marker_menu->set_name ("ArdourContextMenu");
940 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
941 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
943 items.back().set_sensitive (can_remove);
947 Editor::build_new_transport_marker_menu ()
949 using namespace Menu_Helpers;
951 new_transport_marker_menu = new Menu;
952 MenuList& items = new_transport_marker_menu->items();
953 new_transport_marker_menu->set_name ("ArdourContextMenu");
955 items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
956 items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
958 new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
962 Editor::marker_menu_hide ()
966 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
967 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
974 if ((l = find_location_from_marker (marker, is_start)) != 0) {
975 l->set_hidden (true, this);
980 Editor::marker_menu_select_using_range ()
984 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
985 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
992 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
993 set_selection_from_range (*l);
998 Editor::marker_menu_select_all_selectables_using_range ()
1002 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1003 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1010 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1011 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, track_views, Selection::Set, false);
1017 Editor::marker_menu_separate_regions_using_location ()
1021 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1022 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1029 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1030 separate_regions_using_location (*l);
1036 Editor::marker_menu_play_from ()
1040 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1041 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1048 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1051 _session->request_locate (l->start(), true);
1054 //_session->request_bounded_roll (l->start(), l->end());
1057 _session->request_locate (l->start(), true);
1059 _session->request_locate (l->end(), true);
1066 Editor::marker_menu_set_playhead ()
1070 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1071 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1078 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1081 _session->request_locate (l->start(), false);
1085 _session->request_locate (l->start(), false);
1087 _session->request_locate (l->end(), false);
1094 Editor::marker_menu_range_to_next ()
1101 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1102 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1109 if ((l = find_location_from_marker (marker, is_start)) == 0) {
1115 _session->locations()->marks_either_side (marker->position(), start, end);
1117 if (end != max_framepos) {
1118 string range_name = l->name();
1119 range_name += "-range";
1121 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1122 _session->locations()->add (newrange);
1127 Editor::marker_menu_set_from_playhead ()
1131 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1132 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1139 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1142 l->set_start (_session->audible_frame ());
1146 l->set_start (_session->audible_frame ());
1148 l->set_end (_session->audible_frame ());
1155 Editor::marker_menu_set_from_selection (bool /*force_regions*/)
1159 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1160 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1167 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1175 if (!selection->time.empty()) {
1176 l->set (selection->time.start(), selection->time.end_frame());
1177 } else if (!selection->regions.empty()) {
1178 l->set (selection->regions.start(), selection->regions.end_frame());
1186 Editor::marker_menu_play_range ()
1190 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1191 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1198 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1201 _session->request_locate (l->start(), true);
1204 _session->request_bounded_roll (l->start(), l->end());
1211 Editor::marker_menu_loop_range ()
1215 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1216 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1223 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1225 if ((l2 = transport_loop_location()) != 0) {
1226 l2->set (l->start(), l->end());
1228 // enable looping, reposition and start rolling
1229 _session->request_play_loop(true);
1230 _session->request_locate (l2->start(), true);
1235 /** Temporal zoom to the range of the marker_menu_item (plus 5% either side) */
1237 Editor::marker_menu_zoom_to_range ()
1239 Marker* marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"));
1243 Location* l = find_location_from_marker (marker, is_start);
1248 framecnt_t const extra = l->length() * 0.05;
1249 framepos_t a = l->start ();
1254 framepos_t b = l->end ();
1255 if (b < (max_framepos - extra)) {
1259 temporal_zoom_by_frame (a, b);
1263 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1265 Marker* marker = reinterpret_cast<Marker*> (p);
1267 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1271 *m = dynamic_cast<MeterMarker*> (marker);
1272 *t = dynamic_cast<TempoMarker*> (marker);
1276 Editor::marker_menu_edit ()
1280 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1283 edit_meter_section (&mm->meter());
1285 edit_tempo_section (&tm->tempo());
1290 Editor::marker_menu_remove ()
1294 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1297 remove_meter_marker (marker_menu_item);
1299 remove_tempo_marker (marker_menu_item);
1301 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1306 Editor::toggle_marker_menu_lock ()
1310 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1311 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1318 loc = find_location_from_marker (marker, ignored);
1324 if (loc->locked()) {
1332 Editor::marker_menu_rename ()
1336 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1337 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1344 loc = find_location_from_marker (marker, is_start);
1348 ArdourPrompter dialog (true);
1351 dialog.set_prompt (_("New Name:"));
1353 if (loc->is_mark()) {
1354 dialog.set_title (_("Rename Mark"));
1356 dialog.set_title (_("Rename Range"));
1359 dialog.set_name ("MarkRenameWindow");
1360 dialog.set_size_request (250, -1);
1361 dialog.set_position (Gtk::WIN_POS_MOUSE);
1363 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1364 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1365 dialog.set_initial_text (loc->name());
1369 switch (dialog.run ()) {
1370 case RESPONSE_ACCEPT:
1376 begin_reversible_command ( _("rename marker") );
1377 XMLNode &before = _session->locations()->get_state();
1379 dialog.get_result(txt);
1380 loc->set_name (txt);
1382 XMLNode &after = _session->locations()->get_state();
1383 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1384 commit_reversible_command ();
1388 Editor::new_transport_marker_menu_popdown ()
1391 transport_bar_drag_rect->hide();
1397 Editor::new_transport_marker_menu_set_loop ()
1399 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1403 Editor::new_transport_marker_menu_set_punch ()
1405 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1409 Editor::update_loop_range_view (bool visibility)
1411 if (_session == 0) {
1417 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1419 double x1 = frame_to_pixel (tll->start());
1420 double x2 = frame_to_pixel (tll->end());
1422 transport_loop_range_rect->property_x1() = x1;
1423 transport_loop_range_rect->property_x2() = x2;
1426 transport_loop_range_rect->show();
1429 } else if (visibility) {
1430 transport_loop_range_rect->hide();
1435 Editor::update_punch_range_view (bool visibility)
1437 if (_session == 0) {
1443 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1444 guint track_canvas_width,track_canvas_height;
1445 track_canvas->get_size(track_canvas_width,track_canvas_height);
1446 if (_session->config.get_punch_in()) {
1447 transport_punch_range_rect->property_x1() = frame_to_pixel (tpl->start());
1448 transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : frame_to_pixel (JACK_MAX_FRAMES));
1450 transport_punch_range_rect->property_x1() = 0;
1451 transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : track_canvas_width);
1455 transport_punch_range_rect->show();
1457 } else if (visibility) {
1458 transport_punch_range_rect->hide();
1463 Editor::marker_selection_changed ()
1465 if (_session && _session->deletion_in_progress()) {
1469 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1470 i->second->set_selected (false);
1473 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1474 (*x)->set_selected (true);
1478 struct SortLocationsByPosition {
1479 bool operator() (Location* a, Location* b) {
1480 return a->start() < b->start();
1485 Editor::goto_nth_marker (int n)
1490 const Locations::LocationList& l (_session->locations()->list());
1491 Locations::LocationList ordered;
1494 SortLocationsByPosition cmp;
1497 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1498 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1500 _session->request_locate ((*i)->start(), _session->transport_rolling());
1509 Editor::toggle_marker_menu_glue ()
1513 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1514 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1521 loc = find_location_from_marker (marker, ignored);
1527 if (loc->position_lock_style() == MusicTime) {
1528 loc->set_position_lock_style (AudioTime);
1530 loc->set_position_lock_style (MusicTime);
1536 Editor::toggle_marker_lines ()
1538 _show_marker_lines = !_show_marker_lines;
1540 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1541 i->second->set_show_lines (_show_marker_lines);
1546 Editor::remove_sorted_marker (Marker* m)
1548 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1549 i->second.remove (m);
1554 Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
1556 for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1557 if (i->first->id() == id) {
1558 return is_start ? i->second->start : i->second->end;