Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
groove_timing_reach.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <algorithm>
7#include <cstdint>
8
9namespace pulp::timebase {
10
11// The largest absolute displacement a groove can apply to an authored tick.
12// This is a supremum, so widening an absolute selection window by this value
13// cannot miss material that the groove pulls across either edge. The function
14// intentionally accepts both the canonical timeline groove and the compact
15// realtime projector: both expose the same timing vocabulary.
16template <typename Groove> std::int64_t groove_timing_reach(const Groove& groove) noexcept {
17 if (groove.states_no_feel() || groove.timing_strength() == 0)
18 return 0;
19
20 std::int64_t reach = 0;
21 if (const auto grid = groove.swing_grid(); grid.value != 0) {
22 const auto extreme = swing_displacement(TickPosition{grid.value}, grid, groove.swing());
23 reach = extreme.value < 0 ? -extreme.value : extreme.value;
24 }
25
26 std::int64_t widest_step = 0;
27 for (const auto& step : groove.steps()) {
28 const auto offset = step.timing_offset.value;
29 widest_step = std::max(widest_step, offset < 0 ? -offset : offset);
30 }
31 return reach + widest_step;
32}
33
34} // namespace pulp::timebase
Definition beat_division.hpp:11
TickDuration swing_displacement(TickPosition position, TickDuration grid, SwingRatio ratio) noexcept
Definition quantize.hpp:114
std::int64_t groove_timing_reach(const Groove &groove) noexcept
Definition groove_timing_reach.hpp:16
Definition tick.hpp:61