Unify Source and RegionList abstraction

This commit is contained in:
Robin Gareus 2022-01-19 01:59:05 +01:00
parent 0204ea1f24
commit 37877fbdc2
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
8 changed files with 337 additions and 944 deletions

View File

@ -6203,7 +6203,6 @@ Editor::session_going_away ()
/* rip everything out of the list displays */
_sources->clear ();
_routes->clear ();
_route_groups->clear ();

File diff suppressed because it is too large Load Diff

View File

@ -18,137 +18,29 @@
#ifndef __gtk_ardour_editor_sources_h__
#define __gtk_ardour_editor_sources_h__
#include <boost/unordered_map.hpp>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treerowreference.h>
#include <gtkmm/treestore.h>
#include "gtkmm2ext/dndtreeview.h"
#include "editor_component.h"
#include "source_list_base.h"
#include "selection.h"
class EditorSources : public EditorComponent, public ARDOUR::SessionHandlePtr
class EditorSources : public EditorComponent, public SourceListBase
{
public:
EditorSources (Editor *);
void set_session (ARDOUR::Session *);
Gtk::Widget& widget () {
return _scroller;
}
void clear ();
EditorSources (Editor*);
boost::shared_ptr<ARDOUR::Region> get_single_selection ();
void unselect_all () {
_display.get_selection()->unselect_all ();
}
/* user actions */
void remove_selected_sources ();
void recover_selected_sources();
XMLNode& get_state () const;
void set_state (const XMLNode &);
void recover_selected_sources ();
private:
struct Columns : public Gtk::TreeModel::ColumnRecord {
Columns () {
add (name);
add (channels);
add (captd_for);
add (tags);
add (take_id);
add (natural_pos);
add (path);
add (color_);
add (region);
add (natural_s);
add (captd_xruns);
}
Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<int> channels;
Gtk::TreeModelColumn<std::string> captd_for;
Gtk::TreeModelColumn<std::string> tags;
Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
Gtk::TreeModelColumn<Gdk::Color> color_;
Gtk::TreeModelColumn<std::string> natural_pos;
Gtk::TreeModelColumn<std::string> path;
Gtk::TreeModelColumn<std::string> take_id;
Gtk::TreeModelColumn<Temporal::timepos_t> natural_s;
Gtk::TreeModelColumn<size_t> captd_xruns;
};
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 populate_row (Gtk::TreeModel::Row row, boost::shared_ptr<ARDOUR::Region> region);
void selection_changed ();
sigc::connection _change_connection;
int _sort_col_id;
Gtk::SortType _sort_type;
Gtk::Widget* old_focus;
Gtk::CellEditable* tags_editable;
void tag_editing_started (Gtk::CellEditable*, const Glib::ustring&);
void tag_edit (const std::string&, const std::string&);
Gtk::CellEditable* name_editable;
void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
void name_edit (const std::string&, const std::string&);
bool key_press (GdkEventKey *);
bool button_press (GdkEventButton *);
bool focus_in (GdkEventFocus*);
bool focus_out (GdkEventFocus*);
bool enter_notify (GdkEventCrossing*);
bool leave_notify (GdkEventCrossing*);
void init ();
bool key_press (GdkEventKey*);
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 selection_changed ();
void add_source (boost::shared_ptr<ARDOUR::Region>);
void remove_source (boost::shared_ptr<ARDOUR::Source>);
void remove_weak_region (boost::weak_ptr<ARDOUR::Region>);
void remove_weak_source (boost::weak_ptr<ARDOUR::Source>);
void clock_format_changed ();
void redisplay ();
void drag_data_get (Glib::RefPtr<Gdk::DragContext> const&, Gtk::SelectionData&, guint, guint);
void drag_data_received (Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint);
Gtk::ScrolledWindow _scroller;
Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
Glib::RefPtr<Gtk::TreeStore> _model;
PBD::ScopedConnection source_property_connection;
PBD::ScopedConnection add_source_connection;
PBD::ScopedConnection remove_source_connection;
PBD::ScopedConnectionList remove_region_connections;
PBD::ScopedConnection editor_freeze_connection;
PBD::ScopedConnection editor_thaw_connection;
void drag_data_received (Glib::RefPtr<Gdk::DragContext> const&, gint, gint, Gtk::SelectionData const&, guint, guint);
};
#endif

View File

