Class thl::dsp::metronome::MetronomePlayerImpl#

class MetronomePlayerImpl : public thl::dsp::BaseProcessor#

Inheritance diagram for thl::dsp::metronome::MetronomePlayerImpl:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "2" [label="thl::dsp::BaseProcessor" tooltip="thl::dsp::BaseProcessor"] "1" [label="thl::dsp::metronome::MetronomePlayerImpl" tooltip="thl::dsp::metronome::MetronomePlayerImpl" fillcolor="#BFBFBF"] "1" -> "2" [dir=forward tooltip="public-inheritance"] }

Collaboration diagram for thl::dsp::metronome::MetronomePlayerImpl:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "3" [label="std::array< thl::dsp::metronome::MetronomePlayerImpl::Voice, k_num_voices >" tooltip="std::array< thl::dsp::metronome::MetronomePlayerImpl::Voice, k_num_voices >"] "2" [label="thl::dsp::BaseProcessor" tooltip="thl::dsp::BaseProcessor"] "1" [label="thl::dsp::metronome::MetronomePlayerImpl" tooltip="thl::dsp::metronome::MetronomePlayerImpl" fillcolor="#BFBFBF"] "4" [label="thl::dsp::metronome::MetronomePlayerImpl::Voice" tooltip="thl::dsp::metronome::MetronomePlayerImpl::Voice"] "5" [label="thl::dsp::utils::ADSR" tooltip="thl::dsp::utils::ADSR"] "3" -> "4" [dir=forward tooltip="usage"] "1" -> "2" [dir=forward tooltip="public-inheritance"] "1" -> "3" [dir=forward tooltip="usage"] "4" -> "5" [dir=forward tooltip="usage"] }

Sample-accurate metronome processor driven by a TransportClock.

Mixes its output into the buffer (additive), so it can be placed anywhere in the audio processing chain without silencing upstream signal. Uses a voice pool with ADSR-shaped decaying sines for click sounds.

Two sounds: Accent — bar downbeat: 800 Hz, 20 ms exponential decay Click — beat/division: 1200 Hz, 12 ms exponential decay

Override trigger_accent(), trigger_click(), and tick_voices() to replace the built-in sine clicks with custom sounds (e.g. sample playback).

Lifetime

The TransportClock reference passed in must outlive this player.

Modulation

The Rhythm parameter is sampled once per process() block; sub-block change points are not honored. Gain and Enabled may modulate per-trigger.

Real-Time Safety

process() is real-time safe — no allocation, no locks.

Public Functions

explicit MetronomePlayerImpl(transport::TransportClock &clock)#
virtual void prepare(const double &sample_rate, const size_t &samples_per_block, const size_t &num_channels) override#
virtual void process(thl::core::BufferView buffer, uint32_t modulation_offset = 0) override#

Protected Types

enum Parameter#

Values:

enumerator Enabled#

bool — metronome on/off

enumerator Gain#

float — master volume (0.0–1.0)

enumerator Rhythm#

int — subdivision (0=Bar, 1=Half, 2=Beat, 3=Eighth, 4=Sixteenth)

enumerator NumParameters#

Protected Functions

virtual void trigger_accent()#

Called at the exact sample where a bar boundary falls.

virtual void trigger_click()#

Called at the exact sample where a rhythm boundary falls.

virtual float tick_voices()#

Render one sample from all active voices. Called once per sample.

Voice &pick_voice()#

Protected Attributes

std::array<Voice, k_num_voices> m_voices#

Protected Static Attributes

static constexpr int k_num_voices = 4#

Number of voices in the pool.

Each trigger claims the quietest voice, so overlapping clicks fade out naturally without phase discontinuities. 4 is generous headroom — at most 2 clicks overlap in practice, but 4 keeps us safe if decay times are extended or divisions are very fast.

static constexpr float k_attack_ms = 1.5f#
static constexpr float k_accent_freq = 800.0f#
static constexpr float k_accent_decay_ms = 20.0f#
static constexpr float k_click_freq = 1200.0f#
static constexpr float k_click_decay_ms = 12.0f#
static constexpr float k_accent_gain_factor = 1.0f#

Accent gain relative to master. Bar downbeat is louder than subdivision.

static constexpr float k_click_gain_factor = 0.6f#
struct Voice#

Collaboration diagram for thl::dsp::metronome::MetronomePlayerImpl::Voice:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "1" [label="thl::dsp::metronome::MetronomePlayerImpl::Voice" tooltip="thl::dsp::metronome::MetronomePlayerImpl::Voice" fillcolor="#BFBFBF"] "2" [label="thl::dsp::utils::ADSR" tooltip="thl::dsp::utils::ADSR"] "1" -> "2" [dir=forward tooltip="usage"] }

Public Functions

void trigger(float sample_rate, float in_freq, float in_gain, float release_ms)#
float tick(float sample_rate)#

Public Members

thl::dsp::utils::ADSR m_env#
float m_phase = 0.0f#
float m_freq = 1000.0f#
float m_gain = 1.0f#