Make start_touch() truly idempotent

Also don't allow outsiders to call Controllable::set_touching()
This commit is contained in:
Robin Gareus
2017-07-25 20:15:12 +02:00
parent 9bfe404b4e
commit bde3edf1c8
2 changed files with 29 additions and 27 deletions

View File

@@ -266,42 +266,41 @@ AutomationControl::set_automation_state (AutoState as)
}
void
AutomationControl::start_touch(double when)
AutomationControl::start_touch (double when)
{
if (!_list) {
if (!_list || touching ()) {
return;
}
if (!touching()) {
if (alist()->automation_state() == Touch) {
/* subtle. aligns the user value with the playback and
* use take actual value (incl masters).
*
* Touch + hold writes inverse curve of master-automation
* using AutomationWatch::timer ()
*/
AutomationControl::actually_set_value (get_value (), Controllable::NoGroup);
alist()->start_touch (when);
if (!_desc.toggled) {
AutomationWatch::instance().add_automation_watch (shared_from_this());
}
if (alist()->automation_state() == Touch) {
/* subtle. aligns the user value with the playback and
* use take actual value (incl masters).
*
* Touch + hold writes inverse curve of master-automation
* using AutomationWatch::timer ()
*/
AutomationControl::actually_set_value (get_value (), Controllable::NoGroup);
alist()->start_touch (when);
if (!_desc.toggled) {
AutomationWatch::instance().add_automation_watch (shared_from_this());
}
set_touching (true);
}
}
void
AutomationControl::stop_touch(double when)
AutomationControl::stop_touch (double when)
{
if (!_list) return;
if (touching()) {
set_touching (false);
if (!_list || !touching ()) {
return;
}
if (alist()->automation_state() == Touch) {
alist()->stop_touch (when);
if (!_desc.toggled) {
AutomationWatch::instance().remove_automation_watch (shared_from_this());
}
set_touching (false);
if (alist()->automation_state() == Touch) {
alist()->stop_touch (when);
if (!_desc.toggled) {
AutomationWatch::instance().remove_automation_watch (shared_from_this());
}
}
}

View File

@@ -50,7 +50,7 @@ namespace PBD {
*
*/
class LIBPBD_API Controllable : public PBD::StatefulDestructible {
public:
public:
enum Flag {
Toggle = 0x1,
GainLike = 0x2,
@@ -140,7 +140,6 @@ class LIBPBD_API Controllable : public PBD::StatefulDestructible {
std::string name() const { return _name; }
bool touching () const { return _touching; }
void set_touching (bool yn) { _touching = yn; }
bool is_toggle() const { return _flags & Toggle; }
bool is_gain_like() const { return _flags & GainLike; }
@@ -156,7 +155,11 @@ class LIBPBD_API Controllable : public PBD::StatefulDestructible {
static Controllable* by_name (const std::string&);
static const std::string xml_node_name;
private:
protected:
void set_touching (bool yn) { _touching = yn; }
private:
std::string _name;
std::string _units;
Flag _flags;