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.
24 #include <gtkmm2ext/utils.h>
25 #include <gtkmm2ext/stop_signal.h>
27 #include <ardour/utils.h>
28 #include <ardour/configuration.h>
29 #include <ardour/session.h>
31 #include "ardour_ui.h"
33 #include "location_ui.h"
36 #include "gui_thread.h"
40 using namespace ARDOUR;
42 using namespace Gtkmm2ext;
44 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
45 : location(0), session(0),
46 item_table (1, 7, false),
47 start_set_button (_("Set")),
48 start_go_button (_("Go")),
49 start_clock (X_("LocationEditRowClock"), true),
50 end_set_button (_("Set")),
51 end_go_button (_("Go")),
52 end_clock (X_("LocationEditRowClock"), true),
53 length_clock (X_("LocationEditRowClock"), true, true),
54 cd_check_button (_("CD")),
55 hide_check_button (_("Hidden")),
56 remove_button (_("Remove")),
57 scms_check_button (_("SCMS")),
58 preemph_check_button (_("Pre-Emphasis"))
62 i_am_the_modifier = 0;
64 number_label.set_name ("LocationEditNumberLabel");
65 name_label.set_name ("LocationEditNameLabel");
66 name_entry.set_name ("LocationEditNameEntry");
67 start_set_button.set_name ("LocationEditSetButton");
68 start_go_button.set_name ("LocationEditGoButton");
69 end_set_button.set_name ("LocationEditSetButton");
70 end_go_button.set_name ("LocationEditGoButton");
71 cd_check_button.set_name ("LocationEditCdButton");
72 hide_check_button.set_name ("LocationEditHideButton");
73 remove_button.set_name ("LocationEditRemoveButton");
74 isrc_label.set_name ("LocationEditNumberLabel");
75 isrc_entry.set_name ("LocationEditNameEntry");
76 scms_check_button.set_name ("LocationEditCdButton");
77 preemph_check_button.set_name ("LocationEditCdButton");
78 performer_label.set_name ("LocationEditNumberLabel");
79 performer_entry.set_name ("LocationEditNameEntry");
80 composer_label.set_name ("LocationEditNumberLabel");
81 composer_entry.set_name ("LocationEditNameEntry");
84 isrc_label.set_text ("ISRC: ");
85 isrc_label.set_size_request (30, -1);
86 performer_label.set_text ("Performer: ");
87 performer_label.set_size_request (60, -1);
88 composer_label.set_text ("Composer: ");
89 composer_label.set_size_request (60, -1);
91 isrc_entry.set_size_request (112, -1);
92 isrc_entry.set_max_length(12);
93 isrc_entry.set_editable (true);
95 performer_entry.set_size_request (100, -1);
96 performer_entry.set_editable (true);
98 composer_entry.set_size_request (100, -1);
99 composer_entry.set_editable (true);
101 cd_track_details_hbox.pack_start (isrc_label, false, false);
102 cd_track_details_hbox.pack_start (isrc_entry, false, false);
103 cd_track_details_hbox.pack_start (scms_check_button, false, false);
104 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
105 cd_track_details_hbox.pack_start (performer_label, false, false);
106 cd_track_details_hbox.pack_start (performer_entry, true, true);
107 cd_track_details_hbox.pack_start (composer_label, false, false);
108 cd_track_details_hbox.pack_start (composer_entry, true, true);
110 isrc_entry.signal_changed().connect (mem_fun(*this, &LocationEditRow::isrc_entry_changed));
111 performer_entry.signal_changed().connect (mem_fun(*this, &LocationEditRow::performer_entry_changed));
112 composer_entry.signal_changed().connect (mem_fun(*this, &LocationEditRow::composer_entry_changed));
113 scms_check_button.signal_toggled().connect(mem_fun(*this, &LocationEditRow::scms_toggled));
114 preemph_check_button.signal_toggled().connect(mem_fun(*this, &LocationEditRow::preemph_toggled));
120 item_table.attach (number_label, 0, 1, 0, 1, FILL, FILL, 3, 0);
122 start_hbox.pack_start (start_go_button, false, false);
123 start_hbox.pack_start (start_clock, false, false);
124 start_hbox.pack_start (start_set_button, false, false);
126 item_table.attach (start_hbox, 2, 3, 0, 1, FILL, FILL, 4, 0);
129 start_set_button.signal_clicked().connect(bind (mem_fun (*this, &LocationEditRow::set_button_pressed), LocStart));
130 start_go_button.signal_clicked().connect(bind (mem_fun (*this, &LocationEditRow::go_button_pressed), LocStart));
131 start_clock.ValueChanged.connect (bind (mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
134 end_hbox.pack_start (end_go_button, false, false);
135 end_hbox.pack_start (end_clock, false, false);
136 end_hbox.pack_start (end_set_button, false, false);
138 //item_table.attach (end_hbox, 2, 3, 0, 1, 0, 0, 4, 0);
140 end_set_button.signal_clicked().connect(bind (mem_fun (*this, &LocationEditRow::set_button_pressed), LocEnd));
141 end_go_button.signal_clicked().connect(bind (mem_fun (*this, &LocationEditRow::go_button_pressed), LocEnd));
142 end_clock.ValueChanged.connect (bind (mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
144 // item_table.attach (length_clock, 3, 4, 0, 1, 0, 0, 4, 0);
145 length_clock.ValueChanged.connect (bind ( mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
147 // item_table.attach (cd_check_button, 4, 5, 0, 1, 0, Gtk::FILL, 4, 0);
148 // item_table.attach (hide_check_button, 5, 6, 0, 1, 0, Gtk::FILL, 4, 0);
149 // item_table.attach (remove_button, 7, 8, 0, 1, 0, Gtk::FILL, 4, 0);
151 cd_check_button.signal_toggled().connect(mem_fun(*this, &LocationEditRow::cd_toggled));
152 hide_check_button.signal_toggled().connect(mem_fun(*this, &LocationEditRow::hide_toggled));
154 remove_button.signal_clicked().connect(mem_fun(*this, &LocationEditRow::remove_button_pressed));
156 pack_start(item_table, true, true);
162 LocationEditRow::~LocationEditRow()
165 start_changed_connection.disconnect();
166 end_changed_connection.disconnect();
167 name_changed_connection.disconnect();
168 changed_connection.disconnect();
169 flags_changed_connection.disconnect();
174 LocationEditRow::set_session (Session *sess)
178 if (!session) return;
180 start_clock.set_session (session);
181 end_clock.set_session (session);
182 length_clock.set_session (session);
187 LocationEditRow::set_number (int num)
192 number_label.set_text (string_compose ("%1", number));
197 LocationEditRow::set_location (Location *loc)
200 start_changed_connection.disconnect();
201 end_changed_connection.disconnect();
202 name_changed_connection.disconnect();
203 changed_connection.disconnect();
204 flags_changed_connection.disconnect();
209 if (!location) return;
211 if (!hide_check_button.get_parent()) {
212 item_table.attach (hide_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
214 hide_check_button.set_active (location->is_hidden());
216 if (location->is_auto_loop() || location->is_auto_punch()) {
217 // use label instead of entry
219 name_label.set_text (location->name());
220 name_label.set_size_request (80, -1);
222 if (!name_label.get_parent()) {
223 item_table.attach (name_label, 1, 2, 0, 1, FILL, Gtk::FILL, 4, 0);
230 name_entry.set_text (location->name());
231 name_entry.set_size_request (100, -1);
232 name_entry.set_editable (true);
233 name_entry.signal_changed().connect (mem_fun(*this, &LocationEditRow::name_entry_changed));
235 if (!name_entry.get_parent()) {
236 item_table.attach (name_entry, 1, 2, 0, 1, FILL | EXPAND, FILL, 4, 0);
240 if (!cd_check_button.get_parent()) {
241 item_table.attach (cd_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
243 if (!remove_button.get_parent()) {
244 item_table.attach (remove_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
247 /* XXX i can't find a way to hide the button without messing up
248 the row spacing, so make it insensitive (paul).
251 if (location->is_end()) {
252 remove_button.set_sensitive (false);
255 cd_check_button.set_active (location->is_cd_marker());
256 cd_check_button.show();
257 hide_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, 3, 4, 0, 1, FILL, FILL, 4, 0);
267 if (!length_clock.get_parent()) {
268 item_table.attach (length_clock, 4, 5, 0, 1, FILL, FILL, 4, 0);
271 end_clock.set (location->end(), true);
272 length_clock.set (location->length(), true);
274 end_set_button.show();
275 end_go_button.show();
280 end_set_button.hide();
281 end_go_button.hide();
286 start_changed_connection = location->start_changed.connect (mem_fun(*this, &LocationEditRow::start_changed));
287 end_changed_connection = location->end_changed.connect (mem_fun(*this, &LocationEditRow::end_changed));
288 name_changed_connection = location->name_changed.connect (mem_fun(*this, &LocationEditRow::name_changed));
289 changed_connection = location->changed.connect (mem_fun(*this, &LocationEditRow::location_changed));
290 flags_changed_connection = location->FlagsChanged.connect (mem_fun(*this, &LocationEditRow::flags_changed));
295 LocationEditRow::name_entry_changed ()
297 ENSURE_GUI_THREAD(mem_fun(*this, &LocationEditRow::name_entry_changed));
298 if (i_am_the_modifier || !location) return;
300 location->set_name (name_entry.get_text());
305 LocationEditRow::isrc_entry_changed ()
307 ENSURE_GUI_THREAD(mem_fun(*this, &LocationEditRow::isrc_entry_changed));
309 if (i_am_the_modifier || !location) return;
311 if (isrc_entry.get_text() != "" ) {
313 location->cd_info["isrc"] = isrc_entry.get_text();
316 location->cd_info.erase("isrc");
321 LocationEditRow::performer_entry_changed ()
323 ENSURE_GUI_THREAD(mem_fun(*this, &LocationEditRow::performer_entry_changed));
325 if (i_am_the_modifier || !location) return;
327 if (performer_entry.get_text() != "") {
328 location->cd_info["performer"] = performer_entry.get_text();
330 location->cd_info.erase("performer");
335 LocationEditRow::composer_entry_changed ()
337 ENSURE_GUI_THREAD(mem_fun(*this, &LocationEditRow::composer_entry_changed));
339 if (i_am_the_modifier || !location) return;
341 if (composer_entry.get_text() != "") {
342 location->cd_info["composer"] = composer_entry.get_text();
344 location->cd_info.erase("composer");
350 LocationEditRow::set_button_pressed (LocationPart part)
352 if (!location) return;
356 location->set_start (session->transport_frame ());
359 location->set_end (session->transport_frame ());
367 LocationEditRow::go_button_pressed (LocationPart part)
369 if (!location) return;
373 ARDOUR_UI::instance()->do_transport_locate (location->start());
376 ARDOUR_UI::instance()->do_transport_locate (location->end());
384 LocationEditRow::clock_changed (LocationPart part)
386 if (i_am_the_modifier || !location) return;
390 location->set_start (start_clock.current_time());
393 location->set_end (end_clock.current_time());
396 location->set_end (location->start() + length_clock.current_duration());
404 LocationEditRow::cd_toggled ()
407 if (i_am_the_modifier || !location) return;
408 location->set_cd (cd_check_button.get_active(), this);
410 if (location->is_cd_marker() && !(location->is_mark())) {
412 if (location->cd_info.find("isrc") != location->cd_info.end()) {
413 isrc_entry.set_text(location->cd_info["isrc"]);
415 if (location->cd_info.find("performer") != location->cd_info.end()) {
416 performer_entry.set_text(location->cd_info["performer"]);
418 if (location->cd_info.find("composer") != location->cd_info.end()) {
419 composer_entry.set_text(location->cd_info["composer"]);
421 if (location->cd_info.find("scms") != location->cd_info.end()) {
422 scms_check_button.set_active(true);
424 if (location->cd_info.find("preemph") != location->cd_info.end()) {
425 preemph_check_button.set_active(true);
428 if(!cd_track_details_hbox.get_parent()) {
429 item_table.attach (cd_track_details_hbox, 1, 8, 1, 2, FILL | EXPAND, FILL, 4, 0);
431 // item_table.resize(2, 7);
432 cd_track_details_hbox.show_all();
434 } else if (cd_track_details_hbox.get_parent()){
436 item_table.remove (cd_track_details_hbox);
437 // item_table.resize(1, 7);
438 redraw_ranges(); /* EMIT_SIGNAL */
445 LocationEditRow::hide_toggled ()
447 if (i_am_the_modifier || !location) return;
449 location->set_hidden (hide_check_button.get_active(), this);
453 LocationEditRow::remove_button_pressed ()
455 if (!location) return;
457 remove_requested(location); /* EMIT_SIGNAL */
463 LocationEditRow::scms_toggled ()
465 if (i_am_the_modifier || !location) return;
467 if (scms_check_button.get_active()) {
468 location->cd_info["scms"] = "on";
470 location->cd_info.erase("scms");
476 LocationEditRow::preemph_toggled ()
478 if (i_am_the_modifier || !location) return;
480 if (preemph_check_button.get_active()) {
481 location->cd_info["preemph"] = "on";
483 location->cd_info.erase("preemph");
488 LocationEditRow::end_changed (ARDOUR::Location *loc)
490 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::end_changed), loc));
492 if (!location) return;
494 // update end and length
497 end_clock.set (location->end());
498 length_clock.set (location->length());
504 LocationEditRow::start_changed (ARDOUR::Location *loc)
506 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::start_changed), loc));
508 if (!location) return;
510 // update end and length
513 start_clock.set (location->start());
519 LocationEditRow::name_changed (ARDOUR::Location *loc)
521 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::name_changed), loc));
523 if (!location) return;
525 // update end and length
528 name_entry.set_text(location->name());
529 name_label.set_text(location->name());
536 LocationEditRow::location_changed (ARDOUR::Location *loc)
538 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::location_changed), loc));
540 if (!location) return;
544 start_clock.set (location->start());
545 end_clock.set (location->end());
546 length_clock.set (location->length());
553 LocationEditRow::flags_changed (ARDOUR::Location *loc, void *src)
555 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::flags_changed), loc, src));
557 if (!location) return;
561 cd_check_button.set_active (location->is_cd_marker());
562 hide_check_button.set_active (location->is_hidden());
567 LocationUI::LocationUI ()
568 : ArdourDialog ("location dialog"),
569 add_location_button (_("Add New Location")),
570 add_range_button (_("Add New Range"))
572 i_am_the_modifier = 0;
574 set_title(_("ardour: locations"));
575 set_wmclass(_("ardour_locations"), "Ardour");
577 set_name ("LocationWindow");
578 signal_delete_event().connect (bind (ptr_fun (just_hide_it), static_cast<Window*>(this)));
580 add (location_hpacker);
583 location_vpacker.set_border_width (10);
584 location_vpacker.set_spacing (5);
587 location_vpacker.pack_start (loop_edit_row, false, false);
588 location_vpacker.pack_start (punch_edit_row, false, false);
590 location_rows.set_name("LocationLocRows");
591 location_rows_scroller.add (location_rows);
592 location_rows_scroller.set_name ("LocationLocRowsScroller");
593 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
594 location_rows_scroller.set_size_request (-1, 130);
596 loc_frame_box.set_spacing (5);
597 loc_frame_box.set_border_width (5);
598 loc_frame_box.set_name("LocationFrameBox");
600 loc_frame_box.pack_start (location_rows_scroller, true, true);
602 add_location_button.set_name ("LocationAddLocationButton");
603 loc_frame_box.pack_start (add_location_button, false, false);
605 loc_frame.set_name ("LocationLocEditorFrame");
606 loc_frame.set_label (_("Location (CD Index) Markers"));
607 loc_frame.add (loc_frame_box);
608 loc_range_panes.pack1(loc_frame, true, false);
611 range_rows.set_name("LocationRangeRows");
612 range_rows_scroller.add (range_rows);
613 range_rows_scroller.set_name ("LocationRangeRowsScroller");
614 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
615 range_rows_scroller.set_size_request (-1, 130);
617 range_frame_box.set_spacing (5);
618 range_frame_box.set_name("LocationFrameBox");
619 range_frame_box.set_border_width (5);
620 range_frame_box.pack_start (range_rows_scroller, true, true);
622 add_range_button.set_name ("LocationAddRangeButton");
623 range_frame_box.pack_start (add_range_button, false, false);
625 range_frame.set_name ("LocationRangeEditorFrame");
626 range_frame.set_label (_("Range (CD Track) Markers"));
627 range_frame.add (range_frame_box);
628 loc_range_panes.pack2(range_frame, true, false);
629 location_vpacker.pack_start (loc_range_panes, true, true);
631 location_hpacker.pack_start (location_vpacker, true, true);
633 add_location_button.signal_clicked().connect (mem_fun(*this, &LocationUI::add_new_location));
634 add_range_button.signal_clicked().connect (mem_fun(*this, &LocationUI::add_new_range));
636 //add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
641 LocationUI::~LocationUI()
647 gint LocationUI::do_location_remove (ARDOUR::Location *loc)
649 /* this is handled internally by Locations, but there's
650 no point saving state etc. when we know the marker
658 session->begin_reversible_command (_("remove marker"));
659 session->add_undo (session->locations()->get_memento());
660 session->locations()->remove (loc);
661 session->add_redo_no_execute (session->locations()->get_memento());
662 session->commit_reversible_command ();
667 void LocationUI::location_remove_requested (ARDOUR::Location *loc)
669 // must do this to prevent problems when destroying
670 // the effective sender of this event
672 Glib::signal_idle().connect (bind (mem_fun(*this, &LocationUI::do_location_remove), loc));
676 void LocationUI::location_redraw_ranges ()
686 LocationUI::location_added (Location* location)
688 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationUI::location_added), location));
690 if (location->is_auto_punch()) {
691 punch_edit_row.set_location(location);
693 else if (location->is_auto_loop()) {
694 loop_edit_row.set_location(location);
697 refresh_location_list ();
702 LocationUI::location_removed (Location* location)
704 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationUI::location_removed), location));
706 if (location->is_auto_punch()) {
707 punch_edit_row.set_location(0);
709 else if (location->is_auto_loop()) {
710 loop_edit_row.set_location(0);
713 refresh_location_list ();
717 struct LocationSortByStart {
718 bool operator() (Location *a, Location *b) {
719 return a->start() < b->start();
724 LocationUI::map_locations (Locations::LocationList& locations)
726 Locations::LocationList::iterator i;
730 Locations::LocationList temp = locations;
731 LocationSortByStart cmp;
736 Box_Helpers::BoxList & loc_children = location_rows.children();
737 Box_Helpers::BoxList & range_children = range_rows.children();
738 LocationEditRow * erow;
740 for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
744 if (location->is_mark()) {
746 erow = manage (new LocationEditRow(session, location, mark_n));
747 erow->remove_requested.connect (mem_fun(*this, &LocationUI::location_remove_requested));
748 erow->redraw_ranges.connect (mem_fun(*this, &LocationUI::location_redraw_ranges));
749 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
751 else if (location->is_auto_punch()) {
752 punch_edit_row.set_session (session);
753 punch_edit_row.set_location (location);
755 else if (location->is_auto_loop()) {
756 loop_edit_row.set_session (session);
757 loop_edit_row.set_location (location);
760 erow = manage (new LocationEditRow(session, location));
761 erow->remove_requested.connect (mem_fun(*this, &LocationUI::location_remove_requested));
762 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
766 range_rows.show_all();
767 location_rows.show_all();
771 LocationUI::add_new_location()
774 jack_nframes_t where = session->audible_frame();
775 Location *location = new Location (where, where, "mark", Location::IsMark);
776 session->begin_reversible_command (_("add marker"));
777 session->add_undo (session->locations()->get_memento());
778 session->locations()->add (location, true);
779 session->add_redo_no_execute (session->locations()->get_memento());
780 session->commit_reversible_command ();
786 LocationUI::add_new_range()
789 jack_nframes_t where = session->audible_frame();
790 Location *location = new Location (where, where, "unnamed");
791 session->begin_reversible_command (_("add range marker"));
792 session->add_undo (session->locations()->get_memento());
793 session->locations()->add (location, true);
794 session->add_redo_no_execute (session->locations()->get_memento());
795 session->commit_reversible_command ();
801 LocationUI::refresh_location_list_s (Change ignored)
803 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationUI::refresh_location_list_s), ignored));
805 refresh_location_list ();
809 LocationUI::refresh_location_list ()
811 ENSURE_GUI_THREAD(mem_fun(*this, &LocationUI::refresh_location_list));
812 using namespace Box_Helpers;
814 BoxList & loc_children = location_rows.children();
815 BoxList & range_children = range_rows.children();
817 loc_children.clear();
818 range_children.clear();
821 session->locations()->apply (*this, &LocationUI::map_locations);
827 LocationUI::set_session(ARDOUR::Session* sess)
829 ArdourDialog::set_session (sess);
832 session->locations()->changed.connect (mem_fun(*this, &LocationUI::refresh_location_list));
833 session->locations()->StateChanged.connect (mem_fun(*this, &LocationUI::refresh_location_list_s));
834 session->locations()->added.connect (mem_fun(*this, &LocationUI::location_added));
835 session->locations()->removed.connect (mem_fun(*this, &LocationUI::location_removed));
836 session->going_away.connect (mem_fun(*this, &LocationUI::session_gone));
838 refresh_location_list ();
842 LocationUI::session_gone()
844 ENSURE_GUI_THREAD(mem_fun(*this, &LocationUI::session_gone));
848 using namespace Box_Helpers;
849 BoxList & loc_children = location_rows.children();
850 BoxList & range_children = range_rows.children();
852 loc_children.clear();
853 range_children.clear();
855 loop_edit_row.set_session (0);
856 loop_edit_row.set_location (0);
858 punch_edit_row.set_session (0);
859 punch_edit_row.set_location (0);
861 ArdourDialog::session_gone();