2 * Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
4 * Copyright (C) 2006 Hans Fugal <hans@fugal.net>
5 * Copyright (C) 2008-2012 David Robillard <d@drobilla.net>
6 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
7 * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
8 * Copyright (C) 2013 Colin Fletcher <colin.m.fletcher@googlemail.com>
9 * Copyright (C) 2014-2016 Nick Mainsbridge <mainsbridge@gmail.com>
10 * Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <gtkmm2ext/utils.h>
32 #include "ardour/session.h"
33 #include "pbd/memento_command.h"
34 #include "widgets/tooltips.h"
36 #include "ardour_ui.h"
37 #include "clock_group.h"
38 #include "enums_convert.h"
39 #include "main_clock.h"
40 #include "gui_thread.h"
42 #include "location_ui.h"
44 #include "public_editor.h"
45 #include "ui_config.h"
50 using namespace ARDOUR;
51 using namespace ArdourWidgets;
54 using namespace Gtkmm2ext;
56 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
57 : SessionHandlePtr (0) /* explicitly set below */
59 , item_table (1, 6, false)
60 , start_clock (X_("locationstart"), true, "", true, false)
61 , start_to_playhead_button (_("Use PH"))
62 , locate_to_start_button (_("Goto"))
63 , end_clock (X_("locationend"), true, "", true, false)
64 , end_to_playhead_button (_("Use PH"))
65 , locate_to_end_button (_("Goto"))
66 , length_clock (X_("locationlength"), true, "", true, false, true)
67 , cd_check_button (_("CD"))
68 , hide_check_button (_("Hide"))
69 , lock_check_button (_("Lock"))
70 , glue_check_button (_("Glue"))
74 i_am_the_modifier = 0;
76 remove_button.set_icon (ArdourIcon::CloseCross);
77 remove_button.set_events (remove_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
79 number_label.set_name ("LocationEditNumberLabel");
80 date_label.set_name ("LocationDateLabel");
81 name_label.set_name ("LocationEditNameLabel");
82 name_entry.set_name ("LocationEditNameEntry");
83 cd_check_button.set_name ("LocationEditCdButton");
84 hide_check_button.set_name ("LocationEditHideButton");
85 lock_check_button.set_name ("LocationEditLockButton");
86 glue_check_button.set_name ("LocationEditGlueButton");
87 isrc_label.set_name ("LocationEditNumberLabel");
88 isrc_entry.set_name ("LocationEditNameEntry");
89 scms_check_button.set_name ("LocationEditCdButton");
90 preemph_check_button.set_name ("LocationEditCdButton");
91 performer_label.set_name ("LocationEditNumberLabel");
92 performer_entry.set_name ("LocationEditNameEntry");
93 composer_label.set_name ("LocationEditNumberLabel");
94 composer_entry.set_name ("LocationEditNameEntry");
96 isrc_label.set_text (X_("ISRC:"));
97 performer_label.set_text (_("Performer:"));
98 composer_label.set_text (_("Composer:"));
99 scms_label.set_text (X_("SCMS"));
100 preemph_label.set_text (_("Pre-Emphasis"));
102 isrc_entry.set_size_request (112, -1);
103 isrc_entry.set_max_length(12);
104 isrc_entry.set_editable (true);
106 performer_entry.set_size_request (100, -1);
107 performer_entry.set_editable (true);
109 composer_entry.set_size_request (100, -1);
110 composer_entry.set_editable (true);
112 name_label.set_alignment (0, 0.5);
114 Gtk::HBox* front_spacing = manage (new HBox);
115 front_spacing->set_size_request (20, -1);
116 Gtk::HBox* mid_spacing = manage (new HBox);
117 mid_spacing->set_size_request (20, -1);
119 cd_track_details_hbox.set_spacing (4);
120 cd_track_details_hbox.pack_start (*front_spacing, false, false);
121 cd_track_details_hbox.pack_start (isrc_label, false, false);
122 cd_track_details_hbox.pack_start (isrc_entry, false, false);
123 cd_track_details_hbox.pack_start (performer_label, false, false);
124 cd_track_details_hbox.pack_start (performer_entry, true, true);
125 cd_track_details_hbox.pack_start (composer_label, false, false);
126 cd_track_details_hbox.pack_start (composer_entry, true, true);
127 cd_track_details_hbox.pack_start (*mid_spacing, false, false);
128 cd_track_details_hbox.pack_start (scms_label, false, false);
129 cd_track_details_hbox.pack_start (scms_check_button, false, false);
130 cd_track_details_hbox.pack_start (preemph_label, false, false);
131 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
133 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
134 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
135 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
136 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
137 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
141 start_hbox.set_spacing (2);
142 start_hbox.pack_start (locate_to_start_button, false, false);
143 start_hbox.pack_start (start_clock, false, false);
144 start_hbox.pack_start (start_to_playhead_button, false, false);
146 /* this is always in this location, no matter what the location is */
148 item_table.attach (remove_button, 8, 9, 0, 1, SHRINK, SHRINK, 4, 1);
149 item_table.attach (start_hbox, 0, 1, 0, 1, FILL, Gtk::AttachOptions(0), 4, 0);
151 start_to_playhead_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocStart));
152 locate_to_start_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_button_pressed), LocStart));
153 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
154 start_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &start_clock), false);
156 end_hbox.set_spacing (2);
157 end_hbox.pack_start (locate_to_end_button, false, false);
158 end_hbox.pack_start (end_clock, false, false);
159 end_hbox.pack_start (end_to_playhead_button, false, false);
161 end_to_playhead_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocEnd));
162 locate_to_end_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_button_pressed), LocEnd));
163 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
164 end_clock.signal_button_press_event().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::locate_to_clock), &end_clock), false);
166 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
168 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
169 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
170 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
171 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
173 remove_button.signal_clicked.connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
175 pack_start(item_table, true, true);
179 cd_toggled(); // show/hide cd-track details
182 LocationEditRow::~LocationEditRow()
185 connections.drop_connections ();
189 _clock_group->remove (start_clock);
190 _clock_group->remove (end_clock);
191 _clock_group->remove (length_clock);
196 LocationEditRow::set_clock_group (ClockGroup& cg)
199 _clock_group->remove (start_clock);
200 _clock_group->remove (end_clock);
201 _clock_group->remove (length_clock);
206 _clock_group->add (start_clock);
207 _clock_group->add (end_clock);
208 _clock_group->add (length_clock);
212 LocationEditRow::set_session (Session *sess)
214 SessionHandlePtr::set_session (sess);
220 start_clock.set_session (_session);
221 end_clock.set_session (_session);
222 length_clock.set_session (_session);
226 LocationEditRow::set_number (int num)
231 number_label.set_text (string_compose ("%1", number));
236 LocationEditRow::set_location (Location *loc)
239 connections.drop_connections ();
250 if (!hide_check_button.get_parent()) {
251 item_table.attach (hide_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
252 item_table.attach (lock_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
253 item_table.attach (glue_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
255 Glib::DateTime gdt(Glib::DateTime::create_now_local (location->timestamp()));
256 string date = gdt.format ("%F %H:%M");
257 date_label.set_text(date);
258 item_table.attach (date_label, 9, 10, 0, 1, FILL, Gtk::FILL, 4, 0);
261 hide_check_button.set_active (location->is_hidden());
262 lock_check_button.set_active (location->locked());
263 glue_check_button.set_active (location->position_lock_style() == MusicTime);
265 if (location->is_auto_loop() || location-> is_auto_punch()) {
266 // use label instead of entry
268 name_label.set_text (location->name());
269 name_label.set_size_request (80, -1);
271 remove_button.hide ();
273 if (!name_label.get_parent()) {
274 item_table.attach (name_label, 2, 3, 0, 1, EXPAND|FILL, FILL, 4, 0);
281 name_entry.set_text (location->name());
282 name_entry.set_size_request (100, -1);
283 name_entry.set_editable (true);
284 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
286 if (!name_entry.get_parent()) {
287 item_table.attach (name_entry, 2, 3, 0, 1, FILL | EXPAND, FILL, 4, 0);
291 if (!cd_check_button.get_parent()) {
292 item_table.attach (cd_check_button, 4, 5, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
295 if (location->is_session_range()) {
296 remove_button.set_sensitive (false);
299 cd_check_button.set_active (location->is_cd_marker());
300 cd_check_button.show();
302 if (location->start() == _session->current_start_sample()) {
303 cd_check_button.set_sensitive (false);
305 cd_check_button.set_sensitive (true);
308 hide_check_button.show();
309 lock_check_button.show();
310 glue_check_button.show();
313 start_clock.set (location->start(), true);
316 if (!location->is_mark()) {
317 if (!end_hbox.get_parent()) {
318 item_table.attach (end_hbox, 1, 2, 0, 1, FILL, Gtk::AttachOptions (0), 4, 0);
320 if (!length_clock.get_parent()) {
321 end_hbox.pack_start (length_clock, false, false, 4);
324 end_clock.set (location->end(), true);
325 length_clock.set (location->length(), true);
330 if (location->is_cd_marker()) {
331 show_cd_track_details ();
334 set_tooltip (&remove_button, _("Remove this range"));
335 set_tooltip (start_clock, _("Start time - middle click to locate here"));
336 set_tooltip (end_clock, _("End time - middle click to locate here"));
337 set_tooltip (length_clock, _("Length"));
339 set_tooltip (&start_to_playhead_button, _("Set range start from playhead location"));
340 set_tooltip (&end_to_playhead_button, _("Set range end from playhead location"));
344 set_tooltip (&remove_button, _("Remove this marker"));
345 set_tooltip (start_clock, _("Position - middle click to locate here"));
347 set_tooltip (&start_to_playhead_button, _("Set marker time from playhead location"));
353 set_clock_editable_status ();
357 /* connect to per-location signals, since this row only cares about this location */
359 location->NameChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::name_changed, this), gui_context());
360 location->StartChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::start_changed, this), gui_context());
361 location->EndChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::end_changed, this), gui_context());
362 location->Changed.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::location_changed, this), gui_context());
363 location->FlagsChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::flags_changed, this), gui_context());
364 location->LockChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::lock_changed, this), gui_context());
365 location->PositionLockStyleChanged.connect (connections, invalidator (*this), boost::bind (&LocationEditRow::position_lock_style_changed, this), gui_context());
369 LocationEditRow::name_entry_changed ()
371 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed);
373 if (i_am_the_modifier || !location) {
377 location->set_name (name_entry.get_text());
382 LocationEditRow::isrc_entry_changed ()
384 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed);
386 if (i_am_the_modifier || !location) return;
388 if (isrc_entry.get_text() != "" ) {
390 location->cd_info["isrc"] = isrc_entry.get_text();
393 location->cd_info.erase("isrc");
398 LocationEditRow::performer_entry_changed ()
400 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed);
402 if (i_am_the_modifier || !location) return;
404 if (performer_entry.get_text() != "") {
405 location->cd_info["performer"] = performer_entry.get_text();
407 location->cd_info.erase("performer");
412 LocationEditRow::composer_entry_changed ()
414 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed);
416 if (i_am_the_modifier || !location) return;
418 if (composer_entry.get_text() != "") {
419 location->cd_info["composer"] = composer_entry.get_text();
421 location->cd_info.erase("composer");
426 LocationEditRow::to_playhead_button_pressed (LocationPart part)
432 const int32_t divisions = PublicEditor::instance().get_grid_music_divisions (0);
436 location->set_start (_session->transport_sample (), false, true, divisions);
439 location->set_end (_session->transport_sample (), false, true,divisions);
440 if (location->is_session_range()) {
441 _session->set_session_range_is_free (false);
450 LocationEditRow::locate_button_pressed (LocationPart part)
454 _session->request_locate (start_clock.current_time());
457 _session->request_locate (end_clock.current_time());
465 LocationEditRow::locate_to_clock (GdkEventButton* ev, AudioClock* clock)
467 if (Keyboard::is_button2_event (ev)) {
468 _session->request_locate (clock->current_time());
475 LocationEditRow::clock_changed (LocationPart part)
477 if (i_am_the_modifier || !location) {
481 const int32_t divisions = PublicEditor::instance().get_grid_music_divisions (0);
485 location->set_start (start_clock.current_time(), false, true, divisions);
488 location->set_end (end_clock.current_time(), false, true, divisions);
489 if (location->is_session_range()) {
490 _session->set_session_range_is_free (false);
494 location->set_end (location->start() + length_clock.current_duration(), false, true, divisions);
495 if (location->is_session_range()) {
496 _session->set_session_range_is_free (false);
504 LocationEditRow::show_cd_track_details ()
506 if (location->cd_info.find("isrc") != location->cd_info.end()) {
507 isrc_entry.set_text(location->cd_info["isrc"]);
509 if (location->cd_info.find("performer") != location->cd_info.end()) {
510 performer_entry.set_text(location->cd_info["performer"]);
512 if (location->cd_info.find("composer") != location->cd_info.end()) {
513 composer_entry.set_text(location->cd_info["composer"]);
515 if (location->cd_info.find("scms") != location->cd_info.end()) {
516 scms_check_button.set_active(true);
518 if (location->cd_info.find("preemph") != location->cd_info.end()) {
519 preemph_check_button.set_active(true);
523 if (!cd_track_details_hbox.get_parent()) {
524 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
526 // item_table.resize(2, 7);
527 cd_track_details_hbox.show_all();
531 LocationEditRow::cd_toggled ()
533 if (i_am_the_modifier || !location) {
537 //if (cd_check_button.get_active() == location->is_cd_marker()) {
541 if (cd_check_button.get_active()) {
542 if (location->start() <= _session->current_start_sample()) {
543 error << _("You cannot put a CD marker at the start of the session") << endmsg;
544 cd_check_button.set_active (false);
549 location->set_cd (cd_check_button.get_active(), this);
551 if (location->is_cd_marker()) {
553 show_cd_track_details ();
555 } else if (cd_track_details_hbox.get_parent()){
557 item_table.remove (cd_track_details_hbox);
558 // item_table.resize(1, 7);
559 redraw_ranges(); /* EMIT_SIGNAL */
564 LocationEditRow::hide_toggled ()
566 if (i_am_the_modifier || !location) {
570 location->set_hidden (hide_check_button.get_active(), this);
574 LocationEditRow::lock_toggled ()
576 if (i_am_the_modifier || !location) {
580 if (location->locked()) {
588 LocationEditRow::glue_toggled ()
590 if (i_am_the_modifier || !location) {
594 if (location->position_lock_style() == AudioTime) {
595 location->set_position_lock_style (MusicTime);
597 location->set_position_lock_style (AudioTime);
602 LocationEditRow::remove_button_pressed ()
608 remove_requested (location); /* EMIT_SIGNAL */
614 LocationEditRow::scms_toggled ()
616 if (i_am_the_modifier || !location) return;
618 if (scms_check_button.get_active()) {
619 location->cd_info["scms"] = "on";
621 location->cd_info.erase("scms");
627 LocationEditRow::preemph_toggled ()
629 if (i_am_the_modifier || !location) return;
631 if (preemph_check_button.get_active()) {
632 location->cd_info["preemph"] = "on";
634 location->cd_info.erase("preemph");
639 LocationEditRow::end_changed ()
641 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
643 if (!location) return;
645 // update end and length
648 end_clock.set (location->end());
649 length_clock.set (location->length());
655 LocationEditRow::start_changed ()
657 if (!location) return;
659 // update end and length
662 start_clock.set (location->start());
664 if (location->start() == _session->current_start_sample()) {
665 cd_check_button.set_sensitive (false);
667 cd_check_button.set_sensitive (true);
674 LocationEditRow::name_changed ()
676 if (!location) return;
678 // update end and length
681 name_entry.set_text(location->name());
682 name_label.set_text(location->name());
689 LocationEditRow::location_changed ()
692 if (!location) return;
696 start_clock.set (location->start());
697 end_clock.set (location->end());
698 length_clock.set (location->length());
700 set_clock_editable_status ();
707 LocationEditRow::flags_changed ()
715 cd_check_button.set_active (location->is_cd_marker());
716 hide_check_button.set_active (location->is_hidden());
717 glue_check_button.set_active (location->position_lock_style() == MusicTime);
723 LocationEditRow::lock_changed ()
731 lock_check_button.set_active (location->locked());
733 set_clock_editable_status ();
739 LocationEditRow::position_lock_style_changed ()
747 glue_check_button.set_active (location->position_lock_style() == MusicTime);
753 LocationEditRow::focus_name()
755 name_entry.grab_focus ();
759 LocationEditRow::set_clock_editable_status ()
761 start_clock.set_editable (!location->locked());
762 end_clock.set_editable (!location->locked());
763 length_clock.set_editable (!location->locked());
766 /*------------------------------------------------------------------------*/
768 LocationUI::LocationUI (std::string state_node_name)
769 : add_location_button (_("New Marker"))
770 , add_range_button (_("New Range"))
771 , _mode (AudioClock::Samples)
773 , _state_node_name (state_node_name)
775 i_am_the_modifier = 0;
777 _clock_group = new ClockGroup;
779 VBox* vbox = manage (new VBox);
781 Table* table = manage (new Table (2, 2));
782 table->set_spacings (2);
783 table->set_col_spacing (0, 32);
786 Label* l = manage (new Label (_("<b>Loop/Punch Ranges</b>")));
787 l->set_alignment (0, 0.5);
788 l->set_use_markup (true);
789 table->attach (*l, 0, 2, table_row, table_row + 1);
792 loop_edit_row.set_clock_group (*_clock_group);
793 punch_edit_row.set_clock_group (*_clock_group);
795 loop_punch_box.set_border_width (6); // 5 + 1 px framebox-border
796 loop_punch_box.pack_start (loop_edit_row, false, false);
797 loop_punch_box.pack_start (punch_edit_row, false, false);
799 table->attach (loop_punch_box, 1, 2, table_row, table_row + 1);
802 vbox->pack_start (*table, false, false);
804 table = manage (new Table (3, 2));
805 table->set_spacings (2);
806 table->set_col_spacing (0, 32);
809 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
812 l = manage (new Label (_("<b>Markers (Including CD Index)</b>")));
813 l->set_alignment (0, 0.5);
814 l->set_use_markup (true);
815 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
818 location_rows.set_name("LocationLocRows");
819 location_rows_scroller.add (location_rows);
820 location_rows_scroller.set_name ("LocationLocRowsScroller");
821 location_rows_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
822 location_rows_scroller.set_size_request (-1, 130);
826 loc_frame_box.set_spacing (5);
827 loc_frame_box.set_border_width (5);
828 loc_frame_box.set_name("LocationFrameBox");
830 loc_frame_box.pack_start (location_rows_scroller, true, true);
832 add_location_button.set_name ("LocationAddLocationButton");
834 table->attach (loc_frame_box, 0, 2, table_row, table_row + 1);
837 loc_range_panes.add (*table);
839 table = manage (new Table (3, 2));
840 table->set_spacings (2);
841 table->set_col_spacing (0, 32);
844 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
847 l = manage (new Label (_("<b>Ranges (Including CD Track Ranges)</b>")));
848 l->set_alignment (0, 0.5);
849 l->set_use_markup (true);
850 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
853 range_rows.set_name("LocationRangeRows");
854 range_rows_scroller.add (range_rows);
855 range_rows_scroller.set_name ("LocationRangeRowsScroller");
856 range_rows_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
857 range_rows_scroller.set_size_request (-1, 130);
859 range_frame_box.set_spacing (5);
860 range_frame_box.set_name("LocationFrameBox");
861 range_frame_box.set_border_width (5);
862 range_frame_box.pack_start (range_rows_scroller, true, true);
864 add_range_button.set_name ("LocationAddRangeButton");
866 table->attach (range_frame_box, 0, 2, table_row, table_row + 1);
869 loc_range_panes.add (*table);
871 HBox* add_button_box = manage (new HBox);
872 add_button_box->pack_start (add_location_button, true, true);
873 add_button_box->pack_start (add_range_button, true, true);
875 vbox->pack_start (loc_range_panes, true, true);
876 vbox->pack_start (*add_button_box, false, false);
880 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
881 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
885 signal_map().connect (sigc::mem_fun (*this, &LocationUI::refresh_location_list));
888 LocationUI::~LocationUI()
890 loop_edit_row.unset_clock_group ();
891 punch_edit_row.unset_clock_group ();
896 LocationUI::do_location_remove (ARDOUR::Location *loc)
898 /* this is handled internally by Locations, but there's
899 no point saving state etc. when we know the marker
903 if (loc->is_session_range()) {
907 PublicEditor::instance().begin_reversible_command (_("remove marker"));
908 XMLNode &before = _session->locations()->get_state();
909 _session->locations()->remove (loc);
910 XMLNode &after = _session->locations()->get_state();
911 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
912 PublicEditor::instance().commit_reversible_command ();
918 LocationUI::location_remove_requested (ARDOUR::Location *loc)
920 // must do this to prevent problems when destroying
921 // the effective sender of this event
923 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
928 LocationUI::location_redraw_ranges ()
934 struct LocationSortByStart {
935 bool operator() (Location *a, Location *b) {
936 return a->start() < b->start();
941 LocationUI::location_added (Location* location)
943 if (location->is_auto_punch()) {
944 punch_edit_row.set_location(location);
945 } else if (location->is_auto_loop()) {
946 loop_edit_row.set_location(location);
947 } else if (location->is_range_marker() || location->is_mark()) {
948 Locations::LocationList loc = _session->locations()->list ();
949 loc.sort (LocationSortByStart ());
951 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
953 erow->set_clock_group (*_clock_group);
954 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
956 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
958 /* Step through the location list and the GUI list to find the place to insert */
959 Locations::LocationList::iterator i = loc.begin ();
960 Box_Helpers::BoxList::iterator j = children.begin ();
961 while (i != loc.end()) {
963 if (location->flags() != (*i)->flags()) {
964 /* Skip locations in the session list that aren't of the right type */
969 if (*i == location) {
970 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
976 if (j != children.end()) {
981 range_rows.show_all ();
982 location_rows.show_all ();
984 if (location == newest_location) {
992 LocationUI::location_removed (Location* location)
994 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
996 if (location->is_auto_punch()) {
997 punch_edit_row.set_location(0);
998 } else if (location->is_auto_loop()) {
999 loop_edit_row.set_location(0);
1000 } else if (location->is_range_marker() || location->is_mark()) {
1001 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
1002 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
1003 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
1004 if (r && r->get_location() == location) {
1013 LocationUI::map_locations (const Locations::LocationList& locations)
1015 Locations::LocationList::iterator i;
1018 Locations::LocationList temp = locations;
1019 LocationSortByStart cmp;
1023 for (n = 0, i = temp.begin(); i != temp.end(); ++n, ++i) {
1025 Location* location = *i;
1027 if (location->is_mark()) {
1028 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
1030 erow->set_clock_group (*_clock_group);
1031 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
1032 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
1034 Box_Helpers::BoxList & loc_children = location_rows.children();
1035 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
1036 } else if (location->is_auto_punch()) {
1037 punch_edit_row.set_session (_session);
1038 punch_edit_row.set_location (location);
1039 punch_edit_row.show_all();
1040 } else if (location->is_auto_loop()) {
1041 loop_edit_row.set_session (_session);
1042 loop_edit_row.set_location (location);
1043 loop_edit_row.show_all();
1045 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
1047 erow->set_clock_group (*_clock_group);
1048 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
1050 Box_Helpers::BoxList & range_children = range_rows.children();
1051 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
1055 range_rows.show_all();
1056 location_rows.show_all();
1060 LocationUI::add_new_location()
1065 samplepos_t where = _session->audible_sample();
1066 _session->locations()->next_available_name(markername,"mark");
1067 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
1068 if (UIConfiguration::instance().get_name_new_markers()) {
1069 newest_location = location;
1071 PublicEditor::instance().begin_reversible_command (_("add marker"));
1072 XMLNode &before = _session->locations()->get_state();
1073 _session->locations()->add (location, true);
1074 XMLNode &after = _session->locations()->get_state();
1075 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1076 PublicEditor::instance().commit_reversible_command ();
1082 LocationUI::add_new_range()
1087 samplepos_t where = _session->audible_sample();
1088 _session->locations()->next_available_name(rangename,"unnamed");
1089 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
1090 PublicEditor::instance().begin_reversible_command (_("add range marker"));
1091 XMLNode &before = _session->locations()->get_state();
1092 _session->locations()->add (location, true);
1093 XMLNode &after = _session->locations()->get_state();
1094 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1095 PublicEditor::instance().commit_reversible_command ();
1100 LocationUI::refresh_location_list ()
1102 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
1103 using namespace Box_Helpers;
1105 // this is just too expensive to do when window is not shown
1110 BoxList & loc_children = location_rows.children();
1111 BoxList & range_children = range_rows.children();
1113 loc_children.clear();
1114 range_children.clear();
1117 _session->locations()->apply (*this, &LocationUI::map_locations);
1122 LocationUI::set_session(ARDOUR::Session* s)
1124 SessionHandlePtr::set_session (s);
1127 _session->locations()->added.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_added, this, _1), gui_context());
1128 _session->locations()->removed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::location_removed, this, _1), gui_context());
1129 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
1131 _clock_group->set_clock_mode (clock_mode_from_session_instant_xml ());
1136 loop_edit_row.set_session (s);
1137 punch_edit_row.set_session (s);
1139 refresh_location_list ();
1143 LocationUI::session_going_away()
1145 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
1147 using namespace Box_Helpers;
1148 BoxList & loc_children = location_rows.children();
1149 BoxList & range_children = range_rows.children();
1151 loc_children.clear();
1152 range_children.clear();
1154 loop_edit_row.set_session (0);
1155 loop_edit_row.set_location (0);
1157 punch_edit_row.set_session (0);
1158 punch_edit_row.set_location (0);
1162 SessionHandlePtr::session_going_away ();
1166 LocationUI::get_state () const
1168 XMLNode* node = new XMLNode (_state_node_name);
1169 node->set_property (X_("clock-mode"), _clock_group->clock_mode ());
1174 LocationUI::set_state (const XMLNode& node)
1176 if (node.name() != _state_node_name) {
1180 if (!node.get_property (X_("clock-mode"), _mode)) {
1185 _clock_group->set_clock_mode (_mode);
1190 LocationUI::clock_mode_from_session_instant_xml ()
1196 XMLNode* node = _session->instant_xml (_state_node_name);
1198 return ARDOUR_UI::instance()->primary_clock->mode();
1201 if (!node->get_property (X_("clock-mode"), _mode)) {
1202 return ARDOUR_UI::instance()->primary_clock->mode();
1210 /*------------------------*/
1212 LocationUIWindow::LocationUIWindow ()
1213 : ArdourWindow (S_("Ranges|Locations"))
1215 set_wmclass(X_("ardour_locations"), PROGRAM_NAME);
1216 set_name ("LocationWindow");
1221 LocationUIWindow::~LocationUIWindow()
1226 LocationUIWindow::on_map ()
1228 ArdourWindow::on_map ();
1229 _ui.refresh_location_list();
1233 LocationUIWindow::on_delete_event (GdkEventAny*)
1239 LocationUIWindow::set_session (Session *s)
1241 ArdourWindow::set_session (s);
1242 _ui.set_session (s);
1247 LocationUIWindow::session_going_away ()
1249 ArdourWindow::session_going_away ();