tweak Stateful/StatefulDiffCommand changes so that SessionObject's actually get a name; make StatefulDiffCommand use a weak_ptr, not a raw ptr; use .val() rather than .get() to avoid confusion with boost:: smart ptr method of the same name

git-svn-id: svn://localhost/ardour2/branches/3.0@6678 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2010-02-11 23:10:29 +00:00
parent f938687f87
commit a1e0dc13df
19 changed files with 80 additions and 55 deletions

View File

@ -980,7 +980,7 @@ RegionMoveDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
rv->region()->set_position (where, (void*) this);
_editor->session()->add_command (new StatefulDiffCommand (rv->region().get()));
_editor->session()->add_command (new StatefulDiffCommand (rv->region()));
}
if (changed_tracks && !_copy) {

View File

@ -3180,7 +3180,7 @@ Editor::naturalize ()
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
(*i)->region()->clear_history ();
(*i)->region()->move_to_natural_position (this);
_session->add_command (new StatefulDiffCommand ((*i)->region().get()));
_session->add_command (new StatefulDiffCommand ((*i)->region()));
}
commit_reversible_command ();
}
@ -4932,7 +4932,7 @@ Editor::toggle_gain_envelope_active ()
if (arv) {
arv->region()->clear_history ();
arv->audio_region()->set_envelope_active (!arv->audio_region()->envelope_active());
_session->add_command (new StatefulDiffCommand (arv->region().get()));
_session->add_command (new StatefulDiffCommand (arv->region()));
}
}
@ -4953,7 +4953,7 @@ Editor::toggle_region_lock ()
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
(*i)->region()->clear_history ();
(*i)->region()->set_locked (!(*i)->region()->locked());
_session->add_command (new StatefulDiffCommand ((*i)->region().get()));
_session->add_command (new StatefulDiffCommand ((*i)->region()));
}
_session->commit_reversible_command ();
@ -4995,7 +4995,7 @@ Editor::toggle_region_mute ()
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
(*i)->region()->clear_history ();
(*i)->region()->set_muted (!(*i)->region()->muted());
_session->add_command (new StatefulDiffCommand ((*i)->region().get()));
_session->add_command (new StatefulDiffCommand ((*i)->region()));
}
_session->commit_reversible_command ();
@ -5015,7 +5015,7 @@ Editor::toggle_region_opaque ()
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
(*i)->region()->clear_history ();
(*i)->region()->set_opaque (!(*i)->region()->opaque());
_session->add_command (new StatefulDiffCommand ((*i)->region().get()));
_session->add_command (new StatefulDiffCommand ((*i)->region()));
}
_session->commit_reversible_command ();

View File

@ -33,7 +33,7 @@ class PIController {
out_of_bounds ();
}
double get_ratio (int fill_level);
double get_ratio (int fill_level, int period_size);
void out_of_bounds();
public:
@ -60,7 +60,7 @@ class PIChaser {
PIChaser();
~PIChaser();
double get_ratio( nframes64_t chasetime_measured, nframes64_t chasetime, nframes64_t slavetime_measured, nframes64_t slavetime, bool in_control );
double get_ratio( nframes64_t chasetime_measured, nframes64_t chasetime, nframes64_t slavetime_measured, nframes64_t slavetime, bool in_control, int period_size );
void reset();
nframes64_t want_locate() { return want_locate_val; }

View File

@ -41,7 +41,7 @@ class SessionObject : public SessionHandleRef, public PBD::StatefulDestructible
public:
SessionObject (Session& session, const std::string& name)
: SessionHandleRef (session)
, _name (X_("name"), PBD::Change (0), "")
, _name (X_("name"), PBD::Change (0), name)
{
add_state (_name);
}

View File

@ -1433,7 +1433,7 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca
if (s) {
srcs.push_back (s);
s->update_header (capture_info.front()->start, when, twhen);
s->set_captured_for (_name.get());
s->set_captured_for (_name.val());
s->mark_immutable ();
if (Config->get_auto_analyse_audio()) {
Analyser::queue_source_for_analysis (s, true);
@ -1970,7 +1970,7 @@ AudioDiskstream::rename_write_sources ()
for (chan = c->begin(), n = 0; chan != c->end(); ++chan, ++n) {
if ((*chan)->write_source != 0) {
(*chan)->write_source->set_source_name (_name.get(), destructive());
(*chan)->write_source->set_source_name (_name.val(), destructive());
/* XXX what to do if one of them fails ? */
}
}
@ -2178,7 +2178,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node)
first_fs = fs;
}
fs->set_captured_for (_name.get());
fs->set_captured_for (_name.val());
}
}

