maiacore 1.10.1
Music analisys library
chord.h
1#pragma once
2#include <functional>
3#include <numeric> // std::accumulate
4#include <tuple> // std::tuple
5#include <vector>
6#include <algorithm> // std::transform
7
8#include "maiacore/interval.h"
9#include "maiacore/key.h"
10#include "maiacore/note.h"
11
13struct NoteData {
14 Note note = Note("rest");
15 bool wasEnharmonized = false;
16 int enharmonicDiatonicDistance = 0;
17
18 NoteData() : note(Note("rest")), wasEnharmonized(false), enharmonicDiatonicDistance(0) {}
19
20 NoteData(const Note& _originalNotes, const bool _wasEnhar, const int _enharDiat)
21 : note(_originalNotes),
22 wasEnharmonized(_wasEnhar),
23 enharmonicDiatonicDistance(_enharDiat){};
24
25 friend bool operator<(const NoteData& lhs, const NoteData& rhs) {
26 return lhs.note.getMidiNumber() < rhs.note.getMidiNumber();
27 }
28};
29
31
32// NoteDataHeap Type [Vector of NotesData]
33typedef std::vector<NoteData> NoteDataHeap;
34// HeapData Type [NoteDataHeap, stackMatchValue]
35typedef std::tuple<NoteDataHeap, float> HeapData;
36
37bool operator<(const HeapData& a, const HeapData& b);
38
39void printHeap(const NoteDataHeap& heap);
40
41void sortHeapOctaves(NoteDataHeap* heap);
42
59typedef std::tuple<int, float, std::string, int, float, int, float, std::string, int, float, float,
60 float, float>
61 SetharesDissonanceTableRow;
62typedef std::vector<SetharesDissonanceTableRow> SetharesDissonanceTable;
63
70class Chord {
71 private:
75 std::vector<Note> _originalNotes;
76
80 std::vector<Note> _openStack;
81
85 std::vector<Note> _closeStack;
86
90 std::vector<HeapData> _stackedHeaps;
91
95 std::vector<Interval> _closeStackintervals;
96
100 Note _bassNote;
101
105 bool _isStackedInThirds;
106
110 void computeIntervals();
111
116 void stackInThirds(const bool enharmonyNotes = false);
117
123 HeapData stackInThirdsTemplateMatch(const NoteDataHeap& heap) const;
124
129 std::vector<NoteDataHeap> computeEnharmonicUnitsGroups() const;
130
136 std::vector<NoteDataHeap> computeEnharmonicHeaps(const std::vector<NoteDataHeap>& heaps) const;
137
143 std::vector<NoteDataHeap> removeHeapsWithDuplicatedPitchSteps(
144 std::vector<NoteDataHeap>& heaps) const;
145
151 std::vector<NoteDataHeap> computeAllHeapInversions(NoteDataHeap& heap) const;
152
158 std::vector<NoteDataHeap> filterTertianHeapsOnly(const std::vector<NoteDataHeap>& heaps) const;
159
165 std::vector<Note> computeBestOpenStackHeap(std::vector<HeapData>& stackedHeaps);
166
171 void computeCloseStack(const std::vector<Note>& openStack);
172
179 template <typename T>
180 float computeStandardDeviation(const std::vector<T>& v) const {
181 const float sum = std::accumulate(v.begin(), v.end(), 0);
182 const float mean = sum / v.size();
183
184 std::vector<float> diff(v.size());
185 std::transform(v.begin(), v.end(), diff.begin(), [mean](double x) { return x - mean; });
186 const float sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
187 const float stdev = std::sqrt(sq_sum / v.size());
188
189 return stdev;
190 }
191
192 public:
199
205 explicit Chord(const std::vector<Note>& notes, const RhythmFigure rhythmFigure = RhythmFigure::QUARTER);
206
212 explicit Chord(const std::vector<std::string>& pitches, const RhythmFigure rhythmFigure = RhythmFigure::QUARTER);
213
218
222 void clear();
223
228 void addNote(const Note& note);
229
234 void addNote(const std::string& pitch);
235
240
246 void insertNote(Note& insertNote, int positionNote = 0);
247
252 void removeNote(int noteIndex);
253
258 void setDuration(const Duration& duration);
259
265 void setDuration(const float quarterDuration, const int divisionsPerQuarterNote = 256);
266
271 void toInversion(int inversionNumber);
272
277 void transpose(const int semiTonesNumber);
278
283 void transposeStackOnly(const int semiTonesNumber);
284
289
295 std::vector<HeapData> getStackedHeaps(const bool enharmonyNotes = false);
296
301 std::string getDuration() const;
302
307 float getQuarterDuration() const;
308
313 int getDurationTicks() const;
314
320 Note& getNote(int noteIndex);
321
327 const Note& getNote(const int noteIndex) const;
328
333 const Note& getRoot();
334
339 std::string getName();
340
346
351 const std::vector<Note>& getNotes() const;
352
380 float getCloseStackHarmonicComplexity(const bool useEnharmony = false);
381
410 float getHarmonicDensity(int lowerBoundMIDI = -1, int higherBoundMIDI = -1) const;
411
418 float getHarmonicDensity(const std::string& lowerBoundPitch = {},
419 const std::string& higherBoundPitch = {}) const;
420
426 bool haveMajorInterval(const bool useEnharmony = false) const;
427
433 bool haveMinorInterval(const bool useEnharmony = false) const;
434
440 bool havePerfectInterval(const bool useEnharmony = false) const;
441
447 bool haveDiminishedInterval(const bool useEnharmony = false) const;
448
454 bool haveAugmentedInterval(const bool useEnharmony = false) const;
455
456 // ===== ABSTRACTION 1 ===== //
463 bool haveDiminishedUnisson(const bool useEnharmony = false) const;
464
471 bool havePerfectUnisson(const bool useEnharmony = false) const;
472
479 bool haveAugmentedUnisson(const bool useEnharmony = false) const;
480
487 bool haveMinorSecond(const bool useEnharmony = false);
488
495 bool haveMajorSecond(const bool useEnharmony = false);
496
503 bool haveMinorThird(const bool useEnharmony = false);
504
511 bool haveMajorThird(const bool useEnharmony = false);
512
519 bool havePerfectFourth(const bool useEnharmony = false);
520
527 bool haveAugmentedFourth(const bool useEnharmony = false);
528
535 bool haveDiminishedFifth(const bool useEnharmony = false);
536
543 bool havePerfectFifth(const bool useEnharmony = false);
544
551 bool haveAugmentedFifth(const bool useEnharmony = false);
552
559 bool haveMinorSixth(const bool useEnharmony = false);
560
567 bool haveMajorSixth(const bool useEnharmony = false);
568
575 bool haveDiminishedSeventh(const bool useEnharmony = false);
576
583 bool haveMinorSeventh(const bool useEnharmony = false);
584
591 bool haveMajorSeventh(const bool useEnharmony = false);
592
599 bool haveDiminishedOctave(const bool useEnharmony = false);
600
607 bool havePerfectOctave(const bool useEnharmony = false);
608
615 bool haveAugmentedOctave(const bool useEnharmony = false);
616
623 bool haveMinorNinth(const bool useEnharmony = false);
624
631 bool haveMajorNinth(const bool useEnharmony = false);
632
639 bool havePerfectEleventh(const bool useEnharmony = false);
640
647 bool haveSharpEleventh(const bool useEnharmony = false);
648
655 bool haveMinorThirdteenth(const bool useEnharmony = false);
656
663 bool haveMajorThirdteenth(const bool useEnharmony = false);
664
665 // ===== ABSTRACTION 2 ===== //
666
674 bool haveSecond(const bool useEnharmony = false) const;
675
683 bool haveThird(const bool useEnharmony = false) const;
684
692 bool haveFourth(const bool useEnharmony = false) const;
693
701 bool haveFifth(const bool useEnharmony = false) const;
702
710 bool haveSixth(const bool useEnharmony = false) const;
711
719 bool haveSeventh(const bool useEnharmony = false) const;
720
728 bool haveOctave(const bool useEnharmony = false) const;
729
737 bool haveNinth(const bool useEnharmony = false) const;
738
746 bool haveEleventh(const bool useEnharmony = false) const;
747
755 bool haveThirdteenth(const bool useEnharmony = false) const;
756
757 // ===== ABSTRACTION 3 ===== //
758
767 bool haveAnyOctaveMinorSecond(const bool useEnharmony = false) const;
768
777 bool haveAnyOctaveMajorSecond(const bool useEnharmony = false) const;
778
787 bool haveAnyOctaveMinorThird(const bool useEnharmony = false) const;
788
797 bool haveAnyOctaveMajorThird(const bool useEnharmony = false) const;
798
807 bool haveAnyOctavePerfectFourth(const bool useEnharmony = false) const;
808
817 bool haveAnyOctaveAugmentedFourth(const bool useEnharmony = false) const;
818
827 bool haveAnyOctaveDiminishedFifth(const bool useEnharmony = false) const;
828
837 bool haveAnyOctavePerfectFifth(const bool useEnharmony = false) const;
838
847 bool haveAnyOctaveAugmentedFifth(const bool useEnharmony = false) const;
848
857 bool haveAnyOctaveMinorSixth(const bool useEnharmony = false) const;
858
867 bool haveAnyOctaveMajorSixth(const bool useEnharmony = false) const;
868
877 bool haveAnyOctaveDiminishedSeventh(const bool useEnharmony = false) const;
878
887 bool haveAnyOctaveMinorSeventh(const bool useEnharmony = false) const;
888
897 bool haveAnyOctaveMajorSeventh(const bool useEnharmony = false) const;
898
907 bool haveAnyOctaveDiminishedOctave(const bool useEnharmony = false) const;
908
917 bool haveAnyOctavePerfectOctave(const bool useEnharmony = false) const;
918
927 bool haveAnyOctaveAugmentedOctave(const bool useEnharmony = false) const;
928
929 // ===== ABSTRACTION 4 ===== //
930
938
945 bool haveAnyOctaveThird() const;
946
954
961 bool haveAnyOctaveFifth() const;
962
969 bool haveAnyOctaveSixth() const;
970
978
986
992 bool isDyad();
993
999 bool isSus();
1000
1007
1014
1021
1028
1035
1042
1049
1055 std::string getQuality();
1056
1062 bool isSorted() const;
1063
1098 bool isTonal(std::function<bool(const Chord& chord)> model = nullptr);
1099
1106
1114 std::vector<int> getMidiIntervals(const bool firstNoteAsReference = false) const;
1115
1123 std::vector<Interval> getIntervals(const bool firstNoteAsReference = false) const;
1124
1130 std::vector<Interval> getIntervalsFromOriginalSortedNotes() const;
1131
1139 std::vector<Interval> getOpenStackIntervals(const bool firstNoteAsReference = false);
1140
1148 std::vector<Interval> getCloseStackIntervals(const bool firstNoteAsReference = false);
1149
1155 std::vector<Note> getOpenStackNotes();
1156
1162 int size() const;
1163
1170
1175 void print() const;
1176
1181 void printStack() const;
1182
1187 void info();
1188
1195 Chord getOpenStackChord(const bool enharmonyNotes = false);
1196
1203 Chord getCloseStackChord(const bool enharmonyNotes = false);
1204
1211 Chord getCloseChord(const bool enharmonyNotes = false);
1212
1218
1224 std::vector<int> toCents() const;
1225
1233 int getDegree(const Key& key, bool enharmonyNotes = false);
1234
1242 std::string getRomanDegree(const Key& key, bool enharmonyNotes = false);
1243
1250 float getMeanFrequency(const float freqA4 = 440.0f) const;
1251
1258 float getMeanOfExtremesFrequency(const float freqA4 = 440.0f) const;
1259
1266 float getFrequencyStd(const float freqA4 = 440.0f) const;
1267
1273 int getMeanMidiValue() const;
1274
1281
1287 float getMidiValueStd() const;
1288
1295 std::string getMeanPitch(const std::string& accType = {}) const;
1296
1303 std::string getMeanOfExtremesPitch(const std::string& accType = {}) const;
1304
1313 std::pair<std::vector<float>, std::vector<float>> getHarmonicSpectrum(
1314 const int numPartialsPerNote = 6,
1315 const std::function<std::vector<float>(std::vector<float>)> amplCallback = nullptr,
1316 const float partialsDecayExpRate = 0.88f) const;
1317
1367 SetharesDissonanceTable getSetharesDyadsDissonanceValue(
1368 const int numPartials = 6, const bool useMinModel = true,
1369 const std::function<std::vector<float>(std::vector<float>)> amplCallback = nullptr,
1370 const float partialsDecayExpRate = 0.88f) const;
1371
1383 const int numPartialsPerNote = 6, const bool useMinModel = true,
1384 const std::function<std::vector<float>(std::vector<float>)> amplCallback = nullptr,
1385 const float partialsDecayExpRate = 0.88f,
1386 const std::function<float(std::vector<float>)> dissCallback = nullptr) const;
1387
1399 const Note& operator[](size_t index) const { return _originalNotes.at(index); }
1400
1411 Note& operator[](size_t index) { return _originalNotes.at(index); }
1412
1433 bool operator==(const Chord& otherChord) const {
1434 size_t sizeA = this->size();
1435 size_t sizeB = otherChord.size();
1436
1437 if (sizeA != sizeB) {
1438 return false;
1439 }
1440
1441 for (size_t i = 0; i < sizeA; i++) {
1442 if (_originalNotes[i] != otherChord.getNote(i)) {
1443 return false;
1444 }
1445 }
1446
1447 return true;
1448 }
1449
1469 bool operator!=(const Chord& otherChord) const {
1470 size_t sizeA = this->size();
1471 size_t sizeB = otherChord.size();
1472
1473 if (sizeA != sizeB) {
1474 return true;
1475 }
1476
1477 for (size_t i = 0; i < sizeA; i++) {
1478 if (_originalNotes[i] != otherChord.getNote(i)) {
1479 return true;
1480 }
1481 }
1482
1483 return false;
1484 }
1485
1518 Chord operator+(const Chord& otherChord) const {
1519 Chord x = *this;
1520
1521 const size_t sizeChord = otherChord.size();
1522 for (size_t i = 0; i < sizeChord; i++) {
1523 x.addNote(otherChord[i]);
1524 }
1525
1526 return x;
1527 }
1528
1533 std::vector<Note>::iterator begin() { return _originalNotes.begin(); }
1534
1539 std::vector<Note>::iterator end() { return _originalNotes.end(); }
1540
1548 friend std::ostream& operator<<(std::ostream& os, const Chord& chord);
1549};
Represents a musical chord.
Definition: chord.h:70
bool haveSixth(const bool useEnharmony=false) const
Checks if the chord contains any sixth interval (major or minor) between its notes.
bool isMajorChord()
Determines if the chord is a major triad.
int getMeanMidiValue() const
Calculates the arithmetic mean of the MIDI numbers of all notes in the chord.
bool haveAnyOctaveAugmentedOctave(const bool useEnharmony=false) const
Checks if the chord contains an augmented octave interval between any two notes, ignoring octave diff...
bool haveMinorInterval(const bool useEnharmony=false) const
Check if the chord contains at least one minor interval.
bool haveFifth(const bool useEnharmony=false) const
Checks if the chord contains any fifth interval (perfect, augmented, or diminished) between its notes...
bool haveMinorSecond(const bool useEnharmony=false)
Checks if the chord contains a minor second interval (e.g., C and Db).
bool haveAnyOctaveDiminishedOctave(const bool useEnharmony=false) const
Checks if the chord contains a diminished octave interval between any two notes, ignoring octave diff...
bool haveMajorInterval(const bool useEnharmony=false) const
Check if the chord contains at least one major interval.
float getMeanFrequency(const float freqA4=440.0f) const
Calculates the arithmetic mean of the frequencies of all notes in the chord.
void setDuration(const Duration &duration)
Set the duration for all notes in the chord.
bool isTonal(std::function< bool(const Chord &chord)> model=nullptr)
Determines if the chord is tonal according to a given model or default rules.
std::vector< Interval > getOpenStackIntervals(const bool firstNoteAsReference=false)
Returns the intervals between notes in the open stack as Interval objects.
std::string getQuality()
Returns a string describing the chord quality (e.g., "major", "minor", "diminished",...
void removeTopNote()
Remove the top (last) note from the chord.
Chord getOpenStackChord(const bool enharmonyNotes=false)
Returns a Chord object representing the open stack (stacked in thirds).
bool haveAnyOctavePerfectFifth(const bool useEnharmony=false) const
Checks if the chord contains a perfect fifth interval between any two notes, ignoring octave differen...
bool haveOctave(const bool useEnharmony=false) const
Checks if the chord contains any octave interval (perfect, augmented, or diminished) between its note...
std::vector< Interval > getIntervalsFromOriginalSortedNotes() const
Returns the intervals between the sorted original notes as Interval objects.
bool isSus()
Determines if the chord is a suspended chord (sus2 or sus4).
std::string getMeanPitch(const std::string &accType={}) const
Returns the pitch name corresponding to the mean MIDI value of the chord.
bool operator==(const Chord &otherChord) const
Equality operator comparing chords by pitch-space note ordering.
Definition: chord.h:1433
bool isDyad()
Determines if the chord is a dyad (contains exactly two distinct notes).
void addNote(const Note &note)
Add a Note object to the chord.
float getMeanOfExtremesFrequency(const float freqA4=440.0f) const
Calculates the mean frequency between the lowest and highest notes in the chord.
bool haveAnyOctaveMinorSeventh(const bool useEnharmony=false) const
Checks if the chord contains a minor seventh interval between any two notes, ignoring octave differen...
void printStack() const
Prints the pitches of all notes in the open stack to the log.
void insertNote(Note &insertNote, int positionNote=0)
Insert a note at a specific position in the chord.
bool haveAnyOctaveFifth() const
Checks if the chord contains a generic fifth interval (perfect, augmented, or diminished,...
std::vector< Note >::iterator end()
Returns an iterator to the end of the original notes vector.
Definition: chord.h:1539
std::vector< HeapData > getStackedHeaps(const bool enharmonyNotes=false)
Get all possible stacked heaps (enharmonic variants) for the chord.
const Note & getBassNote()
Get the bass note of the chord (lowest note).
bool haveSharpEleventh(const bool useEnharmony=false)
Checks if the chord contains a sharp eleventh interval (e.g., C and F# two octaves apart).
bool havePerfectEleventh(const bool useEnharmony=false)
Checks if the chord contains a perfect eleventh interval (e.g., C and F two octaves apart).
void toInversion(int inversionNumber)
Invert the chord by moving the lowest note up by one octave, repeated inversionNumber times.
void removeDuplicateNotes()
Remove duplicate notes (by pitch) from the chord.
std::vector< Note > getOpenStackNotes()
Returns the notes of the chord in open stack (stacked in thirds) order.
bool haveMajorSeventh(const bool useEnharmony=false)
Checks if the chord contains a major seventh interval (e.g., C and B).
bool isDominantSeventhChord()
Determines if the chord is a dominant seventh chord.
bool haveAnyOctaveDiminishedSeventh(const bool useEnharmony=false) const
Checks if the chord contains a diminished seventh interval between any two notes, ignoring octave dif...
Chord()
Construct an empty Chord object.
bool haveMinorNinth(const bool useEnharmony=false)
Checks if the chord contains a minor ninth interval (e.g., C and Db an octave apart).
void setDuration(const float quarterDuration, const int divisionsPerQuarterNote=256)
Set the duration for all notes in the chord using quarter note value.
bool havePerfectUnisson(const bool useEnharmony=false) const
Checks if the chord contains a perfect unison interval (e.g., two notes with the same pitch).
bool isInRootPosition()
Checks if the chord is in root position (lowest note is the root).
bool isDiminishedChord()
Determines if the chord is a diminished triad.
void info()
Prints detailed information about the chord, including name, size, notes, and stack.
bool haveAugmentedFourth(const bool useEnharmony=false)
Checks if the chord contains an augmented fourth interval (tritone, e.g., C and F#).
bool haveAnyOctaveSecond() const
Checks if the chord contains a generic second interval (major or minor, any octave).
bool haveDiminishedUnisson(const bool useEnharmony=false) const
Checks if the chord contains a diminished unison interval (e.g., C and Cb).
bool haveAnyOctaveThird() const
Checks if the chord contains a generic third interval (major or minor, any octave).
bool haveAnyOctaveFourth() const
Checks if the chord contains a generic fourth interval (perfect, augmented, or diminished,...
float getSetharesDissonance(const int numPartialsPerNote=6, const bool useMinModel=true, const std::function< std::vector< float >(std::vector< float >)> amplCallback=nullptr, const float partialsDecayExpRate=0.88f, const std::function< float(std::vector< float >)> dissCallback=nullptr) const
Calculates the total Sethares dissonance for the chord.
float getQuarterDuration() const
Get the shortest duration in quarter notes among all notes.
bool haveAnyOctaveMajorSeventh(const bool useEnharmony=false) const
Checks if the chord contains a major seventh interval between any two notes, ignoring octave differen...
bool isMinorChord()
Determines if the chord is a minor triad.
bool haveAnyOctaveMajorThird(const bool useEnharmony=false) const
Checks if the chord contains a major third interval between any two notes, ignoring octave difference...
bool haveMinorThird(const bool useEnharmony=false)
Checks if the chord contains a minor third interval (e.g., C and Eb).
bool operator!=(const Chord &otherChord) const
Inequality operator comparing chords by pitch-space note ordering.
Definition: chord.h:1469
bool haveAnyOctavePerfectFourth(const bool useEnharmony=false) const
Checks if the chord contains a perfect fourth interval between any two notes, ignoring octave differe...
std::vector< int > toCents() const
Returns a vector with the intervals (in cents) between each pair of adjacent notes in the chord.
bool haveAnyOctaveMajorSecond(const bool useEnharmony=false) const
Checks if the chord contains a major second interval between any two notes, ignoring octave differenc...
const Note & operator[](size_t index) const
Array subscript operator for read-only access to notes in original (unsorted) order.
Definition: chord.h:1399
Chord(const std::vector< std::string > &pitches, const RhythmFigure rhythmFigure=RhythmFigure::QUARTER)
Construct a Chord from a vector of pitch strings.
Chord(const std::vector< Note > &notes, const RhythmFigure rhythmFigure=RhythmFigure::QUARTER)
Construct a Chord from a vector of Note objects.
Chord getCloseStackChord(const bool enharmonyNotes=false)
Returns a Chord object representing the closed stack (stacked in thirds, closed position).
bool havePerfectFifth(const bool useEnharmony=false)
Checks if the chord contains a perfect fifth interval (e.g., C and G).
bool haveAugmentedFifth(const bool useEnharmony=false)
Checks if the chord contains an augmented fifth interval (e.g., C and G#).
void addNote(const std::string &pitch)
Add a note to the chord by pitch string.
bool haveAnyOctaveSeventh() const
Checks if the chord contains a generic seventh interval (major, minor, or diminished,...
Note & operator[](size_t index)
Array subscript operator for mutable access to notes in original (unsorted) order.
Definition: chord.h:1411
void transposeStackOnly(const int semiTonesNumber)
Transpose only the stacked (open) version of the chord by a number of semitones.
bool haveNinth(const bool useEnharmony=false) const
Checks if the chord contains any ninth interval (major or minor) between its notes.
const Note & getNote(const int noteIndex) const
Get a const reference to a note at a given index.
bool isWholeDiminishedChord()
Determines if the chord is a fully diminished seventh chord.
std::vector< int > getMidiIntervals(const bool firstNoteAsReference=false) const
Returns the intervals between notes in the chord as MIDI semitone values.
float getCloseStackHarmonicComplexity(const bool useEnharmony=false)
Compute the harmonic complexity of the chord in closed position.
bool haveAnyOctavePerfectOctave(const bool useEnharmony=false) const
Checks if the chord contains a perfect octave interval between any two notes, ignoring octave differe...
int getDegree(const Key &key, bool enharmonyNotes=false)
Returns the scale degree of the chord's root in a given key.
float getHarmonicDensity(const std::string &lowerBoundPitch={}, const std::string &higherBoundPitch={}) const
Compute the harmonic density of the chord in a pitch range.
float getFrequencyStd(const float freqA4=440.0f) const
Calculates the standard deviation of the frequencies of all notes in the chord.
bool haveAnyOctaveMinorSecond(const bool useEnharmony=false) const
Checks if the chord contains a minor second interval between any two notes, ignoring octave differenc...
void removeNote(int noteIndex)
Remove a note at a specific index from the chord.
std::string getName()
Get the chord name using tonal analysis (e.g., "Cm7", "G7").
bool haveSecond(const bool useEnharmony=false) const
Checks if the chord contains any second interval (major or minor) between its notes.
bool haveAnyOctaveMinorSixth(const bool useEnharmony=false) const
Checks if the chord contains a minor sixth interval between any two notes, ignoring octave difference...
bool isAugmentedChord()
Determines if the chord is an augmented triad.
bool haveMajorSixth(const bool useEnharmony=false)
Checks if the chord contains a major sixth interval (e.g., C and A).
std::string getDuration() const
Get the shortest duration type among all notes in the chord.
std::string getMeanOfExtremesPitch(const std::string &accType={}) const
Returns the pitch name corresponding to the mean of the lowest and highest MIDI values in the chord.
bool havePerfectOctave(const bool useEnharmony=false)
Checks if the chord contains a perfect octave interval (e.g., C4 and C5).
bool haveAnyOctaveOctave() const
Checks if the chord contains a generic octave interval (perfect, augmented, or diminished,...
bool isSorted() const
Checks if the notes in the chord are sorted in ascending order by MIDI number.
bool haveMinorSeventh(const bool useEnharmony=false)
Checks if the chord contains a minor seventh interval (e.g., C and Bb).
bool haveSeventh(const bool useEnharmony=false) const
Checks if the chord contains any seventh interval (major, minor, or diminished) between its notes.
bool haveThird(const bool useEnharmony=false) const
Checks if the chord contains any third interval (major or minor) between its notes.
bool havePerfectFourth(const bool useEnharmony=false)
Checks if the chord contains a perfect fourth interval (e.g., C and F).
std::vector< Interval > getIntervals(const bool firstNoteAsReference=false) const
Returns the intervals between notes in the chord as Interval objects.
void clear()
Remove all notes from the chord, resetting its state.
bool haveMinorSixth(const bool useEnharmony=false)
Checks if the chord contains a minor sixth interval (e.g., C and Ab).
bool isHalfDiminishedChord()
Determines if the chord is a half-diminished seventh chord.
bool haveDiminishedSeventh(const bool useEnharmony=false)
Checks if the chord contains a diminished seventh interval (e.g., C and Bbb).
bool haveAnyOctaveMinorThird(const bool useEnharmony=false) const
Checks if the chord contains a minor third interval between any two notes, ignoring octave difference...
bool haveDiminishedFifth(const bool useEnharmony=false)
Checks if the chord contains a diminished fifth interval (tritone, e.g., C and Gb).
bool haveThirdteenth(const bool useEnharmony=false) const
Checks if the chord contains any thirteenth interval (major or minor) between its notes.
int size() const
Returns the number of notes in the chord.
bool haveAugmentedInterval(const bool useEnharmony=false) const
Check if the chord contains at least one augmented interval.
bool haveDiminishedOctave(const bool useEnharmony=false)
Checks if the chord contains a diminished octave interval (e.g., C and Cb an octave apart).
bool haveMajorNinth(const bool useEnharmony=false)
Checks if the chord contains a major ninth interval (e.g., C and D an octave apart).
void transpose(const int semiTonesNumber)
Transpose all notes in the chord by a number of semitones.
~Chord()
Destroy the Chord object and release resources.
std::vector< Note >::iterator begin()
Returns an iterator to the beginning of the original notes vector.
Definition: chord.h:1533
std::vector< Interval > getCloseStackIntervals(const bool firstNoteAsReference=false)
Returns the intervals between notes in the closed stack as Interval objects.
bool haveMajorThird(const bool useEnharmony=false)
Checks if the chord contains a major third interval (e.g., C and E).
const Note & getRoot()
Get the root note of the chord (after stacking in thirds).
bool haveAnyOctaveDiminishedFifth(const bool useEnharmony=false) const
Checks if the chord contains a diminished fifth interval between any two notes, ignoring octave diffe...
int getDurationTicks() const
Get the minimum duration in ticks among all notes.
float getMidiValueStd() const
Calculates the standard deviation of the MIDI numbers of all notes in the chord.
bool haveMinorThirdteenth(const bool useEnharmony=false)
Checks if the chord contains a minor thirteenth interval (e.g., C and Ab two octaves plus a sixth apa...
bool haveAnyOctaveMajorSixth(const bool useEnharmony=false) const
Checks if the chord contains a major sixth interval between any two notes, ignoring octave difference...
float getHarmonicDensity(int lowerBoundMIDI=-1, int higherBoundMIDI=-1) const
Compute the harmonic density of the chord in a MIDI range.
Note & getNote(int noteIndex)
Get a reference to a note at a given index.
bool haveEleventh(const bool useEnharmony=false) const
Checks if the chord contains any eleventh interval (perfect or sharp) between its notes.
bool haveMajorSecond(const bool useEnharmony=false)
Checks if the chord contains a major second interval (e.g., C and D).
std::pair< std::vector< float >, std::vector< float > > getHarmonicSpectrum(const int numPartialsPerNote=6, const std::function< std::vector< float >(std::vector< float >)> amplCallback=nullptr, const float partialsDecayExpRate=0.88f) const
Computes the combined harmonic spectrum of the chord by summing the spectra of all notes.
bool havePerfectInterval(const bool useEnharmony=false) const
Check if the chord contains at least one perfect interval.
const std::vector< Note > & getNotes() const
Get all notes in the chord (original order).
Chord getCloseChord(const bool enharmonyNotes=false)
Returns a Chord object representing the closed chord, with octaves adjusted to match the original.
std::string getRomanDegree(const Key &key, bool enharmonyNotes=false)
Returns the Roman numeral degree of the chord's root in a given key.
SetharesDissonanceTable getSetharesDyadsDissonanceValue(const int numPartials=6, const bool useMinModel=true, const std::function< std::vector< float >(std::vector< float >)> amplCallback=nullptr, const float partialsDecayExpRate=0.88f) const
Calculates the Sethares dissonance value for all dyads in the chord.
bool haveAnyOctaveAugmentedFourth(const bool useEnharmony=false) const
Checks if the chord contains an augmented fourth interval between any two notes, ignoring octave diff...
bool haveFourth(const bool useEnharmony=false) const
Checks if the chord contains any fourth interval (perfect, augmented, or diminished) between its note...
bool haveDiminishedInterval(const bool useEnharmony=false) const
Check if the chord contains at least one diminished interval.
int stackSize()
Returns the number of notes in the open stack (after stacking in thirds).
bool haveMajorThirdteenth(const bool useEnharmony=false)
Checks if the chord contains a major thirteenth interval (e.g., C and A two octaves plus a sixth apar...
bool haveAnyOctaveAugmentedFifth(const bool useEnharmony=false) const
Checks if the chord contains an augmented fifth interval between any two notes, ignoring octave diffe...
bool haveAnyOctaveSixth() const
Checks if the chord contains a generic sixth interval (major or minor, any octave).
bool haveAugmentedOctave(const bool useEnharmony=false)
Checks if the chord contains an augmented octave interval (e.g., C and C# an octave apart).
bool haveAugmentedUnisson(const bool useEnharmony=false) const
Checks if the chord contains an augmented unison interval (e.g., C and C#).
friend std::ostream & operator<<(std::ostream &os, const Chord &chord)
Output stream operator for Chord. Prints the chord as a list of pitches.
void sortNotes()
Sorts the notes in the chord in ascending order by MIDI number.
void print() const
Prints the pitches of all notes in the chord to the log.
int getMeanOfExtremesMidiValue() const
Calculates the mean MIDI value between the lowest and highest notes in the chord.
Represents the duration of a musical note, supporting multiple temporal representations.
Definition: duration.h:15
Represents a musical key signature (tonality), including circle of fifths and mode (major/minor).
Definition: key.h:11
Represents a musical note, including pitch, duration, articulation, and MusicXML-related attributes.
Definition: note.h:19