maiacore 1.10.1
Music analisys library
interval.h
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include "maiacore/note.h"
7
14class Interval {
15 private:
16 std::vector<Note> _note;
17 int _numSemitones;
18
23 std::pair<std::string, bool> analyse() const;
24
29 int whiteKeyDistance() const;
30
31 public:
37 Interval(const std::string& pitch_A = "C4", const std::string& pitch_B = "C4");
38
44 Interval(const Note& note_A, const Note& note_B);
45
51 void setNotes(const std::string& pitch_A, const std::string& pitch_B);
52
58 void setNotes(const Note& note_A, const Note& note_B);
59
64 std::string getName() const;
65
71 int getNumSemitones(const bool absoluteValue = false) const;
72
78 int getNumOctaves(const bool absoluteValue = false) const;
79
86 int getDiatonicInterval(const bool useSingleOctave = true,
87 const bool absoluteValue = false) const;
88
95 int getDiatonicSteps(const bool useSingleOctave = true, const bool absoluteValue = false) const;
96
102
107 std::vector<Note> getNotes() const;
108
113 bool isAscendant() const;
114
119 bool isDescendant() const;
120
125 std::string getDirection() const;
126
131 bool isSimple() const;
132
137 bool isCompound() const;
138
143 bool isTonal() const;
144
150 bool isMajor(const bool useEnharmony = false) const;
151
157 bool isMinor(const bool useEnharmony = false) const;
158
164 bool isPerfect(const bool useEnharmony = false) const;
165
171 bool isDiminished(const bool useEnharmony = false) const;
172
178 bool isAugmented(const bool useEnharmony = false) const;
179
180 // ===== ABSTRACTION 1 ===== //
181
187 bool isDiminishedUnisson(const bool useEnharmony = false) const;
188
194 bool isPerfectUnisson(const bool useEnharmony = false) const;
195
201 bool isAugmentedUnisson(const bool useEnharmony = false) const;
202
208 bool isMinorSecond(const bool useEnharmony = false) const;
209
215 bool isMajorSecond(const bool useEnharmony = false) const;
216
222 bool isMinorThird(const bool useEnharmony = false) const;
223
229 bool isMajorThird(const bool useEnharmony = false) const;
230
236 bool isPerfectFourth(const bool useEnharmony = false) const;
237
243 bool isAugmentedFourth(const bool useEnharmony = false) const;
244
250 bool isDiminishedFifth(const bool useEnharmony = false) const;
251
257 bool isPerfectFifth(const bool useEnharmony = false) const;
258
264 bool isAugmentedFifth(const bool useEnharmony = false) const;
265
271 bool isMinorSixth(const bool useEnharmony = false) const;
272
278 bool isMajorSixth(const bool useEnharmony = false) const;
279
285 bool isDiminishedSeventh(const bool useEnharmony = false) const;
286
292 bool isMinorSeventh(const bool useEnharmony = false) const;
293
299 bool isMajorSeventh(const bool useEnharmony = false) const;
300
306 bool isDiminishedOctave(const bool useEnharmony = false) const;
307
313 bool isPerfectOctave(const bool useEnharmony = false) const;
314
320 bool isAugmentedOctave(const bool useEnharmony = false) const;
321
327 bool isMinorNinth(const bool useEnharmony = false) const;
328
334 bool isMajorNinth(const bool useEnharmony = false) const;
335
341 bool isPerfectEleventh(const bool useEnharmony = false) const;
342
348 bool isSharpEleventh(const bool useEnharmony = false) const;
349
355 bool isMinorThirdteenth(const bool useEnharmony = false) const;
356
362 bool isMajorThirdteenth(const bool useEnharmony = false) const;
363
364 // ===== ABSTRACTION 2 ===== //
365
371 bool isSecond(const bool useEnharmony = false) const;
372
378 bool isThird(const bool useEnharmony = false) const;
379
385 bool isFourth(const bool useEnharmony = false) const;
386
392 bool isFifth(const bool useEnharmony = false) const;
393
399 bool isSixth(const bool useEnharmony = false) const;
400
406 bool isSeventh(const bool useEnharmony = false) const;
407
413 bool isOctave(const bool useEnharmony = false) const;
414
420 bool isNinth(const bool useEnharmony = false) const;
421
427 bool isEleventh(const bool useEnharmony = false) const;
428
434 bool isThirdteenth(const bool useEnharmony = false) const;
435
436 // ===== ABSTRACTION 3 ===== //
437
443 bool isAnyOctaveMinorSecond(const bool useEnharmony = false) const;
444
450 bool isAnyOctaveMajorSecond(const bool useEnharmony = false) const;
451
457 bool isAnyOctaveMinorThird(const bool useEnharmony = false) const;
458
464 bool isAnyOctaveMajorThird(const bool useEnharmony = false) const;
465
471 bool isAnyOctavePerfectFourth(const bool useEnharmony = false) const;
472
478 bool isAnyOctaveAugmentedFourth(const bool useEnharmony = false) const;
479
485 bool isAnyOctaveDiminishedFifth(const bool useEnharmony = false) const;
486
492 bool isAnyOctavePerfectFifth(const bool useEnharmony = false) const;
493
499 bool isAnyOctaveAugmentedFifth(const bool useEnharmony = false) const;
500
506 bool isAnyOctaveMinorSixth(const bool useEnharmony = false) const;
507
513 bool isAnyOctaveMajorSixth(const bool useEnharmony = false) const;
514
520 bool isAnyOctaveDiminishedSeventh(const bool useEnharmony = false) const;
521
527 bool isAnyOctaveMinorSeventh(const bool useEnharmony = false) const;
528
534 bool isAnyOctaveMajorSeventh(const bool useEnharmony = false) const;
535
541 bool isAnyOctaveDiminishedOctave(const bool useEnharmony = false) const;
542
548 bool isAnyOctavePerfectOctave(const bool useEnharmony = false) const;
549
555 bool isAnyOctaveAugmentedOctave(const bool useEnharmony = false) const;
556
557 // ===== ABSTRACTION 4 ===== //
558
563 bool isAnyOctaveSecond() const;
564
569 bool isAnyOctaveThird() const;
570
575 bool isAnyOctaveFourth() const;
576
581 bool isAnyOctaveFifth() const;
582
587 bool isAnyOctaveSixth() const;
588
593 bool isAnyOctaveSeventh() const;
594
599 bool isAnyOctaveOctave() const;
600
606 int toCents(const float freqA4 = 440.0f) const;
607
613 bool operator<(const Interval& otherInterval) const {
614 return getNumSemitones(true) < otherInterval.getNumSemitones(true);
615 }
616};
Represents a musical interval between two notes, supporting tonal, diatonic, and chromatic analysis.
Definition: interval.h:14
bool isDiminishedOctave(const bool useEnharmony=false) const
Returns true if the interval is a diminished octave.
bool isAnyOctaveMajorSecond(const bool useEnharmony=false) const
Returns true if the interval is a major second in any octave.
bool isAnyOctaveMajorThird(const bool useEnharmony=false) const
Returns true if the interval is a major third in any octave.
bool isAnyOctaveSeventh() const
Returns true if the interval is a generic seventh (any octave).
int getNumSemitones(const bool absoluteValue=false) const
Returns the number of semitones between the notes.
bool isMajorThirdteenth(const bool useEnharmony=false) const
Returns true if the interval is a major thirteenth.
bool isPerfectFourth(const bool useEnharmony=false) const
Returns true if the interval is a perfect fourth.
bool isTonal() const
Returns true if the interval is tonal (major, minor, perfect, etc.).
bool isThirdteenth(const bool useEnharmony=false) const
Returns true if the interval is a thirteenth (major or minor).
bool isPerfectFifth(const bool useEnharmony=false) const
Returns true if the interval is a perfect fifth.
bool isDiminishedFifth(const bool useEnharmony=false) const
Returns true if the interval is a diminished fifth (tritone).
bool isAnyOctaveFifth() const
Returns true if the interval is a generic fifth (any octave).
bool isPerfectOctave(const bool useEnharmony=false) const
Returns true if the interval is a perfect octave.
bool isAnyOctaveOctave() const
Returns true if the interval is a generic octave (any octave).
bool isThird(const bool useEnharmony=false) const
Returns true if the interval is a generic third (major or minor).
int getPitchStepInterval() const
Returns the pitch step interval (e.g., 1 for unison, 2 for second).
bool isFourth(const bool useEnharmony=false) const
Returns true if the interval is a generic fourth (perfect, augmented, or diminished).
bool isMinorSeventh(const bool useEnharmony=false) const
Returns true if the interval is a minor seventh.
bool isMajorNinth(const bool useEnharmony=false) const
Returns true if the interval is a major ninth.
bool isEleventh(const bool useEnharmony=false) const
Returns true if the interval is an eleventh (perfect or sharp).
bool isSeventh(const bool useEnharmony=false) const
Returns true if the interval is a generic seventh (major, minor, or diminished).
bool isAnyOctaveMinorSixth(const bool useEnharmony=false) const
Returns true if the interval is a minor sixth in any octave.
bool isDiminishedUnisson(const bool useEnharmony=false) const
Returns true if the interval is a diminished unison.
bool isMajorSeventh(const bool useEnharmony=false) const
Returns true if the interval is a major seventh.
int getDiatonicSteps(const bool useSingleOctave=true, const bool absoluteValue=false) const
Returns the number of diatonic steps between the notes.
bool isPerfectUnisson(const bool useEnharmony=false) const
Returns true if the interval is a perfect unison.
bool isAnyOctaveThird() const
Returns true if the interval is a generic third (any octave).
bool isAnyOctaveDiminishedSeventh(const bool useEnharmony=false) const
Returns true if the interval is a diminished seventh in any octave.
bool isMajorThird(const bool useEnharmony=false) const
Returns true if the interval is a major third.
bool isFifth(const bool useEnharmony=false) const
Returns true if the interval is a generic fifth (perfect, augmented, or diminished).
bool isAnyOctaveMinorSeventh(const bool useEnharmony=false) const
Returns true if the interval is a minor seventh in any octave.
std::string getDirection() const
Returns the direction of the interval as a string ("asc", "desc", or empty for unison).
bool operator<(const Interval &otherInterval) const
Less-than operator for comparing intervals by number of semitones.
Definition: interval.h:613
bool isAnyOctaveMajorSixth(const bool useEnharmony=false) const
Returns true if the interval is a major sixth in any octave.
bool isSecond(const bool useEnharmony=false) const
Returns true if the interval is a generic second (major or minor).
bool isMinor(const bool useEnharmony=false) const
Returns true if the interval is minor.
void setNotes(const Note &note_A, const Note &note_B)
Sets the notes of the interval using Note objects.
bool isAugmentedUnisson(const bool useEnharmony=false) const
Returns true if the interval is an augmented unison.
bool isAugmented(const bool useEnharmony=false) const
Returns true if the interval is augmented.
bool isOctave(const bool useEnharmony=false) const
Returns true if the interval is an octave (perfect, augmented, or diminished).
bool isAnyOctaveDiminishedFifth(const bool useEnharmony=false) const
Returns true if the interval is a diminished fifth in any octave.
bool isAnyOctavePerfectOctave(const bool useEnharmony=false) const
Returns true if the interval is a perfect octave in any octave.
bool isPerfectEleventh(const bool useEnharmony=false) const
Returns true if the interval is a perfect eleventh.
bool isMajorSixth(const bool useEnharmony=false) const
Returns true if the interval is a major sixth.
bool isAscendant() const
Returns true if the interval is ascending.
bool isMinorSixth(const bool useEnharmony=false) const
Returns true if the interval is a minor sixth.
bool isMinorNinth(const bool useEnharmony=false) const
Returns true if the interval is a minor ninth.
bool isAnyOctaveMinorSecond(const bool useEnharmony=false) const
Returns true if the interval is a minor second in any octave.
Interval(const std::string &pitch_A="C4", const std::string &pitch_B="C4")
Constructs an Interval from two pitch strings.
std::vector< Note > getNotes() const
Returns the two notes defining the interval.
bool isMinorThirdteenth(const bool useEnharmony=false) const
Returns true if the interval is a minor thirteenth.
bool isAugmentedFifth(const bool useEnharmony=false) const
Returns true if the interval is an augmented fifth.
bool isMajor(const bool useEnharmony=false) const
Returns true if the interval is major.
bool isAugmentedOctave(const bool useEnharmony=false) const
Returns true if the interval is an augmented octave.
bool isAnyOctaveAugmentedFourth(const bool useEnharmony=false) const
Returns true if the interval is an augmented fourth in any octave.
bool isAugmentedFourth(const bool useEnharmony=false) const
Returns true if the interval is an augmented fourth (tritone).
bool isCompound() const
Returns true if the interval is compound (greater than an octave).
bool isSimple() const
Returns true if the interval is simple (within an octave).
bool isMajorSecond(const bool useEnharmony=false) const
Returns true if the interval is a major second.
bool isAnyOctaveAugmentedOctave(const bool useEnharmony=false) const
Returns true if the interval is an augmented octave in any octave.
int getNumOctaves(const bool absoluteValue=false) const
Returns the number of octaves between the notes.
int getDiatonicInterval(const bool useSingleOctave=true, const bool absoluteValue=false) const
Returns the diatonic interval number (e.g., 3 for a third).
bool isAnyOctavePerfectFifth(const bool useEnharmony=false) const
Returns true if the interval is a perfect fifth in any octave.
bool isAnyOctaveDiminishedOctave(const bool useEnharmony=false) const
Returns true if the interval is a diminished octave in any octave.
bool isDiminishedSeventh(const bool useEnharmony=false) const
Returns true if the interval is a diminished seventh.
bool isMinorSecond(const bool useEnharmony=false) const
Returns true if the interval is a minor second.
bool isSixth(const bool useEnharmony=false) const
Returns true if the interval is a generic sixth (major or minor).
bool isDiminished(const bool useEnharmony=false) const
Returns true if the interval is diminished.
void setNotes(const std::string &pitch_A, const std::string &pitch_B)
Sets the notes of the interval using pitch strings.
bool isAnyOctaveSecond() const
Returns true if the interval is a generic second (any octave).
bool isDescendant() const
Returns true if the interval is descending.
bool isPerfect(const bool useEnharmony=false) const
Returns true if the interval is perfect.
bool isMinorThird(const bool useEnharmony=false) const
Returns true if the interval is a minor third.
bool isSharpEleventh(const bool useEnharmony=false) const
Returns true if the interval is a sharp eleventh.
bool isAnyOctaveSixth() const
Returns true if the interval is a generic sixth (any octave).
int toCents(const float freqA4=440.0f) const
Returns the interval size in cents (for microtonal/tuning analysis).
bool isAnyOctaveMajorSeventh(const bool useEnharmony=false) const
Returns true if the interval is a major seventh in any octave.
bool isAnyOctaveFourth() const
Returns true if the interval is a generic fourth (any octave).
bool isAnyOctaveMinorThird(const bool useEnharmony=false) const
Returns true if the interval is a minor third in any octave.
Interval(const Note &note_A, const Note &note_B)
Constructs an Interval from two Note objects.
bool isNinth(const bool useEnharmony=false) const
Returns true if the interval is a ninth (major or minor).
bool isAnyOctaveAugmentedFifth(const bool useEnharmony=false) const
Returns true if the interval is an augmented fifth in any octave.
bool isAnyOctavePerfectFourth(const bool useEnharmony=false) const
Returns true if the interval is a perfect fourth in any octave.
std::string getName() const
Returns the interval name (e.g., "M3", "P5", "m2").
Represents a musical note, including pitch, duration, articulation, and MusicXML-related attributes.
Definition: note.h:19