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.
23 #include <gtkmm2ext/utils.h>
25 #include "ardour/session.h"
26 #include "pbd/memento_command.h"
28 #include "ardour_ui.h"
29 #include "clock_group.h"
30 #include "main_clock.h"
31 #include "gui_thread.h"
33 #include "location_ui.h"
40 using namespace ARDOUR;
41 using namespace ARDOUR_UI_UTILS;
44 using namespace Gtkmm2ext;
46 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
47 : SessionHandlePtr (0) /* explicitly set below */
49 , item_table (1, 6, false)
50 , start_clock (X_("locationstart"), true, "", true, false)
51 , start_to_playhead_button (_("Use PH"))
52 , end_clock (X_("locationend"), true, "", true, false)
53 , end_to_playhead_button (_("Use PH"))
54 , length_clock (X_("locationlength"), true, "", true, false, true)
55 , cd_check_button (_("CD"))
56 , hide_check_button (_("Hide"))
57 , lock_check_button (_("Lock"))
58 , glue_check_button (_("Glue"))
61 i_am_the_modifier = 0;
63 remove_button.set_image (*manage (new Image (Stock::REMOVE, Gtk::ICON_SIZE_MENU)));
65 start_to_playhead_button.set_name ("LocationEditCdButton");
66 end_to_playhead_button.set_name ("LocationEditCdButton");
68 number_label.set_name ("LocationEditNumberLabel");
69 name_label.set_name ("LocationEditNameLabel");
70 name_entry.set_name ("LocationEditNameEntry");
71 cd_check_button.set_name ("LocationEditCdButton");
72 hide_check_button.set_name ("LocationEditHideButton");
73 lock_check_button.set_name ("LocationEditLockButton");
74 glue_check_button.set_name ("LocationEditGlueButton");
75 remove_button.set_name ("LocationEditRemoveButton");
76 isrc_label.set_name ("LocationEditNumberLabel");
77 isrc_entry.set_name ("LocationEditNameEntry");
78 scms_check_button.set_name ("LocationEditCdButton");
79 preemph_check_button.set_name ("LocationEditCdButton");
80 performer_label.set_name ("LocationEditNumberLabel");
81 performer_entry.set_name ("LocationEditNameEntry");
82 composer_label.set_name ("LocationEditNumberLabel");
83 composer_entry.set_name ("LocationEditNameEntry");
85 isrc_label.set_text (X_("ISRC:"));
86 performer_label.set_text (_("Performer:"));
87 composer_label.set_text (_("Composer:"));
88 scms_label.set_text (X_("SCMS"));
89 preemph_label.set_text (_("Pre-Emphasis"));
91 isrc_entry.set_size_request (112, -1);
92 isrc_entry.set_max_length(12);
93 isrc_entry.set_editable (true);
95 performer_entry.set_size_request (100, -1);
96 performer_entry.set_editable (true);
98 composer_entry.set_size_request (100, -1);
99 composer_entry.set_editable (true);
101 name_label.set_alignment (0, 0.5);
103 Gtk::HBox* front_spacing = manage (new HBox);
104 front_spacing->set_size_request (20, -1);
105 Gtk::HBox* mid_spacing = manage (new HBox);
106 mid_spacing->set_size_request (20, -1);
108 cd_track_details_hbox.set_spacing (4);
109 cd_track_details_hbox.pack_start (*front_spacing, false, false);
110 cd_track_details_hbox.pack_start (isrc_label, false, false);
111 cd_track_details_hbox.pack_start (isrc_entry, false, false);
112 cd_track_details_hbox.pack_start (performer_label, false, false);
113 cd_track_details_hbox.pack_start (performer_entry, true, true);
114 cd_track_details_hbox.pack_start (composer_label, false, false);
115 cd_track_details_hbox.pack_start (composer_entry, true, true);
116 cd_track_details_hbox.pack_start (*mid_spacing, false, false);
117 cd_track_details_hbox.pack_start (scms_label, false, false);
118 cd_track_details_hbox.pack_start (scms_check_button, false, false);
119 cd_track_details_hbox.pack_start (preemph_label, false, false);
120 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
122 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
123 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
124 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
125 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
126 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
130 start_hbox.set_spacing (2);
131 start_hbox.pack_start (start_clock, false, false);
132 start_hbox.pack_start (start_to_playhead_button, false, false);
134 /* this is always in this location, no matter what the location is */
136 VBox *rbox = manage (new VBox);
137 rbox->pack_start (remove_button, false, false);
139 item_table.attach (*rbox, 0, 1, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
140 item_table.attach (start_hbox, 2, 3, 0, 1, FILL, Gtk::AttachOptions(0), 4, 0);
142 start_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocStart));
143 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
144 start_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &start_clock), false);
146 end_hbox.set_spacing (2);
147 end_hbox.pack_start (end_clock, false, false);
148 end_hbox.pack_start (end_to_playhead_button, false, false);
150 end_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocEnd));
151 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
152 end_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &end_clock), false);
154 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
156 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
157 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
158 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
159 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
161 remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
163 pack_start(item_table, true, true);
167 cd_toggled(); // show/hide cd-track details
170 LocationEditRow::~LocationEditRow()
173 connections.drop_connections ();
177 _clock_group->remove (start_clock);
178 _clock_group->remove (end_clock);
179 _clock_group->remove (length_clock);
184 LocationEditRow::set_clock_group (ClockGroup& cg)
187 _clock_group->remove (start_clock);
188 _clock_group->remove (end_clock);
189 _clock_group->remove (length_clock);
194 _clock_group->add (start_clock);
195 _clock_group->add (end_clock);
196 _clock_group->add (length_clock);
200 LocationEditRow::set_session (Session *sess)
202 SessionHandlePtr::set_session (sess);
208 start_clock.set_session (_session);
209 end_clock.set_session (_session);
210 length_clock.set_session (_session);
214 LocationEditRow::set_number (int num)
219 number_label.set_text (string_compose ("%1", number));
224 LocationEditRow::set_location (Location *loc)
227 connections.drop_connections ();
238 if (!hide_check_button.get_parent()) {
239 item_table.attach (hide_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
240 item_table.attach (lock_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
241 item_table.attach (glue_check_button, 8, 9, 0, 1, FILL, Gtk::FILL, 4, 0);
243 hide_check_button.set_active (location->is_hidden());
244 lock_check_button.set_active (location->locked());
245 glue_check_button.set_active (location->position_lock_style() == MusicTime);
247 if (location->is_auto_loop() || location-> is_auto_punch()) {
248 // use label instead of entry
250 name_label.set_text (location->name());
251 name_label.set_size_request (80, -1);
253 remove_button.hide ();
255 if (!name_label.get_parent()) {
256 item_table.attach (name_label, 1, 2, 0, 1, FILL, FILL, 4, 0);
263 name_entry.set_text (location->name());
264 name_entry.set_size_request (100, -1);
265 name_entry.set_editable (true);
266 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
268 if (!name_entry.get_parent()) {
269 item_table.attach (name_entry, 1, 2, 0, 1, FILL | EXPAND, FILL, 4, 0);
273 if (!cd_check_button.get_parent()) {
274 item_table.attach (cd_check_button, 5, 6, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
277 if (location->is_session_range()) {
278 remove_button.set_sensitive (false);
281 cd_check_button.set_active (location->is_cd_marker());
282 cd_check_button.show();
284 if (location->start() == _session->current_start_frame()) {
285 cd_check_button.set_sensitive (false);
287 cd_check_button.set_sensitive (true);
290 hide_check_button.show();
291 lock_check_button.show();
292 glue_check_button.show();
295 start_clock.set (location->start(), true);
298 if (!location->is_mark()) {
299 if (!end_hbox.get_parent()) {
300 item_table.attach (end_hbox, 3, 4, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
302 if (!length_clock.get_parent()) {
303 end_hbox.pack_start (length_clock, false, false);
306 end_clock.set (location->end(), true);
307 length_clock.set (location->length(), true);
312 if (location->is_cd_marker()) {
313 show_cd_track_details ();
316 ARDOUR_UI::instance()->set_tip (remove_button, _("Remove this range"));
317 ARDOUR_UI::instance()->set_tip (start_clock, _("Start time - middle click to locate here"));
318 ARDOUR_UI::instance()->set_tip (end_clock, _("End time - middle click to locate here"));
319 ARDOUR_UI::instance()->set_tip (length_clock, _("Length"));
321 ARDOUR_UI::instance()->tooltips().set_tip (start_to_playhead_button, _("Set range start from playhead location"));
322 ARDOUR_UI::instance()->tooltips().set_tip (end_to_playhead_button, _("Set range end from playhead location"));
326 ARDOUR_UI::instance()->set_tip (remove_button, _("Remove this marker"));
327 ARDOUR_UI::instance()->set_tip (start_clock, _("Position - middle click to locate here"));
329 ARDOUR_UI::instance()->tooltips().set_tip (start_to_playhead_button, _("Set marker time from playhead location"));
335 set_clock_editable_status ();
339 /* connect to per-location signals, since this row only cares about this location */
341 location->NameChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::name_changed, this), gui_context());
342 location->StartChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::start_changed, this), gui_context());
343 location->EndChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::end_changed, this), gui_context());
344 location->Changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::location_changed, this), gui_context());
345 location->FlagsChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::flags_changed, this), gui_context());
346 location->LockChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::lock_changed, this), gui_context());
347 location->PositionLockStyleChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::position_lock_style_changed, this), gui_context());
351 LocationEditRow::name_entry_changed ()
353 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed)
355 if (i_am_the_modifier || !location) {
359 location->set_name (name_entry.get_text());
364 LocationEditRow::isrc_entry_changed ()
366 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed)
368 if (i_am_the_modifier || !location) return;
370 if (isrc_entry.get_text() != "" ) {
372 location->cd_info["isrc"] = isrc_entry.get_text();
375 location->cd_info.erase("isrc");
380 LocationEditRow::performer_entry_changed ()
382 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed)
384 if (i_am_the_modifier || !location) return;
386 if (performer_entry.get_text() != "") {
387 location->cd_info["performer"] = performer_entry.get_text();
389 location->cd_info.erase("performer");
394 LocationEditRow::composer_entry_changed ()
396 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed)
398 if (i_am_the_modifier || !location) return;
400 if (composer_entry.get_text() != "") {
401 location->cd_info["composer"] = composer_entry.get_text();
403 location->cd_info.erase("composer");
408 LocationEditRow::to_playhead_button_pressed (LocationPart part)
416 location->set_start (_session->transport_frame ());
419 location->set_end (_session->transport_frame ());
427 LocationEditRow::locate_to_clock (GdkEventButton* ev, AudioClock* clock)
429 if (Keyboard::is_button2_event (ev)) {
430 _session->request_locate (clock->current_time());
437 LocationEditRow::clock_changed (LocationPart part)
439 if (i_am_the_modifier || !location) {
445 location->set_start (start_clock.current_time());
448 location->set_end (end_clock.current_time());
451 location->set_end (location->start() + length_clock.current_duration());
458 LocationEditRow::show_cd_track_details ()
461 if (location->cd_info.find("isrc") != location->cd_info.end()) {
462 isrc_entry.set_text(location->cd_info["isrc"]);
464 if (location->cd_info.find("performer") != location->cd_info.end()) {
465 performer_entry.set_text(location->cd_info["performer"]);
467 if (location->cd_info.find("composer") != location->cd_info.end()) {
468 composer_entry.set_text(location->cd_info["composer"]);
470 if (location->cd_info.find("scms") != location->cd_info.end()) {
471 scms_check_button.set_active(true);
473 if (location->cd_info.find("preemph") != location->cd_info.end()) {
474 preemph_check_button.set_active(true);
478 if (!cd_track_details_hbox.get_parent()) {
479 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
481 // item_table.resize(2, 7);
482 cd_track_details_hbox.show_all();
486 LocationEditRow::cd_toggled ()
488 if (i_am_the_modifier || !location) {
492 //if (cd_check_button.get_active() == location->is_cd_marker()) {
496 if (cd_check_button.get_active()) {
497 if (location->start() <= _session->current_start_frame()) {
498 error << _("You cannot put a CD marker at the start of the session") << endmsg;
499 cd_check_button.set_active (false);
504 location->set_cd (cd_check_button.get_active(), this);
506 if (location->is_cd_marker()) {
508 show_cd_track_details ();
510 } else if (cd_track_details_hbox.get_parent()){
512 item_table.remove (cd_track_details_hbox);
513 // item_table.resize(1, 7);
514 redraw_ranges(); /* EMIT_SIGNAL */
519 LocationEditRow::hide_toggled ()
521 if (i_am_the_modifier || !location) {
525 location->set_hidden (hide_check_button.get_active(), this);
529 LocationEditRow::lock_toggled ()
531 if (i_am_the_modifier || !location) {
535 if (location->locked()) {
543 LocationEditRow::glue_toggled ()
545 if (i_am_the_modifier || !location) {
549 if (location->position_lock_style() == AudioTime) {
550 location->set_position_lock_style (MusicTime);
552 location->set_position_lock_style (AudioTime);
557 LocationEditRow::remove_button_pressed ()
563 remove_requested (location); /* EMIT_SIGNAL */
569 LocationEditRow::scms_toggled ()
571 if (i_am_the_modifier || !location) return;
573 if (scms_check_button.get_active()) {
574 location->cd_info["scms"] = "on";
576 location->cd_info.erase("scms");
582 LocationEditRow::preemph_toggled ()
584 if (i_am_the_modifier || !location) return;
586 if (preemph_check_button.get_active()) {
587 location->cd_info["preemph"] = "on";
589 location->cd_info.erase("preemph");
594 LocationEditRow::end_changed ()
596 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
598 if (!location) return;
600 // update end and length
603 end_clock.set (location->end());
604 length_clock.set (location->length());
610 LocationEditRow::start_changed ()
612 if (!location) return;
614 // update end and length
617 start_clock.set (location->start());
619 if (location->start() == _session->current_start_frame()) {
620 cd_check_button.set_sensitive (false);
622 cd_check_button.set_sensitive (true);
629 LocationEditRow::name_changed ()
631 if (!location) return;
633 // update end and length
636 name_entry.set_text(location->name());
637 name_label.set_text(location->name());
644 LocationEditRow::location_changed ()
647 if (!location) return;
651 start_clock.set (location->start());
652 end_clock.set (location->end());
653 length_clock.set (location->length());
655 set_clock_editable_status ();
662 LocationEditRow::flags_changed ()
670 cd_check_button.set_active (location->is_cd_marker());
671 hide_check_button.set_active (location->is_hidden());
672 glue_check_button.set_active (location->position_lock_style() == MusicTime);
678 LocationEditRow::lock_changed ()
686 lock_check_button.set_active (location->locked());
688 set_clock_editable_status ();
694 LocationEditRow::position_lock_style_changed ()
702 glue_check_button.set_active (location->position_lock_style() == MusicTime);
708 LocationEditRow::focus_name()
710 name_entry.grab_focus ();
714 LocationEditRow::set_clock_editable_status ()
716 start_clock.set_editable (!location->locked());
717 end_clock.set_editable (!location->locked());
718 length_clock.set_editable (!location->locked());
721 /*------------------------------------------------------------------------*/
723 LocationUI::LocationUI ()
724 : add_location_button (_("New Marker"))
725 , add_range_button (_("New Range"))
727 i_am_the_modifier = 0;
729 _clock_group = new ClockGroup;
731 VBox* vbox = manage (new VBox);
733 Table* table = manage (new Table (2, 2));
734 table->set_spacings (2);
735 table->set_col_spacing (0, 32);
738 Label* l = manage (new Label (_("<b>Loop/Punch Ranges</b>")));
739 l->set_alignment (0, 0.5);
740 l->set_use_markup (true);
741 table->attach (*l, 0, 2, table_row, table_row + 1);
744 loop_edit_row.set_clock_group (*_clock_group);
745 punch_edit_row.set_clock_group (*_clock_group);
747 loop_punch_box.pack_start (loop_edit_row, false, false);
748 loop_punch_box.pack_start (punch_edit_row, false, false);
750 table->attach (loop_punch_box, 1, 2, table_row, table_row + 1);
753 vbox->pack_start (*table, false, false);
755 table = manage (new Table (3, 2));
756 table->set_spacings (2);
757 table->set_col_spacing (0, 32);
760 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
763 l = manage (new Label (_("<b>Markers (Including CD Index)</b>")));
764 l->set_alignment (0, 0.5);
765 l->set_use_markup (true);
766 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
769 location_rows.set_name("LocationLocRows");
770 location_rows_scroller.add (location_rows);
771 location_rows_scroller.set_name ("LocationLocRowsScroller");
772 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
773 location_rows_scroller.set_size_request (-1, 130);
777 loc_frame_box.set_spacing (5);
778 loc_frame_box.set_border_width (5);
779 loc_frame_box.set_name("LocationFrameBox");
781 loc_frame_box.pack_start (location_rows_scroller, true, true);
783 add_location_button.set_name ("LocationAddLocationButton");
785 table->attach (loc_frame_box, 0, 2, table_row, table_row + 1);
788 loc_range_panes.pack1 (*table, true, false);
790 table = manage (new Table (3, 2));
791 table->set_spacings (2);
792 table->set_col_spacing (0, 32);
795 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
798 l = manage (new Label (_("<b>Ranges (Including CD Track Ranges)</b>")));
799 l->set_alignment (0, 0.5);
800 l->set_use_markup (true);
801 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
804 range_rows.set_name("LocationRangeRows");
805 range_rows_scroller.add (range_rows);
806 range_rows_scroller.set_name ("LocationRangeRowsScroller");
807 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
808 range_rows_scroller.set_size_request (-1, 130);
810 range_frame_box.set_spacing (5);
811 range_frame_box.set_name("LocationFrameBox");
812 range_frame_box.set_border_width (5);
813 range_frame_box.pack_start (range_rows_scroller, true, true);
815 add_range_button.set_name ("LocationAddRangeButton");
817 table->attach (range_frame_box, 0, 2, table_row, table_row + 1);
820 loc_range_panes.pack2 (*table, true, false);
822 HBox* add_button_box = manage (new HBox);
823 add_button_box->pack_start (add_location_button, true, true);
824 add_button_box->pack_start (add_range_button, true, true);
826 vbox->pack_start (loc_range_panes, true, true);
827 vbox->pack_start (*add_button_box, false, false);
831 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
832 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
836 signal_map().connect (sigc::mem_fun (*this, &LocationUI::refresh_location_list));
839 LocationUI::~LocationUI()
845 LocationUI::do_location_remove (ARDOUR::Location *loc)
847 /* this is handled internally by Locations, but there's
848 no point saving state etc. when we know the marker
852 if (loc->is_session_range()) {
856 _session->begin_reversible_command (_("remove marker"));
857 XMLNode &before = _session->locations()->get_state();
858 _session->locations()->remove (loc);
859 XMLNode &after = _session->locations()->get_state();
860 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
861 _session->commit_reversible_command ();
867 LocationUI::location_remove_requested (ARDOUR::Location *loc)
869 // must do this to prevent problems when destroying
870 // the effective sender of this event
872 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
877 LocationUI::location_redraw_ranges ()
883 struct LocationSortByStart {
884 bool operator() (Location *a, Location *b) {
885 return a->start() < b->start();
890 LocationUI::location_added (Location* location)
892 if (location->is_auto_punch()) {
893 punch_edit_row.set_location(location);
894 } else if (location->is_auto_loop()) {
895 loop_edit_row.set_location(location);
896 } else if (location->is_range_marker() || location->is_mark()) {
897 Locations::LocationList loc = _session->locations()->list ();
898 loc.sort (LocationSortByStart ());
900 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
902 erow->set_clock_group (*_clock_group);
903 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
905 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
907 /* Step through the location list and the GUI list to find the place to insert */
908 Locations::LocationList::iterator i = loc.begin ();
909 Box_Helpers::BoxList::iterator j = children.begin ();
910 while (i != loc.end()) {
912 if (location->flags() != (*i)->flags()) {
913 /* Skip locations in the session list that aren't of the right type */
918 if (*i == location) {
919 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
925 if (j != children.end()) {
930 range_rows.show_all ();
931 location_rows.show_all ();
933 if (location == newest_location) {
941 LocationUI::location_removed (Location* location)
943 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
945 if (location->is_auto_punch()) {
946 punch_edit_row.set_location(0);
947 } else if (location->is_auto_loop()) {
948 loop_edit_row.set_location(0);
949 } else if (location->is_range_marker() || location->is_mark()) {
950 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
951 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
952 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
953 if (r && r->get_location() == location) {
962 LocationUI::map_locations (const Locations::LocationList& locations)
964 Locations::LocationList::iterator i;
967 Locations::LocationList temp = locations;
968 LocationSortByStart cmp;
972 for (n = 0, i = temp.begin(); i != temp.end(); ++n, ++i) {
974 Location* location = *i;
976 if (location->is_mark()) {
977 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
979 erow->set_clock_group (*_clock_group);
980 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
981 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
983 Box_Helpers::BoxList & loc_children = location_rows.children();
984 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
985 } else if (location->is_auto_punch()) {
986 punch_edit_row.set_session (_session);
987 punch_edit_row.set_location (location);
988 punch_edit_row.show_all();
989 } else if (location->is_auto_loop()) {
990 loop_edit_row.set_session (_session);
991 loop_edit_row.set_location (location);
992 loop_edit_row.show_all();
994 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
996 erow->set_clock_group (*_clock_group);
997 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
999 Box_Helpers::BoxList & range_children = range_rows.children();
1000 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
1004 range_rows.show_all();
1005 location_rows.show_all();
1009 LocationUI::add_new_location()
1014 framepos_t where = _session->audible_frame();
1015 _session->locations()->next_available_name(markername,"mark");
1016 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
1017 if (Config->get_name_new_markers()) {
1018 newest_location = location;
1020 _session->begin_reversible_command (_("add marker"));
1021 XMLNode &before = _session->locations()->get_state();
1022 _session->locations()->add (location, true);
1023 XMLNode &after = _session->locations()->get_state();
1024 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1025 _session->commit_reversible_command ();
1031 LocationUI::add_new_range()
1036 framepos_t where = _session->audible_frame();
1037 _session->locations()->next_available_name(rangename,"unnamed");
1038 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
1039 _session->begin_reversible_command (_("add range marker"));
1040 XMLNode &before = _session->locations()->get_state();
1041 _session->locations()->add (location, true);
1042 XMLNode &after = _session->locations()->get_state();
1043 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1044 _session->commit_reversible_command ();
1049 LocationUI::refresh_location_list ()
1051 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
1052 using namespace Box_Helpers;
1054 // this is just too expensive to do when window is not shown
1059 BoxList & loc_children = location_rows.children();
1060 BoxList & range_children = range_rows.children();
1062 loc_children.clear();
1063 range_children.clear();
1066 _session->locations()->apply (*this, &LocationUI::map_locations);
1071 LocationUI::set_session(ARDOUR::Session* s)
1073 SessionHandlePtr::set_session (s);
1076 _session->locations()->added.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_added, this, _1), gui_context());
1077 _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_removed, this, _1), gui_context());
1078 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
1080 _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
1083 loop_edit_row.set_session (s);
1084 punch_edit_row.set_session (s);
1086 refresh_location_list ();
1090 LocationUI::session_going_away()
1092 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
1094 using namespace Box_Helpers;
1095 BoxList & loc_children = location_rows.children();
1096 BoxList & range_children = range_rows.children();
1098 loc_children.clear();
1099 range_children.clear();
1101 loop_edit_row.set_session (0);
1102 loop_edit_row.set_location (0);
1104 punch_edit_row.set_session (0);
1105 punch_edit_row.set_location (0);
1107 SessionHandlePtr::session_going_away ();
1111 LocationUI::get_state () const
1113 XMLNode* node = new XMLNode (X_("LocationUI"));
1114 node->add_property (X_("clock-mode"), enum_2_string (_clock_group->clock_mode ()));
1119 LocationUI::clock_mode_from_session_instant_xml () const
1121 XMLNode* node = _session->instant_xml (X_("LocationUI"));
1123 return AudioClock::Frames;
1126 XMLProperty* p = node->property (X_("clock-mode"));
1128 return ARDOUR_UI::instance()->secondary_clock->mode();
1131 return (AudioClock::Mode) string_2_enum (p->value (), AudioClock::Mode);
1135 /*------------------------*/
1137 LocationUIWindow::LocationUIWindow ()
1138 : ArdourWindow (_("Locations"))
1140 set_wmclass(X_("ardour_locations"), PROGRAM_NAME);
1141 set_name ("LocationWindow");
1146 LocationUIWindow::~LocationUIWindow()
1151 LocationUIWindow::on_map ()
1153 ArdourWindow::on_map ();
1154 _ui.refresh_location_list();
1158 LocationUIWindow::on_delete_event (GdkEventAny*)
1164 LocationUIWindow::set_session (Session *s)
1166 ArdourWindow::set_session (s);
1167 _ui.set_session (s);
1172 LocationUIWindow::session_going_away ()
1174 ArdourWindow::session_going_away ();