Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::dsp::MusicalScale Class Reference

Musical scale descriptor. More...

#include <src/dsp/musical_scale.h>

Inheritance diagram for zrythm::dsp::MusicalScale:
Collaboration diagram for zrythm::dsp::MusicalScale:

Data Structures

struct  DiatonicTriad
 A diatonic triad: the root note and chord type for a scale degree. More...

Public Types

enum class  ScaleType : std::uint8_t {
  Chromatic , Major , Minor , Ionian ,
  Dorian , Phrygian , Lydian , Mixolydian ,
  Aeolian , Locrian , MelodicMinor , HarmonicMinor ,
  WholeTone , MajorPentatonic , MinorPentatonic , OctatonicHalfWhole ,
  OctatonicWholeHalf , Acoustic , HarmonicMajor , PhrygianDominant ,
  MajorLocrian , Algerian , Augmented , DoubleHarmonic ,
  Chinese , Diminished , DominantDiminished , Egyptian ,
  EightToneSpanish , Enigmatic , Geez , Hindu ,
  Hirajoshi , HungarianGypsy , Insen , NeapolitanMajor ,
  NeapolitanMinor , Oriental , RomanianMinor , Altered ,
  Maqam , Yo , BebopLocrian , BebopDominant ,
  BebopMajor , SuperLocrian , EnigmaticMinor , Composite ,
  Bhairav , HungarianMinor , Persian , Iwato ,
  Kumoi , Pelog , Prometheus , PrometheusNeapolitan ,
  PrometheusLiszt , Balinese , Ragatodi , Japanese1 ,
  Japanese2 , Blues , Flamenco , Gypsy ,
  HalfDiminished , In , Istrian , LydianAugmented ,
  Tritone , UkranianDorian
}
 Scale type (name) eg Aeolian. More...

Public Member Functions

 MusicalScale (QObject *parent=nullptr)
 MusicalScale (ScaleType type, MusicalNote root, QObject *parent=nullptr)
auto scaleType () const
void setScaleType (ScaleType type)
Q_SIGNAL void scaleTypeChanged (ScaleType type)
auto rootKey () const
void setRootKey (MusicalNote root_key)
Q_SIGNAL void rootKeyChanged (MusicalNote root_key)
Q_INVOKABLE QString toString () const
Q_INVOKABLE bool containsNote (MusicalNote note) const
 Returns if the given key is in the given MusicalScale.
utils::Utf8String to_string () const
 Prints the MusicalScale to a string.
Q_INVOKABLE bool containsChord (MusicalNote root, ChordType type, ChordAccent accent=ChordAccent::None) const
 Returns if all of the chord's notes are in the scale.
Q_INVOKABLE bool isAccentInScale (MusicalNote chord_root, ChordType type, ChordAccent chord_accent) const
 Returns if the accent is in the scale.
bool is_same_scale (const MusicalScale &other) const

Static Public Member Functions

static Q_INVOKABLE bool scaleContainsNote (ScaleType type, MusicalNote rootKey, MusicalNote note)
static Q_INVOKABLE QString noteToString (MusicalNote note)
static Q_INVOKABLE QStringList allNoteNames ()
 Returns the display names of all 12 notes in a single octave.
static Q_INVOKABLE QVariantList availableScaleTypes ()
static Q_INVOKABLE QVariantList availableScaleTypesExotic ()
static Q_INVOKABLE QVariantList availableScaleTypesWithTriads ()
 Scales with pre-defined triad data in get_triad_types_for_type.
static Q_INVOKABLE QVariantList getDiatonicChords (ScaleType type, MusicalNote rootKey)
 Returns a QVariantList of diatonic chord descriptors for the given scale, each as {display, rootNote, chordType}.
static std::array< bool, 12 > get_notes_for_type (ScaleType type, bool ascending)
 Returns the notes in the given scale.
static std::array< ChordType, 12 > get_triad_types_for_type (ScaleType type, bool ascending)
 Returns the triads in the given scale.
static boost::container::static_vector< DiatonicTriad, 12 > get_diatonic_triads (ScaleType type, MusicalNote root_note)
 Returns the diatonic triads for the given scale and root note.
static utils::Utf8String type_to_string (ScaleType type)

Properties

ScaleType scaleType
zrythm::dsp::chords::MusicalNote rootKey

Friends

