libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
MusicalScale Class Reference

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, ErrorfromName (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 charpitchClassName (int pitchClass)
 Returns the human-readable name for a pitch class.
 
static std::pair< Mode, ErrormodeFromName (const String &name)
 Parses a mode name to the Mode enum.
 
static const charmodeName (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 MembershipMaskmembershipMaskForMode (Mode mode)
 Returns the chromatic membership mask for a mode.
 

Detailed Description

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.

Member Typedef Documentation

◆ MembershipMask

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.

Constructor & Destructor Documentation

◆ MusicalScale()

MusicalScale::MusicalScale ( int  rootPitchClass,
Mode  mode 
)

Constructs a scale with the given root pitch class and mode.

Parameters
rootPitchClassPitch class of the root (0 = C, 1 = C#, ..., 11 = B).
modeScale mode.

Member Function Documentation

◆ constrainNote()

float MusicalScale::constrainNote ( float  midiNote,
float  strength = 1.0f 
) const

Constrains a fractional MIDI note to the nearest scale tone.

Parameters
midiNoteThe input MIDI note (fractional).
strengthSnap strength from 0.0 (no snap) to 1.0 (full snap).
Returns
The constrained MIDI note.

◆ containsNote()

bool MusicalScale::containsNote ( int  midiNote) const

Tests whether a MIDI note number belongs to this scale.

Parameters
midiNoteInteger MIDI note number.
Returns
True if the note is a member of the scale.

◆ fromName()

static std::pair< MusicalScale, Error > MusicalScale::fromName ( const String name)
static

Parses a scale name such as "C Major" or "Eb Blues".

Parameters
nameScale name string.
Returns
A pair of the parsed scale and an error code. Returns Error::Invalid if the name cannot be parsed.

◆ intervalsForMode()

static List< int > MusicalScale::intervalsForMode ( Mode  mode)
static

Returns the interval list (cumulative semitone offsets) for a mode.

Parameters
modeScale mode.
Returns
List of semitone offsets from the root for each scale degree.

◆ membershipMaskForMode()

static const MembershipMask & MusicalScale::membershipMaskForMode ( Mode  mode)
static

Returns the chromatic membership mask for a mode.

Parameters
modeScale mode.
Returns
A 12-element array where 1 indicates a scale member.

◆ midiNoteForDegree()

float MusicalScale::midiNoteForDegree ( int  degree,
int  octave 
) const

Returns the MIDI note number for a given scale degree and octave.

Parameters
degreeScale degree (0-based, may be negative).
octaveMIDI octave number.
Returns
Fractional MIDI note number.

◆ modeFromName()

static std::pair< Mode, Error > MusicalScale::modeFromName ( const String name)
static

Parses a mode name to the Mode enum.

Parameters
nameMode name (case-insensitive).
Returns
A pair of the parsed mode and an error code.

◆ modeName()

static const char * MusicalScale::modeName ( Mode  mode)
static

Returns the human-readable name for a mode.

Parameters
modeScale mode.
Returns
Name string (e.g. "Major", "Natural Minor").

◆ pitchClassFromName()

static int MusicalScale::pitchClassFromName ( const String name)
static

Parses a pitch class name ("C", "F#", "Bb") to a pitch class number.

Parameters
namePitch class name string.
Returns
Pitch class (0–11), or -1 if the name is not recognized.

◆ pitchClassName()

static const char * MusicalScale::pitchClassName ( int  pitchClass)
static

Returns the human-readable name for a pitch class.

Parameters
pitchClassPitch class (0–11).
Returns
Name string (e.g. "C", "C#", "D").

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