Separate RegionList into a case-class for reusing in on the TriggerPage

This commit is contained in:
Robin Gareus 2022-01-18 02:55:43 +01:00
parent 9886d6c19e
commit 5427cec821
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
6 changed files with 1153 additions and 1193 deletions

View File

@ -2581,7 +2581,6 @@ Editor::set_state (const XMLNode& node, int version)
XMLNodeList children = node.children ();
for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
selection->set_state (**i, Stateful::current_state_version);
_regions->set_state (**i);
_locations->set_state (**i);
}
@ -2683,7 +2682,6 @@ Editor::get_state ()
node->set_property (X_("show-touched-automation"), _show_touched_automation);
node->add_child_nocopy (selection->get_state ());
node->add_child_nocopy (_regions->get_state ());
node->set_property ("nudge-clock-value", nudge_clock->current_duration());
@ -6215,7 +6213,6 @@ Editor::session_going_away ()
/* rip everything out of the list displays */
_regions->clear ();
_sources->clear ();
_routes->clear ();
_route_groups->clear ();

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
* Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
* Copyright (C) 2009-2018 Paul Davis <paul@linuxaudiosystems.com>
* Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
* Copyright (C) 2021 Robin Gareus <robin@gareus.org>
*
* 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
@ -21,188 +22,35 @@
#ifndef __gtk_ardour_editor_regions_h__
#define __gtk_ardour_editor_regions_h__
#include <boost/unordered_map.hpp>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treerowreference.h>
#include <gtkmm/treestore.h>
#include "editor_component.h"
#include "region_list_base.h"
#include "region_selection.h"
class EditorRegions : public EditorComponent, public ARDOUR::SessionHandlePtr
class EditorRegions : public EditorComponent, public RegionListBase
{
public:
EditorRegions (Editor *);
EditorRegions (Editor*);
void set_session (ARDOUR::Session *);
Gtk::Widget& widget () {
return _scroller;
}
void clear ();
void set_selected (RegionSelection &);
void selection_mapover (sigc::slot<void,boost::shared_ptr<ARDOUR::Region> >);
void set_selected (RegionSelection&);
void selection_mapover (sigc::slot<void, boost::shared_ptr<ARDOUR::Region>>);
void remove_unused_regions ();
boost::shared_ptr<ARDOUR::Region> get_dragged_region ();
boost::shared_ptr<ARDOUR::Region> get_single_selection ();
void redisplay ();
void suspend_redisplay () {
_no_redisplay = true;
void unselect_all ()
{
_display.get_selection ()->unselect_all ();
}
void resume_redisplay () {
_no_redisplay = false;
redisplay ();
}
void block_change_connection (bool b) {
_change_connection.block (b);
}
void unselect_all () {
_display.get_selection()->unselect_all ();
}
void remove_unused_regions ();
XMLNode& get_state () const;
void set_state (const XMLNode &);
protected:
void regions_changed (boost::shared_ptr<ARDOUR::RegionList>, PBD::PropertyChange const&);
private:
struct Columns : public Gtk::TreeModel::ColumnRecord {
Columns () {
add (name);
add (channels);
add (tags);
add (start);
add (length);
add (end);
add (sync);
add (fadein);
add (fadeout);
add (locked);
add (glued);
add (muted);
add (opaque);
add (path);
add (region);
add (color_);
add (position);
}
Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<int> channels;
Gtk::TreeModelColumn<std::string> tags;
Gtk::TreeModelColumn<Temporal::timepos_t> position;
Gtk::TreeModelColumn<std::string> start;
Gtk::TreeModelColumn<std::string> end;
Gtk::TreeModelColumn<std::string> length;
Gtk::TreeModelColumn<std::string> sync;
Gtk::TreeModelColumn<std::string> fadein;
Gtk::TreeModelColumn<std::string> fadeout;
Gtk::TreeModelColumn<bool> locked;
Gtk::TreeModelColumn<bool> glued;
Gtk::TreeModelColumn<bool> muted;
Gtk::TreeModelColumn<bool> opaque;
Gtk::TreeModelColumn<std::string> path;
Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
Gtk::TreeModelColumn<Gdk::Color> color_;
};
Columns _columns;
Gtk::TreeModel::RowReference last_row;
void freeze_tree_model ();
void thaw_tree_model ();
void regions_changed (boost::shared_ptr<ARDOUR::RegionList>, PBD::PropertyChange const &);
void init ();
void selection_changed ();
sigc::connection _change_connection;
int _sort_col_id;
Gtk::SortType _sort_type;
bool selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
Gtk::Widget* old_focus;
Gtk::CellEditable* name_editable;
void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
void name_edit (const std::string&, const std::string&);
Gtk::CellEditable* tags_editable;
void tag_editing_started (Gtk::CellEditable*, const Glib::ustring&);
void tag_edit (const std::string&, const std::string&);
void locked_changed (std::string const &);
void glued_changed (std::string const &);
void muted_changed (std::string const &);
void opaque_changed (std::string const &);
bool key_press (GdkEventKey *);
bool button_press (GdkEventButton *);
bool focus_in (GdkEventFocus*);
bool focus_out (GdkEventFocus*);
bool enter_notify (GdkEventCrossing*);
bool leave_notify (GdkEventCrossing*);
bool button_press (GdkEventButton*);
void show_context_menu (int button, int time);
void format_position (Temporal::timepos_t const & pos, char* buf, size_t bufsize, bool onoff = true);
void add_region (boost::shared_ptr<ARDOUR::Region>);
void destroy_region (boost::shared_ptr<ARDOUR::Region>);
void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, PBD::PropertyChange const &);
void populate_row_used (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_position (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_end (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_sync (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_fade_in (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
void populate_row_fade_out (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
void populate_row_locked (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_muted (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_glued (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_opaque (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_length (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void update_row (boost::shared_ptr<ARDOUR::Region>);
void clock_format_changed ();
Glib::RefPtr<Gtk::Action> remove_unused_regions_action () const;
Gtk::Menu* _menu;
Gtk::ScrolledWindow _scroller;
Gtk::Frame _frame;
Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
Glib::RefPtr<Gtk::TreeStore> _model;
bool _no_redisplay;
typedef boost::unordered_map<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> RegionRowMap;
RegionRowMap region_row_map;
PBD::ScopedConnection region_property_connection;
PBD::ScopedConnection check_new_region_connection;
PBD::ScopedConnection editor_freeze_connection;
PBD::ScopedConnection editor_thaw_connection;
};
#endif /* __gtk_ardour_editor_regions_h__ */

View File

@ -0,0 +1,821 @@
/*
* 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>
* Copyright (C) 2013-2021 Robin Gareus <robin@gareus.org>
* 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.
*/
#include <algorithm>
#include <string>
#include "ardour/audiofilesource.h"
#include "ardour/audioregion.h"
#include "ardour/region_factory.h"
#include "ardour/session.h"
#include "ardour/session_playlist.h"
#include "ardour/silentfilesource.h"
#include "gtkmm2ext/treeutils.h"
#include "gtkmm2ext/utils.h"
#include "widgets/tooltips.h"
#include "actions.h"
#include "ardour_ui.h"
#include "audio_clock.h"
#include "gui_thread.h"
#include "keyboard.h"
#include "main_clock.h"
#include "region_list_base.h"
#include "ui_config.h"
#include "utils.h"
#include "pbd/i18n.h"
using namespace std;
using namespace ARDOUR;
using namespace ARDOUR_UI_UTILS;
using namespace PBD;
using namespace Gtk;
using namespace Temporal;
using Gtkmm2ext::Keyboard;
RegionListBase::RegionListBase ()
: _name_editable (0)
, _tags_editable (0)
, _old_focus (0)
, _no_redisplay (false)
{
_display.set_size_request (100, -1);
_display.set_rules_hint (true);
_display.set_name ("RegionList");
_display.set_fixed_height_mode (true);
_display.set_reorderable (false);
/* Try to prevent single mouse presses from initiating edits.
* This relies on a hack in gtktreeview.c:gtk_treeview_button_press() */
_display.set_data ("mouse-edits-require-mod1", (gpointer)0x1);
_model = TreeStore::create (_columns);
_model->set_sort_column (0, SORT_ASCENDING);
_display.set_model (_model);
_display.set_headers_visible (true);
_display.set_rules_hint ();
if (UIConfiguration::instance ().get_use_tooltips ()) {
/* show path as the row tooltip */
_display.set_tooltip_column (13); /* path */
}
_display.get_selection ()->set_mode (SELECTION_MULTIPLE);
_scroller.add (_display);
_scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
_display.signal_button_press_event ().connect (sigc::mem_fun (*this, &RegionListBase::button_press), false);
_display.signal_enter_notify_event ().connect (sigc::mem_fun (*this, &RegionListBase::enter_notify), false);
_display.signal_leave_notify_event ().connect (sigc::mem_fun (*this, &RegionListBase::leave_notify), false);
_scroller.signal_focus_in_event ().connect (sigc::mem_fun (*this, &RegionListBase::focus_in), false);
_scroller.signal_focus_out_event ().connect (sigc::mem_fun (*this, &RegionListBase::focus_out));
_scroller.signal_key_press_event ().connect (sigc::mem_fun (*this, &RegionListBase::key_press), false);
ARDOUR_UI::instance ()->primary_clock->mode_changed.connect (sigc::mem_fun (*this, &RegionListBase::clock_format_changed));
}
void
RegionListBase::setup_col (TreeViewColumn* col, int sort_idx, Gtk::AlignmentEnum al, const char* label, const char* tooltip)
{
/* add the label */
Gtk::Label* l = manage (new Label (label));
l->set_alignment (al);
ArdourWidgets::set_tooltip (*l, tooltip);
col->set_widget (*l);
l->show ();
col->set_sort_column (sort_idx);
col->set_expand (false);
/* this sets the alignment of the column header... */
col->set_alignment (al);
/* ...and this sets the alignment for the data cells */
CellRendererText* renderer = dynamic_cast<CellRendererText*> (col->get_first_cell_renderer ());
if (renderer) {
renderer->property_xalign () = (al == ALIGN_RIGHT ? 1.0 : (al == ALIGN_LEFT ? 0.0 : 0.5));
}
}
void
RegionListBase::setup_toggle (Gtk::TreeViewColumn* tvc, sigc::slot<void, std::string> cb)
{
CellRendererToggle* tc = dynamic_cast<CellRendererToggle*> (tvc->get_first_cell_renderer ());
tc->property_activatable () = true;
tc->signal_toggled ().connect (cb);
}
void
RegionListBase::add_name_column ()
{
TreeViewColumn* tvc = append_col (_columns.name, 120);
setup_col (tvc, 0, ALIGN_LEFT, _("Name"), ("Region name"));
/* Region Name: make editable */
CellRendererText* region_name_cell = dynamic_cast<CellRendererText*> (tvc->get_first_cell_renderer ());
region_name_cell->property_editable () = true;
region_name_cell->signal_edited ().connect (sigc::mem_fun (*this, &RegionListBase::name_edit));
region_name_cell->signal_editing_started ().connect (sigc::mem_fun (*this, &RegionListBase::name_editing_started));
/* Region Name: color turns red if source is missing. */
tvc->add_attribute (region_name_cell->property_text (), _columns.name);
tvc->add_attribute (region_name_cell->property_foreground_gdk (), _columns.color_);
tvc->set_expand (true);
}
void
RegionListBase::add_tag_column ()
{
TreeViewColumn* tvc = append_col (_columns.tags, "2099-10-10 10:10:30");
setup_col (tvc, 2, ALIGN_LEFT, _("Tags"), _("Tags"));
/* Tags cell: make editable */
CellRendererText* region_tags_cell = dynamic_cast<CellRendererText*> (tvc->get_first_cell_renderer ());
region_tags_cell->property_editable () = true;
region_tags_cell->signal_edited ().connect (sigc::mem_fun (*this, &RegionListBase::tag_edit));
region_tags_cell->signal_editing_started ().connect (sigc::mem_fun (*this, &RegionListBase::tag_editing_started));
}
bool
RegionListBase::focus_in (GdkEventFocus*)
{
Window* win = dynamic_cast<Window*> (_scroller.get_toplevel ());
if (win) {
_old_focus = win->get_focus ();
} else {
_old_focus = 0;
}
_tags_editable = 0;
_name_editable = 0;
/* try to do nothing on focus in (doesn't work, hence selection_count nonsense) */
return true;
}
bool
RegionListBase::focus_out (GdkEventFocus*)
{
if (_old_focus) {
_old_focus->grab_focus ();
_old_focus = 0;
}
_tags_editable = 0;
_name_editable = 0;
return false;
}
bool
RegionListBase::enter_notify (GdkEventCrossing*)
{
if (_name_editable || _tags_editable) {
return true;
}
Keyboard::magic_widget_grab_focus ();
return false;
}
bool
RegionListBase::leave_notify (GdkEventCrossing*)
{
if (_old_focus) {
_old_focus->grab_focus ();
_old_focus = 0;
}
Keyboard::magic_widget_drop_focus ();
return false;
}
void
RegionListBase::set_session (ARDOUR::Session* s)
{
SessionHandlePtr::set_session (s);
if (!s) {
clear ();
return;
}
ARDOUR::Region::RegionsPropertyChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&RegionListBase::regions_changed, this, _1, _2), gui_context ());
ARDOUR::RegionFactory::CheckNewRegion.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&RegionListBase::add_region, this, _1), gui_context ());
redisplay ();
}
void
RegionListBase::add_region (boost::shared_ptr<Region> region)
{
if (!region || !_session) {
return;
}
/* whole-file regions are shown in the Source List */
if (region->whole_file ()) {
return;
}
/* we only show files-on-disk.
* if there's some other kind of region, we ignore it (for now)
*/
boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (region->source ());
if (!fs || fs->empty ()) {
return;
}
PropertyChange pc;
boost::shared_ptr<RegionList> rl (new RegionList);
rl->push_back (region);
regions_changed (rl, pc);
}
void
RegionListBase::regions_changed (boost::shared_ptr<RegionList> rl, const PropertyChange& what_changed)
{
bool freeze = rl->size () > 2;
if (freeze) {
freeze_tree_model ();
}
for (RegionList::const_iterator i = rl->begin (); i != rl->end (); ++i) {
boost::shared_ptr<Region> r = *i;
RegionRowMap::iterator map_it = region_row_map.find (r);
boost::shared_ptr<ARDOUR::Playlist> pl = r->playlist ();
if (!(pl && _session && _session->playlist_is_active (pl))) {
/* this region is not on an active playlist
* maybe it got deleted, or whatever */
if (map_it != region_row_map.end ()) {
Gtk::TreeModel::iterator r = map_it->second;
region_row_map.erase (map_it);
_model->erase (r);
}
break;
}
if (map_it != region_row_map.end ()) {
/* found the region, update its row properties */
TreeModel::Row row = *(map_it->second);
populate_row (r, row, what_changed);
} else {
/* new region, add it to the list */
TreeModel::iterator iter = _model->append ();
TreeModel::Row row = *iter;
region_row_map.insert (pair<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> (r, iter));
/* set the properties that don't change */
row[_columns.region] = r;
/* now populate the properties that might change... */
populate_row (r, row, PropertyChange ());
}
}
if (freeze) {
thaw_tree_model ();
}
}
void
RegionListBase::redisplay ()
{
if (_no_redisplay || !_session) {
return;
}
/* store sort column id and type for later */
_model->get_sort_column_id (_sort_col_id, _sort_type);
_display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
_model->clear ();
/* Disable sorting to gain performance */
_model->set_sort_column (-2, SORT_ASCENDING);
region_row_map.clear ();
RegionFactory::foreach_region (sigc::mem_fun (*this, &RegionListBase::add_region));
/* re-enabale sorting */
_model->set_sort_column (_sort_col_id, _sort_type);
_display.set_model (_model);
}
void
RegionListBase::clock_format_changed ()
{
if (!_session) {
return;
}
PropertyChange change;
change.add (ARDOUR::Properties::start);
change.add (ARDOUR::Properties::length);
change.add (ARDOUR::Properties::sync_position);
change.add (ARDOUR::Properties::fade_in);
change.add (ARDOUR::Properties::fade_out);
TreeModel::Children rows = _model->children ();
for (TreeModel::iterator i = rows.begin (); i != rows.end (); ++i) {
boost::shared_ptr<ARDOUR::Region> r = (*i)[_columns.region];
populate_row (r, *i, change);
}
}
void
RegionListBase::format_position (timepos_t const& p, char* buf, size_t bufsize, bool onoff)
{
Temporal::BBT_Time bbt;
Timecode::Time timecode;
samplepos_t pos (p.samples ());
if (pos < 0) {
error << string_compose (_("RegionListBase::format_position: negative timecode position: %1"), pos) << endmsg;
snprintf (buf, bufsize, "invalid");
return;
}
switch (ARDOUR_UI::instance ()->primary_clock->mode ()) {
case AudioClock::BBT:
bbt = Temporal::TempoMap::use ()->bbt_at (p);
if (onoff) {
snprintf (buf, bufsize, "%03d|%02d|%04d", bbt.bars, bbt.beats, bbt.ticks);
} else {
snprintf (buf, bufsize, "(%03d|%02d|%04d)", bbt.bars, bbt.beats, bbt.ticks);
}
break;
case AudioClock::MinSec:
samplepos_t left;
int hrs;
int mins;
float secs;
left = pos;
hrs = (int)floor (left / (_session->sample_rate () * 60.0f * 60.0f));
left -= (samplecnt_t)floor (hrs * _session->sample_rate () * 60.0f * 60.0f);
mins = (int)floor (left / (_session->sample_rate () * 60.0f));
left -= (samplecnt_t)floor (mins * _session->sample_rate () * 60.0f);
secs = left / (float)_session->sample_rate ();
if (onoff) {
snprintf (buf, bufsize, "%02d:%02d:%06.3f", hrs, mins, secs);
} else {
snprintf (buf, bufsize, "(%02d:%02d:%06.3f)", hrs, mins, secs);
}
break;
case AudioClock::Seconds:
if (onoff) {
snprintf (buf, bufsize, "%.1f", pos / (float)_session->sample_rate ());
} else {
snprintf (buf, bufsize, "(%.1f)", pos / (float)_session->sample_rate ());
}
break;
case AudioClock::Samples:
if (onoff) {
snprintf (buf, bufsize, "%" PRId64, pos);
} else {
snprintf (buf, bufsize, "(%" PRId64 ")", pos);
}
break;
case AudioClock::Timecode:
default:
_session->timecode_time (pos, timecode);
if (onoff) {
snprintf (buf, bufsize, "%02d:%02d:%02d:%02d", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
} else {
snprintf (buf, bufsize, "(%02d:%02d:%02d:%02d)", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
}
break;
}
}
void
RegionListBase::populate_row (boost::shared_ptr<Region> region, TreeModel::Row const& row, PBD::PropertyChange const& what_changed)
{
assert (region);
{
Gdk::Color c;
bool missing_source = boost::dynamic_pointer_cast<SilentFileSource> (region->source ()) != NULL;
if (missing_source) {
set_color_from_rgba (c, UIConfiguration::instance ().color ("region list missing source"));
} else {
set_color_from_rgba (c, UIConfiguration::instance ().color ("region list whole file"));
}
row[_columns.color_] = c;
}
boost::shared_ptr<AudioRegion> audioregion = boost::dynamic_pointer_cast<AudioRegion> (region);
PropertyChange c;
const bool all = what_changed == c;
if (all || what_changed.contains (Properties::length)) {
populate_row_position (region, row);
}
if (all || what_changed.contains (Properties::start) || what_changed.contains (Properties::sync_position)) {
populate_row_sync (region, row);
}
if (all || what_changed.contains (Properties::fade_in)) {
populate_row_fade_in (region, row, audioregion);
}
if (all || what_changed.contains (Properties::fade_out)) {
populate_row_fade_out (region, row, audioregion);
}
if (all || what_changed.contains (Properties::locked)) {
populate_row_locked (region, row);
}
if (all || what_changed.contains (Properties::time_domain)) {
populate_row_glued (region, row);
}
if (all || what_changed.contains (Properties::muted)) {
populate_row_muted (region, row);
}
if (all || what_changed.contains (Properties::opaque)) {
populate_row_opaque (region, row);
}
if (all || what_changed.contains (Properties::length)) {
populate_row_end (region, row);
populate_row_length (region, row);
}
if (all) {
populate_row_source (region, row);
}
if (all || what_changed.contains (Properties::name) || what_changed.contains (Properties::tags)) {
populate_row_name (region, row);
}
}
void
RegionListBase::populate_row_length (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
char buf[16];
if (ARDOUR_UI::instance ()->primary_clock->mode () == AudioClock::BBT) {
TempoMap::SharedPtr map (TempoMap::use ());
Temporal::BBT_Time bbt; /* uninitialized until full duration works */
// Temporal::BBT_Time bbt = map->bbt_duration_at (region->position(), region->length());
snprintf (buf, sizeof (buf), "%03d|%02d|%04d", bbt.bars, bbt.beats, bbt.ticks);
} else {
format_position (timepos_t (region->length ()), buf, sizeof (buf));
}
row[_columns.length] = buf;
}
void
RegionListBase::populate_row_end (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
#ifndef SHOW_REGION_EXTRAS
return;
#endif
if (region->last_sample () >= region->first_sample ()) {
char buf[16];
format_position (region->nt_last (), buf, sizeof (buf));
row[_columns.end] = buf;
} else {
row[_columns.end] = "empty";
}
}
void
RegionListBase::populate_row_position (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
row[_columns.position] = region->position ();
char buf[16];
format_position (region->position (), buf, sizeof (buf));
row[_columns.start] = buf;
}
void
RegionListBase::populate_row_sync (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
#ifndef SHOW_REGION_EXTRAS
return;
#endif
if (region->sync_position () == region->position ()) {
row[_columns.sync] = _("Start");
} else if (region->sync_position () == (region->last_sample ())) {
row[_columns.sync] = _("End");
} else {
char buf[16];
format_position (region->sync_position (), buf, sizeof (buf));
row[_columns.sync] = buf;
}
}
void
RegionListBase::populate_row_fade_in (boost::shared_ptr<Region> region, TreeModel::Row const& row, boost::shared_ptr<AudioRegion> audioregion)
{
#ifndef SHOW_REGION_EXTRAS
return;
#endif
if (!audioregion) {
row[_columns.fadein] = "";
} else {
char buf[32];
format_position (audioregion->fade_in ()->back ()->when, buf, sizeof (buf), audioregion->fade_in_active ());
row[_columns.fadein] = buf;
}
}
void
RegionListBase::populate_row_fade_out (boost::shared_ptr<Region> region, TreeModel::Row const& row, boost::shared_ptr<AudioRegion> audioregion)
{
#ifndef SHOW_REGION_EXTRAS
return;
#endif
if (!audioregion) {
row[_columns.fadeout] = "";
} else {
char buf[32];
format_position (audioregion->fade_out ()->back ()->when, buf, sizeof (buf), audioregion->fade_out_active ());
row[_columns.fadeout] = buf;
}
}
void
RegionListBase::populate_row_locked (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
row[_columns.locked] = region->locked ();
}
void
RegionListBase::populate_row_glued (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
if (region->position_time_domain () == Temporal::BeatTime) {
row[_columns.glued] = true;
} else {
row[_columns.glued] = false;
}
}
void
RegionListBase::populate_row_muted (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
row[_columns.muted] = region->muted ();
}
void
RegionListBase::populate_row_opaque (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
row[_columns.opaque] = region->opaque ();
}
void
RegionListBase::populate_row_name (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
row[_columns.name] = Gtkmm2ext::markup_escape_text (region->name ());
if (region->data_type () == DataType::MIDI) {
row[_columns.channels] = 0; /*TODO: some better recognition of midi regions*/
} else {
row[_columns.channels] = region->sources ().size ();
}
row[_columns.tags] = region->tags ();
}
void
RegionListBase::populate_row_source (boost::shared_ptr<Region> region, TreeModel::Row const& row)
{
if (boost::dynamic_pointer_cast<SilentFileSource> (region->source ())) {
row[_columns.path] = _("MISSING ") + Gtkmm2ext::markup_escape_text (region->source ()->name ());
} else {
row[_columns.path] = Gtkmm2ext::markup_escape_text (region->source ()->name ());
}
}
bool
RegionListBase::key_press (GdkEventKey* ev)
{
TreeViewColumn* col;
switch (ev->keyval) {
case GDK_Tab:
case GDK_ISO_Left_Tab:
if (_name_editable) {
_name_editable->editing_done ();
_name_editable = 0;
}
if (_tags_editable) {
_tags_editable->editing_done ();
_tags_editable = 0;
}
col = _display.get_column (0); // select&focus on name column
if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
treeview_select_previous (_display, _model, col);
} else {
treeview_select_next (_display, _model, col);
}
return true;
break;
default:
break;
}
return false;
}
void
RegionListBase::name_editing_started (CellEditable* ce, const Glib::ustring& path)
{
_name_editable = ce;
/* give it a special name */
Gtk::Entry* e = dynamic_cast<Gtk::Entry*> (ce);
if (e) {
e->set_name (X_("RegionNameEditorEntry"));
TreeIter iter;
if ((iter = _model->get_iter (path))) {
boost::shared_ptr<Region> region = (*iter)[_columns.region];
if (region) {
e->set_text (region->name ());
}
}
}
}
void
RegionListBase::name_edit (const std::string& path, const std::string& new_text)
{
_name_editable = 0;
boost::shared_ptr<Region> region;
TreeIter row_iter;
if ((row_iter = _model->get_iter (path))) {
region = (*row_iter)[_columns.region];
(*row_iter)[_columns.name] = new_text;
}
if (region) {
region->set_name (new_text);
populate_row_name (region, (*row_iter));
}
}
void
RegionListBase::tag_editing_started (CellEditable* ce, const Glib::ustring& path)
{
_tags_editable = ce;
/* give it a special name */
Gtk::Entry* e = dynamic_cast<Gtk::Entry*> (ce);
if (e) {
e->set_name (X_("RegionTagEditorEntry"));
TreeIter iter;
if ((iter = _model->get_iter (path))) {
boost::shared_ptr<Region> region = (*iter)[_columns.region];
if (region) {
e->set_text (region->tags ());
}
}
}
}
void
RegionListBase::tag_edit (const std::string& path, const std::string& new_text)
{
_tags_editable = 0;
boost::shared_ptr<Region> region;
TreeIter row_iter;
if ((row_iter = _model->get_iter (path))) {
region = (*row_iter)[_columns.region];
(*row_iter)[_columns.tags] = new_text;
}
if (region) {
region->set_tags (new_text);
populate_row_name (region, (*row_iter));
}
}
void
RegionListBase::clear ()
{
_display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
_model->clear ();
_display.set_model (_model);
/* Clean up the maps */
region_row_map.clear ();
}
void
RegionListBase::freeze_tree_model ()
{
/* store sort column id and type for later */
_model->get_sort_column_id (_sort_col_id, _sort_type);
_change_connection.block (true);
_display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
_model->set_sort_column (-2, SORT_ASCENDING); //Disable sorting to gain performance
}
void
RegionListBase::thaw_tree_model ()
{
_model->set_sort_column (_sort_col_id, _sort_type); // re-enabale sorting
_display.set_model (_model);
_change_connection.block (false);
}
void
RegionListBase::locked_changed (std::string const& path)
{
TreeIter i = _model->get_iter (path);
if (i) {
boost::shared_ptr<ARDOUR::Region> region = (*i)[_columns.region];
if (region) {
region->set_locked (!(*i)[_columns.locked]);
}
}
}
void
RegionListBase::glued_changed (std::string const& path)
{
TreeIter i = _model->get_iter (path);
if (i) {
boost::shared_ptr<ARDOUR::Region> region = (*i)[_columns.region];
if (region) {
/* `glued' means MusicTime, and we're toggling here */
region->set_position_time_domain ((*i)[_columns.glued] ? Temporal::AudioTime : Temporal::BeatTime);
}
}
}
void
RegionListBase::muted_changed (std::string const& path)
{
TreeIter i = _model->get_iter (path);
if (i) {
boost::shared_ptr<ARDOUR::Region> region = (*i)[_columns.region];
if (region) {
region->set_muted (!(*i)[_columns.muted]);
}
}
}
void
RegionListBase::opaque_changed (std::string const& path)
{
TreeIter i = _model->get_iter (path);
if (i) {
boost::shared_ptr<ARDOUR::Region> region = (*i)[_columns.region];
if (region) {
region->set_opaque (!(*i)[_columns.opaque]);
}
}
}

View File

@ -0,0 +1,244 @@
/*
* Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
* Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
* Copyright (C) 2009-2018 Paul Davis <paul@linuxaudiosystems.com>
* Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
* Copyright (C) 2021 Robin Gareus <robin@gareus.org>
*
* 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.
*/
#ifndef _gtk_ardour_region_list_base_h_
#define _gtk_ardour_region_list_base_h_
#include <boost/unordered_map.hpp>
#include <gtkmm/celleditable.h>
#include <gtkmm/frame.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treerowreference.h>
#include <gtkmm/treestore.h>
#include "gtkmm2ext/utils.h"
#include "pbd/properties.h"
#include "pbd/signals.h"
#include "ardour/session_handle.h"
#include "ardour/types.h"
#include "gtkmm2ext/dndtreeview.h"
//#define SHOW_REGION_EXTRAS
namespace ARDOUR
{
class Region;
class AudioRegion;
}
class RegionListBase : public ARDOUR::SessionHandlePtr
{
public:
RegionListBase ();
void set_session (ARDOUR::Session*);
Gtk::Widget& widget ()
{
return _scroller;
}
void clear ();
void redisplay ();
void suspend_redisplay ()
{
_no_redisplay = true;
}
void resume_redisplay ()
{
_no_redisplay = false;
redisplay ();
}
void block_change_connection (bool b)
{
_change_connection.block (b);
}
void unselect_all ()
{
_display.get_selection ()->unselect_all ();
}
protected:
struct Columns : public Gtk::TreeModel::ColumnRecord {
Columns ()
{
add (name); // 0
add (channels); // 1
add (tags); // 2
add (start); // 3
add (length); // 3
add (end); // 5
add (sync); // 6
add (fadein); // 7
add (fadeout); // 8
add (locked); // 9
add (glued); // 10
add (muted); // 11
add (opaque); // 12
add (path); // 13
add (region); // 14
add (color_); // 15
add (position); // 16
/* src-list */
add (captd_for); // 17
add (take_id); // 18
add (natural_pos); // 19
add (natural_s); // 20
add (captd_xruns);
}
Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<int> channels;
Gtk::TreeModelColumn<std::string> tags;
Gtk::TreeModelColumn<Temporal::timepos_t> position;
Gtk::TreeModelColumn<std::string> start;
Gtk::TreeModelColumn<std::string> end;
Gtk::TreeModelColumn<std::string> length;
Gtk::TreeModelColumn<std::string> sync;
Gtk::TreeModelColumn<std::string> fadein;
Gtk::TreeModelColumn<std::string> fadeout;
Gtk::TreeModelColumn<bool> locked;
Gtk::TreeModelColumn<bool> glued;
Gtk::TreeModelColumn<bool> muted;
Gtk::TreeModelColumn<bool> opaque;
Gtk::TreeModelColumn<std::string> path;
Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region>> region;
Gtk::TreeModelColumn<Gdk::Color> color_;
Gtk::TreeModelColumn<std::string> captd_for;
Gtk::TreeModelColumn<std::string> take_id;
Gtk::TreeModelColumn<std::string> natural_pos;
Gtk::TreeModelColumn<Temporal::timepos_t> natural_s;
Gtk::TreeModelColumn<size_t> captd_xruns;
};
void add_name_column ();
void add_tag_column ();
template <class T>
Gtk::TreeViewColumn* append_col (Gtk::TreeModelColumn<T> const& col, int width)
{
Gtk::TreeViewColumn* c = manage (new Gtk::TreeViewColumn ("", col));
c->set_fixed_width (width);
c->set_sizing (Gtk::TREE_VIEW_COLUMN_FIXED);
_display.append_column (*c);
return c;
}
template <class T>
Gtk::TreeViewColumn* append_col (Gtk::TreeModelColumn<T> const& col, std::string const& sizing_text)
{
int w, h;
Glib::RefPtr<Pango::Layout> layout = _display.create_pango_layout (sizing_text);
Gtkmm2ext::get_pixel_size (layout, w, h);
return append_col (col, w);
}
void setup_col (Gtk::TreeViewColumn*, int, Gtk::AlignmentEnum, const char*, const char*);
void setup_toggle (Gtk::TreeViewColumn*, sigc::slot<void, std::string>);
void freeze_tree_model ();
void thaw_tree_model ();
virtual void regions_changed (boost::shared_ptr<ARDOUR::RegionList>, PBD::PropertyChange const&);
void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
void name_edit (const std::string&, const std::string&);
void tag_editing_started (Gtk::CellEditable*, const Glib::ustring&);
void tag_edit (const std::string&, const std::string&);
void locked_changed (std::string const&);
void glued_changed (std::string const&);
void muted_changed (std::string const&);
void opaque_changed (std::string const&);
bool key_press (GdkEventKey*);
virtual bool button_press (GdkEventButton*)
{
return false;
}
bool focus_in (GdkEventFocus*);
bool focus_out (GdkEventFocus*);
bool enter_notify (GdkEventCrossing*);
bool leave_notify (GdkEventCrossing*);
void format_position (Temporal::timepos_t const& pos, char* buf, size_t bufsize, bool onoff = true);
void add_region (boost::shared_ptr<ARDOUR::Region>);
void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const&, PBD::PropertyChange const&);
void populate_row_used (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_position (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_end (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_sync (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_fade_in (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
void populate_row_fade_out (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
void populate_row_locked (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_muted (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_glued (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_opaque (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_length (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
void clock_format_changed ();
Columns _columns;
int _sort_col_id;
Gtk::SortType _sort_type;
Gtk::CellEditable* _name_editable;
Gtk::CellEditable* _tags_editable;
Gtk::Widget* _old_focus;
Gtk::ScrolledWindow _scroller;
Gtk::Frame _frame;
Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region>> _display;
Glib::RefPtr<Gtk::TreeStore> _model;
bool _no_redisplay;
typedef boost::unordered_map<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> RegionRowMap;
RegionRowMap region_row_map;
sigc::connection _change_connection;
PBD::ScopedConnection _editor_freeze_connection;
PBD::ScopedConnection _editor_thaw_connection;
};
#endif /* _gtk_ardour_region_list_base_h_ */

View File

@ -250,6 +250,7 @@ gtk2_ardour_sources = [
'region_editor.cc',
'region_gain_line.cc',
'region_layering_order_editor.cc',
'region_list_base.cc',
'region_peak_cursor.cc',
'region_selection.cc',
'region_view.cc',