Skip to content

Commit

Permalink
[core] Continue the coroutine purge
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 29, 2024
1 parent 1338e34 commit b1e84d6
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 59 deletions.
2 changes: 1 addition & 1 deletion include/avnd/binding/max/audio_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct audio_processor

void process_inlet_control(t_symbol* s, long argc, t_atom* argv)
{
for(auto& state : implementation.full_state())
for(auto state : implementation.full_state())
{
switch(argv[0].a_type)
{
Expand Down
7 changes: 4 additions & 3 deletions include/avnd/binding/ossia/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ class safe_node_base : public safe_node_base_base<T>
template <typename Functor, typename... Args>
void process_all_ports(Args&&... args)
{
for(auto& [impl, i, o] : this->impl.full_state())
for(auto [impl, i, o] : this->impl.full_state())
{
static_assert(std::is_reference_v<decltype(impl)>);
Functor f{*this, impl, args...};
if constexpr(avnd::inputs_type<T>::size > 0)
process_inputs_impl(f, i);
Expand Down Expand Up @@ -826,7 +827,7 @@ class safe_node_base : public safe_node_base_base<T>
typename controls_input_queue<T>::i_tuple make_controls_in_tuple()
{
// We only care about the inputs of the first one, since they're all the same
for(auto& state : this->impl.full_state())
for(auto state : this->impl.full_state())
{
return avnd::control_input_introspection<T>::filter_tuple(
state.inputs, [](auto& field) { return field.value; });
Expand All @@ -837,7 +838,7 @@ class safe_node_base : public safe_node_base_base<T>
typename controls_output_queue<T>::o_tuple make_controls_out_tuple()
{
// Note that this does not yet make a lot of sens for polyphonic effects
for(auto& state : this->impl.full_state())
for(auto state : this->impl.full_state())
{
return avnd::control_output_introspection<T>::filter_tuple(
state.outputs, [](auto& field) { return field.value; });
Expand Down
8 changes: 4 additions & 4 deletions include/avnd/binding/ossia/soundfiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct soundfile_storage : soundfile_input_storage<T>
buf[i] = g->data[i].data();

// Update the port
for(auto& state : t.full_state())
for(auto state : t.full_state())
{
auto& port = avnd::pfr::get<NField>(state.inputs);
port.soundfile.data = buf.data();
Expand Down Expand Up @@ -149,7 +149,7 @@ struct soundfile_storage : soundfile_input_storage<T>
}

// Update the port
for(auto& state : t.full_state())
for(auto state : t.full_state())
{
auto& port = avnd::pfr::get<NField>(state.inputs);
port.soundfile.data = buf.data();
Expand Down Expand Up @@ -216,7 +216,7 @@ struct midifile_storage : midifile_input_storage<T>
// Store the handle to keep the memory from being freed
std::exchange(g, hdl);

for(auto& state : t.full_state())
for(auto state : t.full_state())
{
avnd::midifile_port auto& port = avnd::pfr::get<NField>(state.inputs);

Expand Down Expand Up @@ -343,7 +343,7 @@ struct raw_file_storage : raw_file_input_storage<T>
// Store the handle to keep the memory from being freed
std::exchange(g, hdl);

for(auto& state : t.full_state())
for(auto state : t.full_state())
{
avnd::raw_file_port auto& port = avnd::pfr::get<NField>(state.inputs);

Expand Down
2 changes: 1 addition & 1 deletion include/avnd/binding/ossia/time_controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct time_control_storage : time_control_input_storage<T>
auto& g = get<N>(this->handles);
if(g.sync)
{
for(auto& state : t.full_state())
for(auto state : t.full_state())
{
auto& port = avnd::pfr::get<NField>(state.inputs);
port.value = to_seconds(g.value, new_tempo);
Expand Down
2 changes: 1 addition & 1 deletion include/avnd/binding/pd/audio_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct audio_processor

void process_inlet_control(t_symbol* s, int argc, t_atom* argv)
{
for(auto& state : implementation.full_state())
for(auto state : implementation.full_state())
{
switch(argv[0].a_type)
{
Expand Down
6 changes: 6 additions & 0 deletions include/avnd/binding/python/processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ inline consteval const char* c_str(const char* v) noexcept
return v;
}

template <std::size_t Sz>
inline const char* c_str(const std::array<char, Sz>& v) noexcept
{
return v.data();
}

namespace py = pybind11;

template <auto Idx, typename C>
Expand Down
10 changes: 4 additions & 6 deletions include/avnd/binding/vintage/atomic_controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,13 @@ struct Controls<T>
{
std::atomic_thread_fence(std::memory_order_acquire);

[ this, &implementation ]<std::size_t... Index>(
std::integer_sequence<std::size_t, Index...>)
{
for(auto& state : implementation.full_state())
[this, &implementation]<std::size_t... Index>(
std::integer_sequence<std::size_t, Index...>) {
for(auto state : implementation.full_state())
{
(this->write_control<Index>(state.effect, state.inputs), ...);
}
}
(std::make_index_sequence<parameter_count>());
}(std::make_index_sequence<parameter_count>());
}

template <typename Effect_T>
Expand Down
2 changes: 1 addition & 1 deletion include/avnd/wrappers/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static constexpr void init_controls(F& state)
template <typename F>
static constexpr void init_controls(avnd::effect_container<F>& effect)
{
for(auto& state : effect.full_state())
for(auto state : effect.full_state())
{
init_controls(state);
}
Expand Down
7 changes: 5 additions & 2 deletions include/avnd/wrappers/controls_double.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* SPDX-License-Identifier: GPL-3.0-or-later */

#include <avnd/introspection/widgets.hpp>
#include <avnd/wrappers/avnd.hpp>
#include <cmath>

Expand Down Expand Up @@ -50,7 +51,8 @@ static constexpr auto map_control_from_double(std::floating_point auto v)
template <typename T>
static constexpr auto map_control_from_double(std::floating_point auto v)
{
static_assert(std::is_void_v<T>, "Error: unhandled control type");
// static_assert(std::is_void_v<T>, "Error: unhandled control type");
return T{};
}

template <avnd::float_parameter T>
Expand Down Expand Up @@ -89,7 +91,8 @@ static constexpr auto map_control_to_double(const auto& value)
template <typename T>
static constexpr auto map_control_to_double(const auto& value)
{
static_assert(std::is_void_v<T>, "Error: unhandled control type");
// static_assert(std::is_void_v<T>, "Error: unhandled control type");
return 0.;
}

template <avnd::parameter T>
Expand Down
99 changes: 62 additions & 37 deletions include/avnd/wrappers/effect_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ struct member_iterator_poly_effect
}

void operator++() noexcept { i++; }
auto& operator*() const noexcept { return self.effect[i]; }
auto& operator*() const noexcept
{
if constexpr(std::is_same_v<decltype(self.effect), typename T::type>)
return self.effect[i];
else
return self.effect[i].effect;
}
bool operator==(std::default_sentinel_t) const noexcept
{
return i >= self.effects.size();
return i >= self.effect.size();
}
member_iterator_poly_effect begin() const noexcept {
return *this;
Expand All @@ -58,6 +64,26 @@ struct member_iterator_poly_effect
}
};

template <typename T>
struct full_state_iterator
{
T& self;
int i = 0;
explicit full_state_iterator(T& self) noexcept
: self{self}
{
}

void operator++() noexcept { i++; }
auto operator*() const noexcept { return self.full_state(i); }
bool operator==(std::default_sentinel_t) const noexcept
{
return i >= self.effect.size();
}
full_state_iterator begin() const noexcept { return *this; }
auto end() const noexcept { return std::default_sentinel; }
};

template <typename T>
struct inputs_storage
{
Expand Down Expand Up @@ -189,9 +215,7 @@ struct effect_container<T>
auto& outputs() noexcept { return dummy_instance; }
auto& outputs() const noexcept { return dummy_instance; }

member_iterator<T> effects() {
return member_iterator_one_effect<effect_container>{*this};
}
auto effects() { return member_iterator_one_effect<effect_container>{*this}; }

struct ref
{
Expand Down Expand Up @@ -287,13 +311,10 @@ struct effect_container<T>
[[no_unique_address]] avnd::dummy outputs;
};

member_iterator<ref> full_state()
ref full_state(int i) { return {effect[i], this->inputs_storage, dummy_instance}; }
full_state_iterator<effect_container> full_state()
{
for(T& e : effect)
{
ref r{e, this->inputs_storage, dummy_instance};
co_yield r;
}
return full_state_iterator<effect_container>{*this};
}

auto effects()
Expand Down Expand Up @@ -334,13 +355,14 @@ struct effect_container<T>
typename T::outputs& outputs;
};

member_iterator<ref> full_state()
ref full_state(int i)
{
for(state& e : effect)
{
ref r{e.effect, this->inputs_storage, e.outputs_storage};
co_yield r;
}
return {effect[i].effect, this->inputs_storage, effect[i].outputs_storage};
}

full_state_iterator<effect_container> full_state()
{
return full_state_iterator<effect_container>{*this};
}

auto effects()
Expand Down Expand Up @@ -384,13 +406,15 @@ struct effect_container<T>
typename T::inputs& inputs;
decltype(T::outputs)& outputs;
};
member_iterator<ref> full_state()

ref full_state(int i)
{
for(T& e : effect)
{
ref r{e.effect, this->inputs_storage, e.effect.outputs};
co_yield r;
}
return {effect[i].effect, this->inputs_storage, effect[i].effect.outputs};
}

full_state_iterator<effect_container> full_state()
{
return full_state_iterator<effect_container>{*this};
}

auto effects()
Expand Down Expand Up @@ -438,20 +462,19 @@ struct effect_container<T>
decltype(T::inputs)& inputs;
decltype(T::outputs)& outputs;
};
member_iterator<ref> full_state()

ref full_state(int i)
{
for(T& e : effect)
{
ref r{e, e.inputs, e.outputs};
co_yield r;
}
return {effect[i].effect, effect[i].inputs, effect[i].outputs};
}

auto effects()
full_state_iterator<effect_container> full_state()
{
return member_iterator_poly_effect<effect_container>{*this};
return full_state_iterator<effect_container>{*this};
}

auto effects() { return member_iterator_poly_effect<effect_container>{*this}; }

member_iterator<decltype(T::inputs)> inputs()
{
for(auto& e : effect)
Expand Down Expand Up @@ -497,13 +520,15 @@ struct effect_container<T>

[[no_unique_address]] avnd::dummy outputs;
};
member_iterator<ref> full_state()

ref full_state(int i)
{
for(T& e : effect)
{
ref r{e.effect, e.effect.inputs, avnd::dummy_instance};
co_yield r;
}
return {effect[i].effect, effect[i].inputs, avnd::dummy_instance};
}

full_state_iterator<effect_container> full_state()
{
return full_state_iterator<effect_container>{*this};
}

auto effects()
Expand Down
3 changes: 2 additions & 1 deletion include/avnd/wrappers/process/per_sample_arg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ struct process_adapter<T>
for(int c = 0; c < channels && effects_it != effects_range.end();
++c, ++effects_it)
{
auto& [impl, ins, outs] = *effects_it;
auto [impl, ins, outs] = *effects_it;
static_assert(std::is_reference_v<decltype(impl)>);

if constexpr(avnd::has_tick<T>)
{
Expand Down
4 changes: 2 additions & 2 deletions include/avnd/wrappers/process/per_sample_port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct process_adapter<T>

// Here we know that we at least have one in and one out
template <typename FP>
FP process_0(avnd::effect_container<T>& implementation, FP in, auto& ref, auto&& tick)
FP process_0(avnd::effect_container<T>& implementation, FP in, auto ref, auto&& tick)
{
auto& [fx, ins, outs] = ref;
// Copy the input
Expand All @@ -44,7 +44,7 @@ struct process_adapter<T>
}

template <typename FP>
FP process_0(avnd::effect_container<T>& implementation, FP in, auto& ref)
FP process_0(avnd::effect_container<T>& implementation, FP in, auto ref)
{
auto& [fx, ins, outs] = ref;
// Copy the input
Expand Down
12 changes: 12 additions & 0 deletions include/halp/audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct fixed_audio_bus

FP** samples{};
HALP_INLINE_FLATTEN operator FP**() const noexcept { return samples; }
HALP_INLINE_FLATTEN auto get() const noexcept { return *this; }
HALP_INLINE_FLATTEN FP* operator[](int i) const noexcept { return samples[i]; }
HALP_INLINE_FLATTEN avnd::span<FP>
channel(std::size_t i, std::size_t frames) const noexcept
Expand All @@ -71,6 +72,7 @@ struct dynamic_audio_bus_base
int channels{};

HALP_INLINE_FLATTEN operator FP**() const noexcept { return samples; }
HALP_INLINE_FLATTEN auto get() const noexcept { return *this; }
HALP_INLINE_FLATTEN FP* operator[](int i) const noexcept { return samples[i]; }
HALP_INLINE_FLATTEN avnd::span<FP>
channel(std::size_t i, std::size_t frames) const noexcept
Expand All @@ -80,6 +82,15 @@ struct dynamic_audio_bus_base
else
return {};
}

FP** begin() noexcept { return samples; }
FP** end() noexcept { return samples + channels; }
FP* const* begin() const noexcept { return samples; }
FP* const* end() const noexcept { return samples + channels; }
FP* const* cbegin() noexcept { return samples; }
FP* const* cend() noexcept { return samples + channels; }
FP* const* cbegin() const noexcept { return samples; }
FP* const* cend() const noexcept { return samples + channels; }
};

template <static_string Name, typename FP, static_string Desc = "">
Expand Down Expand Up @@ -163,6 +174,7 @@ struct dynamic_audio_spectrum_bus
int channels{};

HALP_INLINE_FLATTEN operator FP**() const noexcept { return samples; }
HALP_INLINE_FLATTEN auto get() const noexcept { return *this; }
HALP_INLINE_FLATTEN FP* operator[](std::size_t i) const noexcept { return samples[i]; }
HALP_INLINE_FLATTEN avnd::span<FP>
channel(std::size_t i, std::size_t frames) const noexcept
Expand Down
Loading

0 comments on commit b1e84d6

Please sign in to comment.