Represents a musical scale with a root pitch class and mode. More...
#include <musicalscale.h>
Public Types | |
| enum | Mode { Chromatic , Major , NaturalMinor , HarmonicMinor , MelodicMinor , Pentatonic , Blues } |
| Scale mode. | |
| using | MembershipMask = std::array< int, 12 > |
| Chromatic membership mask for a scale. | |
Public Member Functions | |
| MusicalScale () | |
| Default-constructs a C Chromatic scale. | |
| MusicalScale (int rootPitchClass, Mode mode) | |
| Constructs a scale with the given root pitch class and mode. | |
| int | rootPitchClass () const |
| Returns the root pitch class (0–11). | |
| Mode | mode () const |
| Returns the scale mode. | |
| int | degreesPerOctave () const |
| Returns the number of degrees per octave in this scale. | |
| float | midiNoteForDegree (int degree, int octave) const |
| Returns the MIDI note number for a given scale degree and octave. | |
| bool | containsNote (int midiNote) const |
| Tests whether a MIDI note number belongs to this scale. | |
| float | constrainNote (float midiNote, float strength=1.0f) const |
| Constrains a fractional MIDI note to the nearest scale tone. | |
Static Public Member Functions | |
| static std::pair< MusicalScale, Error > | fromName (const String &name) |
| Parses a scale name such as "C Major" or "Eb Blues". | |
| static int | pitchClassFromName (const String &name) |
| Parses a pitch class name ("C", "F#", "Bb") to a pitch class number. | |
| static const char * | pitchClassName (int pitchClass) |
| Returns the human-readable name for a pitch class. | |
| static std::pair< Mode, Error > | modeFromName (const String &name) |
| Parses a mode name to the Mode enum. | |
| static const char * | modeName (Mode mode) |
| Returns the human-readable name for a mode. | |
| static List< int > | intervalsForMode (Mode mode) |
| Returns the interval list (cumulative semitone offsets) for a mode. | |
| static const MembershipMask & | membershipMaskForMode (Mode mode) |
| Returns the chromatic membership mask for a mode. | |
Represents a musical scale with a root pitch class and mode.
MusicalScale combines a root note (0–11 pitch class) with a mode (Major, NaturalMinor, etc.) and provides operations for mapping scale degrees to MIDI note numbers, testing scale membership, and constraining arbitrary MIDI notes to the nearest scale tone.
| using MusicalScale::MembershipMask = std::array<int, 12> |
Chromatic membership mask for a scale.
Each element is 1 if the semitone offset from the root is a member of the scale, 0 otherwise.
| MusicalScale::MusicalScale | ( | int | rootPitchClass, |
| Mode | mode | ||
| ) |
Constructs a scale with the given root pitch class and mode.
| rootPitchClass | Pitch class of the root (0 = C, 1 = C#, ..., 11 = B). |
| mode | Scale mode. |
| bool MusicalScale::containsNote | ( | int | midiNote | ) | const |
Tests whether a MIDI note number belongs to this scale.
| midiNote | Integer MIDI note number. |
|
static |
Parses a scale name such as "C Major" or "Eb Blues".
| name | Scale name string. |
Returns the interval list (cumulative semitone offsets) for a mode.
| mode | Scale mode. |
|
static |
Returns the chromatic membership mask for a mode.
| mode | Scale mode. |
| float MusicalScale::midiNoteForDegree | ( | int | degree, |
| int | octave | ||
| ) | const |
Returns the MIDI note number for a given scale degree and octave.
| degree | Scale degree (0-based, may be negative). |
| octave | MIDI octave number. |
Parses a mode name to the Mode enum.
| name | Mode name (case-insensitive). |
Returns the human-readable name for a mode.
| mode | Scale mode. |
Parses a pitch class name ("C", "F#", "Bb") to a pitch class number.
| name | Pitch class name string. |
Returns the human-readable name for a pitch class.
| pitchClass | Pitch class (0–11). |