-
Notifications
You must be signed in to change notification settings - Fork 14
/
Button.h
43 lines (37 loc) · 2.3 KB
/
Button.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// MIDI Elements Button class
// Library to simplify handling of components for MIDI controllers
// Created by Tomash Ghz
// www.tomashg.com
// ghz.tomash@gmail.com
#ifndef Button_H
#define Button_H
//-----------------------------------------------------------------------------------
#include "WProgram.h" //It is very important to remember this! note that if you are using Arduino 1.0 IDE, change "WProgram.h" to "Arduino.h"
#include <MIDIBounce.h>
/*! \brief Class for handling push button switches.
Connect the button to ground and input pin, there is no need for a pull-up resistor, it is enabled internally.
Enable Secondary to send secondary CC messages. (used for mapping momentary switches in Ableton)
Enable debug to print to serial port instead of midi.
*/
class Button {
private:
MIDIBounce *bButn; // bounce class button
bool debugging; // is debugging on
bool secondary; // send secondary midi signal
byte pin; // pin on teensy
byte channel; // midi channel
byte number; // midi number
byte velocity; // midi velocity
void noteOnOff(bool v); // send note on off
public:
Button(byte p); //!< constructor with pin number. @param p pin number
Button(byte p, byte c, byte n); //!< constructor with pin number, midi channel and midi note. @param p pin number @param c midi channel @param n midi note
Button(byte p, byte c, byte n, bool sec); //!< constructor with pin number, midi channel, midi note and secondary messages. @param p pin number @param c midi channel @param n midi note @param sec enable secondary messages
Button(byte p, byte c, byte n, bool sec, bool debug); //!< constructor with pin number, midi channel, midi note, secondary messages and debugging. @param p pin number @param c midi channel @param n midi note @param sec enable secondary message @param debug enable debugging
~Button(); // destructor
void read(); //!< read the values and send a midi message if the button state changed. use in main loop
bool readValue(bool &changed); //!< read the values and return if the button is pressed, pass state change @param changed will beset to true if the state of the button changed
void setVelocity(byte v); //!< change the note on velocity value of the outgoing midi message. @param v set velocity value
};
//-----------------------------------------------------------------------------------
#endif