View File

@ -314,7 +314,7 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
start = _position;
buf += offset;
to_write = min (_length.get(), cnt);
to_write = min (_length.val(), cnt);
} else {
@ -679,7 +679,7 @@ Crossfade::get_state ()
node->add_property ("active", (_active ? "yes" : "no"));
node->add_property ("follow-overlap", (_follow_overlap ? "yes" : "no"));
node->add_property ("fixed", (_fixed ? "yes" : "no"));
snprintf (buf, sizeof(buf), "%" PRIu32, _length.get());
snprintf (buf, sizeof(buf), "%" PRIu32, _length.val());
node->add_property ("length", buf);
snprintf (buf, sizeof(buf), "%" PRIu32, (uint32_t) _anchor_point);
node->add_property ("anchor-point", buf);

View File

@ -1098,7 +1098,7 @@ IO::set_name (const string& requested_name)
for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
string current_name = i->name();
current_name.replace (current_name.find (_name), _name.get().length(), name);
current_name.replace (current_name.find (_name), _name.val().length(), name);
i->set_name (current_name);
}
@ -1267,7 +1267,7 @@ IO::build_legal_port_name (DataType type)
char buf1[name_size+1];
char buf2[name_size+1];
snprintf (buf1, name_size+1, ("%.*s/%s"), limit, _name.get().c_str(), suffix.c_str());
snprintf (buf1, name_size+1, ("%.*s/%s"), limit, _name.val().c_str(), suffix.c_str());
int port_number = find_port_hole (buf1);
snprintf (buf2, name_size+1, "%s %d", buf1, port_number);
@ -1342,9 +1342,9 @@ IO::setup_bundle ()
_bundle->remove_channels ();
if (_direction == Input) {
snprintf(buf, sizeof (buf), _("%s in"), _name.get().c_str());
snprintf(buf, sizeof (buf), _("%s in"), _name.val().c_str());
} else {
snprintf(buf, sizeof (buf), _("%s out"), _name.get().c_str());
snprintf(buf, sizeof (buf), _("%s out"), _name.val().c_str());
}
_bundle->set_name (buf);
uint32_t const ni = _ports.num_ports();

View File

@ -1388,7 +1388,7 @@ int
MidiDiskstream::rename_write_sources ()
{
if (_write_source != 0) {
_write_source->set_source_name (_name.get(), destructive());
_write_source->set_source_name (_name.val(), destructive());
/* XXX what to do if this fails ? */
}
return 0;

View File

@ -51,7 +51,7 @@ using namespace PBD;
MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, nframes_t start, nframes_t length)
: Region (src, start, length, PBD::basename_nosuffix(src->name()), DataType::MIDI, 0, Region::Flag(Region::DefaultFlags|Region::External))
{
assert(_name.get().find("/") == string::npos);
assert(_name.val().find("/") == string::npos);
midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
}
@ -59,7 +59,7 @@ MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, nframes_t start, nfra
MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, nframes_t start, nframes_t length, const string& name, layer_t layer, Flag flags)
: Region (src, start, length, name, DataType::MIDI, layer, flags)
{
assert(_name.get().find("/") == string::npos);
assert(_name.val().find("/") == string::npos);
midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
}
@ -67,7 +67,7 @@ MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, nframes_t start, nfra
MidiRegion::MidiRegion (const SourceList& srcs, nframes_t start, nframes_t length, const string& name, layer_t layer, Flag flags)
: Region (srcs, start, length, name, DataType::MIDI, layer, flags)
{
assert(_name.get().find("/") == string::npos);
assert(_name.val().find("/") == string::npos);
midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
}
@ -76,14 +76,14 @@ MidiRegion::MidiRegion (const SourceList& srcs, nframes_t start, nframes_t lengt
MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, nframes_t offset, nframes_t length, const string& name, layer_t layer, Flag flags)
: Region (other, offset, length, name, layer, flags)
{
assert(_name.get().find("/") == string::npos);
assert(_name.val().find("/") == string::npos);
midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
}
MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other)
: Region (other)
{
assert(_name.get().find("/") == string::npos);
assert(_name.val().find("/") == string::npos);
midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
}
@ -95,7 +95,7 @@ MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, const XMLNode& node)
}
midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
assert(_name.get().find("/") == string::npos);
assert(_name.val().find("/") == string::npos);
assert(_type == DataType::MIDI);
}
@ -107,7 +107,7 @@ MidiRegion::MidiRegion (const SourceList& srcs, const XMLNode& node)
}
midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
assert(_name.get().find("/") == string::npos);
assert(_name.val().find("/") == string::npos);
assert(_type == DataType::MIDI);
}

