Skip to content

Commit

Permalink
esp: more freestanding work
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Dec 10, 2024
1 parent 816033b commit cd5e1d7
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 90 deletions.
55 changes: 35 additions & 20 deletions minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ include(${OSSIA_ROOT}/src/ossia_sources.cmake)
configure_file(${OSSIA_ROOT}/src/ossia-config.hpp.in ossia-config.hpp)

add_library(ossia)
target_compile_options(ossia PRIVATE -std=c++23 -fno-exceptions -fno-rtti -fno-asynchronous-unwind-tables)
target_compile_definitions(ossia PRIVATE OSSIA_EXPORTS=1 OSSIA_FREESTANDING=1 OSSIA_EDITOR=1 OSSIA_SCENARIO_DATAFLOW=1)
target_link_libraries(ossia PRIVATE -Wl,-z,defs -fuse-ld=mold)
target_include_directories(ossia PRIVATE /home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/boost_1_86_0)
target_compile_options(ossia PUBLIC -std=c++23 -fno-exceptions -fno-rtti -fno-asynchronous-unwind-tables)
target_compile_definitions(ossia PUBLIC
OSSIA_EXPORTS=1
OSSIA_FREESTANDING=1
OSSIA_EDITOR=1
OSSIA_SCENARIO_DATAFLOW=1
LIBREMIDI_HEADER_ONLY=1
)
target_link_libraries(ossia PUBLIC -Wl,-z,defs -fuse-ld=mold)
target_include_directories(ossia PUBLIC /home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/boost_1_86_0)

