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_icon (ArdourIcon::CloseCross);
69 remove_button.set_events (remove_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
71 number_label.set_name ("LocationEditNumberLabel");
72 name_label.set_name ("LocationEditNameLabel");
73 name_entry.set_name ("LocationEditNameEntry");
74 cd_check_button.set_name ("LocationEditCdButton");
75 hide_check_button.set_name ("LocationEditHideButton");
76 lock_check_button.set_name ("LocationEditLockButton");
77 glue_check_button.set_name ("LocationEditGlueButton");
78 isrc_label.set_name ("LocationEditNumberLabel");
79 isrc_entry.set_name ("LocationEditNameEntry");
80 scms_check_button.set_name ("LocationEditCdButton");
81 preemph_check_button.set_name ("LocationEditCdButton");
82 performer_label.set_name ("LocationEditNumberLabel");
83 performer_entry.set_name ("LocationEditNameEntry");
84 composer_label.set_name ("LocationEditNumberLabel");
85 composer_entry.set_name ("LocationEditNameEntry");
87 isrc_label.set_text (X_("ISRC:"));
88 performer_label.set_text (_("Performer:"));
89 composer_label.set_text (_("Composer:"));
90 scms_label.set_text (X_("SCMS"));
91 preemph_label.set_text (_("Pre-Emphasis"));
93 isrc_entry.set_size_request (112, -1);
94 isrc_entry.set_max_length(12);
95 isrc_entry.set_editable (true);
97 performer_entry.set_size_request (100, -1);
98 performer_entry.set_editable (true);
100 composer_entry.set_size_request (100, -1);
101 composer_entry.set_editable (true);
103 name_label.set_alignment (0, 0.5);
105 Gtk::HBox* front_spacing = manage (new HBox);
106 front_spacing->set_size_request (20, -1);
107 Gtk::HBox* mid_spacing = manage (new HBox);
108 mid_spacing->set_size_request (20, -1);
110 cd_track_details_hbox.set_spacing (4);
111 cd_track_details_hbox.pack_start (*front_spacing, false, false);
112 cd_track_details_hbox.pack_start (isrc_label, false, false);
113 cd_track_details_hbox.pack_start (isrc_entry, false, false);
114 cd_track_details_hbox.pack_start (performer_label, false, false);
115 cd_track_details_hbox.pack_start (performer_entry, true, true);
116 cd_track_details_hbox.pack_start (composer_label, false, false);
117 cd_track_details_hbox.pack_start (composer_entry, true, true);
118 cd_track_details_hbox.pack_start (*mid_spacing, false, false);
119 cd_track_details_hbox.pack_start (scms_label, false, false);
120 cd_track_details_hbox.pack_start (scms_check_button, false, false);
121 cd_track_details_hbox.pack_start (preemph_label, false, false);
122 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
124 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
125 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
126 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
127 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
128 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
132 start_hbox.set_spacing (2);
133 start_hbox.pack_start (locate_to_start_button, false, false);
134 start_hbox.pack_start (start_clock, false, false);
135 start_hbox.pack_start (start_to_playhead_button, false, false);
137 /* this is always in this location, no matter what the location is */
139 item_table.attach (remove_button, 8, 9, 0, 1, SHRINK, SHRINK, 4, 1);
140 item_table.attach (start_hbox, 0, 1, 0, 1, FILL, Gtk::AttachOptions(0), 4, 0);
142 start_to_playhead_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocStart));
143 locate_to_start_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_button_pressed), LocStart));
144 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
145 start_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &start_clock), false);
147 end_hbox.set_spacing (2);
148 end_hbox.pack_start (locate_to_end_button, false, false);
149 end_hbox.pack_start (end_clock, false, false);
150 end_hbox.pack_start (end_to_playhead_button, false, false);
152 end_to_playhead_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocEnd));
153 locate_to_end_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_button_pressed), LocEnd));
154 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
155 end_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &end_clock), false);
157 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
159 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
160 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
161 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
162 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
164 remove_button.signal_clicked.connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
166 pack_start(item_table, true, true);
170 cd_toggled(); // show/hide cd-track details
173 LocationEditRow::~LocationEditRow()
176 connections.drop_connections ();
180 _clock_group->remove (start_clock);
181 _clock_group->remove (end_clock);
182 _clock_group->remove (length_clock);
187 LocationEditRow::set_clock_group (ClockGroup& cg)
190 _clock_group->remove (start_clock);
191 _clock_group->remove (end_clock);
192 _clock_group->remove (length_clock);
197 _clock_group->add (start_clock);
198 _clock_group->add (end_clock);
199 _clock_group->add (length_clock);
203 LocationEditRow::set_session (Session *sess)
205 SessionHandlePtr::set_session (sess);
211 start_clock.set_session (_session);
212 end_clock.set_session (_session);
213 length_clock.set_session (_session);
217 LocationEditRow::set_number (int num)
222 number_label.set_text (string_compose ("%1", number));
227 LocationEditRow::set_location (Location *loc)
230 connections.drop_connections ();
241 if (!hide_check_button.get_parent()) {
242 item_table.attach (hide_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
243 item_table.attach (lock_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
244 item_table.attach (glue_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
246 hide_check_button.set_active (location->is_hidden());
247 lock_check_button.set_active (location->locked());
248 glue_check_button.set_active (location->position_lock_style() == MusicTime);
250 if (location->is_auto_loop() || location-> is_auto_punch()) {
251 // use label instead of entry
253 name_label.set_text (location->name());
254 name_label.set_size_request (80, -1);
256 remove_button.hide ();
258 if (!name_label.get_parent()) {
259 item_table.attach (name_label, 2, 3, 0, 1, EXPAND|FILL, FILL, 4, 0);
266 name_entry.set_text (location->name());
267 name_entry.set_size_request (100, -1);
268 name_entry.set_editable (true);
269 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
271 if (!name_entry.get_parent()) {
272 item_table.attach (name_entry, 2, 3, 0, 1, FILL | EXPAND, FILL, 4, 0);
276 if (!cd_check_button.get_parent()) {
277 item_table.attach (cd_check_button, 4, 5, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
280 if (location->is_session_range()) {
281 remove_button.set_sensitive (false);
284 cd_check_button.set_active (location->is_cd_marker());
285 cd_check_button.show();
287 if (location->start() == _session->current_start_frame()) {
288 cd_check_button.set_sensitive (false);
290 cd_check_button.set_sensitive (true);
293 hide_check_button.show();
294 lock_check_button.show();
295 glue_check_button.show();
298 start_clock.set (location->start(), true);
301 if (!location->is_mark()) {
302 if (!end_hbox.get_parent()) {
303 item_table.attach (end_hbox, 1, 2, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
305 if (!length_clock.get_parent()) {
306 end_hbox.pack_start (length_clock, false, false, 4);
309 end_clock.set (location->end(), true);
310 length_clock.set (location->length(), true);
315 if (location->is_cd_marker()) {
316 show_cd_track_details ();
319 set_tooltip (&remove_button, _("Remove this range"));
320 set_tooltip (start_clock, _("Start time - middle click to locate here"));
321 set_tooltip (end_clock, _("End time - middle click to locate here"));
322 set_tooltip (length_clock, _("Length"));
324 set_tooltip (&start_to_playhead_button, _("Set range start from playhead location"));
325 set_tooltip (&end_to_playhead_button, _("Set range end from playhead location"));
329 set_tooltip (&remove_button, _("Remove this marker"));
330 set_tooltip (start_clock, _("Position - middle click to locate here"));
332 set_tooltip (&start_to_playhead_button, _("Set marker time from playhead location"));
338 set_clock_editable_status ();
342 /* connect to per-location signals, since this row only cares about this location */
344 location->NameChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::name_changed, this), gui_context());
345 location->StartChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::start_changed, this), gui_context());
346 location->EndChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::end_changed, this), gui_context());
347 location->Changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::location_changed, this), gui_context());
348 location->FlagsChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::flags_changed, this), gui_context());
349 location->LockChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::lock_changed, this), gui_context());
350 location->PositionLockStyleChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::position_lock_style_changed, this), gui_context());
354 LocationEditRow::name_entry_changed ()
356 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed);
358 if (i_am_the_modifier || !location) {
362 location->set_name (name_entry.get_text());
367 LocationEditRow::isrc_entry_changed ()
369 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed);
371 if (i_am_the_modifier || !location) return;
373 if (isrc_entry.get_text() != "" ) {
375 location->cd_info["isrc"] = isrc_entry.get_text();
378 location->cd_info.erase("isrc");
383 LocationEditRow::performer_entry_changed ()
385 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed);
387 if (i_am_the_modifier || !location) return;
389 if (performer_entry.get_text() != "") {
390 location->cd_info["performer"] = performer_entry.get_text();
392 location->cd_info.erase("performer");
397 LocationEditRow::composer_entry_changed ()
399 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed);
401 if (i_am_the_modifier || !location) return;
403 if (composer_entry.get_text() != "") {
404 location->cd_info["composer"] = composer_entry.get_text();
406 location->cd_info.erase("composer");
411 LocationEditRow::to_playhead_button_pressed (LocationPart part)
419 location->set_start (_session->transport_frame ());
422 location->set_end (_session->transport_frame ());
423 if (location->is_session_range()) {
424 _session->set_end_is_free (false);
433 LocationEditRow::locate_button_pressed (LocationPart part)
437 _session->request_locate (start_clock.current_time());
440 _session->request_locate (end_clock.current_time());
448 LocationEditRow::locate_to_clock (GdkEventButton* ev, AudioClock* clock)
450 if (Keyboard::is_button2_event (ev)) {
451 _session->request_locate (clock->current_time());
458 LocationEditRow::clock_changed (LocationPart part)
460 if (i_am_the_modifier || !location) {
466 location->set_start (start_clock.current_time());
469 location->set_end (end_clock.current_time());
470 if (location->is_session_range()) {
471 _session->set_end_is_free (false);
475 location->set_end (location->start() + length_clock.current_duration());
476 if (location->is_session_range()) {
477 _session->set_end_is_free (false);
485 LocationEditRow::show_cd_track_details ()
487 if (location->cd_info.find("isrc") != location->cd_info.end()) {
488 isrc_entry.set_text(location->cd_info["isrc"]);
490 if (location->cd_info.find("performer") != location->cd_info.end()) {
491 performer_entry.set_text(location->cd_info["performer"]);
493 if (location->cd_info.find("composer") != location->cd_info.end()) {
494 composer_entry.set_text(location->cd_info["composer"]);
496 if (location->cd_info.find("scms") != location->cd_info.end()) {
497 scms_check_button.set_active(true);
499 if (location->cd_info.find("preemph") != location->cd_info.end()) {
500 preemph_check_button.set_active(true);
504 if (!cd_track_details_hbox.get_parent()) {
505 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
507 // item_table.resize(2, 7);
508 cd_track_details_hbox.show_all();
512 LocationEditRow::cd_toggled ()
514 if (i_am_the_modifier || !location) {
518 //if (cd_check_button.get_active() == location->is_cd_marker()) {
522 if (cd_check_button.get_active()) {
523 if (location->start() <= _session->current_start_frame()) {
524 error << _("You cannot put a CD marker at the start of the session") << endmsg;
525 cd_check_button.set_active (false);
530 location->set_cd (cd_check_button.get_active(), this);
532 if (location->is_cd_marker()) {
534 show_cd_track_details ();
536 } else if (cd_track_details_hbox.get_parent()){
538 item_table.remove (cd_track_details_hbox);
539 // item_table.resize(1, 7);
540 redraw_ranges(); /* EMIT_SIGNAL */
545 LocationEditRow::hide_toggled ()
547 if (i_am_the_modifier || !location) {
551 location->set_hidden (hide_check_button.get_active(), this);
555 LocationEditRow::lock_toggled ()
557 if (i_am_the_modifier || !location) {
561 if (location->locked()) {
569 LocationEditRow::glue_toggled ()
571 if (i_am_the_modifier || !location) {
575 if (location->position_lock_style() == AudioTime) {
576 location->set_position_lock_style (MusicTime);
578 location->set_position_lock_style (AudioTime);
583 LocationEditRow::remove_button_pressed ()
589 remove_requested (location); /* EMIT_SIGNAL */
595 LocationEditRow::scms_toggled ()
597 if (i_am_the_modifier || !location) return;
599 if (scms_check_button.get_active()) {
600 location->cd_info["scms"] = "on";
602 location->cd_info.erase("scms");
608 LocationEditRow::preemph_toggled ()
610 if (i_am_the_modifier || !location) return;
612 if (preemph_check_button.get_active()) {
613 location->cd_info["preemph"] = "on";
615 location->cd_info.erase("preemph");
620 LocationEditRow::end_changed ()
622 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
624 if (!location) return;
626 // update end and length
629 end_clock.set (location->end());
630 length_clock.set (location->length());
636 LocationEditRow::start_changed ()
638 if (!location) return;
640 // update end and length
643 start_clock.set (location->start());
645 if (location->start() == _session->current_start_frame()) {
646 cd_check_button.set_sensitive (false);
648 cd_check_button.set_sensitive (true);
655 LocationEditRow::name_changed ()
657 if (!location) return;
659 // update end and length
662 name_entry.set_text(location->name());
663 name_label.set_text(location->name());
670 LocationEditRow::location_changed ()
673 if (!location) return;
677 start_clock.set (location->start());
678 end_clock.set (location->end());
679 length_clock.set (location->length());
681 set_clock_editable_status ();
688 LocationEditRow::flags_changed ()
696 cd_check_button.set_active (location->is_cd_marker());
697 hide_check_button.set_active (location->is_hidden());
698 glue_check_button.set_active (location->position_lock_style() == MusicTime);
704 LocationEditRow::lock_changed ()
712 lock_check_button.set_active (location->locked());
714 set_clock_editable_status ();
720 LocationEditRow::position_lock_style_changed ()
728 glue_check_button.set_active (location->position_lock_style() == MusicTime);
734 LocationEditRow::focus_name()
736 name_entry.grab_focus ();
740 LocationEditRow::set_clock_editable_status ()
742 start_clock.set_editable (!location->locked());
743 end_clock.set_editable (!location->locked());
744 length_clock.set_editable (!location->locked());
747 /*------------------------------------------------------------------------*/
749 LocationUI::LocationUI ()
750 : add_location_button (_("New Marker"))
751 , add_range_button (_("New Range"))
753 i_am_the_modifier = 0;
755 _clock_group = new ClockGroup;
757 VBox* vbox = manage (new VBox);
759 Table* table = manage (new Table (2, 2));
760 table->set_spacings (2);
761 table->set_col_spacing (0, 32);
764 Label* l = manage (new Label (_("<b>Loop/Punch Ranges</b>")));
765 l->set_alignment (0, 0.5);
766 l->set_use_markup (true);
767 table->attach (*l, 0, 2, table_row, table_row + 1);
770 loop_edit_row.set_clock_group (*_clock_group);
771 punch_edit_row.set_clock_group (*_clock_group);
773 loop_punch_box.set_border_width (6); // 5 + 1 px framebox-border
774 loop_punch_box.pack_start (loop_edit_row, false, false);
775 loop_punch_box.pack_start (punch_edit_row, false, false);
777 table->attach (loop_punch_box, 1, 2, table_row, table_row + 1);
780 vbox->pack_start (*table, false, false);
782 table = manage (new Table (3, 2));
783 table->set_spacings (2);
784 table->set_col_spacing (0, 32);
787 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
790 l = manage (new Label (_("<b>Markers (Including CD Index)</b>")));
791 l->set_alignment (0, 0.5);
792 l->set_use_markup (true);
793 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
796 location_rows.set_name("LocationLocRows");
797 location_rows_scroller.add (location_rows);
798 location_rows_scroller.set_name ("LocationLocRowsScroller");
799 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
800 location_rows_scroller.set_size_request (-1, 130);
804 loc_frame_box.set_spacing (5);
805 loc_frame_box.set_border_width (5);
806 loc_frame_box.set_name("LocationFrameBox");
808 loc_frame_box.pack_start (location_rows_scroller, true, true);
810 add_location_button.set_name ("LocationAddLocationButton");
812 table->attach (loc_frame_box, 0, 2, table_row, table_row + 1);
815 loc_range_panes.add (*table);
817 table = manage (new Table (3, 2));
818 table->set_spacings (2);
819 table->set_col_spacing (0, 32);
822 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
825 l = manage (new Label (_("<b>Ranges (Including CD Track Ranges)</b>")));
826 l->set_alignment (0, 0.5);
827 l->set_use_markup (true);
828 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
831 range_rows.set_name("LocationRangeRows");
832 range_rows_scroller.add (range_rows);
833 range_rows_scroller.set_name ("LocationRangeRowsScroller");
834 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
835 range_rows_scroller.set_size_request (-1, 130);
837 range_frame_box.set_spacing (5);
838 range_frame_box.set_name("LocationFrameBox");
839 range_frame_box.set_border_width (5);
840 range_frame_box.pack_start (range_rows_scroller, true, true);
842 add_range_button.set_name ("LocationAddRangeButton");
844 table->attach (range_frame_box, 0, 2, table_row, table_row + 1);
847 loc_range_panes.add (*table);
849 HBox* add_button_box = manage (new HBox);
850 add_button_box->pack_start (add_location_button, true, true);
851 add_button_box->pack_start (add_range_button, true, true);
853 vbox->pack_start (loc_range_panes, true, true);
854 vbox->pack_start (*add_button_box, false, false);
858 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
859 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
863 signal_map().connect (sigc::mem_fun (*this, &LocationUI::refresh_location_list));
866 LocationUI::~LocationUI()
868 loop_edit_row.unset_clock_group ();
869 punch_edit_row.unset_clock_group ();
874 LocationUI::do_location_remove (ARDOUR::Location *loc)
876 /* this is handled internally by Locations, but there's
877 no point saving state etc. when we know the marker
881 if (loc->is_session_range()) {
885 PublicEditor::instance().begin_reversible_command (_("remove marker"));
886 XMLNode &before = _session->locations()->get_state();
887 _session->locations()->remove (loc);
888 XMLNode &after = _session->locations()->get_state();
889 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
890 PublicEditor::instance().commit_reversible_command ();
896 LocationUI::location_remove_requested (ARDOUR::Location *loc)
898 // must do this to prevent problems when destroying
899 // the effective sender of this event
901 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
906 LocationUI::location_redraw_ranges ()
912 struct LocationSortByStart {
913 bool operator() (Location *a, Location *b) {
914 return a->start() < b->start();
919 LocationUI::location_added (Location* location)
921 if (location->is_auto_punch()) {
922 punch_edit_row.set_location(location);
923 } else if (location->is_auto_loop()) {
924 loop_edit_row.set_location(location);
925 } else if (location->is_range_marker() || location->is_mark()) {
926 Locations::LocationList loc = _session->locations()->list ();
927 loc.sort (LocationSortByStart ());
929 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
931 erow->set_clock_group (*_clock_group);
932 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
934 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
936 /* Step through the location list and the GUI list to find the place to insert */
937 Locations::LocationList::iterator i = loc.begin ();
938 Box_Helpers::BoxList::iterator j = children.begin ();
939 while (i != loc.end()) {
941 if (location->flags() != (*i)->flags()) {
942 /* Skip locations in the session list that aren't of the right type */
947 if (*i == location) {
948 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
954 if (j != children.end()) {
959 range_rows.show_all ();
960 location_rows.show_all ();
962 if (location == newest_location) {
970 LocationUI::location_removed (Location* location)
972 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
974 if (location->is_auto_punch()) {
975 punch_edit_row.set_location(0);
976 } else if (location->is_auto_loop()) {
977 loop_edit_row.set_location(0);
978 } else if (location->is_range_marker() || location->is_mark()) {
979 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
980 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
981 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
982 if (r && r->get_location() == location) {
991 LocationUI::map_locations (const Locations::LocationList& locations)
993 Locations::LocationList::iterator i;
996 Locations::LocationList temp = locations;
997 LocationSortByStart cmp;
1001 for (n = 0, i = temp.begin(); i != temp.end(); ++n, ++i) {
1003 Location* location = *i;
1005 if (location->is_mark()) {
1006 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
1008 erow->set_clock_group (*_clock_group);
1009 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
1010 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
1012 Box_Helpers::BoxList & loc_children = location_rows.children();
1013 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
1014 } else if (location->is_auto_punch()) {
1015 punch_edit_row.set_session (_session);
1016 punch_edit_row.set_location (location);
1017 punch_edit_row.show_all();
1018 } else if (location->is_auto_loop()) {
1019 loop_edit_row.set_session (_session);
1020 loop_edit_row.set_location (location);
1021 loop_edit_row.show_all();
1023 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
1025 erow->set_clock_group (*_clock_group);
1026 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
1028 Box_Helpers::BoxList & range_children = range_rows.children();
1029 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
1033 range_rows.show_all();
1034 location_rows.show_all();
1038 LocationUI::add_new_location()
1043 framepos_t where = _session->audible_frame();
1044 _session->locations()->next_available_name(markername,"mark");
1045 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
1046 if (UIConfiguration::instance().get_name_new_markers()) {
1047 newest_location = location;
1049 PublicEditor::instance().begin_reversible_command (_("add marker"));
1050 XMLNode &before = _session->locations()->get_state();
1051 _session->locations()->add (location, true);
1052 XMLNode &after = _session->locations()->get_state();
1053 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1054 PublicEditor::instance().commit_reversible_command ();
1060 LocationUI::add_new_range()
1065 framepos_t where = _session->audible_frame();
1066 _session->locations()->next_available_name(rangename,"unnamed");
1067 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
1068 PublicEditor::instance().begin_reversible_command (_("add range marker"));
1069 XMLNode &before = _session->locations()->get_state();
1070 _session->locations()->add (location, true);
1071 XMLNode &after = _session->locations()->get_state();
1072 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1073 PublicEditor::instance().commit_reversible_command ();
1078 LocationUI::refresh_location_list ()
1080 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
1081 using namespace Box_Helpers;
1083 // this is just too expensive to do when window is not shown
1088 BoxList & loc_children = location_rows.children();
1089 BoxList & range_children = range_rows.children();
1091 loc_children.clear();
1092 range_children.clear();
1095 _session->locations()->apply (*this, &LocationUI::map_locations);
1100 LocationUI::set_session(ARDOUR::Session* s)
1102 SessionHandlePtr::set_session (s);
1105 _session->locations()->added.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_added, this, _1), gui_context());
1106 _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_removed, this, _1), gui_context());
1107 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
1109 _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
1112 loop_edit_row.set_session (s);
1113 punch_edit_row.set_session (s);
1115 refresh_location_list ();
1119 LocationUI::session_going_away()
1121 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
1123 using namespace Box_Helpers;
1124 BoxList & loc_children = location_rows.children();
1125 BoxList & range_children = range_rows.children();
1127 loc_children.clear();
1128 range_children.clear();
1130 loop_edit_row.set_session (0);
1131 loop_edit_row.set_location (0);
1133 punch_edit_row.set_session (0);
1134 punch_edit_row.set_location (0);
1136 SessionHandlePtr::session_going_away ();
1140 LocationUI::get_state () const
1142 XMLNode* node = new XMLNode (X_("LocationUI"));
1143 node->add_property (X_("clock-mode"), enum_2_string (_clock_group->clock_mode ()));
1148 LocationUI::clock_mode_from_session_instant_xml () const
1150 XMLNode* node = _session->instant_xml (X_("LocationUI"));
1152 return AudioClock::Frames;
1155 XMLProperty const * p = node->property (X_("clock-mode"));
1157 return ARDOUR_UI::instance()->secondary_clock->mode();
1160 return (AudioClock::Mode) string_2_enum (p->value (), AudioClock::Mode);
1164 /*------------------------*/
1166 LocationUIWindow::LocationUIWindow ()
1167 : ArdourWindow (S_("Ranges|Locations"))
1169 set_wmclass(X_("ardour_locations"), PROGRAM_NAME);
1170 set_name ("LocationWindow");
1175 LocationUIWindow::~LocationUIWindow()
1180 LocationUIWindow::on_map ()
1182 ArdourWindow::on_map ();
1183 _ui.refresh_location_list();
1187 LocationUIWindow::on_delete_event (GdkEventAny*)
1193 LocationUIWindow::set_session (Session *s)
1195 ArdourWindow::set_session (s);
1196 _ui.set_session (s);
1201 LocationUIWindow::session_going_away ()
1203 ArdourWindow::session_going_away ();