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"
22 #include "ardour/audioregion.h"
23 #include "ardour/playlist.h"
24 #include "ardour/utils.h"
25 #include <gtkmm2ext/utils.h>
26 #include <gtkmm2ext/stop_signal.h>
29 #include "audio_region_editor.h"
30 #include "audio_region_view.h"
31 #include "ardour_ui.h"
33 #include "gui_thread.h"
37 using namespace ARDOUR;
41 using namespace Gtkmm2ext;
43 AudioRegionEditor::AudioRegionEditor (Session& s, boost::shared_ptr<AudioRegion> r, AudioRegionView& rv)
47 name_label (_("Name:")),
48 audition_button (_("Play")),
50 position_clock (X_("regionposition"), true, X_("AudioRegionEditorClock"), true),
51 end_clock (X_("regionend"), true, X_("AudioRegionEditorClock"), true),
52 length_clock (X_("regionlength"), true, X_("AudioRegionEditorClock"), true, true),
53 sync_offset_relative_clock (X_("regionsyncoffsetrelative"), true, X_("AudioRegionEditorClock"), true),
54 sync_offset_absolute_clock (X_("regionsyncoffsetabsolute"), true, X_("AudioRegionEditorClock"), true),
55 /* XXX cannot file start yet */
56 start_clock (X_("regionstart"), true, X_("AudioRegionEditorClock"), false)
59 position_clock.set_session (&_session);
60 end_clock.set_session (&_session);
61 length_clock.set_session (&_session);
62 sync_offset_relative_clock.set_session (&_session);
63 sync_offset_absolute_clock.set_session (&_session);
64 start_clock.set_session (&_session);
66 name_entry.set_name ("AudioRegionEditorEntry");
67 name_label.set_name ("AudioRegionEditorLabel");
69 name_hbox.set_spacing (5);
70 name_hbox.pack_start (name_label, false, false);
71 name_hbox.pack_start (name_entry, false, false);
73 ARDOUR_UI::instance()->tooltips().set_tip (audition_button, _("audition this region"));
75 audition_button.unset_flags (Gtk::CAN_FOCUS);
77 audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
79 top_row_button_hbox.set_border_width (5);
80 top_row_button_hbox.set_spacing (5);
81 top_row_button_hbox.set_homogeneous (false);
82 top_row_button_hbox.pack_end (audition_button, false, false);
84 top_row_hbox.pack_start (name_hbox, true, true);
85 top_row_hbox.pack_end (top_row_button_hbox, true, true);
87 position_label.set_name ("AudioRegionEditorLabel");
88 position_label.set_text (_("Position"));
89 end_label.set_name ("AudioRegionEditorLabel");
90 end_label.set_text (_("End"));
91 length_label.set_name ("AudioRegionEditorLabel");
92 length_label.set_text (_("Length"));
93 sync_relative_label.set_name ("AudioRegionEditorLabel");
94 sync_relative_label.set_text (_("Sync point (relative to region position)"));
95 sync_absolute_label.set_name ("AudioRegionEditorLabel");
96 sync_absolute_label.set_text (_("Sync point (absolute)"));
97 start_label.set_name ("AudioRegionEditorLabel");
98 start_label.set_text (_("File start"));
100 time_table.set_col_spacings (2);
101 time_table.set_row_spacings (5);
102 time_table.set_border_width (5);
104 position_label.set_alignment (1, 0.5);
105 time_table.attach (position_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
106 time_table.attach (position_clock, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
108 end_label.set_alignment (1, 0.5);
109 time_table.attach (end_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
110 time_table.attach (end_clock, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL);
112 length_label.set_alignment (1, 0.5);
113 time_table.attach (length_label, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL);
114 time_table.attach (length_clock, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL);
116 sync_relative_label.set_alignment (1, 0.5);
117 time_table.attach (sync_relative_label, 0, 1, 3, 4, Gtk::FILL, Gtk::FILL);
118 time_table.attach (sync_offset_relative_clock, 1, 2, 3, 4, Gtk::FILL, Gtk::FILL);
120 sync_absolute_label.set_alignment (1, 0.5);
121 time_table.attach (sync_absolute_label, 0, 1, 4, 5, Gtk::FILL, Gtk::FILL);
122 time_table.attach (sync_offset_absolute_clock, 1, 2, 4, 5, Gtk::FILL, Gtk::FILL);
124 start_label.set_alignment (1, 0.5);
125 time_table.attach (start_label, 0, 1, 5, 6, Gtk::FILL, Gtk::FILL);
126 time_table.attach (start_clock, 1, 2, 5, 6, Gtk::FILL, Gtk::FILL);
128 lower_hbox.pack_start (time_table, true, true);
129 lower_hbox.pack_start (sep1, false, false);
130 lower_hbox.pack_start (sep2, false, false);
132 get_vbox()->pack_start (top_row_hbox, true, true);
133 get_vbox()->pack_start (sep3, false, false);
134 get_vbox()->pack_start (lower_hbox, true, true);
136 set_name ("AudioRegionEditorWindow");
137 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
139 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (this)));
141 set_title (string_compose (_("Region %1"), _region->name()));
146 bounds_changed (Change (StartChanged|LengthChanged|PositionChanged|StartChanged|Region::SyncOffsetChanged));
148 _region->StateChanged.connect (mem_fun(*this, &AudioRegionEditor::region_changed));
150 spin_arrow_grab = false;
152 connect_editor_events ();
155 AudioRegionEditor::~AudioRegionEditor ()
160 AudioRegionEditor::region_changed (Change what_changed)
162 if (what_changed & NameChanged) {
166 if (what_changed & Change (BoundsChanged|StartChanged|Region::SyncOffsetChanged)) {
167 bounds_changed (what_changed);
172 AudioRegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* /*but*/, void (AudioRegionEditor::*/*pmf*/)())
174 switch (ev->button) {
178 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
179 if (!spin_arrow_grab) {
180 // GTK2FIX probably nuke the region editor
181 // if ((ev->window == but->gobj()->panel)) {
182 // spin_arrow_grab = true;
195 AudioRegionEditor::breleased (GdkEventButton* /*ev*/, Gtk::SpinButton* /*but*/, void (AudioRegionEditor::*pmf)())
197 if (spin_arrow_grab) {
199 spin_arrow_grab = false;
205 AudioRegionEditor::connect_editor_events ()
207 name_entry.signal_changed().connect (mem_fun(*this, &AudioRegionEditor::name_entry_changed));
209 position_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::position_clock_changed));
210 end_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::end_clock_changed));
211 length_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::length_clock_changed));
212 sync_offset_absolute_clock.ValueChanged.connect (mem_fun (*this, &AudioRegionEditor::sync_offset_absolute_clock_changed));
213 sync_offset_relative_clock.ValueChanged.connect (mem_fun (*this, &AudioRegionEditor::sync_offset_relative_clock_changed));
215 audition_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::audition_button_toggled));
216 _session.AuditionActive.connect (mem_fun(*this, &AudioRegionEditor::audition_state_changed));
220 AudioRegionEditor::position_clock_changed ()
222 _session.begin_reversible_command (_("change region start position"));
224 boost::shared_ptr<Playlist> pl = _region->playlist();
227 XMLNode &before = pl->get_state();
228 _region->set_position (position_clock.current_time(), this);
229 XMLNode &after = pl->get_state();
230 _session.add_command(new MementoCommand<Playlist>(*pl, &before, &after));
233 _session.commit_reversible_command ();
237 AudioRegionEditor::end_clock_changed ()
239 _session.begin_reversible_command (_("change region end position"));
241 boost::shared_ptr<Playlist> pl = _region->playlist();
244 XMLNode &before = pl->get_state();
245 _region->trim_end (end_clock.current_time(), this);
246 XMLNode &after = pl->get_state();
247 _session.add_command(new MementoCommand<Playlist>(*pl, &before, &after));
250 _session.commit_reversible_command ();
252 end_clock.set (_region->position() + _region->length() - 1, true);
256 AudioRegionEditor::length_clock_changed ()
258 nframes_t frames = length_clock.current_time();
260 _session.begin_reversible_command (_("change region length"));
262 boost::shared_ptr<Playlist> pl = _region->playlist();
265 XMLNode &before = pl->get_state();
266 _region->trim_end (_region->position() + frames - 1, this);
267 XMLNode &after = pl->get_state();
268 _session.add_command(new MementoCommand<Playlist>(*pl, &before, &after));
271 _session.commit_reversible_command ();
273 length_clock.set (_region->length());
277 AudioRegionEditor::audition_button_toggled ()
279 if (audition_button.get_active()) {
280 _session.audition_region (_region);
282 _session.cancel_audition ();
287 AudioRegionEditor::name_changed ()
289 if (name_entry.get_text() != _region->name()) {
290 name_entry.set_text (_region->name());
295 AudioRegionEditor::bounds_changed (Change what_changed)
297 if ((what_changed & Change (PositionChanged|LengthChanged)) == Change (PositionChanged|LengthChanged)) {
298 position_clock.set (_region->position(), true);
299 end_clock.set (_region->position() + _region->length() - 1, true);
300 length_clock.set (_region->length(), true);
301 } else if (what_changed & Change (PositionChanged)) {
302 position_clock.set (_region->position(), true);
303 end_clock.set (_region->position() + _region->length() - 1, true);
304 } else if (what_changed & Change (LengthChanged)) {
305 end_clock.set (_region->position() + _region->length() - 1, true);
306 length_clock.set (_region->length(), true);
309 if ((what_changed & Region::SyncOffsetChanged) || (what_changed & PositionChanged)) {
311 nframes_t off = _region->sync_offset (dir);
316 if (what_changed & Region::SyncOffsetChanged) {
317 sync_offset_relative_clock.set (off, true);
320 sync_offset_absolute_clock.set (off + _region->position (), true);
323 if (what_changed & StartChanged) {
324 start_clock.set (_region->start(), true);
329 AudioRegionEditor::activation ()
335 AudioRegionEditor::name_entry_changed ()
337 if (name_entry.get_text() != _region->name()) {
338 _region->set_name (name_entry.get_text());
343 AudioRegionEditor::audition_state_changed (bool yn)
345 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionEditor::audition_state_changed), yn));
348 audition_button.set_active (false);
353 AudioRegionEditor::sync_offset_absolute_clock_changed ()
355 _session.begin_reversible_command (_("change region sync point"));
357 XMLNode& before = _region->get_state ();
358 _region->set_sync_position (sync_offset_absolute_clock.current_time());
359 XMLNode& after = _region->get_state ();
360 _session.add_command (new MementoCommand<AudioRegion> (*_region.get(), &before, &after));
362 _session.commit_reversible_command ();
366 AudioRegionEditor::sync_offset_relative_clock_changed ()
368 _session.begin_reversible_command (_("change region sync point"));
370 XMLNode& before = _region->get_state ();
371 _region->set_sync_position (sync_offset_relative_clock.current_time() + _region->position ());
372 XMLNode& after = _region->get_state ();
373 _session.add_command (new MementoCommand<AudioRegion> (*_region.get(), &before, &after));
375 _session.commit_reversible_command ();