(Source List) Source property signals (libardour part)

This commit is contained in:
Ben Loftis 2018-11-15 09:21:31 -06:00
parent 949450bbb5
commit ca3c191d7c
9 changed files with 60 additions and 22 deletions

View File

@ -39,8 +39,7 @@
namespace ARDOUR {
class LIBARDOUR_API AudioSource : virtual public Source,
public ARDOUR::Readable,
public boost::enable_shared_from_this<ARDOUR::AudioSource>
public ARDOUR::Readable
{
public:
AudioSource (Session&, const std::string& name);

View File

@ -43,7 +43,7 @@ class MidiStateTracker;
template<typename T> class MidiRingBuffer;
/** Source for MIDI data */
class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_shared_from_this<MidiSource>
class LIBARDOUR_API MidiSource : virtual public Source
{
public:
typedef Temporal::Beats TimeType;

View File

@ -1754,8 +1754,20 @@ private:
mutable Glib::Threads::Mutex source_lock;
public:
/* Emited when a new source is added to the session */
PBD::Signal1< void, boost::shared_ptr<Source> > SourceAdded;
PBD::Signal1< void, boost::shared_ptr<Source> > SourceRemoved;
typedef std::map<PBD::ID,boost::shared_ptr<Source> > SourceMap;
void foreach_source (boost::function<void( boost::shared_ptr<Source> )> f) {
Glib::Threads::Mutex::Lock ls (source_lock);
for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) {
f ( (*i).second );
}
}
private:
void reset_write_sources (bool mark_write_complete, bool force = false);
SourceMap sources;

View File

@ -25,6 +25,8 @@
#include <glibmm/threads.h>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/utility.hpp>
#include "pbd/statefuldestructible.h"
@ -36,7 +38,8 @@ namespace ARDOUR {
class Session;
class LIBARDOUR_API Source : public SessionObject
class LIBARDOUR_API Source : public SessionObject,
public boost::enable_shared_from_this<ARDOUR::Source>
{
public:
enum Flag {
@ -117,25 +120,24 @@ public:
uint32_t level() const { return _level; }
std::string ancestor_name() { return _ancestor_name.empty() ? name() : _ancestor_name; }
void set_ancestor_name(const std::string& name) { _ancestor_name = name; }
void set_ancestor_name(const std::string& name) { _ancestor_name = name; }
protected:
DataType _type;
Flag _flags;
time_t _timestamp;
std::string _take_id;
samplepos_t _timeline_position;
bool _analysed;
static PBD::Signal1<void,boost::shared_ptr<ARDOUR::Source> > SourcePropertyChanged;
mutable Glib::Threads::Mutex _lock;
mutable Glib::Threads::Mutex _analysis_lock;
gint _use_count; /* atomic */
uint32_t _level; /* how deeply nested is this source w.r.t a disk file */
std::string _ancestor_name;
private:
protected:
DataType _type;
Flag _flags;
time_t _timestamp;
std::string _take_id;
samplepos_t _timeline_position;
bool _analysed;
mutable Glib::Threads::Mutex _lock;
mutable Glib::Threads::Mutex _analysis_lock;
gint _use_count; /* atomic */
uint32_t _level; /* how deeply nested is this source w.r.t a disk file */
std::string _ancestor_name;
private:
void fix_writable_flags ();
};

View File

@ -1220,6 +1220,8 @@ DiskWriter::transport_stopped_wallclock (struct tm& when, time_t twhen, bool abo
strftime (buf, sizeof(buf), "%F %H.%M.%S", &when);
as->set_take_id ( buf );
Source::SourcePropertyChanged(as);
if (Config->get_auto_analyse_audio()) {
Analyser::queue_source_for_analysis (as, true);
}

View File

@ -1555,6 +1555,7 @@ Region::set_master_sources (const SourceList& srcs)
for (SourceList::const_iterator i = _master_sources.begin (); i != _master_sources.end(); ++i) {
(*i)->inc_use_count ();
// Source::SourcePropertyChanged( *i );
}
}

View File

@ -4789,6 +4789,7 @@ Session::destroy_sources (list<boost::shared_ptr<Source> > srcs)
(*s)->mark_for_remove ();
(*s)->drop_references ();
SourceRemoved(*s);
s = srcs.erase (s);
}
@ -4862,6 +4863,8 @@ Session::add_source (boost::shared_ptr<Source> source)
}
source->DropReferences.connect_same_thread (*this, boost::bind (&Session::remove_source, this, boost::weak_ptr<Source> (source)));
SourceAdded(source);
}
}
@ -4884,6 +4887,7 @@ Session::remove_source (boost::weak_ptr<Source> src)
if ((i = sources.find (source->id())) != sources.end()) {
sources.erase (i);
SourceRemoved(source);
}
}

View File

@ -622,7 +622,8 @@ SMFSource::load_model (const Glib::Threads::Mutex::Lock& lock, bool force_reload
}
if (!_model) {
_model = boost::shared_ptr<MidiModel> (new MidiModel (shared_from_this ()));
boost::shared_ptr<SMFSource> smf = boost::dynamic_pointer_cast<SMFSource> ( shared_from_this () );
_model = boost::shared_ptr<MidiModel> (new MidiModel (smf));
} else {
_model->clear();
}

View File

@ -52,6 +52,9 @@ using namespace std;
using namespace ARDOUR;
using namespace PBD;
PBD::Signal1<void,boost::shared_ptr<ARDOUR::Source> > Source::SourcePropertyChanged;
Source::Source (Session& s, DataType type, const string& name, Flag flags)
: SessionObject(s, name)
, _type(type)
@ -292,7 +295,14 @@ Source::set_allow_remove_if_empty (bool yn)
void
Source::inc_use_count ()
{
g_atomic_int_inc (&_use_count);
g_atomic_int_inc (&_use_count);
try {
boost::shared_ptr<Source> sptr = shared_from_this();
SourcePropertyChanged (sptr);
} catch (...) {
/* no shared_ptr available, relax; */
}
}
void
@ -308,6 +318,13 @@ Source::dec_use_count ()
#else
g_atomic_int_add (&_use_count, -1);
#endif
try {
boost::shared_ptr<Source> sptr = shared_from_this();
SourcePropertyChanged (sptr);
} catch (...) {
/* no shared_ptr available, relax; */
}
}
bool