1 #include <gtkmm/table.h>
2 #include <gtkmm/stock.h>
3 #include <gtkmm/alignment.h>
4 #include <ardour/region.h>
6 #include "gui_thread.h"
9 #include "public_editor.h"
10 #include "region_layering_order_editor.h"
15 using namespace ARDOUR;
17 RegionLayeringOrderEditor::RegionLayeringOrderEditor (PublicEditor& pe)
18 : ArdourDialog (pe, _("RegionLayeringOrderEditor"), false, false)
21 , in_row_change (false)
22 , regions_at_position (0)
23 , layering_order_columns ()
24 , layering_order_model (Gtk::ListStore::create (layering_order_columns))
25 , layering_order_display ()
26 , clock ("layer dialog", true, "RegionLayeringOrderEditorClock", false, false, false)
30 set_name ("RegionLayeringOrderEditorWindow");
32 layering_order_display.set_model (layering_order_model);
34 layering_order_display.append_column (_("Region Name"), layering_order_columns.name);
35 layering_order_display.set_headers_visible (true);
36 layering_order_display.set_reorderable (false);
37 layering_order_display.set_rules_hint (true);
39 scroller.set_border_width (10);
40 scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
41 scroller.add (layering_order_display);
43 clock.set_mode (AudioClock::BBT);
46 Gtk::Table* scroller_table = manage (new Gtk::Table);
47 scroller_table->set_size_request (300, 250);
48 scroller_table->attach (scroller, 0, 1, 0, 1);
49 scroller_table->set_col_spacings (5);
50 scroller_table->set_row_spacings (5);
51 scroller_table->set_border_width (5);
53 track_label.set_name ("RegionLayeringOrderEditorLabel");
54 track_label.set_text (_("Track:"));
55 clock_label.set_name ("RegionLayeringOrderEditorLabel");
56 clock_label.set_text (_("Position:"));
57 track_name_label.set_name ("RegionLayeringOrderEditorNameLabel");
58 clock.set_mode (AudioClock::BBT);
60 Gtk::Alignment* track_alignment = manage (new Gtk::Alignment);
61 track_alignment->set (1.0, 0.5);
62 track_alignment->add (track_label);
64 Gtk::Alignment* clock_alignment = manage (new Gtk::Alignment);
65 clock_alignment->set (1.0, 0.5);
66 clock_alignment->add (clock_label);
68 Gtk::Table* info_table = manage (new Gtk::Table (2, 2));
69 info_table->set_col_spacings (5);
70 info_table->set_row_spacings (5);
71 info_table->set_border_width (5);
72 info_table->attach (*track_alignment, 0, 1, 0, 1, FILL, FILL);
73 info_table->attach (track_name_label, 1, 2, 0, 1, FILL, FILL);
74 info_table->attach (*clock_alignment, 0, 1, 1, 2, FILL, FILL);
75 info_table->attach (clock, 1, 2, 1, 2, FILL, FILL);
77 HBox* info_hbox = manage (new HBox);
79 info_hbox->pack_start (*info_table, true, false);
81 get_vbox()->set_spacing (5);
82 get_vbox()->pack_start (*info_hbox, false, false);
83 get_vbox()->pack_start (*scroller_table, true, true);
85 info_table->set_name ("RegionLayeringOrderTable");
86 scroller_table->set_name ("RegionLayeringOrderTable");
88 layering_order_display.set_name ("RegionLayeringOrderDisplay");
90 layering_order_display.signal_row_activated ().connect (mem_fun (*this, &RegionLayeringOrderEditor::row_activated));
92 layering_order_display.grab_focus ();
94 set_title (_("Choose Top Region"));
98 RegionLayeringOrderEditor::~RegionLayeringOrderEditor ()
103 RegionLayeringOrderEditor::row_activated (const TreeModel::Path& path, TreeViewColumn* column)
109 TreeModel::iterator iter = layering_order_model->get_iter (path);
112 TreeModel::Row row = *iter;
113 boost::shared_ptr<Region> region = row[layering_order_columns.region];
115 region->raise_to_top ();
119 typedef boost::shared_ptr<Region> RegionPtr;
121 struct RegionCompareByLayer {
122 bool operator() (RegionPtr a, RegionPtr b) const {
123 return a->layer() > b->layer();
128 RegionLayeringOrderEditor::refill ()
130 regions_at_position = 0;
136 typedef Playlist::RegionList RegionList;
138 in_row_change = true;
140 layering_order_model->clear ();
142 boost::shared_ptr<RegionList> region_list(playlist->regions_at (position));
144 regions_at_position = region_list->size();
146 if (regions_at_position < 2) {
147 playlist_modified_connection.disconnect ();
149 in_row_change = false;
153 RegionCompareByLayer cmp;
154 region_list->sort (cmp);
156 for (RegionList::const_iterator i = region_list->begin(); i != region_list->end(); ++i) {
157 TreeModel::Row newrow = *(layering_order_model->append());
158 newrow[layering_order_columns.name] = (*i)->name();
159 newrow[layering_order_columns.region] = *i;
161 if (i == region_list->begin()) {
162 layering_order_display.get_selection()->select(newrow);
166 in_row_change = false;
170 RegionLayeringOrderEditor::set_context (const string& a_name, Session* s, const boost::shared_ptr<Playlist> & pl, framepos_t pos)
172 track_name_label.set_text (a_name);
174 clock.set_session (s);
175 clock.set (pos, true, 0, 0);
177 playlist_modified_connection.disconnect ();
179 playlist->ContentsChanged.connect (playlist_modified_connection, invalidator (*this), boost::bind
180 (&RegionLayeringOrderEditor::playlist_modified, this), gui_context());
187 RegionLayeringOrderEditor::on_key_press_event (GdkEventKey* ev)
189 bool handled = false;
191 /* in general, we want shortcuts working while in this
192 dialog. However, we'd like to treat "return" specially
193 since it is used for row activation. So ..
195 for return: try normal handling first
196 then try the editor (to get accelerators/shortcuts)
197 then try normal handling (for keys other than return)
200 if (ev->keyval == GDK_Return) {
201 handled = ArdourDialog::on_key_press_event (ev);
205 handled = key_press_focus_accelerator_handler (editor, ev);
209 handled = ArdourDialog::on_key_press_event (ev);
216 RegionLayeringOrderEditor::maybe_present ()
218 if (regions_at_position < 2) {
226 RegionLayeringOrderEditor::playlist_modified ()