ardour
region_layering_order_editor.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011-2012 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 <gtkmm/table.h>
21 #include <gtkmm/stock.h>
22 #include <gtkmm/alignment.h>
23 
25 
26 #include "ardour/region.h"
27 
28 #include "gui_thread.h"
29 #include "keyboard.h"
30 #include "public_editor.h"
32 #include "region_view.h"
33 #include "utils.h"
34 #include "i18n.h"
35 
36 using namespace std;
37 using namespace Gtk;
38 using namespace ARDOUR;
39 using namespace ARDOUR_UI_UTILS;
40 
42  : ArdourWindow (_("RegionLayeringOrderEditor"))
43  , position (0)
44  , in_row_change (false)
45  , regions_at_position (0)
46  , layering_order_model (Gtk::ListStore::create (layering_order_columns))
47  , clock ("layer dialog", true, "", false, false, false)
48  , editor (pe)
49  , _time_axis_view (0)
50 {
51  set_name ("RegionLayeringOrderEditorWindow");
52 
54 
55  layering_order_display.append_column (_("Region Name"), layering_order_columns.name);
56  layering_order_display.set_headers_visible (true);
57  layering_order_display.set_reorderable (false);
58  layering_order_display.set_rules_hint (true);
59 
60  scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
62 
64 
65  Gtk::Table* scroller_table = manage (new Gtk::Table);
66  scroller_table->set_size_request (300, 250);
67  scroller_table->attach (scroller, 0, 1, 0, 1);
68  scroller_table->set_col_spacings (5);
69  scroller_table->set_row_spacings (5);
70 
71  track_label.set_name ("RegionLayeringOrderEditorLabel");
72  track_label.set_text (_("Track:"));
73  track_label.set_alignment (0, 0.5);
74  clock_label.set_name ("RegionLayeringOrderEditorLabel");
75  clock_label.set_text (_("Position:"));
76  clock_label.set_alignment (0, 0.5);
77  track_name_label.set_name ("RegionLayeringOrderEditorNameLabel");
78  track_name_label.set_alignment (0, 0.5);
80 
81  Gtk::Table* info_table = manage (new Gtk::Table (2, 2));
82  info_table->set_col_spacings (5);
83  info_table->set_row_spacings (5);
84  info_table->attach (track_label, 0, 1, 0, 1, FILL, FILL);
85  info_table->attach (track_name_label, 1, 2, 0, 1, FILL, FILL);
86  info_table->attach (clock_label, 0, 1, 1, 2, FILL, FILL);
87  info_table->attach (clock, 1, 2, 1, 2, Gtk::AttachOptions(0), FILL);
88 
89  Gtk::VBox* vbox = Gtk::manage (new Gtk::VBox ());
90  vbox->set_spacing (12);
91  vbox->pack_start (*info_table, false, false);
92  vbox->pack_start (*scroller_table, true, true);
93  add (*vbox);
94 
95  info_table->set_name ("RegionLayeringOrderTable");
96  scroller_table->set_name ("RegionLayeringOrderTable");
97 
98  layering_order_display.set_name ("RegionLayeringOrderDisplay");
99  layering_order_display.get_selection()->set_mode (SELECTION_SINGLE);
100  layering_order_display.get_selection()->signal_changed ().connect (mem_fun (*this, &RegionLayeringOrderEditor::row_selected));
101 
102  layering_order_display.grab_focus ();
103 
104  set_title (_("Choose Top Region"));
105  show_all();
106 }
107 
109 {
110 
111 }
112 
113 void
115 {
116  if (in_row_change) {
117  return;
118  }
119 
120  Glib::RefPtr<TreeSelection> selection = layering_order_display.get_selection();
121  TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
122 
123  if (!iter) {
124  return;
125  }
126 
127  TreeModel::Row row = *iter;
129 
130  vector<RegionView*> eq;
131  editor.get_equivalent_regions (rv, eq, Properties::select.property_id);
132 
133  /* XXX this should be reversible, really */
134 
135  for (vector<RegionView*>::iterator i = eq.begin(); i != eq.end(); ++i) {
136  boost::shared_ptr<Playlist> pl = (*i)->region()->playlist();
137  if (pl) {
138  pl->raise_region_to_top ((*i)->region());
139  }
140  }
141 }
142 
144  bool operator() (RegionView* a, RegionView* b) const {
145  return a->region()->layer() > b->region()->layer();
146  }
147 };
148 
149 void
151 {
152  assert (_time_axis_view);
153 
155  in_row_change = true;
156  layering_order_model->clear ();
157 
158  RegionSelection region_list;
159  TrackViewList ts;
160  ts.push_back (_time_axis_view);
161  editor.get_regions_at (region_list, position, ts);
162 
163  regions_at_position = region_list.size ();
164 
165  if (regions_at_position < 2) {
167  hide ();
168  in_row_change = false;
169  return;
170  }
171 
173  region_list.sort (cmp);
174 
175  for (RegionSelection::const_iterator i = region_list.begin(); i != region_list.end(); ++i) {
176  TreeModel::Row newrow = *(layering_order_model->append());
177  newrow[layering_order_columns.name] = (*i)->region()->name();
178  newrow[layering_order_columns.region_view] = *i;
179 
180  if (i == region_list.begin()) {
181  layering_order_display.get_selection()->select(newrow);
182  }
183  }
184 
185  in_row_change = false;
186 }
187 
188 void
190 {
191  track_name_label.set_text (a_name);
192 
193  clock.set_session (s);
194  clock.set (pos, true);
195 
197  pl->ContentsChanged.connect (playlist_modified_connection, invalidator (*this), boost::bind
199 
200  _time_axis_view = tav;
201 
202  position = pos;
203  refill ();
204 }
205 
206 bool
208 {
209  bool handled = false;
210 
211  /* in general, we want shortcuts working while in this
212  dialog. However, we'd like to treat "return" specially
213  since it is used for row activation. So ..
214 
215  for return: try normal handling first
216  then try the editor (to get accelerators/shortcuts)
217  then try normal handling (for keys other than return)
218  */
219 
220  if (ev->keyval == GDK_Return) {
221  handled = ArdourWindow::on_key_press_event (ev);
222  }
223 
224  if (!handled) {
226  }
227 
228  if (!handled) {
229  handled = ArdourWindow::on_key_press_event (ev);
230  }
231 
232  return handled;
233 }
234 
235 void
237 {
238  if (regions_at_position < 2) {
239  hide ();
240  return;
241  }
242 
243  present ();
244 }
245 
246 void
248 {
249  refill ();
250 }
void set(framepos_t, bool force=false, ARDOUR::framecnt_t offset=0)
Definition: audio_clock.cc:956
void set_session(ARDOUR::Session *s)
Definition: ardour_ui.h:130
bool key_press_focus_accelerator_handler(Gtk::Window &window, GdkEventKey *ev)
Definition: utils.cc:410
virtual void get_regions_at(RegionSelection &, framepos_t where, TrackViewList const &) const =0
Representation of the interface of the Editor class.
PBD::Signal0< void > ContentsChanged
Definition: playlist.h:190
Definition: Beats.hpp:239
virtual void get_equivalent_regions(RegionView *rv, std::vector< RegionView * > &, PBD::PropertyID) const =0
PBD::ScopedConnection playlist_modified_connection
void set_context(const std::string &, ARDOUR::Session *, TimeAxisView *, boost::shared_ptr< ARDOUR::Playlist >, ARDOUR::framepos_t)
#define invalidator(x)
Definition: gui_thread.h:40
#define _(Text)
Definition: i18n.h:11
LayeringOrderColumns layering_order_columns
boost::shared_ptr< ARDOUR::Region > region() const
Definition: region_view.h:66
Definition: amp.h:29
#define gui_context()
Definition: gui_thread.h:36
int64_t framepos_t
Definition: types.h:66
layer_t layer() const
Definition: region.h:115
void set_mode(Mode)
void raise_region_to_top(boost::shared_ptr< Region >)
Definition: playlist.cc:2517
Glib::RefPtr< Gtk::ListStore > layering_order_model
bool operator()(RegionView *a, RegionView *b) const
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > position
Definition: region.cc:65
bool on_key_press_event(GdkEventKey *)
LIBARDOUR_API PBD::PropertyDescriptor< bool > select
Definition: route_group.cc:48
virtual bool on_key_press_event(GdkEventKey *event)