Skip to content

Commit

Permalink
[core] Initial work on making halp available as a C++ module
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Nov 2, 2024
1 parent e9a0f84 commit 36ce533
Show file tree
Hide file tree
Showing 42 changed files with 163 additions and 262 deletions.
4 changes: 4 additions & 0 deletions include/avnd/binding/ossia/builtin_ports.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once
#include <avnd/concepts/processor.hpp>
#include <avnd/introspection/messages.hpp>
#include <ossia/dataflow/audio_port.hpp>
#include <ossia/dataflow/graph_node.hpp>
#include <ossia/dataflow/port.hpp>
#include <ossia/dataflow/value_port.hpp>

namespace oscr
{

Expand Down
1 change: 1 addition & 0 deletions include/avnd/binding/ossia/callbacks.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <avnd/binding/ossia/to_value.hpp>
#include <ossia/dataflow/value_port.hpp>
#include <tuplet/tuple.hpp>

namespace oscr
{
Expand Down
2 changes: 1 addition & 1 deletion include/avnd/binding/ossia/configure.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <avnd/wrappers/configure.hpp>
#include <halp/log.hpp>
// #include <halp/log.hpp>
//#include <fmt/format.h>
//#include <ossia/detail/logger.hpp>
namespace oscr
Expand Down
2 changes: 2 additions & 0 deletions include/avnd/binding/ossia/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// #include <boost/smart_ptr/atomic_shared_ptr.hpp>
#include <ossia/detail/lockfree_queue.hpp>

#include <bitset>

namespace oscr
{

Expand Down
4 changes: 2 additions & 2 deletions include/avnd/common/index_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ template <typename T>
using numbered_index_sequence_t = typename numbered_index_sequence<T>::type;

template <typename T, T... N>
static constexpr auto integer_sequence_to_array(std::integer_sequence<T, N...>)
inline constexpr auto integer_sequence_to_array(std::integer_sequence<T, N...>)
{
return std::array<T, sizeof...(N)>{N...};
}

template <typename T, T... N>
static constexpr auto integer_sequence_to_inverse_array(std::integer_sequence<T, N...>)
inline constexpr auto integer_sequence_to_inverse_array(std::integer_sequence<T, N...>)
{
if constexpr(sizeof...(N) > 0)
{
Expand Down
12 changes: 9 additions & 3 deletions include/avnd/concepts/curve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ template <typename T>
concept curve_segment_map_gamma
= requires(T t) { t.gamma = 0.f; } || requires(T t) { t.power = 0.f; };

struct dummy_function_for_curve
{
int foo = 123;
void operator()(auto x) { return foo * x; }
};

template <typename T>
concept curve_segment_map_function
= requires(T t) { t.function = [foo = 123](auto x) { return foo * x; }; }
|| requires(T t) { t.map = [foo = 123](auto x) { return foo * x; }; };
concept curve_segment_map_function = requires(T t) {
t.function = dummy_function_for_curve{};
} || requires(T t) { t.map = dummy_function_for_curve{}; };

template <typename T>
concept curve_segment_map = curve_segment_map_gamma<T> || curve_segment_map_function<T>;
Expand Down
87 changes: 47 additions & 40 deletions include/halp/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,56 @@
#include <avnd/introspection/input.hpp>
#include <avnd/wrappers/metadatas.hpp>
#include <boost/container/small_vector.hpp>
#include <halp/modules.hpp>

#include <variant>

namespace halp
{

static constexpr bool
string_matches_attribute_name(std::string_view string_a, std::string_view string_b)
{
const int N = string_a.length();
if(N != string_b.length())
return false;

for(int i = 0; i < N; i++)
{
unsigned char a = string_a[i];
unsigned char b = string_b[i];

if(a >= 'a' && a <= 'z')
a -= 'a' - 'A';
if(b >= 'a' && b <= 'z')
b -= 'a' - 'A';
if(a >= '0' && a <= '9' && a >= 'A' && a <= 'Z')
{
if(b >= '0' && b <= '9' && b >= 'A' && b <= 'Z')
{
if(a == b)
continue;
else
return false;
}
else
{
return false;
}
}
else
{
// Let's assume all special chars compare equal for now
if(!(b >= '0' && b <= '9' && b >= 'A' && b <= 'Z'))
continue;
}
}
return true;
}

}

HALP_MODULE_EXPORT
namespace halp
{
template <typename T, typename Attr>
Expand Down Expand Up @@ -84,46 +131,6 @@ bool parse_attribute(T& object, Attr& attr, auto& arg_begin, auto& arg_end)
return true;
}

static constexpr bool
string_matches_attribute_name(std::string_view string_a, std::string_view string_b)
{
const int N = string_a.length();
if(N != string_b.length())
return false;

for(int i = 0; i < N; i++)
{
unsigned char a = string_a[i];
unsigned char b = string_b[i];

if(a >= 'a' && a <= 'z')
a -= 'a' - 'A';
if(b >= 'a' && b <= 'z')
b -= 'a' - 'A';
if(a >= '0' && a <= '9' && a >= 'A' && a <= 'Z')
{
if(b >= '0' && b <= '9' && b >= 'A' && b <= 'Z')
{
if(a == b)
continue;
else
return false;
}
else
{
return false;
}
}
else
{
// Let's assume all special chars compare equal for now
if(!(b >= '0' && b <= '9' && b >= 'A' && b <= 'Z'))
continue;
}
}
return true;
}

template <typename T>
void parse_attributes(T& object, auto& init_arguments)
{
Expand Down
2 changes: 2 additions & 0 deletions include/halp/audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#include <boost/container/small_vector.hpp>
#include <cmath>
#include <halp/inline.hpp>
#include <halp/modules.hpp>
#include <halp/static_string.hpp>

#include <cstdint>
#include <functional>
#include <string_view>
HALP_MODULE_EXPORT
namespace halp
{
template <static_string Name, typename FP, static_string Desc = "">
Expand Down
2 changes: 2 additions & 0 deletions include/halp/callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

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

#include <halp/modules.hpp>
#include <halp/static_string.hpp>

#include <cassert>
#include <cstdint>
#include <string_view>

HALP_MODULE_EXPORT
namespace halp
{

Expand Down
3 changes: 2 additions & 1 deletion include/halp/controls.basic.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once
#include <halp/inline.hpp>
#include <halp/modules.hpp>
#include <halp/polyfill.hpp>
#include <halp/static_string.hpp>

#include <string_view>
#include <type_traits>

HALP_MODULE_EXPORT
namespace halp
{
/// Basic value port
Expand Down
3 changes: 2 additions & 1 deletion include/halp/controls.buttons.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once
#include <halp/inline.hpp>
#include <halp/modules.hpp>
#include <halp/polyfill.hpp>
#include <halp/static_string.hpp>
#include <halp/value_types.hpp>

#include <string_view>
#include <type_traits>

HALP_MODULE_EXPORT
namespace halp
{

Expand Down
2 changes: 2 additions & 0 deletions include/halp/controls.enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#error magic_enum is required
#endif

#include <halp/modules.hpp>
HALP_MODULE_EXPORT
namespace halp
{
/// ComboBox / Enum ///
Expand Down
8 changes: 2 additions & 6 deletions include/halp/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <boost/predef.h>
#include <halp/inline.hpp>
#include <halp/modules.hpp>
#include <halp/polyfill.hpp>
#include <halp/static_string.hpp>

Expand All @@ -16,14 +17,9 @@
#include <halp/controls.basic.hpp>
#include <halp/controls.buttons.hpp>
#include <halp/controls.enums.hpp>

#if(!BOOST_COMP_GNUC || (BOOST_COMP_GNUC >= 12)) && !defined(ESP8266)
#include <halp/controls.sliders.hpp>
#else
#define HALP_GCC10_SLIDERS_WORKAROUND 1
#include <halp/controls.sliders.gcc10.hpp>
#endif

HALP_MODULE_EXPORT
namespace halp
{

Expand Down
Loading

0 comments on commit 36ce533

Please sign in to comment.