29 ,
public QGraphicsItem
33 : QGraphicsItem{parent}
37 void setValue(
double normalized)
40 normalized = std::clamp(normalized, 0., 1.);
41 if(normalized == m_value)
47 QRectF boundingRect()
const override {
return {0., 0., 52., 4.}; }
49 void paint(QPainter* painter,
const QStyleOptionGraphicsItem*, QWidget*)
override
51 auto& skin = score::Skin::instance();
52 const QRectF r = boundingRect();
53 painter->fillRect(r, skin.Background2.darker.brush);
54 painter->fillRect(QRectF{r.x(), r.y(), r.width() * m_value, r.height()}, skin.Base4);
74 const auto& dom = port.domain().get();
75 const auto lo = ossia::get_min(dom);
76 const auto hi = ossia::get_max(dom);
77 if(!lo.valid() || !hi.valid())
81 if(
auto a = lo.target<ossia::vec2f>())
82 if(
auto b = hi.target<ossia::vec2f>())
84 const double tl = (*a)[0], th = (*b)[0];
85 return th == tl ? 0. : std::clamp((
scalarValue(v) - tl) / (th - tl), 0., 1.);
87 return h == l ? 0. : std::clamp((
scalarValue(v) - l) / (h - l), 0., 1.);
110 Item item_init, std::vector<Process::ControlInlet*> ports,
UiEdits& edits)
112 , m_ports{std::move(ports)}
115 using values_type = std::decay_t<
decltype(this->impl.values)>;
116 if constexpr(is_value_tuple<values_type>)
118 setupRaw(std::make_index_sequence<std::tuple_size_v<values_type>>{});
126 ~CustomMultiControl()
131 m_edits.endGesture();
135 template <std::size_t... I>
136 void setupRaw(std::index_sequence<I...>)
138 (setupRawPort<I>(), ...);
141 template <std::
size_t I>
144 using transactions_type = std::decay_t<
decltype(this->impl.transactions)>;
145 if(I >= m_ports.size())
148 if constexpr(I < std::tuple_size_v<transactions_type>)
150 auto& tr = std::get<I>(this->impl.transactions);
152 tr.update = [](
const auto&) { };
154 tr.rollback = [] { };
158 auto* port = m_ports[I];
159 using value_type = std::decay_t<decltype(std::get<I>(this->impl.values))>;
160 auto show = [
this](
const ossia::value& v) {
162 oscr::from_ossia_value(v, val);
163 std::get<I>(this->impl.values) = std::move(val);
167 QObject::connect(port, &Process::ControlInlet::valueChanged,
this, show);
169 if constexpr(
requires {
170 std::get<I>(this->impl.execution_values) = std::optional<value_type>{};
174 port, [
this] {
return &std::get<I>(this->impl.execution_values); },
175 [](
const ossia::value& v) {
177 oscr::from_ossia_value(v, val);
182 if constexpr(I < std::tuple_size_v<transactions_type>)
183 setupRawTransaction<I>(port);
186 template <std::
size_t I>
189 using value_type = std::decay_t<decltype(std::get<I>(this->impl.values))>;
190 auto& tr = std::get<I>(this->impl.transactions);
191 tr.start = [
this] { start(); };
192 tr.update = [
this, port](
const value_type& val) {
193 std::get<I>(this->impl.values) = val;
194 m_edits.set(*port, oscr::to_ossia_value(val));
197 tr.commit = [
this] { commit(); };
198 tr.rollback = [
this] { rollback(); };
201 void setupNormalized()
203 const std::size_t n = std::min(m_ports.size(), std::size(this->impl.values));
204 for(std::size_t i = 0; i < n; i++)
206 auto* port = m_ports[i];
207 auto show = [
this, i, port](
const ossia::value& v) {
208 const auto n = normalize(*port, v);
209 if(n == this->impl.values[i])
211 this->impl.values[i] = n;
215 QObject::connect(port, &Process::ControlInlet::valueChanged,
this, show);
218 if constexpr(
requires { this->impl.execution_values[i] = std::optional<double>{}; })
221 [
this, i]() -> std::optional<double>* {
222 auto& shown = this->impl.execution_values;
223 return i < std::size(shown) ? &shown[i] :
nullptr;
225 [port](
const ossia::value& v) {
return normalize(*port, v); });
228 this->impl.transaction.start = [
this] { start(); };
229 this->impl.transaction.update = [
this, n](
int i,
double normalized) {
230 if(i < 0 || std::size_t(i) >= n)
232 auto& port = *m_ports[i];
233 m_edits.set(port, denormalize(port, normalized));
235 this->impl.transaction.commit = [
this] { commit(); };
236 this->impl.transaction.rollback = [
this] { rollback(); };
247 auto show = [
this, shown](
auto v) {
252 if constexpr(
requires { *dst == v; })
259 port, &Process::ControlInlet::executionValueChanged,
this,
260 [show, convert](
const ossia::value& v) {
261 show(std::make_optional(convert(v)));
263 using shown_type = std::decay_t<
decltype(*shown())>;
265 port, &Process::ControlInlet::executionReset,
this, [show] { show(shown_type{}); });
278 m_edits.endGesture();
290 const auto& dom = port.domain().get();
291 const auto lo = ossia::get_min(dom);
292 const auto hi = ossia::get_max(dom);
293 if(!lo.valid() || !hi.valid())
296 if(
auto a = lo.target<ossia::vec2f>())
297 if(
auto b = hi.target<ossia::vec2f>())
298 return {(*a)[0], (*b)[0]};
299 return {ossia::convert<double>(lo), ossia::convert<double>(hi)};
309 const auto [lo, hi] =
range(port);
310 const double v = lo + std::clamp(n, 0., 1.) * (hi - lo);
312 if(port.value().get_type() == ossia::val_type::INT)
313 return int(std::lround(v));
316 if(port.value().get_type() == ossia::val_type::VEC2F)
317 return ossia::vec2f{float(v), 0.f};
321 std::vector<Process::ControlInlet*> m_ports;