More OSC control

Grab and resize dynamically, select source by index, etc.
This commit is contained in:
Bruno Herbelin
2021-12-21 00:19:39 +01:00
parent fb7bdba388
commit 706c72fda8
5 changed files with 123 additions and 48 deletions

View File

@@ -97,11 +97,14 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m,
else if ( target.compare(OSC_CURRENT) == 0 ) else if ( target.compare(OSC_CURRENT) == 0 )
{ {
// attributes to change current // attributes to change current
if ( attribute.compare(OSC_CURRENT_NONE) == 0) if ( attribute.compare(OSC_SET) == 0) {
Mixer::manager().unsetCurrentSource(); int index = 0;
else if ( attribute.compare(OSC_CURRENT_NEXT) == 0) m.ArgumentStream() >> index >> osc::EndMessage;
Mixer::manager().setCurrentIndex(index);
}
else if ( attribute.compare(OSC_NEXT) == 0)
Mixer::manager().setCurrentNext(); Mixer::manager().setCurrentNext();
else if ( attribute.compare(OSC_CURRENT_PREVIOUS) == 0) else if ( attribute.compare(OSC_PREVIOUS) == 0)
Mixer::manager().setCurrentPrevious(); Mixer::manager().setCurrentPrevious();
// all other attributes operate on current source // all other attributes operate on current source
else else
@@ -259,17 +262,21 @@ void Control::setSourceAttribute(Source *target, const std::string &attribute,
} }
target->call( new SetPlay(!on) ); 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' /// e.g. '/vimix/current/alpha f 0.3'
else if ( attribute.compare(OSC_SOURCE_ALPHA) == 0) { else if ( attribute.compare(OSC_SOURCE_ALPHA) == 0) {
float x = 0.f; float x = 1.f;
arguments >> x >> osc::EndMessage; arguments >> x >> osc::EndMessage;
target->call( new SetAlpha(x) ); target->call( new SetAlpha(x), true );
} }
/// e.g. '/vimix/current/transparency f 0.7' /// e.g. '/vimix/current/transparency f 0.7'
else if ( attribute.compare(OSC_SOURCE_TRANSPARENCY) == 0) { else if ( attribute.compare(OSC_SOURCE_TRANSPARENCY) == 0) {
float x = 0.f; float x = 0.f;
arguments >> x >> osc::EndMessage; 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' /// e.g. '/vimix/current/depth f 5.0'
else if ( attribute.compare(OSC_SOURCE_DEPTH) == 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) ); target->call( new SetDepth(x) );
} }
/// e.g. '/vimix/current/translation ff 10.0 2.2' /// 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; float x = 0.f, y = 0.f;
arguments >> x >> y >> osc::EndMessage; 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 #ifdef CONTROL_DEBUG
else { else {

View File

@@ -14,16 +14,19 @@
#define OSC_ALL "all" #define OSC_ALL "all"
#define OSC_SELECTED "selected" #define OSC_SELECTED "selected"
#define OSC_CURRENT "current" #define OSC_CURRENT "current"
#define OSC_CURRENT_NONE "none" #define OSC_NEXT "next"
#define OSC_CURRENT_NEXT "next" #define OSC_PREVIOUS "previous"
#define OSC_CURRENT_PREVIOUS "previous" #define OSC_SET "set"
//#define OSC_VERSION "version"
#define OSC_SOURCE_PLAY "play" #define OSC_SOURCE_PLAY "play"
#define OSC_SOURCE_PAUSE "pause" #define OSC_SOURCE_PAUSE "pause"
#define OSC_SOURCE_REPLAY "replay"
#define OSC_SOURCE_ALPHA "alpha" #define OSC_SOURCE_ALPHA "alpha"
#define OSC_SOURCE_TRANSPARENCY "transparency" #define OSC_SOURCE_TRANSPARENCY "transparency"
#define OSC_SOURCE_DEPTH "depth" #define OSC_SOURCE_DEPTH "depth"
#define OSC_SOURCE_TRANSLATE "translate" #define OSC_SOURCE_GRAB "grab"
#define OSC_SOURCE_RESIZE "resize"
class Session; class Session;
class Source; class Source;

View File

@@ -79,13 +79,14 @@ void SetDepth::update(Source *s, float dt)
} }
// calculate amplitude of movement // calculate amplitude of movement
progress_ += dt / duration_; progress_ += dt;
// perform movement // 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 // end of movement
if ( progress_ > 1.f ) { if ( progress_ > duration_ ) {
// apply depth to target // apply depth to target
s->group(View::LAYER)->translation_.z = target_; s->group(View::LAYER)->translation_.z = target_;
// ensure reordering of view // 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_) { if (s && s->playing() != play_) {
// reset on first run or upon call of reset() // call play function
if (!initialized_){ s->play(play_);
progress_ = 0.f;
initialized_ = true;
}
// increment time count
progress_ += dt;
// timeout
if ( progress_ > delay_ ) {
// call play function
s->play(play_);
// done
finished_ = true;
}
} }
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) duration_(duration), progress_(0.f)
{ {
} }
void Translation::update(Source *s, float dt) void Grab::update(Source *s, float dt)
{ {
if (s && !s->locked()) { if (s && !s->locked()) {
// reset on first run or upon call of reset() // reset on first run or upon call of reset()
@@ -145,14 +147,48 @@ void Translation::update(Source *s, float dt)
} }
// calculate amplitude of movement // calculate amplitude of movement
progress_ += dt / duration_; progress_ += dt;
// perform movement // 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); s->group(View::GEOMETRY)->translation_ = glm::vec3(pos, s->group(View::GEOMETRY)->translation_.z);
// timeout // 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 // done
finished_ = true; finished_ = true;
} }

View File

@@ -14,7 +14,9 @@ public:
CALLBACK_ALPHA, CALLBACK_ALPHA,
CALLBACK_DEPTH, CALLBACK_DEPTH,
CALLBACK_PLAY, CALLBACK_PLAY,
CALLBACK_TRANSLATION CALLBACK_REPLAY,
CALLBACK_GRAB,
CALLBACK_RESIZE
} CallbackType; } CallbackType;
SourceCallback(); SourceCallback();
@@ -61,16 +63,23 @@ public:
class SetPlay : public SourceCallback class SetPlay : public SourceCallback
{ {
bool play_; bool play_;
float delay_;
float progress_;
public: public:
SetPlay(bool on, float delay = 0.f); SetPlay(bool on);
void update(Source *s, float) override; void update(Source *s, float) override;
CallbackType type () override { return CALLBACK_PLAY; } 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 speed_;
glm::vec2 start_; glm::vec2 start_;
@@ -79,9 +88,23 @@ class Translation : public SourceCallback
float progress_; float progress_;
public: 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; 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; }
}; };

Binary file not shown.