Skip to content

Commit

Permalink
[dmx] Add range paramters on the root node
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Nov 15, 2024
1 parent 555c200 commit 0175915
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
55 changes: 53 additions & 2 deletions src/ossia/protocols/artnet/dmx_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,38 @@ struct artnet_out_visitor
}
};

struct artnet_out_var_visitor
{
dmx_range_parameter& self;
void operator()(int v) const noexcept
{
auto& buf = self.m_buffer.data;
for(int i = self.m_channel;
i < self.m_channel + self.m_bytes && i < DMX_CHANNEL_COUNT; i++)
{
buf[i] = v;
}
}
void operator()(float v) const noexcept { (*this)(int(v)); }
void operator()(bool v) const noexcept { (*this)(v ? 255 : 0); }
void operator()(const std::vector<ossia::value>& v) const noexcept
{
int N = v.size();
auto& buf = self.m_buffer.data;
int k = 0;
for(int i = self.m_channel;
i < self.m_channel + self.m_bytes && i < DMX_CHANNEL_COUNT && k < N; i++, k++)
{
buf[i] = ossia::convert<int>(v[k]);
}
}

template <typename... Args>
void operator()(const Args&...) const noexcept
{
}
};

template <>
struct artnet_out_visitor<1>
{
Expand All @@ -144,8 +176,8 @@ dmx_parameter::dmx_parameter(
net::node_base& node, dmx_buffer& buffer, const unsigned int channel, int min,
int max, int8_t bytes)
: device_parameter(
node, val_type::INT, bounding_mode::CLIP, access_mode::SET,
make_domain(min, max))
node, val_type::INT, bounding_mode::CLIP, access_mode::SET,
make_domain(min, max))
, m_bytes{bytes}
, m_buffer{buffer}
, m_channel{channel}
Expand Down Expand Up @@ -195,11 +227,30 @@ void dmx_parameter::device_update_value()
case 4:
m_current_value.apply(artnet_out_visitor<4>{*this});
break;
default:
}

m_buffer.dirty = true;
}

dmx_range_parameter::dmx_range_parameter(
net::node_base& node, dmx_buffer& buffer, dmx_range range, int min, int max)
: device_parameter(
node, val_type::LIST, bounding_mode::CLIP, access_mode::SET,
make_domain(min, max))
, m_bytes(range.num_bytes)
, m_buffer{buffer}
, m_channel(range.start)
{
}

dmx_range_parameter::~dmx_range_parameter() = default;
void dmx_range_parameter::device_update_value()
{
m_current_value.apply(artnet_out_var_visitor{*this});
m_buffer.dirty = true;
}

static ossia::domain_base<std::string> keys_to_domain(const auto& values)
{
ossia::domain_base<std::string> ret;
Expand Down
36 changes: 35 additions & 1 deletion src/ossia/protocols/artnet/dmx_parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ namespace ossia::net
{

template <std::size_t I>
struct artnet_visitor;
struct artnet_in_visitor;
template <std::size_t I>
struct artnet_out_visitor;
struct artnet_out_var_visitor;
struct dmx_buffer;
struct dmx_range
{
int start{};
int num_bytes{};
};
class OSSIA_EXPORT dmx_parameter : public device_parameter
{
public:
Expand All @@ -36,6 +44,7 @@ class OSSIA_EXPORT dmx_parameter : public device_parameter
friend struct artnet_in_visitor;
template <std::size_t I>
friend struct artnet_out_visitor;
friend struct artnet_out_var_visitor;
};

class OSSIA_EXPORT dmx_enum_parameter : public device_parameter
Expand All @@ -56,6 +65,31 @@ class OSSIA_EXPORT dmx_enum_parameter : public device_parameter
friend struct artnet_enum_visitor;
};

class OSSIA_EXPORT dmx_range_parameter : public device_parameter
{
public:
dmx_range_parameter(
net::node_base& node, dmx_buffer& buffer, dmx_range range, int min = 0,
int max = 255);
~dmx_range_parameter();

uint32_t channel() const noexcept { return m_channel; }

void set_dmx_value(const uint8_t* start, const uint8_t* buffer_end);

private:
void device_update_value() override;

dmx_buffer& m_buffer;
int16_t m_bytes{};
int16_t m_channel{};

template <std::size_t I>
friend struct artnet_in_visitor;
template <std::size_t I>
friend struct artnet_out_visitor;
friend struct artnet_out_var_visitor;
};
/*
struct artnet_range_element {
std::string name;
Expand Down
2 changes: 2 additions & 0 deletions src/ossia/protocols/artnet/dmx_protocol_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ void dmx_protocol_base::set_device(ossia::net::device_base& dev)
if(m_conf.autocreate != m_conf.no_auto)
{
auto& root = dev.get_root_node();
root.set_parameter(std::make_unique<ossia::net::dmx_range_parameter>(
root, m_buffer, ossia::net::dmx_range{0, 512}, 0, 255));
for(unsigned int i = 0; i < DMX_CHANNEL_COUNT; ++i)
{
auto name = m_conf.autocreate == m_conf.channel_index
Expand Down

0 comments on commit 0175915

Please sign in to comment.