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 number_label.set_name ("LocationEditNumberLabel");
64 name_label.set_name ("LocationEditNameLabel");
65 name_entry.set_name ("LocationEditNameEntry");
66 cd_check_button.set_name ("LocationEditCdButton");
67 hide_check_button.set_name ("LocationEditHideButton");
68 lock_check_button.set_name ("LocationEditLockButton");
69 glue_check_button.set_name ("LocationEditGlueButton");
70 remove_button.set_name ("LocationEditRemoveButton");
71 isrc_label.set_name ("LocationEditNumberLabel");
72 isrc_entry.set_name ("LocationEditNameEntry");
73 scms_check_button.set_name ("LocationEditCdButton");
74 preemph_check_button.set_name ("LocationEditCdButton");
75 performer_label.set_name ("LocationEditNumberLabel");
76 performer_entry.set_name ("LocationEditNameEntry");
77 composer_label.set_name ("LocationEditNumberLabel");
78 composer_entry.set_name ("LocationEditNameEntry");
80 isrc_label.set_text (X_("ISRC:"));
81 performer_label.set_text (_("Performer:"));
82 composer_label.set_text (_("Composer:"));
83 scms_label.set_text (X_("SCMS"));
84 preemph_label.set_text (_("Pre-Emphasis"));
86 isrc_entry.set_size_request (112, -1);
87 isrc_entry.set_max_length(12);
88 isrc_entry.set_editable (true);
90 performer_entry.set_size_request (100, -1);
91 performer_entry.set_editable (true);
93 composer_entry.set_size_request (100, -1);
94 composer_entry.set_editable (true);
96 name_label.set_alignment (0, 0.5);
98 Gtk::HBox* front_spacing = manage (new HBox);
99 front_spacing->set_size_request (20, -1);
100 Gtk::HBox* mid_spacing = manage (new HBox);
101 mid_spacing->set_size_request (20, -1);
103 cd_track_details_hbox.set_spacing (4);
104 cd_track_details_hbox.pack_start (*front_spacing, false, false);
105 cd_track_details_hbox.pack_start (isrc_label, false, false);
106 cd_track_details_hbox.pack_start (isrc_entry, false, false);
107 cd_track_details_hbox.pack_start (performer_label, false, false);
108 cd_track_details_hbox.pack_start (performer_entry, true, true);
109 cd_track_details_hbox.pack_start (composer_label, false, false);
110 cd_track_details_hbox.pack_start (composer_entry, true, true);
111 cd_track_details_hbox.pack_start (*mid_spacing, false, false);
112 cd_track_details_hbox.pack_start (scms_label, false, false);
113 cd_track_details_hbox.pack_start (scms_check_button, false, false);
114 cd_track_details_hbox.pack_start (preemph_label, false, false);
115 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
117 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
118 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
119 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
120 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
121 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
125 start_hbox.set_spacing (2);
126 start_hbox.pack_start (start_clock, false, false);
127 start_hbox.pack_start (start_to_playhead_button, false, false);
129 /* this is always in this location, no matter what the location is */
131 VBox *rbox = manage (new VBox);
132 rbox->pack_start (remove_button, false, false);
134 item_table.attach (*rbox, 0, 1, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
135 item_table.attach (start_hbox, 2, 3, 0, 1, FILL, Gtk::AttachOptions(0), 4, 0);
137 start_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocStart));
138 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
139 start_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &start_clock), false);
141 end_hbox.set_spacing (2);
142 end_hbox.pack_start (end_clock, false, false);
143 end_hbox.pack_start (end_to_playhead_button, false, false);
145 end_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocEnd));
146 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
147 end_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &end_clock), false);
149 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
151 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
152 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
153 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
154 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
156 remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
158 pack_start(item_table, true, true);
164 LocationEditRow::~LocationEditRow()
167 connections.drop_connections ();
171 _clock_group->remove (start_clock);
172 _clock_group->remove (end_clock);
173 _clock_group->remove (length_clock);
178 LocationEditRow::set_clock_group (ClockGroup& cg)
181 _clock_group->remove (start_clock);
182 _clock_group->remove (end_clock);
183 _clock_group->remove (length_clock);
188 _clock_group->add (start_clock);
189 _clock_group->add (end_clock);
190 _clock_group->add (length_clock);
194 LocationEditRow::set_session (Session *sess)
196 SessionHandlePtr::set_session (sess);
202 start_clock.set_session (_session);
203 end_clock.set_session (_session);
204 length_clock.set_session (_session);
208 LocationEditRow::set_number (int num)
213 number_label.set_text (string_compose ("%1", number));
218 LocationEditRow::set_location (Location *loc)
221 connections.drop_connections ();
232 if (!hide_check_button.get_parent()) {
233 item_table.attach (hide_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
234 item_table.attach (lock_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
235 item_table.attach (glue_check_button, 8, 9, 0, 1, FILL, Gtk::FILL, 4, 0);
237 hide_check_button.set_active (location->is_hidden());
238 lock_check_button.set_active (location->locked());
239 glue_check_button.set_active (location->position_lock_style() == MusicTime);
241 if (location->is_auto_loop() || location-> is_auto_punch()) {
242 // use label instead of entry
244 name_label.set_text (location->name());
245 name_label.set_size_request (80, -1);
247 remove_button.hide ();
249 if (!name_label.get_parent()) {
250 item_table.attach (name_label, 1, 2, 0, 1, FILL, FILL, 4, 0);
257 name_entry.set_text (location->name());
258 name_entry.set_size_request (100, -1);
259 name_entry.set_editable (true);
260 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
262 if (!name_entry.get_parent()) {
263 item_table.attach (name_entry, 1, 2, 0, 1, FILL | EXPAND, FILL, 4, 0);
267 if (!cd_check_button.get_parent()) {
268 item_table.attach (cd_check_button, 5, 6, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
271 if (location->is_session_range()) {
272 remove_button.set_sensitive (false);
275 cd_check_button.set_active (location->is_cd_marker());
276 cd_check_button.show();
278 if (location->start() == _session->current_start_frame()) {
279 cd_check_button.set_sensitive (false);
281 cd_check_button.set_sensitive (true);
284 hide_check_button.show();
285 lock_check_button.show();
286 glue_check_button.show();
289 start_clock.set (location->start(), true);
292 if (!location->is_mark()) {
293 if (!end_hbox.get_parent()) {
294 item_table.attach (end_hbox, 3, 4, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
296 if (!length_clock.get_parent()) {
297 end_hbox.pack_start (length_clock, false, false);
300 end_clock.set (location->end(), true);
301 length_clock.set (location->length(), true);
306 ARDOUR_UI::instance()->set_tip (remove_button, _("Remove this range"));
307 ARDOUR_UI::instance()->set_tip (start_clock, _("Start time - middle click to locate here"));
308 ARDOUR_UI::instance()->set_tip (end_clock, _("End time - middle click to locate here"));
309 ARDOUR_UI::instance()->set_tip (length_clock, _("Length"));
311 ARDOUR_UI::instance()->tooltips().set_tip (start_to_playhead_button, _("Set range start from playhead location"));
312 ARDOUR_UI::instance()->tooltips().set_tip (end_to_playhead_button, _("Set range end from playhead location"));
316 ARDOUR_UI::instance()->set_tip (remove_button, _("Remove this marker"));
317 ARDOUR_UI::instance()->set_tip (start_clock, _("Position - middle click to locate here"));
319 ARDOUR_UI::instance()->tooltips().set_tip (start_to_playhead_button, _("Set marker time from playhead location"));
325 set_clock_editable_status ();
329 location->start_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::start_changed, this, _1), gui_context());
330 location->end_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::end_changed, this, _1), gui_context());
331 location->name_changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::name_changed, this, _1), gui_context());
332 location->changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::location_changed, this, _1), gui_context());
333 location->FlagsChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::flags_changed, this, _1, _2), gui_context());
334 location->LockChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::lock_changed, this, _1), gui_context());
335 location->PositionLockStyleChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::position_lock_style_changed, this, _1), gui_context());
339 LocationEditRow::name_entry_changed ()
341 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed)
343 if (i_am_the_modifier || !location) {
347 location->set_name (name_entry.get_text());
352 LocationEditRow::isrc_entry_changed ()
354 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed)
356 if (i_am_the_modifier || !location) return;
358 if (isrc_entry.get_text() != "" ) {
360 location->cd_info["isrc"] = isrc_entry.get_text();
363 location->cd_info.erase("isrc");
368 LocationEditRow::performer_entry_changed ()
370 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed)
372 if (i_am_the_modifier || !location) return;
374 if (performer_entry.get_text() != "") {
375 location->cd_info["performer"] = performer_entry.get_text();
377 location->cd_info.erase("performer");
382 LocationEditRow::composer_entry_changed ()
384 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed)
386 if (i_am_the_modifier || !location) return;
388 if (composer_entry.get_text() != "") {
389 location->cd_info["composer"] = composer_entry.get_text();
391 location->cd_info.erase("composer");
396 LocationEditRow::to_playhead_button_pressed (LocationPart part)
404 location->set_start (_session->transport_frame ());
407 location->set_end (_session->transport_frame ());
415 LocationEditRow::locate_to_clock (GdkEventButton* ev, AudioClock* clock)
417 if (Keyboard::is_button2_event (ev)) {
418 _session->request_locate (clock->current_time());
425 LocationEditRow::clock_changed (LocationPart part)
427 if (i_am_the_modifier || !location) {
433 location->set_start (start_clock.current_time());
436 location->set_end (end_clock.current_time());
439 location->set_end (location->start() + length_clock.current_duration());
446 LocationEditRow::cd_toggled ()
448 if (i_am_the_modifier || !location) {
452 //if (cd_check_button.get_active() == location->is_cd_marker()) {
456 if (cd_check_button.get_active()) {
457 if (location->start() <= _session->current_start_frame()) {
458 error << _("You cannot put a CD marker at the start of the session") << endmsg;
459 cd_check_button.set_active (false);
464 location->set_cd (cd_check_button.get_active(), this);
466 if (location->is_cd_marker() && !(location->is_mark())) {
468 if (location->cd_info.find("isrc") != location->cd_info.end()) {
469 isrc_entry.set_text(location->cd_info["isrc"]);
471 if (location->cd_info.find("performer") != location->cd_info.end()) {
472 performer_entry.set_text(location->cd_info["performer"]);
474 if (location->cd_info.find("composer") != location->cd_info.end()) {
475 composer_entry.set_text(location->cd_info["composer"]);
477 if (location->cd_info.find("scms") != location->cd_info.end()) {
478 scms_check_button.set_active(true);
480 if (location->cd_info.find("preemph") != location->cd_info.end()) {
481 preemph_check_button.set_active(true);
484 if (!cd_track_details_hbox.get_parent()) {
485 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
487 // item_table.resize(2, 7);
488 cd_track_details_hbox.show_all();
490 } else if (cd_track_details_hbox.get_parent()){
492 item_table.remove (cd_track_details_hbox);
493 // item_table.resize(1, 7);
494 redraw_ranges(); /* EMIT_SIGNAL */
499 LocationEditRow::hide_toggled ()
501 if (i_am_the_modifier || !location) {
505 location->set_hidden (hide_check_button.get_active(), this);
509 LocationEditRow::lock_toggled ()
511 if (i_am_the_modifier || !location) {
515 if (location->locked()) {
523 LocationEditRow::glue_toggled ()
525 if (i_am_the_modifier || !location) {
529 if (location->position_lock_style() == AudioTime) {
530 location->set_position_lock_style (MusicTime);
532 location->set_position_lock_style (AudioTime);
537 LocationEditRow::remove_button_pressed ()
543 remove_requested (location); /* EMIT_SIGNAL */
549 LocationEditRow::scms_toggled ()
551 if (i_am_the_modifier || !location) return;
553 if (scms_check_button.get_active()) {
554 location->cd_info["scms"] = "on";
556 location->cd_info.erase("scms");
562 LocationEditRow::preemph_toggled ()
564 if (i_am_the_modifier || !location) return;
566 if (preemph_check_button.get_active()) {
567 location->cd_info["preemph"] = "on";
569 location->cd_info.erase("preemph");
574 LocationEditRow::end_changed (ARDOUR::Location *)
576 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
578 if (!location) return;
580 // update end and length
583 end_clock.set (location->end());
584 length_clock.set (location->length());
590 LocationEditRow::start_changed (ARDOUR::Location*)
592 if (!location) return;
594 // update end and length
597 start_clock.set (location->start());
599 if (location->start() == _session->current_start_frame()) {
600 cd_check_button.set_sensitive (false);
602 cd_check_button.set_sensitive (true);
609 LocationEditRow::name_changed (ARDOUR::Location *)
611 if (!location) return;
613 // update end and length
616 name_entry.set_text(location->name());
617 name_label.set_text(location->name());
624 LocationEditRow::location_changed (ARDOUR::Location*)
627 if (!location) return;
631 start_clock.set (location->start());
632 end_clock.set (location->end());
633 length_clock.set (location->length());
635 set_clock_editable_status ();
642 LocationEditRow::flags_changed (ARDOUR::Location*, void *)
650 cd_check_button.set_active (location->is_cd_marker());
651 hide_check_button.set_active (location->is_hidden());
652 glue_check_button.set_active (location->position_lock_style() == MusicTime);
658 LocationEditRow::lock_changed (ARDOUR::Location*)
666 lock_check_button.set_active (location->locked());
668 set_clock_editable_status ();
674 LocationEditRow::position_lock_style_changed (ARDOUR::Location*)
682 glue_check_button.set_active (location->position_lock_style() == MusicTime);
688 LocationEditRow::focus_name()
690 name_entry.grab_focus ();
694 LocationEditRow::set_clock_editable_status ()
696 start_clock.set_editable (!location->locked());
697 end_clock.set_editable (!location->locked());
698 length_clock.set_editable (!location->locked());
701 /*------------------------------------------------------------------------*/
703 LocationUI::LocationUI ()
704 : add_location_button (_("New Marker"))
705 , add_range_button (_("New Range"))
707 i_am_the_modifier = 0;
709 _clock_group = new ClockGroup;
711 VBox* vbox = manage (new VBox);
713 Table* table = manage (new Table (2, 2));
714 table->set_spacings (2);
715 table->set_col_spacing (0, 32);
718 Label* l = manage (new Label (_("<b>Loop/Punch Ranges</b>")));
719 l->set_alignment (0, 0.5);
720 l->set_use_markup (true);
721 table->attach (*l, 0, 2, table_row, table_row + 1);
724 loop_edit_row.set_clock_group (*_clock_group);
725 punch_edit_row.set_clock_group (*_clock_group);
727 loop_punch_box.pack_start (loop_edit_row, false, false);
728 loop_punch_box.pack_start (punch_edit_row, false, false);
730 table->attach (loop_punch_box, 1, 2, table_row, table_row + 1);
733 vbox->pack_start (*table, false, false);
735 table = manage (new Table (3, 2));
736 table->set_spacings (2);
737 table->set_col_spacing (0, 32);
740 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
743 l = manage (new Label (_("<b>Markers (Including CD Index)</b>")));
744 l->set_alignment (0, 0.5);
745 l->set_use_markup (true);
746 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
749 location_rows.set_name("LocationLocRows");
750 location_rows_scroller.add (location_rows);
751 location_rows_scroller.set_name ("LocationLocRowsScroller");
752 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
753 location_rows_scroller.set_size_request (-1, 130);
757 loc_frame_box.set_spacing (5);
758 loc_frame_box.set_border_width (5);
759 loc_frame_box.set_name("LocationFrameBox");
761 loc_frame_box.pack_start (location_rows_scroller, true, true);
763 add_location_button.set_name ("LocationAddLocationButton");
765 table->attach (loc_frame_box, 0, 2, table_row, table_row + 1);
768 loc_range_panes.pack1 (*table, true, false);
770 table = manage (new Table (3, 2));
771 table->set_spacings (2);
772 table->set_col_spacing (0, 32);
775 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
778 l = manage (new Label (_("<b>Ranges (Including CD Track Ranges)</b>")));
779 l->set_alignment (0, 0.5);
780 l->set_use_markup (true);
781 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
784 range_rows.set_name("LocationRangeRows");
785 range_rows_scroller.add (range_rows);
786 range_rows_scroller.set_name ("LocationRangeRowsScroller");
787 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
788 range_rows_scroller.set_size_request (-1, 130);
790 range_frame_box.set_spacing (5);
791 range_frame_box.set_name("LocationFrameBox");
792 range_frame_box.set_border_width (5);
793 range_frame_box.pack_start (range_rows_scroller, true, true);
795 add_range_button.set_name ("LocationAddRangeButton");
797 table->attach (range_frame_box, 0, 2, table_row, table_row + 1);
800 loc_range_panes.pack2 (*table, true, false);
802 HBox* add_button_box = manage (new HBox);
803 add_button_box->pack_start (add_location_button, true, true);
804 add_button_box->pack_start (add_range_button, true, true);
806 vbox->pack_start (loc_range_panes, true, true);
807 vbox->pack_start (*add_button_box, false, false);
811 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
812 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
816 signal_map().connect (sigc::mem_fun (*this, &LocationUI::refresh_location_list));
819 LocationUI::~LocationUI()
825 LocationUI::do_location_remove (ARDOUR::Location *loc)
827 /* this is handled internally by Locations, but there's
828 no point saving state etc. when we know the marker
832 if (loc->is_session_range()) {
836 _session->begin_reversible_command (_("remove marker"));
837 XMLNode &before = _session->locations()->get_state();
838 _session->locations()->remove (loc);
839 XMLNode &after = _session->locations()->get_state();
840 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
841 _session->commit_reversible_command ();
847 LocationUI::location_remove_requested (ARDOUR::Location *loc)
849 // must do this to prevent problems when destroying
850 // the effective sender of this event
852 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
857 LocationUI::location_redraw_ranges ()
863 struct LocationSortByStart {
864 bool operator() (Location *a, Location *b) {
865 return a->start() < b->start();
870 LocationUI::location_added (Location* location)
872 if (location->is_auto_punch()) {
873 punch_edit_row.set_location(location);
874 } else if (location->is_auto_loop()) {
875 loop_edit_row.set_location(location);
876 } else if (location->is_range_marker() || location->is_mark()) {
877 Locations::LocationList loc = _session->locations()->list ();
878 loc.sort (LocationSortByStart ());
880 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
882 erow->set_clock_group (*_clock_group);
883 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
885 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
887 /* Step through the location list and the GUI list to find the place to insert */
888 Locations::LocationList::iterator i = loc.begin ();
889 Box_Helpers::BoxList::iterator j = children.begin ();
890 while (i != loc.end()) {
892 if (location->flags() != (*i)->flags()) {
893 /* Skip locations in the session list that aren't of the right type */
898 if (*i == location) {
899 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
905 if (j != children.end()) {
910 range_rows.show_all ();
911 location_rows.show_all ();
913 if (location == newest_location) {
921 LocationUI::location_removed (Location* location)
923 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
925 if (location->is_auto_punch()) {
926 punch_edit_row.set_location(0);
927 } else if (location->is_auto_loop()) {
928 loop_edit_row.set_location(0);
929 } else if (location->is_range_marker() || location->is_mark()) {
930 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
931 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
932 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
933 if (r && r->get_location() == location) {
942 LocationUI::map_locations (Locations::LocationList& locations)
944 Locations::LocationList::iterator i;
947 Locations::LocationList temp = locations;
948 LocationSortByStart cmp;
953 for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
955 Location* location = *i;
957 if (location->is_mark()) {
958 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
960 erow->set_clock_group (*_clock_group);
961 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
962 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
964 Box_Helpers::BoxList & loc_children = location_rows.children();
965 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
966 } else if (location->is_auto_punch()) {
967 punch_edit_row.set_session (_session);
968 punch_edit_row.set_location (location);
969 punch_edit_row.show_all();
970 } else if (location->is_auto_loop()) {
971 loop_edit_row.set_session (_session);
972 loop_edit_row.set_location (location);
973 loop_edit_row.show_all();
975 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
977 erow->set_clock_group (*_clock_group);
978 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
980 Box_Helpers::BoxList & range_children = range_rows.children();
981 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
985 range_rows.show_all();
986 location_rows.show_all();
990 LocationUI::add_new_location()
995 framepos_t where = _session->audible_frame();
996 _session->locations()->next_available_name(markername,"mark");
997 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
998 if (Config->get_name_new_markers()) {
999 newest_location = location;
1001 _session->begin_reversible_command (_("add marker"));
1002 XMLNode &before = _session->locations()->get_state();
1003 _session->locations()->add (location, true);
1004 XMLNode &after = _session->locations()->get_state();
1005 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1006 _session->commit_reversible_command ();
1012 LocationUI::add_new_range()
1017 framepos_t where = _session->audible_frame();
1018 _session->locations()->next_available_name(rangename,"unnamed");
1019 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
1020 _session->begin_reversible_command (_("add range 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 ();
1030 LocationUI::refresh_location_list ()
1032 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
1033 using namespace Box_Helpers;
1035 // this is just too expensive to do when window is not shown
1040 BoxList & loc_children = location_rows.children();
1041 BoxList & range_children = range_rows.children();
1043 loc_children.clear();
1044 range_children.clear();
1047 _session->locations()->apply (*this, &LocationUI::map_locations);
1052 LocationUI::set_session(ARDOUR::Session* s)
1054 SessionHandlePtr::set_session (s);
1057 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::locations_changed, this, _1), gui_context());
1058 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
1059 _session->locations()->added.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_added, this, _1), gui_context());
1060 _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_removed, this, _1), gui_context());
1061 _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
1064 loop_edit_row.set_session (s);
1065 punch_edit_row.set_session (s);
1067 refresh_location_list ();
1071 LocationUI::locations_changed (Locations::Change c)
1073 /* removal is signalled by both a removed and a changed signal emission from Locations,
1074 so we don't need to refresh the list on a removal
1076 if (c != Locations::REMOVAL) {
1077 refresh_location_list ();
1082 LocationUI::session_going_away()
1084 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
1086 using namespace Box_Helpers;
1087 BoxList & loc_children = location_rows.children();
1088 BoxList & range_children = range_rows.children();
1090 loc_children.clear();
1091 range_children.clear();
1093 loop_edit_row.set_session (0);
1094 loop_edit_row.set_location (0);
1096 punch_edit_row.set_session (0);
1097 punch_edit_row.set_location (0);
1099 SessionHandlePtr::session_going_away ();
1103 LocationUI::get_state () const
1105 XMLNode* node = new XMLNode (X_("LocationUI"));
1106 node->add_property (X_("clock-mode"), enum_2_string (_clock_group->clock_mode ()));
1111 LocationUI::clock_mode_from_session_instant_xml () const
1113 XMLNode* node = _session->instant_xml (X_("LocationUI"));
1115 return AudioClock::Frames;
1118 XMLProperty* p = node->property (X_("clock-mode"));
1120 return AudioClock::Frames;
1123 return (AudioClock::Mode) string_2_enum (p->value (), AudioClock::Mode);
1127 /*------------------------*/
1129 LocationUIWindow::LocationUIWindow ()
1130 : ArdourWindow (_("Locations"))
1132 set_wmclass(X_("ardour_locations"), PROGRAM_NAME);
1133 set_name ("LocationWindow");
1138 LocationUIWindow::~LocationUIWindow()
1143 LocationUIWindow::on_map ()
1145 ArdourWindow::on_map ();
1146 _ui.refresh_location_list();
1150 LocationUIWindow::on_delete_event (GdkEventAny*)
1157 LocationUIWindow::set_session (Session *s)
1159 ArdourWindow::set_session (s);
1160 _ui.set_session (s);
1164 LocationUIWindow::session_going_away ()
1166 ArdourWindow::session_going_away ();