fix setting of BWF info (from 3.0). thanks carl
[ardour2.git] / gtk2_ardour / audio_region_editor.cc
blob288f2b45567cff8b9a0a9189002896c084e5725c
1 /*
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>
27 #include <cmath>
29 #include "audio_region_editor.h"
30 #include "audio_region_view.h"
31 #include "ardour_ui.h"
32 #include "utils.h"
33 #include "gui_thread.h"
35 #include "i18n.h"
37 using namespace ARDOUR;
38 using namespace PBD;
39 using namespace sigc;
40 using namespace std;
41 using namespace Gtkmm2ext;
43 AudioRegionEditor::AudioRegionEditor (Session& s, boost::shared_ptr<AudioRegion> r, AudioRegionView& rv)
44 : RegionEditor (s),
45 _region (r),
46 _region_view (rv),
47 name_label (_("Name:")),
48 audition_button (_("Audition")),
49 time_table (5, 2),
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 /* XXX cannot edit sync point or start yet */
54 sync_offset_clock (X_("regionsyncoffset"), true, X_("AudioRegionEditorClock"), false),
55 start_clock (X_("regionstart"), true, X_("AudioRegionEditorClock"), false)
58 position_clock.set_session (&_session);
59 end_clock.set_session (&_session);
60 length_clock.set_session (&_session);
61 sync_offset_clock.set_session (&_session);
62 start_clock.set_session (&_session);
64 name_entry.set_name ("AudioRegionEditorEntry");
65 name_label.set_name ("AudioRegionEditorLabel");
67 name_hbox.set_spacing (5);
68 name_hbox.pack_start (name_label, false, false);
69 name_hbox.pack_start (name_entry, false, false);
71 ARDOUR_UI::instance()->tooltips().set_tip (audition_button, _("audition this region"));
73 audition_button.unset_flags (Gtk::CAN_FOCUS);
75 audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
77 top_row_button_hbox.set_border_width (5);
78 top_row_button_hbox.set_spacing (5);
79 top_row_button_hbox.set_homogeneous (false);
80 top_row_button_hbox.pack_end (audition_button, false, false);
82 top_row_hbox.pack_start (name_hbox, true, true);
83 top_row_hbox.pack_end (top_row_button_hbox, true, true);
85 position_label.set_name ("AudioRegionEditorLabel");
86 position_label.set_text (_("Position:"));
87 end_label.set_name ("AudioRegionEditorLabel");
88 end_label.set_text (_("End:"));
89 length_label.set_name ("AudioRegionEditorLabel");
90 length_label.set_text (_("Length:"));
91 sync_label.set_name ("AudioRegionEditorLabel");
92 sync_label.set_text (_("Sync Point:"));
93 start_label.set_name ("AudioRegionEditorLabel");
94 start_label.set_text (_("File Start:"));
96 time_table.set_col_spacings (2);
97 time_table.set_row_spacings (5);
98 time_table.set_border_width (5);
100 position_alignment.set (1.0, 0.5);
101 end_alignment.set (1.0, 0.5);
102 length_alignment.set (1.0, 0.5);
103 sync_alignment.set (1.0, 0.5);
104 start_alignment.set (1.0, 0.5);
106 position_alignment.add (position_label);
107 end_alignment.add (end_label);
108 length_alignment.add (length_label);
109 sync_alignment.add (sync_label);
110 start_alignment.add (start_label);
112 time_table.attach (position_alignment, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
113 time_table.attach (position_clock, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
115 time_table.attach (end_alignment, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
116 time_table.attach (end_clock, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL);
118 time_table.attach (length_alignment, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL);
119 time_table.attach (length_clock, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL);
121 time_table.attach (sync_alignment, 0, 1, 3, 4, Gtk::FILL, Gtk::FILL);
122 time_table.attach (sync_offset_clock, 1, 2, 3, 4, Gtk::FILL, Gtk::FILL);
124 time_table.attach (start_alignment, 0, 1, 4, 5, Gtk::FILL, Gtk::FILL);
125 time_table.attach (start_clock, 1, 2, 4, 5, Gtk::FILL, Gtk::FILL);
127 lower_hbox.pack_start (time_table, true, true);
128 lower_hbox.pack_start (sep1, false, false);
129 lower_hbox.pack_start (sep2, false, false);
131 get_vbox()->pack_start (top_row_hbox, true, true);
132 get_vbox()->pack_start (sep3, false, false);
133 get_vbox()->pack_start (lower_hbox, true, true);
135 set_name ("AudioRegionEditorWindow");
136 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
138 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (this)));
140 set_title (string_compose (_("Region %1"), _region->name()));
142 show_all();
144 name_changed ();
145 bounds_changed (Change (StartChanged|LengthChanged|PositionChanged|StartChanged|Region::SyncOffsetChanged));
147 _region->StateChanged.connect (mem_fun(*this, &AudioRegionEditor::region_changed));
149 spin_arrow_grab = false;
151 connect_editor_events ();
154 AudioRegionEditor::~AudioRegionEditor ()
158 void
159 AudioRegionEditor::region_changed (Change what_changed)
161 if (what_changed & NameChanged) {
162 name_changed ();
165 if (what_changed & Change (BoundsChanged|StartChanged|Region::SyncOffsetChanged)) {
166 bounds_changed (what_changed);
170 gint
171 AudioRegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* but, void (AudioRegionEditor::*pmf)())
173 switch (ev->button) {
174 case 1:
175 case 2:
176 case 3:
177 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
178 if (!spin_arrow_grab) {
179 // GTK2FIX probably nuke the region editor
180 // if ((ev->window == but->gobj()->panel)) {
181 // spin_arrow_grab = true;
182 // (this->*pmf)();
183 // }
186 break;
187 default:
188 break;
190 return FALSE;
193 gint
194 AudioRegionEditor::breleased (GdkEventButton* ev, Gtk::SpinButton* but, void (AudioRegionEditor::*pmf)())
196 if (spin_arrow_grab) {
197 (this->*pmf)();
198 spin_arrow_grab = false;
200 return FALSE;
203 void
204 AudioRegionEditor::connect_editor_events ()
206 name_entry.signal_changed().connect (mem_fun(*this, &AudioRegionEditor::name_entry_changed));
208 position_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::position_clock_changed));
209 end_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::end_clock_changed));
210 length_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::length_clock_changed));
212 audition_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::audition_button_toggled));
213 _session.AuditionActive.connect (mem_fun(*this, &AudioRegionEditor::audition_state_changed));
216 void
217 AudioRegionEditor::position_clock_changed ()
219 _session.begin_reversible_command (_("change region start position"));
221 boost::shared_ptr<Playlist> pl = _region->playlist();
223 if (pl) {
224 XMLNode &before = pl->get_state();
225 _region->set_position (position_clock.current_time(), this);
226 XMLNode &after = pl->get_state();
227 _session.add_command(new MementoCommand<Playlist>(*pl, &before, &after));
230 _session.commit_reversible_command ();
233 void
234 AudioRegionEditor::end_clock_changed ()
236 _session.begin_reversible_command (_("change region end position"));
238 boost::shared_ptr<Playlist> pl = _region->playlist();
240 if (pl) {
241 XMLNode &before = pl->get_state();
242 _region->trim_end (end_clock.current_time(), this);
243 XMLNode &after = pl->get_state();
244 _session.add_command(new MementoCommand<Playlist>(*pl, &before, &after));
247 _session.commit_reversible_command ();
249 end_clock.set (_region->position() + _region->length()-1, true);
252 void
253 AudioRegionEditor::length_clock_changed ()
255 nframes_t frames = length_clock.current_time();
257 _session.begin_reversible_command (_("change region length"));
259 boost::shared_ptr<Playlist> pl = _region->playlist();
261 if (pl) {
262 XMLNode &before = pl->get_state();
263 _region->trim_end (_region->position() + frames -1, this);
264 XMLNode &after = pl->get_state();
265 _session.add_command(new MementoCommand<Playlist>(*pl, &before, &after));
268 _session.commit_reversible_command ();
270 length_clock.set (_region->length());
273 void
274 AudioRegionEditor::audition_button_toggled ()
276 if (audition_button.get_active()) {
277 _session.audition_region (_region);
278 } else {
279 _session.cancel_audition ();
283 void
284 AudioRegionEditor::name_changed ()
286 if (name_entry.get_text() != _region->name()) {
287 name_entry.set_text (_region->name());
291 void
292 AudioRegionEditor::bounds_changed (Change what_changed)
294 if ((what_changed & Change (PositionChanged|LengthChanged)) == Change (PositionChanged|LengthChanged)) {
295 position_clock.set (_region->position(), true);
296 end_clock.set (_region->position() + _region->length() -1, true);
297 length_clock.set (_region->length(), true);
298 } else if (what_changed & Change (PositionChanged)) {
299 position_clock.set (_region->position(), true);
300 end_clock.set (_region->position() + _region->length() -1, true);
301 } else if (what_changed & Change (LengthChanged)) {
302 end_clock.set (_region->position() + _region->length() -1, true);
303 length_clock.set (_region->length(), true);
306 if (what_changed & Region::SyncOffsetChanged) {
307 sync_offset_clock.set (_region->sync_position(), true);
310 if (what_changed & StartChanged) {
311 start_clock.set (_region->start(), true);
315 void
316 AudioRegionEditor::activation ()
321 void
322 AudioRegionEditor::name_entry_changed ()
324 if (name_entry.get_text() != _region->name()) {
325 _region->set_name (name_entry.get_text());
329 void
330 AudioRegionEditor::audition_state_changed (bool yn)
332 ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionEditor::audition_state_changed), yn));
334 if (!yn) {
335 audition_button.set_active (false);