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;
43 using namespace Gtkmm2ext;
45 LocationEditRow::LocationEditRow(Session * sess, Location * loc, int32_t num)
46 : location(0), session(0),
47 item_table (1, 7, false),
48 start_set_button (_("Set")),
49 start_go_button (_("Go")),
50 start_clock (X_("LocationEditRowClock"), true),
51 end_set_button (_("Set")),
52 end_go_button (_("Go")),
53 end_clock (X_("LocationEditRowClock"), true),
54 length_clock (X_("LocationEditRowClock"), true, true),
55 cd_check_button (_("CD")),
56 hide_check_button (_("Hidden")),
57 remove_button (_("Remove")),
58 scms_check_button (_("SCMS")),
59 preemph_check_button (_("Pre-Emphasis"))
63 i_am_the_modifier = 0;
65 number_label.set_name ("LocationEditNumberLabel");
66 name_label.set_name ("LocationEditNameLabel");
67 name_entry.set_name ("LocationEditNameEntry");
68 start_set_button.set_name ("LocationEditSetButton");
69 start_go_button.set_name ("LocationEditGoButton");
70 end_set_button.set_name ("LocationEditSetButton");
71 end_go_button.set_name ("LocationEditGoButton");
72 cd_check_button.set_name ("LocationEditCdButton");
73 hide_check_button.set_name ("LocationEditHideButton");
74 remove_button.set_name ("LocationEditRemoveButton");
75 isrc_label.set_name ("LocationEditNumberLabel");
76 isrc_entry.set_name ("LocationEditNameEntry");
77 scms_check_button.set_name ("LocationEditCdButton");
78 preemph_check_button.set_name ("LocationEditCdButton");
79 performer_label.set_name ("LocationEditNumberLabel");
80 performer_entry.set_name ("LocationEditNameEntry");
81 composer_label.set_name ("LocationEditNumberLabel");
82 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 cd_track_details_hbox.pack_start (isrc_label, false, false);
103 cd_track_details_hbox.pack_start (isrc_entry, false, false);
104 cd_track_details_hbox.pack_start (scms_check_button, false, false);
105 cd_track_details_hbox.pack_start (preemph_check_button, false, false);
106 cd_track_details_hbox.pack_start (performer_label, false, false);
107 cd_track_details_hbox.pack_start (performer_entry, true, true);
108 cd_track_details_hbox.pack_start (composer_label, false, false);
109 cd_track_details_hbox.pack_start (composer_entry, true, true);
111 isrc_entry.signal_changed().connect (mem_fun(*this, &LocationEditRow::isrc_entry_changed));
112 performer_entry.signal_changed().connect (mem_fun(*this, &LocationEditRow::performer_entry_changed));
113 composer_entry.signal_changed().connect (mem_fun(*this, &LocationEditRow::composer_entry_changed));
114 scms_check_button.signal_toggled().connect(mem_fun(*this, &LocationEditRow::scms_toggled));
115 preemph_check_button.signal_toggled().connect(mem_fun(*this, &LocationEditRow::preemph_toggled));
121 item_table.attach (number_label, 0, 1, 0, 1, FILL, FILL, 3, 0);
123 start_hbox.pack_start (start_go_button, false, false);
124 start_hbox.pack_start (start_clock, false, false);
125 start_hbox.pack_start (start_set_button, false, false);
127 item_table.attach (start_hbox, 2, 3, 0, 1, FILL, FILL, 4, 0);
130 start_set_button.signal_clicked().connect(bind (mem_fun (*this, &LocationEditRow::set_button_pressed), LocStart));
131 start_go_button.signal_clicked().connect(bind (mem_fun (*this, &LocationEditRow::go_button_pressed), LocStart));
132 start_clock.ValueChanged.connect (bind (mem_fun (*this, &LocationEditRow::clock_changed), LocStart));
135 end_hbox.pack_start (end_go_button, false, false);
136 end_hbox.pack_start (end_clock, false, false);
137 end_hbox.pack_start (end_set_button, false, false);
139 //item_table.attach (end_hbox, 2, 3, 0, 1, 0, 0, 4, 0);
141 end_set_button.signal_clicked().connect(bind (mem_fun (*this, &LocationEditRow::set_button_pressed), LocEnd));
142 end_go_button.signal_clicked().connect(bind (mem_fun (*this, &LocationEditRow::go_button_pressed), LocEnd));
143 end_clock.ValueChanged.connect (bind (mem_fun (*this, &LocationEditRow::clock_changed), LocEnd));
145 // item_table.attach (length_clock, 3, 4, 0, 1, 0, 0, 4, 0);
146 length_clock.ValueChanged.connect (bind ( mem_fun(*this, &LocationEditRow::clock_changed), LocLength));
148 // item_table.attach (cd_check_button, 4, 5, 0, 1, 0, Gtk::FILL, 4, 0);
149 // item_table.attach (hide_check_button, 5, 6, 0, 1, 0, Gtk::FILL, 4, 0);
150 // item_table.attach (remove_button, 7, 8, 0, 1, 0, Gtk::FILL, 4, 0);
152 cd_check_button.signal_toggled().connect(mem_fun(*this, &LocationEditRow::cd_toggled));
153 hide_check_button.signal_toggled().connect(mem_fun(*this, &LocationEditRow::hide_toggled));
155 remove_button.signal_clicked().connect(mem_fun(*this, &LocationEditRow::remove_button_pressed));
157 pack_start(item_table, true, true);
163 LocationEditRow::~LocationEditRow()
166 start_changed_connection.disconnect();
167 end_changed_connection.disconnect();
168 name_changed_connection.disconnect();
169 changed_connection.disconnect();
170 flags_changed_connection.disconnect();
175 LocationEditRow::set_session (Session *sess)
179 if (!session) return;
181 start_clock.set_session (session);
182 end_clock.set_session (session);
183 length_clock.set_session (session);
188 LocationEditRow::set_number (int num)
193 number_label.set_text (string_compose ("%1", number));
198 LocationEditRow::set_location (Location *loc)
201 start_changed_connection.disconnect();
202 end_changed_connection.disconnect();
203 name_changed_connection.disconnect();
204 changed_connection.disconnect();
205 flags_changed_connection.disconnect();
210 if (!location) return;
212 if (!hide_check_button.get_parent()) {
213 item_table.attach (hide_check_button, 6, 7, 0, 1, FILL, Gtk::FILL, 4, 0);
215 hide_check_button.set_active (location->is_hidden());
217 if (location->is_auto_loop() || location->is_auto_punch()) {
218 // use label instead of entry
220 name_label.set_text (location->name());
221 name_label.set_size_request (80, -1);
223 if (!name_label.get_parent()) {
224 item_table.attach (name_label, 1, 2, 0, 1, FILL, Gtk::FILL, 4, 0);
231 name_entry.set_text (location->name());
232 name_entry.set_size_request (100, -1);
233 name_entry.set_editable (true);
234 name_entry.signal_changed().connect (mem_fun(*this, &LocationEditRow::name_entry_changed));
236 if (!name_entry.get_parent()) {
237 item_table.attach (name_entry, 1, 2, 0, 1, FILL | EXPAND, FILL, 4, 0);
241 if (!cd_check_button.get_parent()) {
242 item_table.attach (cd_check_button, 5, 6, 0, 1, FILL, Gtk::FILL, 4, 0);
244 if (!remove_button.get_parent()) {
245 item_table.attach (remove_button, 7, 8, 0, 1, FILL, Gtk::FILL, 4, 0);
248 /* XXX i can't find a way to hide the button without messing up
249 the row spacing, so make it insensitive (paul).
252 if (location->is_end()) {
253 remove_button.set_sensitive (false);
256 cd_check_button.set_active (location->is_cd_marker());
257 cd_check_button.show();
258 hide_check_button.show();
261 start_clock.set (location->start(), true);
264 if (!location->is_mark()) {
265 if (!end_hbox.get_parent()) {
266 item_table.attach (end_hbox, 3, 4, 0, 1, FILL, FILL, 4, 0);
268 if (!length_clock.get_parent()) {
269 item_table.attach (length_clock, 4, 5, 0, 1, FILL, FILL, 4, 0);
272 end_clock.set (location->end(), true);
273 length_clock.set (location->length(), true);
275 end_set_button.show();
276 end_go_button.show();
281 end_set_button.hide();
282 end_go_button.hide();
287 start_changed_connection = location->start_changed.connect (mem_fun(*this, &LocationEditRow::start_changed));
288 end_changed_connection = location->end_changed.connect (mem_fun(*this, &LocationEditRow::end_changed));
289 name_changed_connection = location->name_changed.connect (mem_fun(*this, &LocationEditRow::name_changed));
290 changed_connection = location->changed.connect (mem_fun(*this, &LocationEditRow::location_changed));
291 flags_changed_connection = location->FlagsChanged.connect (mem_fun(*this, &LocationEditRow::flags_changed));
296 LocationEditRow::name_entry_changed ()
298 ENSURE_GUI_THREAD(mem_fun(*this, &LocationEditRow::name_entry_changed));
299 if (i_am_the_modifier || !location) return;
301 location->set_name (name_entry.get_text());
306 LocationEditRow::isrc_entry_changed ()
308 ENSURE_GUI_THREAD(mem_fun(*this, &LocationEditRow::isrc_entry_changed));
310 if (i_am_the_modifier || !location) return;
312 if (isrc_entry.get_text() != "" ) {
314 location->cd_info["isrc"] = isrc_entry.get_text();
317 location->cd_info.erase("isrc");
322 LocationEditRow::performer_entry_changed ()
324 ENSURE_GUI_THREAD(mem_fun(*this, &LocationEditRow::performer_entry_changed));
326 if (i_am_the_modifier || !location) return;
328 if (performer_entry.get_text() != "") {
329 location->cd_info["performer"] = performer_entry.get_text();
331 location->cd_info.erase("performer");
336 LocationEditRow::composer_entry_changed ()
338 ENSURE_GUI_THREAD(mem_fun(*this, &LocationEditRow::composer_entry_changed));
340 if (i_am_the_modifier || !location) return;
342 if (composer_entry.get_text() != "") {
343 location->cd_info["composer"] = composer_entry.get_text();
345 location->cd_info.erase("composer");
351 LocationEditRow::set_button_pressed (LocationPart part)
353 if (!location) return;
357 location->set_start (session->transport_frame ());
360 location->set_end (session->transport_frame ());
368 LocationEditRow::go_button_pressed (LocationPart part)
370 if (!location) return;
374 ARDOUR_UI::instance()->do_transport_locate (location->start());
377 ARDOUR_UI::instance()->do_transport_locate (location->end());
385 LocationEditRow::clock_changed (LocationPart part)
387 if (i_am_the_modifier || !location) return;
391 location->set_start (start_clock.current_time());
394 location->set_end (end_clock.current_time());
397 location->set_end (location->start() + length_clock.current_duration());
405 LocationEditRow::cd_toggled ()
408 if (i_am_the_modifier || !location) return;
409 location->set_cd (cd_check_button.get_active(), this);
411 if (location->is_cd_marker() && !(location->is_mark())) {
413 if (location->cd_info.find("isrc") != location->cd_info.end()) {
414 isrc_entry.set_text(location->cd_info["isrc"]);
416 if (location->cd_info.find("performer") != location->cd_info.end()) {
417 performer_entry.set_text(location->cd_info["performer"]);
419 if (location->cd_info.find("composer") != location->cd_info.end()) {
420 composer_entry.set_text(location->cd_info["composer"]);
422 if (location->cd_info.find("scms") != location->cd_info.end()) {
423 scms_check_button.set_active(true);
425 if (location->cd_info.find("preemph") != location->cd_info.end()) {
426 preemph_check_button.set_active(true);
429 if(!cd_track_details_hbox.get_parent()) {
430 item_table.attach (cd_track_details_hbox, 1, 8, 1, 2, FILL | EXPAND, FILL, 4, 0);
432 // item_table.resize(2, 7);
433 cd_track_details_hbox.show_all();
435 } else if (cd_track_details_hbox.get_parent()){
437 item_table.remove (cd_track_details_hbox);
438 // item_table.resize(1, 7);
439 redraw_ranges(); /* EMIT_SIGNAL */
446 LocationEditRow::hide_toggled ()
448 if (i_am_the_modifier || !location) return;
450 location->set_hidden (hide_check_button.get_active(), this);
454 LocationEditRow::remove_button_pressed ()
456 if (!location) return;
458 remove_requested(location); /* EMIT_SIGNAL */
464 LocationEditRow::scms_toggled ()
466 if (i_am_the_modifier || !location) return;
468 if (scms_check_button.get_active()) {
469 location->cd_info["scms"] = "on";
471 location->cd_info.erase("scms");
477 LocationEditRow::preemph_toggled ()
479 if (i_am_the_modifier || !location) return;
481 if (preemph_check_button.get_active()) {
482 location->cd_info["preemph"] = "on";
484 location->cd_info.erase("preemph");
489 LocationEditRow::end_changed (ARDOUR::Location *loc)
491 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::end_changed), loc));
493 if (!location) return;
495 // update end and length
498 end_clock.set (location->end());
499 length_clock.set (location->length());
505 LocationEditRow::start_changed (ARDOUR::Location *loc)
507 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::start_changed), loc));
509 if (!location) return;
511 // update end and length
514 start_clock.set (location->start());
520 LocationEditRow::name_changed (ARDOUR::Location *loc)
522 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::name_changed), loc));
524 if (!location) return;
526 // update end and length
529 name_entry.set_text(location->name());
530 name_label.set_text(location->name());
537 LocationEditRow::location_changed (ARDOUR::Location *loc)
539 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::location_changed), loc));
541 if (!location) return;
545 start_clock.set (location->start());
546 end_clock.set (location->end());
547 length_clock.set (location->length());
554 LocationEditRow::flags_changed (ARDOUR::Location *loc, void *src)
556 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationEditRow::flags_changed), loc, src));
558 if (!location) return;
562 cd_check_button.set_active (location->is_cd_marker());
563 hide_check_button.set_active (location->is_hidden());
568 LocationUI::LocationUI ()
569 : ArdourDialog ("location dialog"),
570 add_location_button (_("Add New Location")),
571 add_range_button (_("Add New Range"))
573 i_am_the_modifier = 0;
575 set_title(_("ardour: locations"));
576 set_wmclass(_("ardour_locations"), "Ardour");
578 set_name ("LocationWindow");
580 get_vbox()->pack_start (location_hpacker);
582 location_vpacker.set_border_width (10);
583 location_vpacker.set_spacing (5);
585 location_vpacker.pack_start (loop_edit_row, false, false);
586 location_vpacker.pack_start (punch_edit_row, false, false);
588 location_rows.set_name("LocationLocRows");
589 location_rows_scroller.add (location_rows);
590 location_rows_scroller.set_name ("LocationLocRowsScroller");
591 location_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
592 location_rows_scroller.set_size_request (-1, 130);
594 loc_frame_box.set_spacing (5);
595 loc_frame_box.set_border_width (5);
596 loc_frame_box.set_name("LocationFrameBox");
598 loc_frame_box.pack_start (location_rows_scroller, true, true);
600 add_location_button.set_name ("LocationAddLocationButton");
601 loc_frame_box.pack_start (add_location_button, false, false);
603 loc_frame.set_name ("LocationLocEditorFrame");
604 loc_frame.set_label (_("Location (CD Index) Markers"));
605 loc_frame.add (loc_frame_box);
606 loc_range_panes.pack1(loc_frame, true, false);
609 range_rows.set_name("LocationRangeRows");
610 range_rows_scroller.add (range_rows);
611 range_rows_scroller.set_name ("LocationRangeRowsScroller");
612 range_rows_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
613 range_rows_scroller.set_size_request (-1, 130);
615 range_frame_box.set_spacing (5);
616 range_frame_box.set_name("LocationFrameBox");
617 range_frame_box.set_border_width (5);
618 range_frame_box.pack_start (range_rows_scroller, true, true);
620 add_range_button.set_name ("LocationAddRangeButton");
621 range_frame_box.pack_start (add_range_button, false, false);
623 range_frame.set_name ("LocationRangeEditorFrame");
624 range_frame.set_label (_("Range (CD Track) Markers"));
625 range_frame.add (range_frame_box);
626 loc_range_panes.pack2(range_frame, true, false);
627 location_vpacker.pack_start (loc_range_panes, true, true);
629 location_hpacker.pack_start (location_vpacker, true, true);
631 add_location_button.signal_clicked().connect (mem_fun(*this, &LocationUI::add_new_location));
632 add_range_button.signal_clicked().connect (mem_fun(*this, &LocationUI::add_new_range));
634 //add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_RELEASE_MASK);
639 LocationUI::~LocationUI()
645 gint LocationUI::do_location_remove (ARDOUR::Location *loc)
647 /* this is handled internally by Locations, but there's
648 no point saving state etc. when we know the marker
656 session->begin_reversible_command (_("remove marker"));
657 session->add_undo (session->locations()->get_memento());
658 session->locations()->remove (loc);
659 session->add_redo_no_execute (session->locations()->get_memento());
660 session->commit_reversible_command ();
665 void LocationUI::location_remove_requested (ARDOUR::Location *loc)
667 // must do this to prevent problems when destroying
668 // the effective sender of this event
670 Glib::signal_idle().connect (bind (mem_fun(*this, &LocationUI::do_location_remove), loc));
674 void LocationUI::location_redraw_ranges ()
684 LocationUI::location_added (Location* location)
686 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationUI::location_added), location));
688 if (location->is_auto_punch()) {
689 punch_edit_row.set_location(location);
691 else if (location->is_auto_loop()) {
692 loop_edit_row.set_location(location);
695 refresh_location_list ();
700 LocationUI::location_removed (Location* location)
702 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationUI::location_removed), location));
704 if (location->is_auto_punch()) {
705 punch_edit_row.set_location(0);
707 else if (location->is_auto_loop()) {
708 loop_edit_row.set_location(0);
711 refresh_location_list ();
715 struct LocationSortByStart {
716 bool operator() (Location *a, Location *b) {
717 return a->start() < b->start();
722 LocationUI::map_locations (Locations::LocationList& locations)
724 Locations::LocationList::iterator i;
728 Locations::LocationList temp = locations;
729 LocationSortByStart cmp;
734 Box_Helpers::BoxList & loc_children = location_rows.children();
735 Box_Helpers::BoxList & range_children = range_rows.children();
736 LocationEditRow * erow;
738 for (n = 0, i = locations.begin(); i != locations.end(); ++n, ++i) {
742 if (location->is_mark()) {
744 erow = manage (new LocationEditRow(session, location, mark_n));
745 erow->remove_requested.connect (mem_fun(*this, &LocationUI::location_remove_requested));
746 erow->redraw_ranges.connect (mem_fun(*this, &LocationUI::location_redraw_ranges));
747 loc_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
749 else if (location->is_auto_punch()) {
750 punch_edit_row.set_session (session);
751 punch_edit_row.set_location (location);
753 else if (location->is_auto_loop()) {
754 loop_edit_row.set_session (session);
755 loop_edit_row.set_location (location);
758 erow = manage (new LocationEditRow(session, location));
759 erow->remove_requested.connect (mem_fun(*this, &LocationUI::location_remove_requested));
760 range_children.push_back(Box_Helpers::Element(*erow, PACK_SHRINK, 1, PACK_START));
764 range_rows.show_all();
765 location_rows.show_all();
769 LocationUI::add_new_location()
772 jack_nframes_t where = session->audible_frame();
773 Location *location = new Location (where, where, "mark", Location::IsMark);
774 session->begin_reversible_command (_("add marker"));
775 session->add_undo (session->locations()->get_memento());
776 session->locations()->add (location, true);
777 session->add_redo_no_execute (session->locations()->get_memento());
778 session->commit_reversible_command ();
784 LocationUI::add_new_range()
787 jack_nframes_t where = session->audible_frame();
788 Location *location = new Location (where, where, "unnamed",
789 Location::IsRangeMarker);
790 session->begin_reversible_command (_("add range marker"));
791 session->add_undo (session->locations()->get_memento());
792 session->locations()->add (location, true);
793 session->add_redo_no_execute (session->locations()->get_memento());
794 session->commit_reversible_command ();
800 LocationUI::refresh_location_list_s (Change ignored)
802 ENSURE_GUI_THREAD(bind (mem_fun(*this, &LocationUI::refresh_location_list_s), ignored));
804 refresh_location_list ();
808 LocationUI::refresh_location_list ()
810 ENSURE_GUI_THREAD(mem_fun(*this, &LocationUI::refresh_location_list));
811 using namespace Box_Helpers;
813 BoxList & loc_children = location_rows.children();
814 BoxList & range_children = range_rows.children();
816 loc_children.clear();
817 range_children.clear();
820 session->locations()->apply (*this, &LocationUI::map_locations);
826 LocationUI::set_session(ARDOUR::Session* sess)
828 ArdourDialog::set_session (sess);
831 session->locations()->changed.connect (mem_fun(*this, &LocationUI::refresh_location_list));
832 session->locations()->StateChanged.connect (mem_fun(*this, &LocationUI::refresh_location_list_s));
833 session->locations()->added.connect (mem_fun(*this, &LocationUI::location_added));
834 session->locations()->removed.connect (mem_fun(*this, &LocationUI::location_removed));
835 session->going_away.connect (mem_fun(*this, &LocationUI::session_gone));
837 refresh_location_list ();
841 LocationUI::session_gone()
843 ENSURE_GUI_THREAD(mem_fun(*this, &LocationUI::session_gone));
847 using namespace Box_Helpers;
848 BoxList & loc_children = location_rows.children();
849 BoxList & range_children = range_rows.children();
851 loc_children.clear();
852 range_children.clear();
854 loop_edit_row.set_session (0);
855 loop_edit_row.set_location (0);
857 punch_edit_row.set_session (0);
858 punch_edit_row.set_location (0);
860 ArdourDialog::session_gone ();
864 LocationUI::on_delete_event (GdkEventAny* ev)