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");
91 _sources_label.set_text (_("Sources:"));
93 _table.set_col_spacings (12);
94 _table.set_row_spacings (6);
95 _table.set_border_width (12);
97 name_label.set_alignment (1, 0.5);
98 position_label.set_alignment (1, 0.5);
99 end_label.set_alignment (1, 0.5);
100 length_label.set_alignment (1, 0.5);
101 sync_relative_label.set_alignment (1, 0.5);
102 sync_absolute_label.set_alignment (1, 0.5);
103 start_label.set_alignment (1, 0.5);
104 _sources_label.set_alignment (1, 0.5);
106 Gtk::HBox* nb = Gtk::manage (new Gtk::HBox);
108 nb->pack_start (name_entry);
109 nb->pack_start (audition_button);
111 _table.attach (name_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
112 _table.attach (*nb, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
115 _table.attach (position_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
116 _table.attach (position_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
119 _table.attach (end_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
120 _table.attach (end_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
123 _table.attach (length_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
124 _table.attach (length_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
127 _table.attach (sync_relative_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
128 _table.attach (sync_offset_relative_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
131 _table.attach (sync_absolute_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
132 _table.attach (sync_offset_absolute_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
135 _table.attach (start_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
136 _table.attach (start_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
139 _table.attach (_sources_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
140 _table.attach (_sources, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
143 get_vbox()->pack_start (_table, true, true);
145 add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_ACCEPT);
147 set_name ("RegionEditorWindow");
148 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
150 signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (this)));
151 signal_response().connect (sigc::mem_fun (*this, &RegionEditor::handle_response));
153 set_title (string_compose (_("Region '%1'"), _region->name()));
155 for (uint32_t i = 0; i < _region->n_channels(); ++i) {
156 _sources.append_text (_region->source(i)->name());
159 _sources.set_headers_visible (false);
160 Gtk::CellRendererText* t = dynamic_cast<Gtk::CellRendererText*> (_sources.get_column_cell_renderer(0));
162 t->property_ellipsize() = Pango::ELLIPSIZE_END;
168 PropertyChange change;
170 change.add (ARDOUR::Properties::start);
171 change.add (ARDOUR::Properties::length);
172 change.add (ARDOUR::Properties::position);
173 change.add (ARDOUR::Properties::sync_position);
175 bounds_changed (change);
177 _region->PropertyChanged.connect (state_connection, invalidator (*this), ui_bind (&RegionEditor::region_changed, this, _1), gui_context());
179 spin_arrow_grab = false;
181 connect_editor_events ();
185 RegionEditor::region_changed (const PBD::PropertyChange& what_changed)
187 if (what_changed.contains (ARDOUR::Properties::name)) {
191 PropertyChange interesting_stuff;
193 interesting_stuff.add (ARDOUR::Properties::position);
194 interesting_stuff.add (ARDOUR::Properties::length);
195 interesting_stuff.add (ARDOUR::Properties::start);
196 interesting_stuff.add (ARDOUR::Properties::sync_position);
198 if (what_changed.contains (interesting_stuff)) {
199 bounds_changed (what_changed);
204 RegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* /*but*/, void (RegionEditor::*/*pmf*/)())
206 switch (ev->button) {
210 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
211 if (!spin_arrow_grab) {
212 // GTK2FIX probably nuke the region editor
213 // if ((ev->window == but->gobj()->panel)) {
214 // spin_arrow_grab = true;
227 RegionEditor::breleased (GdkEventButton* /*ev*/, Gtk::SpinButton* /*but*/, void (RegionEditor::*pmf)())
229 if (spin_arrow_grab) {
231 spin_arrow_grab = false;
237 RegionEditor::connect_editor_events ()
239 name_entry.signal_changed().connect (sigc::mem_fun(*this, &RegionEditor::name_entry_changed));
241 position_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::position_clock_changed));
242 end_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::end_clock_changed));
243 length_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::length_clock_changed));
244 sync_offset_absolute_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_absolute_clock_changed));
245 sync_offset_relative_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_relative_clock_changed));
247 audition_button.signal_toggled().connect (sigc::mem_fun(*this, &RegionEditor::audition_button_toggled));
249 _session->AuditionActive.connect (audition_connection, invalidator (*this), ui_bind (&RegionEditor::audition_state_changed, this, _1), gui_context());
253 RegionEditor::position_clock_changed ()
255 _session->begin_reversible_command (_("change region start position"));
257 boost::shared_ptr<Playlist> pl = _region->playlist();
260 _region->clear_changes ();
261 _region->set_position (position_clock.current_time(), this);
262 _session->add_command(new StatefulDiffCommand (_region));
265 _session->commit_reversible_command ();
269 RegionEditor::end_clock_changed ()
271 _session->begin_reversible_command (_("change region end position"));
273 boost::shared_ptr<Playlist> pl = _region->playlist();
276 _region->clear_changes ();
277 _region->trim_end (end_clock.current_time(), this);
278 _session->add_command(new StatefulDiffCommand (_region));
281 _session->commit_reversible_command ();
283 end_clock.set (_region->position() + _region->length() - 1, true);
287 RegionEditor::length_clock_changed ()
289 nframes_t frames = length_clock.current_time();
291 _session->begin_reversible_command (_("change region length"));
293 boost::shared_ptr<Playlist> pl = _region->playlist();
296 _region->clear_changes ();
297 _region->trim_end (_region->position() + frames - 1, this);
298 _session->add_command(new StatefulDiffCommand (_region));
301 _session->commit_reversible_command ();
303 length_clock.set (_region->length());
307 RegionEditor::audition_button_toggled ()
309 if (audition_button.get_active()) {
310 _session->audition_region (_region);
312 _session->cancel_audition ();
317 RegionEditor::name_changed ()
319 if (name_entry.get_text() != _region->name()) {
320 name_entry.set_text (_region->name());
325 RegionEditor::bounds_changed (const PropertyChange& what_changed)
327 if (what_changed.contains (ARDOUR::Properties::position) && what_changed.contains (ARDOUR::Properties::length)) {
328 position_clock.set (_region->position(), true);
329 end_clock.set (_region->position() + _region->length() - 1, true);
330 length_clock.set (_region->length(), true);
331 } else if (what_changed.contains (ARDOUR::Properties::position)) {
332 position_clock.set (_region->position(), true);
333 end_clock.set (_region->position() + _region->length() - 1, true);
334 } else if (what_changed.contains (ARDOUR::Properties::length)) {
335 end_clock.set (_region->position() + _region->length() - 1, true);
336 length_clock.set (_region->length(), true);
339 if (what_changed.contains (ARDOUR::Properties::sync_position) || what_changed.contains (ARDOUR::Properties::position)) {
341 nframes_t off = _region->sync_offset (dir);
346 if (what_changed.contains (ARDOUR::Properties::sync_position)) {
347 sync_offset_relative_clock.set (off, true);
350 sync_offset_absolute_clock.set (off + _region->position (), true);
353 if (what_changed.contains (ARDOUR::Properties::start)) {
354 start_clock.set (_region->start(), true);
359 RegionEditor::activation ()
365 RegionEditor::name_entry_changed ()
367 if (name_entry.get_text() != _region->name()) {
368 _region->set_name (name_entry.get_text());
373 RegionEditor::audition_state_changed (bool yn)
375 ENSURE_GUI_THREAD (*this, &RegionEditor::audition_state_changed, yn)
378 audition_button.set_active (false);
383 RegionEditor::sync_offset_absolute_clock_changed ()
385 _session->begin_reversible_command (_("change region sync point"));
387 _region->clear_changes ();
388 _region->set_sync_position (sync_offset_absolute_clock.current_time());
389 _session->add_command (new StatefulDiffCommand (_region));
391 _session->commit_reversible_command ();
395 RegionEditor::sync_offset_relative_clock_changed ()
397 _session->begin_reversible_command (_("change region sync point"));
399 _region->clear_changes ();
400 _region->set_sync_position (sync_offset_relative_clock.current_time() + _region->position ());
401 _session->add_command (new StatefulDiffCommand (_region));
403 _session->commit_reversible_command ();
407 RegionEditor::on_delete_event (GdkEventAny*)
409 PropertyChange change;
411 change.add (ARDOUR::Properties::start);
412 change.add (ARDOUR::Properties::length);
413 change.add (ARDOUR::Properties::position);
414 change.add (ARDOUR::Properties::sync_position);
416 bounds_changed (change);
422 RegionEditor::handle_response (int)