This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Chords.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Intervals.hpp"
5 
7 
8 class 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 
15 template <uint8_t N>
16 class 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>
23  Chord<N + M> operator+(const Chord<M> &rhs) const {
24  return {cat(this->getOffsets(), rhs.getOffsets())};
25  }
26 
27  Chord<N + 1> operator+(int8_t rhs) const { return *this + Chord<1>{{rhs}}; }
28 
29  const Array<int8_t, N> getOffsets() const { return offsets; }
30 
31  private:
33 };
34 
37 
39 namespace Chords {
40 
41 using namespace Intervals;
42 
43 const Chord<2> Major = {{M3, P5}};
44 const Chord<2> MajorFirstInv = {{M3, P5 - P8}}; // First inversion
45 const Chord<2> MajorSecondInv = {{M3 - P8, P5 - P8}}; // Second inversion
46 
47 const Chord<2> Minor = {{m3, P5}};
48 const Chord<2> MinorFirstInv = {{m3, P5 - P8}};
49 const Chord<2> MinorSecondInv = {{m3 - P8, P5 - P8}};
50 
51 const Chord<2> Diminished = {{m3, d5}};
52 const Chord<2> Augmented = {{m3, m6}};
53 
55 const Chord<3> MajorSeventh = {{M3, P5, M7}};
56 
57 } // namespace Chords
58 
60 namespace Bass {
61 
62 using namespace Intervals;
63 
64 const Chord<1> Single = {{-P8}};
65 const Chord<2> Double = {{-P8, -2 * P8}};
66 const Chord<3> Triple = {{-P8, -2 * P8, -3 * P8}};
67 
68 } // namespace Bass
69 
71 
Intervals::m3
constexpr int8_t m3
Definition: Intervals.hpp:10
IChord::begin
virtual const int8_t * begin() const =0
Chords::MinorFirstInv
const Chord< 2 > MinorFirstInv
Definition: Chords.hpp:48
Intervals::M7
constexpr int8_t M7
Definition: Intervals.hpp:18
Chord
Definition: Chords.hpp:16
Chord::Chord
Chord(const Array< int8_t, N > &offsets)
Definition: Chords.hpp:18
Chord::operator+
Chord< N+1 > operator+(int8_t rhs) const
Definition: Chords.hpp:27
Bass
Predefined Chord constants with bass notes.
Definition: Chords.hpp:60
Chords::MajorSecondInv
const Chord< 2 > MajorSecondInv
Definition: Chords.hpp:45
IChord::~IChord
virtual ~IChord()=default
Array< int8_t, N >
Intervals::m7
constexpr int8_t m7
Definition: Intervals.hpp:17
Chords::MajorSeventh
const Chord< 3 > MajorSeventh
Definition: Chords.hpp:55
Chords::MinorSecondInv
const Chord< 2 > MinorSecondInv
Definition: Chords.hpp:49
Chords::Minor
const Chord< 2 > Minor
Definition: Chords.hpp:47
Intervals
Definition: Intervals.hpp:5
Intervals::M3
constexpr int8_t M3
Definition: Intervals.hpp:11
Intervals.hpp
Chord::operator+
Chord< N+M > operator+(const Chord< M > &rhs) const
Definition: Chords.hpp:23
Chords::Diminished
const Chord< 2 > Diminished
Definition: Chords.hpp:51
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
Bass::Single
const Chord< 1 > Single
Definition: Chords.hpp:64
Chord::offsets
Array< int8_t, N > offsets
Definition: Chords.hpp:32
Chords::Augmented
const Chord< 2 > Augmented
Definition: Chords.hpp:52
Intervals::P5
constexpr int8_t P5
Definition: Intervals.hpp:14
IChord::end
virtual const int8_t * end() const =0
Chords::MajorFirstInv
const Chord< 2 > MajorFirstInv
Definition: Chords.hpp:44
IChord
Definition: Chords.hpp:8
ArrayHelpers.hpp
Array::end
T * end()
Get a pointer to the memory beyond the array.
Definition: Array.hpp:72
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
Intervals::P8
constexpr int8_t P8
Definition: Intervals.hpp:19
Chords::DominantSeventh
const Chord< 3 > DominantSeventh
Definition: Chords.hpp:54
Chords::Major
const Chord< 2 > Major
Definition: Chords.hpp:43
Chord::begin
const int8_t * begin() const override
Definition: Chords.hpp:19
Bass::Triple
const Chord< 3 > Triple
Definition: Chords.hpp:66
Bass::Double
const Chord< 2 > Double
Definition: Chords.hpp:65
Intervals::d5
constexpr int8_t d5
Definition: Intervals.hpp:13
Chords
Predefined Chord constants.
Definition: Chords.hpp:39
Chord::end
const int8_t * end() const override
Definition: Chords.hpp:20
Intervals::m6
constexpr int8_t m6
Definition: Intervals.hpp:15
Chord::getOffsets
const Array< int8_t, N > getOffsets() const
Definition: Chords.hpp:29
Array::begin
T * begin()
Get a pointer to the first element.
Definition: Array.hpp:62
cat
Array< T, M+N > cat(const Array< T, M > &a, const Array< T, N > &b)
Concatenate two arrays.
Definition: ArrayHelpers.hpp:173