2012-01-23 20:31:42 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011-2012 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
#include <gtkmm/table.h>
|
|
|
|
#include <gtkmm/stock.h>
|
|
|
|
#include <gtkmm/alignment.h>
|
2012-12-05 13:29:07 -05:00
|
|
|
|
|
|
|
#include "pbd/stateful_diff_command.h"
|
|
|
|
|
2010-10-04 20:25:57 -04:00
|
|
|
#include "ardour/region.h"
|
2010-08-25 15:37:54 -04:00
|
|
|
|
|
|
|
#include "gui_thread.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "public_editor.h"
|
|
|
|
#include "region_layering_order_editor.h"
|
2012-01-23 20:31:42 -05:00
|
|
|
#include "region_view.h"
|
2010-08-25 15:37:54 -04:00
|
|
|
#include "utils.h"
|
2011-04-22 23:34:42 -04:00
|
|
|
#include "i18n.h"
|
2010-08-25 15:37:54 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
|
|
|
RegionLayeringOrderEditor::RegionLayeringOrderEditor (PublicEditor& pe)
|
2011-12-26 18:38:56 -05:00
|
|
|
: ArdourWindow (_("RegionLayeringOrderEditor"))
|
2012-01-23 20:31:42 -05:00
|
|
|
, position (0)
|
2010-08-25 15:37:54 -04:00
|
|
|
, in_row_change (false)
|
|
|
|
, regions_at_position (0)
|
|
|
|
, layering_order_model (Gtk::ListStore::create (layering_order_columns))
|
2011-12-26 18:18:58 -05:00
|
|
|
, clock ("layer dialog", true, "", false, false, false)
|
2010-08-25 15:37:54 -04:00
|
|
|
, editor (pe)
|
2012-01-23 20:31:42 -05:00
|
|
|
, _time_axis_view (0)
|
2010-08-25 15:37:54 -04:00
|
|
|
{
|
|
|
|
set_name ("RegionLayeringOrderEditorWindow");
|
|
|
|
|
|
|
|
layering_order_display.set_model (layering_order_model);
|
|
|
|
|
|
|
|
layering_order_display.append_column (_("Region Name"), layering_order_columns.name);
|
|
|
|
layering_order_display.set_headers_visible (true);
|
|
|
|
layering_order_display.set_reorderable (false);
|
|
|
|
layering_order_display.set_rules_hint (true);
|
|
|
|
|
|
|
|
scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
|
|
|
scroller.add (layering_order_display);
|
|
|
|
|
|
|
|
clock.set_mode (AudioClock::BBT);
|
|
|
|
|
|
|
|
Gtk::Table* scroller_table = manage (new Gtk::Table);
|
|
|
|
scroller_table->set_size_request (300, 250);
|
|
|
|
scroller_table->attach (scroller, 0, 1, 0, 1);
|
|
|
|
scroller_table->set_col_spacings (5);
|
|
|
|
scroller_table->set_row_spacings (5);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
track_label.set_name ("RegionLayeringOrderEditorLabel");
|
|
|
|
track_label.set_text (_("Track:"));
|
2010-08-25 22:34:45 -04:00
|
|
|
track_label.set_alignment (0, 0.5);
|
2010-08-25 15:37:54 -04:00
|
|
|
clock_label.set_name ("RegionLayeringOrderEditorLabel");
|
|
|
|
clock_label.set_text (_("Position:"));
|
2010-08-25 22:34:45 -04:00
|
|
|
clock_label.set_alignment (0, 0.5);
|
2010-08-25 15:37:54 -04:00
|
|
|
track_name_label.set_name ("RegionLayeringOrderEditorNameLabel");
|
2010-08-25 22:34:45 -04:00
|
|
|
track_name_label.set_alignment (0, 0.5);
|
2010-08-25 15:37:54 -04:00
|
|
|
clock.set_mode (AudioClock::BBT);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
Gtk::Table* info_table = manage (new Gtk::Table (2, 2));
|
|
|
|
info_table->set_col_spacings (5);
|
|
|
|
info_table->set_row_spacings (5);
|
2010-08-25 22:34:45 -04:00
|
|
|
info_table->attach (track_label, 0, 1, 0, 1, FILL, FILL);
|
2010-08-25 15:37:54 -04:00
|
|
|
info_table->attach (track_name_label, 1, 2, 0, 1, FILL, FILL);
|
2010-08-25 22:34:45 -04:00
|
|
|
info_table->attach (clock_label, 0, 1, 1, 2, FILL, FILL);
|
2012-12-05 13:29:07 -05:00
|
|
|
info_table->attach (clock, 1, 2, 1, 2, Gtk::AttachOptions(0), FILL);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
Gtk::VBox* vbox = Gtk::manage (new Gtk::VBox ());
|
|
|
|
vbox->set_spacing (12);
|
|
|
|
vbox->pack_start (*info_table, false, false);
|
|
|
|
vbox->pack_start (*scroller_table, true, true);
|
|
|
|
add (*vbox);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
info_table->set_name ("RegionLayeringOrderTable");
|
|
|
|
scroller_table->set_name ("RegionLayeringOrderTable");
|
|
|
|
|
|
|
|
layering_order_display.set_name ("RegionLayeringOrderDisplay");
|
2012-12-05 13:29:07 -05:00
|
|
|
layering_order_display.get_selection()->set_mode (SELECTION_SINGLE);
|
|
|
|
layering_order_display.get_selection()->signal_changed ().connect (mem_fun (*this, &RegionLayeringOrderEditor::row_selected));
|
2010-08-25 15:37:54 -04:00
|
|
|
|
|
|
|
layering_order_display.grab_focus ();
|
|
|
|
|
|
|
|
set_title (_("Choose Top Region"));
|
|
|
|
show_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
RegionLayeringOrderEditor::~RegionLayeringOrderEditor ()
|
|
|
|
{
|
2012-01-23 20:31:42 -05:00
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-05 13:29:07 -05:00
|
|
|
RegionLayeringOrderEditor::row_selected ()
|
2010-08-25 15:37:54 -04:00
|
|
|
{
|
|
|
|
if (in_row_change) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-05 13:29:07 -05:00
|
|
|
Glib::RefPtr<TreeSelection> selection = layering_order_display.get_selection();
|
|
|
|
TreeModel::iterator iter = selection->get_selected(); // only used with Gtk::SELECTION_SINGLE
|
2010-08-25 15:37:54 -04:00
|
|
|
|
2012-01-23 20:31:42 -05:00
|
|
|
if (!iter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeModel::Row row = *iter;
|
|
|
|
RegionView* rv = row[layering_order_columns.region_view];
|
|
|
|
|
|
|
|
vector<RegionView*> eq;
|
2012-12-26 12:50:29 -05:00
|
|
|
editor.get_equivalent_regions (rv, eq, Properties::select.property_id);
|
2012-12-05 13:29:07 -05:00
|
|
|
|
|
|
|
/* XXX this should be reversible, really */
|
2012-01-23 20:31:42 -05:00
|
|
|
|
|
|
|
for (vector<RegionView*>::iterator i = eq.begin(); i != eq.end(); ++i) {
|
2012-12-05 13:29:07 -05:00
|
|
|
boost::shared_ptr<Playlist> pl = (*i)->region()->playlist();
|
|
|
|
if (pl) {
|
|
|
|
pl->raise_region_to_top ((*i)->region());
|
|
|
|
}
|
2010-08-25 15:37:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-23 20:31:42 -05:00
|
|
|
struct RegionViewCompareByLayer {
|
|
|
|
bool operator() (RegionView* a, RegionView* b) const {
|
|
|
|
return a->region()->layer() > b->region()->layer();
|
|
|
|
}
|
2010-08-25 15:37:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
RegionLayeringOrderEditor::refill ()
|
|
|
|
{
|
2012-01-23 20:31:42 -05:00
|
|
|
assert (_time_axis_view);
|
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
regions_at_position = 0;
|
|
|
|
in_row_change = true;
|
|
|
|
layering_order_model->clear ();
|
|
|
|
|
2012-01-23 20:31:42 -05:00
|
|
|
RegionSelection region_list;
|
|
|
|
TrackViewList ts;
|
|
|
|
ts.push_back (_time_axis_view);
|
|
|
|
editor.get_regions_at (region_list, position, ts);
|
2010-08-25 15:37:54 -04:00
|
|
|
|
2012-01-23 20:31:42 -05:00
|
|
|
regions_at_position = region_list.size ();
|
2010-08-25 15:37:54 -04:00
|
|
|
|
|
|
|
if (regions_at_position < 2) {
|
|
|
|
playlist_modified_connection.disconnect ();
|
|
|
|
hide ();
|
|
|
|
in_row_change = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-23 20:31:42 -05:00
|
|
|
RegionViewCompareByLayer cmp;
|
|
|
|
region_list.sort (cmp);
|
2010-08-25 15:37:54 -04:00
|
|
|
|
2012-01-23 20:31:42 -05:00
|
|
|
for (RegionSelection::const_iterator i = region_list.begin(); i != region_list.end(); ++i) {
|
2010-08-25 15:37:54 -04:00
|
|
|
TreeModel::Row newrow = *(layering_order_model->append());
|
2012-01-23 20:31:42 -05:00
|
|
|
newrow[layering_order_columns.name] = (*i)->region()->name();
|
|
|
|
newrow[layering_order_columns.region_view] = *i;
|
2010-08-25 15:37:54 -04:00
|
|
|
|
2012-01-23 20:31:42 -05:00
|
|
|
if (i == region_list.begin()) {
|
2010-08-25 15:37:54 -04:00
|
|
|
layering_order_display.get_selection()->select(newrow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
in_row_change = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-01-23 20:31:42 -05:00
|
|
|
RegionLayeringOrderEditor::set_context (const string& a_name, Session* s, TimeAxisView* tav, boost::shared_ptr<Playlist> pl, framepos_t pos)
|
2010-08-25 15:37:54 -04:00
|
|
|
{
|
|
|
|
track_name_label.set_text (a_name);
|
|
|
|
|
|
|
|
clock.set_session (s);
|
2011-11-18 13:06:16 -05:00
|
|
|
clock.set (pos, true);
|
2010-08-25 15:37:54 -04:00
|
|
|
|
|
|
|
playlist_modified_connection.disconnect ();
|
2012-01-23 20:31:42 -05:00
|
|
|
pl->ContentsChanged.connect (playlist_modified_connection, invalidator (*this), boost::bind
|
|
|
|
(&RegionLayeringOrderEditor::playlist_modified, this), gui_context());
|
|
|
|
|
|
|
|
_time_axis_view = tav;
|
2010-08-25 15:37:54 -04:00
|
|
|
|
|
|
|
position = pos;
|
|
|
|
refill ();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RegionLayeringOrderEditor::on_key_press_event (GdkEventKey* ev)
|
|
|
|
{
|
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
/* in general, we want shortcuts working while in this
|
|
|
|
dialog. However, we'd like to treat "return" specially
|
|
|
|
since it is used for row activation. So ..
|
|
|
|
|
|
|
|
for return: try normal handling first
|
|
|
|
then try the editor (to get accelerators/shortcuts)
|
|
|
|
then try normal handling (for keys other than return)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ev->keyval == GDK_Return) {
|
2011-11-18 19:56:35 -05:00
|
|
|
handled = ArdourWindow::on_key_press_event (ev);
|
2010-08-25 15:37:54 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
if (!handled) {
|
|
|
|
handled = key_press_focus_accelerator_handler (editor, ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled) {
|
2011-11-18 19:56:35 -05:00
|
|
|
handled = ArdourWindow::on_key_press_event (ev);
|
2010-08-25 15:37:54 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
return handled;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
void
|
|
|
|
RegionLayeringOrderEditor::maybe_present ()
|
|
|
|
{
|
|
|
|
if (regions_at_position < 2) {
|
|
|
|
hide ();
|
|
|
|
return;
|
|
|
|
}
|
2010-08-25 18:42:35 -04:00
|
|
|
|
2010-08-25 15:37:54 -04:00
|
|
|
present ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RegionLayeringOrderEditor::playlist_modified ()
|
|
|
|
{
|
|
|
|
refill ();
|
|
|
|
}
|