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"
36 #include "public_editor.h"
38 #include "ui_config.h"
43 using namespace ARDOUR;
44 using namespace ARDOUR_UI_UTILS;
47 using namespace Gtkmm2ext;
49 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
50 : SessionHandlePtr (0) /* explicitly set below */
52 , item_table (1, 6, false)
53 , start_clock (X_("locationstart"), true, "", true, false)
54 , start_to_playhead_button (_("Use PH"))
55 , locate_to_start_button (_("Goto"))
56 , end_clock (X_("locationend"), true, "", true, false)
57 , end_to_playhead_button (_("Use PH"))
58 , locate_to_end_button (_("Goto"))
59 , length_clock (X_("locationlength"), true, "", true, false, true)
60 , cd_check_button (_("CD"))
61 , hide_check_button (_("Hide"))
62 , lock_check_button (_("Lock"))
63 , glue_check_button (_("Glue"))
66 i_am_the_modifier = 0;
68 remove_button.set_image (*manage (new Image (Stock::REMOVE, Gtk::ICON_SIZE_MENU)));
70 start_to_playhead_button.set_name ("LocationEditCdButton");
71 end_to_playhead_button.set_name ("LocationEditCdButton");
72 locate_to_start_button.set_name ("LocationEditCdButton");
73 locate_to_end_button.set_name ("LocationEditCdButton");
75 number_label.set_name ("LocationEditNumberLabel");
76 name_label.set_name ("LocationEditNameLabel");
77 name_entry.set_name ("LocationEditNameEntry");
78 cd_check_button.set_name ("LocationEditCdButton");
79 hide_check_button.set_name ("LocationEditHideButton");
80 lock_check_button.set_name ("LocationEditLockButton");
81 glue_check_button.set_name ("LocationEditGlueButton");
82 remove_button.set_name ("LocationEditRemoveButton");
83 isrc_label.set_name ("LocationEditNumberLabel");
84 isrc_entry.set_name ("LocationEditNameEntry");
85 scms_check_button.set_name ("LocationEditCdButton");
86 preemph_check_button.set_name ("LocationEditCdButton");
87 performer_label.set_name ("LocationEditNumberLabel");
88 performer_entry.set_name ("LocationEditNameEntry");
89 composer_label.set_name ("LocationEditNumberLabel");
90 composer_entry.set_name ("LocationEditNameEntry");
92 isrc_label.set_text (X_("ISRC:"));
93 performer_label.set_text (_("Performer:"));
94 composer_label.set_text (_("Composer:"));
95 scms_label.set_text (X_("SCMS"));
96 preemph_label.set_text (_("Pre-Emphasis"));
98 isrc_entry.set_size_request (112, -1);
99 isrc_entry.set_max_length(12);
100 isrc_entry.set_editable (true);
102 performer_entry.set_size_request (100, -1);
103 performer_entry.set_editable (true);
105 composer_entry.set_size_request (100, -1);
106 composer_entry.set_editable (true);
108 name_label.set_alignment (0, 0.5);
110 Gtk::HBox* front_spacing = manage (new HBox);
111 front_spacing->set_size_request (20, -1);
112 Gtk::HBox* mid_spacing = manage (new HBox);
113 mid_spacing->set_size_request (20, -1);
115 cd_track_details_hbox.set_spacing (4);
116 cd_track_details_hbox.pack_start (*front_spacing, false, false);
117 cd_track_details_hbox.pack_start (isrc_label, false, false);
118 cd_track_details_hbox.pack_start (isrc_entry, false, false);
119 cd_track_details_hbox.pack_start (performer_label, false, false);
120 cd_track_details_hbox.pack_start (performer_entry, true, true);
121 cd_track_details_hbox.pack_start (composer_label, false, false);
122 cd_track_details_hbox.pack_start (composer_entry, true, true);
123 cd_track_details_hbox.pack_start (*mid_spacing, false, false);
124 cd_track_details_hbox.pack_start (scms_label, false, false);
125 cd_track_details_hbox.pack_start (scms_check_button, false, false);
126 cd_track_details_hbox.pack_start (preemph_label, false, false);
127 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
129 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
130 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
131 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
132 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
133 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
137 start_hbox.set_spacing (2);
138 start_hbox.pack_start (start_clock, false, false);
139 start_hbox.pack_start (start_to_playhead_button, false, false);
140 start_hbox.pack_start (locate_to_start_button, false, false);
142 /* this is always in this location, no matter what the location is */
144 VBox *rbox = manage (new VBox);
145 rbox->pack_start (remove_button, false, false);
147 item_table.attach (*rbox, 0, 1, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
148 item_table.attach (start_hbox, 2, 3, 0, 1, FILL, Gtk::AttachOptions(0), 4, 0);
150 start_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocStart));
151 locate_to_start_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_button_pressed), LocStart));
152 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
153 start_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &start_clock), false);
155 end_hbox.set_spacing (2);
156 end_hbox.pack_start (end_clock, false, false);
157 end_hbox.pack_start (end_to_playhead_button, false, false);
158 end_hbox.pack_start (locate_to_end_button, false, false);
160 end_to_playhead_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocEnd));
161 locate_to_end_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_button_pressed), LocEnd));
162 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
163 end_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &end_clock), false);
165 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
167 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
168 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
169 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
170 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
172 remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
174 pack_start(item_table, true, true);
178 cd_toggled(); // show/hide cd-track details
181 LocationEditRow::~LocationEditRow()
184 connections.drop_connections ();
188 _clock_group->remove (start_clock);
189 _clock_group->remove (end_clock);
190 _clock_group->remove (length_clock);
195 LocationEditRow::set_clock_group (ClockGroup& cg)
198 _clock_group->remove (start_clock);
199 _clock_group->remove (end_clock);
200 _clock_group->remove (length_clock);
205 _clock_group->add (start_clock);
206 _clock_group->add (end_clock);
207 _clock_group->add (length_clock);
211 LocationEditRow::set_session (Session *sess)
213 SessionHandlePtr::set_session (sess);
219 start_clock.set_session (_session);
220 end_clock.set_session (_session);
221 length_clock.set_session (_session);
225 LocationEditRow::set_number (int num)
230 number_label.set_text (string_compose ("%1", number));
235 LocationEditRow::set_location (Location *loc)
238 connections.drop_connections ();
249 if (!hide_check_button.get_parent()) {
250 item_table.attach (hide_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
251 item_table.attach (lock_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
252 item_table.attach (glue_check_button, 8, 9, 0, 1, FILL, Gtk::FILL, 4, 0);
254 hide_check_button.set_active (location->is_hidden());
255 lock_check_button.set_active (location->locked());
256 glue_check_button.set_active (location->position_lock_style() == MusicTime);
258 if (location->is_auto_loop() || location-> is_auto_punch()) {
259 // use label instead of entry
261 name_label.set_text (location->name());
262 name_label.set_size_request (80, -1);
264 remove_button.hide ();
266 if (!name_label.get_parent()) {
267 item_table.attach (name_label, 1, 2, 0, 1, FILL, FILL, 4, 0);
274 name_entry.set_text (location->name());
275 name_entry.set_size_request (100, -1);
276 name_entry.set_editable (true);
277 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
279 if (!name_entry.get_parent()) {
280 item_table.attach (name_entry, 1, 2, 0, 1, FILL | EXPAND, FILL, 4, 0);
284 if (!cd_check_button.get_parent()) {
285 item_table.attach (cd_check_button, 5, 6, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
288 if (location->is_session_range()) {
289 remove_button.set_sensitive (false);
292 cd_check_button.set_active (location->is_cd_marker());
293 cd_check_button.show();
295 if (location->start() == _session->current_start_frame()) {
296 cd_check_button.set_sensitive (false);
298 cd_check_button.set_sensitive (true);
301 hide_check_button.show();
302 lock_check_button.show();
303 glue_check_button.show();
306 start_clock.set (location->start(), true);
309 if (!location->is_mark()) {
310 if (!end_hbox.get_parent()) {
311 item_table.attach (end_hbox, 3, 4, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
313 if (!length_clock.get_parent()) {
314 end_hbox.pack_start (length_clock, false, false);
317 end_clock.set (location->end(), true);
318 length_clock.set (location->length(), true);
323 if (location->is_cd_marker()) {
324 show_cd_track_details ();
327 set_tooltip (remove_button, _("Remove this range"));
328 set_tooltip (start_clock, _("Start time - middle click to locate here"));
329 set_tooltip (end_clock, _("End time - middle click to locate here"));
330 set_tooltip (length_clock, _("Length"));
332 set_tooltip (start_to_playhead_button, _("Set range start from playhead location"));
333 set_tooltip (end_to_playhead_button, _("Set range end from playhead location"));
337 set_tooltip (remove_button, _("Remove this marker"));
338 set_tooltip (start_clock, _("Position - middle click to locate here"));
340 set_tooltip (start_to_playhead_button, _("Set marker time from playhead location"));
346 set_clock_editable_status ();
350 /* connect to per-location signals, since this row only cares about this location */
352 location->NameChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::name_changed, this), gui_context());
353 location->StartChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::start_changed, this), gui_context());
354 location->EndChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::end_changed, this), gui_context());
355 location->Changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::location_changed, this), gui_context());
356 location->FlagsChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::flags_changed, this), gui_context());
357 location->LockChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::lock_changed, this), gui_context());
358 location->PositionLockStyleChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::position_lock_style_changed, this), gui_context());
362 LocationEditRow::name_entry_changed ()
364 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed);
366 if (i_am_the_modifier || !location) {
370 location->set_name (name_entry.get_text());
375 LocationEditRow::isrc_entry_changed ()
377 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed);
379 if (i_am_the_modifier || !location) return;
381 if (isrc_entry.get_text() != "" ) {
383 location->cd_info["isrc"] = isrc_entry.get_text();
386 location->cd_info.erase("isrc");
391 LocationEditRow::performer_entry_changed ()
393 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed);
395 if (i_am_the_modifier || !location) return;
397 if (performer_entry.get_text() != "") {
398 location->cd_info["performer"] = performer_entry.get_text();
400 location->cd_info.erase("performer");
405 LocationEditRow::composer_entry_changed ()
407 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed);
409 if (i_am_the_modifier || !location) return;
411 if (composer_entry.get_text() != "") {
412 location->cd_info["composer"] = composer_entry.get_text();
414 location->cd_info.erase("composer");
419 LocationEditRow::to_playhead_button_pressed (LocationPart part)
427 location->set_start (_session->transport_frame ());
430 location->set_end (_session->transport_frame ());
438 LocationEditRow::locate_button_pressed (LocationPart part)
442 _session->request_locate (start_clock.current_time());
445 _session->request_locate (end_clock.current_time());
453 LocationEditRow::locate_to_clock (GdkEventButton* ev, AudioClock* clock)
455 if (Keyboard::is_button2_event (ev)) {
456 _session->request_locate (clock->current_time());
463 LocationEditRow::clock_changed (LocationPart part)
465 if (i_am_the_modifier || !location) {
471 location->set_start (start_clock.current_time());
474 location->set_end (end_clock.current_time());
477 location->set_end (location->start() + length_clock.current_duration());
484 LocationEditRow::show_cd_track_details ()
486 if (location->cd_info.find("isrc") != location->cd_info.end()) {
487 isrc_entry.set_text(location->cd_info["isrc"]);
489 if (location->cd_info.find("performer") != location->cd_info.end()) {
490 performer_entry.set_text(location->cd_info["performer"]);
492 if (location->cd_info.find("composer") != location->cd_info.end()) {
493 composer_entry.set_text(location->cd_info["composer"]);
495 if (location->cd_info.find("scms") != location->cd_info.end()) {
496 scms_check_button.set_active(true);
498 if (location->cd_info.find("preemph") != location->cd_info.end()) {
499 preemph_check_button.set_active(true);
503 if (!cd_track_details_hbox.get_parent()) {
504 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
506 // item_table.resize(2, 7);
507 cd_track_details_hbox.show_all();
511 LocationEditRow::cd_toggled ()
513 if (i_am_the_modifier || !location) {
517 //if (cd_check_button.get_active() == location->is_cd_marker()) {
521 if (cd_check_button.get_active()) {
522 if (location->start() <= _session->current_start_frame()) {
523 error << _("You cannot put a CD marker at the start of the session") << endmsg;
524 cd_check_button.set_active (false);
529 location->set_cd (cd_check_button.get_active(), this);
531 if (location->is_cd_marker()) {
533 show_cd_track_details ();
535 } else if (cd_track_details_hbox.get_parent()){
537 item_table.remove (cd_track_details_hbox);
538 // item_table.resize(1, 7);
539 redraw_ranges(); /* EMIT_SIGNAL */
544 LocationEditRow::hide_toggled ()
546 if (i_am_the_modifier || !location) {
550 location->set_hidden (hide_check_button.get_active(), this);
554 LocationEditRow::lock_toggled ()
556 if (i_am_the_modifier || !location) {
560 if (location->locked()) {
568 LocationEditRow::glue_toggled ()
570 if (i_am_the_modifier || !location) {
574 if (location->position_lock_style() == AudioTime) {
575 location->set_position_lock_style (MusicTime);
577 location->set_position_lock_style (AudioTime);
582 LocationEditRow::remove_button_pressed ()
588 remove_requested (location); /* EMIT_SIGNAL */
594 LocationEditRow::scms_toggled ()
596 if (i_am_the_modifier || !location) return;
598 if (scms_check_button.get_active()) {
599 location->cd_info["scms"] = "on";
601 location->cd_info.erase("scms");
607 LocationEditRow::preemph_toggled ()
609 if (i_am_the_modifier || !location) return;
611 if (preemph_check_button.get_active()) {
612 location->cd_info["preemph"] = "on";
614 location->cd_info.erase("preemph");
619 LocationEditRow::end_changed ()
621 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
623 if (!location) return;
625 // update end and length
628 end_clock.set (location->end());
629 length_clock.set (location->length());
635 LocationEditRow::start_changed ()
637 if (!location) return;
639 // update end and length
642 start_clock.set (location->start());
644 if (location->start() == _session->current_start_frame()) {
645 cd_check_button.set_sensitive (false);
647 cd_check_button.set_sensitive (true);
654 LocationEditRow::name_changed ()
656 if (!location) return;
658 // update end and length
661 name_entry.set_text(location->name());
662 name_label.set_text(location->name());
669 LocationEditRow::location_changed ()
672 if (!location) return;
676 start_clock.set (location->start());
677 end_clock.set (location->end());
678 length_clock.set (location->length());
680 set_clock_editable_status ();
687 LocationEditRow::flags_changed ()
695 cd_check_button.set_active (location->is_cd_marker());
696 hide_check_button.set_active (location->is_hidden());
697 glue_check_button.set_active (location->position_lock_style() == MusicTime);
703 LocationEditRow::lock_changed ()
711 lock_check_button.set_active (location->locked());
713 set_clock_editable_status ();
719 LocationEditRow::position_lock_style_changed ()
727 glue_check_button.set_active (location->position_lock_style() == MusicTime);
733 LocationEditRow::focus_name()
735 name_entry.grab_focus ();
739 LocationEditRow::set_clock_editable_status ()
741 start_clock.set_editable (!location->locked());
742 end_clock.set_editable (!location->locked());
743 length_clock.set_editable (!location->locked());
746 /*------------------------------------------------------------------------*/
748 LocationUI::LocationUI ()
749 : add_location_button (_("New Marker"))
750 , add_range_button (_("New Range"))
752 i_am_the_modifier = 0;
754 _clock_group = new ClockGroup;
756 VBox* vbox = manage (new VBox);
758 Table* table = manage (new Table (2, 2));
759 table->set_spacings (2);
760 table->set_col_spacing (0, 32);
763 Label* l = manage (new Label (_("<b>Loop/Punch Ranges</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);
769 loop_edit_row.set_clock_group (*_clock_group);
770 punch_edit_row.set_clock_group (*_clock_group);
772 loop_punch_box.pack_start (loop_edit_row, false, false);
773 loop_punch_box.pack_start (punch_edit_row, false, false);
775 table->attach (loop_punch_box, 1, 2, table_row, table_row + 1);
778 vbox->pack_start (*table, false, false);
780 table = manage (new Table (3, 2));
781 table->set_spacings (2);
782 table->set_col_spacing (0, 32);
785 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
788 l = manage (new Label (_("<b>Markers (Including CD Index)</b>")));
789 l->set_alignment (0, 0.5);
790 l->set_use_markup (true);
791 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
794 location_rows.set_name("LocationLocRows");
795 location_rows_scroller.add (location_rows);
796 location_rows_scroller.set_name ("LocationLocRowsScroller");
797 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
798 location_rows_scroller.set_size_request (-1, 130);
802 loc_frame_box.set_spacing (5);
803 loc_frame_box.set_border_width (5);
804 loc_frame_box.set_name("LocationFrameBox");
806 loc_frame_box.pack_start (location_rows_scroller, true, true);
808 add_location_button.set_name ("LocationAddLocationButton");
810 table->attach (loc_frame_box, 0, 2, table_row, table_row + 1);
813 loc_range_panes.pack1 (*table, true, false);
815 table = manage (new Table (3, 2));
816 table->set_spacings (2);
817 table->set_col_spacing (0, 32);
820 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
823 l = manage (new Label (_("<b>Ranges (Including CD Track Ranges)</b>")));
824 l->set_alignment (0, 0.5);
825 l->set_use_markup (true);
826 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
829 range_rows.set_name("LocationRangeRows");
830 range_rows_scroller.add (range_rows);
831 range_rows_scroller.set_name ("LocationRangeRowsScroller");
832 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
833 range_rows_scroller.set_size_request (-1, 130);
835 range_frame_box.set_spacing (5);
836 range_frame_box.set_name("LocationFrameBox");
837 range_frame_box.set_border_width (5);
838 range_frame_box.pack_start (range_rows_scroller, true, true);
840 add_range_button.set_name ("LocationAddRangeButton");
842 table->attach (range_frame_box, 0, 2, table_row, table_row + 1);
845 loc_range_panes.pack2 (*table, true, false);
847 HBox* add_button_box = manage (new HBox);
848 add_button_box->pack_start (add_location_button, true, true);
849 add_button_box->pack_start (add_range_button, true, true);
851 vbox->pack_start (loc_range_panes, true, true);
852 vbox->pack_start (*add_button_box, false, false);
856 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
857 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
861 signal_map().connect (sigc::mem_fun (*this, &LocationUI::refresh_location_list));
864 LocationUI::~LocationUI()
866 loop_edit_row.unset_clock_group ();
867 punch_edit_row.unset_clock_group ();
872 LocationUI::do_location_remove (ARDOUR::Location *loc)
874 /* this is handled internally by Locations, but there's
875 no point saving state etc. when we know the marker
879 if (loc->is_session_range()) {
883 PublicEditor::instance().begin_reversible_command (_("remove marker"));
884 XMLNode &before = _session->locations()->get_state();
885 _session->locations()->remove (loc);
886 XMLNode &after = _session->locations()->get_state();
887 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
888 PublicEditor::instance().commit_reversible_command ();
894 LocationUI::location_remove_requested (ARDOUR::Location *loc)
896 // must do this to prevent problems when destroying
897 // the effective sender of this event
899 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
904 LocationUI::location_redraw_ranges ()
910 struct LocationSortByStart {
911 bool operator() (Location *a, Location *b) {
912 return a->start() < b->start();
917 LocationUI::location_added (Location* location)
919 if (location->is_auto_punch()) {
920 punch_edit_row.set_location(location);
921 } else if (location->is_auto_loop()) {
922 loop_edit_row.set_location(location);
923 } else if (location->is_range_marker() || location->is_mark()) {
924 Locations::LocationList loc = _session->locations()->list ();
925 loc.sort (LocationSortByStart ());
927 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
929 erow->set_clock_group (*_clock_group);
930 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
932 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
934 /* Step through the location list and the GUI list to find the place to insert */
935 Locations::LocationList::iterator i = loc.begin ();
936 Box_Helpers::BoxList::iterator j = children.begin ();
937 while (i != loc.end()) {
939 if (location->flags() != (*i)->flags()) {
940 /* Skip locations in the session list that aren't of the right type */
945 if (*i == location) {
946 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
952 if (j != children.end()) {
957 range_rows.show_all ();
958 location_rows.show_all ();
960 if (location == newest_location) {
968 LocationUI::location_removed (Location* location)
970 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
972 if (location->is_auto_punch()) {
973 punch_edit_row.set_location(0);
974 } else if (location->is_auto_loop()) {
975 loop_edit_row.set_location(0);
976 } else if (location->is_range_marker() || location->is_mark()) {
977 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
978 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
979 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
980 if (r && r->get_location() == location) {
989 LocationUI::map_locations (const Locations::LocationList& locations)
991 Locations::LocationList::iterator i;
994 Locations::LocationList temp = locations;
995 LocationSortByStart cmp;
999 for (n = 0, i = temp.begin(); i != temp.end(); ++n, ++i) {
1001 Location* location = *i;
1003 if (location->is_mark()) {
1004 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
1006 erow->set_clock_group (*_clock_group);
1007 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
1008 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
1010 Box_Helpers::BoxList & loc_children = location_rows.children();
1011 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
1012 } else if (location->is_auto_punch()) {
1013 punch_edit_row.set_session (_session);
1014 punch_edit_row.set_location (location);
1015 punch_edit_row.show_all();
1016 } else if (location->is_auto_loop()) {
1017 loop_edit_row.set_session (_session);
1018 loop_edit_row.set_location (location);
1019 loop_edit_row.show_all();
1021 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
1023 erow->set_clock_group (*_clock_group);
1024 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
1026 Box_Helpers::BoxList & range_children = range_rows.children();
1027 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
1031 range_rows.show_all();
1032 location_rows.show_all();
1036 LocationUI::add_new_location()
1041 framepos_t where = _session->audible_frame();
1042 _session->locations()->next_available_name(markername,"mark");
1043 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
1044 if (UIConfiguration::instance().get_name_new_markers()) {
1045 newest_location = location;
1047 PublicEditor::instance().begin_reversible_command (_("add marker"));
1048 XMLNode &before = _session->locations()->get_state();
1049 _session->locations()->add (location, true);
1050 XMLNode &after = _session->locations()->get_state();
1051 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1052 PublicEditor::instance().commit_reversible_command ();
1058 LocationUI::add_new_range()
1063 framepos_t where = _session->audible_frame();
1064 _session->locations()->next_available_name(rangename,"unnamed");
1065 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
1066 PublicEditor::instance().begin_reversible_command (_("add range marker"));
1067 XMLNode &before = _session->locations()->get_state();
1068 _session->locations()->add (location, true);
1069 XMLNode &after = _session->locations()->get_state();
1070 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1071 PublicEditor::instance().commit_reversible_command ();
1076 LocationUI::refresh_location_list ()
1078 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
1079 using namespace Box_Helpers;
1081 // this is just too expensive to do when window is not shown
1086 BoxList & loc_children = location_rows.children();
1087 BoxList & range_children = range_rows.children();
1089 loc_children.clear();
1090 range_children.clear();
1093 _session->locations()->apply (*this, &LocationUI::map_locations);
1098 LocationUI::set_session(ARDOUR::Session* s)
1100 SessionHandlePtr::set_session (s);
1103 _session->locations()->added.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_added, this, _1), gui_context());
1104 _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_removed, this, _1), gui_context());
1105 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
1107 _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
1110 loop_edit_row.set_session (s);
1111 punch_edit_row.set_session (s);
1113 refresh_location_list ();
1117 LocationUI::session_going_away()
1119 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
1121 using namespace Box_Helpers;
1122 BoxList & loc_children = location_rows.children();
1123 BoxList & range_children = range_rows.children();
1125 loc_children.clear();
1126 range_children.clear();
1128 loop_edit_row.set_session (0);
1129 loop_edit_row.set_location (0);
1131 punch_edit_row.set_session (0);
1132 punch_edit_row.set_location (0);
1134 SessionHandlePtr::session_going_away ();
1138 LocationUI::get_state () const
1140 XMLNode* node = new XMLNode (X_("LocationUI"));
1141 node->add_property (X_("clock-mode"), enum_2_string (_clock_group->clock_mode ()));
1146 LocationUI::clock_mode_from_session_instant_xml () const
1148 XMLNode* node = _session->instant_xml (X_("LocationUI"));
1150 return AudioClock::Frames;
1153 XMLProperty* p = node->property (X_("clock-mode"));
1155 return ARDOUR_UI::instance()->secondary_clock->mode();
1158 return (AudioClock::Mode) string_2_enum (p->value (), AudioClock::Mode);
1162 /*------------------------*/
1164 LocationUIWindow::LocationUIWindow ()
1165 : ArdourWindow (_("Locations"))
1167 set_wmclass(X_("ardour_locations"), PROGRAM_NAME);
1168 set_name ("LocationWindow");
1173 LocationUIWindow::~LocationUIWindow()
1178 LocationUIWindow::on_map ()
1180 ArdourWindow::on_map ();
1181 _ui.refresh_location_list();
1185 LocationUIWindow::on_delete_event (GdkEventAny*)
1191 LocationUIWindow::set_session (Session *s)
1193 ArdourWindow::set_session (s);
1194 _ui.set_session (s);
1199 LocationUIWindow::session_going_away ()
1201 ArdourWindow::session_going_away ();