target_include_directories(ossia SYSTEM PRIVATE
target_include_directories(ossia SYSTEM PUBLIC
${OSSIA_ROOT}/src
#$<BUILD_INTERFACE:${OSSIA_3RDPARTY_FOLDER}/compile-time-regular-expressions/include>
$<BUILD_INTERFACE:${OSSIA_3RDPARTY_FOLDER}/nano-signal-slot/include>
Expand All @@ -33,6 +39,10 @@ set(SOURCE_FILES
"${SRC}/detail/thread.cpp"
"${SRC}/detail/any_map.cpp"

"${SRC}/audio/audio_parameter.cpp"
"${SRC}/audio/audio_device.cpp"
"${SRC}/audio/audio_engine.cpp"

"${SRC}/network/base/device.cpp"
"${SRC}/network/base/protocol.cpp"
"${SRC}/network/base/parameter.cpp"
Expand Down Expand Up @@ -60,7 +70,12 @@ set(SOURCE_FILES
"${SRC}/dataflow/data.cpp"
"${SRC}/dataflow/port.cpp"
"${SRC}/dataflow/graph_node.cpp"
"${SRC}/dataflow/graph/graph.cpp"
"${SRC}/dataflow/execution_state.cpp"
"${SRC}/dataflow/execution/execution_policy.cpp"
"${SRC}/dataflow/execution/default_policy.cpp"
"${SRC}/dataflow/execution/merged_policy.cpp"
"${SRC}/dataflow/execution/local_state_execution_policy.cpp"
"${SRC}/dataflow/nodes/state.cpp"

"${SRC}/editor/curve/curve.cpp"
Expand Down Expand Up @@ -89,6 +104,8 @@ set(SOURCE_FILES
"${SRC}/editor/scenario/detail/scenario_execution.cpp"
)

add_executable(test_minimal test.cpp)
target_link_libraries(test_minimal PRIVATE ossia)

target_sources(ossia PRIVATE ${SOURCE_FILES})

Expand All @@ -102,19 +119,19 @@ install(DIRECTORY "${SRC}" DESTINATION src
FILES_MATCHING PATTERN "*.hpp")


install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/nano-signal-slot/include/" DESTINATION src)
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/tuplet/include/" DESTINATION src)
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/SmallFunction/smallfun/include/" DESTINATION src)
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/span/include/" DESTINATION src)
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/unordered_dense/include/" DESTINATION src)
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/libremidi/include/" DESTINATION src)
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/concurrentqueue/" DESTINATION src
FILES_MATCHING
PATTERN "*.h"
PATTERN "*/build*" EXCLUDE
PATTERN "*/tests*" EXCLUDE
PATTERN "*/benchmarks*" EXCLUDE
)
# install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/nano-signal-slot/include/" DESTINATION src)
# install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/tuplet/include/" DESTINATION src)
# install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/SmallFunction/smallfun/include/" DESTINATION src)
# install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/span/include/" DESTINATION src)
# install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/unordered_dense/include/" DESTINATION src)
# install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/libremidi/include/" DESTINATION src)
# install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/concurrentqueue/" DESTINATION src
# FILES_MATCHING
# PATTERN "*.h"
# PATTERN "*/build*" EXCLUDE
# PATTERN "*/tests*" EXCLUDE
# PATTERN "*/benchmarks*" EXCLUDE
# )
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/boost_1_86_0/boost" DESTINATION include)
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/nano-signal-slot/include/" DESTINATION include)
install(DIRECTORY "${OSSIA_3RDPARTY_FOLDER}/tuplet/include/" DESTINATION include)
Expand All @@ -134,8 +151,6 @@ foreach(file ${SOURCE_FILES})
get_filename_component(_fileName "${file}" NAME)
string(REPLACE "${SRC}/" "" _fileDir "${file}")
string(REPLACE "${_fileName}" "" _fileDir "${_fileDir}")
# get_filename_component(_fileDir "${file}" ABSOLUTE BASE_DIR "${SRC}")
message(" => '${_fileName}' :: '${_fileDir}'")
install(FILES "${file}" DESTINATION "src/ossia/${_fileDir}")
endforeach()

Expand Down
2 changes: 2 additions & 0 deletions src/ossia/audio/audio_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <smallfun.hpp>

#include <atomic>

#include <ossia-config.hpp>

namespace ossia
Expand Down
2 changes: 2 additions & 0 deletions src/ossia/audio/audio_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ audio_parameter::audio_parameter(net::node_base& n)
m_type = parameter_type::AUDIO;
}

audio_parameter::~audio_parameter() = default;

void audio_parameter::clone_value(audio_vector& res_vec) const
{
if(res_vec.size() < audio.size())
Expand Down
14 changes: 14 additions & 0 deletions src/ossia/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ boost::asio::detail::winsock_init<2, 2>::manual manual_winsock_init;
#include <boost/asio/detail/winsock_init.hpp>
#endif

#if !defined(__cpp_exceptions)
#include <boost/throw_exception.hpp>
namespace boost
{
void throw_exception(std::exception const& e)
{
std::terminate();
}
void throw_exception(std::exception const& e, boost::source_location const& loc)
{
std::terminate();
}
}
#endif
namespace ossia
{
#if defined(__cpp_exceptions)
Expand Down
2 changes: 2 additions & 0 deletions src/ossia/dataflow/execution/merged_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void merged_execution_state_policy::commit()
commit_common();
}

#if !defined(OSSIA_FREESTANDING)
threaded_merged_execution_state_policy::threaded_merged_execution_state_policy()
{
m_valuesOutputThread = std::thread{[this] {
Expand Down Expand Up @@ -112,4 +113,5 @@ void threaded_merged_execution_state_policy::commit()

commit_common();
}
#endif
}
2 changes: 2 additions & 0 deletions src/ossia/dataflow/execution_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void execution_state::set_policy(const tick_setup_options& opt)
{
switch(opt.commit)
{
#if !defined(OSSIA_FREESTANDING)
case tick_setup_options::Default:
m_policy = std::make_unique<default_execution_state_policy>();
return;
Expand All @@ -38,6 +39,7 @@ void execution_state::set_policy(const tick_setup_options& opt)
case tick_setup_options::Priorized:
m_policy = std::make_unique<priorized_execution_state_policy>();
return;
#endif
case tick_setup_options::Merged:
m_policy = std::make_unique<merged_execution_state_policy>();
return;
Expand Down
11 changes: 8 additions & 3 deletions src/ossia/dataflow/graph/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <ossia/network/value/format_value.hpp>

#include <boost/pool/pool.hpp>

#if !defined(OSSIA_FREESTANDING)
#include <spdlog/spdlog.h>
#endif
namespace ossia
{
using boost_pool = boost::pool<boost::default_user_allocator_malloc_free>;
Expand Down Expand Up @@ -79,8 +80,10 @@ graph_interface::graph_interface()
: pool{std::make_shared<edge_pool>()}
{
// Reserve some space
#if !defined(OSSIA_FREESTANDING)
auto arr = pool->pool.ordered_malloc(1000);
pool->pool.ordered_free(arr);
#endif
}

edge_ptr graph_interface::allocate_edge(
Expand Down Expand Up @@ -406,6 +409,7 @@ void graph_util::check_outputs(
}
void graph_util::log_inputs(const graph_node& n, ossia::logger_type& logger)
{
#if !defined(OSSIA_FREESTANDING)
int i = 0;
struct
{
Expand Down Expand Up @@ -462,10 +466,12 @@ void graph_util::log_inputs(const graph_node& n, ossia::logger_type& logger)
} vis{logger, i, n.processed_frames()};

for_each_inlet(n, [&](auto& in) { in.visit(vis); });
#endif
}

void graph_util::log_outputs(const graph_node& n, ossia::logger_type& logger)
{
#if !defined(OSSIA_FREESTANDING)
int i = 0;
struct
{
Expand Down Expand Up @@ -521,10 +527,9 @@ void graph_util::log_outputs(const graph_node& n, ossia::logger_type& logger)
} vis{logger, i, n.processed_frames()};

for_each_outlet(n, [&](auto& out) { out.visit(vis); });
#endif
}
graph_interface::~graph_interface() = default;
audio_parameter::~audio_parameter() = default;

graph::~graph()
{
clear();
Expand Down
2 changes: 2 additions & 0 deletions src/ossia/dataflow/graph/graph_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ struct graph_static final
explicit graph_static(const ossia::graph_setup_options& opt = {})
: update_fun{*this, opt}
{
#if !defined(OSSIA_FREESTANDING)
m_all_nodes.reserve(1024);
m_enabled_cache.reserve(1024);
m_topo_order_cache.reserve(1024);
m_color_map_cache.reserve(1024);
m_stack_cache.reserve(1024);
#endif
}
~graph_static() override { clear(); }

Expand Down
6 changes: 6 additions & 0 deletions src/ossia/dataflow/graph/graph_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,11 @@ struct OSSIA_EXPORT graph_base : graph_interface
{
graph_base() noexcept
{
#if !defined(OSSIA_FREESTANDING)
m_nodes.reserve(1024);
m_node_list.reserve(1024);
m_edges.reserve(1024);
#endif
}
[[nodiscard]] tcb::span<ossia::graph_node* const>
get_nodes() const noexcept final override
Expand Down Expand Up @@ -877,7 +879,11 @@ struct OSSIA_EXPORT graph_base : graph_interface

node_map m_nodes;
edge_map m_edges;
#if defined(OSSIA_FREESTANDING)
ossia::small_vector<ossia::graph_node*, 16> m_node_list;
#else
ossia::small_vector<ossia::graph_node*, 1024> m_node_list;
#endif

graph_t m_graph;

Expand Down
2 changes: 1 addition & 1 deletion src/ossia/dataflow/graph/small_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct container_gen<smallvecS, ValueType>
// using Allocator = typename Alloc::template rebind<ValueType>::other Allocator;

// Needed because tests allocate graphs on the stack and that's too much
#if defined(OSSIA_TESTNG)
#if defined(OSSIA_TESTING) || defined(OSSIA_FREESTANDING)
static constexpr std::size_t small_vec_size = 16;
#else
static constexpr std::size_t small_vec_size = 1024;
Expand Down
42 changes: 42 additions & 0 deletions src/ossia/dataflow/nodes/sine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,46 @@ struct sine final : public ossia::nonowning_graph_node
}
}
};

struct sine_value final : public ossia::nonowning_graph_node
{
ossia::value_inlet freq_in;
ossia::value_outlet sin_out;

double m_cos = 1.;
double m_sin = 0.;

public:
double freq = 440.;
double amplitude = 0.8;
sine_value()
{
m_inlets.push_back(&freq_in);
m_outlets.push_back(&sin_out);
}

std::string label() const noexcept override { return "sine"; }
void run(const ossia::token_request& t, ossia::exec_state_facade st) noexcept override
{
auto& vals = freq_in.target<ossia::value_port>()->get_data();
if(!vals.empty())
{
freq = ossia::clamp(ossia::convert<float>(vals.back().value), 0.f, 20000.f);
}

ossia::value_port& out = *sin_out;
const auto [tick_start, N] = st.timings(t);

const auto fs = st.sampleRate();
auto frequ_cos = std::cos(ossia::two_pi * freq / fs);
auto frequ_sin = std::sin(ossia::two_pi * freq / fs);
auto new_cos = m_cos * frequ_cos - m_sin * frequ_sin;
auto new_sin = m_cos * frequ_sin + m_sin * frequ_cos;
auto norm = (new_cos * new_cos + new_sin * new_sin);
m_cos = new_cos / norm;
m_sin = new_sin / norm;

out.write_value(amplitude * m_sin, tick_start);
}
};
}
3 changes: 2 additions & 1 deletion src/ossia/dataflow/token_request_format.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <ossia/dataflow/token_request.hpp>
#include <ossia/detail/fmt.hpp>

#if !defined(OSSIA_FREESTANDING)
namespace fmt
{
template <>
Expand All @@ -23,3 +23,4 @@ struct formatter<ossia::token_request> final : formatter<string_view>
}
};
}
#endif
5 changes: 1 addition & 4 deletions src/ossia/editor/curve/curve.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <ossia/editor/curve/curve.hpp>

#if defined(__cpp_exceptions)
#include <ossia/editor/curve/behavior.hpp>
#include <ossia/editor/curve/curve.hpp>
#include <ossia/editor/curve/curve_abstract.hpp>

namespace ossia
Expand Down Expand Up @@ -37,4 +35,3 @@ void behavior::reset()
ossia::apply(behavior_reset{}, *this);
}
}
#endif
Loading

0 comments on commit cd5e1d7

Please sign in to comment.