Skip to content
Closed
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
58 changes: 48 additions & 10 deletions src/plugins/score-plugin-avnd/Crousti/Layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include <score/graphics/layouts/GraphicsSplitLayout.hpp>
#include <score/graphics/layouts/GraphicsTabLayout.hpp>
#include <score/graphics/widgets/QGraphicsLineEdit.hpp>
#include <score/tools/File.hpp>

#include <avnd/common/aggregates.hpp>
#include <avnd/concepts/file_port.hpp>
#include <avnd/concepts/layout.hpp>

#include <avnd/common/aggregates.hpp>
#include <avnd/concepts/midifile.hpp>
#include <avnd/concepts/soundfile.hpp>

namespace oscr
{
Expand Down Expand Up @@ -124,6 +126,41 @@ struct pmf_member_type<V T::*>
template <typename T>
using pmf_member_type_t = typename pmf_member_type<T>::type;

template <typename T>
struct SetGUIValue
{
const score::DocumentContext& ctx;
void operator()(const ossia::value& v, auto& dst) const
{
T p;
oscr::from_ossia_value(p, v, dst);
}
};

// File & folder ports: paths are stored in the document as templates
// (<PROJECT>:..., <LIBRARY>:..., or document-relative); resolve them so the
// ui items always receive a usable absolute path.
template <typename T>
requires(
avnd::soundfile_port<T> || avnd::midifile_port<T> || avnd::file_port<T>
|| requires { T::widget::folder; })
struct SetGUIValue<T>
{
const score::DocumentContext& ctx;
void operator()(const ossia::value& v, auto& dst) const
{
T p;
if(auto str = v.target<std::string>(); str && !str->empty())
oscr::from_ossia_value(
p,
ossia::value{
score::locateFilePath(QString::fromStdString(*str), ctx).toStdString()},
dst);
else
oscr::from_ossia_value(p, v, dst);
}
};

template <typename Info>
struct LayoutBuilder final : Process::LayoutBuilderBase
{
Expand All @@ -148,15 +185,15 @@ struct LayoutBuilder final : Process::LayoutBuilderBase
if constexpr(requires { sizeof(Item::value); })
{
using avnd_port_type = pmf_member_type_t<decltype(item.model)>;
avnd_port_type p;
oscr::from_ossia_value(p, inl->value(), item.value);
SetGUIValue<avnd_port_type>{doc}(inl->value(), item.value);
if constexpr(requires { rootUi->on_control_update(); })
{
QObject::connect(
inl, &Process::ControlInlet::valueChanged, &context,
[rui = rootUi, layout = this->layout, &item](const ossia::value& v) {
avnd_port_type p;
oscr::from_ossia_value(p, v, item.value);
[rui = rootUi, layout = this->layout, &item,
&ctx = static_cast<const score::DocumentContext&>(this->doc)](
const ossia::value& v) {
SetGUIValue<avnd_port_type>{ctx}(v, item.value);

rui->on_control_update();
layout->update();
Expand All @@ -166,9 +203,10 @@ struct LayoutBuilder final : Process::LayoutBuilderBase
{
QObject::connect(
inl, &Process::ControlInlet::valueChanged, &context,
[layout = this->layout, &item](const ossia::value& v) {
avnd_port_type p;
oscr::from_ossia_value(p, v, item.value);
[layout = this->layout, &item,
&ctx = static_cast<const score::DocumentContext&>(this->doc)](
const ossia::value& v) {
SetGUIValue<avnd_port_type>{ctx}(v, item.value);
layout->update();
});
}
Expand Down