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 <gtkmm2ext/utils.h>
29 #include <gtkmm2ext/stop_signal.h>
32 #include "region_editor.h"
33 #include "ardour_ui.h"
35 #include "gui_thread.h"
39 using namespace ARDOUR;
42 using namespace Gtkmm2ext;
44 RegionEditor::RegionEditor (Session* s, boost::shared_ptr<Region> r)
45 : ArdourDialog (_("Region")),
48 name_label (_("Name:")),
49 audition_button (_("Play")),
50 position_clock (X_("regionposition"), true, X_("RegionEditorClock"), true, false),
51 end_clock (X_("regionend"), true, X_("RegionEditorClock"), true, false),
52 length_clock (X_("regionlength"), true, X_("RegionEditorClock"), true, false, true),
53 sync_offset_relative_clock (X_("regionsyncoffsetrelative"), true, X_("RegionEditorClock"), true, false),
54 sync_offset_absolute_clock (X_("regionsyncoffsetabsolute"), true, X_("RegionEditorClock"), true, false),
55 /* XXX cannot file start yet */
56 start_clock (X_("regionstart"), true, X_("RegionEditorClock"), false, false)
60 position_clock.set_session (_session);
61 end_clock.set_session (_session);
62 length_clock.set_session (_session);
63 sync_offset_relative_clock.set_session (_session);
64 sync_offset_absolute_clock.set_session (_session);
65 start_clock.set_session (_session);
67 ARDOUR_UI::instance()->set_tip (audition_button, _("audition this region"));
69 audition_button.unset_flags (Gtk::CAN_FOCUS);
71 audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
73 name_entry.set_name ("RegionEditorEntry");
74 name_label.set_name ("RegionEditorLabel");
75 position_label.set_name ("RegionEditorLabel");
76 position_label.set_text (_("Position:"));
77 end_label.set_name ("RegionEditorLabel");
78 end_label.set_text (_("End:"));
79 length_label.set_name ("RegionEditorLabel");
80 length_label.set_text (_("Length:"));
81 sync_relative_label.set_name ("RegionEditorLabel");
82 sync_relative_label.set_text (_("Sync point (relative to region):"));
83 sync_absolute_label.set_name ("RegionEditorLabel");
84 sync_absolute_label.set_text (_("Sync point (absolute):"));
85 start_label.set_name ("RegionEditorLabel");
86 start_label.set_text (_("File start:"));
88 _table.set_col_spacings (12);
89 _table.set_row_spacings (6);
90 _table.set_border_width (12);
92 name_label.set_alignment (1, 0.5);
93 position_label.set_alignment (1, 0.5);
94 end_label.set_alignment (1, 0.5);
95 length_label.set_alignment (1, 0.5);
96 sync_relative_label.set_alignment (1, 0.5);
97 sync_absolute_label.set_alignment (1, 0.5);
98 start_label.set_alignment (1, 0.5);
100 Gtk::HBox* nb = Gtk::manage (new Gtk::HBox);
102 nb->pack_start (name_entry);
103 nb->pack_start (audition_button);
105 _table.attach (name_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
106 _table.attach (*nb, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
108 _table.attach (position_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
109 _table.attach (position_clock, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL);
111 _table.attach (end_label, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL);
112 _table.attach (end_clock, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL);
114 _table.attach (length_label, 0, 1, 3, 4, Gtk::FILL, Gtk::FILL);
115 _table.attach (length_clock, 1, 2, 3, 4, Gtk::FILL, Gtk::FILL);
117 _table.attach (sync_relative_label, 0, 1, 4, 5, Gtk::FILL, Gtk::FILL);
118 _table.attach (sync_offset_relative_clock, 1, 2, 4, 5, Gtk::FILL, Gtk::FILL);
120 _table.attach (sync_absolute_label, 0, 1, 5, 6, Gtk::FILL, Gtk::FILL);
121 _table.attach (sync_offset_absolute_clock, 1, 2, 5, 6, Gtk::FILL, Gtk::FILL);
123 _table.attach (start_label, 0, 1, 6, 7, Gtk::FILL, Gtk::FILL);
124 _table.attach (start_clock, 1, 2, 6, 7, Gtk::FILL, Gtk::FILL);
126 get_vbox()->pack_start (_table, true, true);
128 add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_ACCEPT);
130 set_name ("RegionEditorWindow");
131 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
133 signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (this)));
134 signal_response().connect (sigc::mem_fun (*this, &RegionEditor::handle_response));
136 set_title (string_compose (_("Region '%1'"), _region->name()));
142 PropertyChange change;
144 change.add (ARDOUR::Properties::start);
145 change.add (ARDOUR::Properties::length);
146 change.add (ARDOUR::Properties::position);
147 change.add (ARDOUR::Properties::sync_position);
149 bounds_changed (change);
151 _region->PropertyChanged.connect (state_connection, invalidator (*this), ui_bind (&RegionEditor::region_changed, this, _1), gui_context());
153 spin_arrow_grab = false;
155 connect_editor_events ();
159 RegionEditor::region_changed (const PBD::PropertyChange& what_changed)
161 if (what_changed.contains (ARDOUR::Properties::name)) {
165 PropertyChange interesting_stuff;
167 interesting_stuff.add (ARDOUR::Properties::position);
168 interesting_stuff.add (ARDOUR::Properties::length);
169 interesting_stuff.add (ARDOUR::Properties::start);
170 interesting_stuff.add (ARDOUR::Properties::sync_position);
172 if (what_changed.contains (interesting_stuff)) {
173 bounds_changed (what_changed);
178 RegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* /*but*/, void (RegionEditor::*/*pmf*/)())
180 switch (ev->button) {
184 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
185 if (!spin_arrow_grab) {
186 // GTK2FIX probably nuke the region editor
187 // if ((ev->window == but->gobj()->panel)) {
188 // spin_arrow_grab = true;
201 RegionEditor::breleased (GdkEventButton* /*ev*/, Gtk::SpinButton* /*but*/, void (RegionEditor::*pmf)())
203 if (spin_arrow_grab) {
205 spin_arrow_grab = false;
211 RegionEditor::connect_editor_events ()
213 name_entry.signal_changed().connect (sigc::mem_fun(*this, &RegionEditor::name_entry_changed));
215 position_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::position_clock_changed));
216 end_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::end_clock_changed));
217 length_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::length_clock_changed));
218 sync_offset_absolute_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_absolute_clock_changed));
219 sync_offset_relative_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_relative_clock_changed));
221 audition_button.signal_toggled().connect (sigc::mem_fun(*this, &RegionEditor::audition_button_toggled));
223 _session->AuditionActive.connect (audition_connection, invalidator (*this), ui_bind (&RegionEditor::audition_state_changed, this, _1), gui_context());
227 RegionEditor::position_clock_changed ()
229 _session->begin_reversible_command (_("change region start position"));
231 boost::shared_ptr<Playlist> pl = _region->playlist();
234 _region->clear_history ();
235 _region->set_position (position_clock.current_time(), this);
236 _session->add_command(new StatefulDiffCommand (_region));
239 _session->commit_reversible_command ();
243 RegionEditor::end_clock_changed ()
245 _session->begin_reversible_command (_("change region end position"));
247 boost::shared_ptr<Playlist> pl = _region->playlist();
250 _region->clear_history ();
251 _region->trim_end (end_clock.current_time(), this);
252 _session->add_command(new StatefulDiffCommand (_region));
255 _session->commit_reversible_command ();
257 end_clock.set (_region->position() + _region->length() - 1, true);
261 RegionEditor::length_clock_changed ()
263 nframes_t frames = length_clock.current_time();
265 _session->begin_reversible_command (_("change region length"));
267 boost::shared_ptr<Playlist> pl = _region->playlist();
270 _region->clear_history ();
271 _region->trim_end (_region->position() + frames - 1, this);
272 _session->add_command(new StatefulDiffCommand (_region));
275 _session->commit_reversible_command ();
277 length_clock.set (_region->length());
281 RegionEditor::audition_button_toggled ()
283 if (audition_button.get_active()) {
284 _session->audition_region (_region);
286 _session->cancel_audition ();
291 RegionEditor::name_changed ()
293 if (name_entry.get_text() != _region->name()) {
294 name_entry.set_text (_region->name());
299 RegionEditor::bounds_changed (const PropertyChange& what_changed)
301 if (what_changed.contains (ARDOUR::Properties::position) && what_changed.contains (ARDOUR::Properties::length)) {
302 position_clock.set (_region->position(), true);
303 end_clock.set (_region->position() + _region->length() - 1, true);
304 length_clock.set (_region->length(), true);
305 } else if (what_changed.contains (ARDOUR::Properties::position)) {
306 position_clock.set (_region->position(), true);
307 end_clock.set (_region->position() + _region->length() - 1, true);
308 } else if (what_changed.contains (ARDOUR::Properties::length)) {
309 end_clock.set (_region->position() + _region->length() - 1, true);
310 length_clock.set (_region->length(), true);
313 if (what_changed.contains (ARDOUR::Properties::sync_position) || what_changed.contains (ARDOUR::Properties::position)) {
315 nframes_t off = _region->sync_offset (dir);
320 if (what_changed.contains (ARDOUR::Properties::sync_position)) {
321 sync_offset_relative_clock.set (off, true);
324 sync_offset_absolute_clock.set (off + _region->position (), true);
327 if (what_changed.contains (ARDOUR::Properties::start)) {
328 start_clock.set (_region->start(), true);
333 RegionEditor::activation ()
339 RegionEditor::name_entry_changed ()
341 if (name_entry.get_text() != _region->name()) {
342 _region->set_name (name_entry.get_text());
347 RegionEditor::audition_state_changed (bool yn)
349 ENSURE_GUI_THREAD (*this, &RegionEditor::audition_state_changed, yn)
352 audition_button.set_active (false);
357 RegionEditor::sync_offset_absolute_clock_changed ()
359 _session->begin_reversible_command (_("change region sync point"));
361 _region->clear_history ();
362 _region->set_sync_position (sync_offset_absolute_clock.current_time());
363 _session->add_command (new StatefulDiffCommand (_region));
365 _session->commit_reversible_command ();
369 RegionEditor::sync_offset_relative_clock_changed ()
371 _session->begin_reversible_command (_("change region sync point"));
373 _region->clear_history ();
374 _region->set_sync_position (sync_offset_relative_clock.current_time() + _region->position ());
375 _session->add_command (new StatefulDiffCommand (_region));
377 _session->commit_reversible_command ();
381 RegionEditor::on_delete_event (GdkEventAny* ev)
383 PropertyChange change;
385 change.add (ARDOUR::Properties::start);
386 change.add (ARDOUR::Properties::length);
387 change.add (ARDOUR::Properties::position);
388 change.add (ARDOUR::Properties::sync_position);
390 bounds_changed (change);
392 return RegionEditor::on_delete_event (ev);
396 RegionEditor::handle_response (int)