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.
20 #include "pbd/memento_command.h"
21 #include "pbd/stateful_diff_command.h"
23 #include "ardour/session.h"
24 #include "ardour/region.h"
25 #include "ardour/playlist.h"
26 #include "ardour/utils.h"
27 #include "ardour/dB.h"
28 #include "ardour/source.h"
29 #include "gtkmm2ext/utils.h"
30 #include <gtkmm/listviewtext.h>
33 #include "region_editor.h"
34 #include "ardour_ui.h"
36 #include "gui_thread.h"
40 using namespace ARDOUR;
43 using namespace Gtkmm2ext;
45 RegionEditor::RegionEditor (Session* s, boost::shared_ptr<Region> r)
46 : ArdourDialog (_("Region")),
50 name_label (_("Name:")),
51 audition_button (_("Play")),
52 position_clock (X_("regionposition"), true, X_("RegionEditorClock"), true, false),
53 end_clock (X_("regionend"), true, X_("RegionEditorClock"), true, false),
54 length_clock (X_("regionlength"), true, X_("RegionEditorClock"), true, false, true),
55 sync_offset_relative_clock (X_("regionsyncoffsetrelative"), true, X_("RegionEditorClock"), true, false),
56 sync_offset_absolute_clock (X_("regionsyncoffsetabsolute"), true, X_("RegionEditorClock"), true, false),
57 /* XXX cannot file start yet */
58 start_clock (X_("regionstart"), true, X_("RegionEditorClock"), false, false),
63 position_clock.set_session (_session);
64 end_clock.set_session (_session);
65 length_clock.set_session (_session);
66 sync_offset_relative_clock.set_session (_session);
67 sync_offset_absolute_clock.set_session (_session);
68 start_clock.set_session (_session);
70 ARDOUR_UI::instance()->set_tip (audition_button, _("audition this region"));
72 audition_button.unset_flags (Gtk::CAN_FOCUS);
74 audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
76 name_entry.set_name ("RegionEditorEntry");
77 name_label.set_name ("RegionEditorLabel");
78 position_label.set_name ("RegionEditorLabel");
79 position_label.set_text (_("Position:"));
80 end_label.set_name ("RegionEditorLabel");
81 end_label.set_text (_("End:"));
82 length_label.set_name ("RegionEditorLabel");
83 length_label.set_text (_("Length:"));
84 sync_relative_label.set_name ("RegionEditorLabel");
85 sync_relative_label.set_text (_("Sync point (relative to region):"));
86 sync_absolute_label.set_name ("RegionEditorLabel");
87 sync_absolute_label.set_text (_("Sync point (absolute):"));
88 start_label.set_name ("RegionEditorLabel");
89 start_label.set_text (_("File start:"));
90 _sources_label.set_name ("RegionEditorLabel");
92 if (_region->n_channels() > 1) {
93 _sources_label.set_text (_("Sources:"));
95 _sources_label.set_text (_("Source:"));
98 _table.set_col_spacings (12);
99 _table.set_row_spacings (6);
100 _table.set_border_width (12);
102 name_label.set_alignment (1, 0.5);
103 position_label.set_alignment (1, 0.5);
104 end_label.set_alignment (1, 0.5);
105 length_label.set_alignment (1, 0.5);
106 sync_relative_label.set_alignment (1, 0.5);
107 sync_absolute_label.set_alignment (1, 0.5);
108 start_label.set_alignment (1, 0.5);
109 _sources_label.set_alignment (1, 0.5);
111 Gtk::HBox* nb = Gtk::manage (new Gtk::HBox);
113 nb->pack_start (name_entry);
114 nb->pack_start (audition_button);
116 _table.attach (name_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
117 _table.attach (*nb, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
120 _table.attach (position_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
121 _table.attach (position_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
124 _table.attach (end_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
125 _table.attach (end_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
128 _table.attach (length_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
129 _table.attach (length_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
132 _table.attach (sync_relative_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
133 _table.attach (sync_offset_relative_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
136 _table.attach (sync_absolute_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
137 _table.attach (sync_offset_absolute_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
140 _table.attach (start_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
141 _table.attach (start_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
144 _table.attach (_sources_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
145 _table.attach (_sources, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
148 get_vbox()->pack_start (_table, true, true);
150 add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_ACCEPT);
152 set_name ("RegionEditorWindow");
153 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
155 signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (this)));
156 signal_response().connect (sigc::mem_fun (*this, &RegionEditor::handle_response));
158 set_title (string_compose (_("Region '%1'"), _region->name()));
160 for (uint32_t i = 0; i < _region->n_channels(); ++i) {
161 _sources.append_text (_region->source(i)->name());
164 _sources.set_headers_visible (false);
165 Gtk::CellRendererText* t = dynamic_cast<Gtk::CellRendererText*> (_sources.get_column_cell_renderer(0));
167 t->property_ellipsize() = Pango::ELLIPSIZE_END;
173 PropertyChange change;
175 change.add (ARDOUR::Properties::start);
176 change.add (ARDOUR::Properties::length);
177 change.add (ARDOUR::Properties::position);
178 change.add (ARDOUR::Properties::sync_position);
180 bounds_changed (change);
182 _region->PropertyChanged.connect (state_connection, invalidator (*this), ui_bind (&RegionEditor::region_changed, this, _1), gui_context());
184 spin_arrow_grab = false;
186 connect_editor_events ();
190 RegionEditor::region_changed (const PBD::PropertyChange& what_changed)
192 if (what_changed.contains (ARDOUR::Properties::name)) {
196 PropertyChange interesting_stuff;
198 interesting_stuff.add (ARDOUR::Properties::position);
199 interesting_stuff.add (ARDOUR::Properties::length);
200 interesting_stuff.add (ARDOUR::Properties::start);
201 interesting_stuff.add (ARDOUR::Properties::sync_position);
203 if (what_changed.contains (interesting_stuff)) {
204 bounds_changed (what_changed);
209 RegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* /*but*/, void (RegionEditor::*/*pmf*/)())
211 switch (ev->button) {
215 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
216 if (!spin_arrow_grab) {
217 // GTK2FIX probably nuke the region editor
218 // if ((ev->window == but->gobj()->panel)) {
219 // spin_arrow_grab = true;
232 RegionEditor::breleased (GdkEventButton* /*ev*/, Gtk::SpinButton* /*but*/, void (RegionEditor::*pmf)())
234 if (spin_arrow_grab) {
236 spin_arrow_grab = false;
242 RegionEditor::connect_editor_events ()
244 name_entry.signal_changed().connect (sigc::mem_fun(*this, &RegionEditor::name_entry_changed));
246 position_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::position_clock_changed));
247 end_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::end_clock_changed));
248 length_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::length_clock_changed));
249 sync_offset_absolute_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_absolute_clock_changed));
250 sync_offset_relative_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_relative_clock_changed));
252 audition_button.signal_toggled().connect (sigc::mem_fun(*this, &RegionEditor::audition_button_toggled));
254 _session->AuditionActive.connect (audition_connection, invalidator (*this), ui_bind (&RegionEditor::audition_state_changed, this, _1), gui_context());
258 RegionEditor::position_clock_changed ()
260 _session->begin_reversible_command (_("change region start position"));
262 boost::shared_ptr<Playlist> pl = _region->playlist();
265 _region->clear_changes ();
266 _region->set_position (position_clock.current_time(), this);
267 _session->add_command(new StatefulDiffCommand (_region));
270 _session->commit_reversible_command ();
274 RegionEditor::end_clock_changed ()
276 _session->begin_reversible_command (_("change region end position"));
278 boost::shared_ptr<Playlist> pl = _region->playlist();
281 _region->clear_changes ();
282 _region->trim_end (end_clock.current_time(), this);
283 _session->add_command(new StatefulDiffCommand (_region));
286 _session->commit_reversible_command ();
288 end_clock.set (_region->position() + _region->length() - 1, true);
292 RegionEditor::length_clock_changed ()
294 framecnt_t frames = length_clock.current_time();
296 _session->begin_reversible_command (_("change region length"));
298 boost::shared_ptr<Playlist> pl = _region->playlist();
301 _region->clear_changes ();
302 _region->trim_end (_region->position() + frames - 1, this);
303 _session->add_command(new StatefulDiffCommand (_region));
306 _session->commit_reversible_command ();
308 length_clock.set (_region->length());
312 RegionEditor::audition_button_toggled ()
314 if (audition_button.get_active()) {
315 _session->audition_region (_region);
317 _session->cancel_audition ();
322 RegionEditor::name_changed ()
324 if (name_entry.get_text() != _region->name()) {
325 name_entry.set_text (_region->name());
330 RegionEditor::bounds_changed (const PropertyChange& what_changed)
332 if (what_changed.contains (ARDOUR::Properties::position) && what_changed.contains (ARDOUR::Properties::length)) {
333 position_clock.set (_region->position(), true);
334 end_clock.set (_region->position() + _region->length() - 1, true);
335 length_clock.set (_region->length(), true);
336 } else if (what_changed.contains (ARDOUR::Properties::position)) {
337 position_clock.set (_region->position(), true);
338 end_clock.set (_region->position() + _region->length() - 1, true);
339 } else if (what_changed.contains (ARDOUR::Properties::length)) {
340 end_clock.set (_region->position() + _region->length() - 1, true);
341 length_clock.set (_region->length(), true);
344 if (what_changed.contains (ARDOUR::Properties::sync_position) || what_changed.contains (ARDOUR::Properties::position)) {
346 frameoffset_t off = _region->sync_offset (dir);
351 if (what_changed.contains (ARDOUR::Properties::sync_position)) {
352 sync_offset_relative_clock.set (off, true);
355 sync_offset_absolute_clock.set (off + _region->position (), true);
358 if (what_changed.contains (ARDOUR::Properties::start)) {
359 start_clock.set (_region->start(), true);
364 RegionEditor::activation ()
370 RegionEditor::name_entry_changed ()
372 if (name_entry.get_text() != _region->name()) {
373 _region->set_name (name_entry.get_text());
378 RegionEditor::audition_state_changed (bool yn)
380 ENSURE_GUI_THREAD (*this, &RegionEditor::audition_state_changed, yn)
383 audition_button.set_active (false);
388 RegionEditor::sync_offset_absolute_clock_changed ()
390 _session->begin_reversible_command (_("change region sync point"));
392 _region->clear_changes ();
393 _region->set_sync_position (sync_offset_absolute_clock.current_time());
394 _session->add_command (new StatefulDiffCommand (_region));
396 _session->commit_reversible_command ();
400 RegionEditor::sync_offset_relative_clock_changed ()
402 _session->begin_reversible_command (_("change region sync point"));
404 _region->clear_changes ();
405 _region->set_sync_position (sync_offset_relative_clock.current_time() + _region->position ());
406 _session->add_command (new StatefulDiffCommand (_region));
408 _session->commit_reversible_command ();
412 RegionEditor::on_delete_event (GdkEventAny*)
414 PropertyChange change;
416 change.add (ARDOUR::Properties::start);
417 change.add (ARDOUR::Properties::length);
418 change.add (ARDOUR::Properties::position);
419 change.add (ARDOUR::Properties::sync_position);
421 bounds_changed (change);
427 RegionEditor::handle_response (int)