Control Surface  1.1.1
MIDI Control Surface library for Arduino
Chords.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Intervals.hpp"
4 #include <Def/Def.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::d5
constexpr int8_t d5
Definition: Intervals.hpp:13
AH::Array::end
T * end()
Get a pointer to the memory beyond the array.
Definition: Array.hpp:88
Chords::DominantSeventh
const Chord< 3 > DominantSeventh
Definition: Chords.hpp:54
IChord::~IChord
virtual ~IChord()=default
Intervals::P5
constexpr int8_t P5
Definition: Intervals.hpp:14
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
Chords::MinorFirstInv
const Chord< 2 > MinorFirstInv
Definition: Chords.hpp:48
Bass
Predefined Chord constants with bass notes.
Definition: Chords.hpp:60
Def.hpp
Intervals::m7
constexpr int8_t m7
Definition: Intervals.hpp:17
Chord::begin
const int8_t * begin() const override
Definition: Chords.hpp:19
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
AH::cat
Array< T, M+N > cat(const Array< T, M > &a, const Array< T, N > &b)
Concatenate two arrays.
Definition: ArrayHelpers.hpp:204
Bass::Triple
const Chord< 3 > Triple
Definition: Chords.hpp:66
Intervals
Definition: Intervals.hpp:5
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
Intervals.hpp
Intervals::m3
constexpr int8_t m3
Definition: Intervals.hpp:10
Intervals::m6
constexpr int8_t m6
Definition: Intervals.hpp:15
Chord::offsets
Array< int8_t, N > offsets
Definition: Chords.hpp:32
IChord::end
virtual const int8_t * end() const =0
AH::Array
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:36
Chords::Diminished
const Chord< 2 > Diminished
Definition: Chords.hpp:51
IChord
Definition: Chords.hpp:8
Intervals::P8
constexpr int8_t P8
Definition: Intervals.hpp:19
Bass::Single
const Chord< 1 > Single
Definition: Chords.hpp:64
AH::Array::begin
T * begin()
Get a pointer to the first element.
Definition: Array.hpp:78
Chords::Minor
const Chord< 2 > Minor
Definition: Chords.hpp:47
Chords::Augmented
const Chord< 2 > Augmented
Definition: Chords.hpp:52
IChord::begin
virtual const int8_t * begin() const =0
Chord::operator+
Chord< N+1 > operator+(int8_t rhs) const
Definition: Chords.hpp:27
Chords::MajorSeventh
const Chord< 3 > MajorSeventh
Definition: Chords.hpp:55
Chords::MajorFirstInv
const Chord< 2 > MajorFirstInv
Definition: Chords.hpp:44
Chords
Predefined Chord constants.
Definition: Chords.hpp:39
Intervals::M3
constexpr int8_t M3
Definition: Intervals.hpp:11
Bass::Double
const Chord< 2 > Double
Definition: Chords.hpp:65
Chords::Major
const Chord< 2 > Major
Definition: Chords.hpp:43
Chords::MinorSecondInv
const Chord< 2 > MinorSecondInv
Definition: Chords.hpp:49
Chords::MajorSecondInv
const Chord< 2 > MajorSecondInv
Definition: Chords.hpp:45
Chord::end
const int8_t * end() const override
Definition: Chords.hpp:20
Chord::getOffsets
const Array< int8_t, N > getOffsets() const
Definition: Chords.hpp:29
Chord::operator+
Chord< N+M > operator+(const Chord< M > &rhs) const
Definition: Chords.hpp:23