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 <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"
31 #include "canvas/canvas.h"
32 #include "canvas/item.h"
33 #include "canvas/rectangle.h"
37 #include "selection.h"
39 #include "gui_thread.h"
42 #include "editor_drag.h"
47 using namespace ARDOUR;
50 using namespace Gtkmm2ext;
53 Editor::clear_marker_display ()
55 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
59 location_markers.clear ();
60 _sorted_marker_lists.clear ();
64 Editor::add_new_location (Location *location)
66 ENSURE_GUI_THREAD (*this, &Editor::add_new_location, location);
68 ArdourCanvas::Group* group = add_new_location_internal (location);
70 /* Do a full update of the markers in this group */
71 update_marker_labels (group);
74 /** Add a new location, without a time-consuming update of all marker labels;
75 * the caller must call update_marker_labels () after calling this.
76 * @return canvas group that the location's marker was added to.
79 Editor::add_new_location_internal (Location* location)
81 LocationMarkers *lam = new LocationMarkers;
84 /* make a note here of which group this marker ends up in */
85 ArdourCanvas::Group* group = 0;
87 if (location->is_cd_marker()) {
88 color = location_cd_marker_color;
89 } else if (location->is_mark()) {
90 color = location_marker_color;
91 } else if (location->is_auto_loop()) {
92 color = location_loop_color;
93 } else if (location->is_auto_punch()) {
94 color = location_punch_color;
96 color = location_range_color;
99 if (location->is_mark()) {
101 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
102 lam->start = new Marker (*this, *cd_marker_group, color, location->name(), Marker::Mark, location->start());
103 group = cd_marker_group;
105 lam->start = new Marker (*this, *marker_group, color, location->name(), Marker::Mark, location->start());
106 group = marker_group;
111 } else if (location->is_auto_loop()) {
114 lam->start = new Marker (*this, *transport_marker_group, color,
115 location->name(), Marker::LoopStart, location->start());
116 lam->end = new Marker (*this, *transport_marker_group, color,
117 location->name(), Marker::LoopEnd, location->end());
118 group = transport_marker_group;
120 } else if (location->is_auto_punch()) {
123 lam->start = new Marker (*this, *transport_marker_group, color,
124 location->name(), Marker::PunchIn, location->start());
125 lam->end = new Marker (*this, *transport_marker_group, color,
126 location->name(), Marker::PunchOut, location->end());
127 group = transport_marker_group;
129 } else if (location->is_session_range()) {
132 lam->start = new Marker (*this, *marker_group, color, _("start"), Marker::SessionStart, location->start());
133 lam->end = new Marker (*this, *marker_group, color, _("end"), Marker::SessionEnd, location->end());
134 group = marker_group;
138 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
139 lam->start = new Marker (*this, *cd_marker_group, color,
140 location->name(), Marker::RangeStart, location->start());
141 lam->end = new Marker (*this, *cd_marker_group, color,
142 location->name(), Marker::RangeEnd, location->end());
143 group = cd_marker_group;
145 lam->start = new Marker (*this, *range_marker_group, color,
146 location->name(), Marker::RangeStart, location->start());
147 lam->end = new Marker (*this, *range_marker_group, color,
148 location->name(), Marker::RangeEnd, location->end());
149 group = range_marker_group;
153 if (location->is_hidden ()) {
159 location->start_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
160 location->end_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
161 location->changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
162 location->name_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
163 location->FlagsChanged.connect (*this, invalidator (*this), boost::bind (&Editor::location_flags_changed, this, _1, _2), gui_context());
165 pair<Location*,LocationMarkers*> newpair;
167 newpair.first = location;
168 newpair.second = lam;
170 location_markers.insert (newpair);
172 if (select_new_marker && location->is_mark()) {
173 selection->set (lam->start);
174 select_new_marker = false;
177 lam->canvas_height_set (_visible_canvas_height);
178 lam->set_show_lines (_show_marker_lines);
180 /* Add these markers to the appropriate sorted marker lists, which will render
181 them unsorted until a call to update_marker_labels() sorts them out.
183 _sorted_marker_lists[group].push_back (lam->start);
185 _sorted_marker_lists[group].push_back (lam->end);
192 Editor::location_changed (Location *location)
194 ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
196 LocationMarkers *lam = find_location_markers (location);
199 /* a location that isn't "marked" with markers */
203 lam->set_name (location->name ());
204 lam->set_position (location->start(), location->end());
206 if (location->is_auto_loop()) {
207 update_loop_range_view ();
208 } else if (location->is_auto_punch()) {
209 update_punch_range_view ();
212 check_marker_label (lam->start);
214 check_marker_label (lam->end);
218 /** Look at a marker and check whether its label, and those of the previous and next markers,
219 * need to have their labels updated (in case those labels need to be shortened or can be
223 Editor::check_marker_label (Marker* m)
225 /* Get a time-ordered list of markers from the last time anything changed */
226 std::list<Marker*>& sorted = _sorted_marker_lists[m->get_parent()];
228 list<Marker*>::iterator i = find (sorted.begin(), sorted.end(), m);
230 list<Marker*>::iterator prev = sorted.end ();
231 list<Marker*>::iterator next = i;
234 /* Look to see if the previous marker is still behind `m' in time */
235 if (i != sorted.begin()) {
240 if ((*prev)->position() > m->position()) {
241 /* This marker is no longer in the correct order with the previous one, so
242 * update all the markers in this group.
244 update_marker_labels (m->get_parent ());
249 /* Look to see if the next marker is still ahead of `m' in time */
250 if (next != sorted.end() && (*next)->position() < m->position()) {
251 /* This marker is no longer in the correct order with the next one, so
252 * update all the markers in this group.
254 update_marker_labels (m->get_parent ());
258 if (prev != sorted.end()) {
260 /* Update just the available space between the previous marker and this one */
262 double const p = frame_to_pixel (m->position() - (*prev)->position());
264 if (m->label_on_left()) {
265 (*prev)->set_right_label_limit (p / 2);
267 (*prev)->set_right_label_limit (p);
270 if ((*prev)->label_on_left ()) {
271 m->set_left_label_limit (p);
273 m->set_left_label_limit (p / 2);
277 if (next != sorted.end()) {
279 /* Update just the available space between this marker and the next */
281 double const p = frame_to_pixel ((*next)->position() - m->position());
283 if ((*next)->label_on_left()) {
284 m->set_right_label_limit (p / 2);
286 m->set_right_label_limit (p);
289 if (m->label_on_left()) {
290 (*next)->set_left_label_limit (p);
292 (*next)->set_left_label_limit (p / 2);
297 struct MarkerComparator {
298 bool operator() (Marker const * a, Marker const * b) {
299 return a->position() < b->position();
303 /** Update all marker labels in all groups */
305 Editor::update_marker_labels ()
307 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
308 update_marker_labels (i->first);
312 /** Look at all markers in a group and update label widths */
314 Editor::update_marker_labels (ArdourCanvas::Group* group)
316 list<Marker*>& sorted = _sorted_marker_lists[group];
318 if (sorted.empty()) {
322 /* We sort the list of markers and then set up the space available between each one */
324 sorted.sort (MarkerComparator ());
326 list<Marker*>::iterator i = sorted.begin ();
328 list<Marker*>::iterator prev = sorted.end ();
329 list<Marker*>::iterator next = i;
332 while (i != sorted.end()) {
334 if (prev != sorted.end()) {
335 double const p = frame_to_pixel ((*i)->position() - (*prev)->position());
337 if ((*prev)->label_on_left()) {
338 (*i)->set_left_label_limit (p);
340 (*i)->set_left_label_limit (p / 2);
345 if (next != sorted.end()) {
346 double const p = frame_to_pixel ((*next)->position() - (*i)->position());
348 if ((*next)->label_on_left()) {
349 (*i)->set_right_label_limit (p / 2);
351 (*i)->set_right_label_limit (p);
362 Editor::location_flags_changed (Location *location, void*)
364 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
366 LocationMarkers *lam = find_location_markers (location);
369 /* a location that isn't "marked" with markers */
373 // move cd markers to/from cd marker bar as appropriate
374 ensure_cd_marker_updated (lam, location);
376 if (location->is_cd_marker()) {
377 lam->set_color_rgba (location_cd_marker_color);
378 } else if (location->is_mark()) {
379 lam->set_color_rgba (location_marker_color);
380 } else if (location->is_auto_punch()) {
381 lam->set_color_rgba (location_punch_color);
382 } else if (location->is_auto_loop()) {
383 lam->set_color_rgba (location_loop_color);
385 lam->set_color_rgba (location_range_color);
388 if (location->is_hidden()) {
395 void Editor::update_cd_marker_display ()
397 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
398 LocationMarkers * lam = i->second;
399 Location * location = i->first;
401 ensure_cd_marker_updated (lam, location);
405 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
407 if (location->is_cd_marker()
408 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
410 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
412 lam->start->reparent (*cd_marker_group);
415 lam->end->reparent (*cd_marker_group);
418 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
419 && (lam->start->get_parent() == cd_marker_group))
421 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
422 if (location->is_mark()) {
424 lam->start->reparent (*marker_group);
427 lam->end->reparent (*marker_group);
432 lam->start->reparent (*range_marker_group);
435 lam->end->reparent (*range_marker_group);
441 Editor::LocationMarkers::~LocationMarkers ()
447 Editor::LocationMarkers *
448 Editor::find_location_markers (Location *location) const
450 LocationMarkerMap::const_iterator i;
452 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
453 if ((*i).first == location) {
462 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
464 LocationMarkerMap::const_iterator i;
466 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
467 LocationMarkers *lm = (*i).second;
468 if (lm->start == marker) {
471 } else if (lm->end == marker) {
481 Editor::refresh_location_display_internal (Locations::LocationList& locations)
485 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
486 i->second->valid = false;
491 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
493 LocationMarkerMap::iterator x;
495 if ((x = location_markers.find (*i)) != location_markers.end()) {
496 x->second->valid = true;
500 add_new_location_internal (*i);
503 /* remove dead ones */
505 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
507 LocationMarkerMap::iterator tmp;
512 if (!i->second->valid) {
514 remove_sorted_marker (i->second->start);
515 if (i->second->end) {
516 remove_sorted_marker (i->second->end);
519 LocationMarkers* m = i->second;
520 location_markers.erase (i);
527 update_punch_range_view (false);
528 update_loop_range_view (false);
532 Editor::refresh_location_display ()
534 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
537 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
540 update_marker_labels ();
544 Editor::LocationMarkers::hide()
553 Editor::LocationMarkers::show()
562 Editor::LocationMarkers::canvas_height_set (double h)
564 start->canvas_height_set (h);
566 end->canvas_height_set (h);
571 Editor::LocationMarkers::set_name (const string& str)
573 /* XXX: hack: don't change names of session start/end markers */
575 if (start->type() != Marker::SessionStart) {
576 start->set_name (str);
579 if (end && end->type() != Marker::SessionEnd) {
585 Editor::LocationMarkers::set_position (framepos_t startf,
588 start->set_position (startf);
590 end->set_position (endf);
595 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
597 start->set_color_rgba (rgba);
599 end->set_color_rgba (rgba);
604 Editor::LocationMarkers::set_show_lines (bool s)
606 start->set_show_line (s);
608 end->set_show_line (s);
613 Editor::LocationMarkers::set_selected (bool s)
615 start->set_selected (s);
617 end->set_selected (s);
622 Editor::LocationMarkers::setup_lines ()
624 start->setup_line ();
631 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
633 string markername, markerprefix;
634 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
637 markerprefix = "xrun";
638 flags = Location::IsMark;
640 markerprefix = "mark";
644 _session->locations()->next_available_name(markername, markerprefix);
645 if (!is_xrun && !choose_new_marker_name(markername)) {
648 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
649 _session->begin_reversible_command (_("add marker"));
650 XMLNode &before = _session->locations()->get_state();
651 _session->locations()->add (location, true);
652 XMLNode &after = _session->locations()->get_state();
653 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
654 _session->commit_reversible_command ();
656 /* find the marker we just added */
658 LocationMarkers *lam = find_location_markers (location);
660 /* make it the selected marker */
661 selection->set (lam->start);
667 Editor::mouse_add_new_range (framepos_t where)
673 /* Make this marker 1/8th of the visible area of the session so that
674 it's reasonably easy to manipulate after creation.
677 framepos_t const end = where + current_page_frames() / 8;
680 _session->locations()->next_available_name (name, _("range"));
681 Location* loc = new Location (*_session, where, end, name, Location::IsRangeMarker);
683 begin_reversible_command (_("new range marker"));
684 XMLNode& before = _session->locations()->get_state ();
685 _session->locations()->add (loc, true);
686 XMLNode& after = _session->locations()->get_state ();
687 _session->add_command (new MementoCommand<Locations> (*_session->locations(), &before, &after));
688 commit_reversible_command ();
692 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
697 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
698 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
702 if (entered_marker == marker) {
703 entered_marker = NULL;
706 Location* loc = find_location_from_marker (marker, is_start);
708 if (_session && loc) {
709 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
714 Editor::really_remove_marker (Location* loc)
716 _session->begin_reversible_command (_("remove marker"));
717 XMLNode &before = _session->locations()->get_state();
718 _session->locations()->remove (loc);
719 XMLNode &after = _session->locations()->get_state();
720 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
721 _session->commit_reversible_command ();
726 Editor::location_gone (Location *location)
728 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
730 LocationMarkerMap::iterator i;
732 if (location == transport_loop_location()) {
733 update_loop_range_view (true);
736 if (location == transport_punch_location()) {
737 update_punch_range_view (true);
740 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
741 if (i->first == location) {
743 remove_sorted_marker (i->second->start);
744 if (i->second->end) {
745 remove_sorted_marker (i->second->end);
748 LocationMarkers* m = i->second;
749 location_markers.erase (i);
757 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
759 marker_menu_item = item;
763 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
765 bool can_remove = false;
768 can_remove = mm->meter().movable ();
770 can_remove = tm->tempo().movable ();
775 delete tempo_or_meter_marker_menu;
776 build_tempo_or_meter_marker_menu (can_remove);
777 tempo_or_meter_marker_menu->popup (1, ev->time);
781 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
784 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
785 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
790 Location * loc = find_location_from_marker (marker, is_start);
792 if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) {
794 if (transport_marker_menu == 0) {
795 build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range());
798 marker_menu_item = item;
799 transport_marker_menu->popup (1, ev->time);
801 } else if (loc->is_mark()) {
804 build_marker_menu (loc);
806 // GTK2FIX use action group sensitivity
808 if (children.size() >= 3) {
809 MenuItem * loopitem = &children[2];
811 if (loc->is_mark()) {
812 loopitem->set_sensitive(false);
815 loopitem->set_sensitive(true);
820 marker_menu_item = item;
821 marker_menu->popup (1, ev->time);
823 } else if (loc->is_range_marker()) {
824 if (range_marker_menu == 0) {
825 build_range_marker_menu (false, false);
827 marker_menu_item = item;
828 range_marker_menu->popup (1, ev->time);
833 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
835 if (new_transport_marker_menu == 0) {
836 build_new_transport_marker_menu ();
839 new_transport_marker_menu->popup (1, ev->time);
844 Editor::build_marker_menu (Location* loc)
846 using namespace Menu_Helpers;
848 marker_menu = new Menu;
849 MenuList& items = marker_menu->items();
850 marker_menu->set_name ("ArdourContextMenu");
852 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
853 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
854 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
856 items.push_back (SeparatorElem());
858 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
860 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
861 items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
863 items.push_back (CheckMenuElem (_("Lock")));
864 CheckMenuItem* lock_item = static_cast<CheckMenuItem*> (&items.back());
865 if (loc->locked ()) {
866 lock_item->set_active ();
868 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
870 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
871 CheckMenuItem* glue_item = static_cast<CheckMenuItem*> (&items.back());
872 if (loc->position_lock_style() == MusicTime) {
873 glue_item->set_active ();
875 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
877 items.push_back (SeparatorElem());
879 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
883 Editor::build_range_marker_menu (bool loop_or_punch, bool session)
885 using namespace Menu_Helpers;
887 bool const loop_or_punch_or_session = loop_or_punch | session;
889 Menu *markerMenu = new Menu;
890 if (loop_or_punch_or_session) {
891 transport_marker_menu = markerMenu;
893 range_marker_menu = markerMenu;
895 MenuList& items = markerMenu->items();
896 markerMenu->set_name ("ArdourContextMenu");
898 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
899 items.push_back (MenuElem (_("Locate to Marker"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
900 items.push_back (MenuElem (_("Play from Marker"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
901 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
903 items.push_back (MenuElem (_("Set Marker from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
904 if (!Profile->get_sae()) {
905 items.push_back (MenuElem (_("Set Range from Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection), false)));
908 items.push_back (MenuElem (_("Zoom to Range"), sigc::mem_fun (*this, &Editor::marker_menu_zoom_to_range)));
910 items.push_back (SeparatorElem());
911 items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_range)));
912 items.push_back (SeparatorElem());
914 if (!loop_or_punch_or_session) {
915 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
916 items.push_back (MenuElem (_("Rename Range..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
920 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
923 if (!loop_or_punch_or_session || !session) {
924 items.push_back (SeparatorElem());
927 items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
928 items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
929 if (!Profile->get_sae()) {
930 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
935 Editor::build_tempo_or_meter_marker_menu (bool can_remove)
937 using namespace Menu_Helpers;
939 tempo_or_meter_marker_menu = new Menu;
940 MenuList& items = tempo_or_meter_marker_menu->items();
941 tempo_or_meter_marker_menu->set_name ("ArdourContextMenu");
943 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
944 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
946 items.back().set_sensitive (can_remove);
950 Editor::build_new_transport_marker_menu ()
952 using namespace Menu_Helpers;
954 new_transport_marker_menu = new Menu;
955 MenuList& items = new_transport_marker_menu->items();
956 new_transport_marker_menu->set_name ("ArdourContextMenu");
958 items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
959 items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
961 new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
965 Editor::marker_menu_hide ()
969 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
970 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
977 if ((l = find_location_from_marker (marker, is_start)) != 0) {
978 l->set_hidden (true, this);
983 Editor::marker_menu_select_using_range ()
987 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
988 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
995 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
996 set_selection_from_range (*l);
1001 Editor::marker_menu_select_all_selectables_using_range ()
1005 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1006 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1013 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1014 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, track_views, Selection::Set, false);
1020 Editor::marker_menu_separate_regions_using_location ()
1024 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1025 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1032 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1033 separate_regions_using_location (*l);
1039 Editor::marker_menu_play_from ()
1043 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1044 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1051 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1054 _session->request_locate (l->start(), true);
1057 //_session->request_bounded_roll (l->start(), l->end());
1060 _session->request_locate (l->start(), true);
1062 _session->request_locate (l->end(), true);
1069 Editor::marker_menu_set_playhead ()
1073 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1074 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1081 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1084 _session->request_locate (l->start(), false);
1088 _session->request_locate (l->start(), false);
1090 _session->request_locate (l->end(), false);
1097 Editor::marker_menu_range_to_next ()
1104 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1105 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1112 if ((l = find_location_from_marker (marker, is_start)) == 0) {
1118 _session->locations()->marks_either_side (marker->position(), start, end);
1120 if (end != max_framepos) {
1121 string range_name = l->name();
1122 range_name += "-range";
1124 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1125 _session->locations()->add (newrange);
1130 Editor::marker_menu_set_from_playhead ()
1134 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1135 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1142 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1145 l->set_start (_session->audible_frame ());
1149 l->set_start (_session->audible_frame ());
1151 l->set_end (_session->audible_frame ());
1158 Editor::marker_menu_set_from_selection (bool /*force_regions*/)
1162 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1163 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1170 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1178 if (!selection->time.empty()) {
1179 l->set (selection->time.start(), selection->time.end_frame());
1180 } else if (!selection->regions.empty()) {
1181 l->set (selection->regions.start(), selection->regions.end_frame());
1189 Editor::marker_menu_play_range ()
1193 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1194 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1201 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1204 _session->request_locate (l->start(), true);
1207 _session->request_bounded_roll (l->start(), l->end());
1214 Editor::marker_menu_loop_range ()
1218 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1219 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1226 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1228 if ((l2 = transport_loop_location()) != 0) {
1229 l2->set (l->start(), l->end());
1231 // enable looping, reposition and start rolling
1232 _session->request_play_loop(true);
1233 _session->request_locate (l2->start(), true);
1238 /** Temporal zoom to the range of the marker_menu_item (plus 5% either side) */
1240 Editor::marker_menu_zoom_to_range ()
1242 Marker* marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"));
1246 Location* l = find_location_from_marker (marker, is_start);
1251 framecnt_t const extra = l->length() * 0.05;
1252 framepos_t a = l->start ();
1257 framepos_t b = l->end ();
1258 if (b < (max_framepos - extra)) {
1262 temporal_zoom_by_frame (a, b);
1266 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1268 Marker* marker = reinterpret_cast<Marker*> (p);
1270 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1274 *m = dynamic_cast<MeterMarker*> (marker);
1275 *t = dynamic_cast<TempoMarker*> (marker);
1279 Editor::marker_menu_edit ()
1283 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1286 edit_meter_section (&mm->meter());
1288 edit_tempo_section (&tm->tempo());
1293 Editor::marker_menu_remove ()
1297 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1300 remove_meter_marker (marker_menu_item);
1302 remove_tempo_marker (marker_menu_item);
1304 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1309 Editor::toggle_marker_menu_lock ()
1313 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1314 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1321 loc = find_location_from_marker (marker, ignored);
1327 if (loc->locked()) {
1335 Editor::marker_menu_rename ()
1339 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1340 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1347 loc = find_location_from_marker (marker, is_start);
1351 ArdourPrompter dialog (true);
1354 dialog.set_prompt (_("New Name:"));
1356 if (loc->is_mark()) {
1357 dialog.set_title (_("Rename Mark"));
1359 dialog.set_title (_("Rename Range"));
1362 dialog.set_name ("MarkRenameWindow");
1363 dialog.set_size_request (250, -1);
1364 dialog.set_position (Gtk::WIN_POS_MOUSE);
1366 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1367 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1368 dialog.set_initial_text (loc->name());
1372 switch (dialog.run ()) {
1373 case RESPONSE_ACCEPT:
1379 begin_reversible_command ( _("rename marker") );
1380 XMLNode &before = _session->locations()->get_state();
1382 dialog.get_result(txt);
1383 loc->set_name (txt);
1385 XMLNode &after = _session->locations()->get_state();
1386 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1387 commit_reversible_command ();
1391 Editor::new_transport_marker_menu_popdown ()
1394 transport_bar_drag_rect->hide();
1400 Editor::new_transport_marker_menu_set_loop ()
1402 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1406 Editor::new_transport_marker_menu_set_punch ()
1408 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1412 Editor::update_loop_range_view (bool visibility)
1414 if (_session == 0) {
1420 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1422 double x1 = frame_to_pixel (tll->start());
1423 double x2 = frame_to_pixel (tll->end());
1425 transport_loop_range_rect->set_x0 (x1);
1426 transport_loop_range_rect->set_x1 (x2);
1429 transport_loop_range_rect->show();
1432 } else if (visibility) {
1433 transport_loop_range_rect->hide();
1438 Editor::update_punch_range_view (bool visibility)
1440 if (_session == 0) {
1446 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1447 ArdourCanvas::Rect const v = _track_canvas_viewport->visible_area ();
1448 if (_session->config.get_punch_in()) {
1449 transport_punch_range_rect->set_x0 (frame_to_pixel (tpl->start()));
1450 transport_punch_range_rect->set_x1 (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : frame_to_pixel (JACK_MAX_FRAMES));
1452 transport_punch_range_rect->set_x0 (0);
1453 transport_punch_range_rect->set_x1 (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : v.width ());
1457 transport_punch_range_rect->show();
1459 } else if (visibility) {
1460 transport_punch_range_rect->hide();
1465 Editor::marker_selection_changed ()
1467 if (_session && _session->deletion_in_progress()) {
1471 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1472 i->second->set_selected (false);
1475 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1476 (*x)->set_selected (true);
1480 struct SortLocationsByPosition {
1481 bool operator() (Location* a, Location* b) {
1482 return a->start() < b->start();
1487 Editor::goto_nth_marker (int n)
1492 const Locations::LocationList& l (_session->locations()->list());
1493 Locations::LocationList ordered;
1496 SortLocationsByPosition cmp;
1499 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1500 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1502 _session->request_locate ((*i)->start(), _session->transport_rolling());
1511 Editor::toggle_marker_menu_glue ()
1515 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1516 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1523 loc = find_location_from_marker (marker, ignored);
1529 if (loc->position_lock_style() == MusicTime) {
1530 loc->set_position_lock_style (AudioTime);
1532 loc->set_position_lock_style (MusicTime);
1538 Editor::toggle_marker_lines ()
1540 _show_marker_lines = !_show_marker_lines;
1542 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1543 i->second->set_show_lines (_show_marker_lines);
1548 Editor::remove_sorted_marker (Marker* m)
1550 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1551 i->second.remove (m);
1556 Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
1558 for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1559 if (i->first->id() == id) {
1560 return is_start ? i->second->start : i->second->end;