Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::DiatonicMapT< SampleType > Class Template Reference

Key + scale interval mapper. More...

#include <harmony_engine.hpp>

Public Member Functions

 DiatonicMapT ()
void set_key (int root_pitch_class)
 Root pitch class, 0 = C .. 11 = B.
int key () const
void set_scale (ScaleType scale)
ScaleType scale () const
void set_off_scale_policy (OffScalePolicy policy)
OffScalePolicy off_scale_policy () const
int degree_count () const
 Number of degrees in the active scale — 7 for the modes, 5 for the pentatonics.
int degree_semitone (int index) const
 Semitone offset of degree index above the root.
DiatonicMapping map_midi (int midi_note, int interval_steps) const
 Maps a chromatic MIDI note.
DiatonicMapping map_hz (double f0_hz, int interval_steps) const
 Maps a tracked frequency: rounds to the nearest chromatic note, then map_midi.

Static Public Attributes

static constexpr int kMaxDegrees = 12
 A pitch-class mask has at most 12 degrees.
static constexpr int kIntervalStepsMax = 14
 Interval range in scale steps — ±two octaves of a 7-note scale.
static constexpr int kShiftSemitonesMax = 12
 The ±1 octave ratio clamp the shifter stage imposes ([0.5, 2.0]).

Detailed Description

template<typename SampleType = float>
class pulp::signal::DiatonicMapT< SampleType >

Key + scale interval mapper.

Pure control-domain integer arithmetic — no audio, no state that process touches, but the same lifecycle conventions as the audio blocks.

RT contract: nothing here allocates, locks, or throws. The degree list is a fixed 12-entry array (a 12-bit pitch-class mask cannot have more than 12 degrees), so a key or scale change mid-stream is a rewrite of that array rather than a resize.

The whole point: +2 steps means "up two entries in this scale", so a third above the tonic of C major is 4 semitones and a third above the supertonic is 3. That falls straight out of the major scale's W-W-H-W-W-W-H structure — there are no fitted constants and no tabulated shifts anywhere in this class.

Constructor & Destructor Documentation

◆ DiatonicMapT()

template<typename SampleType = float>
pulp::signal::DiatonicMapT< SampleType >::DiatonicMapT ( )
inline

Member Function Documentation

◆ degree_count()

template<typename SampleType = float>
int pulp::signal::DiatonicMapT< SampleType >::degree_count ( ) const
inline

Number of degrees in the active scale — 7 for the modes, 5 for the pentatonics.

Scale-step arithmetic wraps on this.

◆ degree_semitone()

template<typename SampleType = float>
int pulp::signal::DiatonicMapT< SampleType >::degree_semitone ( int index) const
inline

Semitone offset of degree index above the root.

Exposed so a test can compute its expectation FROM THE MASK rather than restate a table.

◆ key()

template<typename SampleType = float>
int pulp::signal::DiatonicMapT< SampleType >::key ( ) const
inline

◆ map_hz()

template<typename SampleType = float>
DiatonicMapping pulp::signal::DiatonicMapT< SampleType >::map_hz ( double f0_hz,
int interval_steps ) const
inline

Maps a tracked frequency: rounds to the nearest chromatic note, then map_midi.

◆ map_midi()

template<typename SampleType = float>
DiatonicMapping pulp::signal::DiatonicMapT< SampleType >::map_midi ( int midi_note,
int interval_steps ) const
inline

Maps a chromatic MIDI note.

The integer entry point — exact, and what the mapping tests drive.

◆ off_scale_policy()

template<typename SampleType = float>
OffScalePolicy pulp::signal::DiatonicMapT< SampleType >::off_scale_policy ( ) const
inline

◆ scale()

template<typename SampleType = float>
ScaleType pulp::signal::DiatonicMapT< SampleType >::scale ( ) const
inline

◆ set_key()

template<typename SampleType = float>
void pulp::signal::DiatonicMapT< SampleType >::set_key ( int root_pitch_class)
inline

Root pitch class, 0 = C .. 11 = B.

◆ set_off_scale_policy()

template<typename SampleType = float>
void pulp::signal::DiatonicMapT< SampleType >::set_off_scale_policy ( OffScalePolicy policy)
inline

◆ set_scale()

template<typename SampleType = float>
void pulp::signal::DiatonicMapT< SampleType >::set_scale ( ScaleType scale)
inline

Member Data Documentation

◆ kIntervalStepsMax

template<typename SampleType = float>
int pulp::signal::DiatonicMapT< SampleType >::kIntervalStepsMax = 14
staticconstexpr

Interval range in scale steps — ±two octaves of a 7-note scale.

[design parameter] default +2 (a 3rd above), range −14 .. +14.

◆ kMaxDegrees

template<typename SampleType = float>
int pulp::signal::DiatonicMapT< SampleType >::kMaxDegrees = 12
staticconstexpr

A pitch-class mask has at most 12 degrees.

The specification calls for a fixed [16]; 12 is the provable bound and is used instead.

◆ kShiftSemitonesMax

template<typename SampleType = float>
int pulp::signal::DiatonicMapT< SampleType >::kShiftSemitonesMax = 12
staticconstexpr

The ±1 octave ratio clamp the shifter stage imposes ([0.5, 2.0]).

Clamping to exactly ±12 is musically safe rather than merely bounded: an octave is in every scale in the table, so a clamped target is still a scale tone. [design parameter] default ±12 semitones, fixed by kRatioMin/Max.


The documentation for this class was generated from the following file: