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 namespace Nodes
14 {
15 
16 template <typename State>
17 static void setMathExpressionTiming(
18  State& self, int64_t input_time, int64_t prev_time, std::integral auto parent_dur)
19  = delete;
20 
21 template <typename State>
22 static void setMathExpressionTiming(
23  State& self, int64_t input_time, int64_t prev_time,
24  std::floating_point auto parent_dur)
25 {
26  self.cur_time = input_time;
27  self.cur_deltatime = (input_time - prev_time);
28  self.cur_pos = parent_dur > 0 ? double(input_time) / parent_dur : 0;
29 }
30 
31 template <typename State>
32 static void setMathExpressionTiming(
33  State& self, ossia::time_value input_time, ossia::time_value prev_time,
34  ossia::time_value parent_dur, double modelToSamples)
35 {
36  setMathExpressionTiming(
37  self, input_time.impl * modelToSamples, prev_time.impl * modelToSamples,
38  parent_dur.impl * modelToSamples);
39 }
40 
41 // template <typename State>
42 // static void setMathExpressionTiming(State& self, const ossia::token_request& tk, ossia::exec_state_facade st)
43 // {
44 // setMathExpressionTiming(self, tk.date, tk.prev_date, tk.parent_duration, st.modelToSamples());
45 // }
46 
47 template <typename State>
48 static void setMathExpressionTiming(State& self, const halp::tick_flicks& tk)
49 {
50  self.cur_time = tk.end_in_flicks;
51  self.cur_deltatime = tk.end_in_flicks - tk.start_in_flicks;
52  self.cur_pos = tk.parent_duration > 0 ? tk.relative_position : 0.;
53 }
54 }
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33