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/utils.h"
26 #include "ardour/configuration.h"
27 #include "ardour/session.h"
28 #include "pbd/memento_command.h"
30 #include "ardour_ui.h"
31 #include "clock_group.h"
32 #include "gui_thread.h"
34 #include "location_ui.h"
41 using namespace ARDOUR;
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 , end_clock (X_("locationend"), true, "", true, false)
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"))
57 , scms_check_button (_("SCMS"))
58 , preemph_check_button (_("Pre-Emphasis"))
61 i_am_the_modifier = 0;
63 start_go_button.set_image (*manage (new Image (Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
64 end_go_button.set_image (*manage (new Image (Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
65 remove_button.set_image (*manage (new Image (Stock::REMOVE, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
67 number_label.set_name ("LocationEditNumberLabel");
68 name_label.set_name ("LocationEditNameLabel");
69 name_entry.set_name ("LocationEditNameEntry");
70 start_go_button.set_name ("LocationEditGoButton");
71 end_go_button.set_name ("LocationEditGoButton");
72 cd_check_button.set_name ("LocationEditCdButton");
73 hide_check_button.set_name ("LocationEditHideButton");
74 lock_check_button.set_name ("LocationEditLockButton");
75 glue_check_button.set_name ("LocationEditGlueButton");
76 remove_button.set_name ("LocationEditRemoveButton");
77 isrc_label.set_name ("LocationEditNumberLabel");
78 isrc_entry.set_name ("LocationEditNameEntry");
79 scms_check_button.set_name ("LocationEditCdButton");
80 preemph_check_button.set_name ("LocationEditCdButton");
81 performer_label.set_name ("LocationEditNumberLabel");
82 performer_entry.set_name ("LocationEditNameEntry");
83 composer_label.set_name ("LocationEditNumberLabel");
84 composer_entry.set_name ("LocationEditNameEntry");
86 Gtk::Button* start_to_playhead_button = manage (new Button (_("Use PH")));
87 Gtk::Button* end_to_playhead_button = manage (new Button (_("Use PH")));
89 ARDOUR_UI::instance()->tooltips().set_tip (*start_to_playhead_button, _("Set value to playhead"));
90 ARDOUR_UI::instance()->tooltips().set_tip (*end_to_playhead_button, _("Set value to playhead"));
92 isrc_label.set_text ("ISRC: ");
93 isrc_label.set_size_request (30, -1);
94 performer_label.set_text ("Performer: ");
95 performer_label.set_size_request (60, -1);
96 composer_label.set_text ("Composer: ");
97 composer_label.set_size_request (60, -1);
99 isrc_entry.set_size_request (112, -1);
100 isrc_entry.set_max_length(12);
101 isrc_entry.set_editable (true);
103 performer_entry.set_size_request (100, -1);
104 performer_entry.set_editable (true);
106 composer_entry.set_size_request (100, -1);
107 composer_entry.set_editable (true);
109 name_label.set_alignment (0, 0.5);
111 cd_track_details_hbox.pack_start (isrc_label, false, false);
112 cd_track_details_hbox.pack_start (isrc_entry, false, false);
113 cd_track_details_hbox.pack_start (scms_check_button, false, false);
114 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
115 cd_track_details_hbox.pack_start (performer_label, false, false);
116 cd_track_details_hbox.pack_start (performer_entry, true, true);
117 cd_track_details_hbox.pack_start (composer_label, false, false);
118 cd_track_details_hbox.pack_start (composer_entry, true, true);
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.pack_start (start_go_button, false, false);
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 item_table.attach (start_hbox, 1, 2, 0, 1, FILL, FILL, 4, 0);
136 start_go_button.signal_clicked().connect(sigc::bind (sigc::mem_fun (*this, &LocationEditRow::go_button_pressed), LocStart));
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));
140 end_hbox.pack_start (end_go_button, false, false);
141 end_hbox.pack_start (end_clock, false, false);
142 end_hbox.pack_start (*end_to_playhead_button, false, false);
144 end_go_button.signal_clicked().connect(sigc::bind (sigc::mem_fun (*this, &LocationEditRow::go_button_pressed), LocEnd));
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));
148 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
150 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
151 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
152 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
153 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
155 remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
157 pack_start(item_table, true, true);
163 LocationEditRow::~LocationEditRow()
166 connections.drop_connections ();
170 _clock_group->remove (start_clock);
171 _clock_group->remove (end_clock);
172 _clock_group->remove (length_clock);
177 LocationEditRow::set_clock_group (ClockGroup& cg)
180 _clock_group->remove (start_clock);
181 _clock_group->remove (end_clock);
182 _clock_group->remove (length_clock);
187 _clock_group->add (start_clock);
188 _clock_group->add (end_clock);
189 _clock_group->add (length_clock);
193 LocationEditRow::set_session (Session *sess)
195 SessionHandlePtr::set_session (sess);
201 start_clock.set_session (_session);
202 end_clock.set_session (_session);
203 length_clock.set_session (_session);
207 LocationEditRow::set_number (int num)
212 number_label.set_text (string_compose ("%1", number));
217 LocationEditRow::set_location (Location *loc)
220 connections.drop_connections ();
231 if (!hide_check_button.get_parent()) {
232 item_table.attach (hide_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
233 item_table.attach (lock_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
234 item_table.attach (glue_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
236 hide_check_button.set_active (location->is_hidden());
237 lock_check_button.set_active (location->locked());
238 glue_check_button.set_active (location->position_lock_style() == MusicTime);
240 if (location->is_auto_loop() || location-> is_auto_punch()) {
241 // use label instead of entry
243 name_label.set_text (location->name());
244 name_label.set_size_request (80, -1);
246 if (!name_label.get_parent()) {
247 item_table.attach (name_label, 0, 1, 0, 1, FILL, FILL, 4, 0);
254 name_entry.set_text (location->name());
255 name_entry.set_size_request (100, -1);
256 name_entry.set_editable (true);
257 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
259 if (!name_entry.get_parent()) {
260 item_table.attach (name_entry, 0, 1, 0, 1, FILL | EXPAND, FILL, 4, 0);
264 if (!cd_check_button.get_parent()) {
265 item_table.attach (cd_check_button, 4, 5, 0, 1, FILL, FILL, 4, 0);
267 if (!remove_button.get_parent()) {
268 item_table.attach (remove_button, 8, 9, 0, 1, FILL, FILL, 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, 2, 3, 0, 1, FILL, FILL, 4, 0);
296 if (!length_clock.get_parent()) {
297 item_table.attach (length_clock, 3, 4, 0, 1, FILL, FILL, 4, 0);
300 end_clock.set (location->end(), true);
301 length_clock.set (location->length(), true);
303 end_go_button.show();
307 ARDOUR_UI::instance()->set_tip (end_go_button, _("Jump to the end of this range"));
308 ARDOUR_UI::instance()->set_tip (start_go_button, _("Jump to the start of this range"));
309 ARDOUR_UI::instance()->set_tip (remove_button, _("Forget this range"));
310 ARDOUR_UI::instance()->set_tip (start_clock, _("Start time"));
311 ARDOUR_UI::instance()->set_tip (end_clock, _("End time"));
312 ARDOUR_UI::instance()->set_tip (length_clock, _("Length"));
316 ARDOUR_UI::instance()->set_tip (start_go_button, _("Jump to this marker"));
317 ARDOUR_UI::instance()->set_tip (remove_button, _("Forget this marker"));
318 ARDOUR_UI::instance()->set_tip (start_clock, _("Position"));
320 end_go_button.hide();
325 set_clock_sensitivity ();
329 location->start_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::start_changed, this, _1), gui_context());
330 location->end_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::end_changed, this, _1), gui_context());
331 location->name_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::name_changed, this, _1), gui_context());
332 location->changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::location_changed, this, _1), gui_context());
333 location->FlagsChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::flags_changed, this, _1, _2), gui_context());
334 location->LockChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::lock_changed, this, _1), gui_context());
335 location->PositionLockStyleChanged.connect (connections, invalidator (*this), ui_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");
397 LocationEditRow::go_button_pressed (LocationPart part)
405 ARDOUR_UI::instance()->do_transport_locate (location->start(), _session->transport_rolling ());
408 ARDOUR_UI::instance()->do_transport_locate (location->end(), _session->transport_rolling ());
416 LocationEditRow::to_playhead_button_pressed (LocationPart part)
424 location->set_start (_session->transport_frame ());
427 location->set_end (_session->transport_frame ());
435 LocationEditRow::clock_changed (LocationPart part)
437 if (i_am_the_modifier || !location) {
443 location->set_start (start_clock.current_time());
446 location->set_end (end_clock.current_time());
449 location->set_end (location->start() + length_clock.current_duration());
456 LocationEditRow::cd_toggled ()
458 if (i_am_the_modifier || !location) {
462 //if (cd_check_button.get_active() == location->is_cd_marker()) {
466 if (cd_check_button.get_active()) {
467 if (location->start() <= _session->current_start_frame()) {
468 error << _("You cannot put a CD marker at the start of the session") << endmsg;
469 cd_check_button.set_active (false);
474 location->set_cd (cd_check_button.get_active(), this);
476 if (location->is_cd_marker() && !(location->is_mark())) {
478 if (location->cd_info.find("isrc") != location->cd_info.end()) {
479 isrc_entry.set_text(location->cd_info["isrc"]);
481 if (location->cd_info.find("performer") != location->cd_info.end()) {
482 performer_entry.set_text(location->cd_info["performer"]);
484 if (location->cd_info.find("composer") != location->cd_info.end()) {
485 composer_entry.set_text(location->cd_info["composer"]);
487 if (location->cd_info.find("scms") != location->cd_info.end()) {
488 scms_check_button.set_active(true);
490 if (location->cd_info.find("preemph") != location->cd_info.end()) {
491 preemph_check_button.set_active(true);
494 if (!cd_track_details_hbox.get_parent()) {
495 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
497 // item_table.resize(2, 7);
498 cd_track_details_hbox.show_all();
500 } else if (cd_track_details_hbox.get_parent()){
502 item_table.remove (cd_track_details_hbox);
503 // item_table.resize(1, 7);
504 redraw_ranges(); /* EMIT_SIGNAL */
509 LocationEditRow::hide_toggled ()
511 if (i_am_the_modifier || !location) {
515 location->set_hidden (hide_check_button.get_active(), this);
519 LocationEditRow::lock_toggled ()
521 if (i_am_the_modifier || !location) {
525 if (location->locked()) {
533 LocationEditRow::glue_toggled ()
535 if (i_am_the_modifier || !location) {
539 if (location->position_lock_style() == AudioTime) {
540 location->set_position_lock_style (MusicTime);
542 location->set_position_lock_style (AudioTime);
547 LocationEditRow::remove_button_pressed ()
553 remove_requested (location); /* EMIT_SIGNAL */
559 LocationEditRow::scms_toggled ()
561 if (i_am_the_modifier || !location) return;
563 if (scms_check_button.get_active()) {
564 location->cd_info["scms"] = "on";
566 location->cd_info.erase("scms");
572 LocationEditRow::preemph_toggled ()
574 if (i_am_the_modifier || !location) return;
576 if (preemph_check_button.get_active()) {
577 location->cd_info["preemph"] = "on";
579 location->cd_info.erase("preemph");
584 LocationEditRow::end_changed (ARDOUR::Location *)
586 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
588 if (!location) return;
590 // update end and length
593 end_clock.set (location->end());
594 length_clock.set (location->length());
600 LocationEditRow::start_changed (ARDOUR::Location*)
602 if (!location) return;
604 // update end and length
607 start_clock.set (location->start());
609 if (location->start() == _session->current_start_frame()) {
610 cd_check_button.set_sensitive (false);
612 cd_check_button.set_sensitive (true);
619 LocationEditRow::name_changed (ARDOUR::Location *)
621 if (!location) return;
623 // update end and length
626 name_entry.set_text(location->name());
627 name_label.set_text(location->name());
634 LocationEditRow::location_changed (ARDOUR::Location*)
637 if (!location) return;
641 start_clock.set (location->start());
642 end_clock.set (location->end());
643 length_clock.set (location->length());
645 set_clock_sensitivity ();
652 LocationEditRow::flags_changed (ARDOUR::Location*, void *)
660 cd_check_button.set_active (location->is_cd_marker());
661 hide_check_button.set_active (location->is_hidden());
662 glue_check_button.set_active (location->position_lock_style() == MusicTime);
668 LocationEditRow::lock_changed (ARDOUR::Location*)
676 lock_check_button.set_active (location->locked());
678 set_clock_sensitivity ();
684 LocationEditRow::position_lock_style_changed (ARDOUR::Location*)
692 glue_check_button.set_active (location->position_lock_style() == MusicTime);
698 LocationEditRow::focus_name() {
699 name_entry.grab_focus();
703 LocationEditRow::set_clock_sensitivity ()
705 start_clock.set_sensitive (!location->locked());
706 end_clock.set_sensitive (!location->locked());
707 length_clock.set_sensitive (!location->locked());
710 /*------------------------------------------------------------------------*/
712 LocationUI::LocationUI ()
713 : add_location_button (_("New Marker"))
714 , add_range_button (_("New Range"))
716 i_am_the_modifier = 0;
718 _clock_group = new ClockGroup;
720 VBox* vbox = manage (new VBox);
722 Table* table = manage (new Table (2, 2));
723 table->set_spacings (4);
724 table->set_col_spacing (0, 32);
727 Label* l = manage (new Label (_("<b>Loop/Punch Ranges</b>")));
728 l->set_alignment (0, 0.5);
729 l->set_use_markup (true);
730 table->attach (*l, 0, 2, table_row, table_row + 1);
733 loop_edit_row.set_clock_group (*_clock_group);
734 punch_edit_row.set_clock_group (*_clock_group);
736 loop_punch_box.pack_start (loop_edit_row, false, false);
737 loop_punch_box.pack_start (punch_edit_row, false, false);
739 table->attach (loop_punch_box, 1, 2, table_row, table_row + 1);
742 vbox->pack_start (*table, false, false);
744 table = manage (new Table (3, 2));
745 table->set_spacings (4);
746 table->set_col_spacing (0, 32);
749 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
752 l = manage (new Label (_("<b>Markers (Including CD Index)</b>")));
753 l->set_alignment (0, 0.5);
754 l->set_use_markup (true);
755 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
758 location_rows.set_name("LocationLocRows");
759 location_rows_scroller.add (location_rows);
760 location_rows_scroller.set_name ("LocationLocRowsScroller");
761 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
762 location_rows_scroller.set_size_request (-1, 130);
766 loc_frame_box.set_spacing (5);
767 loc_frame_box.set_border_width (5);
768 loc_frame_box.set_name("LocationFrameBox");
770 loc_frame_box.pack_start (location_rows_scroller, true, true);
772 add_location_button.set_name ("LocationAddLocationButton");
774 table->attach (loc_frame_box, 1, 2, table_row, table_row + 1);
777 loc_range_panes.pack1 (*table, true, false);
779 table = manage (new Table (3, 2));
780 table->set_spacings (4);
781 table->set_col_spacing (0, 32);
784 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
787 l = manage (new Label (_("<b>Ranges (Including CD Track Ranges)</b>")));
788 l->set_alignment (0, 0.5);
789 l->set_use_markup (true);
790 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
793 range_rows.set_name("LocationRangeRows");
794 range_rows_scroller.add (range_rows);
795 range_rows_scroller.set_name ("LocationRangeRowsScroller");
796 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
797 range_rows_scroller.set_size_request (-1, 130);
799 range_frame_box.set_spacing (5);
800 range_frame_box.set_name("LocationFrameBox");
801 range_frame_box.set_border_width (5);
802 range_frame_box.pack_start (range_rows_scroller, true, true);
804 add_range_button.set_name ("LocationAddRangeButton");
806 table->attach (range_frame_box, 1, 2, table_row, table_row + 1);
809 loc_range_panes.pack2 (*table, true, false);
811 HBox* add_button_box = manage (new HBox);
812 add_button_box->pack_start (add_location_button, true, true);
813 add_button_box->pack_start (add_range_button, true, true);
815 vbox->pack_start (loc_range_panes, true, true);
816 vbox->pack_start (*add_button_box, false, false);
820 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
821 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
826 LocationUI::~LocationUI()
832 LocationUI::do_location_remove (ARDOUR::Location *loc)
834 /* this is handled internally by Locations, but there's
835 no point saving state etc. when we know the marker
839 if (loc->is_session_range()) {
843 _session->begin_reversible_command (_("remove marker"));
844 XMLNode &before = _session->locations()->get_state();
845 _session->locations()->remove (loc);
846 XMLNode &after = _session->locations()->get_state();
847 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
848 _session->commit_reversible_command ();
854 LocationUI::location_remove_requested (ARDOUR::Location *loc)
856 // must do this to prevent problems when destroying
857 // the effective sender of this event
859 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
864 LocationUI::location_redraw_ranges ()
870 struct LocationSortByStart {
871 bool operator() (Location *a, Location *b) {
872 return a->start() < b->start();
877 LocationUI::location_added (Location* location)
879 if (location->is_auto_punch()) {
880 punch_edit_row.set_location(location);
881 } else if (location->is_auto_loop()) {
882 loop_edit_row.set_location(location);
883 } else if (location->is_range_marker() || location->is_mark()) {
884 Locations::LocationList loc = _session->locations()->list ();
885 loc.sort (LocationSortByStart ());
887 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
889 erow->set_clock_group (*_clock_group);
890 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
892 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
894 /* Step through the location list and the GUI list to find the place to insert */
895 Locations::LocationList::iterator i = loc.begin ();
896 Box_Helpers::BoxList::iterator j = children.begin ();
897 while (i != loc.end()) {
899 if (location->flags() != (*i)->flags()) {
900 /* Skip locations in the session list that aren't of the right type */
905 if (*i == location) {
906 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
912 if (j != children.end()) {
917 range_rows.show_all ();
918 location_rows.show_all ();
923 LocationUI::location_removed (Location* location)
925 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
927 if (location->is_auto_punch()) {
928 punch_edit_row.set_location(0);
929 } else if (location->is_auto_loop()) {
930 loop_edit_row.set_location(0);
931 } else if (location->is_range_marker() || location->is_mark()) {
932 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
933 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
934 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
935 if (r && r->get_location() == location) {
944 LocationUI::map_locations (Locations::LocationList& locations)
946 Locations::LocationList::iterator i;
949 Locations::LocationList temp = locations;
950 LocationSortByStart cmp;
955 for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
957 Location* location = *i;
959 if (location->is_mark()) {
960 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
962 erow->set_clock_group (*_clock_group);
963 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
964 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
966 Box_Helpers::BoxList & loc_children = location_rows.children();
967 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
968 if (location == newest_location) {
972 } else if (location->is_auto_punch()) {
973 punch_edit_row.set_session (_session);
974 punch_edit_row.set_location (location);
975 punch_edit_row.show_all();
976 } else if (location->is_auto_loop()) {
977 loop_edit_row.set_session (_session);
978 loop_edit_row.set_location (location);
979 loop_edit_row.show_all();
981 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
983 erow->set_clock_group (*_clock_group);
984 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
986 Box_Helpers::BoxList & range_children = range_rows.children();
987 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
991 range_rows.show_all();
992 location_rows.show_all();
996 LocationUI::add_new_location()
1001 framepos_t where = _session->audible_frame();
1002 _session->locations()->next_available_name(markername,"mark");
1003 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
1004 if (Config->get_name_new_markers()) {
1005 newest_location = location;
1007 _session->begin_reversible_command (_("add marker"));
1008 XMLNode &before = _session->locations()->get_state();
1009 _session->locations()->add (location, true);
1010 XMLNode &after = _session->locations()->get_state();
1011 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1012 _session->commit_reversible_command ();
1018 LocationUI::add_new_range()
1023 framepos_t where = _session->audible_frame();
1024 _session->locations()->next_available_name(rangename,"unnamed");
1025 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
1026 _session->begin_reversible_command (_("add range marker"));
1027 XMLNode &before = _session->locations()->get_state();
1028 _session->locations()->add (location, true);
1029 XMLNode &after = _session->locations()->get_state();
1030 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1031 _session->commit_reversible_command ();
1036 LocationUI::refresh_location_list ()
1038 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
1039 using namespace Box_Helpers;
1041 // this is just too expensive to do when window is not shown
1046 BoxList & loc_children = location_rows.children();
1047 BoxList & range_children = range_rows.children();
1049 loc_children.clear();
1050 range_children.clear();
1053 _session->locations()->apply (*this, &LocationUI::map_locations);
1058 LocationUI::set_session(ARDOUR::Session* s)
1060 SessionHandlePtr::set_session (s);
1063 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::locations_changed, this, _1), gui_context());
1064 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
1065 _session->locations()->added.connect (_session_connections, invalidator (*this), ui_bind (&LocationUI::location_added, this, _1), gui_context());
1066 _session->locations()->removed.connect (_session_connections, invalidator (*this), ui_bind (&LocationUI::location_removed, this, _1), gui_context());
1067 _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
1070 loop_edit_row.set_session (s);
1071 punch_edit_row.set_session (s);
1073 refresh_location_list ();
1077 LocationUI::locations_changed (Locations::Change c)
1079 /* removal is signalled by both a removed and a changed signal emission from Locations,
1080 so we don't need to refresh the list on a removal
1082 if (c != Locations::REMOVAL) {
1083 refresh_location_list ();
1088 LocationUI::session_going_away()
1090 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
1092 using namespace Box_Helpers;
1093 BoxList & loc_children = location_rows.children();
1094 BoxList & range_children = range_rows.children();
1096 loc_children.clear();
1097 range_children.clear();
1099 loop_edit_row.set_session (0);
1100 loop_edit_row.set_location (0);
1102 punch_edit_row.set_session (0);
1103 punch_edit_row.set_location (0);
1105 SessionHandlePtr::session_going_away ();
1109 LocationUI::get_state () const
1111 XMLNode* node = new XMLNode (X_("LocationUI"));
1112 node->add_property (X_("clock-mode"), enum_2_string (_clock_group->clock_mode ()));
1117 LocationUI::clock_mode_from_session_instant_xml () const
1119 XMLNode* node = _session->instant_xml (X_("LocationUI"));
1121 return AudioClock::Frames;
1124 XMLProperty* p = node->property (X_("clock-mode"));
1126 return AudioClock::Frames;
1129 return (AudioClock::Mode) string_2_enum (p->value (), AudioClock::Mode);
1133 /*------------------------*/
1135 LocationUIWindow::LocationUIWindow ()
1136 : ArdourWindow (_("Locations"))
1138 set_wmclass(X_("ardour_locations"), PROGRAM_NAME);
1139 set_name ("LocationWindow");
1144 LocationUIWindow::~LocationUIWindow()
1149 LocationUIWindow::on_map ()
1151 ArdourWindow::on_map ();
1152 _ui.refresh_location_list();
1156 LocationUIWindow::on_delete_event (GdkEventAny*)
1163 LocationUIWindow::set_session (Session *s)
1165 ArdourWindow::set_session (s);
1166 _ui.set_session (s);
1170 LocationUIWindow::session_going_away ()
1172 ArdourWindow::session_going_away ();