ardour
region_editor.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2001 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <cmath>
21 
22 #include <gtkmm/listviewtext.h>
23 
24 #include "pbd/memento_command.h"
26 
27 #include "ardour/region.h"
28 #include "ardour/session.h"
29 #include "ardour/source.h"
30 
31 #include "ardour_ui.h"
32 #include "clock_group.h"
33 #include "main_clock.h"
34 #include "gui_thread.h"
35 #include "region_editor.h"
36 #include "public_editor.h"
37 
38 #include "i18n.h"
39 
40 using namespace ARDOUR;
41 using namespace PBD;
42 using namespace std;
43 using namespace Gtkmm2ext;
44 
46  : ArdourDialog (_("Region"))
47  , _table (9, 2)
48  , _table_row (0)
49  , _region (r)
50  , name_label (_("Name:"))
51  , audition_button (_("Audition"))
52  , _clock_group (new ClockGroup)
53  , position_clock (X_("regionposition"), true, "", true, false)
54  , end_clock (X_("regionend"), true, "", true, false)
55  , length_clock (X_("regionlength"), true, "", true, false, true)
56  , sync_offset_relative_clock (X_("regionsyncoffsetrelative"), true, "", true, false)
57  , sync_offset_absolute_clock (X_("regionsyncoffsetabsolute"), true, "", true, false)
58  /* XXX cannot file start yet */
59  , start_clock (X_("regionstart"), true, "", false, false)
60  , _sources (1)
61 {
62  set_session (s);
63 
64  _clock_group->set_clock_mode (ARDOUR_UI::instance()->secondary_clock->mode());
71 
78 
79  ARDOUR_UI::instance()->set_tip (audition_button, _("audition this region"));
80 
81  audition_button.unset_flags (Gtk::CAN_FOCUS);
82 
83  audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
84 
85  name_entry.set_name ("RegionEditorEntry");
86  name_label.set_name ("RegionEditorLabel");
87  position_label.set_name ("RegionEditorLabel");
88  position_label.set_text (_("Position:"));
89  end_label.set_name ("RegionEditorLabel");
90  end_label.set_text (_("End:"));
91  length_label.set_name ("RegionEditorLabel");
92  length_label.set_text (_("Length:"));
93  sync_relative_label.set_name ("RegionEditorLabel");
94  sync_relative_label.set_text (_("Sync point (relative to region):"));
95  sync_absolute_label.set_name ("RegionEditorLabel");
96  sync_absolute_label.set_text (_("Sync point (absolute):"));
97  start_label.set_name ("RegionEditorLabel");
98  start_label.set_text (_("File start:"));
99  _sources_label.set_name ("RegionEditorLabel");
100 
101  if (_region->n_channels() > 1) {
102  _sources_label.set_text (_("Sources:"));
103  } else {
104  _sources_label.set_text (_("Source:"));
105  }
106 
107  _table.set_col_spacings (12);
108  _table.set_row_spacings (6);
109  _table.set_border_width (12);
110 
111  name_label.set_alignment (1, 0.5);
112  position_label.set_alignment (1, 0.5);
113  end_label.set_alignment (1, 0.5);
114  length_label.set_alignment (1, 0.5);
115  sync_relative_label.set_alignment (1, 0.5);
116  sync_absolute_label.set_alignment (1, 0.5);
117  start_label.set_alignment (1, 0.5);
118  _sources_label.set_alignment (1, 0.5);
119 
120  Gtk::HBox* nb = Gtk::manage (new Gtk::HBox);
121  nb->set_spacing (6);
122  nb->pack_start (name_entry);
123  nb->pack_start (audition_button, false, false);
124 
125  _table.attach (name_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
126  _table.attach (*nb, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
127  ++_table_row;
128 
129  _table.attach (position_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
130  _table.attach (position_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
131  ++_table_row;
132 
133  _table.attach (end_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
134  _table.attach (end_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
135  ++_table_row;
136 
137  _table.attach (length_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
138  _table.attach (length_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
139  ++_table_row;
140 
141  _table.attach (sync_relative_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
142  _table.attach (sync_offset_relative_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
143  ++_table_row;
144 
145  _table.attach (sync_absolute_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
146  _table.attach (sync_offset_absolute_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
147  ++_table_row;
148 
149  _table.attach (start_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
150  _table.attach (start_clock, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
151  ++_table_row;
152 
153  _table.attach (_sources_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
154  _table.attach (_sources, 1, 2, _table_row, _table_row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
155  ++_table_row;
156 
157  get_vbox()->pack_start (_table, true, true);
158 
159  add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_ACCEPT);
160 
161  set_name ("RegionEditorWindow");
162  add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
163 
164  signal_response().connect (sigc::mem_fun (*this, &RegionEditor::handle_response));
165 
166  set_title (string_compose (_("Region '%1'"), _region->name()));
167 
168  for (uint32_t i = 0; i < _region->n_channels(); ++i) {
169  _sources.append_text (_region->source(i)->name());
170  }
171 
172  _sources.set_headers_visible (false);
173  Gtk::CellRendererText* t = dynamic_cast<Gtk::CellRendererText*> (_sources.get_column_cell_renderer(0));
174  assert (t);
175  t->property_ellipsize() = Pango::ELLIPSIZE_END;
176 
177  show_all();
178 
179  name_changed ();
180 
181  PropertyChange change;
182 
187 
188  bounds_changed (change);
189 
190  _region->PropertyChanged.connect (state_connection, invalidator (*this), boost::bind (&RegionEditor::region_changed, this, _1), gui_context());
191 
192  spin_arrow_grab = false;
193 
195 }
196 
198 {
199  delete _clock_group;
200 }
201 
202 void
204 {
205  if (what_changed.contains (ARDOUR::Properties::name)) {
206  name_changed ();
207  }
208 
209  PropertyChange interesting_stuff;
210 
211  interesting_stuff.add (ARDOUR::Properties::position);
212  interesting_stuff.add (ARDOUR::Properties::length);
213  interesting_stuff.add (ARDOUR::Properties::start);
214  interesting_stuff.add (ARDOUR::Properties::sync_position);
215 
216  if (what_changed.contains (interesting_stuff)) {
217  bounds_changed (what_changed);
218  }
219 }
220 
221 gint
222 RegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* /*but*/, void (RegionEditor::*/*pmf*/)())
223 {
224  switch (ev->button) {
225  case 1:
226  case 2:
227  case 3:
228  if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
229  if (!spin_arrow_grab) {
230  // GTK2FIX probably nuke the region editor
231  // if ((ev->window == but->gobj()->panel)) {
232  // spin_arrow_grab = true;
233  // (this->*pmf)();
234  // }
235  }
236  }
237  break;
238  default:
239  break;
240  }
241  return FALSE;
242 }
243 
244 gint
245 RegionEditor::breleased (GdkEventButton* /*ev*/, Gtk::SpinButton* /*but*/, void (RegionEditor::*pmf)())
246 {
247  if (spin_arrow_grab) {
248  (this->*pmf)();
249  spin_arrow_grab = false;
250  }
251  return FALSE;
252 }
253 
254 void
256 {
257  name_entry.signal_changed().connect (sigc::mem_fun(*this, &RegionEditor::name_entry_changed));
258 
259  position_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::position_clock_changed));
260  end_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::end_clock_changed));
261  length_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::length_clock_changed));
264 
265  audition_button.signal_toggled().connect (sigc::mem_fun(*this, &RegionEditor::audition_button_toggled));
266 
268 }
269 
270 void
272 {
273  PublicEditor::instance().begin_reversible_command (_("change region start position"));
274 
276 
277  if (pl) {
281  }
282 
284 }
285 
286 void
288 {
289  PublicEditor::instance().begin_reversible_command (_("change region end position"));
290 
292 
293  if (pl) {
297  }
298 
300 
301  end_clock.set (_region->position() + _region->length() - 1, true);
302 }
303 
304 void
306 {
308 
309  PublicEditor::instance().begin_reversible_command (_("change region length"));
310 
312 
313  if (pl) {
315  _region->trim_end (_region->position() + frames - 1);
317  }
318 
320 
322 }
323 
324 void
326 {
327  if (audition_button.get_active()) {
329  } else {
331  }
332 }
333 
334 void
336 {
337  if (name_entry.get_text() != _region->name()) {
338  name_entry.set_text (_region->name());
339  }
340 }
341 
342 void
344 {
345  if (what_changed.contains (ARDOUR::Properties::position) && what_changed.contains (ARDOUR::Properties::length)) {
346  position_clock.set (_region->position(), true);
347  end_clock.set (_region->position() + _region->length() - 1, true);
348  length_clock.set (_region->length(), true);
349  } else if (what_changed.contains (ARDOUR::Properties::position)) {
350  position_clock.set (_region->position(), true);
351  end_clock.set (_region->position() + _region->length() - 1, true);
352  } else if (what_changed.contains (ARDOUR::Properties::length)) {
353  end_clock.set (_region->position() + _region->length() - 1, true);
354  length_clock.set (_region->length(), true);
355  }
356 
358  int dir;
359  frameoffset_t off = _region->sync_offset (dir);
360  if (dir == -1) {
361  off = -off;
362  }
363 
364  if (what_changed.contains (ARDOUR::Properties::sync_position)) {
365  sync_offset_relative_clock.set (off, true);
366  }
367 
369  }
370 
371  if (what_changed.contains (ARDOUR::Properties::start)) {
372  start_clock.set (_region->start(), true);
373  }
374 }
375 
376 void
378 {
379 
380 }
381 
382 void
384 {
385  if (name_entry.get_text() != _region->name()) {
386  _region->set_name (name_entry.get_text());
387  }
388 }
389 
390 void
392 {
394 
395  if (!yn) {
396  audition_button.set_active (false);
397  }
398 }
399 
400 void
402 {
403  PublicEditor::instance().begin_reversible_command (_("change region sync point"));
404 
408 
410 }
411 
412 void
414 {
415  PublicEditor::instance().begin_reversible_command (_("change region sync point"));
416 
420 
422 }
423 
424 bool
426 {
427  PropertyChange change;
428 
433 
434  bounds_changed (change);
435 
436  return true;
437 }
438 
439 void
441 {
442  hide ();
443 }
AudioClock start_clock
Definition: region_editor.h:87
Gtk::Label name_label
Definition: region_editor.h:69
framepos_t current_time(framepos_t position=0) const
virtual ~RegionEditor()
bool spin_arrow_grab
void set(framepos_t, bool force=false, ARDOUR::framecnt_t offset=0)
Definition: audio_clock.cc:956
PBD::ScopedConnection audition_connection
Definition: region_editor.h:90
Gtk::Label position_label
Definition: region_editor.h:73
Gtk::Label sync_absolute_label
Definition: region_editor.h:77
PBD::Signal1< void, const PropertyChange & > PropertyChanged
Definition: stateful.h:87
void set_session(ARDOUR::Session *s)
PBD::ScopedConnection state_connection
Definition: region_editor.h:89
RegionEditor(ARDOUR::Session *, boost::shared_ptr< ARDOUR::Region >)
static ARDOUR_UI * instance()
Definition: ardour_ui.h:187
LIBARDOUR_API PBD::PropertyDescriptor< std::string > name
void add_command(Command *const cmd)
Definition: session.h:787
void position_clock_changed()
bool set_name(const std::string &str)
Definition: region.cc:417
Gtk::Entry name_entry
Definition: region_editor.h:70
Definition: Beats.hpp:239
boost::shared_ptr< Source > source(uint32_t n=0) const
Definition: region.h:258
void length_clock_changed()
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
Gtk::Label end_label
Definition: region_editor.h:74
bool on_delete_event(GdkEventAny *)
void set_sync_position(framepos_t n)
Definition: region.cc:1010
#define ENSURE_GUI_THREAD(obj, method,...)
Definition: gui_thread.h:34
#define invalidator(x)
Definition: gui_thread.h:40
Gtk::ToggleButton audition_button
Definition: region_editor.h:71
void cancel_audition()
Definition: session.cc:4160
void name_changed()
#define _(Text)
Definition: i18n.h:11
void trim_end(framepos_t new_position)
Definition: region.cc:836
void handle_response(int)
#define X_(Text)
Definition: i18n.h:13
int64_t framecnt_t
Definition: types.h:76
void set_position(framepos_t)
Definition: region.cc:579
Gtk::Label length_label
Definition: region_editor.h:75
Definition: amp.h:29
void audition_state_changed(bool)
PBD::Signal1< void, bool > AuditionActive
Definition: session.h:679
virtual void begin_reversible_command(std::string cmd_name)=0
#define gui_context()
Definition: gui_thread.h:36
virtual void commit_reversible_command()=0
AudioClock end_clock
Definition: region_editor.h:83
frameoffset_t sync_offset(int &dir) const
Definition: region.cc:1041
AudioClock sync_offset_absolute_clock
sync offset relative to the start of the timeline
Definition: region_editor.h:86
int64_t frameoffset_t
Definition: types.h:71
void name_entry_changed()
sigc::signal< void > ValueChanged
Definition: audio_clock.h:92
framepos_t position() const
Definition: region.h:112
void set_tip(Gtk::Widget &w, const gchar *tip)
void end_clock_changed()
ClockGroup * _clock_group
Definition: region_editor.h:80
void audition_region(boost::shared_ptr< Region >)
Definition: session.cc:4152
static PublicEditor & instance()
Gtk::Table _table
Definition: region_editor.h:61
uint32_t n_channels() const
Definition: region.h:259
void bounds_changed(const PBD::PropertyChange &)
boost::shared_ptr< ARDOUR::Region > _region
Definition: region_editor.h:65
Gtk::Label _sources_label
gint bpressed(GdkEventButton *ev, Gtk::SpinButton *but, void(RegionEditor::*pmf)())
std::string name() const
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > position
Definition: region.cc:65
LIBARDOUR_API PBD::PropertyDescriptor< framecnt_t > sync_position
Definition: region.cc:66
Definition: debug.h:30
AudioClock sync_offset_relative_clock
sync offset relative to the start of the region
Definition: region_editor.h:85
bool contains(PropertyDescriptor< T > p) const
void add(AudioClock &)
Definition: clock_group.cc:33
framecnt_t length() const
Definition: region.h:114
virtual void set_session(ARDOUR::Session *)
framepos_t start() const
Definition: region.h:113
AudioClock length_clock
Definition: region_editor.h:84
Gtk::Label sync_relative_label
Definition: region_editor.h:76
Gtk::ListViewText _sources
void clear_changes()
Definition: stateful.cc:184
Gtk::Label start_label
Definition: region_editor.h:78
ARDOUR::Session * _session
void add(PropertyID id)
void sync_offset_absolute_clock_changed()
void connect_editor_events()
AudioClock position_clock
Definition: region_editor.h:82
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
gint breleased(GdkEventButton *ev, Gtk::SpinButton *but, void(RegionEditor::*pmf)())
boost::shared_ptr< ARDOUR::Playlist > playlist() const
Definition: region.h:251
virtual void region_changed(const PBD::PropertyChange &)
void audition_button_toggled()
LIBARDOUR_API PBD::PropertyDescriptor< framecnt_t > length
Definition: region.cc:64
void sync_offset_relative_clock_changed()
void set_clock_mode(AudioClock::Mode)
Definition: clock_group.cc:56