View File

@ -230,7 +230,7 @@ MidiSource::session_saved()
if (_model && _model->edited()) {
string newname;
const string basename = PBD::basename_nosuffix(_name.get());
const string basename = PBD::basename_nosuffix(_name.val());
string::size_type last_dash = basename.find_last_of("-");
if (last_dash == string::npos || last_dash == basename.find_first_of("-")) {
newname = basename + "-1";

View File

@ -429,7 +429,7 @@ MTC_Slave::speed_and_position (double& speed, nframes64_t& pos)
static double average_speed = 0;
nframes64_t ref_now = session.engine().frame_time_at_cycle_start();
average_speed = pic->get_ratio (last.timestamp, last.position, ref_now, slave_pos, in_control );
average_speed = pic->get_ratio (last.timestamp, last.position, ref_now, slave_pos, in_control, session.engine().frames_per_cycle());
pic_want_locate = pic->want_locate();

View File

@ -56,10 +56,10 @@ PIController::~PIController ()
}
double
PIController::get_ratio (int fill_level)
PIController::get_ratio (int fill_level, int period_size)
{
double offset = fill_level;
double this_catch_factor = catch_factor;
double this_catch_factor = catch_factor * 4096.0/(double)period_size;
// Save offset.
@ -151,7 +151,7 @@ PIChaser::~PIChaser() {
}
double
PIChaser::get_ratio(nframes64_t chasetime_measured, nframes64_t chasetime, nframes64_t slavetime_measured, nframes64_t slavetime, bool in_control ) {
PIChaser::get_ratio(nframes64_t chasetime_measured, nframes64_t chasetime, nframes64_t slavetime_measured, nframes64_t slavetime, bool in_control, int period_size ) {
feed_estimator( chasetime_measured, chasetime );
std::cerr << (double)chasetime_measured/48000.0 << " " << chasetime << " " << slavetime << " ";
@ -159,7 +159,7 @@ PIChaser::get_ratio(nframes64_t chasetime_measured, nframes64_t chasetime, nfram
double fine;
nframes64_t massaged_chasetime = chasetime + (nframes64_t)( (double)(slavetime_measured - chasetime_measured) * crude );
fine = pic->get_ratio( slavetime - massaged_chasetime );
fine = pic->get_ratio( slavetime - massaged_chasetime, period_size );
if (in_control) {
if (fabs(fine-crude) > crude*speed_threshold) {
std::cout << "reset to " << crude << " fine = " << fine << "\n";

View File

@ -1197,12 +1197,12 @@ Region::set_live_state (const XMLNode& node, int /*version*/, Change& what_chang
/* fix problems with old sessions corrupted by impossible
values for _stretch or _shift
*/
if (_stretch == 0.0) {
_stretch = 1.0;
if (_stretch == 0.0f) {
_stretch = 1.0f;
}
if (_shift == 0.0) {
_shift = 1.0;
if (_shift == 0.0f) {
_shift = 1.0f;
}
/* note: derived classes set flags */

View File

@ -78,6 +78,7 @@ Route::Route (Session& sess, string name, Flag flg, DataType default_type)
, _default_type (default_type)
{
cerr << "New route with n=" << name << " has name = " << _name.val() << endl;
init ();
/* add standard processors other than amp (added by ::init()) */

View File

@ -144,7 +144,7 @@ Session::stateful_diff_command_factory (XMLNode* n)
if ((obj_T == typeid (AudioRegion).name() || obj_T == typeid (MidiRegion).name())) {
boost::shared_ptr<Region> r = RegionFactory::region_by_id (id);
if (r) {
return new StatefulDiffCommand (r.get(), *n);
return new StatefulDiffCommand (r, *n);
}
}

View File

@ -306,7 +306,7 @@ SndFileSource::read_unlocked (Sample *dst, sframes_t start, nframes_t cnt) const
if (sf_seek (sf, (sf_count_t) start, SEEK_SET|SFM_READ) != (sf_count_t) start) {
char errbuf[256];
sf_error_str (0, errbuf, sizeof (errbuf) - 1);
error << string_compose(_("SndFileSource: could not seek to frame %1 within %2 (%3)"), start, _name.get().substr (1), errbuf) << endmsg;
error << string_compose(_("SndFileSource: could not seek to frame %1 within %2 (%3)"), start, _name.val().substr (1), errbuf) << endmsg;
return 0;
}
@ -316,7 +316,7 @@ SndFileSource::read_unlocked (Sample *dst, sframes_t start, nframes_t cnt) const
if (ret != file_cnt) {
char errbuf[256];
sf_error_str (0, errbuf, sizeof (errbuf) - 1);
cerr << string_compose(_("SndFileSource: @ %1 could not read %2 within %3 (%4) (len = %5)"), start, file_cnt, _name.get().substr (1), errbuf, _length) << endl;
cerr << string_compose(_("SndFileSource: @ %1 could not read %2 within %3 (%4) (len = %5)"), start, file_cnt, _name.val().substr (1), errbuf, _length) << endl;
}
return ret;
}

View File

@ -99,20 +99,20 @@ public:
set (_current + v);
return _current;
}
bool operator== (std::string const & o) const {
return o == to_string (_current);
bool operator== (const T& other) const {
return _current == other;
}
bool operator!= (std::string const & o) const {
return o != to_string (_current);
bool operator!= (const T& other) const {
return _current != other;
}
operator T const & () const {
return _current;
}
T const & get () const {
T const & val () const {
return _current;
}
@ -165,7 +165,7 @@ protected:
template<class T>
std::ostream& operator<< (std::ostream& os, StateTemplate<T> const & s)
{
os << s.get();
os << s.val();
return os;
}
@ -190,6 +190,7 @@ public:
private:
std::string to_string (T const & v) const {
std::stringstream s;
s.precision (12); // in case its floating point
s << v;
return s.str ();
}
@ -197,6 +198,7 @@ private:
T from_string (std::string const & s) const {
std::stringstream t (s);
T v;
t.precision (12); // in case its floating point
t >> v;
return v;
}

View File

@ -17,6 +17,11 @@
*/
#ifndef __pbd_stateful_diff_command_h__
#define __pbd_stateful_diff_command_h__
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include "pbd/command.h"
namespace PBD
@ -30,8 +35,8 @@ class Stateful;
class StatefulDiffCommand : public Command
{
public:
StatefulDiffCommand (Stateful *);
StatefulDiffCommand (Stateful *, XMLNode const &);
StatefulDiffCommand (boost::shared_ptr<Stateful>);
StatefulDiffCommand (boost::shared_ptr<Stateful>, XMLNode const &);
~StatefulDiffCommand ();
void operator() ();
@ -40,9 +45,11 @@ public:
XMLNode& get_state ();
private:
Stateful* _object; ///< the object in question
boost::weak_ptr<Stateful> _object; ///< the object in question
XMLNode* _before; ///< XML node containing the previous values of XML properties which changed
XMLNode* _after; ///< XML node containing the new values of XML properties which changed
};
};
#endif /* __pbd_stateful_diff_command_h__ */

View File

@ -28,7 +28,7 @@ using namespace PBD;
* @param s Stateful object.
*/
StatefulDiffCommand::StatefulDiffCommand (Stateful* s)
StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s)
: _object (s)
{
pair<XMLNode *, XMLNode*> const p = s->diff ();
@ -36,7 +36,7 @@ StatefulDiffCommand::StatefulDiffCommand (Stateful* s)
_after = p.second;
}
StatefulDiffCommand::StatefulDiffCommand (Stateful* s, XMLNode const & n)
StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s, XMLNode const & n)
: _object (s)
{
_before = new XMLNode (*n.children().front());
@ -53,22 +53,37 @@ StatefulDiffCommand::~StatefulDiffCommand ()
void
StatefulDiffCommand::operator() ()
{
_object->set_state (*_after, Stateful::current_state_version);
boost::shared_ptr<Stateful> s (_object.lock());
if (s) {
s->set_state (*_after, Stateful::current_state_version);
}
}
void
StatefulDiffCommand::undo ()
{
_object->set_state (*_before, Stateful::current_state_version);
boost::shared_ptr<Stateful> s (_object.lock());
if (s) {
s->set_state (*_before, Stateful::current_state_version);
}
}
XMLNode&
StatefulDiffCommand::get_state ()
{
boost::shared_ptr<Stateful> s (_object.lock());
if (!s) {
/* XXX should we throw? */
return * new XMLNode("");
}
XMLNode* node = new XMLNode (X_("StatefulDiffCommand"));
node->add_property ("obj-id", _object->id().to_s());
node->add_property ("type-name", typeid(*_object).name());
node->add_property ("obj-id", s->id().to_s());
node->add_property ("type-name", typeid(*s.get()).name());
node->add_child_copy (*_before);
node->add_child_copy (*_after);