Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions theatre/effects/randomselecteffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,48 @@ class RandomSelectEffect final : public Effect {
size_t Count() const { return _count; }
void SetCount(size_t count) { _count = count; }

void SetTransition(const Transition &transition) { transition_ = transition; }
const Transition &GetTransition() const { return transition_; }

private:
virtual void MixImplementation(const ControlValue *values,
const Timing &timing, bool primary) final {
size_t n_active = std::min(_count, Connections().size());
if (values[0] && n_active != 0) {
std::vector<size_t> &activeConnections = _activeConnections[primary];
std::vector<size_t> &transition_connections =
transition_connections_[primary];
if (Connections().size() != activeConnections.size()) {
activeConnections.resize(Connections().size());
for (size_t i = 0; i != activeConnections.size(); ++i)
for (size_t i = 0; i != activeConnections.size(); ++i) {
activeConnections[i] = i;
}
transition_connections = activeConnections;
Shuffle(activeConnections, timing, false);
active_transition_[primary] = false;
}
if (!_active[primary] ||
timing.TimeInMS() - _startTime[primary] > _delay) {
const bool delay_expired =
timing.TimeInMS() - _startTime[primary] >= _delay;
if (!_active[primary] || delay_expired) {
_active[primary] = true;
_startTime[primary] = timing.TimeInMS();
transition_connections = activeConnections;
Shuffle(activeConnections, timing, true);
active_transition_[primary] = delay_expired;
}
for (size_t i = 0; i != n_active; ++i) {
if (activeConnections[i] < Connections().size()) {
const std::pair<Controllable *, size_t> &connection =
Connections()[activeConnections[i]];
connection.first->MixInput(connection.second, values[0]);
}
double transition_time;
if (active_transition_[primary]) {
transition_time = timing.TimeInMS() - _startTime[primary];
active_transition_[primary] =
transition_time < transition_.LengthInMs();
}
if (active_transition_[primary]) {
MixDirect(transition_connections,
values[0] * transition_.OutValue(transition_time, timing));
MixDirect(activeConnections,
values[0] * transition_.InValue(transition_time, timing));
} else {
MixDirect(activeConnections, values[0]);
}
} else {
_active[primary] = false;
Expand All @@ -63,12 +81,27 @@ class RandomSelectEffect final : public Effect {
}
}

void MixDirect(const std::vector<size_t> &connections,
const ControlValue value) {
size_t n_active = std::min(_count, Connections().size());
for (size_t i = 0; i != n_active; ++i) {
if (connections[i] < Connections().size()) {
const std::pair<Controllable *, size_t> &connection =
Connections()[connections[i]];
connection.first->MixInput(connection.second, value);
}
}
}

bool _active[2] = {false, false};
std::array<std::vector<size_t>, 2> _activeConnections;
std::array<std::vector<size_t>, 2> transition_connections_;
double _startTime[2] = {0.0, 0.0};
bool active_transition_[2] = {false, false};

double _delay = 10000.0;
size_t _count = 1;
Transition transition_;
};

} // namespace glight::theatre
Expand Down
27 changes: 22 additions & 5 deletions theatre/properties/randomselecteffectps.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ class RandomSelectEffectPS final : public PropertySet {
addProperty(
Property("delay", "Delay for reselection", PropertyType::Duration));
addProperty(Property("count", "Number of outputs", PropertyType::Integer));
addProperty(Property("transition", "Transition", PropertyType::Transition));
}

protected:
virtual void setDuration(FolderObject &object, size_t index,
double value) const final override {
double value) const final {
RandomSelectEffect &rfx = static_cast<RandomSelectEffect &>(object);
switch (index) {
case 0:
Expand All @@ -27,7 +28,7 @@ class RandomSelectEffectPS final : public PropertySet {
}

virtual double getDuration(const FolderObject &object,
size_t index) const final override {
size_t index) const final {
const RandomSelectEffect &rfx =
static_cast<const RandomSelectEffect &>(object);
switch (index) {
Expand All @@ -38,7 +39,7 @@ class RandomSelectEffectPS final : public PropertySet {
}

virtual void setInteger(FolderObject &object, size_t index,
int value) const final override {
int value) const final {
RandomSelectEffect &rfx = static_cast<RandomSelectEffect &>(object);
switch (index) {
case 1:
Expand All @@ -47,8 +48,7 @@ class RandomSelectEffectPS final : public PropertySet {
}
}

virtual int getInteger(const FolderObject &object,
size_t index) const final override {
virtual int getInteger(const FolderObject &object, size_t index) const final {
const RandomSelectEffect &rfx =
static_cast<const RandomSelectEffect &>(object);
switch (index) {
Expand All @@ -57,6 +57,23 @@ class RandomSelectEffectPS final : public PropertySet {
}
return 0;
}

virtual void setTransition(FolderObject &object, size_t index,
const Transition &value) const final {
RandomSelectEffect &rfx = static_cast<RandomSelectEffect &>(object);
switch (index) {
case 2:
rfx.SetTransition(value);
break;
}
}

virtual Transition getTransition(const FolderObject &object,
size_t index) const final {
const RandomSelectEffect &rfx =
static_cast<const RandomSelectEffect &>(object);
return rfx.GetTransition();
}
};

} // namespace glight::theatre
Expand Down
28 changes: 12 additions & 16 deletions theatre/transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,22 @@ ControlValue Transition::InValue(double transition_time,
return ControlValue::Zero();
}
case TransitionType::SlowStrobe:
return timing.TimestepNumber() % 8 == 0 ? ControlValue::Max()
: ControlValue::Zero();
return (timing.TimestepNumber() % 8) == 0 ? ControlValue::Max()
: ControlValue::Zero();
case TransitionType::FastStrobe:
return timing.TimestepNumber() % 2 == 0 ? ControlValue::Max()
: ControlValue::Zero();
return (timing.TimestepNumber() % 2) == 0 ? ControlValue::Max()
: ControlValue::Zero();
case TransitionType::StrobeAB:
return transition_time * 2.0 < length_in_ms_ &&
return transition_time * 2.0 >= length_in_ms_ &&
timing.TimestepNumber() % 2 == 0
? ControlValue::Max()
: ControlValue::Zero();
case TransitionType::Black:
case TransitionType::FadeToBlack:
return ControlValue::Zero();
case TransitionType::Full:
case TransitionType::FadeFromFull:
return ControlValue::Max();
case TransitionType::FadeToBlack: {
const unsigned ratio = (unsigned)((transition_time / length_in_ms_) *
ControlValue::MaxUInt());
return ControlValue(ControlValue::MaxUInt() - ratio);
}
}
assert(false);
return ControlValue::Zero();
Expand Down Expand Up @@ -173,14 +169,14 @@ ControlValue Transition::OutValue(double transition_time,
return ControlValue::Zero();
}
case TransitionType::SlowStrobe:
return timing.TimestepNumber() % 8 + 4 == 0 ? ControlValue::Max()
: ControlValue::Zero();
return (timing.TimestepNumber() % 8) == 4 ? ControlValue::Max()
: ControlValue::Zero();
case TransitionType::FastStrobe:
return timing.TimestepNumber() % 2 == 1 ? ControlValue::Max()
: ControlValue::Zero();
return (timing.TimestepNumber() % 2) == 1 ? ControlValue::Max()
: ControlValue::Zero();
case TransitionType::StrobeAB:
return transition_time * 2.0 >= length_in_ms_ &&
timing.TimestepNumber() % 2 == 0
return transition_time * 2.0 < length_in_ms_ &&
timing.TimestepNumber() % 2 == 1
? ControlValue::Max()
: ControlValue::Zero();
case TransitionType::Black:
Expand Down
2 changes: 2 additions & 0 deletions theatre/transition.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class Transition {
constexpr Transition(double length_in_ms, TransitionType type) noexcept
: length_in_ms_(length_in_ms), type_(type) {}

constexpr bool operator==(const Transition &rhs) const = default;

constexpr TransitionType Type() const { return type_; }
void SetType(TransitionType type) { type_ = type; }

Expand Down