LCOV - code coverage report
Current view: top level - src/MIDI_Constants/Chords - Chords.hpp (source / functions) Hit Total Coverage
Test: 3a807a259ebe0769dd942f7f612dca5273937539 Lines: 2 4 50.0 %
Date: 2024-03-24 17:16:54 Functions: 4 11 36.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "Intervals.hpp"
       4             : #include <Def/Def.hpp>
       5             : 
       6             : BEGIN_CS_NAMESPACE
       7             : 
       8             : class IChord {
       9             :   public:
      10        7761 :     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:
      18        7761 :     Chord(const Array<int8_t, N> &offsets) : offsets(offsets) {}
      19           0 :     const int8_t *begin() const override { return offsets.begin(); }
      20           0 :     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 {
      28             :         return *this + Chord<1> {{rhs}};
      29             :     }
      30             : 
      31             :     const Array<int8_t, N> getOffsets() const { return offsets; }
      32             : 
      33             :   private:
      34             :     Array<int8_t, N> offsets;
      35             : };
      36             : 
      37             : /// @addtogroup MIDIConstants
      38             : /// @{
      39             : 
      40             : /// Predefined Chord constants.
      41             : namespace Chords {
      42             : 
      43             : using namespace Intervals;
      44             : 
      45             : const Chord<2> Major = {{M3, P5}};
      46             : const Chord<2> MajorFirstInv = {{M3, P5 - P8}};       // First inversion
      47             : const Chord<2> MajorSecondInv = {{M3 - P8, P5 - P8}}; // Second inversion
      48             : 
      49             : const Chord<2> Minor = {{m3, P5}};
      50             : const Chord<2> MinorFirstInv = {{m3, P5 - P8}};
      51             : const Chord<2> MinorSecondInv = {{m3 - P8, P5 - P8}};
      52             : 
      53             : const Chord<2> Diminished = {{m3, d5}};
      54             : const Chord<2> Augmented = {{m3, m6}};
      55             : 
      56             : const Chord<3> DominantSeventh = {{M3, P5, m7}};
      57             : const Chord<3> MajorSeventh = {{M3, P5, M7}};
      58             : 
      59             : } // namespace Chords
      60             : 
      61             : /// Predefined Chord constants with bass notes.
      62             : namespace Bass {
      63             : 
      64             : using namespace Intervals;
      65             : 
      66             : const Chord<1> Single = {{-P8}};
      67             : const Chord<2> Double = {{-P8, -2 * P8}};
      68             : const Chord<3> Triple = {{-P8, -2 * P8, -3 * P8}};
      69             : 
      70             : } // namespace Bass
      71             : 
      72             : /// @}
      73             : 
      74             : END_CS_NAMESPACE

Generated by: LCOV version 1.15