diff --git a/ControlManager.cpp b/ControlManager.cpp index e4153b7..f778eaa 100644 --- a/ControlManager.cpp +++ b/ControlManager.cpp @@ -97,11 +97,14 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m, else if ( target.compare(OSC_CURRENT) == 0 ) { // attributes to change current - if ( attribute.compare(OSC_CURRENT_NONE) == 0) - Mixer::manager().unsetCurrentSource(); - else if ( attribute.compare(OSC_CURRENT_NEXT) == 0) + if ( attribute.compare(OSC_SET) == 0) { + int index = 0; + m.ArgumentStream() >> index >> osc::EndMessage; + Mixer::manager().setCurrentIndex(index); + } + else if ( attribute.compare(OSC_NEXT) == 0) Mixer::manager().setCurrentNext(); - else if ( attribute.compare(OSC_CURRENT_PREVIOUS) == 0) + else if ( attribute.compare(OSC_PREVIOUS) == 0) Mixer::manager().setCurrentPrevious(); // all other attributes operate on current source else @@ -259,17 +262,21 @@ void Control::setSourceAttribute(Source *target, const std::string &attribute, } target->call( new SetPlay(!on) ); } + /// e.g. '/vimix/current/replay' + else if ( attribute.compare(OSC_SOURCE_REPLAY) == 0) { + target->call( new RePlay() ); + } /// e.g. '/vimix/current/alpha f 0.3' else if ( attribute.compare(OSC_SOURCE_ALPHA) == 0) { - float x = 0.f; + float x = 1.f; arguments >> x >> osc::EndMessage; - target->call( new SetAlpha(x) ); + target->call( new SetAlpha(x), true ); } /// e.g. '/vimix/current/transparency f 0.7' else if ( attribute.compare(OSC_SOURCE_TRANSPARENCY) == 0) { float x = 0.f; arguments >> x >> osc::EndMessage; - target->call( new SetAlpha(1.f - x) ); + target->call( new SetAlpha(1.f - x), true ); } /// e.g. '/vimix/current/depth f 5.0' else if ( attribute.compare(OSC_SOURCE_DEPTH) == 0) { @@ -278,10 +285,16 @@ void Control::setSourceAttribute(Source *target, const std::string &attribute, target->call( new SetDepth(x) ); } /// e.g. '/vimix/current/translation ff 10.0 2.2' - else if ( attribute.compare(OSC_SOURCE_TRANSLATE) == 0) { + else if ( attribute.compare(OSC_SOURCE_GRAB) == 0) { float x = 0.f, y = 0.f; arguments >> x >> y >> osc::EndMessage; - target->call( new Translation( x, y), true ); + target->call( new Grab( x, y), true ); + } + /// e.g. '/vimix/current/scale ff 10.0 2.2' + else if ( attribute.compare(OSC_SOURCE_RESIZE) == 0) { + float x = 0.f, y = 0.f; + arguments >> x >> y >> osc::EndMessage; + target->call( new Resize( x, y), true ); } #ifdef CONTROL_DEBUG else { diff --git a/ControlManager.h b/ControlManager.h index c412a18..6701443 100644 --- a/ControlManager.h +++ b/ControlManager.h @@ -14,16 +14,19 @@ #define OSC_ALL "all" #define OSC_SELECTED "selected" #define OSC_CURRENT "current" -#define OSC_CURRENT_NONE "none" -#define OSC_CURRENT_NEXT "next" -#define OSC_CURRENT_PREVIOUS "previous" +#define OSC_NEXT "next" +#define OSC_PREVIOUS "previous" +#define OSC_SET "set" +//#define OSC_VERSION "version" #define OSC_SOURCE_PLAY "play" #define OSC_SOURCE_PAUSE "pause" +#define OSC_SOURCE_REPLAY "replay" #define OSC_SOURCE_ALPHA "alpha" #define OSC_SOURCE_TRANSPARENCY "transparency" #define OSC_SOURCE_DEPTH "depth" -#define OSC_SOURCE_TRANSLATE "translate" +#define OSC_SOURCE_GRAB "grab" +#define OSC_SOURCE_RESIZE "resize" class Session; class Source; diff --git a/SourceCallback.cpp b/SourceCallback.cpp index 96556d5..f8d6693 100644 --- a/SourceCallback.cpp +++ b/SourceCallback.cpp @@ -79,13 +79,14 @@ void SetDepth::update(Source *s, float dt) } // calculate amplitude of movement - progress_ += dt / duration_; + progress_ += dt; // perform movement - s->group(View::LAYER)->translation_.z = start_ + progress_ * (target_ - start_); + if ( ABS(duration_) > 0.f) + s->group(View::LAYER)->translation_.z = start_ + (progress_/duration_) * (target_ - start_); // end of movement - if ( progress_ > 1.f ) { + if ( progress_ > duration_ ) { // apply depth to target s->group(View::LAYER)->translation_.z = target_; // ensure reordering of view @@ -99,40 +100,41 @@ void SetDepth::update(Source *s, float dt) } -SetPlay::SetPlay(bool on, float delay) : SourceCallback(), play_(on), delay_(delay), progress_(0.f) +SetPlay::SetPlay(bool on) : SourceCallback(), play_(on) { } -void SetPlay::update(Source *s, float dt) +void SetPlay::update(Source *s, float) { if (s && s->playing() != play_) { - // reset on first run or upon call of reset() - if (!initialized_){ - progress_ = 0.f; - initialized_ = true; - } - - // increment time count - progress_ += dt; - - // timeout - if ( progress_ > delay_ ) { - // call play function - s->play(play_); - // done - finished_ = true; - } + // call play function + s->play(play_); } - else - finished_ = true; + + finished_ = true; } -Translation::Translation(float dx, float dy, float duration) : SourceCallback(), speed_(glm::vec2(dx,dy)), +RePlay::RePlay() : SourceCallback() +{ +} + +void RePlay::update(Source *s, float) +{ + if (s) { + // call replay function + s->replay(); + } + + finished_ = true; +} + + +Grab::Grab(float dx, float dy, float duration) : SourceCallback(), speed_(glm::vec2(dx,dy)), duration_(duration), progress_(0.f) { } -void Translation::update(Source *s, float dt) +void Grab::update(Source *s, float dt) { if (s && !s->locked()) { // reset on first run or upon call of reset() @@ -145,14 +147,48 @@ void Translation::update(Source *s, float dt) } // calculate amplitude of movement - progress_ += dt / duration_; + progress_ += dt; // perform movement - glm::vec2 pos = start_ + speed_ * dt; + glm::vec2 pos = start_ + speed_ * ( dt * 0.001f); s->group(View::GEOMETRY)->translation_ = glm::vec3(pos, s->group(View::GEOMETRY)->translation_.z); // timeout - if ( progress_ > 1.f ) { + if ( progress_ > duration_ ) { + // done + finished_ = true; + } + } + else + finished_ = true; +} + +Resize::Resize(float dx, float dy, float duration) : SourceCallback(), speed_(glm::vec2(dx,dy)), + duration_(duration), progress_(0.f) +{ +} + +void Resize::update(Source *s, float dt) +{ + if (s && !s->locked()) { + // reset on first run or upon call of reset() + if (!initialized_){ + // start animation + progress_ = 0.f; + // initial position + start_ = glm::vec2(s->group(View::GEOMETRY)->scale_); + initialized_ = true; + } + + // calculate amplitude of movement + progress_ += dt; + + // perform movement + glm::vec2 pos = start_ + speed_ * ( dt * 0.001f); + s->group(View::GEOMETRY)->scale_ = glm::vec3(pos, s->group(View::GEOMETRY)->scale_.z); + + // timeout + if ( progress_ > duration_ ) { // done finished_ = true; } diff --git a/SourceCallback.h b/SourceCallback.h index 30a8490..536de17 100644 --- a/SourceCallback.h +++ b/SourceCallback.h @@ -14,7 +14,9 @@ public: CALLBACK_ALPHA, CALLBACK_DEPTH, CALLBACK_PLAY, - CALLBACK_TRANSLATION + CALLBACK_REPLAY, + CALLBACK_GRAB, + CALLBACK_RESIZE } CallbackType; SourceCallback(); @@ -61,16 +63,23 @@ public: class SetPlay : public SourceCallback { bool play_; - float delay_; - float progress_; public: - SetPlay(bool on, float delay = 0.f); + SetPlay(bool on); void update(Source *s, float) override; CallbackType type () override { return CALLBACK_PLAY; } }; -class Translation : public SourceCallback +class RePlay : public SourceCallback +{ + +public: + RePlay(); + void update(Source *s, float) override; + CallbackType type () override { return CALLBACK_REPLAY; } +}; + +class Grab : public SourceCallback { glm::vec2 speed_; glm::vec2 start_; @@ -79,9 +88,23 @@ class Translation : public SourceCallback float progress_; public: - Translation(float dx, float dy, float duration = 0.f); + Grab(float dx, float dy, float duration = 0.f); void update(Source *s, float) override; - CallbackType type () override { return CALLBACK_TRANSLATION; } + CallbackType type () override { return CALLBACK_GRAB; } +}; + +class Resize : public SourceCallback +{ + glm::vec2 speed_; + glm::vec2 start_; + glm::vec2 target_; + float duration_; + float progress_; + +public: + Resize(float dx, float dy, float duration = 0.f); + void update(Source *s, float) override; + CallbackType type () override { return CALLBACK_RESIZE; } }; diff --git a/rsc/osc/vimix.tosc b/rsc/osc/vimix.tosc index cb65380..aeb8337 100644 Binary files a/rsc/osc/vimix.tosc and b/rsc/osc/vimix.tosc differ