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 ();
61 Editor::add_new_location (Location *location)
63 ENSURE_GUI_THREAD (*this, &Editor::add_new_location, location)
65 LocationMarkers *lam = new LocationMarkers;
68 /* make a note here of which group this marker ends up in */
69 ArdourCanvas::Group* group = 0;
71 if (location->is_cd_marker()) {
72 color = location_cd_marker_color;
73 } else if (location->is_mark()) {
74 color = location_marker_color;
75 } else if (location->is_auto_loop()) {
76 color = location_loop_color;
77 } else if (location->is_auto_punch()) {
78 color = location_punch_color;
80 color = location_range_color;
83 if (location->is_mark()) {
85 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
86 lam->start = new Marker (*this, *cd_marker_group, *cursor_group, color, location->name(), Marker::Mark, location->start());
87 group = cd_marker_group;
89 lam->start = new Marker (*this, *marker_group, *cursor_group, color, location->name(), Marker::Mark, location->start());
95 } else if (location->is_auto_loop()) {
98 lam->start = new Marker (*this, *transport_marker_group, *cursor_group, color,
99 location->name(), Marker::LoopStart, location->start());
100 lam->end = new Marker (*this, *transport_marker_group, *cursor_group, color,
101 location->name(), Marker::LoopEnd, location->end());
102 group = transport_marker_group;
104 } else if (location->is_auto_punch()) {
107 lam->start = new Marker (*this, *transport_marker_group, *cursor_group, color,
108 location->name(), Marker::PunchIn, location->start());
109 lam->end = new Marker (*this, *transport_marker_group, *cursor_group, color,
110 location->name(), Marker::PunchOut, location->end());
111 group = transport_marker_group;
113 } else if (location->is_session_range()) {
116 lam->start = new Marker (*this, *marker_group, *cursor_group, color, _("start"), Marker::SessionStart, location->start());
117 lam->end = new Marker (*this, *marker_group, *cursor_group, color, _("end"), Marker::SessionEnd, location->end());
118 group = marker_group;
122 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
123 lam->start = new Marker (*this, *cd_marker_group, *cursor_group, color,
124 location->name(), Marker::RangeStart, location->start());
125 lam->end = new Marker (*this, *cd_marker_group, *cursor_group, color,
126 location->name(), Marker::RangeEnd, location->end());
127 group = cd_marker_group;
129 lam->start = new Marker (*this, *range_marker_group, *cursor_group, color,
130 location->name(), Marker::RangeStart, location->start());
131 lam->end = new Marker (*this, *range_marker_group, *cursor_group, color,
132 location->name(), Marker::RangeEnd, location->end());
133 group = range_marker_group;
137 if (location->is_hidden ()) {
143 location->start_changed.connect (*this, invalidator (*this), ui_bind (&Editor::location_changed, this, _1), gui_context());
144 location->end_changed.connect (*this, invalidator (*this), ui_bind (&Editor::location_changed, this, _1), gui_context());
145 location->changed.connect (*this, invalidator (*this), ui_bind (&Editor::location_changed, this, _1), gui_context());
146 location->name_changed.connect (*this, invalidator (*this), ui_bind (&Editor::location_changed, this, _1), gui_context());
147 location->FlagsChanged.connect (*this, invalidator (*this), ui_bind (&Editor::location_flags_changed, this, _1, _2), gui_context());
149 pair<Location*,LocationMarkers*> newpair;
151 newpair.first = location;
152 newpair.second = lam;
154 location_markers.insert (newpair);
156 if (select_new_marker && location->is_mark()) {
157 selection->set (lam->start);
158 select_new_marker = false;
161 lam->canvas_height_set (_canvas_height);
162 lam->set_show_lines (_show_marker_lines);
164 /* Add these markers to the appropriate sorted marker lists, which will render
165 them unsorted until the update_marker_labels() below sorts them out.
167 _sorted_marker_lists[group].push_back (lam->start);
169 _sorted_marker_lists[group].push_back (lam->end);
172 /* Do a full update of the markers in this group */
173 update_marker_labels (group);
177 Editor::location_changed (Location *location)
179 ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
181 LocationMarkers *lam = find_location_markers (location);
184 /* a location that isn't "marked" with markers */
188 lam->set_name (location->name ());
189 lam->set_position (location->start(), location->end());
191 if (location->is_auto_loop()) {
192 update_loop_range_view ();
193 } else if (location->is_auto_punch()) {
194 update_punch_range_view ();
197 check_marker_label (lam->start);
199 check_marker_label (lam->end);
203 /** Look at a marker and check whether its label, and those of the previous and next markers,
204 * need to have their labels updated (in case those labels need to be shortened or can be
208 Editor::check_marker_label (Marker* m)
210 /* Get a time-ordered list of markers from the last time anything changed */
211 std::list<Marker*>& sorted = _sorted_marker_lists[m->get_parent()];
213 list<Marker*>::iterator i = find (sorted.begin(), sorted.end(), m);
215 list<Marker*>::iterator prev = sorted.end ();
216 list<Marker*>::iterator next = i;
219 /* Look to see if the previous marker is still behind `m' in time */
220 if (i != sorted.begin()) {
225 if ((*prev)->position() > m->position()) {
226 /* This marker is no longer in the correct order with the previous one, so
227 * update all the markers in this group.
229 update_marker_labels (m->get_parent ());
234 /* Look to see if the next marker is still ahead of `m' in time */
235 if (next != sorted.end() && (*next)->position() < m->position()) {
236 /* This marker is no longer in the correct order with the next one, so
237 * update all the markers in this group.
239 update_marker_labels (m->get_parent ());
243 if (prev != sorted.end()) {
245 /* Update just the available space between the previous marker and this one */
247 double const p = frame_to_pixel (m->position() - (*prev)->position());
249 if (m->label_on_left()) {
250 (*prev)->set_right_label_limit (p / 2);
252 (*prev)->set_right_label_limit (p);
255 if ((*prev)->label_on_left ()) {
256 m->set_left_label_limit (p);
258 m->set_left_label_limit (p / 2);
262 if (next != sorted.end()) {
264 /* Update just the available space between this marker and the next */
266 double const p = frame_to_pixel ((*next)->position() - m->position());
268 if ((*next)->label_on_left()) {
269 m->set_right_label_limit (p / 2);
271 m->set_right_label_limit (p);
274 if (m->label_on_left()) {
275 (*next)->set_left_label_limit (p);
277 (*next)->set_left_label_limit (p / 2);
282 struct MarkerComparator {
283 bool operator() (Marker const * a, Marker const * b) {
284 return a->position() < b->position();
288 /** Update all marker labels in all groups */
290 Editor::update_marker_labels ()
292 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
293 update_marker_labels (i->first);
297 /** Look at all markers in a group and update label widths */
299 Editor::update_marker_labels (ArdourCanvas::Group* group)
301 list<Marker*>& sorted = _sorted_marker_lists[group];
303 if (sorted.empty()) {
307 /* We sort the list of markers and then set up the space available between each one */
309 sorted.sort (MarkerComparator ());
311 list<Marker*>::iterator i = sorted.begin ();
313 list<Marker*>::iterator prev = sorted.end ();
314 list<Marker*>::iterator next = i;
317 while (i != sorted.end()) {
319 if (prev != sorted.end()) {
320 double const p = frame_to_pixel ((*i)->position() - (*prev)->position());
322 if ((*prev)->label_on_left()) {
323 (*i)->set_left_label_limit (p);
325 (*i)->set_left_label_limit (p / 2);
330 if (next != sorted.end()) {
331 double const p = frame_to_pixel ((*next)->position() - (*i)->position());
333 if ((*next)->label_on_left()) {
334 (*i)->set_right_label_limit (p / 2);
336 (*i)->set_right_label_limit (p);
347 Editor::location_flags_changed (Location *location, void*)
349 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
351 LocationMarkers *lam = find_location_markers (location);
354 /* a location that isn't "marked" with markers */
358 // move cd markers to/from cd marker bar as appropriate
359 ensure_cd_marker_updated (lam, location);
361 if (location->is_cd_marker()) {
362 lam->set_color_rgba (location_cd_marker_color);
363 } else if (location->is_mark()) {
364 lam->set_color_rgba (location_marker_color);
365 } else if (location->is_auto_punch()) {
366 lam->set_color_rgba (location_punch_color);
367 } else if (location->is_auto_loop()) {
368 lam->set_color_rgba (location_loop_color);
370 lam->set_color_rgba (location_range_color);
373 if (location->is_hidden()) {
380 void Editor::update_cd_marker_display ()
382 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
383 LocationMarkers * lam = i->second;
384 Location * location = i->first;
386 ensure_cd_marker_updated (lam, location);
390 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
392 if (location->is_cd_marker()
393 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
395 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
397 lam->start->reparent (*cd_marker_group);
400 lam->end->reparent (*cd_marker_group);
403 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
404 && (lam->start->get_parent() == cd_marker_group))
406 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
407 if (location->is_mark()) {
409 lam->start->reparent (*marker_group);
412 lam->end->reparent (*marker_group);
417 lam->start->reparent (*range_marker_group);
420 lam->end->reparent (*range_marker_group);
426 Editor::LocationMarkers::~LocationMarkers ()
432 Editor::LocationMarkers *
433 Editor::find_location_markers (Location *location) const
435 LocationMarkerMap::const_iterator i;
437 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
438 if ((*i).first == location) {
447 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
449 LocationMarkerMap::const_iterator i;
451 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
452 LocationMarkers *lm = (*i).second;
453 if (lm->start == marker) {
456 } else if (lm->end == marker) {
466 Editor::refresh_location_display_internal (Locations::LocationList& locations)
470 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
471 i->second->valid = false;
476 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
478 LocationMarkerMap::iterator x;
480 if ((x = location_markers.find (*i)) != location_markers.end()) {
481 x->second->valid = true;
485 add_new_location (*i);
488 /* remove dead ones */
490 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
492 LocationMarkerMap::iterator tmp;
497 if (!i->second->valid) {
499 location_markers.erase (i);
505 update_punch_range_view (false);
506 update_loop_range_view (false);
510 Editor::refresh_location_display ()
512 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
515 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
520 Editor::refresh_location_display_s (const PropertyChange&)
522 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display_s, ignored)
525 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
530 Editor::LocationMarkers::hide()
539 Editor::LocationMarkers::show()
548 Editor::LocationMarkers::canvas_height_set (double h)
550 start->canvas_height_set (h);
552 end->canvas_height_set (h);
557 Editor::LocationMarkers::set_name (const string& str)
559 /* XXX: hack: don't change names of session start/end markers */
561 if (start->type() != Marker::SessionStart) {
562 start->set_name (str);
565 if (end && end->type() != Marker::SessionEnd) {
571 Editor::LocationMarkers::set_position (framepos_t startf,
574 start->set_position (startf);
576 end->set_position (endf);
581 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
583 start->set_color_rgba (rgba);
585 end->set_color_rgba (rgba);
590 Editor::LocationMarkers::set_show_lines (bool s)
592 start->set_show_line (s);
594 end->set_show_line (s);
599 Editor::LocationMarkers::set_selected (bool s)
601 start->set_selected (s);
603 end->set_selected (s);
608 Editor::LocationMarkers::setup_lines ()
610 start->setup_line ();
617 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
619 string markername, markerprefix;
620 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
623 markerprefix = "xrun";
624 flags = Location::IsMark;
626 markerprefix = "mark";
630 _session->locations()->next_available_name(markername, markerprefix);
631 if (!is_xrun && !choose_new_marker_name(markername)) {
634 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
635 _session->begin_reversible_command (_("add marker"));
636 XMLNode &before = _session->locations()->get_state();
637 _session->locations()->add (location, true);
638 XMLNode &after = _session->locations()->get_state();
639 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
640 _session->commit_reversible_command ();
642 /* find the marker we just added */
644 LocationMarkers *lam = find_location_markers (location);
646 /* make it the selected marker */
647 selection->set (lam->start);
653 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
658 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
659 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
663 if (entered_marker == marker) {
664 entered_marker = NULL;
667 Location* loc = find_location_from_marker (marker, is_start);
669 if (_session && loc) {
670 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
675 Editor::really_remove_marker (Location* loc)
677 _session->begin_reversible_command (_("remove marker"));
678 XMLNode &before = _session->locations()->get_state();
679 _session->locations()->remove (loc);
680 XMLNode &after = _session->locations()->get_state();
681 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
682 _session->commit_reversible_command ();
687 Editor::location_gone (Location *location)
689 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
691 LocationMarkerMap::iterator i;
693 if (location == transport_loop_location()) {
694 update_loop_range_view (true);
697 if (location == transport_punch_location()) {
698 update_punch_range_view (true);
701 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
702 if ((*i).first == location) {
704 location_markers.erase (i);
711 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
713 marker_menu_item = item;
717 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
719 bool can_remove = false;
722 can_remove = mm->meter().movable ();
724 can_remove = tm->tempo().movable ();
729 delete tempo_or_meter_marker_menu;
730 build_tempo_or_meter_marker_menu (can_remove);
731 tempo_or_meter_marker_menu->popup (1, ev->time);
735 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
738 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
739 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
744 Location * loc = find_location_from_marker (marker, is_start);
745 if (loc == transport_loop_location() || loc == transport_punch_location()) {
746 if (transport_marker_menu == 0) {
747 build_range_marker_menu (true);
749 marker_menu_item = item;
750 transport_marker_menu->popup (1, ev->time);
753 if (loc->is_mark()) {
755 if (loc->is_session_range ()) {
756 delete session_range_marker_menu;
757 build_marker_menu (true, loc);
758 markerMenu = session_range_marker_menu;
761 build_marker_menu (false, loc);
762 markerMenu = marker_menu;
766 // GTK2FIX use action group sensitivity
768 if (children.size() >= 3) {
769 MenuItem * loopitem = &children[2];
771 if (loc->is_mark()) {
772 loopitem->set_sensitive(false);
775 loopitem->set_sensitive(true);
780 marker_menu_item = item;
781 markerMenu->popup (1, ev->time);
784 if (loc->is_range_marker()) {
785 if (range_marker_menu == 0){
786 build_range_marker_menu (false);
788 marker_menu_item = item;
789 range_marker_menu->popup (1, ev->time);
795 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
797 if (new_transport_marker_menu == 0) {
798 build_new_transport_marker_menu ();
801 new_transport_marker_menu->popup (1, ev->time);
806 Editor::transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
808 if (transport_marker_menu == 0) {
809 build_range_marker_menu (true);
812 transport_marker_menu->popup (1, ev->time);
816 Editor::build_marker_menu (bool session_range, Location* loc)
818 using namespace Menu_Helpers;
820 Menu *markerMenu = new Menu;
822 session_range_marker_menu = markerMenu;
824 marker_menu = markerMenu;
826 MenuList& items = markerMenu->items();
827 markerMenu->set_name ("ArdourContextMenu");
829 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
830 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
831 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
833 items.push_back (SeparatorElem());
835 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
837 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
841 items.push_back (MenuElem (_("Rename"), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
843 items.push_back (CheckMenuElem (_("Lock")));
844 CheckMenuItem* lock_item = static_cast<CheckMenuItem*> (&items.back());
845 if (loc->locked ()) {
846 lock_item->set_active ();
848 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
850 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
851 CheckMenuItem* glue_item = static_cast<CheckMenuItem*> (&items.back());
852 if (loc->position_lock_style() == MusicTime) {
853 glue_item->set_active ();
855 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
857 items.push_back (SeparatorElem());
859 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
863 Editor::build_range_marker_menu (bool loop_or_punch)
865 using namespace Menu_Helpers;
867 Menu *markerMenu = new Menu;
869 transport_marker_menu = markerMenu;
871 range_marker_menu = markerMenu;
873 MenuList& items = markerMenu->items();
874 markerMenu->set_name ("ArdourContextMenu");
876 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
877 items.push_back (MenuElem (_("Locate to Range Mark"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
878 items.push_back (MenuElem (_("Play from Range Mark"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
879 if (! loop_or_punch) {
880 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
882 items.push_back (MenuElem (_("Set Range Mark from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
883 if (!Profile->get_sae()) {
884 items.push_back (MenuElem (_("Set Range from Range Selection"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection)));
887 items.push_back (SeparatorElem());
888 items.push_back (MenuElem (_("Export Range"), sigc::mem_fun(*this, &Editor::export_range)));
889 items.push_back (SeparatorElem());
891 if (!loop_or_punch) {
892 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
893 items.push_back (MenuElem (_("Rename Range"), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
894 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
895 items.push_back (SeparatorElem());
898 items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
899 items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
900 if (!Profile->get_sae()) {
901 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
906 Editor::build_tempo_or_meter_marker_menu (bool can_remove)
908 using namespace Menu_Helpers;
910 tempo_or_meter_marker_menu = new Menu;
911 MenuList& items = tempo_or_meter_marker_menu->items();
912 tempo_or_meter_marker_menu->set_name ("ArdourContextMenu");
914 items.push_back (MenuElem (_("Edit"), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
915 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
917 items.back().set_sensitive (can_remove);
921 Editor::build_new_transport_marker_menu ()
923 using namespace Menu_Helpers;
925 new_transport_marker_menu = new Menu;
926 MenuList& items = new_transport_marker_menu->items();
927 new_transport_marker_menu->set_name ("ArdourContextMenu");
929 items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
930 items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
932 new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
936 Editor::marker_menu_hide ()
940 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
941 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
948 if ((l = find_location_from_marker (marker, is_start)) != 0) {
949 l->set_hidden (true, this);
954 Editor::marker_menu_select_using_range ()
958 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
959 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
966 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
967 set_selection_from_range (*l);
972 Editor::marker_menu_select_all_selectables_using_range ()
976 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
977 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
984 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
985 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, track_views, Selection::Set, false);
991 Editor::marker_menu_separate_regions_using_location ()
995 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
996 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1003 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1004 separate_regions_using_location (*l);
1010 Editor::marker_menu_play_from ()
1014 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1015 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1022 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1025 _session->request_locate (l->start(), true);
1028 //_session->request_bounded_roll (l->start(), l->end());
1031 _session->request_locate (l->start(), true);
1033 _session->request_locate (l->end(), true);
1040 Editor::marker_menu_set_playhead ()
1044 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1045 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1052 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1055 _session->request_locate (l->start(), false);
1059 _session->request_locate (l->start(), false);
1061 _session->request_locate (l->end(), false);
1068 Editor::marker_menu_range_to_next ()
1075 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1076 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1083 if ((l = find_location_from_marker (marker, is_start)) == 0) {
1089 _session->locations()->marks_either_side (marker->position(), start, end);
1091 if (end != max_framepos) {
1092 string range_name = l->name();
1093 range_name += "-range";
1095 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1096 _session->locations()->add (newrange);
1101 Editor::marker_menu_set_from_playhead ()
1105 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1106 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1113 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1116 l->set_start (_session->audible_frame ());
1120 l->set_start (_session->audible_frame ());
1122 l->set_end (_session->audible_frame ());
1129 Editor::marker_menu_set_from_selection ()
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) {
1148 /* if range selection use first to last */
1150 if (mouse_mode == Editing::MouseRange) {
1151 if (!selection->time.empty()) {
1152 l->set_start (selection->time.start());
1153 l->set_end (selection->time.end_frame());
1157 if (!selection->regions.empty()) {
1158 l->set_start (selection->regions.start());
1159 l->set_end (selection->regions.end_frame());
1168 Editor::marker_menu_play_range ()
1172 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1173 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1180 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1183 _session->request_locate (l->start(), true);
1186 _session->request_bounded_roll (l->start(), l->end());
1193 Editor::marker_menu_loop_range ()
1197 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1198 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1205 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1207 if ((l2 = transport_loop_location()) != 0) {
1208 l2->set (l->start(), l->end());
1210 // enable looping, reposition and start rolling
1211 _session->request_play_loop(true);
1212 _session->request_locate (l2->start(), true);
1218 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1220 Marker* marker = reinterpret_cast<Marker*> (p);
1222 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1226 *m = dynamic_cast<MeterMarker*> (marker);
1227 *t = dynamic_cast<TempoMarker*> (marker);
1231 Editor::marker_menu_edit ()
1235 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1238 edit_meter_section (&mm->meter());
1240 edit_tempo_section (&tm->tempo());
1245 Editor::marker_menu_remove ()
1249 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1252 remove_meter_marker (marker_menu_item);
1254 remove_tempo_marker (marker_menu_item);
1256 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1261 Editor::toggle_marker_menu_lock ()
1265 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1266 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1273 loc = find_location_from_marker (marker, ignored);
1279 if (loc->locked()) {
1287 Editor::marker_menu_rename ()
1291 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1292 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1299 loc = find_location_from_marker (marker, is_start);
1303 ArdourPrompter dialog (true);
1306 dialog.set_prompt (_("New Name:"));
1308 if (loc->is_mark()) {
1309 dialog.set_title (_("Rename Mark"));
1311 dialog.set_title (_("Rename Range"));
1314 dialog.set_name ("MarkRenameWindow");
1315 dialog.set_size_request (250, -1);
1316 dialog.set_position (Gtk::WIN_POS_MOUSE);
1318 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1319 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1320 dialog.set_initial_text (loc->name());
1324 switch (dialog.run ()) {
1325 case RESPONSE_ACCEPT:
1331 begin_reversible_command ( _("rename marker") );
1332 XMLNode &before = _session->locations()->get_state();
1334 dialog.get_result(txt);
1335 loc->set_name (txt);
1337 XMLNode &after = _session->locations()->get_state();
1338 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1339 commit_reversible_command ();
1343 Editor::new_transport_marker_menu_popdown ()
1346 transport_bar_drag_rect->hide();
1352 Editor::new_transport_marker_menu_set_loop ()
1354 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1358 Editor::new_transport_marker_menu_set_punch ()
1360 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1364 Editor::update_loop_range_view (bool visibility)
1366 if (_session == 0) {
1372 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1374 double x1 = frame_to_pixel (tll->start());
1375 double x2 = frame_to_pixel (tll->end());
1377 transport_loop_range_rect->property_x1() = x1;
1378 transport_loop_range_rect->property_x2() = x2;
1381 transport_loop_range_rect->show();
1384 } else if (visibility) {
1385 transport_loop_range_rect->hide();
1390 Editor::update_punch_range_view (bool visibility)
1392 if (_session == 0) {
1398 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1399 guint track_canvas_width,track_canvas_height;
1400 track_canvas->get_size(track_canvas_width,track_canvas_height);
1401 if (_session->config.get_punch_in()) {
1402 transport_punch_range_rect->property_x1() = frame_to_pixel (tpl->start());
1403 transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : frame_to_pixel (JACK_MAX_FRAMES));
1405 transport_punch_range_rect->property_x1() = 0;
1406 transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : track_canvas_width);
1410 transport_punch_range_rect->show();
1412 } else if (visibility) {
1413 transport_punch_range_rect->hide();
1418 Editor::marker_selection_changed ()
1420 if (_session && _session->deletion_in_progress()) {
1424 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1425 i->second->set_selected (false);
1428 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1429 (*x)->set_selected (true);
1433 struct SortLocationsByPosition {
1434 bool operator() (Location* a, Location* b) {
1435 return a->start() < b->start();
1440 Editor::goto_nth_marker (int n)
1445 const Locations::LocationList& l (_session->locations()->list());
1446 Locations::LocationList ordered;
1449 SortLocationsByPosition cmp;
1452 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1453 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1455 _session->request_locate ((*i)->start(), _session->transport_rolling());
1464 Editor::toggle_marker_menu_glue ()
1468 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1469 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1476 loc = find_location_from_marker (marker, ignored);
1482 if (loc->position_lock_style() == MusicTime) {
1483 loc->set_position_lock_style (AudioTime);
1485 loc->set_position_lock_style (MusicTime);
1491 Editor::toggle_marker_lines ()
1493 _show_marker_lines = !_show_marker_lines;
1495 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1496 i->second->set_show_lines (_show_marker_lines);