2 Copyright (C) 2001 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.
22 #include <gtkmm/listviewtext.h>
23 #include <gtkmm/stock.h>
25 #include "pbd/memento_command.h"
26 #include "pbd/stateful_diff_command.h"
28 #include "widgets/tooltips.h"
30 #include "ardour/region.h"
31 #include "ardour/session.h"
32 #include "ardour/source.h"
34 #include "ardour_ui.h"
35 #include "clock_group.h"
36 #include "main_clock.h"
37 #include "gui_thread.h"
38 #include "region_editor.h"
39 #include "public_editor.h"
43 using namespace ARDOUR;
46 using namespace Gtkmm2ext;
48 RegionEditor::RegionEditor (Session* s, boost::shared_ptr<Region> r)
49 : ArdourDialog (_("Region"))
53 , name_label (_("Name:"))
54 , audition_button (_("Audition"))
55 , _clock_group (new ClockGroup)
56 , position_clock (X_("regionposition"), true, "", true, false)
57 , end_clock (X_("regionend"), true, "", true, false)
58 , length_clock (X_("regionlength"), true, "", true, false, true)
59 , sync_offset_relative_clock (X_("regionsyncoffsetrelative"), true, "", true, false)
60 , sync_offset_absolute_clock (X_("regionsyncoffsetabsolute"), true, "", true, false)
61 /* XXX cannot file start yet */
62 , start_clock (X_("regionstart"), true, "", false, false)
67 _clock_group->set_clock_mode (ARDOUR_UI::instance()->secondary_clock->mode());
68 _clock_group->add (position_clock);
69 _clock_group->add (end_clock);
70 _clock_group->add (length_clock);
71 _clock_group->add (sync_offset_relative_clock);
72 _clock_group->add (sync_offset_absolute_clock);
73 _clock_group->add (start_clock);
75 position_clock.set_session (_session);
76 end_clock.set_session (_session);
77 length_clock.set_session (_session);
78 sync_offset_relative_clock.set_session (_session);
79 sync_offset_absolute_clock.set_session (_session);
80 start_clock.set_session (_session);
82 ArdourWidgets::set_tooltip (audition_button, _("audition this region"));
84 audition_button.unset_flags (Gtk::CAN_FOCUS);
86 audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
88 name_entry.set_name ("RegionEditorEntry");
89 name_label.set_name ("RegionEditorLabel");
90 position_label.set_name ("RegionEditorLabel");
91 position_label.set_text (_("Position:"));
92 end_label.set_name ("RegionEditorLabel");
93 end_label.set_text (_("End:"));
94 length_label.set_name ("RegionEditorLabel");
95 length_label.set_text (_("Length:"));
96 sync_relative_label.set_name ("RegionEditorLabel");
97 sync_relative_label.set_text (_("Sync point (relative to region):"));
98 sync_absolute_label.set_name ("RegionEditorLabel");
99 sync_absolute_label.set_text (_("Sync point (absolute):"));
100 start_label.set_name ("RegionEditorLabel");
101 start_label.set_text (_("File start:"));
102 _sources_label.set_name ("RegionEditorLabel");
104 if (_region->n_channels() > 1) {
105 _sources_label.set_text (_("Sources:"));
107 _sources_label.set_text (_("Source:"));
110 _table.set_col_spacings (12);
111 _table.set_row_spacings (6);
112 _table.set_border_width (12);
114 name_label.set_alignment (1, 0.5);
115 position_label.set_alignment (1, 0.5);
116 end_label.set_alignment (1, 0.5);
117 length_label.set_alignment (1, 0.5);
118 sync_relative_label.set_alignment (1, 0.5);
119 sync_absolute_label.set_alignment (1, 0.5);
120 start_label.set_alignment (1, 0.5);
121 _sources_label.set_alignment (1, 0.5);
123 Gtk::HBox* nb = Gtk::manage (new Gtk::HBox);
125 nb->pack_start (name_entry);
126 nb->pack_start (audition_button, false, false);
128 _table.attach (name_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
129 _table.attach (*nb, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
132 _table.attach (position_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
133 _table.attach (position_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
136 _table.attach (end_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
137 _table.attach (end_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
140 _table.attach (length_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
141 _table.attach (length_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
144 _table.attach (sync_relative_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
145 _table.attach (sync_offset_relative_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
148 _table.attach (sync_absolute_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
149 _table.attach (sync_offset_absolute_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
152 _table.attach (start_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
153 _table.attach (start_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
156 _table.attach (_sources_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
157 _table.attach (_sources, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
160 get_vbox()->pack_start (_table, true, true);
162 add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_ACCEPT);
164 set_name ("RegionEditorWindow");
165 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
167 signal_response().connect (sigc::mem_fun (*this, &RegionEditor::handle_response));
169 set_title (string_compose (_("Region '%1'"), _region->name()));
171 for (uint32_t i = 0; i < _region->n_channels(); ++i) {
172 _sources.append_text (_region->source(i)->name());
175 _sources.set_headers_visible (false);
176 Gtk::CellRendererText* t = dynamic_cast<Gtk::CellRendererText*> (_sources.get_column_cell_renderer(0));
178 t->property_ellipsize() = Pango::ELLIPSIZE_END;
184 PropertyChange change;
186 change.add (ARDOUR::Properties::start);
187 change.add (ARDOUR::Properties::length);
188 change.add (ARDOUR::Properties::position);
189 change.add (ARDOUR::Properties::sync_position);
191 bounds_changed (change);
193 _region->PropertyChanged.connect (state_connection, invalidator (*this), boost::bind (&RegionEditor::region_changed, this, _1), gui_context());
195 spin_arrow_grab = false;
197 connect_editor_events ();
200 RegionEditor::~RegionEditor ()
206 RegionEditor::region_changed (const PBD::PropertyChange& what_changed)
208 if (what_changed.contains (ARDOUR::Properties::name)) {
212 PropertyChange interesting_stuff;
214 interesting_stuff.add (ARDOUR::Properties::position);
215 interesting_stuff.add (ARDOUR::Properties::length);
216 interesting_stuff.add (ARDOUR::Properties::start);
217 interesting_stuff.add (ARDOUR::Properties::sync_position);
219 if (what_changed.contains (interesting_stuff)) {
220 bounds_changed (what_changed);
225 RegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* /*but*/, void (RegionEditor::*/*pmf*/)())
227 switch (ev->button) {
231 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
232 if (!spin_arrow_grab) {
233 // GTK2FIX probably nuke the region editor
234 // if ((ev->window == but->gobj()->panel)) {
235 // spin_arrow_grab = true;
248 RegionEditor::breleased (GdkEventButton* /*ev*/, Gtk::SpinButton* /*but*/, void (RegionEditor::*pmf)())
250 if (spin_arrow_grab) {
252 spin_arrow_grab = false;
258 RegionEditor::connect_editor_events ()
260 name_entry.signal_changed().connect (sigc::mem_fun(*this, &RegionEditor::name_entry_changed));
262 position_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::position_clock_changed));
263 end_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::end_clock_changed));
264 length_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::length_clock_changed));
265 sync_offset_absolute_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_absolute_clock_changed));
266 sync_offset_relative_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_relative_clock_changed));
268 audition_button.signal_toggled().connect (sigc::mem_fun(*this, &RegionEditor::audition_button_toggled));
270 _session->AuditionActive.connect (audition_connection, invalidator (*this), boost::bind (&RegionEditor::audition_state_changed, this, _1), gui_context());
274 RegionEditor::position_clock_changed ()
276 bool in_command = false;
277 boost::shared_ptr<Playlist> pl = _region->playlist();
280 PublicEditor::instance().begin_reversible_command (_("change region start position"));
283 _region->clear_changes ();
284 _region->set_position (position_clock.current_time());
285 _session->add_command(new StatefulDiffCommand (_region));
289 PublicEditor::instance().commit_reversible_command ();
294 RegionEditor::end_clock_changed ()
296 bool in_command = false;
297 boost::shared_ptr<Playlist> pl = _region->playlist();
300 PublicEditor::instance().begin_reversible_command (_("change region end position"));
303 _region->clear_changes ();
304 _region->trim_end (end_clock.current_time());
305 _session->add_command(new StatefulDiffCommand (_region));
309 PublicEditor::instance().commit_reversible_command ();
312 end_clock.set (_region->position() + _region->length() - 1, true);
316 RegionEditor::length_clock_changed ()
318 framecnt_t frames = length_clock.current_time();
319 bool in_command = false;
320 boost::shared_ptr<Playlist> pl = _region->playlist();
323 PublicEditor::instance().begin_reversible_command (_("change region length"));
326 _region->clear_changes ();
327 _region->trim_end (_region->position() + frames - 1);
328 _session->add_command(new StatefulDiffCommand (_region));
332 PublicEditor::instance().commit_reversible_command ();
335 length_clock.set (_region->length());
339 RegionEditor::audition_button_toggled ()
341 if (audition_button.get_active()) {
342 _session->audition_region (_region);
344 _session->cancel_audition ();
349 RegionEditor::name_changed ()
351 if (name_entry.get_text() != _region->name()) {
352 name_entry.set_text (_region->name());
357 RegionEditor::bounds_changed (const PropertyChange& what_changed)
359 if (what_changed.contains (ARDOUR::Properties::position) && what_changed.contains (ARDOUR::Properties::length)) {
360 position_clock.set (_region->position(), true);
361 end_clock.set (_region->position() + _region->length() - 1, true);
362 length_clock.set (_region->length(), true);
363 } else if (what_changed.contains (ARDOUR::Properties::position)) {
364 position_clock.set (_region->position(), true);
365 end_clock.set (_region->position() + _region->length() - 1, true);
366 } else if (what_changed.contains (ARDOUR::Properties::length)) {
367 end_clock.set (_region->position() + _region->length() - 1, true);
368 length_clock.set (_region->length(), true);
371 if (what_changed.contains (ARDOUR::Properties::sync_position) || what_changed.contains (ARDOUR::Properties::position)) {
373 frameoffset_t off = _region->sync_offset (dir);
378 if (what_changed.contains (ARDOUR::Properties::sync_position)) {
379 sync_offset_relative_clock.set (off, true);
382 sync_offset_absolute_clock.set (off + _region->position (), true);
385 if (what_changed.contains (ARDOUR::Properties::start)) {
386 start_clock.set (_region->start(), true);
391 RegionEditor::activation ()
397 RegionEditor::name_entry_changed ()
399 if (name_entry.get_text() != _region->name()) {
400 _region->set_name (name_entry.get_text());
405 RegionEditor::audition_state_changed (bool yn)
407 ENSURE_GUI_THREAD (*this, &RegionEditor::audition_state_changed, yn)
410 audition_button.set_active (false);
415 RegionEditor::sync_offset_absolute_clock_changed ()
417 PublicEditor::instance().begin_reversible_command (_("change region sync point"));
419 _region->clear_changes ();
420 _region->set_sync_position (sync_offset_absolute_clock.current_time());
421 _session->add_command (new StatefulDiffCommand (_region));
423 PublicEditor::instance().commit_reversible_command ();
427 RegionEditor::sync_offset_relative_clock_changed ()
429 PublicEditor::instance().begin_reversible_command (_("change region sync point"));
431 _region->clear_changes ();
432 _region->set_sync_position (sync_offset_relative_clock.current_time() + _region->position ());
433 _session->add_command (new StatefulDiffCommand (_region));
435 PublicEditor::instance().commit_reversible_command ();
439 RegionEditor::on_delete_event (GdkEventAny*)
441 PropertyChange change;
443 change.add (ARDOUR::Properties::start);
444 change.add (ARDOUR::Properties::length);
445 change.add (ARDOUR::Properties::position);
446 change.add (ARDOUR::Properties::sync_position);
448 bounds_changed (change);
454 RegionEditor::handle_response (int)