Skip to content

Commit 6188673

Browse files
committed
queue: add manual output mode
1 parent e36a1ee commit 6188673

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

  • src/plugins/score-plugin-avnd/AvndProcesses

src/plugins/score-plugin-avnd/AvndProcesses/Queue.hpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#pragma once
2+
#include <ossia/network/value/value.hpp>
3+
24
#include <boost/circular_buffer.hpp>
35

46
#include <halp/controls.hpp>
57
#include <halp/meta.hpp>
6-
#include <ossia/network/value/value.hpp>
8+
#include <halp/value_types.hpp>
79

10+
#include <optional>
811

912
namespace avnd_tools
1013
{
@@ -22,7 +25,9 @@ struct Queue
2225
enum OutputMode
2326
{
2427
Always,
25-
WhenFull
28+
WhenFull,
29+
ManualBang,
30+
ManualPop,
2631
};
2732
enum OutputData
2833
{
@@ -45,6 +50,7 @@ struct Queue
4550
halp::maintained_button<"Lock"> lock;
4651
halp::enum_t<OutputMode, "Mode"> mode;
4752
halp::enum_t<OutputData, "Data"> data;
53+
halp::val_port<"Bang", std::optional<halp::impulse>> bang;
4854
} inputs;
4955

5056
struct
@@ -56,26 +62,42 @@ struct Queue
5662

5763
void operator()()
5864
{
59-
if(!inputs.input.value.valid())
60-
return;
61-
62-
if(!inputs.lock && !inputs.clear)
63-
buffer.push_back(std::move(inputs.input.value));
65+
if(inputs.input.value.valid())
66+
{
67+
if(!inputs.lock && !inputs.clear)
68+
buffer.push_back(std::move(inputs.input.value));
69+
}
6470

6571
if(inputs.clear)
6672
buffer.clear();
6773

6874
if(inputs.mode == OutputMode::WhenFull)
75+
{
6976
if(buffer.size() < buffer.capacity())
7077
return;
78+
}
79+
else if(inputs.mode == OutputMode::ManualBang)
80+
{
81+
if(!inputs.bang.value)
82+
return;
83+
}
84+
else if(inputs.mode == OutputMode::ManualPop)
85+
{
86+
if(!inputs.bang.value)
87+
return;
88+
}
7189

7290
if(buffer.empty())
7391
{
7492
if(inputs.data == OutputData::WholeBuffer)
7593
{
7694
outputs.output.value = std::vector<ossia::value>{};
77-
return;
7895
}
96+
else
97+
{
98+
outputs.output.value = ossia::value{};
99+
}
100+
return;
79101
}
80102

81103
switch(inputs.data)
@@ -88,6 +110,11 @@ struct Queue
88110
break;
89111
}
90112
}
113+
114+
if(inputs.mode == OutputMode::ManualPop)
115+
{
116+
buffer.pop_front();
117+
}
91118
}
92119
};
93120
}

0 commit comments

Comments
 (0)