@ -25,12 +25,17 @@
#include <algorithm>
#include <string>
#include "pbd/file_utils.h"
#include "ardour/audiofilesource.h"
#include "ardour/audioregion.h"
#include "ardour/midi_source.h"
#include "ardour/region_factory.h"
#include "ardour/session.h"
#include "ardour/session_directory.h"
#include "ardour/session_playlist.h"
#include "ardour/silentfilesource.h"
#include "ardour/smf_source.h"
#include "gtkmm2ext/treeutils.h"
#include "gtkmm2ext/utils.h"
@ -254,14 +259,32 @@ RegionListBase::set_session (ARDOUR::Session* s)
}
void
RegionListBase::add_region (boost::shared_ptr<Region> region)
RegionListBase::remove_weak_region (boost::weak_ptr<ARDOUR::Region> r)
{
if (!region || !_session) {
boost::shared_ptr<ARDOUR::Region> region = r.lock ();
if (!region) {
return;
}
RegionRowMap::iterator map_it = region_row_map.find (region);
if (map_it != region_row_map.end ()) {
Gtk::TreeModel::iterator r_it = map_it->second;
region_row_map.erase (map_it);
_model->erase (r_it);
}
}
bool
RegionListBase::list_region (boost::shared_ptr<ARDOUR::Region> region) const
{
/* whole-file regions are shown in the Source List */
if (region->whole_file ()) {
return !region->whole_file ();
}
void
RegionListBase::add_region (boost::shared_ptr<Region> region)
{
if (!region || !_session || !list_region (region)) {
return;
}
@ -269,10 +292,21 @@ RegionListBase::add_region (boost::shared_ptr<Region> region)
* 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 ()) {
if (!fs) {
return;
}
if (fs->empty ()) {
/* MIDI sources are allowed to be empty */
if (!boost::dynamic_pointer_cast<MidiSource> (region->source ())) {
return;
}
}
if (region->whole_file ()) {
region->DropReferences.connect (_remove_region_connections, MISSING_INVALIDATOR, boost::bind (&RegionListBase::remove_weak_region, this, boost::weak_ptr<Region> (region)), gui_context ());
}
PropertyChange pc;
boost::shared_ptr<RegionList> rl (new RegionList);
rl->push_back (region);
@ -289,16 +323,18 @@ RegionListBase::regions_changed (boost::shared_ptr<RegionList> rl, const Propert
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);
RegionRowMap::iterator map_it = region_row_map.find (r);
boost::shared_ptr<ARDOUR::Playlist> pl = r->playlist ();
boost::shared_ptr<ARDOUR::Playlist> pl = r->playlist ();
if (!(pl && _session && _session->playlist_is_active (pl))) {
bool is_on_active_playlist = pl && _session && _session->playlist_is_active (pl);
if (!((is_on_active_playlist || r->whole_file ()) && list_region (r))) {
/* 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;
Gtk::TreeModel::iterator r_it = map_it->second;
region_row_map.erase (map_it);
_model->erase (r);
_model->erase (r_it);
}
break;
}
@ -335,6 +371,8 @@ RegionListBase::redisplay ()
/* store sort column id and type for later */
_model->get_sort_column_id (_sort_col_id, _sort_type);
_remove_region_connections.drop_connections ();
_display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
_model->clear ();
/* Disable sorting to gain performance */
@ -495,6 +533,8 @@ RegionListBase::populate_row (boost::shared_ptr<Region> region, TreeModel::Row c
if (all || what_changed.contains (Properties::name) || what_changed.contains (Properties::tags)) {
populate_row_name (region, row);
}
/* CAPTURED DROPOUTS */
row[_columns.captd_xruns] = region->source ()->n_captured_xruns ();
}
void
@ -632,10 +672,44 @@ RegionListBase::populate_row_name (boost::shared_ptr<Region> region, TreeModel::
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 ());
boost::shared_ptr<ARDOUR::Source> source = region->source ();
if (boost::dynamic_pointer_cast<SilentFileSource> (source)) {
row[_columns.path] = _("MISSING ") + Gtkmm2ext::markup_escape_text (source->name ());
} else {
row[_columns.path] = Gtkmm2ext::markup_escape_text (region->source ()->name ());
row[_columns.path] = Gtkmm2ext::markup_escape_text (source->name ());
boost::shared_ptr<FileSource> fs = boost::dynamic_pointer_cast<FileSource> (source);
if (fs) {
boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (source);
if (afs) {
const string audio_directory = _session->session_directory ().sound_path ();
if (!PBD::path_is_within (audio_directory, fs->path ())) {
row[_columns.path] = Gtkmm2ext::markup_escape_text (fs->path ());
}
}
boost::shared_ptr<SMFSource> mfs = boost::dynamic_pointer_cast<SMFSource> (source);
if (mfs) {
const string midi_directory = _session->session_directory ().midi_path ();
if (!PBD::path_is_within (midi_directory, fs->path ())) {
row[_columns.path] = Gtkmm2ext::markup_escape_text (fs->path ());
}
}
}
}
row[_columns.captd_for] = source->captured_for ();
row[_columns.take_id] = source->take_id ();
/* Natural Position (samples, an invisible column for sorting) */
row[_columns.natural_s] = source->natural_position ();
/* Natural Position (text representation) */
if (source->have_natural_position ()) {
char buf[64];
format_position (source->natural_position (), buf, sizeof (buf));
row[_columns.natural_pos] = buf;
} else {
row[_columns.natural_pos] = X_("--");
}
}
@ -765,6 +839,7 @@ RegionListBase::tag_edit (const std::string& path, const std::string& new_text)
void
RegionListBase::clear ()
{
_remove_region_connections.drop_connections ();
_display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
_model->clear ();
_display.set_model (_model);

View File

@ -166,21 +166,22 @@ protected:
void freeze_tree_model ();
void thaw_tree_model ();
void remove_weak_region (boost::weak_ptr<ARDOUR::Region>);
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&);
virtual void name_edit (const std::string&, const std::string&);
virtual 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 key_press (GdkEventKey*);
virtual bool button_press (GdkEventButton*)
{
return false;
@ -215,6 +216,8 @@ protected:
void drag_data_get (Glib::RefPtr<Gdk::DragContext> const&, Gtk::SelectionData&, guint, guint);
virtual bool list_region (boost::shared_ptr<ARDOUR::Region>) const;
Columns _columns;
int _sort_col_id;
@ -241,6 +244,8 @@ protected:
PBD::ScopedConnection _editor_freeze_connection;
PBD::ScopedConnection _editor_thaw_connection;
PBD::ScopedConnectionList _remove_region_connections;
};
#endif /* _gtk_ardour_region_list_base_h_ */

View File

@ -0,0 +1,104 @@
/*
* 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.
*/
#include "ardour/region.h"
#include "ardour/session.h"
#include "gui_thread.h"
#include "source_list_base.h"
#include "pbd/i18n.h"
using namespace Gtk;
SourceListBase::SourceListBase ()
{
}
void
SourceListBase::set_session (ARDOUR::Session* s)
{
if (s) {
s->SourceRemoved.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&SourceListBase::remove_weak_source, this, _1), gui_context ());
}
RegionListBase::set_session (s);
}
void
SourceListBase::remove_weak_source (boost::weak_ptr<ARDOUR::Source> src)
{
boost::shared_ptr<ARDOUR::Source> source = src.lock ();
if (source) {
remove_source (source);
}
}
void
SourceListBase::remove_source (boost::shared_ptr<ARDOUR::Source> source)
{
TreeModel::iterator i;
TreeModel::Children rows = _model->children ();
for (i = rows.begin (); i != rows.end (); ++i) {
boost::shared_ptr<ARDOUR::Region> rr = (*i)[_columns.region];
if (rr->source () == source) {
RegionRowMap::iterator map_it = region_row_map.find (rr);
assert (map_it != region_row_map.end () && i == map_it->second);
region_row_map.erase (map_it);
_model->erase (i);
break;
}
}
}
bool
SourceListBase::list_region (boost::shared_ptr<ARDOUR::Region> region) const
{
/* by definition, the Source List only shows whole-file regions
* this roughly equates to Source objects, but preserves the stereo-ness
* (or multichannel-ness) of a stereo source file.
*/
return region->whole_file ();
}
void
SourceListBase::tag_edit (const std::string& path, const std::string& new_text)
{
RegionListBase::tag_edit (path, new_text);
TreeIter row_iter;
if ((row_iter = _model->get_iter (path))) {
boost::shared_ptr<ARDOUR::Region> region = (*row_iter)[_columns.region];
if (region) {
_session->set_dirty (); // whole-file regions aren't in a playlist to catch property changes, so we need to explicitly set the session dirty
}
}
}
void
SourceListBase::name_edit (const std::string& path, const std::string& new_text)
{
RegionListBase::name_edit (path, new_text);
TreeIter row_iter;
if ((row_iter = _model->get_iter (path))) {
boost::shared_ptr<ARDOUR::Region> region = (*row_iter)[_columns.region];
if (region) {
_session->set_dirty (); // whole-file regions aren't in a playlist to catch property changes, so we need to explicitly set the session dirty
}
}
}

View File

@ -0,0 +1,39 @@
/*
* 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_source_list_base_h_
#define _gtk_ardour_source_list_base_h_
#include "region_list_base.h"
class SourceListBase : public RegionListBase
{
public:
SourceListBase ();
void set_session (ARDOUR::Session*);
protected:
void name_edit (const std::string&, const std::string&);
void tag_edit (const std::string&, const std::string&);
bool list_region (boost::shared_ptr<ARDOUR::Region>) const;
private:
void remove_source (boost::shared_ptr<ARDOUR::Source>);
void remove_weak_source (boost::weak_ptr<ARDOUR::Source>);
};
#endif /* _gtk_ardour_source_list_base_h_ */

View File

@ -280,6 +280,7 @@ gtk2_ardour_sources = [
'sfdb_ui.cc',
'shuttle_control.cc',
'slot_properties_box.cc',
'source_list_base.cc',
'soundcloud_export_selector.cc',
'splash.cc',
'speaker_dialog.cc',