libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
musicalscale.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <array>
11#include <promeki/core/string.h>
12#include <promeki/core/list.h>
13#include <promeki/core/error.h>
14
16
27 public:
29 enum Mode {
30 Chromatic,
31 Major,
32 NaturalMinor,
33 HarmonicMinor,
34 MelodicMinor,
35 Pentatonic,
36 Blues
37 };
38
45 using MembershipMask = std::array<int, 12>;
46
49
56
63 static std::pair<MusicalScale, Error> fromName(const String &name);
64
66 int rootPitchClass() const { return _rootPitchClass; }
67
69 Mode mode() const { return _mode; }
70
72 int degreesPerOctave() const { return static_cast<int>(_intervals.size()); }
73
80 float midiNoteForDegree(int degree, int octave) const;
81
87 bool containsNote(int midiNote) const;
88
95 float constrainNote(float midiNote, float strength = 1.0f) const;
96
102 static int pitchClassFromName(const String &name);
103
109 static const char *pitchClassName(int pitchClass);
110
116 static std::pair<Mode, Error> modeFromName(const String &name);
117
123 static const char *modeName(Mode mode);
124
131
138
139 private:
140 int _rootPitchClass = 0;
141 Mode _mode = Chromatic;
142 List<int> _intervals;
143};
144
Dynamic array container wrapping std::vector.
Definition list.h:40
size_t size() const noexcept
Returns the number of elements in the list.
Definition list.h:301
Represents a musical scale with a root pitch class and mode.
Definition musicalscale.h:26
static const MembershipMask & membershipMaskForMode(Mode mode)
Returns the chromatic membership mask for a mode.
int degreesPerOctave() const
Returns the number of degrees per octave in this scale.
Definition musicalscale.h:72
static std::pair< MusicalScale, Error > fromName(const String &name)
Parses a scale name such as "C Major" or "Eb Blues".
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).
Definition musicalscale.h:66
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.
static const char * modeName(Mode mode)
Returns the human-readable name for a mode.
Mode
Scale mode.
Definition musicalscale.h:29
std::array< int, 12 > MembershipMask
Chromatic membership mask for a scale.
Definition musicalscale.h:45
Mode mode() const
Returns the scale mode.
Definition musicalscale.h:69
static List< int > intervalsForMode(Mode mode)
Returns the interval list (cumulative semitone offsets) for a mode.
float constrainNote(float midiNote, float strength=1.0f) const
Constrains a fractional MIDI note to the nearest scale tone.
static const char * pitchClassName(int pitchClass)
Returns the human-readable name for a pitch class.
static int pitchClassFromName(const String &name)
Parses a pitch class name ("C", "F#", "Bb") to a pitch class number.
static std::pair< Mode, Error > modeFromName(const String &name)
Parses a mode name to the Mode enum.
MusicalScale()
Default-constructs a C Chromatic scale.
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19