diff --git a/SessionCreator.cpp b/SessionCreator.cpp index ad04f25..44f32b0 100644 --- a/SessionCreator.cpp +++ b/SessionCreator.cpp @@ -1151,11 +1151,22 @@ void SessionLoader::visit (SourceCallback &) { } +void SessionLoader::visit (Play &c) +{ + bool p = true; + xmlCurrent_->QueryBoolAttribute("play", &p); + c.setValue(p); +} + void SessionLoader::visit (SetAlpha &c) { float a = 0.f; xmlCurrent_->QueryFloatAttribute("alpha", &a); c.setValue(a); + + float d = 0.f; + xmlCurrent_->QueryFloatAttribute("duration", &d); + c.setDuration(d); } void SessionLoader::visit (SetDepth &c) diff --git a/SessionCreator.h b/SessionCreator.h index 73cab72..54a461f 100644 --- a/SessionCreator.h +++ b/SessionCreator.h @@ -71,6 +71,7 @@ public: void visit (Grab&) override; void visit (Resize&) override; void visit (Turn&) override; + void visit (Play&) override; static void XMLToNode(const tinyxml2::XMLElement *xml, Node &n); static void XMLToSourcecore(tinyxml2::XMLElement *xml, SourceCore &s); diff --git a/SessionVisitor.cpp b/SessionVisitor.cpp index ad3c210..479a741 100644 --- a/SessionVisitor.cpp +++ b/SessionVisitor.cpp @@ -764,9 +764,15 @@ void SessionVisitor::visit (SourceCallback &c) xmlCurrent_->SetAttribute("type", (uint) c.type()); } +void SessionVisitor::visit (Play &c) +{ + xmlCurrent_->SetAttribute("play", c.value()); +} + void SessionVisitor::visit (SetAlpha &c) { xmlCurrent_->SetAttribute("alpha", c.value()); + xmlCurrent_->SetAttribute("duration", c.duration()); } void SessionVisitor::visit (SetDepth &c) diff --git a/SessionVisitor.h b/SessionVisitor.h index 5c0ddd3..cc1746a 100644 --- a/SessionVisitor.h +++ b/SessionVisitor.h @@ -77,6 +77,7 @@ public: void visit (Grab&) override; void visit (Resize&) override; void visit (Turn&) override; + void visit (Play&) override; static tinyxml2::XMLElement *NodeToXML(const Node &n, tinyxml2::XMLDocument *doc); static tinyxml2::XMLElement *ImageToXML(const FrameBufferImage *img, tinyxml2::XMLDocument *doc); diff --git a/SourceCallback.cpp b/SourceCallback.cpp index 6c22e67..4b6d806 100644 --- a/SourceCallback.cpp +++ b/SourceCallback.cpp @@ -133,43 +133,71 @@ SourceCallback *ResetGeometry::clone() const return new ResetGeometry; } -SetAlpha::SetAlpha() : SourceCallback(), alpha_(0.f) +SetAlpha::SetAlpha() : SourceCallback(), duration_(0.f), progress_(0.f), alpha_(0.f) { - pos_ = glm::vec2(); - step_ = glm::normalize(glm::vec2(1.f, 1.f)); // step in diagonal by default + start_ = glm::vec2(); + target_ = glm::vec2(); } -SetAlpha::SetAlpha(float alpha) : SetAlpha() +SetAlpha::SetAlpha(float alpha, float duration) : SetAlpha() { alpha_ = CLAMP(alpha, 0.f, 1.f); + duration_ = duration; } -void SetAlpha::update(Source *s, float) +void SetAlpha::update(Source *s, float dt) { if (s && !s->locked()) { // set start position on first run or upon call of reset() if (!initialized_){ - // initial position - pos_ = glm::vec2(s->group(View::MIXING)->translation_); + // initial mixing view position + start_ = glm::vec2(s->group(View::MIXING)->translation_); + + // step in diagonal by default + glm::vec2 step = glm::normalize(glm::vec2(1.f, 1.f)); // step in direction of source translation if possible - if ( glm::length(pos_) > DELTA_ALPHA) - step_ = glm::normalize(pos_); + if ( glm::length(start_) > DELTA_ALPHA) + step = glm::normalize(start_); + // + // target mixing view position + // + // special case Alpha = 0 + if (alpha_ < DELTA_ALPHA) { + target_ = step; + } + // special case Alpha = 1 + else if (alpha_ > 1.f - DELTA_ALPHA) { + target_ = step * 0.005f; + } + // general case + else { + // converge to reduce the difference of alpha using dichotomic algorithm + target_ = start_; + float delta = 1.f; + do { + target_ += step * (delta / 2.f); + delta = SourceCore::alphaFromCordinates(target_.x, target_.y) - alpha_; + } while (glm::abs(delta) > DELTA_ALPHA); + } initialized_ = true; } - // perform operation - float delta = SourceCore::alphaFromCordinates(pos_.x, pos_.y) - alpha_; + // time passed + progress_ += dt; - // converge to reduce the difference of alpha using dichotomic algorithm - if ( glm::abs(delta) > DELTA_ALPHA ){ - pos_ += step_ * (delta / 2.f); - s->group(View::MIXING)->translation_ = glm::vec3(pos_, s->group(View::MIXING)->translation_.z); - } - // reached alpha target - else { + // perform movement + if ( ABS(duration_) > 0.f) + s->group(View::MIXING)->translation_ = glm::vec3(start_ + (progress_/duration_) * target_, s->group(View::MIXING)->translation_.z); + + // time-out + if ( progress_ > duration_ ) { + // apply depth to target + s->group(View::MIXING)->translation_ = glm::vec3(target_, s->group(View::MIXING)->translation_.z); + // done finished_ = true; } + } else finished_ = true; @@ -378,6 +406,12 @@ SourceCallback *Play::reverse(Source *s) const return new Play(s->playing()); } +void Play::accept(Visitor& v) +{ + SourceCallback::accept(v); + v.visit(*this); +} + RePlay::RePlay() : SourceCallback() { } diff --git a/SourceCallback.h b/SourceCallback.h index 2c5b4f4..7650397 100644 --- a/SourceCallback.h +++ b/SourceCallback.h @@ -12,16 +12,16 @@ public: typedef enum { CALLBACK_GENERIC = 0, - CALLBACK_ALPHA, - CALLBACK_LOOM, - CALLBACK_GRAB, - CALLBACK_RESIZE, - CALLBACK_TURN, - CALLBACK_DEPTH, - CALLBACK_PLAY, - CALLBACK_REPLAY, - CALLBACK_RESETGEO, - CALLBACK_LOCK + CALLBACK_ALPHA = 1, + CALLBACK_LOOM = 2, + CALLBACK_GRAB = 3, + CALLBACK_RESIZE = 4, + CALLBACK_TURN = 5, + CALLBACK_DEPTH = 6, + CALLBACK_PLAY = 7, + CALLBACK_REPLAY = 8, + CALLBACK_RESETGEO = 9, + CALLBACK_LOCK = 10 } CallbackType; static SourceCallback *create(CallbackType type); @@ -56,16 +56,20 @@ public: class SetAlpha : public SourceCallback { + float duration_; + float progress_; float alpha_; - glm::vec2 pos_; - glm::vec2 step_; + glm::vec2 start_; + glm::vec2 target_; public: SetAlpha (); - SetAlpha (float alpha); + SetAlpha (float alpha, float duration = 0.f); float value () const { return alpha_;} void setValue (float a) { alpha_ = a; } + float duration () const { return duration_;} + void setDuration (float d) { duration_ = d; } void update (Source *s, float) override; void multiply (float factor) override; @@ -154,6 +158,7 @@ public: SourceCallback *clone() const override; SourceCallback *reverse(Source *s) const override; CallbackType type () const override { return CALLBACK_PLAY; } + void accept (Visitor& v) override; }; class RePlay : public SourceCallback diff --git a/Visitor.h b/Visitor.h index 7c9ed44..a8189c3 100644 --- a/Visitor.h +++ b/Visitor.h @@ -48,6 +48,7 @@ class Loom; class Grab; class Resize; class Turn; +class Play; // Declares the interface for the visitors @@ -101,6 +102,7 @@ public: virtual void visit (Grab&) {} virtual void visit (Resize&) {} virtual void visit (Turn&) {} + virtual void visit (Play&) {} };