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