void init_from (MusicalScale &obj, const MusicalScale &other, utils::ObjectCloneType clone_type)
void to_json (nlohmann::json &j, const MusicalScale &s)
void from_json (const nlohmann::json &j, MusicalScale &s)

Detailed Description

Musical scale descriptor.

See also
https://pianoscales.org/

Definition at line 25 of file musical_scale.h.

Member Enumeration Documentation

◆ ScaleType

enum class zrythm::dsp::MusicalScale::ScaleType : std::uint8_t
strong

Scale type (name) eg Aeolian.

Enumerator
Chromatic 

All keys.

Minor 

Natural minor.

Ionian 

Major (same as SCALE_MAJOR).

Aeolian 

Natural minor (same as Minor).

Acoustic 

Lydian dominant.

Definition at line 37 of file musical_scale.h.

Constructor & Destructor Documentation

◆ MusicalScale() [1/2]

zrythm::dsp::MusicalScale::MusicalScale ( QObject * parent = nullptr)
inline

Definition at line 133 of file musical_scale.h.

◆ MusicalScale() [2/2]

zrythm::dsp::MusicalScale::MusicalScale ( ScaleType type,
MusicalNote root,
QObject * parent = nullptr )
inline

Definition at line 134 of file musical_scale.h.

Member Function Documentation

◆ allNoteNames()

Q_INVOKABLE QStringList zrythm::dsp::MusicalScale::allNoteNames ( )
static

Returns the display names of all 12 notes in a single octave.

Convenience for QML consumers that need the full list in a single call instead of invoking noteToString 12 times.

◆ availableScaleTypesWithTriads()

Q_INVOKABLE QVariantList zrythm::dsp::MusicalScale::availableScaleTypesWithTriads ( )
static

Scales with pre-defined triad data in get_triad_types_for_type.

Used by the chord pad to populate chords from a scale.

◆ containsNote()

Q_INVOKABLE bool zrythm::dsp::MusicalScale::containsNote ( MusicalNote note) const

Returns if the given key is in the given MusicalScale.

Parameters
noteA note inside a single octave (0-11).

◆ get_diatonic_triads()

boost::container::static_vector< DiatonicTriad, 12 > zrythm::dsp::MusicalScale::get_diatonic_triads ( ScaleType type,
MusicalNote root_note )
static

Returns the diatonic triads for the given scale and root note.

Enumerates the enabled notes in the scale, pairs each with its corresponding triad type, and computes the absolute root note. Returns an empty result if the scale type is unimplemented.

Parameters
typeThe scale type.
root_noteThe root note of the scale.

◆ get_notes_for_type()

std::array< bool, 12 > zrythm::dsp::MusicalScale::get_notes_for_type ( ScaleType type,
bool ascending )
static

Returns the notes in the given scale.

Parameters
ascendingWhether to get the notes when ascending or descending (some scales have different notes when rising/falling).

◆ get_triad_types_for_type()

std::array< ChordType, 12 > zrythm::dsp::MusicalScale::get_triad_types_for_type ( ScaleType type,
bool ascending )
static

Returns the triads in the given scale.

There will be as many chords are enabled notes in the scale, and the rest of the array will be filled with CHORD_TYPE_NONE.

Parameters
ascendingWhether to get the triads when ascending or descending (some scales have different triads when rising/falling).

◆ is_same_scale()

bool zrythm::dsp::MusicalScale::is_same_scale ( const MusicalScale & other) const
inline

Definition at line 277 of file musical_scale.h.

◆ rootKey()

auto zrythm::dsp::MusicalScale::rootKey ( ) const
inline

Definition at line 159 of file musical_scale.h.

◆ scaleType()

auto zrythm::dsp::MusicalScale::scaleType ( ) const
inline

Definition at line 147 of file musical_scale.h.

◆ setRootKey()

void zrythm::dsp::MusicalScale::setRootKey ( MusicalNote root_key)
inline

Definition at line 160 of file musical_scale.h.

◆ setScaleType()

void zrythm::dsp::MusicalScale::setScaleType ( ScaleType type)
inline

Definition at line 148 of file musical_scale.h.

Property Documentation

◆ rootKey

zrythm::dsp::chords::MusicalNote zrythm::dsp::MusicalScale::rootKey
readwrite

Definition at line 29 of file musical_scale.h.

◆ scaleType

ScaleType zrythm::dsp::MusicalScale::scaleType
readwrite

Definition at line 28 of file musical_scale.h.


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