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 "gui_thread.h"
32 #include "location_ui.h"
39 using namespace ARDOUR;
42 using namespace Gtkmm2ext;
44 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
45 : SessionHandlePtr (0) /* explicitly set below */
47 , item_table (1, 6, false)
48 , start_clock (X_("locationstart"), true, "", true, false)
49 , start_to_playhead_button (_("Use PH"))
50 , end_clock (X_("locationend"), true, "", true, false)
51 , end_to_playhead_button (_("Use PH"))
52 , length_clock (X_("locationlength"), true, "", true, false, true)
53 , cd_check_button (_("CD"))
54 , hide_check_button (_("Hide"))
55 , lock_check_button (_("Lock"))
56 , glue_check_button (_("Glue"))
59 i_am_the_modifier = 0;
61 remove_button.set_image (*manage (new Image (Stock::REMOVE, Gtk::ICON_SIZE_MENU)));
63 start_to_playhead_button.set_name ("LocationEditCdButton");
64 end_to_playhead_button.set_name ("LocationEditCdButton");
66 number_label.set_name ("LocationEditNumberLabel");
67 name_label.set_name ("LocationEditNameLabel");
68 name_entry.set_name ("LocationEditNameEntry");
69 cd_check_button.set_name ("LocationEditCdButton");
70 hide_check_button.set_name ("LocationEditHideButton");
71 lock_check_button.set_name ("LocationEditLockButton");
72 glue_check_button.set_name ("LocationEditGlueButton");
73 remove_button.set_name ("LocationEditRemoveButton");
74 isrc_label.set_name ("LocationEditNumberLabel");
75 isrc_entry.set_name ("LocationEditNameEntry");
76 scms_check_button.set_name ("LocationEditCdButton");
77 preemph_check_button.set_name ("LocationEditCdButton");
78 performer_label.set_name ("LocationEditNumberLabel");
79 performer_entry.set_name ("LocationEditNameEntry");
80 composer_label.set_name ("LocationEditNumberLabel");
81 composer_entry.set_name ("LocationEditNameEntry");
83 isrc_label.set_text (X_("ISRC:"));
84 performer_label.set_text (_("Performer:"));
85 composer_label.set_text (_("Composer:"));
86 scms_label.set_text (X_("SCMS"));
87 preemph_label.set_text (_("Pre-Emphasis"));
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 Gtk::HBox* front_spacing = manage (new HBox);
102 front_spacing->set_size_request (20, -1);
103 Gtk::HBox* mid_spacing = manage (new HBox);
104 mid_spacing->set_size_request (20, -1);
106 cd_track_details_hbox.set_spacing (4);
107 cd_track_details_hbox.pack_start (*front_spacing, false, false);
108 cd_track_details_hbox.pack_start (isrc_label, false, false);
109 cd_track_details_hbox.pack_start (isrc_entry, false, false);
110 cd_track_details_hbox.pack_start (performer_label, false, false);
111 cd_track_details_hbox.pack_start (performer_entry, true, true);
112 cd_track_details_hbox.pack_start (composer_label, false, false);
113 cd_track_details_hbox.pack_start (composer_entry, true, true);
114 cd_track_details_hbox.pack_start (*mid_spacing, false, false);
115 cd_track_details_hbox.pack_start (scms_label, false, false);
116 cd_track_details_hbox.pack_start (scms_check_button, false, false);
117 cd_track_details_hbox.pack_start (preemph_label, false, false);
118 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
120 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
121 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
122 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
123 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
124 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
128 start_hbox.set_spacing (2);
129 start_hbox.pack_start (start_clock, false, false);
130 start_hbox.pack_start (start_to_playhead_button, false, false);
132 /* this is always in this location, no matter what the location is */
134 VBox *rbox = manage (new VBox);
135 rbox->pack_start (remove_button, false, false);
137 item_table.attach (*rbox, 0, 1, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
138 item_table.attach (start_hbox, 2, 3, 0, 1, FILL, Gtk::AttachOptions(0), 4, 0);
140 start_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocStart));
141 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
142 start_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &start_clock), false);
144 end_hbox.set_spacing (2);
145 end_hbox.pack_start (end_clock, false, false);
146 end_hbox.pack_start (end_to_playhead_button, false, false);
148 end_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocEnd));
149 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
150 end_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &end_clock), false);
152 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
154 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
155 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
156 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
157 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
159 remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
161 pack_start(item_table, true, true);
167 LocationEditRow::~LocationEditRow()
170 connections.drop_connections ();
174 _clock_group->remove (start_clock);
175 _clock_group->remove (end_clock);
176 _clock_group->remove (length_clock);
181 LocationEditRow::set_clock_group (ClockGroup& cg)
184 _clock_group->remove (start_clock);
185 _clock_group->remove (end_clock);
186 _clock_group->remove (length_clock);
191 _clock_group->add (start_clock);
192 _clock_group->add (end_clock);
193 _clock_group->add (length_clock);
197 LocationEditRow::set_session (Session *sess)
199 SessionHandlePtr::set_session (sess);
205 start_clock.set_session (_session);
206 end_clock.set_session (_session);
207 length_clock.set_session (_session);
211 LocationEditRow::set_number (int num)
216 number_label.set_text (string_compose ("%1", number));
221 LocationEditRow::set_location (Location *loc)
224 connections.drop_connections ();
235 if (!hide_check_button.get_parent()) {
236 item_table.attach (hide_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
237 item_table.attach (lock_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
238 item_table.attach (glue_check_button, 8, 9, 0, 1, FILL, Gtk::FILL, 4, 0);
240 hide_check_button.set_active (location->is_hidden());
241 lock_check_button.set_active (location->locked());
242 glue_check_button.set_active (location->position_lock_style() == MusicTime);
244 if (location->is_auto_loop() || location-> is_auto_punch()) {
245 // use label instead of entry
247 name_label.set_text (location->name());
248 name_label.set_size_request (80, -1);
250 remove_button.hide ();
252 if (!name_label.get_parent()) {
253 item_table.attach (name_label, 1, 2, 0, 1, FILL, FILL, 4, 0);
260 name_entry.set_text (location->name());
261 name_entry.set_size_request (100, -1);
262 name_entry.set_editable (true);
263 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
265 if (!name_entry.get_parent()) {
266 item_table.attach (name_entry, 1, 2, 0, 1, FILL | EXPAND, FILL, 4, 0);
270 if (!cd_check_button.get_parent()) {
271 item_table.attach (cd_check_button, 5, 6, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
274 if (location->is_session_range()) {
275 remove_button.set_sensitive (false);
278 cd_check_button.set_active (location->is_cd_marker());
279 cd_check_button.show();
281 if (location->start() == _session->current_start_frame()) {
282 cd_check_button.set_sensitive (false);
284 cd_check_button.set_sensitive (true);
287 hide_check_button.show();
288 lock_check_button.show();
289 glue_check_button.show();
292 start_clock.set (location->start(), true);
295 if (!location->is_mark()) {
296 if (!end_hbox.get_parent()) {
297 item_table.attach (end_hbox, 3, 4, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
299 if (!length_clock.get_parent()) {
300 end_hbox.pack_start (length_clock, false, false);
303 end_clock.set (location->end(), true);
304 length_clock.set (location->length(), true);
309 ARDOUR_UI::instance()->set_tip (remove_button, _("Remove this range"));
310 ARDOUR_UI::instance()->set_tip (start_clock, _("Start time - middle click to locate here"));
311 ARDOUR_UI::instance()->set_tip (end_clock, _("End time - middle click to locate here"));
312 ARDOUR_UI::instance()->set_tip (length_clock, _("Length"));
314 ARDOUR_UI::instance()->tooltips().set_tip (start_to_playhead_button, _("Set range start from playhead location"));
315 ARDOUR_UI::instance()->tooltips().set_tip (end_to_playhead_button, _("Set range end from playhead location"));
319 ARDOUR_UI::instance()->set_tip (remove_button, _("Remove this marker"));
320 ARDOUR_UI::instance()->set_tip (start_clock, _("Position - middle click to locate here"));
322 ARDOUR_UI::instance()->tooltips().set_tip (start_to_playhead_button, _("Set marker time from playhead location"));
328 set_clock_editable_status ();
332 location->start_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::start_changed, this, _1), gui_context());
333 location->end_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::end_changed, this, _1), gui_context());
334 location->name_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::name_changed, this, _1), gui_context());
335 location->changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::location_changed, this, _1), gui_context());
336 location->FlagsChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::flags_changed, this, _1, _2), gui_context());
337 location->LockChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::lock_changed, this, _1), gui_context());
338 location->PositionLockStyleChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::position_lock_style_changed, this, _1), gui_context());
342 LocationEditRow::name_entry_changed ()
344 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed)
346 if (i_am_the_modifier || !location) {
350 location->set_name (name_entry.get_text());
355 LocationEditRow::isrc_entry_changed ()
357 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed)
359 if (i_am_the_modifier || !location) return;
361 if (isrc_entry.get_text() != "" ) {
363 location->cd_info["isrc"] = isrc_entry.get_text();
366 location->cd_info.erase("isrc");
371 LocationEditRow::performer_entry_changed ()
373 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed)
375 if (i_am_the_modifier || !location) return;
377 if (performer_entry.get_text() != "") {
378 location->cd_info["performer"] = performer_entry.get_text();
380 location->cd_info.erase("performer");
385 LocationEditRow::composer_entry_changed ()
387 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed)
389 if (i_am_the_modifier || !location) return;
391 if (composer_entry.get_text() != "") {
392 location->cd_info["composer"] = composer_entry.get_text();
394 location->cd_info.erase("composer");
399 LocationEditRow::to_playhead_button_pressed (LocationPart part)
407 location->set_start (_session->transport_frame ());
410 location->set_end (_session->transport_frame ());
418 LocationEditRow::locate_to_clock (GdkEventButton* ev, AudioClock* clock)
420 if (Keyboard::is_button2_event (ev)) {
421 _session->request_locate (clock->current_time());
428 LocationEditRow::clock_changed (LocationPart part)
430 if (i_am_the_modifier || !location) {
436 location->set_start (start_clock.current_time());
439 location->set_end (end_clock.current_time());
442 location->set_end (location->start() + length_clock.current_duration());
449 LocationEditRow::cd_toggled ()
451 if (i_am_the_modifier || !location) {
455 //if (cd_check_button.get_active() == location->is_cd_marker()) {
459 if (cd_check_button.get_active()) {
460 if (location->start() <= _session->current_start_frame()) {
461 error << _("You cannot put a CD marker at the start of the session") << endmsg;
462 cd_check_button.set_active (false);
467 location->set_cd (cd_check_button.get_active(), this);
469 if (location->is_cd_marker() && !(location->is_mark())) {
471 if (location->cd_info.find("isrc") != location->cd_info.end()) {
472 isrc_entry.set_text(location->cd_info["isrc"]);
474 if (location->cd_info.find("performer") != location->cd_info.end()) {
475 performer_entry.set_text(location->cd_info["performer"]);
477 if (location->cd_info.find("composer") != location->cd_info.end()) {
478 composer_entry.set_text(location->cd_info["composer"]);
480 if (location->cd_info.find("scms") != location->cd_info.end()) {
481 scms_check_button.set_active(true);
483 if (location->cd_info.find("preemph") != location->cd_info.end()) {
484 preemph_check_button.set_active(true);
487 if (!cd_track_details_hbox.get_parent()) {
488 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
490 // item_table.resize(2, 7);
491 cd_track_details_hbox.show_all();
493 } else if (cd_track_details_hbox.get_parent()){
495 item_table.remove (cd_track_details_hbox);
496 // item_table.resize(1, 7);
497 redraw_ranges(); /* EMIT_SIGNAL */
502 LocationEditRow::hide_toggled ()
504 if (i_am_the_modifier || !location) {
508 location->set_hidden (hide_check_button.get_active(), this);
512 LocationEditRow::lock_toggled ()
514 if (i_am_the_modifier || !location) {
518 if (location->locked()) {
526 LocationEditRow::glue_toggled ()
528 if (i_am_the_modifier || !location) {
532 if (location->position_lock_style() == AudioTime) {
533 location->set_position_lock_style (MusicTime);
535 location->set_position_lock_style (AudioTime);
540 LocationEditRow::remove_button_pressed ()
546 remove_requested (location); /* EMIT_SIGNAL */
552 LocationEditRow::scms_toggled ()
554 if (i_am_the_modifier || !location) return;
556 if (scms_check_button.get_active()) {
557 location->cd_info["scms"] = "on";
559 location->cd_info.erase("scms");
565 LocationEditRow::preemph_toggled ()
567 if (i_am_the_modifier || !location) return;
569 if (preemph_check_button.get_active()) {
570 location->cd_info["preemph"] = "on";
572 location->cd_info.erase("preemph");
577 LocationEditRow::end_changed (ARDOUR::Location *)
579 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
581 if (!location) return;
583 // update end and length
586 end_clock.set (location->end());
587 length_clock.set (location->length());
593 LocationEditRow::start_changed (ARDOUR::Location*)
595 if (!location) return;
597 // update end and length
600 start_clock.set (location->start());
602 if (location->start() == _session->current_start_frame()) {
603 cd_check_button.set_sensitive (false);
605 cd_check_button.set_sensitive (true);
612 LocationEditRow::name_changed (ARDOUR::Location *)
614 if (!location) return;
616 // update end and length
619 name_entry.set_text(location->name());
620 name_label.set_text(location->name());
627 LocationEditRow::location_changed (ARDOUR::Location*)
630 if (!location) return;
634 start_clock.set (location->start());
635 end_clock.set (location->end());
636 length_clock.set (location->length());
638 set_clock_editable_status ();
645 LocationEditRow::flags_changed (ARDOUR::Location*, void *)
653 cd_check_button.set_active (location->is_cd_marker());
654 hide_check_button.set_active (location->is_hidden());
655 glue_check_button.set_active (location->position_lock_style() == MusicTime);
661 LocationEditRow::lock_changed (ARDOUR::Location*)
669 lock_check_button.set_active (location->locked());
671 set_clock_editable_status ();
677 LocationEditRow::position_lock_style_changed (ARDOUR::Location*)
685 glue_check_button.set_active (location->position_lock_style() == MusicTime);
691 LocationEditRow::focus_name()
693 name_entry.grab_focus ();
697 LocationEditRow::set_clock_editable_status ()
699 start_clock.set_editable (!location->locked());
700 end_clock.set_editable (!location->locked());
701 length_clock.set_editable (!location->locked());
704 /*------------------------------------------------------------------------*/
706 LocationUI::LocationUI ()
707 : add_location_button (_("New Marker"))
708 , add_range_button (_("New Range"))
710 i_am_the_modifier = 0;
712 _clock_group = new ClockGroup;
714 VBox* vbox = manage (new VBox);
716 Table* table = manage (new Table (2, 2));
717 table->set_spacings (2);
718 table->set_col_spacing (0, 32);
721 Label* l = manage (new Label (_("<b>Loop/Punch Ranges</b>")));
722 l->set_alignment (0, 0.5);
723 l->set_use_markup (true);
724 table->attach (*l, 0, 2, table_row, table_row + 1);
727 loop_edit_row.set_clock_group (*_clock_group);
728 punch_edit_row.set_clock_group (*_clock_group);
730 loop_punch_box.pack_start (loop_edit_row, false, false);
731 loop_punch_box.pack_start (punch_edit_row, false, false);
733 table->attach (loop_punch_box, 1, 2, table_row, table_row + 1);
736 vbox->pack_start (*table, false, false);
738 table = manage (new Table (3, 2));
739 table->set_spacings (2);
740 table->set_col_spacing (0, 32);
743 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
746 l = manage (new Label (_("<b>Markers (Including CD Index)</b>")));
747 l->set_alignment (0, 0.5);
748 l->set_use_markup (true);
749 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
752 location_rows.set_name("LocationLocRows");
753 location_rows_scroller.add (location_rows);
754 location_rows_scroller.set_name ("LocationLocRowsScroller");
755 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
756 location_rows_scroller.set_size_request (-1, 130);
760 loc_frame_box.set_spacing (5);
761 loc_frame_box.set_border_width (5);
762 loc_frame_box.set_name("LocationFrameBox");
764 loc_frame_box.pack_start (location_rows_scroller, true, true);
766 add_location_button.set_name ("LocationAddLocationButton");
768 table->attach (loc_frame_box, 0, 2, table_row, table_row + 1);
771 loc_range_panes.pack1 (*table, true, false);
773 table = manage (new Table (3, 2));
774 table->set_spacings (2);
775 table->set_col_spacing (0, 32);
778 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
781 l = manage (new Label (_("<b>Ranges (Including CD Track Ranges)</b>")));
782 l->set_alignment (0, 0.5);
783 l->set_use_markup (true);
784 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
787 range_rows.set_name("LocationRangeRows");
788 range_rows_scroller.add (range_rows);
789 range_rows_scroller.set_name ("LocationRangeRowsScroller");
790 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
791 range_rows_scroller.set_size_request (-1, 130);
793 range_frame_box.set_spacing (5);
794 range_frame_box.set_name("LocationFrameBox");
795 range_frame_box.set_border_width (5);
796 range_frame_box.pack_start (range_rows_scroller, true, true);
798 add_range_button.set_name ("LocationAddRangeButton");
800 table->attach (range_frame_box, 0, 2, table_row, table_row + 1);
803 loc_range_panes.pack2 (*table, true, false);
805 HBox* add_button_box = manage (new HBox);
806 add_button_box->pack_start (add_location_button, true, true);
807 add_button_box->pack_start (add_range_button, true, true);
809 vbox->pack_start (loc_range_panes, true, true);
810 vbox->pack_start (*add_button_box, false, false);
814 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
815 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
819 signal_map().connect (sigc::mem_fun (*this, &LocationUI::refresh_location_list));
822 LocationUI::~LocationUI()
828 LocationUI::do_location_remove (ARDOUR::Location *loc)
830 /* this is handled internally by Locations, but there's
831 no point saving state etc. when we know the marker
835 if (loc->is_session_range()) {
839 _session->begin_reversible_command (_("remove marker"));
840 XMLNode &before = _session->locations()->get_state();
841 _session->locations()->remove (loc);
842 XMLNode &after = _session->locations()->get_state();
843 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
844 _session->commit_reversible_command ();
850 LocationUI::location_remove_requested (ARDOUR::Location *loc)
852 // must do this to prevent problems when destroying
853 // the effective sender of this event
855 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
860 LocationUI::location_redraw_ranges ()
866 struct LocationSortByStart {
867 bool operator() (Location *a, Location *b) {
868 return a->start() < b->start();
873 LocationUI::location_added (Location* location)
875 if (location->is_auto_punch()) {
876 punch_edit_row.set_location(location);
877 } else if (location->is_auto_loop()) {
878 loop_edit_row.set_location(location);
879 } else if (location->is_range_marker() || location->is_mark()) {
880 Locations::LocationList loc = _session->locations()->list ();
881 loc.sort (LocationSortByStart ());
883 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
885 erow->set_clock_group (*_clock_group);
886 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
888 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
890 /* Step through the location list and the GUI list to find the place to insert */
891 Locations::LocationList::iterator i = loc.begin ();
892 Box_Helpers::BoxList::iterator j = children.begin ();
893 while (i != loc.end()) {
895 if (location->flags() != (*i)->flags()) {
896 /* Skip locations in the session list that aren't of the right type */
901 if (*i == location) {
902 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
908 if (j != children.end()) {
913 range_rows.show_all ();
914 location_rows.show_all ();
916 if (location == newest_location) {
924 LocationUI::location_removed (Location* location)
926 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
928 if (location->is_auto_punch()) {
929 punch_edit_row.set_location(0);
930 } else if (location->is_auto_loop()) {
931 loop_edit_row.set_location(0);
932 } else if (location->is_range_marker() || location->is_mark()) {
933 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
934 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
935 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
936 if (r && r->get_location() == location) {
945 LocationUI::map_locations (Locations::LocationList& locations)
947 Locations::LocationList::iterator i;
950 Locations::LocationList temp = locations;
951 LocationSortByStart cmp;
956 for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
958 Location* location = *i;
960 if (location->is_mark()) {
961 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
963 erow->set_clock_group (*_clock_group);
964 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
965 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
967 Box_Helpers::BoxList & loc_children = location_rows.children();
968 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
969 } else if (location->is_auto_punch()) {
970 punch_edit_row.set_session (_session);
971 punch_edit_row.set_location (location);
972 punch_edit_row.show_all();
973 } else if (location->is_auto_loop()) {
974 loop_edit_row.set_session (_session);
975 loop_edit_row.set_location (location);
976 loop_edit_row.show_all();
978 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
980 erow->set_clock_group (*_clock_group);
981 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
983 Box_Helpers::BoxList & range_children = range_rows.children();
984 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
988 range_rows.show_all();
989 location_rows.show_all();
993 LocationUI::add_new_location()
998 framepos_t where = _session->audible_frame();
999 _session->locations()->next_available_name(markername,"mark");
1000 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
1001 if (Config->get_name_new_markers()) {
1002 newest_location = location;
1004 _session->begin_reversible_command (_("add marker"));
1005 XMLNode &before = _session->locations()->get_state();
1006 _session->locations()->add (location, true);
1007 XMLNode &after = _session->locations()->get_state();
1008 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1009 _session->commit_reversible_command ();
1015 LocationUI::add_new_range()
1020 framepos_t where = _session->audible_frame();
1021 _session->locations()->next_available_name(rangename,"unnamed");
1022 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
1023 _session->begin_reversible_command (_("add range marker"));
1024 XMLNode &before = _session->locations()->get_state();
1025 _session->locations()->add (location, true);
1026 XMLNode &after = _session->locations()->get_state();
1027 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1028 _session->commit_reversible_command ();
1033 LocationUI::refresh_location_list ()
1035 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
1036 using namespace Box_Helpers;
1038 // this is just too expensive to do when window is not shown
1043 BoxList & loc_children = location_rows.children();
1044 BoxList & range_children = range_rows.children();
1046 loc_children.clear();
1047 range_children.clear();
1050 _session->locations()->apply (*this, &LocationUI::map_locations);
1055 LocationUI::set_session(ARDOUR::Session* s)
1057 SessionHandlePtr::set_session (s);
1060 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::locations_changed, this, _1), gui_context());
1061 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
1062 _session->locations()->added.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_added, this, _1), gui_context());
1063 _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_removed, this, _1), gui_context());
1064 _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
1067 loop_edit_row.set_session (s);
1068 punch_edit_row.set_session (s);
1070 refresh_location_list ();
1074 LocationUI::locations_changed (Locations::Change c)
1076 /* removal is signalled by both a removed and a changed signal emission from Locations,
1077 so we don't need to refresh the list on a removal
1079 if (c != Locations::REMOVAL) {
1080 refresh_location_list ();
1085 LocationUI::session_going_away()
1087 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
1089 using namespace Box_Helpers;
1090 BoxList & loc_children = location_rows.children();
1091 BoxList & range_children = range_rows.children();
1093 loc_children.clear();
1094 range_children.clear();
1096 loop_edit_row.set_session (0);
1097 loop_edit_row.set_location (0);
1099 punch_edit_row.set_session (0);
1100 punch_edit_row.set_location (0);
1102 SessionHandlePtr::session_going_away ();
1106 LocationUI::get_state () const
1108 XMLNode* node = new XMLNode (X_("LocationUI"));
1109 node->add_property (X_("clock-mode"), enum_2_string (_clock_group->clock_mode ()));
1114 LocationUI::clock_mode_from_session_instant_xml () const
1116 XMLNode* node = _session->instant_xml (X_("LocationUI"));
1118 return AudioClock::Frames;
1121 XMLProperty* p = node->property (X_("clock-mode"));
1123 return AudioClock::Frames;
1126 return (AudioClock::Mode) string_2_enum (p->value (), AudioClock::Mode);
1130 /*------------------------*/
1132 LocationUIWindow::LocationUIWindow ()
1133 : ArdourWindow (_("Locations"))
1135 set_wmclass(X_("ardour_locations"), PROGRAM_NAME);
1136 set_name ("LocationWindow");
1141 LocationUIWindow::~LocationUIWindow()
1146 LocationUIWindow::on_map ()
1148 ArdourWindow::on_map ();
1149 _ui.refresh_location_list();
1153 LocationUIWindow::on_delete_event (GdkEventAny*)
1160 LocationUIWindow::set_session (Session *s)
1162 ArdourWindow::set_session (s);
1163 _ui.set_session (s);
1167 LocationUIWindow::session_going_away ()
1169 ArdourWindow::session_going_away ();