white versions of the SVG dynamics icons
[ardour2.git] / gtk2_ardour / location_ui.cc
blobcf6862f2d6c55343ec5680be5b95e4916345abc9
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 "prompter.h"
32 #include "location_ui.h"
33 #include "keyboard.h"
34 #include "utils.h"
35 #include "gui_thread.h"
37 #include "i18n.h"
39 using namespace std;
40 using namespace ARDOUR;
41 using namespace PBD;
42 using namespace Gtk;
43 using namespace Gtkmm2ext;
45 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
46 : SessionHandlePtr (0), /* explicitly set below */
47 location(0),
48 item_table (1, 6, false),
49 start_clock (X_("locationstart"), true, X_("LocationEditRowClock"), true, false),
50 end_clock (X_("locationend"), true, X_("LocationEditRowClock"), true, false),
51 length_clock (X_("locationlength"), true, X_("LocationEditRowClock"), true, false, true),
52 cd_check_button (_("CD")),
53 hide_check_button (_("Hide")),
54 lock_check_button (_("Lock")),
55 glue_check_button (_("Glue")),
56 scms_check_button (_("SCMS")),
57 preemph_check_button (_("Pre-Emphasis"))
60 i_am_the_modifier = 0;
62 start_go_button.set_image (*manage (new Image (Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
63 end_go_button.set_image (*manage (new Image (Stock::JUMP_TO, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
64 remove_button.set_image (*manage (new Image (Stock::REMOVE, Gtk::ICON_SIZE_SMALL_TOOLBAR)));
66 number_label.set_name ("LocationEditNumberLabel");
67 name_label.set_name ("LocationEditNameLabel");
68 name_entry.set_name ("LocationEditNameEntry");
69 start_go_button.set_name ("LocationEditGoButton");
70 end_go_button.set_name ("LocationEditGoButton");
71 cd_check_button.set_name ("LocationEditCdButton");
72 hide_check_button.set_name ("LocationEditHideButton");
73 lock_check_button.set_name ("LocationEditLockButton");
74 glue_check_button.set_name ("LocationEditGlueButton");
75 remove_button.set_name ("LocationEditRemoveButton");
76 isrc_label.set_name ("LocationEditNumberLabel");
77 isrc_entry.set_name ("LocationEditNameEntry");
78 scms_check_button.set_name ("LocationEditCdButton");
79 preemph_check_button.set_name ("LocationEditCdButton");
80 performer_label.set_name ("LocationEditNumberLabel");
81 performer_entry.set_name ("LocationEditNameEntry");
82 composer_label.set_name ("LocationEditNumberLabel");
83 composer_entry.set_name ("LocationEditNameEntry");
85 isrc_label.set_text ("ISRC: ");
86 isrc_label.set_size_request (30, -1);
87 performer_label.set_text ("Performer: ");
88 performer_label.set_size_request (60, -1);
89 composer_label.set_text ("Composer: ");
90 composer_label.set_size_request (60, -1);
92 isrc_entry.set_size_request (112, -1);
93 isrc_entry.set_max_length(12);
94 isrc_entry.set_editable (true);
96 performer_entry.set_size_request (100, -1);
97 performer_entry.set_editable (true);
99 composer_entry.set_size_request (100, -1);
100 composer_entry.set_editable (true);
102 name_label.set_alignment (0, 0.5);
104 cd_track_details_hbox.pack_start (isrc_label, false, false);
105 cd_track_details_hbox.pack_start (isrc_entry, false, false);
106 cd_track_details_hbox.pack_start (scms_check_button, false, false);
107 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
108 cd_track_details_hbox.pack_start (performer_label, false, false);
109 cd_track_details_hbox.pack_start (performer_entry, true, true);
110 cd_track_details_hbox.pack_start (composer_label, false, false);
111 cd_track_details_hbox.pack_start (composer_entry, true, true);
113 isrc_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::isrc_entry_changed));
114 performer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::performer_entry_changed));
115 composer_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::composer_entry_changed));
116 scms_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::scms_toggled));
117 preemph_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::preemph_toggled));
119 set_session (sess);
121 // start_hbox.pack_start (start_go_button, false, false);
122 start_hbox.pack_start (start_clock, false, false);
124 /* this is always in this location, no matter what the location is */
126 item_table.attach (start_hbox, 1, 2, 0, 1, FILL, FILL, 4, 0);
128 start_go_button.signal_clicked().connect(sigc::bind (sigc::mem_fun (*this, &LocationEditRow::go_button_pressed), LocStart));
129 start_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
130 start_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocStart));
132 // end_hbox.pack_start (end_go_button, false, false);
133 end_hbox.pack_start (end_clock, false, false);
135 end_go_button.signal_clicked().connect(sigc::bind (sigc::mem_fun (*this, &LocationEditRow::go_button_pressed), LocEnd));
136 end_clock.ValueChanged.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
137 end_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocEnd));
139 length_clock.ValueChanged.connect (sigc::bind ( sigc::mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
140 length_clock.ChangeAborted.connect (sigc::bind (sigc::mem_fun (*this, &LocationEditRow::change_aborted), LocLength));
142 cd_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::cd_toggled));
143 hide_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::hide_toggled));
144 lock_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::lock_toggled));
145 glue_check_button.signal_toggled().connect(sigc::mem_fun(*this, &LocationEditRow::glue_toggled));
147 remove_button.signal_clicked().connect(sigc::mem_fun(*this, &LocationEditRow::remove_button_pressed));
149 pack_start(item_table, true, true);
151 set_location (loc);
152 set_number (num);
155 LocationEditRow::~LocationEditRow()
157 if (location) {
158 connections.drop_connections ();
162 void
163 LocationEditRow::set_session (Session *sess)
165 SessionHandlePtr::set_session (sess);
167 if (!_session) {
168 return;
171 start_clock.set_session (_session);
172 end_clock.set_session (_session);
173 length_clock.set_session (_session);
177 void
178 LocationEditRow::set_number (int num)
180 number = num;
182 if (number >= 0 ) {
183 number_label.set_text (string_compose ("%1", number));
187 void
188 LocationEditRow::set_location (Location *loc)
190 if (location) {
191 connections.drop_connections ();
194 location = loc;
196 if (!location) {
197 return;
200 ++i_am_the_modifier;
202 if (!hide_check_button.get_parent()) {
203 item_table.attach (hide_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
204 item_table.attach (lock_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
205 item_table.attach (glue_check_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
207 hide_check_button.set_active (location->is_hidden());
208 lock_check_button.set_active (location->locked());
209 glue_check_button.set_active (location->position_lock_style() == MusicTime);
211 if (location->is_auto_loop() || location-> is_auto_punch()) {
212 // use label instead of entry
214 name_label.set_text (location->name());
215 name_label.set_size_request (80, -1);
217 if (!name_label.get_parent()) {
218 item_table.attach (name_label, 0, 1, 0, 1, FILL, FILL, 4, 0);
221 name_label.show();
223 } else {
225 name_entry.set_text (location->name());
226 name_entry.set_size_request (100, -1);
227 name_entry.set_editable (true);
228 name_entry.signal_changed().connect (sigc::mem_fun(*this, &LocationEditRow::name_entry_changed));
230 if (!name_entry.get_parent()) {
231 item_table.attach (name_entry, 0, 1, 0, 1, FILL | EXPAND, FILL, 4, 0);
233 name_entry.show();
235 if (!cd_check_button.get_parent()) {
236 item_table.attach (cd_check_button, 4, 5, 0, 1, FILL, FILL, 4, 0);
238 if (!remove_button.get_parent()) {
239 item_table.attach (remove_button, 8, 9, 0, 1, FILL, FILL, 4, 0);
242 if (location->is_session_range()) {
243 remove_button.set_sensitive (false);
246 cd_check_button.set_active (location->is_cd_marker());
247 cd_check_button.show();
249 if (location->start() == _session->current_start_frame()) {
250 cd_check_button.set_sensitive (false);
251 } else {
252 cd_check_button.set_sensitive (true);
255 hide_check_button.show();
256 lock_check_button.show();
257 glue_check_button.show();
260 start_clock.set (location->start(), true);
263 if (!location->is_mark()) {
264 if (!end_hbox.get_parent()) {
265 item_table.attach (end_hbox, 2, 3, 0, 1, FILL, FILL, 4, 0);
267 if (!length_clock.get_parent()) {
268 item_table.attach (length_clock, 3, 4, 0, 1, FILL, FILL, 4, 0);
271 end_clock.set (location->end(), true);
272 length_clock.set (location->length(), true);
274 end_go_button.show();
275 end_clock.show();
276 length_clock.show();
278 ARDOUR_UI::instance()->set_tip (end_go_button, _("Jump to the end of this range"));
279 ARDOUR_UI::instance()->set_tip (start_go_button, _("Jump to the start of this range"));
280 ARDOUR_UI::instance()->set_tip (remove_button, _("Forget this range"));
281 ARDOUR_UI::instance()->set_tip (start_clock, _("Start time"));
282 ARDOUR_UI::instance()->set_tip (end_clock, _("End time"));
283 ARDOUR_UI::instance()->set_tip (length_clock, _("Length"));
285 } else {
287 ARDOUR_UI::instance()->set_tip (start_go_button, _("Jump to this marker"));
288 ARDOUR_UI::instance()->set_tip (remove_button, _("Forget this marker"));
289 ARDOUR_UI::instance()->set_tip (start_clock, _("Position"));
291 end_go_button.hide();
292 end_clock.hide();
293 length_clock.hide();
296 set_clock_sensitivity ();
298 --i_am_the_modifier;
300 location->start_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::start_changed, this, _1), gui_context());
301 location->end_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::end_changed, this, _1), gui_context());
302 location->name_changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::name_changed, this, _1), gui_context());
303 location->changed.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::location_changed, this, _1), gui_context());
304 location->FlagsChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::flags_changed, this, _1, _2), gui_context());
305 location->LockChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::lock_changed, this, _1), gui_context());
306 location->PositionLockStyleChanged.connect (connections, invalidator (*this), ui_bind (&LocationEditRow::position_lock_style_changed, this, _1), gui_context());
309 void
310 LocationEditRow::name_entry_changed ()
312 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_entry_changed)
313 if (i_am_the_modifier || !location) return;
315 location->set_name (name_entry.get_text());
319 void
320 LocationEditRow::isrc_entry_changed ()
322 ENSURE_GUI_THREAD (*this, &LocationEditRow::isrc_entry_changed)
324 if (i_am_the_modifier || !location) return;
326 if (isrc_entry.get_text() != "" ) {
328 location->cd_info["isrc"] = isrc_entry.get_text();
330 } else {
331 location->cd_info.erase("isrc");
335 void
336 LocationEditRow::performer_entry_changed ()
338 ENSURE_GUI_THREAD (*this, &LocationEditRow::performer_entry_changed)
340 if (i_am_the_modifier || !location) return;
342 if (performer_entry.get_text() != "") {
343 location->cd_info["performer"] = performer_entry.get_text();
344 } else {
345 location->cd_info.erase("performer");
349 void
350 LocationEditRow::composer_entry_changed ()
352 ENSURE_GUI_THREAD (*this, &LocationEditRow::composer_entry_changed)
354 if (i_am_the_modifier || !location) return;
356 if (composer_entry.get_text() != "") {
357 location->cd_info["composer"] = composer_entry.get_text();
358 } else {
359 location->cd_info.erase("composer");
364 void
365 LocationEditRow::go_button_pressed (LocationPart part)
367 if (!location) return;
369 switch (part) {
370 case LocStart:
371 ARDOUR_UI::instance()->do_transport_locate (location->start());
372 break;
373 case LocEnd:
374 ARDOUR_UI::instance()->do_transport_locate (location->end());
375 break;
376 default:
377 break;
381 void
382 LocationEditRow::clock_changed (LocationPart part)
384 if (i_am_the_modifier || !location) {
385 return;
388 switch (part) {
389 case LocStart:
390 location->set_start (start_clock.current_time());
391 break;
392 case LocEnd:
393 location->set_end (end_clock.current_time());
394 break;
395 case LocLength:
396 location->set_end (location->start() + length_clock.current_duration());
397 default:
398 break;
402 void
403 LocationEditRow::change_aborted (LocationPart /*part*/)
405 if (i_am_the_modifier || !location) return;
407 set_location(location);
410 void
411 LocationEditRow::cd_toggled ()
413 if (i_am_the_modifier || !location) {
414 return;
417 //if (cd_check_button.get_active() == location->is_cd_marker()) {
418 // return;
421 if (cd_check_button.get_active()) {
422 if (location->start() <= _session->current_start_frame()) {
423 error << _("You cannot put a CD marker at the start of the session") << endmsg;
424 cd_check_button.set_active (false);
425 return;
429 location->set_cd (cd_check_button.get_active(), this);
431 if (location->is_cd_marker() && !(location->is_mark())) {
433 if (location->cd_info.find("isrc") != location->cd_info.end()) {
434 isrc_entry.set_text(location->cd_info["isrc"]);
436 if (location->cd_info.find("performer") != location->cd_info.end()) {
437 performer_entry.set_text(location->cd_info["performer"]);
439 if (location->cd_info.find("composer") != location->cd_info.end()) {
440 composer_entry.set_text(location->cd_info["composer"]);
442 if (location->cd_info.find("scms") != location->cd_info.end()) {
443 scms_check_button.set_active(true);
445 if (location->cd_info.find("preemph") != location->cd_info.end()) {
446 preemph_check_button.set_active(true);
449 if (!cd_track_details_hbox.get_parent()) {
450 item_table.attach (cd_track_details_hbox, 0, 7, 1, 2, FILL | EXPAND, FILL, 4, 0);
452 // item_table.resize(2, 7);
453 cd_track_details_hbox.show_all();
455 } else if (cd_track_details_hbox.get_parent()){
457 item_table.remove (cd_track_details_hbox);
458 // item_table.resize(1, 7);
459 redraw_ranges(); /* EMIT_SIGNAL */
463 void
464 LocationEditRow::hide_toggled ()
466 if (i_am_the_modifier || !location) {
467 return;
470 location->set_hidden (hide_check_button.get_active(), this);
473 void
474 LocationEditRow::lock_toggled ()
476 if (i_am_the_modifier || !location) {
477 return;
480 if (location->locked()) {
481 location->unlock ();
482 } else {
483 location->lock ();
487 void
488 LocationEditRow::glue_toggled ()
490 if (i_am_the_modifier || !location) {
491 return;
494 if (location->position_lock_style() == AudioTime) {
495 location->set_position_lock_style (MusicTime);
496 } else {
497 location->set_position_lock_style (AudioTime);
501 void
502 LocationEditRow::remove_button_pressed ()
504 if (!location) {
505 return;
508 remove_requested (location); /* EMIT_SIGNAL */
513 void
514 LocationEditRow::scms_toggled ()
516 if (i_am_the_modifier || !location) return;
518 if (scms_check_button.get_active()) {
519 location->cd_info["scms"] = "on";
520 } else {
521 location->cd_info.erase("scms");
526 void
527 LocationEditRow::preemph_toggled ()
529 if (i_am_the_modifier || !location) return;
531 if (preemph_check_button.get_active()) {
532 location->cd_info["preemph"] = "on";
533 } else {
534 location->cd_info.erase("preemph");
538 void
539 LocationEditRow::end_changed (ARDOUR::Location *loc)
541 ENSURE_GUI_THREAD (*this, &LocationEditRow::end_changed, loc)
543 if (!location) return;
545 // update end and length
546 i_am_the_modifier++;
548 end_clock.set (location->end());
549 length_clock.set (location->length());
551 i_am_the_modifier--;
554 void
555 LocationEditRow::start_changed (ARDOUR::Location *loc)
557 ENSURE_GUI_THREAD (*this, &LocationEditRow::start_changed, loc)
559 if (!location) return;
561 // update end and length
562 i_am_the_modifier++;
564 start_clock.set (location->start());
566 if (location->start() == _session->current_start_frame()) {
567 cd_check_button.set_sensitive (false);
568 } else {
569 cd_check_button.set_sensitive (true);
572 i_am_the_modifier--;
575 void
576 LocationEditRow::name_changed (ARDOUR::Location *loc)
578 ENSURE_GUI_THREAD (*this, &LocationEditRow::name_changed, loc)
580 if (!location) return;
582 // update end and length
583 i_am_the_modifier++;
585 name_entry.set_text(location->name());
586 name_label.set_text(location->name());
588 i_am_the_modifier--;
592 void
593 LocationEditRow::location_changed (ARDOUR::Location *loc)
595 ENSURE_GUI_THREAD (*this, &LocationEditRow::location_changed, loc)
597 if (!location) return;
599 i_am_the_modifier++;
601 start_clock.set (location->start());
602 end_clock.set (location->end());
603 length_clock.set (location->length());
605 set_clock_sensitivity ();
607 i_am_the_modifier--;
611 void
612 LocationEditRow::flags_changed (ARDOUR::Location *loc, void *src)
614 if (!location) {
615 return;
618 i_am_the_modifier++;
620 cd_check_button.set_active (location->is_cd_marker());
621 hide_check_button.set_active (location->is_hidden());
622 glue_check_button.set_active (location->position_lock_style() == MusicTime);
624 i_am_the_modifier--;
627 void
628 LocationEditRow::lock_changed (ARDOUR::Location *loc)
630 if (!location) {
631 return;
634 i_am_the_modifier++;
636 lock_check_button.set_active (location->locked());
638 set_clock_sensitivity ();
640 i_am_the_modifier--;
643 void
644 LocationEditRow::position_lock_style_changed (ARDOUR::Location* loc)
646 if (!location) {
647 return;
650 i_am_the_modifier++;
652 glue_check_button.set_active (location->position_lock_style() == MusicTime);
654 i_am_the_modifier--;
657 void
658 LocationEditRow::focus_name() {
659 name_entry.grab_focus();
663 LocationUI::LocationUI ()
664 : add_location_button (_("New Marker"))
665 , add_range_button (_("New Range"))
667 i_am_the_modifier = 0;
669 location_vpacker.set_spacing (5);
671 add_location_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
672 add_range_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
674 loop_punch_box.pack_start (loop_edit_row, false, false);
675 loop_punch_box.pack_start (punch_edit_row, false, false);
677 loop_punch_scroller.add (loop_punch_box);
678 loop_punch_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
679 loop_punch_scroller.set_shadow_type (Gtk::SHADOW_NONE);
681 location_vpacker.pack_start (loop_punch_scroller, false, false);
683 location_rows.set_name("LocationLocRows");
684 location_rows_scroller.add (location_rows);
685 location_rows_scroller.set_name ("LocationLocRowsScroller");
686 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
687 location_rows_scroller.set_size_request (-1, 130);
689 newest_location = 0;
691 loc_frame_box.set_spacing (5);
692 loc_frame_box.set_border_width (5);
693 loc_frame_box.set_name("LocationFrameBox");
695 loc_frame_box.pack_start (location_rows_scroller, true, true);
697 add_location_button.set_name ("LocationAddLocationButton");
699 HBox* add_button_box = manage (new HBox);
701 // loc_frame_box.pack_start (add_location_button, false, false);
702 add_button_box->pack_start (add_location_button, true, true);
704 loc_frame.set_name ("LocationLocEditorFrame");
705 loc_frame.set_label (_("Markers (including CD index)"));
706 loc_frame.add (loc_frame_box);
707 loc_range_panes.pack1(loc_frame, true, false);
710 range_rows.set_name("LocationRangeRows");
711 range_rows_scroller.add (range_rows);
712 range_rows_scroller.set_name ("LocationRangeRowsScroller");
713 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
714 range_rows_scroller.set_size_request (-1, 130);
716 range_frame_box.set_spacing (5);
717 range_frame_box.set_name("LocationFrameBox");
718 range_frame_box.set_border_width (5);
719 range_frame_box.pack_start (range_rows_scroller, true, true);
721 add_range_button.set_name ("LocationAddRangeButton");
722 //range_frame_box.pack_start (add_range_button, false, false);
724 add_button_box->pack_start (add_range_button, true, true);
726 range_frame.set_name ("LocationRangeEditorFrame");
727 range_frame.set_label (_("Ranges (including CD track ranges)"));
728 range_frame.add (range_frame_box);
729 loc_range_panes.pack2(range_frame, true, false);
730 location_vpacker.pack_start (loc_range_panes, true, true);
731 location_vpacker.pack_start (*add_button_box, false, false);
733 pack_start (location_vpacker, true, true);
735 add_location_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_location));
736 add_range_button.signal_clicked().connect (sigc::mem_fun(*this, &LocationUI::add_new_range));
738 show_all ();
741 LocationUI::~LocationUI()
745 gint
746 LocationUI::do_location_remove (ARDOUR::Location *loc)
748 /* this is handled internally by Locations, but there's
749 no point saving state etc. when we know the marker
750 cannot be removed.
753 if (loc->is_session_range()) {
754 return FALSE;
757 _session->begin_reversible_command (_("remove marker"));
758 XMLNode &before = _session->locations()->get_state();
759 _session->locations()->remove (loc);
760 XMLNode &after = _session->locations()->get_state();
761 _session->add_command(new MementoCommand<Locations>(*(_session->locations()), &before, &after));
762 _session->commit_reversible_command ();
764 return FALSE;
767 void
768 LocationUI::location_remove_requested (ARDOUR::Location *loc)
770 // must do this to prevent problems when destroying
771 // the effective sender of this event
773 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun(*this, &LocationUI::do_location_remove), loc));
777 void
778 LocationUI::location_redraw_ranges ()
780 range_rows.hide();
781 range_rows.show();
784 struct LocationSortByStart {
785 bool operator() (Location *a, Location *b) {
786 return a->start() < b->start();
790 void
791 LocationUI::location_added (Location* location)
793 ENSURE_GUI_THREAD (*this, &LocationUI::location_added, location)
795 if (location->is_auto_punch()) {
796 punch_edit_row.set_location(location);
797 } else if (location->is_auto_loop()) {
798 loop_edit_row.set_location(location);
799 } else if (location->is_range_marker() || location->is_mark()) {
800 Locations::LocationList loc = _session->locations()->list ();
801 loc.sort (LocationSortByStart ());
803 LocationEditRow* erow = manage (new LocationEditRow (_session, location));
804 erow->remove_requested.connect (sigc::mem_fun (*this, &LocationUI::location_remove_requested));
805 Box_Helpers::BoxList & children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
807 /* Step through the location list and the GUI list to find the place to insert */
808 Locations::LocationList::iterator i = loc.begin ();
809 Box_Helpers::BoxList::iterator j = children.begin ();
810 while (i != loc.end()) {
812 if (location->flags() != (*i)->flags()) {
813 /* Skip locations in the session list that aren't of the right type */
814 ++i;
815 continue;
818 if (*i == location) {
819 children.insert (j, Box_Helpers::Element (*erow, PACK_SHRINK, 1, PACK_START));
820 break;
823 ++i;
825 if (j != children.end()) {
826 ++j;
830 range_rows.show_all ();
831 location_rows.show_all ();
835 void
836 LocationUI::location_removed (Location* location)
838 ENSURE_GUI_THREAD (*this, &LocationUI::location_removed, location)
840 if (location->is_auto_punch()) {
841 punch_edit_row.set_location(0);
842 } else if (location->is_auto_loop()) {
843 loop_edit_row.set_location(0);
844 } else if (location->is_range_marker() || location->is_mark()) {
845 Box_Helpers::BoxList& children = location->is_range_marker() ? range_rows.children () : location_rows.children ();
846 for (Box_Helpers::BoxList::iterator i = children.begin(); i != children.end(); ++i) {
847 LocationEditRow* r = dynamic_cast<LocationEditRow*> (i->get_widget());
848 if (r && r->get_location() == location) {
849 children.erase (i);
850 break;
856 void
857 LocationUI::map_locations (Locations::LocationList& locations)
859 Locations::LocationList::iterator i;
860 gint n;
861 int mark_n = 0;
862 Locations::LocationList temp = locations;
863 LocationSortByStart cmp;
865 temp.sort (cmp);
866 locations = temp;
868 for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
870 Location* location = *i;
872 if (location->is_mark()) {
873 LocationEditRow* erow = manage (new LocationEditRow (_session, location, mark_n));
874 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
875 erow->redraw_ranges.connect (sigc::mem_fun(*this, &LocationUI::location_redraw_ranges));
876 Box_Helpers::BoxList & loc_children = location_rows.children();
877 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
878 if (location == newest_location) {
879 newest_location = 0;
880 erow->focus_name();
882 } else if (location->is_auto_punch()) {
883 punch_edit_row.set_session (_session);
884 punch_edit_row.set_location (location);
885 punch_edit_row.show_all();
886 } else if (location->is_auto_loop()) {
887 loop_edit_row.set_session (_session);
888 loop_edit_row.set_location (location);
889 loop_edit_row.show_all();
890 } else {
891 LocationEditRow* erow = manage (new LocationEditRow(_session, location));
892 erow->remove_requested.connect (sigc::mem_fun(*this, &LocationUI::location_remove_requested));
893 Box_Helpers::BoxList & range_children = range_rows.children();
894 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
898 range_rows.show_all();
899 location_rows.show_all();
902 void
903 LocationUI::add_new_location()
905 string markername;
907 if (_session) {
908 nframes_t where = _session->audible_frame();
909 _session->locations()->next_available_name(markername,"mark");
910 Location *location = new Location (*_session, where, where, markername, Location::IsMark);
911 if (Config->get_name_new_markers()) {
912 newest_location = location;
914 _session->begin_reversible_command (_("add marker"));
915 XMLNode &before = _session->locations()->get_state();
916 _session->locations()->add (location, true);
917 XMLNode &after = _session->locations()->get_state();
918 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
919 _session->commit_reversible_command ();
924 void
925 LocationUI::add_new_range()
927 string rangename;
929 if (_session) {
930 nframes_t where = _session->audible_frame();
931 _session->locations()->next_available_name(rangename,"unnamed");
932 Location *location = new Location (*_session, where, where, rangename, Location::IsRangeMarker);
933 _session->begin_reversible_command (_("add range marker"));
934 XMLNode &before = _session->locations()->get_state();
935 _session->locations()->add (location, true);
936 XMLNode &after = _session->locations()->get_state();
937 _session->add_command (new MementoCommand<Locations>(*(_session->locations()), &before, &after));
938 _session->commit_reversible_command ();
942 void
943 LocationUI::refresh_location_list ()
945 ENSURE_GUI_THREAD (*this, &LocationUI::refresh_location_list)
946 using namespace Box_Helpers;
948 // this is just too expensive to do when window is not shown
949 if (!is_visible()) return;
951 BoxList & loc_children = location_rows.children();
952 BoxList & range_children = range_rows.children();
954 loc_children.clear();
955 range_children.clear();
957 if (_session) {
958 _session->locations()->apply (*this, &LocationUI::map_locations);
963 void
964 LocationUI::set_session(ARDOUR::Session* s)
966 SessionHandlePtr::set_session (s);
968 if (_session) {
969 _session->locations()->changed.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::locations_changed, this, _1), gui_context());
970 _session->locations()->StateChanged.connect (_session_connections, invalidator (*this), boost::bind (&LocationUI::refresh_location_list, this), gui_context());
971 _session->locations()->added.connect (_session_connections, invalidator (*this), ui_bind (&LocationUI::location_added, this, _1), gui_context());
972 _session->locations()->removed.connect (_session_connections, invalidator (*this), ui_bind (&LocationUI::location_removed, this, _1), gui_context());
975 loop_edit_row.set_session (s);
976 punch_edit_row.set_session (s);
978 refresh_location_list ();
981 void
982 LocationUI::locations_changed (Locations::Change c)
984 /* removal is signalled by both a removed and a changed signal emission from Locations,
985 so we don't need to refresh the list on a removal
987 if (c != Locations::REMOVAL) {
988 refresh_location_list ();
992 void
993 LocationUI::session_going_away()
995 ENSURE_GUI_THREAD (*this, &LocationUI::session_going_away);
997 using namespace Box_Helpers;
998 BoxList & loc_children = location_rows.children();
999 BoxList & range_children = range_rows.children();
1001 loc_children.clear();
1002 range_children.clear();
1004 loop_edit_row.set_session (0);
1005 loop_edit_row.set_location (0);
1007 punch_edit_row.set_session (0);
1008 punch_edit_row.set_location (0);
1010 SessionHandlePtr::session_going_away ();
1013 void
1014 LocationEditRow::set_clock_sensitivity ()
1016 start_clock.set_sensitive (!location->locked());
1017 end_clock.set_sensitive (!location->locked());
1018 length_clock.set_sensitive (!location->locked());
1021 /*------------------------*/
1023 LocationUIWindow::LocationUIWindow ()
1024 : ArdourDialog (_("Locations"))
1026 set_wmclass(X_("ardour_locations"), "Ardour");
1027 set_name ("LocationWindow");
1029 get_vbox()->pack_start (_ui);
1032 LocationUIWindow::~LocationUIWindow()
1036 void
1037 LocationUIWindow::on_show()
1039 _ui.refresh_location_list();
1040 ArdourDialog::on_show();
1043 bool
1044 LocationUIWindow::on_delete_event (GdkEventAny*)
1046 hide ();
1047 return true;
1050 void
1051 LocationUIWindow::set_session (Session *s)
1053 ArdourDialog::set_session (s);
1054 _ui.set_session (s);
1057 void
1058 LocationUIWindow::session_going_away ()
1060 ArdourDialog::session_going_away ();
1061 hide_all();