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]). | |
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.
|
inline |
|
inline |
Number of degrees in the active scale — 7 for the modes, 5 for the pentatonics.
Scale-step arithmetic wraps on this.
|
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.
|
inline |
|
inline |
Maps a tracked frequency: rounds to the nearest chromatic note, then map_midi.
|
inline |
Maps a chromatic MIDI note.
The integer entry point — exact, and what the mapping tests drive.
|
inline |
|
inline |
|
inline |
Root pitch class, 0 = C .. 11 = B.
|
inline |
|
inline |
|
staticconstexpr |
Interval range in scale steps — ±two octaves of a 7-note scale.
[design parameter] default +2 (a 3rd above), range −14 .. +14.
|
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.
|
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.