Struct thl::dsp::sampler::LoopRegion#

struct LoopRegion#

The part of a sample a play head may play, plus its direction.

Start is the entry, End the exit and Loop the re-entry, so End before Start plays backwards. The bounds are always stored ascending ([m_start, m_end) with m_loop_point inside) and head logic runs in those “virtual” forward coordinates; a reversed region only mirrors the position that is finally read: physical = m_start + m_end - 1 - virtual.

Anything that decides what plays — markers, a slice, a host’s own logic — resolves to a LoopRegion; nothing below it needs to know which.

Public Functions

inline size_t size() const#
inline double physical(double virtual_position) const#

Virtual -> physical read position.

inline FramePos physical(FramePos virtual_position) const#

Virtual -> physical read position (integer frames).

Public Members

size_t m_start = {0}#

Lower bound, virtual entry.

size_t m_end = {0}#

Upper bound (exclusive), virtual exit.

size_t m_loop_point = {0}#

Virtual re-entry, inside [m_start, m_end].

bool m_reverse = {false}#

Plays from the top down.

Public Static Functions

static inline LoopRegion full(size_t total_frames)#

The whole sample, forwards, looping from its start.

static inline LoopRegion from_normalized(float start, float end, float loop, size_t total_frames)#

Normalised [0, 1] markers to a region.

Inputs are clamped before the size_t casts (a negative float -> size_t cast is undefined). End below Start reverses; Loop is mirrored into virtual coordinates with the bounds (see virtual_loop()).

static inline size_t to_frame(float normalized, size_t total_frames)#

One normalised marker to its frame, as from_normalized() reads it.

static inline LoopRegion from_frames(size_t start, size_t end, size_t loop, size_t total_frames)#

Start / End / Loop already in (physical) frames.

static inline size_t virtual_loop(size_t loop, size_t lo, size_t hi, bool reverse)#

Loop (a physical frame) as the virtual re-entry.

Outside the region, or on its exit (the last frame before End; for a reversed region that is the lowest frame), there is no loop body to play, so the region loops whole from its entry. A UI that clamps Loop into [Start, End] parks it on End when the markers are squeezed together; that must not leave a one-frame loop.