2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <sigc++/retype.h>
24 #include <libgnomecanvas/libgnomecanvas.h>
25 #include <gtkmm2ext/gtk_ui.h>
27 #include "ardour/session.h"
28 #include "ardour/location.h"
29 #include "ardour/profile.h"
30 #include "pbd/memento_command.h"
34 #include "selection.h"
36 #include "gui_thread.h"
37 #include "simplerect.h"
40 #include "editor_drag.h"
45 using namespace ARDOUR;
48 using namespace Gtkmm2ext;
51 Editor::clear_marker_display ()
53 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
57 location_markers.clear ();
58 _sorted_marker_lists.clear ();
62 Editor::add_new_location (Location *location)
64 ENSURE_GUI_THREAD (*this, &Editor::add_new_location, location)
66 LocationMarkers *lam = new LocationMarkers;
69 /* make a note here of which group this marker ends up in */
70 ArdourCanvas::Group* group = 0;
72 if (location->is_cd_marker()) {
73 color = location_cd_marker_color;
74 } else if (location->is_mark()) {
75 color = location_marker_color;
76 } else if (location->is_auto_loop()) {
77 color = location_loop_color;
78 } else if (location->is_auto_punch()) {
79 color = location_punch_color;
81 color = location_range_color;
84 if (location->is_mark()) {
86 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
87 lam->start = new Marker (*this, *cd_marker_group, *cursor_group, color, location->name(), Marker::Mark, location->start());
88 group = cd_marker_group;
90 lam->start = new Marker (*this, *marker_group, *cursor_group, color, location->name(), Marker::Mark, location->start());
96 } else if (location->is_auto_loop()) {
99 lam->start = new Marker (*this, *transport_marker_group, *cursor_group, color,
100 location->name(), Marker::LoopStart, location->start());
101 lam->end = new Marker (*this, *transport_marker_group, *cursor_group, color,
102 location->name(), Marker::LoopEnd, location->end());
103 group = transport_marker_group;
105 } else if (location->is_auto_punch()) {
108 lam->start = new Marker (*this, *transport_marker_group, *cursor_group, color,
109 location->name(), Marker::PunchIn, location->start());
110 lam->end = new Marker (*this, *transport_marker_group, *cursor_group, color,
111 location->name(), Marker::PunchOut, location->end());
112 group = transport_marker_group;
114 } else if (location->is_session_range()) {
117 lam->start = new Marker (*this, *marker_group, *cursor_group, color, _("start"), Marker::SessionStart, location->start());
118 lam->end = new Marker (*this, *marker_group, *cursor_group, color, _("end"), Marker::SessionEnd, location->end());
119 group = marker_group;
123 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
124 lam->start = new Marker (*this, *cd_marker_group, *cursor_group, color,
125 location->name(), Marker::RangeStart, location->start());
126 lam->end = new Marker (*this, *cd_marker_group, *cursor_group, color,
127 location->name(), Marker::RangeEnd, location->end());
128 group = cd_marker_group;
130 lam->start = new Marker (*this, *range_marker_group, *cursor_group, color,
131 location->name(), Marker::RangeStart, location->start());
132 lam->end = new Marker (*this, *range_marker_group, *cursor_group, color,
133 location->name(), Marker::RangeEnd, location->end());
134 group = range_marker_group;
138 if (location->is_hidden ()) {
144 location->start_changed.connect (*this, invalidator (*this), ui_bind (&Editor::location_changed, this, _1), gui_context());
145 location->end_changed.connect (*this, invalidator (*this), ui_bind (&Editor::location_changed, this, _1), gui_context());
146 location->changed.connect (*this, invalidator (*this), ui_bind (&Editor::location_changed, this, _1), gui_context());
147 location->name_changed.connect (*this, invalidator (*this), ui_bind (&Editor::location_changed, this, _1), gui_context());
148 location->FlagsChanged.connect (*this, invalidator (*this), ui_bind (&Editor::location_flags_changed, this, _1, _2), gui_context());
150 pair<Location*,LocationMarkers*> newpair;
152 newpair.first = location;
153 newpair.second = lam;
155 location_markers.insert (newpair);
157 if (select_new_marker && location->is_mark()) {
158 selection->set (lam->start);
159 select_new_marker = false;
162 lam->canvas_height_set (_canvas_height);
163 lam->set_show_lines (_show_marker_lines);
165 /* Add these markers to the appropriate sorted marker lists, which will render
166 them unsorted until the update_marker_labels() below sorts them out.
168 _sorted_marker_lists[group].push_back (lam->start);
170 _sorted_marker_lists[group].push_back (lam->end);
173 /* Do a full update of the markers in this group */
174 update_marker_labels (group);
178 Editor::location_changed (Location *location)
180 ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
182 LocationMarkers *lam = find_location_markers (location);
185 /* a location that isn't "marked" with markers */
189 lam->set_name (location->name ());
190 lam->set_position (location->start(), location->end());
192 if (location->is_auto_loop()) {
193 update_loop_range_view ();
194 } else if (location->is_auto_punch()) {
195 update_punch_range_view ();
198 check_marker_label (lam->start);
200 check_marker_label (lam->end);
204 /** Look at a marker and check whether its label, and those of the previous and next markers,
205 * need to have their labels updated (in case those labels need to be shortened or can be
209 Editor::check_marker_label (Marker* m)
211 /* Get a time-ordered list of markers from the last time anything changed */
212 std::list<Marker*>& sorted = _sorted_marker_lists[m->get_parent()];
214 list<Marker*>::iterator i = find (sorted.begin(), sorted.end(), m);
216 list<Marker*>::iterator prev = sorted.end ();
217 list<Marker*>::iterator next = i;
220 /* Look to see if the previous marker is still behind `m' in time */
221 if (i != sorted.begin()) {
226 if ((*prev)->position() > m->position()) {
227 /* This marker is no longer in the correct order with the previous one, so
228 * update all the markers in this group.
230 update_marker_labels (m->get_parent ());
235 /* Look to see if the next marker is still ahead of `m' in time */
236 if (next != sorted.end() && (*next)->position() < m->position()) {
237 /* This marker is no longer in the correct order with the next one, so
238 * update all the markers in this group.
240 update_marker_labels (m->get_parent ());
244 if (prev != sorted.end()) {
246 /* Update just the available space between the previous marker and this one */
248 double const p = frame_to_pixel (m->position() - (*prev)->position());
250 if (m->label_on_left()) {
251 (*prev)->set_right_label_limit (p / 2);
253 (*prev)->set_right_label_limit (p);
256 if ((*prev)->label_on_left ()) {
257 m->set_left_label_limit (p);
259 m->set_left_label_limit (p / 2);
263 if (next != sorted.end()) {
265 /* Update just the available space between this marker and the next */
267 double const p = frame_to_pixel ((*next)->position() - m->position());
269 if ((*next)->label_on_left()) {
270 m->set_right_label_limit (p / 2);
272 m->set_right_label_limit (p);
275 if (m->label_on_left()) {
276 (*next)->set_left_label_limit (p);
278 (*next)->set_left_label_limit (p / 2);
283 struct MarkerComparator {
284 bool operator() (Marker const * a, Marker const * b) {
285 return a->position() < b->position();
289 /** Update all marker labels in all groups */
291 Editor::update_marker_labels ()
293 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
294 update_marker_labels (i->first);
298 /** Look at all markers in a group and update label widths */
300 Editor::update_marker_labels (ArdourCanvas::Group* group)
302 list<Marker*>& sorted = _sorted_marker_lists[group];
304 if (sorted.empty()) {
308 /* We sort the list of markers and then set up the space available between each one */
310 sorted.sort (MarkerComparator ());
312 list<Marker*>::iterator i = sorted.begin ();
314 list<Marker*>::iterator prev = sorted.end ();
315 list<Marker*>::iterator next = i;
318 while (i != sorted.end()) {
320 if (prev != sorted.end()) {
321 double const p = frame_to_pixel ((*i)->position() - (*prev)->position());
323 if ((*prev)->label_on_left()) {
324 (*i)->set_left_label_limit (p);
326 (*i)->set_left_label_limit (p / 2);
331 if (next != sorted.end()) {
332 double const p = frame_to_pixel ((*next)->position() - (*i)->position());
334 if ((*next)->label_on_left()) {
335 (*i)->set_right_label_limit (p / 2);
337 (*i)->set_right_label_limit (p);
348 Editor::location_flags_changed (Location *location, void*)
350 ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
352 LocationMarkers *lam = find_location_markers (location);
355 /* a location that isn't "marked" with markers */
359 // move cd markers to/from cd marker bar as appropriate
360 ensure_cd_marker_updated (lam, location);
362 if (location->is_cd_marker()) {
363 lam->set_color_rgba (location_cd_marker_color);
364 } else if (location->is_mark()) {
365 lam->set_color_rgba (location_marker_color);
366 } else if (location->is_auto_punch()) {
367 lam->set_color_rgba (location_punch_color);
368 } else if (location->is_auto_loop()) {
369 lam->set_color_rgba (location_loop_color);
371 lam->set_color_rgba (location_range_color);
374 if (location->is_hidden()) {
381 void Editor::update_cd_marker_display ()
383 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
384 LocationMarkers * lam = i->second;
385 Location * location = i->first;
387 ensure_cd_marker_updated (lam, location);
391 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
393 if (location->is_cd_marker()
394 && (ruler_cd_marker_action->get_active() && lam->start->get_parent() != cd_marker_group))
396 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
398 lam->start->reparent (*cd_marker_group);
401 lam->end->reparent (*cd_marker_group);
404 else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
405 && (lam->start->get_parent() == cd_marker_group))
407 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
408 if (location->is_mark()) {
410 lam->start->reparent (*marker_group);
413 lam->end->reparent (*marker_group);
418 lam->start->reparent (*range_marker_group);
421 lam->end->reparent (*range_marker_group);
427 Editor::LocationMarkers::~LocationMarkers ()
433 Editor::LocationMarkers *
434 Editor::find_location_markers (Location *location) const
436 LocationMarkerMap::const_iterator i;
438 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
439 if ((*i).first == location) {
448 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
450 LocationMarkerMap::const_iterator i;
452 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
453 LocationMarkers *lm = (*i).second;
454 if (lm->start == marker) {
457 } else if (lm->end == marker) {
467 Editor::refresh_location_display_internal (Locations::LocationList& locations)
471 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
472 i->second->valid = false;
477 for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
479 LocationMarkerMap::iterator x;
481 if ((x = location_markers.find (*i)) != location_markers.end()) {
482 x->second->valid = true;
486 add_new_location (*i);
489 /* remove dead ones */
491 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
493 LocationMarkerMap::iterator tmp;
498 if (!i->second->valid) {
500 remove_sorted_marker (i->second->start);
501 if (i->second->end) {
502 remove_sorted_marker (i->second->end);
506 location_markers.erase (i);
512 update_punch_range_view (false);
513 update_loop_range_view (false);
517 Editor::refresh_location_display ()
519 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
522 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
527 Editor::refresh_location_display_s (const PropertyChange&)
529 ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display_s, ignored)
532 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
537 Editor::LocationMarkers::hide()
546 Editor::LocationMarkers::show()
555 Editor::LocationMarkers::canvas_height_set (double h)
557 start->canvas_height_set (h);
559 end->canvas_height_set (h);
564 Editor::LocationMarkers::set_name (const string& str)
566 /* XXX: hack: don't change names of session start/end markers */
568 if (start->type() != Marker::SessionStart) {
569 start->set_name (str);
572 if (end && end->type() != Marker::SessionEnd) {
578 Editor::LocationMarkers::set_position (framepos_t startf,
581 start->set_position (startf);
583 end->set_position (endf);
588 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
590 start->set_color_rgba (rgba);
592 end->set_color_rgba (rgba);
597 Editor::LocationMarkers::set_show_lines (bool s)
599 start->set_show_line (s);
601 end->set_show_line (s);
606 Editor::LocationMarkers::set_selected (bool s)
608 start->set_selected (s);
610 end->set_selected (s);
615 Editor::LocationMarkers::setup_lines ()
617 start->setup_line ();
624 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
626 string markername, markerprefix;
627 int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
630 markerprefix = "xrun";
631 flags = Location::IsMark;
633 markerprefix = "mark";
637 _session->locations()->next_available_name(markername, markerprefix);
638 if (!is_xrun && !choose_new_marker_name(markername)) {
641 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
642 _session->begin_reversible_command (_("add marker"));
643 XMLNode &before = _session->locations()->get_state();
644 _session->locations()->add (location, true);
645 XMLNode &after = _session->locations()->get_state();
646 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
647 _session->commit_reversible_command ();
649 /* find the marker we just added */
651 LocationMarkers *lam = find_location_markers (location);
653 /* make it the selected marker */
654 selection->set (lam->start);
660 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
665 if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
666 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
670 if (entered_marker == marker) {
671 entered_marker = NULL;
674 Location* loc = find_location_from_marker (marker, is_start);
676 if (_session && loc) {
677 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
682 Editor::really_remove_marker (Location* loc)
684 _session->begin_reversible_command (_("remove marker"));
685 XMLNode &before = _session->locations()->get_state();
686 _session->locations()->remove (loc);
687 XMLNode &after = _session->locations()->get_state();
688 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
689 _session->commit_reversible_command ();
694 Editor::location_gone (Location *location)
696 ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
698 LocationMarkerMap::iterator i;
700 if (location == transport_loop_location()) {
701 update_loop_range_view (true);
704 if (location == transport_punch_location()) {
705 update_punch_range_view (true);
708 for (i = location_markers.begin(); i != location_markers.end(); ++i) {
709 if (i->first == location) {
711 remove_sorted_marker (i->second->start);
712 if (i->second->end) {
713 remove_sorted_marker (i->second->end);
718 location_markers.erase (i);
725 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
727 marker_menu_item = item;
731 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
733 bool can_remove = false;
736 can_remove = mm->meter().movable ();
738 can_remove = tm->tempo().movable ();
743 delete tempo_or_meter_marker_menu;
744 build_tempo_or_meter_marker_menu (can_remove);
745 tempo_or_meter_marker_menu->popup (1, ev->time);
749 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
752 if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
753 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
758 Location * loc = find_location_from_marker (marker, is_start);
759 if (loc == transport_loop_location() || loc == transport_punch_location()) {
760 if (transport_marker_menu == 0) {
761 build_range_marker_menu (true);
763 marker_menu_item = item;
764 transport_marker_menu->popup (1, ev->time);
767 if (loc->is_mark()) {
769 if (loc->is_session_range ()) {
770 delete session_range_marker_menu;
771 build_marker_menu (true, loc);
772 markerMenu = session_range_marker_menu;
775 build_marker_menu (false, loc);
776 markerMenu = marker_menu;
780 // GTK2FIX use action group sensitivity
782 if (children.size() >= 3) {
783 MenuItem * loopitem = &children[2];
785 if (loc->is_mark()) {
786 loopitem->set_sensitive(false);
789 loopitem->set_sensitive(true);
794 marker_menu_item = item;
795 markerMenu->popup (1, ev->time);
798 if (loc->is_range_marker()) {
799 if (range_marker_menu == 0){
800 build_range_marker_menu (false);
802 marker_menu_item = item;
803 range_marker_menu->popup (1, ev->time);
809 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
811 if (new_transport_marker_menu == 0) {
812 build_new_transport_marker_menu ();
815 new_transport_marker_menu->popup (1, ev->time);
820 Editor::transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
822 if (transport_marker_menu == 0) {
823 build_range_marker_menu (true);
826 transport_marker_menu->popup (1, ev->time);
830 Editor::build_marker_menu (bool session_range, Location* loc)
832 using namespace Menu_Helpers;
834 Menu *markerMenu = new Menu;
836 session_range_marker_menu = markerMenu;
838 marker_menu = markerMenu;
840 MenuList& items = markerMenu->items();
841 markerMenu->set_name ("ArdourContextMenu");
843 items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
844 items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
845 items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
847 items.push_back (SeparatorElem());
849 items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
851 items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
855 items.push_back (MenuElem (_("Rename"), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
857 items.push_back (CheckMenuElem (_("Lock")));
858 CheckMenuItem* lock_item = static_cast<CheckMenuItem*> (&items.back());
859 if (loc->locked ()) {
860 lock_item->set_active ();
862 lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
864 items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
865 CheckMenuItem* glue_item = static_cast<CheckMenuItem*> (&items.back());
866 if (loc->position_lock_style() == MusicTime) {
867 glue_item->set_active ();
869 glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
871 items.push_back (SeparatorElem());
873 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
877 Editor::build_range_marker_menu (bool loop_or_punch)
879 using namespace Menu_Helpers;
881 Menu *markerMenu = new Menu;
883 transport_marker_menu = markerMenu;
885 range_marker_menu = markerMenu;
887 MenuList& items = markerMenu->items();
888 markerMenu->set_name ("ArdourContextMenu");
890 items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
891 items.push_back (MenuElem (_("Locate to Range Mark"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
892 items.push_back (MenuElem (_("Play from Range Mark"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
893 if (! loop_or_punch) {
894 items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
896 items.push_back (MenuElem (_("Set Range Mark from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
897 if (!Profile->get_sae()) {
898 items.push_back (MenuElem (_("Set Range from Range Selection"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection)));
901 items.push_back (SeparatorElem());
902 items.push_back (MenuElem (_("Export Range"), sigc::mem_fun(*this, &Editor::export_range)));
903 items.push_back (SeparatorElem());
905 if (!loop_or_punch) {
906 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
907 items.push_back (MenuElem (_("Rename Range"), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
908 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
909 items.push_back (SeparatorElem());
912 items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
913 items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
914 if (!Profile->get_sae()) {
915 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
920 Editor::build_tempo_or_meter_marker_menu (bool can_remove)
922 using namespace Menu_Helpers;
924 tempo_or_meter_marker_menu = new Menu;
925 MenuList& items = tempo_or_meter_marker_menu->items();
926 tempo_or_meter_marker_menu->set_name ("ArdourContextMenu");
928 items.push_back (MenuElem (_("Edit"), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
929 items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
931 items.back().set_sensitive (can_remove);
935 Editor::build_new_transport_marker_menu ()
937 using namespace Menu_Helpers;
939 new_transport_marker_menu = new Menu;
940 MenuList& items = new_transport_marker_menu->items();
941 new_transport_marker_menu->set_name ("ArdourContextMenu");
943 items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
944 items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
946 new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
950 Editor::marker_menu_hide ()
954 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
955 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
962 if ((l = find_location_from_marker (marker, is_start)) != 0) {
963 l->set_hidden (true, this);
968 Editor::marker_menu_select_using_range ()
972 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
973 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
980 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
981 set_selection_from_range (*l);
986 Editor::marker_menu_select_all_selectables_using_range ()
990 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
991 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
998 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
999 select_all_within (l->start(), l->end() - 1, 0, DBL_MAX, track_views, Selection::Set, false);
1005 Editor::marker_menu_separate_regions_using_location ()
1009 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1010 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1017 if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1018 separate_regions_using_location (*l);
1024 Editor::marker_menu_play_from ()
1028 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1029 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1036 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1039 _session->request_locate (l->start(), true);
1042 //_session->request_bounded_roll (l->start(), l->end());
1045 _session->request_locate (l->start(), true);
1047 _session->request_locate (l->end(), true);
1054 Editor::marker_menu_set_playhead ()
1058 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1059 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1066 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1069 _session->request_locate (l->start(), false);
1073 _session->request_locate (l->start(), false);
1075 _session->request_locate (l->end(), false);
1082 Editor::marker_menu_range_to_next ()
1089 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1090 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1097 if ((l = find_location_from_marker (marker, is_start)) == 0) {
1103 _session->locations()->marks_either_side (marker->position(), start, end);
1105 if (end != max_framepos) {
1106 string range_name = l->name();
1107 range_name += "-range";
1109 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1110 _session->locations()->add (newrange);
1115 Editor::marker_menu_set_from_playhead ()
1119 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1120 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1127 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1130 l->set_start (_session->audible_frame ());
1134 l->set_start (_session->audible_frame ());
1136 l->set_end (_session->audible_frame ());
1143 Editor::marker_menu_set_from_selection ()
1147 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1148 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1155 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1162 /* if range selection use first to last */
1164 if (mouse_mode == Editing::MouseRange) {
1165 if (!selection->time.empty()) {
1166 l->set_start (selection->time.start());
1167 l->set_end (selection->time.end_frame());
1171 if (!selection->regions.empty()) {
1172 l->set_start (selection->regions.start());
1173 l->set_end (selection->regions.end_frame());
1182 Editor::marker_menu_play_range ()
1186 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1187 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1194 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1197 _session->request_locate (l->start(), true);
1200 _session->request_bounded_roll (l->start(), l->end());
1207 Editor::marker_menu_loop_range ()
1211 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1212 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1219 if ((l = find_location_from_marker (marker, is_start)) != 0) {
1221 if ((l2 = transport_loop_location()) != 0) {
1222 l2->set (l->start(), l->end());
1224 // enable looping, reposition and start rolling
1225 _session->request_play_loop(true);
1226 _session->request_locate (l2->start(), true);
1232 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1234 Marker* marker = reinterpret_cast<Marker*> (p);
1236 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1240 *m = dynamic_cast<MeterMarker*> (marker);
1241 *t = dynamic_cast<TempoMarker*> (marker);
1245 Editor::marker_menu_edit ()
1249 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1252 edit_meter_section (&mm->meter());
1254 edit_tempo_section (&tm->tempo());
1259 Editor::marker_menu_remove ()
1263 dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1266 remove_meter_marker (marker_menu_item);
1268 remove_tempo_marker (marker_menu_item);
1270 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1275 Editor::toggle_marker_menu_lock ()
1279 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1280 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1287 loc = find_location_from_marker (marker, ignored);
1293 if (loc->locked()) {
1301 Editor::marker_menu_rename ()
1305 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1306 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1313 loc = find_location_from_marker (marker, is_start);
1317 ArdourPrompter dialog (true);
1320 dialog.set_prompt (_("New Name:"));
1322 if (loc->is_mark()) {
1323 dialog.set_title (_("Rename Mark"));
1325 dialog.set_title (_("Rename Range"));
1328 dialog.set_name ("MarkRenameWindow");
1329 dialog.set_size_request (250, -1);
1330 dialog.set_position (Gtk::WIN_POS_MOUSE);
1332 dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1333 dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1334 dialog.set_initial_text (loc->name());
1338 switch (dialog.run ()) {
1339 case RESPONSE_ACCEPT:
1345 begin_reversible_command ( _("rename marker") );
1346 XMLNode &before = _session->locations()->get_state();
1348 dialog.get_result(txt);
1349 loc->set_name (txt);
1351 XMLNode &after = _session->locations()->get_state();
1352 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1353 commit_reversible_command ();
1357 Editor::new_transport_marker_menu_popdown ()
1360 transport_bar_drag_rect->hide();
1366 Editor::new_transport_marker_menu_set_loop ()
1368 set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1372 Editor::new_transport_marker_menu_set_punch ()
1374 set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1378 Editor::update_loop_range_view (bool visibility)
1380 if (_session == 0) {
1386 if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1388 double x1 = frame_to_pixel (tll->start());
1389 double x2 = frame_to_pixel (tll->end());
1391 transport_loop_range_rect->property_x1() = x1;
1392 transport_loop_range_rect->property_x2() = x2;
1395 transport_loop_range_rect->show();
1398 } else if (visibility) {
1399 transport_loop_range_rect->hide();
1404 Editor::update_punch_range_view (bool visibility)
1406 if (_session == 0) {
1412 if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1413 guint track_canvas_width,track_canvas_height;
1414 track_canvas->get_size(track_canvas_width,track_canvas_height);
1415 if (_session->config.get_punch_in()) {
1416 transport_punch_range_rect->property_x1() = frame_to_pixel (tpl->start());
1417 transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : frame_to_pixel (JACK_MAX_FRAMES));
1419 transport_punch_range_rect->property_x1() = 0;
1420 transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : track_canvas_width);
1424 transport_punch_range_rect->show();
1426 } else if (visibility) {
1427 transport_punch_range_rect->hide();
1432 Editor::marker_selection_changed ()
1434 if (_session && _session->deletion_in_progress()) {
1438 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1439 i->second->set_selected (false);
1442 for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1443 (*x)->set_selected (true);
1447 struct SortLocationsByPosition {
1448 bool operator() (Location* a, Location* b) {
1449 return a->start() < b->start();
1454 Editor::goto_nth_marker (int n)
1459 const Locations::LocationList& l (_session->locations()->list());
1460 Locations::LocationList ordered;
1463 SortLocationsByPosition cmp;
1466 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1467 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1469 _session->request_locate ((*i)->start(), _session->transport_rolling());
1478 Editor::toggle_marker_menu_glue ()
1482 if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1483 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1490 loc = find_location_from_marker (marker, ignored);
1496 if (loc->position_lock_style() == MusicTime) {
1497 loc->set_position_lock_style (AudioTime);
1499 loc->set_position_lock_style (MusicTime);
1505 Editor::toggle_marker_lines ()
1507 _show_marker_lines = !_show_marker_lines;
1509 for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1510 i->second->set_show_lines (_show_marker_lines);
1515 Editor::remove_sorted_marker (Marker* m)
1517 for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1518 i->second.remove (m);