|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Comprehensive musical harmony calculations - scales, chords, MIDI, theory. More...
#include <array>#include <string_view>#include <cstdint>#include <algorithm>#include <optional>

Go to the source code of this file.
Classes | |
| struct | dspark::harmony::Scale |
| Descriptor holding the name, pitch mask and chord tags for a musical scale. More... | |
| struct | dspark::harmony::Chord |
| A chord "recipe" defining the required intervals relative to its root. More... | |
| struct | dspark::harmony::DiatonicChord |
| Contains the structure and generated symbol name of a diatonic chord. More... | |
Namespaces | |
| namespace | dspark |
| Main namespace for the DSPark framework. | |
| namespace | dspark::harmony |
| namespace | dspark::harmony::detail |
Typedefs | |
| using | dspark::harmony::NoteSet = std::uint16_t |
| A 12-bit bitmask representing the 12 pitch-classes of the chromatic scale. | |
| using | dspark::harmony::Degree = int |
| Integer index used to select a degree inside standard diatonic representations (0-based). | |
Functions | |
| constexpr ChordTag | dspark::harmony::operator| (ChordTag lhs, ChordTag rhs) noexcept |
| Bitwise OR operator for ChordTag flags. | |
| constexpr ChordTag | dspark::harmony::operator& (ChordTag lhs, ChordTag rhs) noexcept |
| Bitwise AND operator for ChordTag flags (intersection). | |
| constexpr bool | dspark::harmony::hasTags (ChordTag tags, ChordTag wanted) noexcept |
Tests whether tags contains ALL flags in wanted. | |
| consteval NoteSet | dspark::harmony::makeMask (bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7, bool b8, bool b9, bool b10, bool b11) noexcept |
| Build a NoteSet from 12 boolean flags (b0 = C, b1 = C#/Db, ... b11 = B). | |
| consteval NoteSet | dspark::harmony::makeMask (std::initializer_list< int > degrees) noexcept |
| Build a NoteSet from a list of semitone degrees. | |
| constexpr void | dspark::harmony::detail::copy (char *dst, std::string_view src, std::size_t dstCapacity) noexcept |
| Safe small string copy used only for compile-time-friendly name building. | |
| constexpr std::array< int, 7 > | dspark::harmony::detail::activeDegrees (NoteSet mask) noexcept |
| Extract active scale degrees and expand them sequentially across the octave. | |
| constexpr int | dspark::harmony::detail::interval (const std::array< int, 7 > °, int degIdx, int skip) noexcept |
| Calculate semitone interval skipping 'skip' degrees in the scale. | |
| constexpr std::string_view | dspark::harmony::noteName (int midi, int root=0) noexcept |
| Returns a human-readable note name for the given MIDI note (0..127). | |
| constexpr std::optional< int > | dspark::harmony::parseNote (std::string_view s) noexcept |
| Parse a simple note name (no octave) into a pitch-class (0..11). | |
| constexpr NoteSet | dspark::harmony::scaleAtRoot (NoteSet base, int root) noexcept |
| Circularly rotate a NoteSet so it becomes rooted at a specific key. | |
| constexpr std::array< int, 7 > | dspark::harmony::chordAtRootMidi (const Chord &c, int rootMidi, int inversion=0) noexcept |
| Build MIDI note numbers for a chord recipe located at a specific root. | |
| constexpr std::array< const Scale *, 16 > | dspark::harmony::scalesForChordMask (NoteSet chordMask) noexcept |
Reverse lookup: find up to 16 scales that fully contain chordMask. | |
| constexpr std::array< const Scale *, 16 > | dspark::harmony::scalesForChord (const Chord &chord) noexcept |
| Reverse lookup wrapper: find scales that can contain a specific Chord recipe. | |
| constexpr DiatonicChord | dspark::harmony::diatonicChord (const Scale &sc, Degree degree, ChordLevel level) noexcept |
| Generates the diatonic chord built upon a specific degree of a scale. | |
| constexpr std::array< int, 7 > | dspark::harmony::diatonicChordToMidi (const DiatonicChord &c, int rootMidi) noexcept |
| Convert a DiatonicChord's interval recipe into absolute MIDI notes. | |
| constexpr std::optional< int > | dspark::harmony::parseNoteWithOctave (std::string_view note) noexcept |
| Parse a note string containing an optional octave (e.g. "C#4", "C-1"). | |
| constexpr int | dspark::harmony::getOctaveFromNote (std::string_view note) noexcept |
| Extract octave number from a note string. Supports negative octaves. | |
| constexpr int | dspark::harmony::transposeByOctaves (int midi, int octaveDelta) noexcept |
| Transpose a MIDI note by a discrete number of full octaves. | |
Variables | |
| constexpr std::array< Scale, 61 > | dspark::harmony::allScales |
| constexpr std::array< std::string_view, 12 > | dspark::harmony::sharpNames |
| constexpr std::array< std::string_view, 12 > | dspark::harmony::flatNames |
| constexpr std::array< bool, 12 > | dspark::harmony::useSharpsForRoot |
| constexpr std::array< Chord, 15 > | dspark::harmony::allChords |
Comprehensive musical harmony calculations - scales, chords, MIDI, theory.
A complete, strictly constexpr toolkit for working with musical scales and chords. Fully functional at compile-time (constexpr / consteval) to guarantee zero-overhead runtime execution and generate static data tables for audio plugins and musical analysis.
Complies with DSPark strict real-time constraints:
Threading: everything here is stateless, immutable constexpr data and pure functions - safe to call concurrently from any thread, including the audio thread.
Dependencies: C++20 standard library only.
Definition in file HarmonyConstants.h.