Skip to content

Commit

Permalink
Use included Encoder library
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Sep 7, 2020
1 parent bfff16b commit 40e3d7a
Show file tree
Hide file tree
Showing 36 changed files with 91 additions and 94 deletions.
11 changes: 2 additions & 9 deletions doxygen/pages/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,7 @@ git pull

If you are using an Arduino board with on-board USB capabilities, you need the
[**MIDIUSB library**](https://github.com/arduino-libraries/MIDIUSB).
Install it as explained before, or by using the [Library Manager](
https://www.arduino.cc/en/Guide/Libraries#toc3).

The Control Surface Library depends on the [**PJRC Encoder library**](
https://www.pjrc.com/teensy/td_libs_Encoder.html) for reading the
input from rotary encoders. Download and install it if you plan on using those.

If you are using a Teensy, you don't need the MIDIUSB library, and the Encoder
library should already be installed by default.
Install it as explained before, or by using the
[Library Manager](https://www.arduino.cc/en/Guide/Libraries#toc3).

To use AppleMIDI, you also need the [AppleMIDI](https://github.com/lathoub/Arduino-AppleMIDI-Library) library and its dependencies.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
* https://github.com/tttapa/Control-Surface
*/

#include <Encoder.h> // Include the Encoder library.
// This must be done before the Control Surface library.
#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over USB interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include <Control_Surface.h>

#include <AH/Hardware/MCP23017Encoders.hpp>
#include <MIDI_Outputs/Abstract/MIDIRotaryEncoder.hpp>

#include <Wire.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
#include <Control_Surface.h>

#include <AH/Hardware/MCP23017Encoders.hpp>
#include <MIDI_Outputs/Abstract/MIDIRotaryEncoder.hpp>

#include <Wire.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
* https://github.com/tttapa/Control-Surface
*/

#include <Encoder.h> // Include the Encoder library.
// This must be done before the Control Surface library.
#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over USB interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
* https://github.com/tttapa/Control-Surface
*/

#include <Encoder.h>
// Encoder has to be included before Control_Surface
#include <Control_Surface.h>

USBMIDI_Interface usbmidi;
Expand Down
2 changes: 0 additions & 2 deletions examples/7.Displays/MCU-OLED-SSD1306/MCU-OLED-SSD1306.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
* https://github.com/tttapa/Control-Surface
*/

#include <Encoder.h> // Include the Encoder library.
// This must be done before the Control Surface library.
#include <Control_Surface.h> // Include the Control Surface library
// Include the display interface you'd like to use
#include <Display/DisplayInterfaces/DisplayInterfaceSSD1306.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* https://github.com/tttapa/Control-Surface/issues/66
*/

#include <Encoder.h>
// Encoder must be included before Control Surface
#include <Control_Surface.h>

// MIDI Interface to use
Expand Down
1 change: 0 additions & 1 deletion scripts/install-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ else
git clone https://github.com/adafruit/Adafruit-GFX-Library.git &
git clone https://github.com/adafruit/Adafruit_SSD1306.git &
git clone https://github.com/adafruit/Adafruit_BusIO.git &
git clone https://github.com/PaulStoffregen/Encoder.git &
git clone https://github.com/FastLED/FastLED.git &
git clone https://github.com/arduino-libraries/MIDIUSB.git &
git clone https://github.com/lathoub/Arduino-AppleMIDI-Library.git &
Expand Down
6 changes: 6 additions & 0 deletions src/AH/Hardware/MCP23017Encoders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ class MCP23017Encoders {
*position = pos;
}
}

#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
// begin_if_possible doesn't work on GCC 4.x and earlier, so provide a
// dummy begin method instead.
void begin() {}
#endif
};

/**
Expand Down
5 changes: 0 additions & 5 deletions src/Control_Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@
#include <MIDI_Outputs/ManyAddresses/PBPotentiometer.hpp>
#include <MIDI_Outputs/ManyAddresses/PCButton.hpp>

#ifdef Encoder_h_
#include <MIDI_Outputs/Bankable/CCAbsoluteEncoder.hpp>
#include <MIDI_Outputs/Bankable/CCRotaryEncoder.hpp>
#include <MIDI_Outputs/Bankable/PBAbsoluteEncoder.hpp>
#include <MIDI_Outputs/CCAbsoluteEncoder.hpp>
#include <MIDI_Outputs/CCRotaryEncoder.hpp>
#include <MIDI_Outputs/ManyAddresses/CCRotaryEncoder.hpp>
#include <MIDI_Outputs/PBAbsoluteEncoder.hpp>
#endif

// ------------------------------ MIDI Inputs ------------------------------- //
#include <MIDI_Inputs/MCU/AssignmentDisplay.hpp>
Expand Down Expand Up @@ -112,10 +110,7 @@
#include <Selectors/ManyButtonsSelector.hpp>
#include <Selectors/ProgramChangeSelector.hpp>
#include <Selectors/SwitchSelector.hpp>

#ifdef Encoder_h_
#include <Selectors/EncoderSelector.hpp>
#endif

#include <Selectors/LEDs/SelectorLEDs.hpp>

Expand Down
31 changes: 31 additions & 0 deletions src/Def/TypeTraits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <Settings/NamespaceSettings.hpp>

#include <AH/STL/type_traits>
#include <AH/STL/utility>

BEGIN_CS_NAMESPACE

template <class...>
using void_t = void;

template <class, class = void>
struct has_method_begin : std::false_type {};

template <class T>
struct has_method_begin<T, void_t<decltype(std::declval<T>().begin())>>
: std::true_type {};

/// Calls the `begin()` method of `t` if that method exists.
template <class T>
typename std::enable_if<has_method_begin<T>::value>::type
begin_if_possible(T &t) {
t.begin();
}

template <class T>
typename std::enable_if<!has_method_begin<T>::value>::type
begin_if_possible(T &) {}

END_CS_NAMESPACE
6 changes: 3 additions & 3 deletions src/Display/MCU/VPotDisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// TODO:

#include "VPotDisplay.hpp"
#ifdef TEST_COMPILE_ALL_HEADERS_SEPARATELY
#include "VPotDisplay.hpp"
#endif
12 changes: 9 additions & 3 deletions src/MIDI_Outputs/Abstract/MIDIAbsoluteEncoder.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#pragma once

#include <AH/STL/type_traits> // std::make_signed
#include <AH/STL/utility> // std::forward
#include <AH/STL/utility> // std::forward
#include <Def/Def.hpp>
#include <Encoder.h>
#include <Def/TypeTraits.hpp>
#include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>

#ifdef ARDUINO
#include <Submodules/Encoder/Encoder.h>
#else
#include <Encoder.h> // Mock
#endif

AH_DIAGNOSTIC_WERROR()

BEGIN_CS_NAMESPACE
Expand All @@ -24,7 +30,7 @@ class GenericMIDIAbsoluteEncoder : public MIDIOutputElement {
multiplier(multiplier), pulsesPerStep(pulsesPerStep), sender(sender) {
}

void begin() override {}
void begin() override { begin_if_possible(encoder); }

void update() override {
Enc_t encval = encoder.read();
Expand Down
1 change: 0 additions & 1 deletion src/MIDI_Outputs/Abstract/MIDIRotaryEncoder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#ifdef TEST_COMPILE_ALL_HEADERS_SEPARATELY
#include <Encoder.h>
#include "MIDIRotaryEncoder.hpp"
#endif
15 changes: 9 additions & 6 deletions src/MIDI_Outputs/Abstract/MIDIRotaryEncoder.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#pragma once

#include <AH/STL/type_traits> // std::make_signed
#include <AH/STL/utility> // std::forward
#include <AH/STL/utility> // std::forward
#include <Def/Def.hpp>
#include <Def/TypeTraits.hpp>
#include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>

#ifdef ARDUINO
#include <Submodules/Encoder/Encoder.h>
#else
#include <Encoder.h> // Mock
#endif

AH_DIAGNOSTIC_WERROR()

BEGIN_CS_NAMESPACE
Expand All @@ -27,7 +34,7 @@ class GenericMIDIRotaryEncoder : public MIDIOutputElement {
speedMultiply(speedMultiply), pulsesPerStep(pulsesPerStep),
sender(sender) {}

void begin() override {}
void begin() override { begin_if_possible(encoder); }

void update() override {
Enc_t encval = encoder.read();
Expand Down Expand Up @@ -56,16 +63,12 @@ class GenericMIDIRotaryEncoder : public MIDIOutputElement {
Sender sender;
};

#if defined(Encoder_h_) || not defined(ARDUINO)

template <class Sender>
using MIDIRotaryEncoder = GenericMIDIRotaryEncoder<Encoder, Sender>;

template <class Sender>
using BorrowedMIDIRotaryEncoder = GenericMIDIRotaryEncoder<Encoder &, Sender>;

#endif

END_CS_NAMESPACE

AH_DIAGNOSTIC_POP()
12 changes: 9 additions & 3 deletions src/MIDI_Outputs/Bankable/Abstract/MIDIAbsoluteEncoder.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#pragma once

#include <AH/STL/type_traits> // std::make_signed
#include <AH/STL/utility> // std::forward
#include <AH/STL/utility> // std::forward
#include <Banks/BankableAddresses.hpp>
#include <Def/Def.hpp>
#include <Encoder.h>
#include <Def/TypeTraits.hpp>
#include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>

#ifdef ARDUINO
#include <Submodules/Encoder/Encoder.h>
#else
#include <Encoder.h> // Mock
#endif

AH_DIAGNOSTIC_WERROR()

BEGIN_CS_NAMESPACE
Expand All @@ -27,7 +33,7 @@ class GenericMIDIAbsoluteEncoder : public MIDIOutputElement {
multiplier(multiplier), pulsesPerStep(pulsesPerStep), sender(sender) {
}

void begin() override {}
void begin() override { begin_if_possible(encoder); }

void update() override {
Enc_t encval = encoder.read();
Expand Down
1 change: 0 additions & 1 deletion src/MIDI_Outputs/Bankable/Abstract/MIDIRotaryEncoder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#ifdef TEST_COMPILE_ALL_HEADERS_SEPARATELY
#include <Encoder.h>
#include "MIDIRotaryEncoder.hpp"
#endif
9 changes: 8 additions & 1 deletion src/MIDI_Outputs/Bankable/Abstract/MIDIRotaryEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
#include <AH/STL/utility> // std::forward
#include <Banks/BankableAddresses.hpp>
#include <Def/Def.hpp>
#include <Def/TypeTraits.hpp>
#include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>

#ifdef ARDUINO
#include <Submodules/Encoder/Encoder.h>
#else
#include <Encoder.h> // Mock
#endif

AH_DIAGNOSTIC_WERROR()

BEGIN_CS_NAMESPACE
Expand All @@ -32,7 +39,7 @@ class GenericMIDIRotaryEncoder : public MIDIOutputElement {
sender(sender) {}

public:
void begin() override {}
void begin() override { begin_if_possible(encoder); }

void update() override {
Enc_t encval = encoder.read();
Expand Down
2 changes: 0 additions & 2 deletions src/MIDI_Outputs/Bankable/CCAbsoluteEncoder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#ifdef TEST_COMPILE_ALL_HEADERS_SEPARATELY
#include <Encoder.h>

#include "CCAbsoluteEncoder.hpp"
#endif
4 changes: 0 additions & 4 deletions src/MIDI_Outputs/Bankable/CCAbsoluteEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ namespace Bankable {
*
* This version can be banked.
*
* @note To use this class, include the [PJRC Encoder library]
* (https://github.com/PaulStoffregen/Encoder) before the
* Control-Surface library.
*
* @tparam NumBanks
* The number of banks.
*
Expand Down
1 change: 0 additions & 1 deletion src/MIDI_Outputs/Bankable/CCRotaryEncoder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#ifdef TEST_COMPILE_ALL_HEADERS_SEPARATELY
#include <Encoder.h>
#include "CCRotaryEncoder.hpp"
#endif
4 changes: 0 additions & 4 deletions src/MIDI_Outputs/Bankable/CCRotaryEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ namespace Bankable {
*
* This version can be banked.
*
* @note To use this class, include the [PJRC Encoder library]
* (https://github.com/PaulStoffregen/Encoder) before the
* Control-Surface library.
*
* @ingroup BankableMIDIOutputElements
*/
class CCRotaryEncoder
Expand Down
2 changes: 0 additions & 2 deletions src/MIDI_Outputs/Bankable/PBAbsoluteEncoder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#ifdef TEST_COMPILE_ALL_HEADERS_SEPARATELY
#include <Encoder.h>

#include "PBAbsoluteEncoder.hpp"
#endif
12 changes: 7 additions & 5 deletions src/MIDI_Outputs/Bankable/PBAbsoluteEncoder.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#pragma once

#include <AH/Settings/Warnings.hpp>

#include <Banks/BankAddresses.hpp>
#include <MIDI_Outputs/Bankable/Abstract/MIDIAbsoluteEncoder.hpp>
#include <MIDI_Senders/PitchBendSender.hpp>

AH_DIAGNOSTIC_WERROR()

BEGIN_CS_NAMESPACE

namespace Bankable {
Expand All @@ -15,10 +19,6 @@ namespace Bankable {
*
* This version can be banked.
*
* @note To use this class, include the [PJRC Encoder library]
* (https://github.com/PaulStoffregen/Encoder) before the
* Control-Surface library.
*
* @tparam NumBanks
* The number of banks.
*
Expand Down Expand Up @@ -69,4 +69,6 @@ class PBAbsoluteEncoder

} // namespace Bankable

END_CS_NAMESPACE
END_CS_NAMESPACE

AH_DIAGNOSTIC_POP()
4 changes: 0 additions & 4 deletions src/MIDI_Outputs/CCAbsoluteEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ BEGIN_CS_NAMESPACE
*
* This version cannot be banked.
*
* @note To use this class, include the [PJRC Encoder library]
* (https://github.com/PaulStoffregen/Encoder) before the
* Control-Surface library.
*
* @ingroup MIDIOutputElements
*/
class CCAbsoluteEncoder : public MIDIAbsoluteEncoder<ContinuousCCSender> {
Expand Down
Loading

0 comments on commit 40e3d7a

Please sign in to comment.