2009-07-03 18:42:22 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2009-2018 Paul Davis <paul@linuxaudiosystems.com>
|
2022-01-17 20:55:43 -05:00
|
|
|
* Copyright (C) 2013-2021 Robin Gareus <robin@gareus.org>
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2016 Nick Mainsbridge <mainsbridge@gmail.com>
|
|
|
|
* Copyright (C) 2018-2019 Ben Loftis <ben@harrisonconsoles.com>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2009-07-03 18:42:22 -04:00
|
|
|
|
|
|
|
#include <algorithm>
|
2022-01-17 20:55:43 -05:00
|
|
|
#include <list>
|
2019-08-12 18:56:48 -04:00
|
|
|
#include <string>
|
2009-07-03 18:42:22 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
#include "ardour/region.h"
|
2010-03-06 10:40:42 -05:00
|
|
|
#include "ardour/session.h"
|
2010-09-28 13:27:58 -04:00
|
|
|
|
2017-07-16 22:55:52 -04:00
|
|
|
#include "widgets/choice.h"
|
2017-07-15 11:38:28 -04:00
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
#include "ardour_ui.h"
|
|
|
|
#include "editor.h"
|
|
|
|
#include "editor_regions.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "region_view.h"
|
|
|
|
#include "utils.h"
|
2009-07-03 18:42:22 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2009-07-03 18:42:22 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace Gtk;
|
2020-11-16 13:19:22 -05:00
|
|
|
|
2009-12-04 17:51:32 -05:00
|
|
|
using Gtkmm2ext::Keyboard;
|
2009-07-03 18:42:22 -04:00
|
|
|
|
|
|
|
EditorRegions::EditorRegions (Editor* e)
|
2022-01-17 20:55:43 -05:00
|
|
|
: EditorComponent (e)
|
2009-07-03 18:42:22 -04:00
|
|
|
{
|
2022-01-17 20:55:43 -05:00
|
|
|
init ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
_change_connection = _display.get_selection ()->signal_changed ().connect (sigc::mem_fun (*this, &EditorRegions::selection_changed));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
e->EditorFreeze.connect (_editor_freeze_connection, MISSING_INVALIDATOR, boost::bind (&EditorRegions::freeze_tree_model, this), gui_context ());
|
|
|
|
e->EditorThaw.connect (_editor_thaw_connection, MISSING_INVALIDATOR, boost::bind (&EditorRegions::thaw_tree_model, this), gui_context ());
|
2010-09-28 22:01:35 -04:00
|
|
|
}
|
|
|
|
|
2009-07-03 18:42:22 -04:00
|
|
|
void
|
2022-01-17 20:55:43 -05:00
|
|
|
EditorRegions::init ()
|
2009-07-03 18:42:22 -04:00
|
|
|
{
|
2022-01-17 20:55:43 -05:00
|
|
|
add_name_column ();
|
2022-01-26 16:19:32 -05:00
|
|
|
setup_col (append_col (_columns.channels, "Chans "), 1, ALIGN_START, _("# Ch"), _("# Channels in the region"));
|
2022-01-17 20:55:43 -05:00
|
|
|
add_tag_column ();
|
2011-02-14 16:49:43 -05:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
int cb_width = 24;
|
|
|
|
int bbt_width, height;
|
2011-02-14 16:49:43 -05:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
Glib::RefPtr<Pango::Layout> layout = _display.create_pango_layout (X_("000|000|000"));
|
2022-09-19 21:21:35 -04:00
|
|
|
layout->get_pixel_size (bbt_width, height);
|
2011-02-14 16:49:43 -05:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
TreeViewColumn* tvc;
|
2011-02-14 16:49:43 -05:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
tvc = append_col (_columns.start, bbt_width);
|
2022-01-26 16:20:26 -05:00
|
|
|
setup_col (tvc, 16, ALIGN_END, _("Start"), _("Position of start of region"));
|
2022-01-17 20:55:43 -05:00
|
|
|
tvc = append_col (_columns.length, bbt_width);
|
2022-01-26 16:20:26 -05:00
|
|
|
setup_col (tvc, 4, ALIGN_END, _("Length"), _("Length of the region"));
|
2011-02-14 16:49:43 -05:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
tvc = append_col (_columns.locked, cb_width);
|
|
|
|
setup_col (tvc, -1, ALIGN_CENTER, S_("Lock|L"), _("Region position locked?"));
|
|
|
|
setup_toggle (tvc, sigc::mem_fun (*this, &EditorRegions::locked_changed));
|
2021-05-07 16:45:28 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
tvc = append_col (_columns.muted, cb_width);
|
|
|
|
setup_col (tvc, -1, ALIGN_CENTER, S_("Mute|M"), _("Region muted?"));
|
|
|
|
setup_toggle (tvc, sigc::mem_fun (*this, &EditorRegions::muted_changed));
|
2009-07-03 18:42:22 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
tvc = append_col (_columns.opaque, cb_width);
|
|
|
|
setup_col (tvc, -1, ALIGN_CENTER, S_("Opaque|O"), _("Region opaque (blocks regions below it from being heard)?"));
|
|
|
|
setup_toggle (tvc, sigc::mem_fun (*this, &EditorRegions::opaque_changed));
|
2010-11-25 15:37:39 -05:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
#ifdef SHOW_REGION_EXTRAS
|
|
|
|
tvc = append_col (_columns.end, bbt_width);
|
2022-01-26 16:20:26 -05:00
|
|
|
setup_col (tvc, 5, ALIGN_END, _("End"), _("Position of end of region"));
|
2022-01-17 20:55:43 -05:00
|
|
|
tvc = append_col (_columns.sync, bbt_width);
|
2022-01-26 16:20:26 -05:00
|
|
|
setup_col (tvc, -1, ALIGN_END, _("Sync"), _("Position of region sync point, relative to start of the region"));
|
2022-01-17 20:55:43 -05:00
|
|
|
tvc = append_col (_columns.fadein, bbt_width);
|
2022-01-26 16:20:26 -05:00
|
|
|
setup_col (tvc, -1, ALIGN_END, _("Fade In"), _("Length of region fade-in (unit: secondary clock, enclosed in parenthesis if the fade is disabled)"));
|
2022-01-17 20:55:43 -05:00
|
|
|
tvc = append_col (_columns.fadeout, bbt_width);
|
2022-01-26 16:20:26 -05:00
|
|
|
setup_col (tvc, -1, ALIGN_END, _("Fade out"), _("Length of region fade-out (unit: secondary clock, enclosed in parenthesis if the fade is disabled)"));
|
2022-01-17 20:55:43 -05:00
|
|
|
#endif
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-14 12:10:01 -04:00
|
|
|
EditorRegions::selection_changed ()
|
2009-07-03 18:42:22 -04:00
|
|
|
{
|
2010-09-28 13:27:58 -04:00
|
|
|
_editor->_region_selection_change_updates_region_list = false;
|
2010-09-18 19:31:39 -04:00
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
if (_display.get_selection ()->count_selected_rows () > 0) {
|
|
|
|
TreeIter iter;
|
|
|
|
TreeView::Selection::ListHandle_Path rows = _display.get_selection ()->get_selected_rows ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
_editor->get_selection ().clear_regions ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin (); i != rows.end (); ++i) {
|
2012-05-23 22:54:10 -04:00
|
|
|
if ((iter = _model->get_iter (*i))) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Region> region = (*iter)[_columns.region];
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-11-25 15:37:39 -05:00
|
|
|
// they could have clicked on a row that is just a placeholder, like "Hidden"
|
|
|
|
// although that is not allowed by our selection filter. check it anyway
|
|
|
|
// since we need a region ptr.
|
2010-09-28 13:27:58 -04:00
|
|
|
|
2009-07-03 18:42:22 -04:00
|
|
|
if (region) {
|
2013-01-04 17:46:51 -05:00
|
|
|
_change_connection.block (true);
|
|
|
|
_editor->set_selected_regionview_from_region_list (region, Selection::Add);
|
|
|
|
_change_connection.block (false);
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-08-12 18:56:48 -04:00
|
|
|
_editor->get_selection ().clear_regions ();
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
2010-09-18 19:31:39 -04:00
|
|
|
|
2010-09-28 13:27:58 -04:00
|
|
|
_editor->_region_selection_change_updates_region_list = true;
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EditorRegions::set_selected (RegionSelection& regions)
|
|
|
|
{
|
2019-08-12 18:56:48 -04:00
|
|
|
for (RegionSelection::iterator i = regions.begin (); i != regions.end (); ++i) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Region> r ((*i)->region ());
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-14 16:49:43 -05:00
|
|
|
RegionRowMap::iterator it;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-14 16:49:43 -05:00
|
|
|
it = region_row_map.find (r);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
if (it != region_row_map.end ()) {
|
2018-10-15 16:04:53 -04:00
|
|
|
TreeModel::iterator j = it->second;
|
2019-08-12 18:56:48 -04:00
|
|
|
_display.get_selection ()->select (*j);
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EditorRegions::show_context_menu (int button, int time)
|
|
|
|
{
|
2018-10-22 17:46:44 -04:00
|
|
|
using namespace Gtk::Menu_Helpers;
|
2022-01-17 20:55:43 -05:00
|
|
|
Gtk::Menu* menu = dynamic_cast<Menu*> (ActionManager::get_widget (X_("/PopupRegionMenu")));
|
2018-10-22 17:46:44 -04:00
|
|
|
menu->popup (button, time);
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-08-12 18:56:48 -04:00
|
|
|
EditorRegions::button_press (GdkEventButton* ev)
|
2009-07-03 18:42:22 -04:00
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Region> region;
|
2019-08-12 18:56:48 -04:00
|
|
|
TreeIter iter;
|
|
|
|
TreeModel::Path path;
|
|
|
|
TreeViewColumn* column;
|
|
|
|
int cellx;
|
|
|
|
int celly;
|
2009-07-03 18:42:22 -04:00
|
|
|
|
|
|
|
if (_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
|
|
|
|
if ((iter = _model->get_iter (path))) {
|
|
|
|
region = (*iter)[_columns.region];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Keyboard::is_context_menu_event (ev)) {
|
|
|
|
show_context_menu (ev->button, ev->time);
|
2019-08-11 20:07:03 -04:00
|
|
|
return true;
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (region != 0 && Keyboard::is_button2_event (ev)) {
|
2019-08-12 18:56:48 -04:00
|
|
|
/* start/stop audition */
|
2009-07-03 18:42:22 -04:00
|
|
|
if (!Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
|
|
|
_editor->consider_auditioning (region);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-03 18:42:22 -04:00
|
|
|
return false;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2009-07-03 18:42:22 -04:00
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
EditorRegions::selection_mapover (sigc::slot<void, std::shared_ptr<Region>> sl)
|
2009-07-03 18:42:22 -04:00
|
|
|
{
|
2019-08-12 18:56:48 -04:00
|
|
|
Glib::RefPtr<TreeSelection> selection = _display.get_selection ();
|
|
|
|
TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
|
|
|
|
TreeView::Selection::ListHandle_Path::iterator i = rows.begin ();
|
2009-07-03 18:42:22 -04:00
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
if (selection->count_selected_rows () == 0 || _session == 0) {
|
2009-07-03 18:42:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
for (; i != rows.end (); ++i) {
|
2009-07-03 18:42:22 -04:00
|
|
|
TreeIter iter;
|
|
|
|
|
|
|
|
if ((iter = _model->get_iter (*i))) {
|
|
|
|
/* some rows don't have a region associated with them, but can still be
|
|
|
|
selected (XXX maybe prevent them from being selected)
|
|
|
|
*/
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Region> r = (*iter)[_columns.region];
|
2009-07-03 18:42:22 -04:00
|
|
|
|
|
|
|
if (r) {
|
|
|
|
sl (r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
EditorRegions::regions_changed (std::shared_ptr<RegionList> rl, const PropertyChange& what_changed)
|
2009-07-03 18:42:22 -04:00
|
|
|
{
|
2022-01-17 20:55:43 -05:00
|
|
|
/* the grid is most interested in the regions that are *visible* in the editor.
|
|
|
|
* this is a convenient place to flag changes to the grid cache, on a visible region */
|
|
|
|
PropertyChange grid_interests;
|
|
|
|
grid_interests.add (ARDOUR::Properties::length);
|
|
|
|
grid_interests.add (ARDOUR::Properties::sync_position);
|
2018-11-15 10:27:04 -05:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
if (what_changed.contains (grid_interests)) {
|
|
|
|
_editor->mark_region_boundary_cache_dirty ();
|
2018-11-15 10:27:04 -05:00
|
|
|
}
|
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
RegionListBase::regions_changed (rl, what_changed);
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Region>
|
2009-07-03 18:42:22 -04:00
|
|
|
EditorRegions::get_single_selection ()
|
|
|
|
{
|
2019-08-12 18:56:48 -04:00
|
|
|
Glib::RefPtr<TreeSelection> selected = _display.get_selection ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
if (selected->count_selected_rows () != 1) {
|
2023-02-16 18:33:28 -05:00
|
|
|
return std::shared_ptr<Region> ();
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-03 18:42:22 -04:00
|
|
|
TreeView::Selection::ListHandle_Path rows = selected->get_selected_rows ();
|
|
|
|
|
|
|
|
/* only one row selected, so rows.begin() is it */
|
|
|
|
|
2019-08-12 18:56:48 -04:00
|
|
|
TreeIter iter = _model->get_iter (*rows.begin ());
|
2009-07-03 18:42:22 -04:00
|
|
|
|
|
|
|
if (!iter) {
|
2023-02-16 18:33:28 -05:00
|
|
|
return std::shared_ptr<Region> ();
|
2009-07-03 18:42:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (*iter)[_columns.region];
|
|
|
|
}
|
2010-06-27 20:41:01 -04:00
|
|
|
|
2016-04-08 13:21:13 -04:00
|
|
|
void
|
2022-01-17 20:55:43 -05:00
|
|
|
EditorRegions::remove_unused_regions ()
|
2010-06-27 20:41:01 -04:00
|
|
|
{
|
2022-01-17 20:55:43 -05:00
|
|
|
vector<string> choices;
|
|
|
|
string prompt;
|
2010-06-27 20:41:01 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
if (!_session) {
|
|
|
|
return;
|
2010-06-27 20:41:01 -04:00
|
|
|
}
|
2010-09-18 22:18:59 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
prompt = _("Do you really want to remove unused regions?"
|
|
|
|
"\n(This is destructive and cannot be undone)");
|
2010-09-18 22:18:59 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
choices.push_back (_("No, do nothing."));
|
|
|
|
choices.push_back (_("Yes, remove."));
|
2011-02-14 16:49:43 -05:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
ArdourWidgets::Choice prompter (_("Remove unused regions"), prompt, choices);
|
2010-09-20 15:18:17 -04:00
|
|
|
|
2022-01-17 20:55:43 -05:00
|
|
|
if (prompter.run () == 1) {
|
|
|
|
_no_redisplay = true;
|
|
|
|
_session->cleanup_regions ();
|
|
|
|
_no_redisplay = false;
|
2010-11-25 15:37:39 -05:00
|
|
|
redisplay ();
|
|
|
|
}
|
2010-09-18 22:18:59 -04:00
|
|
|
}
|