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) {
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 ();
}
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()));
}
}
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 ();
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 ();
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 ();
out_of_bounds ();
}
- double get_ratio (int fill_level);
+ double get_ratio (int fill_level, int period_size);
void out_of_bounds();
public:
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; }
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);
}
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);
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 ? */
}
}
first_fs = fs;
}
- fs->set_captured_for (_name.get());
+ fs->set_captured_for (_name.val());
}
}
start = _position;
buf += offset;
- to_write = min (_length.get(), cnt);
+ to_write = min (_length.val(), cnt);
} else {
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);
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);
}
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);
_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();
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;
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));
}
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));
}
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));
}
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));
}
}
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);
}
}
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);
}
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";
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();
}
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.
}
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 << " ";
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";
/* 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 */
, _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()) */
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);
}
}
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;
}
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;
}
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;
}
template<class T>
std::ostream& operator<< (std::ostream& os, StateTemplate<T> const & s)
{
- os << s.get();
+ os << s.val();
return os;
}
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 ();
}
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;
}
*/
+#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
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() ();
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__ */
* @param s Stateful object.
*/
-StatefulDiffCommand::StatefulDiffCommand (Stateful* s)
+StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s)
: _object (s)
{
pair<XMLNode *, XMLNode*> const p = s->diff ();
_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());
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);