Remove erroneous assert which I added earlier.
[ardour2.git] / gtk2_ardour / location_ui.cc
blobc0f5d1f325a59cc0e7833d26b53beecf5d783a66
1 /*
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.
20 #include <cmath>
21 #include <cstdlib>
23 #include <gtkmm2ext/utils.h>
25 #include "ardour/utils.h"
26 #include "ardour/configuration.h"
27 #include "ardour/session.h"
28 #include "pbd/memento_command.h"
30 #include "ardour_ui.h"
31 #include "clock_group.h"
32 #include "gui_thread.h"
33 #include "keyboard.h"
34 #include "location_ui.h"
35 #include "prompter.h"
36 #include "utils.h"
38 #include "i18n.h"
40 using namespace std;
41 using namespace ARDOUR;
42 using namespace PBD;
43 using namespace Gtk;
44 using namespace Gtkmm2ext;
46 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
47 : SessionHandlePtr (0) /* explicitly set below */
48 , location(0)
49 , item_table (1, 6, false)
50 , start_clock (X_("locationstart"), true, X_("LocationEditRowClock"), true, false)
51 , end_clock (X_("locationend"), true, X_("LocationEditRowClock"), true, false)
52 , length_clock (X_("locationlength"), true, X_("LocationEditRowClock"), true, false, true)
53 , cd_check_button (_("CD"))
54 , hide_check_button (_("Hide"))
55 , lock_check_button (_("Lock"))
56 , glue_check_button (_("Glue"))
57 , scms_check_button (_("SCMS"))
58 , preemph_check_button (_("Pre-Emphasis"))
59 , _clock_group (0)
61 i_am_the_modifier = 0;
63 start_go_button.set_image (*manage (new Image (Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
64 end_go_button.set_image (*manage (new Image (Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
65 remove_button.set_image (*manage (new Image (Stock::REMOVE, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
67 number_label.set_name ("LocationEditNumberLabel");
68 name_label.set_name ("LocationEditNameLabel");
69 name_entry.set_name ("LocationEditNameEntry");
70 start_go_button.set_name ("LocationEditGoButton");
71 end_go_button.set_name ("LocationEditGoButton");
72 cd_check_button.set_name ("LocationEditCdButton");
73 hide_check_button.set_name ("LocationEditHideButton");
74 lock_check_button.set_name ("LocationEditLockButton");
75 glue_check_button.set_name ("LocationEditGlueButton");
76 remove_button.set_name ("LocationEditRemoveButton");
77 isrc_label.set_name ("LocationEditNumberLabel");
78 isrc_entry.set_name ("LocationEditNameEntry");
79 scms_check_button.set_name ("LocationEditCdButton");
80 preemph_check_button.set_name ("LocationEditCdButton");
81 performer_label.set_name ("LocationEditNumberLabel");
82 performer_entry.set_name ("LocationEditNameEntry");
83 composer_label.set_name ("LocationEditNumberLabel");
84 composer_entry.set_name ("LocationEditNameEntry");
86 Gtk::Button* start_to_playhead_button = manage (new Button (_("Use PH")));
87 Gtk::Button* end_to_playhead_button = manage (new Button (_("Use PH")));
89 ARDOUR_UI::instance()->tooltips().set_tip (*start_to_playhead_button, _("Set value to playhead"));
90 ARDOUR_UI::instance()->tooltips().set_tip (*end_to_playhead_button, _("Set value to playhead"));
92 isrc_label.set_text ("ISRC: ");
93 isrc_label.set_size_request (30, -1);
94 performer_label.set_text ("Performer: ");
95 performer_label.set_size_request (60, -1);
96 composer_label.set_text ("Composer: ");
97 composer_label.set_size_request (60, -1);
99 isrc_entry.set_size_request (112, -1);
100 isrc_entry.set_max_length(12);
101 isrc_entry.set_editable (true);
103 performer_entry.set_size_request (100, -1);
104 performer_entry.set_editable (true);
106 composer_entry.set_size_request (100, -1);
107 composer_entry.set_editable (true);
109 name_label.set_alignment (0, 0.5);
111 cd_track_details_hbox.pack_start (isrc_label, false, false);
112 cd_track_details_hbox.pack_start (isrc_entry, false, false);
113 cd_track_details_hbox.pack_start (scms_check_button, false, false);
114 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
115 cd_track_details_hbox.pack_start (performer_label, false, false);
116 cd_track_details_hbox.pack_start (performer_entry, true, true);
117 cd_track_details_hbox.pack_start (composer_label, false, false);
118 cd_track_details_hbox.pack_start (composer_entry, true, true);
120 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
121 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
122 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
123 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
124 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
126 set_session (sess);
128 start_hbox.pack_start (start_go_button, false, false);
129 start_hbox.pack_start (start_clock, false, false);
130 start_hbox.pack_start (*start_to_playhead_button, false, false);
132 /* this is always in this location, no matter what the location is */
134 item_table.attach (start_hbox, 1, 2, 0, 1, FILL, FILL, 4, 0);
136 start_go_button.signal_clicked().connect(sigc::bind (sigc::mem_fun (*this, &LocationEditRow::go_button_pressed), LocStart));
137 start_to_playhead_button->signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocStart));
138 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
139 start_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocStart));
141 end_hbox.pack_start (end_go_button, false, false);
142 end_hbox.pack_start (end_clock, false, false);
143 end_hbox.pack_start (*end_to_playhead_button, false, false);
145 end_go_button.signal_clicked().connect(sigc::bind (sigc::mem_fun (*this, &LocationEditRow::go_button_pressed), LocEnd));
146 end_to_playhead_button->signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::to_playhead_button_pressed), LocEnd));
147 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
148 end_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocEnd));
150 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
151 length_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocLength));
153 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
154 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
155 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
156 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
158 remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
160 pack_start(item_table, true, true);
162 set_location (loc);
163 set_number (num);
166 LocationEditRow::~LocationEditRow()
168 if (location) {
169 connections.drop_connections ();
172 if (_clock_group) {
173 _clock_group->remove (start_clock);
174 _clock_group->remove (end_clock);
175 _clock_group->remove (length_clock);
179 void
180 LocationEditRow::set_clock_group (ClockGroup& cg)
182 if (_clock_group) {
183 _clock_group->remove (start_clock);
184 _clock_group->remove (end_clock);
185 _clock_group->remove (length_clock);
188 _clock_group = &cg;
190 _clock_group->add (start_clock);
191 _clock_group->add (end_clock);
192 _clock_group->add (length_clock);
195 void
196 LocationEditRow::set_session (Session *sess)
198 SessionHandlePtr::set_session (sess);
200 if (!_session) {
201 return;
204 start_clock.set_session (_session);
205 end_clock.set_session (_session);
206 length_clock.set_session (_session);
210 void
211 LocationEditRow::set_number (int num)
213 number = num;
215 if (number >= 0 ) {
216 number_label.set_text (string_compose ("%1", number));
220 void
221 LocationEditRow::set_location (Location *loc)
223 if (location) {
224 connections.drop_connections ();
227 location = loc;
229 if (!location) {
230 return;
233 ++i_am_the_modifier;
235 if (!hide_check_button.get_parent()) {
236 item_table.attach (hide_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
237 item_table.attach (lock_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
238 item_table.attach (glue_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
240 hide_check_button.set_active (location->is_hidden());
241 lock_check_button.set_active (location->locked());
242 glue_check_button.set_active (location->position_lock_style() == MusicTime);
244 if (location->is_auto_loop() || location-> is_auto_punch()) {
245 // use label instead of entry
247 name_label.set_text (location->name());
248 name_label.set_size_request (80, -1);
250 if (!name_label.get_parent()) {
251 item_table.attach (name_label, 0, 1, 0, 1, FILL, FILL, 4, 0);
254 name_label.show();
256 } else {
258 name_entry.set_text (location->name());
259 name_entry.set_size_request (100, -1);
260 name_entry.set_editable (true);
261 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
263 if (!name_entry.get_parent()) {
264 item_table.attach (name_entry, 0, 1, 0, 1, FILL | EXPAND, FILL, 4, 0);
266 name_entry.show();
268 if (!cd_check_button.get_parent()) {
269 item_table.attach (cd_check_button, 4, 5, 0, 1, FILL, FILL, 4, 0);
271 if (!remove_button.get_parent()) {
272 item_table.attach (remove_button, 8, 9, 0, 1, FILL, FILL, 4, 0);
275 if (location->is_session_range()) {
276 remove_button.set_sensitive (false);
279 cd_check_button.set_active (location->is_cd_marker());
280 cd_check_button.show();
282 if (location->start() == _session->current_start_frame()) {
283 cd_check_button.set_sensitive (false);
284 } else {
285 cd_check_button.set_sensitive (true);
288 hide_check_button.show();
289 lock_check_button.show();
290 glue_check_button.show();
293 start_clock.set (location->start(), true);
296 if (!location->is_mark()) {
297 if (!end_hbox.get_parent()) {
298 item_table.attach (end_hbox, 2, 3, 0, 1, FILL, FILL, 4, 0);
300 if (!length_clock.get_parent()) {
301 item_table.attach (length_clock, 3, 4, 0, 1, FILL, FILL, 4, 0);
304 end_clock.set (location->end(), true);
305 length_clock.set (location->length(), true);
307 end_go_button.show();
308 end_clock.show();
309 length_clock.show();
311 ARDOUR_UI::instance()->set_tip (end_go_button, _("Jump to the end of this range"));
312 ARDOUR_UI::instance()->set_tip (start_go_button, _("Jump to the start of this range"));
313 ARDOUR_UI::instance()->set_tip (remove_button, _("Forget this range"));
314 ARDOUR_UI::instance()->set_tip (start_clock, _("Start time"));
315 ARDOUR_UI::instance()->set_tip (end_clock, _("End time"));
316 ARDOUR_UI::instance()->set_tip (length_clock, _("Length"));
318 } else {
320 ARDOUR_UI::instance()->set_tip (start_go_button, _("Jump to this marker"));
321 ARDOUR_UI::instance()->set_tip (remove_button, _("Forget this marker"));
322 ARDOUR_UI::instance()->set_tip (start_clock, _("Position"));
324 end_go_button.hide();
325 end_clock.hide();
326 length_clock.hide();
329 set_clock_sensitivity ();
331 --i_am_the_modifier;
333 location->start_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::start_changed, this, _1), gui_context());
334 location->end_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::end_changed, this, _1), gui_context());
335 location->name_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::name_changed, this, _1), gui_context());
336 location->changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::location_changed, this, _1), gui_context());
337 location->FlagsChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::flags_changed, this, _1, _2), gui_context());
338 location->LockChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::lock_changed, this, _1), gui_context());
339 location->PositionLockStyleChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::position_lock_style_changed, this, _1), gui_context());
342 void
343 LocationEditRow::name_entry_changed ()
345 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed)
347 if (i_am_the_modifier || !location) {
348 return;
351 location->set_name (name_entry.get_text());
355 void
356 LocationEditRow::isrc_entry_changed ()
358 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed)
360 if (i_am_the_modifier || !location) return;
362 if (isrc_entry.get_text() != "" ) {
364 location->cd_info["isrc"] = isrc_entry.get_text();
366 } else {
367 location->cd_info.erase("isrc");
371 void
372 LocationEditRow::performer_entry_changed ()
374 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed)
376 if (i_am_the_modifier || !location) return;
378 if (performer_entry.get_text() != "") {
379 location->cd_info["performer"] = performer_entry.get_text();
380 } else {
381 location->cd_info.erase("performer");
385 void
386 LocationEditRow::composer_entry_changed ()
388 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed)
390 if (i_am_the_modifier || !location) return;
392 if (composer_entry.get_text() != "") {
393 location->cd_info["composer"] = composer_entry.get_text();
394 } else {
395 location->cd_info.erase("composer");
400 void
401 LocationEditRow::go_button_pressed (LocationPart part)
403 if (!location) {
404 return;
407 switch (part) {
408 case LocStart:
409 ARDOUR_UI::instance()->do_transport_locate (location->start(), _session->transport_rolling ());
410 break;
411 case LocEnd:
412 ARDOUR_UI::instance()->do_transport_locate (location->end(), _session->transport_rolling ());
413 break;
414 default:
415 break;
419 void
420 LocationEditRow::to_playhead_button_pressed (LocationPart part)
422 if (!location) {
423 return;
426 switch (part) {
427 case LocStart:
428 location->set_start (_session->transport_frame ());
429 break;
430 case LocEnd:
431 location->set_end (_session->transport_frame ());
432 break;
433 default:
434 break;
438 void
439 LocationEditRow::clock_changed (LocationPart part)
441 if (i_am_the_modifier || !location) {
442 return;
445 switch (part) {
446 case LocStart:
447 location->set_start (start_clock.current_time());
448 break;
449 case LocEnd:
450 location->set_end (end_clock.current_time());
451 break;
452 case LocLength:
453 location->set_end (location->start() + length_clock.current_duration());
454 default:
455 break;
459 void
460 LocationEditRow::change_aborted (LocationPart /*part*/)
462 if (i_am_the_modifier || !location) return;
464 set_location(location);
467 void
468 LocationEditRow::cd_toggled ()
470 if (i_am_the_modifier || !location) {
471 return;
474 //if (cd_check_button.get_active() == location->is_cd_marker()) {
475 // return;
478 if (cd_check_button.get_active()) {
479 if (location->start() <= _session->current_start_frame()) {
480 error << _("You cannot put a CD marker at the start of the session") << endmsg;
481 cd_check_button.set_active (false);
482 return;
486 location->set_cd (cd_check_button.get_active(), this);
488 if (location->is_cd_marker() && !(location->is_mark())) {
490 if (location->cd_info.find("isrc") != location->cd_info.end()) {
491 isrc_entry.set_text(location->cd_info["isrc"]);
493 if (location->cd_info.find("performer") != location->cd_info.end()) {
494 performer_entry.set_text(location->cd_info["performer"]);
496 if (location->cd_info.find("composer") != location->cd_info.end()) {
497 composer_entry.set_text(location->cd_info["composer"]);
499 if (location->cd_info.find("scms") != location->cd_info.end()) {
500 scms_check_button.set_active(true);
502 if (location->cd_info.find("preemph") != location->cd_info.end()) {
503 preemph_check_button.set_active(true);
506 if (!cd_track_details_hbox.get_parent()) {
507 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
509 // item_table.resize(2, 7);
510 cd_track_details_hbox.show_all();
512 } else if (cd_track_details_hbox.get_parent()){
514 item_table.remove (cd_track_details_hbox);
515 // item_table.resize(1, 7);
516 redraw_ranges(); /* EMIT_SIGNAL */
520 void
521 LocationEditRow::hide_toggled ()
523 if (i_am_the_modifier || !location) {
524 return;
527 location->set_hidden (hide_check_button.get_active(), this);
530 void
531 LocationEditRow::lock_toggled ()
533 if (i_am_the_modifier || !location) {
534 return;
537 if (location->locked()) {
538 location->unlock ();
539 } else {
540 location->lock ();
544 void
545 LocationEditRow::glue_toggled ()
547 if (i_am_the_modifier || !location) {
548 return;
551 if (location->position_lock_style() == AudioTime) {
552 location->set_position_lock_style (MusicTime);
553 } else {
554 location->set_position_lock_style (AudioTime);
558 void
559 LocationEditRow::remove_button_pressed ()
561 if (!location) {
562 return;
565 remove_requested (location); /* EMIT_SIGNAL */
570 void
571 LocationEditRow::scms_toggled ()
573 if (i_am_the_modifier || !location) return;
575 if (scms_check_button.get_active()) {
576 location->cd_info["scms"] = "on";
577 } else {
578 location->cd_info.erase("scms");
583 void
584 LocationEditRow::preemph_toggled ()
586 if (i_am_the_modifier || !location) return;
588 if (preemph_check_button.get_active()) {
589 location->cd_info["preemph"] = "on";
590 } else {
591 location->cd_info.erase("preemph");
595 void
596 LocationEditRow::end_changed (ARDOUR::Location *loc)
598 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
600 if (!location) return;
602 // update end and length
603 i_am_the_modifier++;
605 end_clock.set (location->end());
606 length_clock.set (location->length());
608 i_am_the_modifier--;
611 void
612 LocationEditRow::start_changed (ARDOUR::Location*)
614 if (!location) return;
616 // update end and length
617 i_am_the_modifier++;
619 start_clock.set (location->start());
621 if (location->start() == _session->current_start_frame()) {
622 cd_check_button.set_sensitive (false);
623 } else {
624 cd_check_button.set_sensitive (true);
627 i_am_the_modifier--;
630 void
631 LocationEditRow::name_changed (ARDOUR::Location *)
633 if (!location) return;
635 // update end and length
636 i_am_the_modifier++;
638 name_entry.set_text(location->name());
639 name_label.set_text(location->name());
641 i_am_the_modifier--;
645 void
646 LocationEditRow::location_changed (ARDOUR::Location*)
649 if (!location) return;
651 i_am_the_modifier++;
653 start_clock.set (location->start());
654 end_clock.set (location->end());
655 length_clock.set (location->length());
657 set_clock_sensitivity ();
659 i_am_the_modifier--;
663 void
664 LocationEditRow::flags_changed (ARDOUR::Location*, void *)
666 if (!location) {
667 return;
670 i_am_the_modifier++;
672 cd_check_button.set_active (location->is_cd_marker());
673 hide_check_button.set_active (location->is_hidden());
674 glue_check_button.set_active (location->position_lock_style() == MusicTime);
676 i_am_the_modifier--;
679 void
680 LocationEditRow::lock_changed (ARDOUR::Location*)
682 if (!location) {
683 return;
686 i_am_the_modifier++;
688 lock_check_button.set_active (location->locked());
690 set_clock_sensitivity ();
692 i_am_the_modifier--;
695 void
696 LocationEditRow::position_lock_style_changed (ARDOUR::Location*)
698 if (!location) {
699 return;
702 i_am_the_modifier++;
704 glue_check_button.set_active (location->position_lock_style() == MusicTime);
706 i_am_the_modifier--;
709 void
710 LocationEditRow::focus_name() {
711 name_entry.grab_focus();
714 void
715 LocationEditRow::set_clock_sensitivity ()
717 start_clock.set_sensitive (!location->locked());
718 end_clock.set_sensitive (!location->locked());
719 length_clock.set_sensitive (!location->locked());
722 /*------------------------------------------------------------------------*/
724 LocationUI::LocationUI ()
725 : add_location_button (_("New Marker"))
726 , add_range_button (_("New Range"))
728 i_am_the_modifier = 0;
730 _clock_group = new ClockGroup;
731 _clock_group->set_clock_mode (AudioClock::Frames);
733 VBox* vbox = manage (new VBox);
735 Table* table = manage (new Table (2, 2));
736 table->set_spacings (4);
737 table->set_col_spacing (0, 32);
738 int table_row = 0;
740 Label* l = manage (new Label (_("<b>Loop/Punch Ranges</b>")));
741 l->set_alignment (0, 0.5);
742 l->set_use_markup (true);
743 table->attach (*l, 0, 2, table_row, table_row + 1);
744 ++table_row;
746 loop_edit_row.set_clock_group (*_clock_group);
747 punch_edit_row.set_clock_group (*_clock_group);
749 loop_punch_box.pack_start (loop_edit_row, false, false);
750 loop_punch_box.pack_start (punch_edit_row, false, false);
752 table->attach (loop_punch_box, 1, 2, table_row, table_row + 1);
753 ++table_row;
755 vbox->pack_start (*table, false, false);
757 table = manage (new Table (3, 2));
758 table->set_spacings (4);
759 table->set_col_spacing (0, 32);
760 table_row = 0;
762 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
763 ++table_row;
765 l = manage (new Label (_("<b>Markers (Including CD Index)</b>")));
766 l->set_alignment (0, 0.5);
767 l->set_use_markup (true);
768 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
769 ++table_row;
771 location_rows.set_name("LocationLocRows");
772 location_rows_scroller.add (location_rows);
773 location_rows_scroller.set_name ("LocationLocRowsScroller");
774 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
775 location_rows_scroller.set_size_request (-1, 130);
777 newest_location = 0;
779 loc_frame_box.set_spacing (5);
780 loc_frame_box.set_border_width (5);
781 loc_frame_box.set_name("LocationFrameBox");
783 loc_frame_box.pack_start (location_rows_scroller, true, true);
785 add_location_button.set_name ("LocationAddLocationButton");
787 table->attach (loc_frame_box, 1, 2, table_row, table_row + 1);
788 ++table_row;
790 loc_range_panes.pack1 (*table, true, false);
792 table = manage (new Table (3, 2));
793 table->set_spacings (4);
794 table->set_col_spacing (0, 32);
795 table_row = 0;
797 table->attach (*manage (new Label ("")), 0, 2, table_row, table_row + 1, Gtk::SHRINK, Gtk::SHRINK);
798 ++table_row;
800 l = manage (new Label (_("<b>Ranges (Including CD Track Ranges)</b>")));
801 l->set_alignment (0, 0.5);
802 l->set_use_markup (true);
803 table->attach (*l, 0, 2, table_row, table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
804 ++table_row;
806 range_rows.set_name("LocationRangeRows");
807 range_rows_scroller.add (range_rows);
808 range_rows_scroller.set_name ("LocationRangeRowsScroller");
809 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
810 range_rows_scroller.set_size_request (-1, 130);
812 range_frame_box.set_spacing (5);
813 range_frame_box.set_name("LocationFrameBox");
814 range_frame_box.set_border_width (5);
815 range_frame_box.pack_start (range_rows_scroller, true, true);
817 add_range_button.set_name ("LocationAddRangeButton");
819 table->attach (range_frame_box, 1, 2, table_row, table_row + 1);
820 ++table_row;
822 loc_range_panes.pack2 (*table, true, false);
824 HBox* add_button_box = manage (new HBox);
825 add_button_box->pack_start (add_location_button, true, true);
826 add_button_box->pack_start (add_range_button, true, true);
828 vbox->pack_start (loc_range_panes, true, true);
829 vbox->pack_start (*add_button_box, false, false);
831 pack_start (*vbox);
833 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
834 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
836 show_all ();
839 LocationUI::~LocationUI()
841 delete _clock_group;
844 gint
845 LocationUI::do_location_remove (ARDOUR::Location *loc)
847 /* this is handled internally by Locations, but there's
848 no point saving state etc. when we know the marker
849 cannot be removed.
852 if (loc->is_session_range()) {
853 return FALSE;
856 _session->begin_reversible_command (_("remove marker"));
857 XMLNode &before = _session->locations()->get_state();
858 _session->locations()->remove (loc);
859 XMLNode &after = _session->locations()->get_state();
860 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
861 _session->commit_reversible_command ();
863 return FALSE;
866 void
867 LocationUI::location_remove_requested (ARDOUR::Location *loc)
869 // must do this to prevent problems when destroying
870 // the effective sender of this event
872 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
876 void
877 LocationUI::location_redraw_ranges ()
879 range_rows.hide();
880 range_rows.show();
883 struct LocationSortByStart {
884 bool operator() (Location *a, Location *b) {
885 return a->start() < b->start();
889 void
890 LocationUI::location_added (Location* location)
892 if (location->is_auto_punch()) {
893 punch_edit_row.set_location(location);
894 } else if (location->is_auto_loop()) {
895 loop_edit_row.set_location(location);
896 } else if (location->is_range_marker() || location->is_mark()) {
897 Locations::LocationList loc = _session->locations()->list ();
898 loc.sort (LocationSortByStart ());
900 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
902 erow->set_clock_group (*_clock_group);
903 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
905 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
907 /* Step through the location list and the GUI list to find the place to insert */
908 Locations::LocationList::iterator i = loc.begin ();
909 Box_Helpers::BoxList::iterator j = children.begin ();
910 while (i != loc.end()) {
912 if (location->flags() != (*i)->flags()) {
913 /* Skip locations in the session list that aren't of the right type */
914 ++i;
915 continue;
918 if (*i == location) {
919 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
920 break;
923 ++i;
925 if (j != children.end()) {
926 ++j;
930 range_rows.show_all ();
931 location_rows.show_all ();
935 void
936 LocationUI::location_removed (Location* location)
938 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
940 if (location->is_auto_punch()) {
941 punch_edit_row.set_location(0);
942 } else if (location->is_auto_loop()) {
943 loop_edit_row.set_location(0);
944 } else if (location->is_range_marker() || location->is_mark()) {
945 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
946 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
947 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
948 if (r && r->get_location() == location) {
949 children.erase (i);
950 break;
956 void
957 LocationUI::map_locations (Locations::LocationList& locations)
959 Locations::LocationList::iterator i;
960 gint n;
961 int mark_n = 0;
962 Locations::LocationList temp = locations;
963 LocationSortByStart cmp;
965 temp.sort (cmp);
966 locations = temp;
968 for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
970 Location* location = *i;
972 if (location->is_mark()) {
973 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
975 erow->set_clock_group (*_clock_group);
976 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
977 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
979 Box_Helpers::BoxList & loc_children = location_rows.children();
980 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
981 if (location == newest_location) {
982 newest_location = 0;
983 erow->focus_name();
985 } else if (location->is_auto_punch()) {
986 punch_edit_row.set_session (_session);
987 punch_edit_row.set_location (location);
988 punch_edit_row.show_all();
989 } else if (location->is_auto_loop()) {
990 loop_edit_row.set_session (_session);
991 loop_edit_row.set_location (location);
992 loop_edit_row.show_all();
993 } else {
994 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
996 erow->set_clock_group (*_clock_group);
997 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
999 Box_Helpers::BoxList & range_children = range_rows.children();
1000 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
1004 range_rows.show_all();
1005 location_rows.show_all();
1008 void
1009 LocationUI::add_new_location()
1011 string markername;
1013 if (_session) {
1014 framepos_t where = _session->audible_frame();
1015 _session->locations()->next_available_name(markername,"mark");
1016 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
1017 if (Config->get_name_new_markers()) {
1018 newest_location = location;
1020 _session->begin_reversible_command (_("add marker"));
1021 XMLNode &before = _session->locations()->get_state();
1022 _session->locations()->add (location, true);
1023 XMLNode &after = _session->locations()->get_state();
1024 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1025 _session->commit_reversible_command ();
1030 void
1031 LocationUI::add_new_range()
1033 string rangename;
1035 if (_session) {
1036 framepos_t where = _session->audible_frame();
1037 _session->locations()->next_available_name(rangename,"unnamed");
1038 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
1039 _session->begin_reversible_command (_("add range marker"));
1040 XMLNode &before = _session->locations()->get_state();
1041 _session->locations()->add (location, true);
1042 XMLNode &after = _session->locations()->get_state();
1043 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
1044 _session->commit_reversible_command ();
1048 void
1049 LocationUI::refresh_location_list ()
1051 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
1052 using namespace Box_Helpers;
1054 // this is just too expensive to do when window is not shown
1055 if (!is_mapped()) {
1056 return;
1059 BoxList & loc_children = location_rows.children();
1060 BoxList & range_children = range_rows.children();
1062 loc_children.clear();
1063 range_children.clear();
1065 if (_session) {
1066 _session->locations()->apply (*this, &LocationUI::map_locations);
1070 void
1071 LocationUI::set_session(ARDOUR::Session* s)
1073 SessionHandlePtr::set_session (s);
1075 if (_session) {
1076 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::locations_changed, this, _1), gui_context());
1077 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
1078 _session->locations()->added.connect (_session_connections, invalidator (*this), ui_bind (&LocationUI::location_added, this, _1), gui_context());
1079 _session->locations()->removed.connect (_session_connections, invalidator (*this), ui_bind (&LocationUI::location_removed, this, _1), gui_context());
1082 loop_edit_row.set_session (s);
1083 punch_edit_row.set_session (s);
1085 refresh_location_list ();
1088 void
1089 LocationUI::locations_changed (Locations::Change c)
1091 /* removal is signalled by both a removed and a changed signal emission from Locations,
1092 so we don't need to refresh the list on a removal
1094 if (c != Locations::REMOVAL) {
1095 refresh_location_list ();
1099 void
1100 LocationUI::session_going_away()
1102 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
1104 using namespace Box_Helpers;
1105 BoxList & loc_children = location_rows.children();
1106 BoxList & range_children = range_rows.children();
1108 loc_children.clear();
1109 range_children.clear();
1111 loop_edit_row.set_session (0);
1112 loop_edit_row.set_location (0);
1114 punch_edit_row.set_session (0);
1115 punch_edit_row.set_location (0);
1117 SessionHandlePtr::session_going_away ();
1121 /*------------------------*/
1123 LocationUIWindow::LocationUIWindow ()
1124 : ArdourDialog (_("Locations"))
1126 set_wmclass(X_("ardour_locations"), PROGRAM_NAME);
1127 set_name ("LocationWindow");
1129 get_vbox()->pack_start (_ui);
1132 LocationUIWindow::~LocationUIWindow()
1136 void
1137 LocationUIWindow::on_map ()
1139 ArdourDialog::on_map ();
1140 _ui.refresh_location_list();
1143 bool
1144 LocationUIWindow::on_delete_event (GdkEventAny*)
1146 hide ();
1147 return true;
1150 void
1151 LocationUIWindow::set_session (Session *s)
1153 ArdourDialog::set_session (s);
1154 _ui.set_session (s);
1157 void
1158 LocationUIWindow::session_going_away ()
1160 ArdourDialog::session_going_away ();
1161 hide_all();