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
5 changes: 3 additions & 2 deletions gui/dialogs/createchasedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ void CreateChaseDialog::onCreateChaseButtonClicked() {
new_chase->SetName(folder.GetAvailableName("Chase"));
folder.Add(new_chase);

theatre::Sequence &sequence = new_chase->GetSequence();
std::vector<theatre::Input> sequence;
Gtk::TreeModel::Children children = _newChaseListModel->children();
for (const Gtk::TreeRow &row : children) {
theatre::Controllable *object = row[_newChaseListColumns._controllable];
sequence.Add(*object, 0);
sequence.emplace_back(*object, 0);
}
new_chase->SetSequence(sequence);

lock.unlock();

Expand Down
6 changes: 4 additions & 2 deletions gui/windows/chasepropertieswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ void ChasePropertiesWindow::onToTimeSequenceClicked() {
theatre::TimeSequence &tSequence = *time_sequence_ptr;
tSequence.SetRepeatCount(0);
size_t index = 0;
for (theatre::Input &input : _chase->GetSequence().List()) {
tSequence.AddStep(*input.GetControllable(), input.InputIndex());
for (const theatre::Input &input : _chase->GetSequence()) {
theatre::Controllable &controllable =
Instance::Management().GetNonConst(*input.GetControllable());
tSequence.AddStep(controllable, input.InputIndex());
theatre::TimeSequence::Step &step = tSequence.GetStep(index);
if (_chase->GetTrigger().Type() == theatre::TriggerType::Delay)
step.transition = _chase->GetTransition();
Expand Down
1 change: 1 addition & 0 deletions gui/windows/designwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "theatre/folder.h"
#include "theatre/folderoperations.h"
#include "theatre/management.h"
#include "theatre/presetcollection.h"
#include "theatre/theatre.h"
#include "theatre/timesequence.h"

Expand Down
6 changes: 3 additions & 3 deletions gui/windows/scenewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ void SceneWindow::fillControllablesList() {
_latestSelectedControllable = nullptr;
}
}
for (size_t output_index = 0; output_index != _selectedScene->NOutputs();
++output_index) {
for (size_t output_index = 0;
output_index != _selectedScene->NConnections(); ++output_index) {
std::pair<const glight::theatre::Controllable *, size_t> output =
_selectedScene->Output(output_index);
_selectedScene->GetConnection(output_index);
Gtk::TreeModel::iterator iter = _controllablesListModel->append();
Gtk::TreeModel::Row &row = *iter;
row[_controllablesListColumns._text] = output.first->Name();
Expand Down
2 changes: 1 addition & 1 deletion gui/windows/timesequencepropertieswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void TimeSequencePropertiesWindow::fillStepsList() {
for (size_t i = 0; i != _timeSequence->Size(); ++i) {
Gtk::TreeModel::iterator iter = _stepsStore->append();
Gtk::TreeModel::Row &row = *iter;
theatre::Input &input = _timeSequence->Sequence().List()[i];
const theatre::Input &input = _timeSequence->Sequence()[i];
row[_stepsListColumns._title] =
input.GetControllable()->InputName(input.InputIndex());
row[_stepsListColumns._trigger] =
Expand Down
14 changes: 8 additions & 6 deletions system/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "theatre/fixturetype.h"
#include "theatre/folder.h"
#include "theatre/management.h"
#include "theatre/presetcollection.h"
#include "theatre/presetvalue.h"
#include "theatre/theatre.h"
#include "theatre/timesequence.h"
Expand Down Expand Up @@ -320,17 +321,18 @@ void ParsePresetCollection(const Object &node, Management &management) {
}
}

void ParseSequence(const Object &node, Sequence &sequence,
Management &management) {
std::vector<Input> ParseSequence(const Object &node, Management &management) {
const Array &inputs = ToArr(node["inputs"]);
std::vector<Input> sequence;
for (Node &item_node : inputs) {
const Object &item = ToObj(item_node);
size_t input = OptionalSize(item, "input-index", 0);
size_t folderId = OptionalSize(item, "folder", 0);
Controllable &c = dynamic_cast<Controllable &>(
management.Folders()[folderId]->GetChild(ToStr(item["name"])));
sequence.Add(c, input);
sequence.emplace_back(c, input);
}
return sequence;
}

void ParseTrigger(const Object &node, Trigger &trigger) {
Expand All @@ -353,7 +355,7 @@ void ParseChase(const Object &node, Management &management) {
Chase &chase = *chase_ptr;
ParseTrigger(ToObj(node["trigger"]), chase.GetTrigger());
chase.GetTransition() = ParseTransition(ToObj(node["transition"]));
ParseSequence(ToObj(node["sequence"]), chase.GetSequence(), management);
chase.SetSequence(ParseSequence(ToObj(node["sequence"]), management));
}

void ParseTimeSequence(const Object &node, Management &management) {
Expand All @@ -363,15 +365,15 @@ void ParseTimeSequence(const Object &node, Management &management) {
TimeSequence &time_sequence = *time_sequence_ptr;
time_sequence.SetSustain(ToBool(node["sustain"]));
time_sequence.SetRepeatCount(ToNum(node["repeat-count"]).AsSize());
ParseSequence(ToObj(node["sequence"]), time_sequence.Sequence(), management);
time_sequence.SetSequence(ParseSequence(ToObj(node["sequence"]), management));
const Array &steps = ToArr(node["steps"]);
for (Node &item : steps) {
const Object &step_obj = ToObj(item);
TimeSequence::Step &step = time_sequence.Steps().emplace_back();
ParseTrigger(ToObj(step_obj["trigger"]), step.trigger);
step.transition = ParseTransition(ToObj(step_obj["transition"]));
}
if (time_sequence.Steps().size() != time_sequence.Sequence().Size())
if (time_sequence.Steps().size() != time_sequence.Sequence().size())
throw std::runtime_error(
"nr of steps in time sequence doesn't match sequence size");
}
Expand Down
15 changes: 8 additions & 7 deletions system/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "theatre/fixturetype.h"
#include "theatre/folder.h"
#include "theatre/management.h"
#include "theatre/presetcollection.h"
#include "theatre/presetvalue.h"
#include "theatre/theatre.h"
#include "theatre/timesequence.h"
Expand Down Expand Up @@ -289,7 +290,7 @@ void writePresetValue(WriteState &state, const PresetValue &presetValue) {
}

void writePresetCollection(WriteState &state,
const class PresetCollection &presetCollection) {
const PresetCollection &presetCollection) {
const std::vector<std::unique_ptr<PresetValue>> &values =
presetCollection.PresetValues();
for (const std::unique_ptr<PresetValue> &pv : values)
Expand Down Expand Up @@ -339,10 +340,10 @@ void writeTransition(WriteState &state, const Transition &transition,
state.writer.EndObject();
}

void writeSequence(WriteState &state, const Sequence &sequence) {
void writeSequence(WriteState &state, const std::vector<Input> &sequence) {
state.writer.StartObject("sequence");
state.writer.StartArray("inputs");
for (const Input &input : sequence.List()) {
for (const Input &input : sequence) {
state.writer.StartObject();
if (input.InputIndex())
state.writer.Number("input-index", input.InputIndex());
Expand All @@ -356,7 +357,7 @@ void writeSequence(WriteState &state, const Sequence &sequence) {
}

void writeChase(WriteState &state, const Chase &chase) {
const std::vector<Input> &list = chase.GetSequence().List();
const std::vector<Input> &list = chase.GetSequence();
for (const Input &input : list)
writeControllable(state, *input.GetControllable());

Expand All @@ -370,7 +371,7 @@ void writeChase(WriteState &state, const Chase &chase) {
}

void writeTimeSequence(WriteState &state, const TimeSequence &timeSequence) {
const std::vector<Input> &list = timeSequence.Sequence().List();
const std::vector<Input> &list = timeSequence.Sequence();
for (const Input &input : list)
writeControllable(state, *input.GetControllable());

Expand Down Expand Up @@ -500,8 +501,8 @@ void writeSceneItem(WriteState &state, const SceneItem &item) {
}

void writeScene(WriteState &state, const Scene &scene) {
for (size_t i = 0; i != scene.NOutputs(); ++i) {
writeControllable(state, *scene.Output(i).first);
for (size_t i = 0; i != scene.NConnections(); ++i) {
writeControllable(state, *scene.GetConnection(i).first);
}

state.writer.StartObject();
Expand Down
17 changes: 9 additions & 8 deletions tests/system/tfileformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ void FillManagement(Management &management) {
ObservingPtr<Chase> chase = management.AddChasePtr();
chase->SetName("A chase");
subFolder.Add(chase);
chase->GetSequence().Add(*a, 0);
chase->GetSequence().Add(*b, 0);
std::vector<Input> sequence{{*a, 0}, {*b, 0}};
chase->SetSequence(std::move(sequence));
management.AddSourceValue(*chase, 0);

ObservingPtr<TimeSequence> timeSequence = management.AddTimeSequencePtr();
Expand Down Expand Up @@ -186,7 +186,7 @@ void CheckEqual(const Management &a, const Management &b) {
BOOST_CHECK_EQUAL(a_fixture_control->Name(), "Control for RGBW fixture");
BOOST_CHECK_EQUAL(a_fixture_control->NInputs(),
3); // rgb filter will make it 3
BOOST_CHECK_EQUAL(a_fixture_control->NOutputs(), 0);
BOOST_CHECK_EQUAL(a_fixture_control->NConnections(), 0);
BOOST_CHECK_EQUAL(
a.GetFixtureControl(a_fixture).Get(),
&a.GetObjectFromPath(
Expand Down Expand Up @@ -219,7 +219,7 @@ void CheckEqual(const Management &a, const Management &b) {
"The root folder/A subfolder/A preset collection"));
BOOST_CHECK_EQUAL(readCollection.Name(), "A preset collection");
BOOST_CHECK_EQUAL(readCollection.NInputs(), 1);
BOOST_CHECK_EQUAL(readCollection.NOutputs(), 2);
BOOST_CHECK_EQUAL(readCollection.NConnections(), 2);
BOOST_CHECK_EQUAL(readCollection.PresetValues()[0]->Value().UInt(),
ControlValue::MaxUInt() / 2);
BOOST_CHECK_EQUAL(&readCollection.PresetValues()[0]->GetControllable(),
Expand All @@ -239,10 +239,10 @@ void CheckEqual(const Management &a, const Management &b) {

const Chase &readChase = static_cast<const Chase &>(
a.GetObjectFromPath("The root folder/A subfolder/A chase"));
BOOST_CHECK_EQUAL(readChase.GetSequence().Size(), 2);
BOOST_CHECK_EQUAL(readChase.GetSequence().List()[0].GetControllable(),
BOOST_CHECK_EQUAL(readChase.GetSequence().size(), 2);
BOOST_CHECK_EQUAL(readChase.GetSequence()[0].GetControllable(),
&readCollection);
BOOST_CHECK_EQUAL(readChase.GetSequence().List()[0].InputIndex(), 0);
BOOST_CHECK_EQUAL(readChase.GetSequence()[0].InputIndex(), 0);

const AudioLevelEffect *readEffect = dynamic_cast<const AudioLevelEffect *>(
&a.GetObjectFromPath("The root folder/Effect folder/An audio effect"));
Expand All @@ -261,7 +261,8 @@ void CheckEqual(const Management &a, const Management &b) {
const Controllable &controllable_b = *b.Controllables()[controllable_index];
BOOST_CHECK_EQUAL(controllable_a.FullPath(), controllable_b.FullPath());
BOOST_CHECK_EQUAL(controllable_a.NInputs(), controllable_b.NInputs());
BOOST_CHECK_EQUAL(controllable_a.NOutputs(), controllable_b.NOutputs());
BOOST_CHECK_EQUAL(controllable_a.NConnections(),
controllable_b.NConnections());
if (const Scene *scene_a = dynamic_cast<const Scene *>(&controllable_a);
scene_a) {
const Scene *scene_b = dynamic_cast<const Scene *>(&controllable_b);
Expand Down
7 changes: 4 additions & 3 deletions tests/theatre/tchase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ BOOST_AUTO_TEST_CASE(remove_indirect) {
pcB->SetFromCurrentSituation(management);
ObservingPtr<Chase> chase = management.AddChasePtr();
chase->SetName("chase");
Sequence &sequence = chase->GetSequence();
root.Add(chase);
sequence.Add(*pcA, 0);
sequence.Add(*pcB, 0);
std::vector<Input> sequence;
sequence.emplace_back(*pcA, 0);
sequence.emplace_back(*pcB, 0);
chase->SetSequence(sequence);
BOOST_CHECK_EQUAL(management.Controllables().size(),
4); // 1 preset, 2 collections, 1 chase
management.RemoveControllable(*pcA);
Expand Down
2 changes: 1 addition & 1 deletion tests/theatre/tfixturecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(SetValue) {
BOOST_CHECK_EQUAL(fixture.Functions().front()->MainChannel().Channel(), 100);
BOOST_CHECK(!fixture.Functions().front()->FineChannel());
control->InputValue(0) = ControlValue::Zero();
control->MixInput(0, ControlValue::Max());
control->MixInput(0, ControlValue::Max(), 0);
std::vector<unsigned> values(512, 0);
Timing timing(0.0, 0, 0, 0, 0);
control->Mix(timing, true);
Expand Down
3 changes: 2 additions & 1 deletion tests/theatre/tfolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ BOOST_AUTO_TEST_CASE(RemoveFolder) {
ObservingPtr<Chase> c = management.AddChasePtr();
c->SetName("c");
folder.Add(c);
c->GetSequence().Add(*control, 0);
std::vector<Input> sequence{{*control, 0}};
c->SetSequence(std::move(sequence));

ts1->AddStep(*c, 0);

Expand Down
2 changes: 1 addition & 1 deletion tests/theatre/tpresetcollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(SetValue) {

fixtureControl.InputValue(0) = ControlValue::Zero();
presetCollection.InputValue(0) = ControlValue::Zero();
presetCollection.MixInput(0, ControlValue::Max());
presetCollection.MixInput(0, ControlValue::Max(), 0);

std::vector<unsigned> values(512, 0);
Timing timing(0.0, 0, 0, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/theatre/ttheatre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(add_fixture) {
BOOST_CHECK(control.InputColor(0) == Color(255, 0, 0));
BOOST_CHECK(control.InputColor(1) == Color(0, 255, 0));
BOOST_CHECK(control.InputColor(2) == Color(0, 0, 255));
BOOST_CHECK_EQUAL(control.NOutputs(), 0);
BOOST_CHECK_EQUAL(control.NConnections(), 0);
BOOST_CHECK(control.InputType(0) != control.InputType(1));
BOOST_CHECK(control.InputType(1) != control.InputType(2));
}
Expand Down
25 changes: 19 additions & 6 deletions tests/theatre/ttransition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace glight {

using theatre::Connection;
using theatre::ControlValue;
using theatre::Timing;
using theatre::Transition;
Expand Down Expand Up @@ -58,34 +59,46 @@ BOOST_AUTO_TEST_CASE(fade_mix) {
const Transition t(500.0, TransitionType::Fade);

VariableEffect result_a;
t.Mix(result_a, 0, result_a, 1, 0.0, ControlValue::Max(), timing);
Connection a0{&result_a, 0, {0, 0}};
Connection a1{&result_a, 1, {0, 0}};
t.Mix(a0, a1, 0.0, ControlValue::Max(), timing, true);
BOOST_CHECK_EQUAL(result_a.InputValue(0).ToUChar(), 255);
BOOST_CHECK_EQUAL(result_a.InputValue(1).ToUChar(), 0);

VariableEffect result_b;
t.Mix(result_b, 0, result_b, 1, 500.0, ControlValue::Max() / 2, timing);
Connection b0{&result_b, 0, {0, 0}};
Connection b1{&result_b, 1, {0, 0}};
t.Mix(b0, b1, 500.0, ControlValue::Max() / 2, timing, true);
BOOST_CHECK_EQUAL(result_b.InputValue(0).ToUChar(), 0);
BOOST_CHECK_EQUAL(result_b.InputValue(1).ToUChar(), 127);

VariableEffect result_c;
t.Mix(result_c, 0, result_c, 1, 125.0, ControlValue::Max(), timing);
Connection c0{&result_c, 0, {0, 0}};
Connection c1{&result_c, 1, {0, 0}};
t.Mix(c0, c1, 125.0, ControlValue::Max(), timing, true);
BOOST_CHECK_EQUAL(result_c.InputValue(0).ToUChar(), 192);
BOOST_CHECK_EQUAL(result_c.InputValue(1).ToUChar(), 63);

// Test for time values outside the transition range
VariableEffect result_d;
t.Mix(result_d, 0, result_d, 1, -100.0, ControlValue::Max(), timing);
Connection d0{&result_d, 0, {0, 0}};
Connection d1{&result_d, 1, {0, 0}};
t.Mix(d0, d1, -100.0, ControlValue::Max(), timing, true);
BOOST_CHECK_EQUAL(result_d.InputValue(0).ToUChar(), 255);
BOOST_CHECK_EQUAL(result_d.InputValue(1).ToUChar(), 0);

VariableEffect result_e;
t.Mix(result_e, 0, result_e, 1, 600.0, ControlValue::Max(), timing);
Connection e0{&result_e, 0, {0, 0}};
Connection e1{&result_e, 1, {0, 0}};
t.Mix(e0, e1, 600.0, ControlValue::Max(), timing, true);
BOOST_CHECK_EQUAL(result_e.InputValue(0).ToUChar(), 0);
BOOST_CHECK_EQUAL(result_e.InputValue(1).ToUChar(), 255);

// Test for too high control values
VariableEffect result_f;
t.Mix(result_f, 0, result_f, 1, 500.0, ControlValue::Max() * 5u / 4, timing);
Connection f0{&result_f, 0, {0, 0}};
Connection f1{&result_f, 1, {0, 0}};
t.Mix(f0, f1, 500.0, ControlValue::Max() * 5u / 4, timing, true);
BOOST_CHECK_EQUAL(result_f.InputValue(0).ToUChar(), 0);
BOOST_CHECK_EQUAL(result_f.InputValue(1).ToUChar(), 255);
}
Expand Down
Loading
Loading