LCOV - code coverage report
Current view: top level - src/Control_Surface - Control_Surface_Class.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 7 7 100.0 %
Date: 2019-11-24 14:50:27 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* ✔ */
       2             : 
       3             : #pragma once
       4             : 
       5             : #include <MIDI_Interfaces/MIDI_Interface.hpp>
       6             : 
       7             : #include <Display/DisplayElement.hpp>
       8             : #include <Display/DisplayInterface.hpp>
       9             : #include <Helpers/MillisMicrosTimer.hpp>
      10             : 
      11             : BEGIN_CS_NAMESPACE
      12             : 
      13             : /** 
      14             :  * @brief   This class ensures initialization, updating, and interaction between
      15             :  *          all other classes, it's the glue that holds everything together.
      16             :  * 
      17             :  * @ingroup ControlSurfaceModule
      18             :  */
      19           2 : class Control_Surface_ : public MIDI_Callbacks {
      20             :   public:
      21             :     // Copying is not allowed
      22             :     Control_Surface_(Control_Surface_ const &) = delete;
      23             :     void operator=(Control_Surface_ const &) = delete;
      24             : 
      25             :     /**
      26             :      * @brief   Return the static Control_Surface_ instance.
      27             :      *          (Control_Surface_ is a singleton.)
      28             :      */
      29             :     static Control_Surface_ &getInstance();
      30             : 
      31             :     /**
      32             :      * @brief   Initialize the Control_Surface.
      33             :      */
      34             :     void begin();
      35             : 
      36             :     /**
      37             :      * @brief   Update all MIDI elements, send MIDI events and read MIDI input.
      38             :      */
      39             :     void loop();
      40             : 
      41             :     /**
      42             :      * @brief   Get the MIDI interface of the Control Surface.
      43             :      *
      44             :      * @return  A reference to the Control Surface's MIDI interface.
      45             :      * 
      46             :      * @todo    This violate's the Law of Demeter.
      47             :      */
      48             :     MIDI_Interface &MIDI();
      49             : 
      50             :     /** 
      51             :      * @brief   Update all MIDI interfaces to receive new MIDI events.
      52             :      */
      53             :     void updateMidiInput();
      54             : 
      55             :     /**
      56             :      * @brief   Update all MIDIInputElement%s.
      57             :      */
      58             :     void updateInputs();
      59             : 
      60             :     /** 
      61             :      * @brief   Clear, draw and display all displays.
      62             :      */
      63             :     void updateDisplays();
      64             : 
      65             :   private:
      66             :     /**
      67             :      * @brief   Control_Surface_ is a singleton, so the constructor is private.
      68             :      */
      69           4 :     Control_Surface_() = default;
      70             : 
      71             :     /** 
      72             :      * @brief   The callback to be called when a MIDI channel message is
      73             :      *          received.
      74             :      */
      75             :     void onChannelMessage(Parsing_MIDI_Interface &midi) override;
      76             : 
      77             :     /** 
      78             :      * @brief   The callback to be called when a MIDI System Exclusive message
      79             :      *          is received.
      80             :      */
      81             :     void onSysExMessage(Parsing_MIDI_Interface &midi) override;
      82             : 
      83             :     /** 
      84             :      * @brief   The callback to be called when a MIDI Real-Time message is 
      85             :      *          received.
      86             :      */
      87             :     void onRealtimeMessage(Parsing_MIDI_Interface &midi,
      88             :                            uint8_t message) override;
      89             : 
      90             :     /// A timer to know when to update the analog inputs.
      91           2 :     Timer<micros> potentiometerTimer = {FILTERED_INPUT_UPDATE_INTERVAL};
      92             :     /// A timer to know when to refresh the displays.
      93           2 :     Timer<micros> displayTimer = {1000000UL / MAX_FPS};
      94             : 
      95             :   public:
      96             :     /// Callback function type for channel messages. Return true if handling is
      97             :     /// done in the user-provided callback, false if `Control_Surface`
      98             :     /// should handle the message.
      99             :     using ChannelMessageCallback = bool (*)(ChannelMessage);
     100             :     /// Callback function type for SysEx messages. Return true if handling is
     101             :     /// done in the user-provided callback, false if `Control_Surface`
     102             :     /// should handle the message.
     103             :     using SysExMessageCallback = bool (*)(SysExMessage);
     104             :     /// Callback function type for Real-Time messages. Return true if handling
     105             :     /// is done in the user-provided callback, false if `Control_Surface`
     106             :     /// should handle the message.
     107             :     using RealTimeMessageCallback = bool (*)(RealTimeMessage);
     108             : 
     109             :     /// Set the MIDI input callbacks.
     110             :     void
     111             :     setMIDIInputCallbacks(ChannelMessageCallback channelMessageCallback,
     112             :                           SysExMessageCallback sysExMessageCallback,
     113             :                           RealTimeMessageCallback realTimeMessageCallback) {
     114             :         this->channelMessageCallback = channelMessageCallback;
     115             :         this->sysExMessageCallback = sysExMessageCallback;
     116             :         this->realTimeMessageCallback = realTimeMessageCallback;
     117             :     }
     118             : 
     119             :   private:
     120           2 :     ChannelMessageCallback channelMessageCallback = nullptr;
     121           2 :     SysExMessageCallback sysExMessageCallback = nullptr;
     122           2 :     RealTimeMessageCallback realTimeMessageCallback = nullptr;
     123             : };
     124             : 
     125             : /// A predefined instance of the Control Surface to use in the Arduino sketches.
     126             : extern Control_Surface_ &Control_Surface;
     127             : 
     128             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6