replace unicode dash with (monospace) minus.
[ardour.git] / gtk2_ardour / editor_markers.cc
1 /*
2     Copyright (C) 2000 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <sigc++/retype.h>
21 #include <cstdlib>
22 #include <cmath>
23
24 #include <libgnomecanvas/libgnomecanvas.h>
25 #include <gtkmm2ext/gtk_ui.h>
26
27 #include "ardour/session.h"
28 #include "ardour/location.h"
29 #include "ardour/profile.h"
30 #include "pbd/memento_command.h"
31
32 #include "editor.h"
33 #include "marker.h"
34 #include "selection.h"
35 #include "editing.h"
36 #include "gui_thread.h"
37 #include "simplerect.h"
38 #include "actions.h"
39 #include "prompter.h"
40 #include "editor_drag.h"
41
42 #include "i18n.h"
43
44 using namespace std;
45 using namespace ARDOUR;
46 using namespace PBD;
47 using namespace Gtk;
48 using namespace Gtkmm2ext;
49
50 void
51 Editor::clear_marker_display ()
52 {
53         for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
54                 delete i->second;
55         }
56
57         location_markers.clear ();
58         _sorted_marker_lists.clear ();
59 }
60
61 void
62 Editor::add_new_location (Location *location)
63 {
64         ENSURE_GUI_THREAD (*this, &Editor::add_new_location, location);
65
66         ArdourCanvas::Group* group = add_new_location_internal (location);
67
68         /* Do a full update of the markers in this group */
69         update_marker_labels (group);
70 }
71
72 /** Add a new location, without a time-consuming update of all marker labels;
73  *  the caller must call update_marker_labels () after calling this.
74  *  @return canvas group that the location's marker was added to.
75  */
76 ArdourCanvas::Group*
77 Editor::add_new_location_internal (Location* location)
78 {
79         LocationMarkers *lam = new LocationMarkers;
80         uint32_t color;
81
82         /* make a note here of which group this marker ends up in */
83         ArdourCanvas::Group* group = 0;
84
85         if (location->is_cd_marker()) {
86                 color = location_cd_marker_color;
87         } else if (location->is_mark()) {
88                 color = location_marker_color;
89         } else if (location->is_auto_loop()) {
90                 color = location_loop_color;
91         } else if (location->is_auto_punch()) {
92                 color = location_punch_color;
93         } else {
94                 color = location_range_color;
95         }
96
97         if (location->is_mark()) {
98
99                 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
100                         lam->start = new Marker (*this, *cd_marker_group, color, location->name(), Marker::Mark, location->start());
101                         group = cd_marker_group;
102                 } else {
103                         lam->start = new Marker (*this, *marker_group, color, location->name(), Marker::Mark, location->start());
104                         group = marker_group;
105                 }
106
107                 lam->end = 0;
108
109         } else if (location->is_auto_loop()) {
110
111                 // transport marker
112                 lam->start = new Marker (*this, *transport_marker_group, color,
113                                          location->name(), Marker::LoopStart, location->start());
114                 lam->end   = new Marker (*this, *transport_marker_group, color,
115                                          location->name(), Marker::LoopEnd, location->end());
116                 group = transport_marker_group;
117
118         } else if (location->is_auto_punch()) {
119
120                 // transport marker
121                 lam->start = new Marker (*this, *transport_marker_group, color,
122                                          location->name(), Marker::PunchIn, location->start());
123                 lam->end   = new Marker (*this, *transport_marker_group, color,
124                                          location->name(), Marker::PunchOut, location->end());
125                 group = transport_marker_group;
126
127         } else if (location->is_session_range()) {
128
129                 // session range
130                 lam->start = new Marker (*this, *marker_group, color, _("start"), Marker::SessionStart, location->start());
131                 lam->end = new Marker (*this, *marker_group, color, _("end"), Marker::SessionEnd, location->end());
132                 group = marker_group;
133
134         } else {
135                 // range marker
136                 if (location->is_cd_marker() && ruler_cd_marker_action->get_active()) {
137                         lam->start = new Marker (*this, *cd_marker_group, color,
138                                                  location->name(), Marker::RangeStart, location->start());
139                         lam->end   = new Marker (*this, *cd_marker_group, color,
140                                                  location->name(), Marker::RangeEnd, location->end());
141                         group = cd_marker_group;
142                 } else {
143                         lam->start = new Marker (*this, *range_marker_group, color,
144                                                  location->name(), Marker::RangeStart, location->start());
145                         lam->end   = new Marker (*this, *range_marker_group, color,
146                                                  location->name(), Marker::RangeEnd, location->end());
147                         group = range_marker_group;
148                 }
149         }
150
151         if (location->is_hidden ()) {
152                 lam->hide();
153         } else {
154                 lam->show ();
155         }
156
157         location->start_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
158         location->end_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
159         location->changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
160         location->name_changed.connect (*this, invalidator (*this), boost::bind (&Editor::location_changed, this, _1), gui_context());
161         location->FlagsChanged.connect (*this, invalidator (*this), boost::bind (&Editor::location_flags_changed, this, _1, _2), gui_context());
162
163         pair<Location*,LocationMarkers*> newpair;
164
165         newpair.first = location;
166         newpair.second = lam;
167
168         location_markers.insert (newpair);
169
170         if (select_new_marker && location->is_mark()) {
171                 selection->set (lam->start);
172                 select_new_marker = false;
173         }
174
175         lam->canvas_height_set (_canvas_height);
176         lam->set_show_lines (_show_marker_lines);
177
178         /* Add these markers to the appropriate sorted marker lists, which will render
179            them unsorted until a call to update_marker_labels() sorts them out.
180         */
181         _sorted_marker_lists[group].push_back (lam->start);
182         if (lam->end) {
183                 _sorted_marker_lists[group].push_back (lam->end);
184         }
185
186         return group;
187 }
188
189 void
190 Editor::location_changed (Location *location)
191 {
192         ENSURE_GUI_THREAD (*this, &Editor::location_changed, location)
193
194         LocationMarkers *lam = find_location_markers (location);
195
196         if (lam == 0) {
197                 /* a location that isn't "marked" with markers */
198                 return;
199         }
200
201         lam->set_name (location->name ());
202         lam->set_position (location->start(), location->end());
203
204         if (location->is_auto_loop()) {
205                 update_loop_range_view ();
206         } else if (location->is_auto_punch()) {
207                 update_punch_range_view ();
208         }
209
210         check_marker_label (lam->start);
211         if (lam->end) {
212                 check_marker_label (lam->end);
213         }
214 }
215
216 /** Look at a marker and check whether its label, and those of the previous and next markers,
217  *  need to have their labels updated (in case those labels need to be shortened or can be
218  *  lengthened)
219  */
220 void
221 Editor::check_marker_label (Marker* m)
222 {
223         /* Get a time-ordered list of markers from the last time anything changed */
224         std::list<Marker*>& sorted = _sorted_marker_lists[m->get_parent()];
225
226         list<Marker*>::iterator i = find (sorted.begin(), sorted.end(), m);
227
228         list<Marker*>::iterator prev = sorted.end ();
229         list<Marker*>::iterator next = i;
230         ++next;
231
232         /* Look to see if the previous marker is still behind `m' in time */
233         if (i != sorted.begin()) {
234
235                 prev = i;
236                 --prev;
237
238                 if ((*prev)->position() > m->position()) {
239                         /* This marker is no longer in the correct order with the previous one, so
240                          * update all the markers in this group.
241                          */
242                         update_marker_labels (m->get_parent ());
243                         return;
244                 }
245         }
246
247         /* Look to see if the next marker is still ahead of `m' in time */
248         if (next != sorted.end() && (*next)->position() < m->position()) {
249                 /* This marker is no longer in the correct order with the next one, so
250                  * update all the markers in this group.
251                  */
252                 update_marker_labels (m->get_parent ());
253                 return;
254         }
255
256         if (prev != sorted.end()) {
257
258                 /* Update just the available space between the previous marker and this one */
259
260                 double const p = frame_to_pixel (m->position() - (*prev)->position());
261
262                 if (m->label_on_left()) {
263                         (*prev)->set_right_label_limit (p / 2);
264                 } else {
265                         (*prev)->set_right_label_limit (p);
266                 }
267
268                 if ((*prev)->label_on_left ()) {
269                         m->set_left_label_limit (p);
270                 } else {
271                         m->set_left_label_limit (p / 2);
272                 }
273         }
274
275         if (next != sorted.end()) {
276
277                 /* Update just the available space between this marker and the next */
278
279                 double const p = frame_to_pixel ((*next)->position() - m->position());
280
281                 if ((*next)->label_on_left()) {
282                         m->set_right_label_limit (p / 2);
283                 } else {
284                         m->set_right_label_limit (p);
285                 }
286
287                 if (m->label_on_left()) {
288                         (*next)->set_left_label_limit (p);
289                 } else {
290                         (*next)->set_left_label_limit (p / 2);
291                 }
292         }
293 }
294
295 struct MarkerComparator {
296         bool operator() (Marker const * a, Marker const * b) {
297                 return a->position() < b->position();
298         }
299 };
300
301 /** Update all marker labels in all groups */
302 void
303 Editor::update_marker_labels ()
304 {
305         for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
306                 update_marker_labels (i->first);
307         }
308 }
309
310 /** Look at all markers in a group and update label widths */
311 void
312 Editor::update_marker_labels (ArdourCanvas::Group* group)
313 {
314         list<Marker*>& sorted = _sorted_marker_lists[group];
315
316         if (sorted.empty()) {
317                 return;
318         }
319
320         /* We sort the list of markers and then set up the space available between each one */
321
322         sorted.sort (MarkerComparator ());
323
324         list<Marker*>::iterator i = sorted.begin ();
325
326         list<Marker*>::iterator prev = sorted.end ();
327         list<Marker*>::iterator next = i;
328         ++next;
329
330         while (i != sorted.end()) {
331
332                 if (prev != sorted.end()) {
333                         double const p = frame_to_pixel ((*i)->position() - (*prev)->position());
334
335                         if ((*prev)->label_on_left()) {
336                                 (*i)->set_left_label_limit (p);
337                         } else {
338                                 (*i)->set_left_label_limit (p / 2);
339                         }
340
341                 }
342
343                 if (next != sorted.end()) {
344                         double const p = frame_to_pixel ((*next)->position() - (*i)->position());
345
346                         if ((*next)->label_on_left()) {
347                                 (*i)->set_right_label_limit (p / 2);
348                         } else {
349                                 (*i)->set_right_label_limit (p);
350                         }
351                 }
352
353                 prev = i;
354                 ++i;
355                 ++next;
356         }
357 }
358
359 void
360 Editor::location_flags_changed (Location *location, void*)
361 {
362         ENSURE_GUI_THREAD (*this, &Editor::location_flags_changed, location, src)
363
364         LocationMarkers *lam = find_location_markers (location);
365
366         if (lam == 0) {
367                 /* a location that isn't "marked" with markers */
368                 return;
369         }
370
371         // move cd markers to/from cd marker bar as appropriate
372         ensure_cd_marker_updated (lam, location);
373
374         if (location->is_cd_marker()) {
375                 lam->set_color_rgba (location_cd_marker_color);
376         } else if (location->is_mark()) {
377                 lam->set_color_rgba (location_marker_color);
378         } else if (location->is_auto_punch()) {
379                 lam->set_color_rgba (location_punch_color);
380         } else if (location->is_auto_loop()) {
381                 lam->set_color_rgba (location_loop_color);
382         } else {
383                 lam->set_color_rgba (location_range_color);
384         }
385
386         if (location->is_hidden()) {
387                 lam->hide();
388         } else {
389                 lam->show ();
390         }
391 }
392
393 void Editor::update_cd_marker_display ()
394 {
395         for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
396                 LocationMarkers * lam = i->second;
397                 Location * location = i->first;
398
399                 ensure_cd_marker_updated (lam, location);
400         }
401 }
402
403 void Editor::ensure_cd_marker_updated (LocationMarkers * lam, Location * location)
404 {
405         if (location->is_cd_marker()
406             && (ruler_cd_marker_action->get_active() &&  lam->start->get_parent() != cd_marker_group))
407         {
408                 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
409                 if (lam->start) {
410                         lam->start->reparent (*cd_marker_group);
411                 }
412                 if (lam->end) {
413                         lam->end->reparent (*cd_marker_group);
414                 }
415         }
416         else if ( (!location->is_cd_marker() || !ruler_cd_marker_action->get_active())
417                   && (lam->start->get_parent() == cd_marker_group))
418         {
419                 //cerr << "reparenting non-cd marker so it can be relocated: " << location->name() << endl;
420                 if (location->is_mark()) {
421                         if (lam->start) {
422                                 lam->start->reparent (*marker_group);
423                         }
424                         if (lam->end) {
425                                 lam->end->reparent (*marker_group);
426                         }
427                 }
428                 else {
429                         if (lam->start) {
430                                 lam->start->reparent (*range_marker_group);
431                         }
432                         if (lam->end) {
433                                 lam->end->reparent (*range_marker_group);
434                         }
435                 }
436         }
437 }
438
439 Editor::LocationMarkers::~LocationMarkers ()
440 {
441         delete start;
442         delete end;
443 }
444
445 Editor::LocationMarkers *
446 Editor::find_location_markers (Location *location) const
447 {
448         LocationMarkerMap::const_iterator i;
449
450         for (i = location_markers.begin(); i != location_markers.end(); ++i) {
451                 if ((*i).first == location) {
452                         return (*i).second;
453                 }
454         }
455
456         return 0;
457 }
458
459 Location *
460 Editor::find_location_from_marker (Marker *marker, bool& is_start) const
461 {
462         LocationMarkerMap::const_iterator i;
463
464         for (i = location_markers.begin(); i != location_markers.end(); ++i) {
465                 LocationMarkers *lm = (*i).second;
466                 if (lm->start == marker) {
467                         is_start = true;
468                         return (*i).first;
469                 } else if (lm->end == marker) {
470                         is_start = false;
471                         return (*i).first;
472                 }
473         }
474
475         return 0;
476 }
477
478 void
479 Editor::refresh_location_display_internal (Locations::LocationList& locations)
480 {
481         /* invalidate all */
482
483         for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
484                 i->second->valid = false;
485         }
486
487         /* add new ones */
488
489         for (Locations::LocationList::iterator i = locations.begin(); i != locations.end(); ++i) {
490
491                 LocationMarkerMap::iterator x;
492
493                 if ((x = location_markers.find (*i)) != location_markers.end()) {
494                         x->second->valid = true;
495                         continue;
496                 }
497
498                 add_new_location_internal (*i);
499         }
500
501         /* remove dead ones */
502
503         for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ) {
504
505                 LocationMarkerMap::iterator tmp;
506
507                 tmp = i;
508                 ++tmp;
509
510                 if (!i->second->valid) {
511
512                         remove_sorted_marker (i->second->start);
513                         if (i->second->end) {
514                                 remove_sorted_marker (i->second->end);
515                         }
516
517                         LocationMarkers* m = i->second;
518                         location_markers.erase (i);
519                         delete m;
520                 }
521
522                 i = tmp;
523         }
524
525         update_punch_range_view (false);
526         update_loop_range_view (false);
527 }
528
529 void
530 Editor::refresh_location_display ()
531 {
532         ENSURE_GUI_THREAD (*this, &Editor::refresh_location_display)
533
534         if (_session) {
535                 _session->locations()->apply (*this, &Editor::refresh_location_display_internal);
536         }
537
538         update_marker_labels ();
539 }
540
541 void
542 Editor::LocationMarkers::hide()
543 {
544         start->hide ();
545         if (end) {
546                 end->hide ();
547         }
548 }
549
550 void
551 Editor::LocationMarkers::show()
552 {
553         start->show ();
554         if (end) {
555                 end->show ();
556         }
557 }
558
559 void
560 Editor::LocationMarkers::canvas_height_set (double h)
561 {
562         start->canvas_height_set (h);
563         if (end) {
564                 end->canvas_height_set (h);
565         }
566 }
567
568 void
569 Editor::LocationMarkers::set_name (const string& str)
570 {
571         /* XXX: hack: don't change names of session start/end markers */
572
573         if (start->type() != Marker::SessionStart) {
574                 start->set_name (str);
575         }
576
577         if (end && end->type() != Marker::SessionEnd) {
578                 end->set_name (str);
579         }
580 }
581
582 void
583 Editor::LocationMarkers::set_position (framepos_t startf,
584                                        framepos_t endf)
585 {
586         start->set_position (startf);
587         if (end) {
588                 end->set_position (endf);
589         }
590 }
591
592 void
593 Editor::LocationMarkers::set_color_rgba (uint32_t rgba)
594 {
595         start->set_color_rgba (rgba);
596         if (end) {
597                 end->set_color_rgba (rgba);
598         }
599 }
600
601 void
602 Editor::LocationMarkers::set_show_lines (bool s)
603 {
604         start->set_show_line (s);
605         if (end) {
606                 end->set_show_line (s);
607         }
608 }
609
610 void
611 Editor::LocationMarkers::set_selected (bool s)
612 {
613         start->set_selected (s);
614         if (end) {
615                 end->set_selected (s);
616         }
617 }
618
619 void
620 Editor::LocationMarkers::setup_lines ()
621 {
622         start->setup_line ();
623         if (end) {
624                 end->setup_line ();
625         }
626 }
627
628 void
629 Editor::mouse_add_new_marker (framepos_t where, bool is_cd, bool is_xrun)
630 {
631         string markername, markerprefix;
632         int flags = (is_cd ? Location::IsCDMarker|Location::IsMark : Location::IsMark);
633
634         if (is_xrun) {
635                 markerprefix = "xrun";
636                 flags = Location::IsMark;
637         } else {
638                 markerprefix = "mark";
639         }
640
641         if (_session) {
642                 _session->locations()->next_available_name(markername, markerprefix);
643                 if (!is_xrun && !choose_new_marker_name(markername)) {
644                         return;
645                 }
646                 Location *location = new Location (*_session, where, where, markername, (Location::Flags) flags);
647                 _session->begin_reversible_command (_("add marker"));
648                 XMLNode &before = _session->locations()->get_state();
649                 _session->locations()->add (location, true);
650                 XMLNode &after = _session->locations()->get_state();
651                 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
652                 _session->commit_reversible_command ();
653
654                 /* find the marker we just added */
655
656                 LocationMarkers *lam = find_location_markers (location);
657                 if (lam) {
658                         /* make it the selected marker */
659                         selection->set (lam->start);
660                 }
661         }
662 }
663
664 void
665 Editor::mouse_add_new_range (framepos_t where)
666 {
667         if (!_session) {
668                 return;
669         }
670
671         /* Make this marker 1/8th of the visible area of the session so that
672            it's reasonably easy to manipulate after creation.
673         */
674
675         framepos_t const end = where + current_page_frames() / 8;
676
677         string name;
678         _session->locations()->next_available_name (name, _("range"));
679         Location* loc = new Location (*_session, where, end, name, Location::IsRangeMarker);
680
681         begin_reversible_command (_("new range marker"));
682         XMLNode& before = _session->locations()->get_state ();
683         _session->locations()->add (loc, true);
684         XMLNode& after = _session->locations()->get_state ();
685         _session->add_command (new MementoCommand<Locations> (*_session->locations(), &before, &after));
686         commit_reversible_command ();
687 }
688
689 void
690 Editor::remove_marker (ArdourCanvas::Item& item, GdkEvent*)
691 {
692         Marker* marker;
693         bool is_start;
694
695         if ((marker = static_cast<Marker*> (item.get_data ("marker"))) == 0) {
696                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
697                 /*NOTREACHED*/
698         }
699
700         if (entered_marker == marker) {
701                 entered_marker = NULL;
702         }
703
704         Location* loc = find_location_from_marker (marker, is_start);
705
706         if (_session && loc) {
707                 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &Editor::really_remove_marker), loc));
708         }
709 }
710
711 gint
712 Editor::really_remove_marker (Location* loc)
713 {
714         _session->begin_reversible_command (_("remove marker"));
715         XMLNode &before = _session->locations()->get_state();
716         _session->locations()->remove (loc);
717         XMLNode &after = _session->locations()->get_state();
718         _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
719         _session->commit_reversible_command ();
720         return FALSE;
721 }
722
723 void
724 Editor::location_gone (Location *location)
725 {
726         ENSURE_GUI_THREAD (*this, &Editor::location_gone, location)
727
728         LocationMarkerMap::iterator i;
729
730         if (location == transport_loop_location()) {
731                 update_loop_range_view (true);
732         }
733
734         if (location == transport_punch_location()) {
735                 update_punch_range_view (true);
736         }
737
738         for (i = location_markers.begin(); i != location_markers.end(); ++i) {
739                 if (i->first == location) {
740
741                         remove_sorted_marker (i->second->start);
742                         if (i->second->end) {
743                                 remove_sorted_marker (i->second->end);
744                         }
745
746                         LocationMarkers* m = i->second;
747                         location_markers.erase (i);
748                         delete m;
749                         break;
750                 }
751         }
752 }
753
754 void
755 Editor::tempo_or_meter_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
756 {
757         marker_menu_item = item;
758
759         MeterMarker* mm;
760         TempoMarker* tm;
761         dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
762
763         bool can_remove = false;
764
765         if (mm) {
766                 can_remove = mm->meter().movable ();
767         } else if (tm) {
768                 can_remove = tm->tempo().movable ();
769         } else {
770                 return;
771         }
772
773         delete tempo_or_meter_marker_menu;
774         build_tempo_or_meter_marker_menu (can_remove);
775         tempo_or_meter_marker_menu->popup (1, ev->time);
776 }
777
778 void
779 Editor::marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item* item)
780 {
781         Marker * marker;
782         if ((marker = reinterpret_cast<Marker *> (item->get_data("marker"))) == 0) {
783                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
784                 /*NOTREACHED*/
785         }
786
787         bool is_start;
788         Location * loc = find_location_from_marker (marker, is_start);
789
790         if (loc == transport_loop_location() || loc == transport_punch_location() || loc->is_session_range ()) {
791
792                 if (transport_marker_menu == 0) {
793                         build_range_marker_menu (loc == transport_loop_location() || loc == transport_punch_location(), loc->is_session_range());
794                 }
795
796                 marker_menu_item = item;
797                 transport_marker_menu->popup (1, ev->time);
798
799         } else if (loc->is_mark()) {
800
801                         delete marker_menu;
802                         build_marker_menu (loc);
803
804                 // GTK2FIX use action group sensitivity
805 #ifdef GTK2FIX
806                         if (children.size() >= 3) {
807                                 MenuItem * loopitem = &children[2];
808                                 if (loopitem) {
809                                         if (loc->is_mark()) {
810                                                 loopitem->set_sensitive(false);
811                                         }
812                                         else {
813                                                 loopitem->set_sensitive(true);
814                                         }
815                                 }
816                         }
817 #endif
818                         marker_menu_item = item;
819                         marker_menu->popup (1, ev->time);
820
821         } else if (loc->is_range_marker()) {
822                 if (range_marker_menu == 0) {
823                         build_range_marker_menu (false, false);
824                 }
825                 marker_menu_item = item;
826                 range_marker_menu->popup (1, ev->time);
827         }
828 }
829
830 void
831 Editor::new_transport_marker_context_menu (GdkEventButton* ev, ArdourCanvas::Item*)
832 {
833         if (new_transport_marker_menu == 0) {
834                 build_new_transport_marker_menu ();
835         }
836
837         new_transport_marker_menu->popup (1, ev->time);
838
839 }
840
841 void
842 Editor::build_marker_menu (Location* loc)
843 {
844         using namespace Menu_Helpers;
845
846         marker_menu = new Menu;
847         MenuList& items = marker_menu->items();
848         marker_menu->set_name ("ArdourContextMenu");
849
850         items.push_back (MenuElem (_("Locate to Here"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
851         items.push_back (MenuElem (_("Play from Here"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
852         items.push_back (MenuElem (_("Move Mark to Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
853
854         items.push_back (SeparatorElem());
855
856         items.push_back (MenuElem (_("Create Range to Next Marker"), sigc::mem_fun(*this, &Editor::marker_menu_range_to_next)));
857
858         items.push_back (MenuElem (_("Hide"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
859         items.push_back (MenuElem (_("Rename..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
860
861         items.push_back (CheckMenuElem (_("Lock")));
862         CheckMenuItem* lock_item = static_cast<CheckMenuItem*> (&items.back());
863         if (loc->locked ()) {
864                 lock_item->set_active ();
865         }
866         lock_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_lock));
867
868         items.push_back (CheckMenuElem (_("Glue to Bars and Beats")));
869         CheckMenuItem* glue_item = static_cast<CheckMenuItem*> (&items.back());
870         if (loc->position_lock_style() == MusicTime) {
871                 glue_item->set_active ();
872         }
873         glue_item->signal_activate().connect (sigc::mem_fun (*this, &Editor::toggle_marker_menu_glue));
874
875         items.push_back (SeparatorElem());
876
877         items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
878 }
879
880 void
881 Editor::build_range_marker_menu (bool loop_or_punch, bool session)
882 {
883         using namespace Menu_Helpers;
884
885         bool const loop_or_punch_or_session = loop_or_punch | session;
886
887         Menu *markerMenu = new Menu;
888         if (loop_or_punch_or_session) {
889                 transport_marker_menu = markerMenu;
890         } else {
891                 range_marker_menu = markerMenu;
892         }
893         MenuList& items = markerMenu->items();
894         markerMenu->set_name ("ArdourContextMenu");
895
896         items.push_back (MenuElem (_("Play Range"), sigc::mem_fun(*this, &Editor::marker_menu_play_range)));
897         items.push_back (MenuElem (_("Locate to Marker"), sigc::mem_fun(*this, &Editor::marker_menu_set_playhead)));
898         items.push_back (MenuElem (_("Play from Marker"), sigc::mem_fun(*this, &Editor::marker_menu_play_from)));
899         items.push_back (MenuElem (_("Loop Range"), sigc::mem_fun(*this, &Editor::marker_menu_loop_range)));
900
901         items.push_back (MenuElem (_("Set Marker from Playhead"), sigc::mem_fun(*this, &Editor::marker_menu_set_from_playhead)));
902         if (!Profile->get_sae()) {
903                 items.push_back (MenuElem (_("Set Range from Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::marker_menu_set_from_selection), false)));
904         }
905
906         items.push_back (MenuElem (_("Zoom to Range"), sigc::mem_fun (*this, &Editor::marker_menu_zoom_to_range)));
907
908         items.push_back (SeparatorElem());
909         items.push_back (MenuElem (_("Export Range..."), sigc::mem_fun(*this, &Editor::export_range)));
910         items.push_back (SeparatorElem());
911
912         if (!loop_or_punch_or_session) {
913                 items.push_back (MenuElem (_("Hide Range"), sigc::mem_fun(*this, &Editor::marker_menu_hide)));
914                 items.push_back (MenuElem (_("Rename Range..."), sigc::mem_fun(*this, &Editor::marker_menu_rename)));
915         }
916
917         if (!session) {
918                 items.push_back (MenuElem (_("Remove Range"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
919         }
920
921         if (!loop_or_punch_or_session || !session) {
922                 items.push_back (SeparatorElem());
923         }
924         
925         items.push_back (MenuElem (_("Separate Regions in Range"), sigc::mem_fun(*this, &Editor::marker_menu_separate_regions_using_location)));
926         items.push_back (MenuElem (_("Select All in Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_all_selectables_using_range)));
927         if (!Profile->get_sae()) {
928                 items.push_back (MenuElem (_("Select Range"), sigc::mem_fun(*this, &Editor::marker_menu_select_using_range)));
929         }
930 }
931
932 void
933 Editor::build_tempo_or_meter_marker_menu (bool can_remove)
934 {
935         using namespace Menu_Helpers;
936
937         tempo_or_meter_marker_menu = new Menu;
938         MenuList& items = tempo_or_meter_marker_menu->items();
939         tempo_or_meter_marker_menu->set_name ("ArdourContextMenu");
940
941         items.push_back (MenuElem (_("Edit..."), sigc::mem_fun(*this, &Editor::marker_menu_edit)));
942         items.push_back (MenuElem (_("Remove"), sigc::mem_fun(*this, &Editor::marker_menu_remove)));
943
944         items.back().set_sensitive (can_remove);
945 }
946
947 void
948 Editor::build_new_transport_marker_menu ()
949 {
950         using namespace Menu_Helpers;
951
952         new_transport_marker_menu = new Menu;
953         MenuList& items = new_transport_marker_menu->items();
954         new_transport_marker_menu->set_name ("ArdourContextMenu");
955
956         items.push_back (MenuElem (_("Set Loop Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_loop)));
957         items.push_back (MenuElem (_("Set Punch Range"), sigc::mem_fun(*this, &Editor::new_transport_marker_menu_set_punch)));
958
959         new_transport_marker_menu->signal_unmap().connect ( sigc::mem_fun(*this, &Editor::new_transport_marker_menu_popdown));
960 }
961
962 void
963 Editor::marker_menu_hide ()
964 {
965         Marker* marker;
966
967         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
968                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
969                 /*NOTREACHED*/
970         }
971
972         Location* l;
973         bool is_start;
974
975         if ((l = find_location_from_marker (marker, is_start)) != 0) {
976                 l->set_hidden (true, this);
977         }
978 }
979
980 void
981 Editor::marker_menu_select_using_range ()
982 {
983         Marker* marker;
984
985         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
986                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
987                 /*NOTREACHED*/
988         }
989
990         Location* l;
991         bool is_start;
992
993         if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
994                 set_selection_from_range (*l);
995         }
996 }
997
998 void
999 Editor::marker_menu_select_all_selectables_using_range ()
1000 {
1001         Marker* marker;
1002
1003         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1004                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1005                 /*NOTREACHED*/
1006         }
1007
1008         Location* l;
1009         bool is_start;
1010
1011         if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1012                 select_all_within (l->start(), l->end() - 1, 0,  DBL_MAX, track_views, Selection::Set, false);
1013         }
1014
1015 }
1016
1017 void
1018 Editor::marker_menu_separate_regions_using_location ()
1019 {
1020         Marker* marker;
1021
1022         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1023                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1024                 /*NOTREACHED*/
1025         }
1026
1027         Location* l;
1028         bool is_start;
1029
1030         if (((l = find_location_from_marker (marker, is_start)) != 0) && (l->end() > l->start())) {
1031                 separate_regions_using_location (*l);
1032         }
1033
1034 }
1035
1036 void
1037 Editor::marker_menu_play_from ()
1038 {
1039         Marker* marker;
1040
1041         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1042                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1043                 /*NOTREACHED*/
1044         }
1045
1046         Location* l;
1047         bool is_start;
1048
1049         if ((l = find_location_from_marker (marker, is_start)) != 0) {
1050
1051                 if (l->is_mark()) {
1052                         _session->request_locate (l->start(), true);
1053                 }
1054                 else {
1055                         //_session->request_bounded_roll (l->start(), l->end());
1056
1057                         if (is_start) {
1058                                 _session->request_locate (l->start(), true);
1059                         } else {
1060                                 _session->request_locate (l->end(), true);
1061                         }
1062                 }
1063         }
1064 }
1065
1066 void
1067 Editor::marker_menu_set_playhead ()
1068 {
1069         Marker* marker;
1070
1071         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1072                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1073                 /*NOTREACHED*/
1074         }
1075
1076         Location* l;
1077         bool is_start;
1078
1079         if ((l = find_location_from_marker (marker, is_start)) != 0) {
1080
1081                 if (l->is_mark()) {
1082                         _session->request_locate (l->start(), false);
1083                 }
1084                 else {
1085                         if (is_start) {
1086                                 _session->request_locate (l->start(), false);
1087                         } else {
1088                                 _session->request_locate (l->end(), false);
1089                         }
1090                 }
1091         }
1092 }
1093
1094 void
1095 Editor::marker_menu_range_to_next ()
1096 {
1097         Marker* marker;
1098         if (!_session) {
1099                 return;
1100         }
1101
1102         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1103                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1104                 /*NOTREACHED*/
1105         }
1106
1107         Location* l;
1108         bool is_start;
1109
1110         if ((l = find_location_from_marker (marker, is_start)) == 0) {
1111                 return;
1112         }
1113
1114         framepos_t start;
1115         framepos_t end;
1116         _session->locations()->marks_either_side (marker->position(), start, end);
1117
1118         if (end != max_framepos) {
1119                 string range_name = l->name();
1120                 range_name += "-range";
1121
1122                 Location* newrange = new Location (*_session, marker->position(), end, range_name, Location::IsRangeMarker);
1123                 _session->locations()->add (newrange);
1124         }
1125 }
1126
1127 void
1128 Editor::marker_menu_set_from_playhead ()
1129 {
1130         Marker* marker;
1131
1132         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1133                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1134                 /*NOTREACHED*/
1135         }
1136
1137         Location* l;
1138         bool is_start;
1139
1140         if ((l = find_location_from_marker (marker, is_start)) != 0) {
1141
1142                 if (l->is_mark()) {
1143                         l->set_start (_session->audible_frame ());
1144                 }
1145                 else {
1146                         if (is_start) {
1147                                 l->set_start (_session->audible_frame ());
1148                         } else {
1149                                 l->set_end (_session->audible_frame ());
1150                         }
1151                 }
1152         }
1153 }
1154
1155 void
1156 Editor::marker_menu_set_from_selection (bool /*force_regions*/)
1157 {
1158         Marker* marker;
1159
1160         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1161                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1162                 /*NOTREACHED*/
1163         }
1164
1165         Location* l;
1166         bool is_start;
1167
1168         if ((l = find_location_from_marker (marker, is_start)) != 0) {
1169
1170                 if (l->is_mark()) {
1171
1172                         // nothing for now
1173
1174                 } else {
1175                         
1176                         if (!selection->time.empty()) {
1177                                 l->set (selection->time.start(), selection->time.end_frame());
1178                         } else if (!selection->regions.empty()) {
1179                                 l->set (selection->regions.start(), selection->regions.end_frame());
1180                         }
1181                 }
1182         }
1183 }
1184
1185
1186 void
1187 Editor::marker_menu_play_range ()
1188 {
1189         Marker* marker;
1190
1191         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1192                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1193                 /*NOTREACHED*/
1194         }
1195
1196         Location* l;
1197         bool is_start;
1198
1199         if ((l = find_location_from_marker (marker, is_start)) != 0) {
1200
1201                 if (l->is_mark()) {
1202                         _session->request_locate (l->start(), true);
1203                 }
1204                 else {
1205                         _session->request_bounded_roll (l->start(), l->end());
1206
1207                 }
1208         }
1209 }
1210
1211 void
1212 Editor::marker_menu_loop_range ()
1213 {
1214         Marker* marker;
1215
1216         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1217                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1218                 /*NOTREACHED*/
1219         }
1220
1221         Location* l;
1222         bool is_start;
1223
1224         if ((l = find_location_from_marker (marker, is_start)) != 0) {
1225                 Location* l2;
1226                 if ((l2 = transport_loop_location()) != 0) {
1227                         l2->set (l->start(), l->end());
1228
1229                         // enable looping, reposition and start rolling
1230                         _session->request_play_loop(true);
1231                         _session->request_locate (l2->start(), true);
1232                 }
1233         }
1234 }
1235
1236 /** Temporal zoom to the range of the marker_menu_item (plus 5% either side) */
1237 void
1238 Editor::marker_menu_zoom_to_range ()
1239 {
1240         Marker* marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"));
1241         assert (marker);
1242
1243         bool is_start;
1244         Location* l = find_location_from_marker (marker, is_start);
1245         if (l == 0) {
1246                 return;
1247         }
1248
1249         framecnt_t const extra = l->length() * 0.05;
1250         framepos_t a = l->start ();
1251         if (a >= extra) {
1252                 a -= extra;
1253         }
1254         
1255         framepos_t b = l->end ();
1256         if (b < (max_framepos - extra)) {
1257                 b += extra;
1258         }
1259
1260         temporal_zoom_by_frame (a, b);
1261 }
1262
1263 void
1264 Editor::dynamic_cast_marker_object (void* p, MeterMarker** m, TempoMarker** t) const
1265 {
1266         Marker* marker = reinterpret_cast<Marker*> (p);
1267         if (!marker) {
1268                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1269                 /*NOTREACHED*/
1270         }
1271
1272         *m = dynamic_cast<MeterMarker*> (marker);
1273         *t = dynamic_cast<TempoMarker*> (marker);
1274 }
1275
1276 void
1277 Editor::marker_menu_edit ()
1278 {
1279         MeterMarker* mm;
1280         TempoMarker* tm;
1281         dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1282
1283         if (mm) {
1284                 edit_meter_section (&mm->meter());
1285         } else if (tm) {
1286                 edit_tempo_section (&tm->tempo());
1287         }
1288 }
1289
1290 void
1291 Editor::marker_menu_remove ()
1292 {
1293         MeterMarker* mm;
1294         TempoMarker* tm;
1295         dynamic_cast_marker_object (marker_menu_item->get_data ("marker"), &mm, &tm);
1296
1297         if (mm) {
1298                 remove_meter_marker (marker_menu_item);
1299         } else if (tm) {
1300                 remove_tempo_marker (marker_menu_item);
1301         } else {
1302                 remove_marker (*marker_menu_item, (GdkEvent*) 0);
1303         }
1304 }
1305
1306 void
1307 Editor::toggle_marker_menu_lock ()
1308 {
1309         Marker* marker;
1310
1311         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1312                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1313                 /*NOTREACHED*/
1314         }
1315
1316         Location* loc;
1317         bool ignored;
1318
1319         loc = find_location_from_marker (marker, ignored);
1320
1321         if (!loc) {
1322                 return;
1323         }
1324
1325         if (loc->locked()) {
1326                 loc->unlock ();
1327         } else {
1328                 loc->lock ();
1329         }
1330 }
1331
1332 void
1333 Editor::marker_menu_rename ()
1334 {
1335         Marker* marker;
1336
1337         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1338                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1339                 /*NOTREACHED*/
1340         }
1341
1342         Location* loc;
1343         bool is_start;
1344
1345         loc = find_location_from_marker (marker, is_start);
1346
1347         if (!loc) return;
1348
1349         ArdourPrompter dialog (true);
1350         string txt;
1351
1352         dialog.set_prompt (_("New Name:"));
1353
1354         if (loc->is_mark()) {
1355                 dialog.set_title (_("Rename Mark"));
1356         } else {
1357                 dialog.set_title (_("Rename Range"));
1358         }
1359
1360         dialog.set_name ("MarkRenameWindow");
1361         dialog.set_size_request (250, -1);
1362         dialog.set_position (Gtk::WIN_POS_MOUSE);
1363
1364         dialog.add_button (_("Rename"), RESPONSE_ACCEPT);
1365         dialog.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1366         dialog.set_initial_text (loc->name());
1367
1368         dialog.show ();
1369
1370         switch (dialog.run ()) {
1371         case RESPONSE_ACCEPT:
1372                 break;
1373         default:
1374                 return;
1375         }
1376
1377         begin_reversible_command ( _("rename marker") );
1378         XMLNode &before = _session->locations()->get_state();
1379
1380         dialog.get_result(txt);
1381         loc->set_name (txt);
1382
1383         XMLNode &after = _session->locations()->get_state();
1384         _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1385         commit_reversible_command ();
1386 }
1387
1388 void
1389 Editor::new_transport_marker_menu_popdown ()
1390 {
1391         // hide rects
1392         transport_bar_drag_rect->hide();
1393
1394         _drags->abort ();
1395 }
1396
1397 void
1398 Editor::new_transport_marker_menu_set_loop ()
1399 {
1400         set_loop_range (temp_location->start(), temp_location->end(), _("set loop range"));
1401 }
1402
1403 void
1404 Editor::new_transport_marker_menu_set_punch ()
1405 {
1406         set_punch_range (temp_location->start(), temp_location->end(), _("set punch range"));
1407 }
1408
1409 void
1410 Editor::update_loop_range_view (bool visibility)
1411 {
1412         if (_session == 0) {
1413                 return;
1414         }
1415
1416         Location* tll;
1417
1418         if (_session->get_play_loop() && ((tll = transport_loop_location()) != 0)) {
1419
1420                 double x1 = frame_to_pixel (tll->start());
1421                 double x2 = frame_to_pixel (tll->end());
1422
1423                 transport_loop_range_rect->property_x1() = x1;
1424                 transport_loop_range_rect->property_x2() = x2;
1425
1426                 if (visibility) {
1427                         transport_loop_range_rect->show();
1428                 }
1429
1430         } else if (visibility) {
1431                 transport_loop_range_rect->hide();
1432         }
1433 }
1434
1435 void
1436 Editor::update_punch_range_view (bool visibility)
1437 {
1438         if (_session == 0) {
1439                 return;
1440         }
1441
1442         Location* tpl;
1443
1444         if ((_session->config.get_punch_in() || _session->config.get_punch_out()) && ((tpl = transport_punch_location()) != 0)) {
1445                 guint track_canvas_width,track_canvas_height;
1446                 track_canvas->get_size(track_canvas_width,track_canvas_height);
1447                 if (_session->config.get_punch_in()) {
1448                         transport_punch_range_rect->property_x1() = frame_to_pixel (tpl->start());
1449                         transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : frame_to_pixel (JACK_MAX_FRAMES));
1450                 } else {
1451                         transport_punch_range_rect->property_x1() = 0;
1452                         transport_punch_range_rect->property_x2() = (_session->config.get_punch_out() ? frame_to_pixel (tpl->end()) : track_canvas_width);
1453                 }
1454
1455                 if (visibility) {
1456                         transport_punch_range_rect->show();
1457                 }
1458         } else if (visibility) {
1459                 transport_punch_range_rect->hide();
1460         }
1461 }
1462
1463 void
1464 Editor::marker_selection_changed ()
1465 {
1466         if (_session && _session->deletion_in_progress()) {
1467                 return;
1468         }
1469
1470         for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1471                 i->second->set_selected (false);
1472         }
1473
1474         for (MarkerSelection::iterator x = selection->markers.begin(); x != selection->markers.end(); ++x) {
1475                 (*x)->set_selected (true);
1476         }
1477 }
1478
1479 struct SortLocationsByPosition {
1480     bool operator() (Location* a, Location* b) {
1481             return a->start() < b->start();
1482     }
1483 };
1484
1485 void
1486 Editor::goto_nth_marker (int n)
1487 {
1488         if (!_session) {
1489                 return;
1490         }
1491         const Locations::LocationList& l (_session->locations()->list());
1492         Locations::LocationList ordered;
1493         ordered = l;
1494
1495         SortLocationsByPosition cmp;
1496         ordered.sort (cmp);
1497
1498         for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
1499                 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
1500                         if (n == 0) {
1501                                 _session->request_locate ((*i)->start(), _session->transport_rolling());
1502                                 break;
1503                         }
1504                         --n;
1505                 }
1506         }
1507 }
1508
1509 void
1510 Editor::toggle_marker_menu_glue ()
1511 {
1512         Marker* marker;
1513
1514         if ((marker = reinterpret_cast<Marker *> (marker_menu_item->get_data ("marker"))) == 0) {
1515                 fatal << _("programming error: marker canvas item has no marker object pointer!") << endmsg;
1516                 /*NOTREACHED*/
1517         }
1518
1519         Location* loc;
1520         bool ignored;
1521
1522         loc = find_location_from_marker (marker, ignored);
1523
1524         if (!loc) {
1525                 return;
1526         }
1527
1528         if (loc->position_lock_style() == MusicTime) {
1529                 loc->set_position_lock_style (AudioTime);
1530         } else {
1531                 loc->set_position_lock_style (MusicTime);
1532         }
1533
1534 }
1535
1536 void
1537 Editor::toggle_marker_lines ()
1538 {
1539         _show_marker_lines = !_show_marker_lines;
1540
1541         for (LocationMarkerMap::iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1542                 i->second->set_show_lines (_show_marker_lines);
1543         }
1544 }
1545
1546 void
1547 Editor::remove_sorted_marker (Marker* m)
1548 {
1549         for (std::map<ArdourCanvas::Group *, std::list<Marker *> >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) {
1550                 i->second.remove (m);
1551         }
1552 }
1553
1554 Marker *
1555 Editor::find_marker_from_location_id (PBD::ID const & id, bool is_start) const
1556 {
1557         for (LocationMarkerMap::const_iterator i = location_markers.begin(); i != location_markers.end(); ++i) {
1558                 if (i->first->id() == id) {
1559                         return is_start ? i->second->start : i->second->end;
1560                 }
1561         }
1562
1563         return 0;
1564 }