Control Surface pin-t-adl
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
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>
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
39namespace Chords {
40
41using namespace Intervals;
42
43const Chord<2> Major = {{M3, P5}};
44const Chord<2> MajorFirstInv = {{M3, P5 - P8}}; // First inversion
45const Chord<2> MajorSecondInv = {{M3 - P8, P5 - P8}}; // Second inversion
46
47const Chord<2> Minor = {{m3, P5}};
48const Chord<2> MinorFirstInv = {{m3, P5 - P8}};
49const Chord<2> MinorSecondInv = {{m3 - P8, P5 - P8}};
50
51const Chord<2> Diminished = {{m3, d5}};
52const Chord<2> Augmented = {{m3, m6}};
53
56
57} // namespace Chords
58
60namespace Bass {
61
62using namespace Intervals;
63
64const Chord<1> Single = {{-P8}};
65const Chord<2> Double = {{-P8, -2 * P8}};
66const Chord<3> Triple = {{-P8, -2 * P8, -3 * P8}};
67
68} // namespace Bass
69
71
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Chords.hpp:16
Chord< N+1 > operator+(int8_t rhs) const
Definition: Chords.hpp:27
Array< int8_t, N > offsets
Definition: Chords.hpp:32
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:29
const int8_t * end() const override
Definition: Chords.hpp:20
const int8_t * begin() const override
Definition: Chords.hpp:19
Definition: Chords.hpp:8
virtual ~IChord()=default
virtual const int8_t * begin() const =0
virtual const int8_t * end() const =0
Array< T, M+N > cat(const Array< T, M > &a, const Array< T, N > &b)
Concatenate two arrays.
Predefined Chord constants with bass notes.
Definition: Chords.hpp:60
const Chord< 3 > Triple
Definition: Chords.hpp:66
const Chord< 2 > Double
Definition: Chords.hpp:65
const Chord< 1 > Single
Definition: Chords.hpp:64
Predefined Chord constants.
Definition: Chords.hpp:39
const Chord< 2 > MajorSecondInv
Definition: Chords.hpp:45
const Chord< 2 > Augmented
Definition: Chords.hpp:52
const Chord< 2 > MajorFirstInv
Definition: Chords.hpp:44
const Chord< 3 > DominantSeventh
Definition: Chords.hpp:54
const Chord< 3 > MajorSeventh
Definition: Chords.hpp:55
const Chord< 2 > MinorSecondInv
Definition: Chords.hpp:49
const Chord< 2 > Minor
Definition: Chords.hpp:47
const Chord< 2 > MinorFirstInv
Definition: Chords.hpp:48
const Chord< 2 > Major
Definition: Chords.hpp:43
const Chord< 2 > Diminished
Definition: Chords.hpp:51
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:36
T * begin()
Get a pointer to the first element.
Definition: Array.hpp:78
T * end()
Get a pointer to the memory beyond the array.
Definition: Array.hpp:88