17 halp_meta(name,
"Table (1D)")
18 halp_meta(author,
"ossia team")
19 halp_meta(category,
"Control/Data processing")
20 halp_meta(description,
"Store arbitrary data in a 1-dimensional table")
21 halp_meta(c_name,
"avnd_table_1d")
22 halp_meta(uuid,
"a7b3c1d2-4e5f-6789-abcd-ef0123456781")
23 halp_meta(manual_url,
"https://ossia.io/score-docs/processes/table.html")
25 using value_type = ossia::value;
29 struct : halp::val_port<
"Read", std::optional<int64_t>>
38 t.outputs.output.value = ossia::value{};
42 struct : halp::val_port<
"Set", std::pair<int64_t, ossia::value>>
44 void update(
Table1D& t) { t.set(value.first, value.second); }
47 struct : halp::val_port<
"Prepend", ossia::value>
49 void update(
Table1D& t) { t.prepend(value); }
52 struct : halp::val_port<
"Append", ossia::value>
54 void update(
Table1D& t) { t.append(value); }
57 struct : halp::val_port<
"Insert", std::pair<int64_t, ossia::value>>
59 void update(
Table1D& t) { t.insert(value.first, value.second); }
62 struct : halp::val_port<
"Erase", int64_t>
64 void update(
Table1D& t) { t.erase(value); }
67 struct : halp::val_port<
"Pop front",
bool>
76 struct : halp::val_port<
"Pop back",
bool>
85 struct : halp::val_port<
"Resize", int64_t>
87 void update(
Table1D& t) { t.resize(value); }
90 struct : halp::val_port<
"Fill", ossia::value>
92 void update(
Table1D& t) { t.fill(value); }
95 halp::maintained_button<
"Clear"> clear;
96 halp::maintained_button<
"Lock"> lock;
97 struct : halp::impulse_button<
"Dump">
99 void update(
Table1D& t) { t.outputs.output.value = t.buffer; }
101 halp::toggle<
"Preserve"> preserve;
107 halp::val_port<
"Output", ossia::value> output;
108 halp::val_port<
"Front", ossia::value> front;
109 halp::val_port<
"Back", ossia::value> back;
110 halp::val_port<
"Size", int64_t> size;
111 halp::val_port<
"All", std::vector<ossia::value>> all;
114 std::vector<value_type> buffer;
116 bool read(int64_t index)
121 const std::size_t idx =
static_cast<std::size_t
>(index);
122 if(idx >= buffer.size())
125 outputs.output.value = buffer[idx];
129 void set(int64_t index,
const value_type& value)
131 if(index < 0 || index >= INT_MAX)
134 const std::size_t idx =
static_cast<std::size_t
>(index);
136 if(idx >= buffer.size())
137 buffer.resize(idx + 1);
142 void prepend(
const value_type& value) { buffer.insert(buffer.begin(), value); }
144 void append(
const value_type& value) { buffer.push_back(value); }
146 void insert(int64_t index,
const value_type& value)
151 const std::size_t idx =
static_cast<std::size_t
>(index);
153 if(idx >= buffer.size())
159 buffer.insert(buffer.begin() + idx, value);
162 void erase(int64_t index)
167 const std::size_t idx =
static_cast<std::size_t
>(index);
169 if(idx >= buffer.size())
172 buffer.erase(buffer.begin() + idx);
179 buffer.erase(buffer.begin());
189 void resize(int64_t new_size)
193 buffer.resize(
static_cast<std::size_t
>(new_size));
196 void fill(
const value_type& value) { std::fill(buffer.begin(), buffer.end(), value); }
198 void do_clear() { buffer.clear(); }
207 const std::size_t sz = buffer.size();
209 outputs.size.value =
static_cast<int64_t
>(sz);
213 outputs.front.value = buffer.front();
214 outputs.back.value = buffer.back();
218 outputs.front.value = ossia::value{};
219 outputs.back.value = ossia::value{};
222 outputs.all.value = buffer;