LCOV - code coverage report
Current view: top level - src/MIDI_Inputs - MIDIInputElementChannelPressure.hpp (source / functions) Hit Total Coverage
Test: 90a1b9beff85a60dc6ebcea034a947a845e56960 Lines: 24 30 80.0 %
Date: 2019-11-30 15:53:32 Functions: 6 9 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "MIDIInputElement.hpp"
       4             : #include <AH/Containers/LinkedList.hpp>
       5             : 
       6             : #if defined(ESP32)
       7             : #include <mutex>
       8             : #define GUARD_LIST_LOCK std::lock_guard<std::mutex> _guard(mutex)
       9             : #else
      10             : #define GUARD_LIST_LOCK
      11             : #endif
      12             : 
      13             : BEGIN_CS_NAMESPACE
      14             : 
      15             : class MIDIInputElementChannelPressure
      16             :     : public MIDIInputElement,
      17             :       public DoublyLinkable<MIDIInputElementChannelPressure> {
      18             :   public:
      19             :     /**
      20             :      * @brief   Constructor.
      21             :      * @todo    Documentation.
      22             :      */
      23          12 :     MIDIInputElementChannelPressure(const MIDICNChannelAddress &address)
      24          24 :         : MIDIInputElement(address) {
      25             :         GUARD_LIST_LOCK;
      26          12 :         elements.append(this);
      27          12 :     }
      28             : 
      29             :     /**
      30             :      * @brief   Destructor.
      31             :      * @todo    Documentation.
      32             :      */
      33          12 :     virtual ~MIDIInputElementChannelPressure() {
      34             :         GUARD_LIST_LOCK;
      35          12 :         elements.remove(this);
      36          12 :     }
      37             : 
      38           1 :     static void beginAll() {
      39             :         GUARD_LIST_LOCK;
      40           2 :         for (MIDIInputElementChannelPressure &el : elements)
      41           1 :             el.begin();
      42           1 :     }
      43             : 
      44             :     /**
      45             :      * @brief   Reset all MIDIInputElementChannelPressure elements to their 
      46             :      *          initial state.
      47             :      *
      48             :      * @see     MIDIInputElementChannelPressure#reset
      49             :      */
      50           0 :     static void resetAll() {
      51             :         GUARD_LIST_LOCK;
      52           0 :         for (MIDIInputElementChannelPressure &el : elements)
      53           0 :             el.reset();
      54           0 :     }
      55             : 
      56             :     /**
      57             :      * @brief   Update all MIDIInputElementChannelPressure elements.
      58             :      */
      59           1 :     static void updateAll() {
      60             :         GUARD_LIST_LOCK;
      61           2 :         for (MIDIInputElementChannelPressure &el : elements)
      62           1 :             el.update();
      63           1 :     }
      64             : 
      65             :     /**
      66             :      * @brief   Update all MIDIInputElementChannelPressure elements with a new MIDI
      67             :      *          message.
      68             :      *
      69             :      * @see     MIDIInputElementChannelPressure#updateWith
      70             :      */
      71          19 :     static void updateAllWith(const ChannelMessageMatcher &midimsg) {
      72          19 :         for (MIDIInputElementChannelPressure &e : elements)
      73          19 :             if (e.updateWith(midimsg)) {
      74          19 :                 e.moveDown();
      75          19 :                 return;
      76             :             }
      77             :         // No mutex required:
      78             :         // e.moveDown may alter the list, but if it does, it always returns,
      79             :         // and we stop iterating, so it doesn't matter.
      80          19 :     }
      81             : 
      82             :   private:
      83             :     /// Channel Pressure doesn't have an address, so the target consists of just
      84             :     /// the channel and the cable number.
      85             :     MIDICNChannelAddress
      86           0 :     getTarget(const ChannelMessageMatcher &midimsg) const override {
      87           0 :         return {0, Channel(midimsg.channel), midimsg.CN};
      88             :     }
      89             : 
      90             :     /**
      91             :      * @brief   Move down this element in the linked list of elements.
      92             :      * 
      93             :      * This means that the element will be checked earlier on the next
      94             :      * iteration.
      95             :      */
      96          19 :     void moveDown() {
      97             :         GUARD_LIST_LOCK;
      98          19 :         elements.moveDown(this);
      99          19 :     }
     100             : 
     101             :     static DoublyLinkedList<MIDIInputElementChannelPressure> elements;
     102             : #ifdef ESP32
     103             :     static std::mutex mutex;
     104             : #endif
     105             : };
     106             : 
     107             : #undef GUARD_LIST_LOCK
     108             : 
     109             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6