uilleann/pipe.h

79 lines
2.0 KiB
C
Raw Normal View History

2020-11-11 20:20:21 -07:00
#pragma once
#include <Adafruit_MPR121.h>
2020-11-26 18:49:09 -07:00
#include <Adafruit_VL6180X.h>
#include <SparkFun_Qwiic_Button.h>
#include <stdint.h>
2020-11-24 16:56:58 -07:00
#include "tuning.h"
2020-11-11 20:20:21 -07:00
2020-11-26 18:49:09 -07:00
#define NUM_KEYS 12
2020-11-25 17:13:54 -07:00
enum Adjust {
ADJUST_DOWN = -1,
ADJUST_NONE = 0,
ADJUST_UP = 1,
ADJUST_BOTH,
};
2020-11-11 20:20:21 -07:00
class Pipe {
public:
// kneeClosedness indicates how "closed" the knee sensor is. 0 = wide open.
2020-11-26 18:49:09 -07:00
uint8_t KneeClosedness;
2020-11-11 20:20:21 -07:00
// keys are which keys are being pressed.
2020-11-26 18:49:09 -07:00
uint16_t Keys;
uint16_t KeysLast;
float KeyPressure[NUM_KEYS];
2020-11-11 20:20:21 -07:00
// note holds the note being played, according to the fingering chart.
2020-11-26 18:49:09 -07:00
Note CurrentNote;
2020-11-24 16:56:58 -07:00
// glissandoNote is the note that would be played if partially open keys were fully open.
2020-11-26 18:49:09 -07:00
Note GlissandoNote;
2020-11-24 16:56:58 -07:00
2020-11-26 18:49:09 -07:00
// glissandoPressure is how "closed" the holes are in the direction away from the glissandoNote.
float GlissandoPressure;
2020-11-11 20:20:21 -07:00
// silent is true if all keys and the knee are closed.
2020-11-26 18:49:09 -07:00
bool Silent;
2020-11-11 20:20:21 -07:00
// bag is true if the bag is being squished.
2020-11-26 18:49:09 -07:00
bool Bag;
2020-11-11 20:20:21 -07:00
// altFingering is true if the "alternate fingering" is being played.
// This should sound different than the standard fingering.
2020-11-26 18:49:09 -07:00
bool AltFingering;
2020-11-11 20:20:21 -07:00
Pipe();
2020-11-11 20:20:21 -07:00
// Init initializes everything.
//
// Returns true if it all worked. You can run it again if it didn't.
bool Init();
2020-11-11 20:20:21 -07:00
// Update reads sensors and updates pipe state.
//
// It should be run once per loop.
void Update();
2020-11-11 20:20:21 -07:00
// Pressed returns whether the given key is pressed.
bool Pressed(uint8_t key);
2020-11-24 16:56:58 -07:00
// JustPressed returns whether the given key was just pressed.
bool JustPressed(uint8_t key);
2020-11-24 16:56:58 -07:00
2020-11-25 17:13:54 -07:00
// ReadAdjust returns the input for two keys paired as up/down.
//
// delay is the number of milliseconds to wait before repeating a key
// repeat is the number of milliseconds to wait between repeated keystrokes
Adjust ReadAdjust(uint8_t upKey, uint8_t downKey, uint16_t delay, uint16_t repeat);
private:
Adafruit_MPR121 capSensor;
2020-11-26 18:49:09 -07:00
Adafruit_VL6180X kneeSensor;
QwiicButton bagSensor;
bool bag_enabled;
2020-11-25 17:13:54 -07:00
unsigned long nextRepeat[NUM_KEYS];
bool typematicEvent(uint8_t key, uint16_t delay, uint16_t repeat);
2020-11-11 20:20:21 -07:00
};