Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Chords.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Intervals.hpp"
4#include <Def/Def.hpp>
5
7
8class IChord {
9 public:
10 virtual ~IChord() = default;
11 virtual const int8_t *begin() const = 0;
12 virtual const int8_t *end() const = 0;
13};
14
15template <uint8_t N>
16class Chord : public IChord {
17 public:
19 const int8_t *begin() const override { return offsets.begin(); }
20 const int8_t *end() const override { return offsets.end(); }
21
22 template <uint8_t M>
24 return {cat(this->getOffsets(), rhs.getOffsets())};
25 }
26
28 return *this + Chord<1> {{rhs}};
29 }
30
31 const Array<int8_t, N> getOffsets() const { return offsets; }
32
33 private:
35};
36
39
41namespace Chords {
42
43using namespace Intervals;
44
45const Chord<2> Major = {{M3, P5}};
46const Chord<2> MajorFirstInv = {{M3, P5 - P8}}; // First inversion
47const Chord<2> MajorSecondInv = {{M3 - P8, P5 - P8}}; // Second inversion
48
49const Chord<2> Minor = {{m3, P5}};
50const Chord<2> MinorFirstInv = {{m3, P5 - P8}};
51const Chord<2> MinorSecondInv = {{m3 - P8, P5 - P8}};
52
53const Chord<2> Diminished = {{m3, d5}};
54const Chord<2> Augmented = {{m3, m6}};
55
58
59} // namespace Chords
60
62namespace Bass {
63
64using namespace Intervals;
65
66const Chord<1> Single = {{-P8}};
67const Chord<2> Double = {{-P8, -2 * P8}};
68const Chord<3> Triple = {{-P8, -2 * P8, -3 * P8}};
69
70} // namespace Bass
71
73
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Chord< N+1 > operator+(int8_t rhs) const
Definition Chords.hpp:27
Array< int8_t, N > offsets
Definition Chords.hpp:34
Chord< N+M > operator+(const Chord< M > &rhs) const
Definition Chords.hpp:23
Chord(const Array< int8_t, N > &offsets)
Definition Chords.hpp:18
const Array< int8_t, N > getOffsets() const
Definition Chords.hpp:31
const int8_t * end() const override
Definition Chords.hpp:20
const int8_t * begin() const override
Definition Chords.hpp:19
virtual ~IChord()=default
virtual const int8_t * begin() const =0
virtual const int8_t * end() const =0
Predefined Chord constants with bass notes.
Definition Chords.hpp:62
const Chord< 3 > Triple
Definition Chords.hpp:68
const Chord< 2 > Double
Definition Chords.hpp:67
const Chord< 1 > Single
Definition Chords.hpp:66
Predefined Chord constants.
Definition Chords.hpp:41
const Chord< 2 > MajorSecondInv
Definition Chords.hpp:47
const Chord< 2 > Augmented
Definition Chords.hpp:54
const Chord< 2 > MajorFirstInv
Definition Chords.hpp:46
const Chord< 3 > DominantSeventh
Definition Chords.hpp:56
const Chord< 3 > MajorSeventh
Definition Chords.hpp:57
const Chord< 2 > MinorSecondInv
Definition Chords.hpp:51
const Chord< 2 > Minor
Definition Chords.hpp:49
const Chord< 2 > MinorFirstInv
Definition Chords.hpp:50
const Chord< 2 > Major
Definition Chords.hpp:45
const Chord< 2 > Diminished
Definition Chords.hpp:53
constexpr int8_t m3
Minor third.
Definition Intervals.hpp:10
constexpr int8_t P8
Perfect octave.
Definition Intervals.hpp:19
constexpr int8_t d5
Diminished fifth.
Definition Intervals.hpp:13
constexpr int8_t m7
Minor seventh.
Definition Intervals.hpp:17
constexpr int8_t M7
Major seventh.
Definition Intervals.hpp:18
constexpr int8_t M3
Major third.
Definition Intervals.hpp:11
constexpr int8_t m6
Minor sixth.
Definition Intervals.hpp:15
constexpr int8_t P5
Perfect fifth.
Definition Intervals.hpp:14
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32
T * begin()
Get a pointer to the first element.
Definition Array.hpp:74
T * end()
Get a pointer to the memory beyond the array.
Definition Array.hpp:84