LCOV - code coverage report
Current view: top level - src/MIDI_Constants/Chords - Chords.hpp (source / functions) Hit Total Coverage
Test: 90a1b9beff85a60dc6ebcea034a947a845e56960 Lines: 17 19 89.5 %
Date: 2019-11-30 15:53:32 Functions: 21 31 67.7 %
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          26 : class IChord {
       9             :   public:
      10          26 :     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          26 : class Chord : public IChord {
      17             :   public:
      18          26 :     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 { return *this + Chord<1>{{rhs}}; }
      28             : 
      29             :     const Array<int8_t, N> getOffsets() const { return offsets; }
      30             : 
      31             :   private:
      32             :     Array<int8_t, N> offsets;
      33             : };
      34             : 
      35             : /// @addtogroup MIDIConstants
      36             : /// @{
      37             : 
      38             : /// Predefined Chord constants.
      39             : namespace Chords {
      40             : 
      41             : using namespace Intervals;
      42             : 
      43           2 : const Chord<2> Major = {{M3, P5}};
      44           2 : const Chord<2> MajorFirstInv = {{M3, P5 - P8}};       // First inversion
      45           2 : const Chord<2> MajorSecondInv = {{M3 - P8, P5 - P8}}; // Second inversion
      46             : 
      47           2 : const Chord<2> Minor = {{m3, P5}};
      48           2 : const Chord<2> MinorFirstInv = {{m3, P5 - P8}};
      49           2 : const Chord<2> MinorSecondInv = {{m3 - P8, P5 - P8}};
      50             : 
      51           2 : const Chord<2> Diminished = {{m3, d5}};
      52           2 : const Chord<2> Augmented = {{m3, m6}};
      53             : 
      54           2 : const Chord<3> DominantSeventh = {{M3, P5, m7}};
      55           2 : const Chord<3> MajorSeventh = {{M3, P5, M7}};
      56             : 
      57             : } // namespace Chords
      58             : 
      59             : /// Predefined Chord constants with bass notes.
      60             : namespace Bass {
      61             : 
      62             : using namespace Intervals;
      63             : 
      64           2 : const Chord<1> Single = {{-P8}};
      65           2 : const Chord<2> Double = {{-P8, -2 * P8}};
      66           2 : const Chord<3> Triple = {{-P8, -2 * P8, -3 * P8}};
      67             : 
      68             : } // namespace Bass
      69             : 
      70             : /// @}
      71             : 
      72             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6