colinf's vertical double arrow track resize cursor patch
[ardour2.git] / gtk2_ardour / location_ui.cc
blob1bb251999c587760625177527b8ff55a341eea94
1 /*
2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <cmath>
21 #include <cstdlib>
23 #include <gtkmm2ext/utils.h>
24 #include <gtkmm2ext/stop_signal.h>
26 #include "ardour/utils.h"
27 #include "ardour/configuration.h"
28 #include "ardour/session.h"
29 #include "pbd/memento_command.h"
31 #include "ardour_ui.h"
32 #include "prompter.h"
33 #include "location_ui.h"
34 #include "keyboard.h"
35 #include "utils.h"
36 #include "gui_thread.h"
38 #include "i18n.h"
40 using namespace std;
41 using namespace ARDOUR;
42 using namespace PBD;
43 using namespace Gtk;
44 using namespace Gtkmm2ext;
46 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
47 : SessionHandlePtr (0), /* explicitly set below */
48 location(0),
49 item_table (1, 6, false),
50 start_clock (X_("locationstart"), true, X_("LocationEditRowClock"), true, false),
51 end_clock (X_("locationend"), true, X_("LocationEditRowClock"), true, false),
52 length_clock (X_("locationlength"), true, X_("LocationEditRowClock"), true, false, true),
53 cd_check_button (_("CD")),
54 hide_check_button (_("Hide")),
55 scms_check_button (_("SCMS")),
56 preemph_check_button (_("Pre-Emphasis"))
59 i_am_the_modifier = 0;
61 start_go_button.set_image (*manage (new Image (Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
62 end_go_button.set_image (*manage (new Image (Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
63 remove_button.set_image (*manage (new Image (Stock::REMOVE, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
65 number_label.set_name ("LocationEditNumberLabel");
66 name_label.set_name ("LocationEditNameLabel");
67 name_entry.set_name ("LocationEditNameEntry");
68 start_go_button.set_name ("LocationEditGoButton");
69 end_go_button.set_name ("LocationEditGoButton");
70 cd_check_button.set_name ("LocationEditCdButton");
71 hide_check_button.set_name ("LocationEditHideButton");
72 remove_button.set_name ("LocationEditRemoveButton");
73 isrc_label.set_name ("LocationEditNumberLabel");
74 isrc_entry.set_name ("LocationEditNameEntry");
75 scms_check_button.set_name ("LocationEditCdButton");
76 preemph_check_button.set_name ("LocationEditCdButton");
77 performer_label.set_name ("LocationEditNumberLabel");
78 performer_entry.set_name ("LocationEditNameEntry");
79 composer_label.set_name ("LocationEditNumberLabel");
80 composer_entry.set_name ("LocationEditNameEntry");
82 isrc_label.set_text ("ISRC: ");
83 isrc_label.set_size_request (30, -1);
84 performer_label.set_text ("Performer: ");
85 performer_label.set_size_request (60, -1);
86 composer_label.set_text ("Composer: ");
87 composer_label.set_size_request (60, -1);
89 isrc_entry.set_size_request (112, -1);
90 isrc_entry.set_max_length(12);
91 isrc_entry.set_editable (true);
93 performer_entry.set_size_request (100, -1);
94 performer_entry.set_editable (true);
96 composer_entry.set_size_request (100, -1);
97 composer_entry.set_editable (true);
99 name_label.set_alignment (0, 0.5);
101 cd_track_details_hbox.pack_start (isrc_label, false, false);
102 cd_track_details_hbox.pack_start (isrc_entry, false, false);
103 cd_track_details_hbox.pack_start (scms_check_button, false, false);
104 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
105 cd_track_details_hbox.pack_start (performer_label, false, false);
106 cd_track_details_hbox.pack_start (performer_entry, true, true);
107 cd_track_details_hbox.pack_start (composer_label, false, false);
108 cd_track_details_hbox.pack_start (composer_entry, true, true);
110 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
111 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
112 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
113 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
114 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
116 set_session (sess);
118 // start_hbox.pack_start (start_go_button, false, false);
119 start_hbox.pack_start (start_clock, false, false);
121 /* this is always in this location, no matter what the location is */
123 item_table.attach (start_hbox, 1, 2, 0, 1, FILL, FILL, 4, 0);
125 start_go_button.signal_clicked().connect(sigc::bind (sigc::mem_fun (*this, &LocationEditRow::go_button_pressed), LocStart));
126 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
127 start_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocStart));
129 // end_hbox.pack_start (end_go_button, false, false);
130 end_hbox.pack_start (end_clock, false, false);
132 end_go_button.signal_clicked().connect(sigc::bind (sigc::mem_fun (*this, &LocationEditRow::go_button_pressed), LocEnd));
133 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
134 end_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocEnd));
136 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
137 length_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocLength));
139 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
140 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
142 remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
144 pack_start(item_table, true, true);
146 set_location (loc);
147 set_number (num);
150 LocationEditRow::~LocationEditRow()
152 if (location) {
153 connections.drop_connections ();
157 void
158 LocationEditRow::set_session (Session *sess)
160 SessionHandlePtr::set_session (sess);
162 if (!_session) {
163 return;
166 start_clock.set_session (_session);
167 end_clock.set_session (_session);
168 length_clock.set_session (_session);
172 void
173 LocationEditRow::set_number (int num)
175 number = num;
177 if (number >= 0 ) {
178 number_label.set_text (string_compose ("%1", number));
182 void
183 LocationEditRow::set_location (Location *loc)
185 if (location) {
186 connections.drop_connections ();
189 location = loc;
191 if (!location) return;
193 if (!hide_check_button.get_parent()) {
194 item_table.attach (hide_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
196 hide_check_button.set_active (location->is_hidden());
198 if (location->is_auto_loop() || location-> is_auto_punch()) {
199 // use label instead of entry
201 name_label.set_text (location->name());
202 name_label.set_size_request (80, -1);
204 if (!name_label.get_parent()) {
205 item_table.attach (name_label, 0, 1, 0, 1, FILL, FILL, 4, 0);
208 name_label.show();
210 } else {
212 name_entry.set_text (location->name());
213 name_entry.set_size_request (100, -1);
214 name_entry.set_editable (true);
215 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
217 if (!name_entry.get_parent()) {
218 item_table.attach (name_entry, 0, 1, 0, 1, FILL | EXPAND, FILL, 4, 0);
220 name_entry.show();
222 if (!cd_check_button.get_parent()) {
223 item_table.attach (cd_check_button, 4, 5, 0, 1, FILL, FILL, 4, 0);
225 if (!remove_button.get_parent()) {
226 item_table.attach (remove_button, 6, 7, 0, 1, FILL, FILL, 4, 0);
229 if (location->is_end() || location->is_start()) {
230 remove_button.set_sensitive (false);
233 cd_check_button.set_active (location->is_cd_marker());
234 cd_check_button.show();
236 if (location->start() == _session->current_start_frame()) {
237 cd_check_button.set_sensitive (false);
238 } else {
239 cd_check_button.set_sensitive (true);
242 hide_check_button.show();
245 start_clock.set (location->start(), true);
248 if (!location->is_mark()) {
249 if (!end_hbox.get_parent()) {
250 item_table.attach (end_hbox, 2, 3, 0, 1, FILL, FILL, 4, 0);
252 if (!length_clock.get_parent()) {
253 item_table.attach (length_clock, 3, 4, 0, 1, FILL, FILL, 4, 0);
256 end_clock.set (location->end(), true);
257 length_clock.set (location->length(), true);
259 end_go_button.show();
260 end_clock.show();
261 length_clock.show();
263 ARDOUR_UI::instance()->set_tip (end_go_button, _("Jump to the end of this range"));
264 ARDOUR_UI::instance()->set_tip (start_go_button, _("Jump to the start of this range"));
265 ARDOUR_UI::instance()->set_tip (remove_button, _("Forget this range"));
266 ARDOUR_UI::instance()->set_tip (start_clock, _("Start time"));
267 ARDOUR_UI::instance()->set_tip (end_clock, _("End time"));
268 ARDOUR_UI::instance()->set_tip (length_clock, _("Length"));
270 } else {
272 ARDOUR_UI::instance()->set_tip (start_go_button, _("Jump to this marker"));
273 ARDOUR_UI::instance()->set_tip (remove_button, _("Forget this marker"));
274 ARDOUR_UI::instance()->set_tip (start_clock, _("Position"));
276 end_go_button.hide();
277 end_clock.hide();
278 length_clock.hide();
281 start_clock.set_sensitive (!location->locked());
282 end_clock.set_sensitive (!location->locked());
283 length_clock.set_sensitive (!location->locked());
285 location->start_changed.connect (connections, ui_bind (&LocationEditRow::start_changed, this, _1), gui_context());
286 location->end_changed.connect (connections, ui_bind (&LocationEditRow::end_changed, this, _1), gui_context());
287 location->name_changed.connect (connections, ui_bind (&LocationEditRow::name_changed, this, _1), gui_context());
288 location->changed.connect (connections, ui_bind (&LocationEditRow::location_changed, this, _1), gui_context());
289 location->FlagsChanged.connect (connections, ui_bind (&LocationEditRow::flags_changed, this, _1, _2), gui_context());
292 void
293 LocationEditRow::name_entry_changed ()
295 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed)
296 if (i_am_the_modifier || !location) return;
298 location->set_name (name_entry.get_text());
302 void
303 LocationEditRow::isrc_entry_changed ()
305 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed)
307 if (i_am_the_modifier || !location) return;
309 if (isrc_entry.get_text() != "" ) {
311 location->cd_info["isrc"] = isrc_entry.get_text();
313 } else {
314 location->cd_info.erase("isrc");
318 void
319 LocationEditRow::performer_entry_changed ()
321 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed)
323 if (i_am_the_modifier || !location) return;
325 if (performer_entry.get_text() != "") {
326 location->cd_info["performer"] = performer_entry.get_text();
327 } else {
328 location->cd_info.erase("performer");
332 void
333 LocationEditRow::composer_entry_changed ()
335 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed)
337 if (i_am_the_modifier || !location) return;
339 if (composer_entry.get_text() != "") {
340 location->cd_info["composer"] = composer_entry.get_text();
341 } else {
342 location->cd_info.erase("composer");
347 void
348 LocationEditRow::go_button_pressed (LocationPart part)
350 if (!location) return;
352 switch (part) {
353 case LocStart:
354 ARDOUR_UI::instance()->do_transport_locate (location->start());
355 break;
356 case LocEnd:
357 ARDOUR_UI::instance()->do_transport_locate (location->end());
358 break;
359 default:
360 break;
364 void
365 LocationEditRow::clock_changed (LocationPart part)
367 if (i_am_the_modifier || !location) return;
369 switch (part) {
370 case LocStart:
371 location->set_start (start_clock.current_time());
372 break;
373 case LocEnd:
374 location->set_end (end_clock.current_time());
375 break;
376 case LocLength:
377 location->set_end (location->start() + length_clock.current_duration());
378 default:
379 break;
384 void
385 LocationEditRow::change_aborted (LocationPart /*part*/)
387 if (i_am_the_modifier || !location) return;
389 set_location(location);
392 void
393 LocationEditRow::cd_toggled ()
395 if (i_am_the_modifier || !location) {
396 return;
399 //if (cd_check_button.get_active() == location->is_cd_marker()) {
400 // return;
403 if (cd_check_button.get_active()) {
404 if (location->start() <= _session->current_start_frame()) {
405 error << _("You cannot put a CD marker at the start of the session") << endmsg;
406 cd_check_button.set_active (false);
407 return;
411 location->set_cd (cd_check_button.get_active(), this);
413 if (location->is_cd_marker() && !(location->is_mark())) {
415 if (location->cd_info.find("isrc") != location->cd_info.end()) {
416 isrc_entry.set_text(location->cd_info["isrc"]);
418 if (location->cd_info.find("performer") != location->cd_info.end()) {
419 performer_entry.set_text(location->cd_info["performer"]);
421 if (location->cd_info.find("composer") != location->cd_info.end()) {
422 composer_entry.set_text(location->cd_info["composer"]);
424 if (location->cd_info.find("scms") != location->cd_info.end()) {
425 scms_check_button.set_active(true);
427 if (location->cd_info.find("preemph") != location->cd_info.end()) {
428 preemph_check_button.set_active(true);
431 if (!cd_track_details_hbox.get_parent()) {
432 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
434 // item_table.resize(2, 7);
435 cd_track_details_hbox.show_all();
437 } else if (cd_track_details_hbox.get_parent()){
439 item_table.remove (cd_track_details_hbox);
440 // item_table.resize(1, 7);
441 redraw_ranges(); /* EMIT_SIGNAL */
445 void
446 LocationEditRow::hide_toggled ()
448 if (i_am_the_modifier || !location) return;
450 location->set_hidden (hide_check_button.get_active(), this);
453 void
454 LocationEditRow::remove_button_pressed ()
456 if (!location) return;
458 remove_requested(location); /* EMIT_SIGNAL */
463 void
464 LocationEditRow::scms_toggled ()
466 if (i_am_the_modifier || !location) return;
468 if (scms_check_button.get_active()) {
469 location->cd_info["scms"] = "on";
470 } else {
471 location->cd_info.erase("scms");
476 void
477 LocationEditRow::preemph_toggled ()
479 if (i_am_the_modifier || !location) return;
481 if (preemph_check_button.get_active()) {
482 location->cd_info["preemph"] = "on";
483 } else {
484 location->cd_info.erase("preemph");
488 void
489 LocationEditRow::end_changed (ARDOUR::Location *loc)
491 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
493 if (!location) return;
495 // update end and length
496 i_am_the_modifier++;
498 end_clock.set (location->end());
499 length_clock.set (location->length());
501 i_am_the_modifier--;
504 void
505 LocationEditRow::start_changed (ARDOUR::Location *loc)
507 ENSURE_GUI_THREAD (*this, &LocationEditRow::start_changed, loc)
509 if (!location) return;
511 // update end and length
512 i_am_the_modifier++;
514 start_clock.set (location->start());
516 if (location->start() == _session->current_start_frame()) {
517 cd_check_button.set_sensitive (false);
518 } else {
519 cd_check_button.set_sensitive (true);
522 i_am_the_modifier--;
525 void
526 LocationEditRow::name_changed (ARDOUR::Location *loc)
528 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_changed, loc)
530 if (!location) return;
532 // update end and length
533 i_am_the_modifier++;
535 name_entry.set_text(location->name());
536 name_label.set_text(location->name());
538 i_am_the_modifier--;
542 void
543 LocationEditRow::location_changed (ARDOUR::Location *loc)
545 ENSURE_GUI_THREAD (*this, &LocationEditRow::location_changed, loc)
547 if (!location) return;
549 i_am_the_modifier++;
551 start_clock.set (location->start());
552 end_clock.set (location->end());
553 length_clock.set (location->length());
555 start_clock.set_sensitive (!location->locked());
556 end_clock.set_sensitive (!location->locked());
557 length_clock.set_sensitive (!location->locked());
559 i_am_the_modifier--;
563 void
564 LocationEditRow::flags_changed (ARDOUR::Location *loc, void *src)
566 ENSURE_GUI_THREAD (*this, &LocationEditRow::flags_changed, loc, src)
568 if (!location) return;
570 i_am_the_modifier++;
572 cd_check_button.set_active (location->is_cd_marker());
573 hide_check_button.set_active (location->is_hidden());
575 i_am_the_modifier--;
578 void
579 LocationEditRow::focus_name() {
580 name_entry.grab_focus();
584 LocationUI::LocationUI ()
585 : add_location_button (_("New Marker"))
586 , add_range_button (_("New Range"))
588 i_am_the_modifier = 0;
590 location_vpacker.set_spacing (5);
592 add_location_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
593 add_range_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
595 loop_punch_box.pack_start (loop_edit_row, false, false);
596 loop_punch_box.pack_start (punch_edit_row, false, false);
598 loop_punch_scroller.add (loop_punch_box);
599 loop_punch_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
600 loop_punch_scroller.set_shadow_type (Gtk::SHADOW_NONE);
602 location_vpacker.pack_start (loop_punch_scroller, false, false);
604 location_rows.set_name("LocationLocRows");
605 location_rows_scroller.add (location_rows);
606 location_rows_scroller.set_name ("LocationLocRowsScroller");
607 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
608 location_rows_scroller.set_size_request (-1, 130);
610 newest_location = 0;
612 loc_frame_box.set_spacing (5);
613 loc_frame_box.set_border_width (5);
614 loc_frame_box.set_name("LocationFrameBox");
616 loc_frame_box.pack_start (location_rows_scroller, true, true);
618 add_location_button.set_name ("LocationAddLocationButton");
620 HBox* add_button_box = manage (new HBox);
622 // loc_frame_box.pack_start (add_location_button, false, false);
623 add_button_box->pack_start (add_location_button, true, true);
625 loc_frame.set_name ("LocationLocEditorFrame");
626 loc_frame.set_label (_("Markers (including CD index)"));
627 loc_frame.add (loc_frame_box);
628 loc_range_panes.pack1(loc_frame, true, false);
631 range_rows.set_name("LocationRangeRows");
632 range_rows_scroller.add (range_rows);
633 range_rows_scroller.set_name ("LocationRangeRowsScroller");
634 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
635 range_rows_scroller.set_size_request (-1, 130);
637 range_frame_box.set_spacing (5);
638 range_frame_box.set_name("LocationFrameBox");
639 range_frame_box.set_border_width (5);
640 range_frame_box.pack_start (range_rows_scroller, true, true);
642 add_range_button.set_name ("LocationAddRangeButton");
643 //range_frame_box.pack_start (add_range_button, false, false);
645 add_button_box->pack_start (add_range_button, true, true);
647 range_frame.set_name ("LocationRangeEditorFrame");
648 range_frame.set_label (_("Ranges (including CD track ranges)"));
649 range_frame.add (range_frame_box);
650 loc_range_panes.pack2(range_frame, true, false);
651 location_vpacker.pack_start (loc_range_panes, true, true);
652 location_vpacker.pack_start (*add_button_box, false, false);
654 pack_start (location_vpacker, true, true);
656 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
657 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
659 show_all ();
662 LocationUI::~LocationUI()
666 gint
667 LocationUI::do_location_remove (ARDOUR::Location *loc)
669 /* this is handled internally by Locations, but there's
670 no point saving state etc. when we know the marker
671 cannot be removed.
674 if (loc->is_end()) {
675 return FALSE;
678 _session->begin_reversible_command (_("remove marker"));
679 XMLNode &before = _session->locations()->get_state();
680 _session->locations()->remove (loc);
681 XMLNode &after = _session->locations()->get_state();
682 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
683 _session->commit_reversible_command ();
685 return FALSE;
688 void
689 LocationUI::location_remove_requested (ARDOUR::Location *loc)
691 // must do this to prevent problems when destroying
692 // the effective sender of this event
694 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
698 void
699 LocationUI::location_redraw_ranges ()
701 range_rows.hide();
702 range_rows.show();
705 void
706 LocationUI::location_added (Location* location)
708 ENSURE_GUI_THREAD (*this, &LocationUI::location_added, location)
710 if (location->is_auto_punch()) {
711 punch_edit_row.set_location(location);
713 else if (location->is_auto_loop()) {
714 loop_edit_row.set_location(location);
716 else {
717 refresh_location_list ();
721 void
722 LocationUI::location_removed (Location* location)
724 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
726 if (location->is_auto_punch()) {
727 punch_edit_row.set_location(0);
729 else if (location->is_auto_loop()) {
730 loop_edit_row.set_location(0);
732 else {
733 refresh_location_list ();
737 struct LocationSortByStart {
738 bool operator() (Location *a, Location *b) {
739 return a->start() < b->start();
743 void
744 LocationUI::map_locations (Locations::LocationList& locations)
746 Locations::LocationList::iterator i;
747 Location* location;
748 gint n;
749 int mark_n = 0;
750 Locations::LocationList temp = locations;
751 LocationSortByStart cmp;
753 temp.sort (cmp);
754 locations = temp;
756 Box_Helpers::BoxList & loc_children = location_rows.children();
757 Box_Helpers::BoxList & range_children = range_rows.children();
758 LocationEditRow * erow;
760 for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
762 location = *i;
764 if (location->is_mark()) {
765 mark_n++;
766 erow = manage (new LocationEditRow(_session, location, mark_n));
767 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
768 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
769 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
770 if (location == newest_location) {
771 newest_location = 0;
772 erow->focus_name();
775 else if (location->is_auto_punch()) {
776 punch_edit_row.set_session (_session);
777 punch_edit_row.set_location (location);
778 punch_edit_row.show_all();
780 else if (location->is_auto_loop()) {
781 loop_edit_row.set_session (_session);
782 loop_edit_row.set_location (location);
783 loop_edit_row.show_all();
785 else {
786 erow = manage (new LocationEditRow(_session, location));
787 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
788 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
792 range_rows.show_all();
793 location_rows.show_all();
796 void
797 LocationUI::add_new_location()
799 string markername;
801 if (_session) {
802 nframes_t where = _session->audible_frame();
803 _session->locations()->next_available_name(markername,"mark");
804 Location *location = new Location (where, where, markername, Location::IsMark);
805 if (Config->get_name_new_markers()) {
806 newest_location = location;
808 _session->begin_reversible_command (_("add marker"));
809 XMLNode &before = _session->locations()->get_state();
810 _session->locations()->add (location, true);
811 XMLNode &after = _session->locations()->get_state();
812 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
813 _session->commit_reversible_command ();
818 void
819 LocationUI::add_new_range()
821 string rangename;
823 if (_session) {
824 nframes_t where = _session->audible_frame();
825 _session->locations()->next_available_name(rangename,"unnamed");
826 Location *location = new Location (where, where, rangename, Location::IsRangeMarker);
827 _session->begin_reversible_command (_("add range marker"));
828 XMLNode &before = _session->locations()->get_state();
829 _session->locations()->add (location, true);
830 XMLNode &after = _session->locations()->get_state();
831 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
832 _session->commit_reversible_command ();
836 void
837 LocationUI::refresh_location_list ()
839 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
840 using namespace Box_Helpers;
842 // this is just too expensive to do when window is not shown
843 if (!is_visible()) return;
845 BoxList & loc_children = location_rows.children();
846 BoxList & range_children = range_rows.children();
848 loc_children.clear();
849 range_children.clear();
851 if (_session) {
852 _session->locations()->apply (*this, &LocationUI::map_locations);
857 void
858 LocationUI::set_session(ARDOUR::Session* s)
860 SessionHandlePtr::set_session (s);
862 if (_session) {
863 _session->locations()->changed.connect (_session_connections, boost::bind (&LocationUI::refresh_location_list, this), gui_context());
864 _session->locations()->StateChanged.connect (_session_connections, boost::bind (&LocationUI::refresh_location_list, this), gui_context());
865 _session->locations()->added.connect (_session_connections, ui_bind (&LocationUI::location_added, this, _1), gui_context());
866 _session->locations()->removed.connect (_session_connections, ui_bind (&LocationUI::location_removed, this, _1), gui_context());
869 loop_edit_row.set_session (s);
870 punch_edit_row.set_session (s);
872 refresh_location_list ();
875 void
876 LocationUI::session_going_away()
878 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
880 using namespace Box_Helpers;
881 BoxList & loc_children = location_rows.children();
882 BoxList & range_children = range_rows.children();
884 loc_children.clear();
885 range_children.clear();
887 loop_edit_row.set_session (0);
888 loop_edit_row.set_location (0);
890 punch_edit_row.set_session (0);
891 punch_edit_row.set_location (0);
893 SessionHandlePtr::session_going_away ();
896 /*------------------------*/
898 LocationUIWindow::LocationUIWindow ()
899 : ArdourDialog ("locations dialog")
901 set_title (_("Locations"));
902 set_wmclass(X_("ardour_locations"), "Ardour");
903 set_name ("LocationWindow");
905 get_vbox()->pack_start (_ui);
908 LocationUIWindow::~LocationUIWindow()
912 void
913 LocationUIWindow::on_show()
915 _ui.refresh_location_list();
916 ArdourDialog::on_show();
919 bool
920 LocationUIWindow::on_delete_event (GdkEventAny*)
922 hide ();
923 return true;
926 void
927 LocationUIWindow::set_session (Session *s)
929 ArdourDialog::set_session (s);
930 _ui.set_session (s);
933 void
934 LocationUIWindow::session_going_away ()
936 ArdourDialog::session_going_away ();
937 hide_all();