Loading...
Searching...
No Matches
MathHelpers.hpp
1#pragma once
2
3#include <ossia/dataflow/exec_state_facade.hpp>
4#include <ossia/dataflow/token_request.hpp>
5#include <ossia/editor/scenario/time_value.hpp>
6#include <ossia/math/math_expression.hpp>
7
8#include <halp/audio.hpp>
9#include <halp/controls.hpp>
10#include <halp/meta.hpp>
11#include <halp/midi.hpp>
12
13#include <string_view>
14
15namespace Nodes
16{
17
23inline bool uses_identifier(std::string_view expr, std::string_view id) noexcept
24{
25 static constexpr auto is_ident_char = [](char c) noexcept {
26 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
27 || c == '_';
28 };
29
30 for(auto pos = expr.find(id); pos != std::string_view::npos;
31 pos = expr.find(id, pos + 1))
32 {
33 const auto end = pos + id.size();
34 const bool left_ok = (pos == 0) || !is_ident_char(expr[pos - 1]);
35 const bool right_ok = (end >= expr.size()) || !is_ident_char(expr[end]);
36 if(left_ok && right_ok)
37 return true;
38 }
39 return false;
40}
41
42template <typename State>
43static void setMathExpressionTiming(
44 State& self, int64_t input_time, int64_t prev_time, std::integral auto parent_dur)
45 = delete;
46
47template <typename State>
48static void setMathExpressionTiming(
49 State& self, int64_t input_time, int64_t prev_time,
50 std::floating_point auto parent_pos)
51{
52 self.cur_time = input_time;
53 self.cur_deltatime = (input_time - prev_time);
54 self.cur_pos = parent_pos;
55}
56
57template <typename State>
58static void setMathExpressionTiming(State& self, const halp::tick_flicks& tk)
59{
60 self.cur_time = tk.end_in_flicks;
61 self.cur_deltatime = tk.end_in_flicks - tk.start_in_flicks;
62 self.cur_pos = tk.parent_duration > 0 ? tk.relative_position : 0.;
63}
64}
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:35