77 lines
2.0 KiB

#pragma once
#include <Adafruit_MPR121.h>
#include <Adafruit_VL6180X.h>
#include <SparkFun_Qwiic_Button.h>
#include <stdint.h>
#include "tuning.h"
#define NUM_KEYS 12
// A mapping of MPR121 input to pipe key
const int KeySensor[NUM_KEYS] = { 11, -1, 0, 1, 2, 3, 4, 5, 6, 7, -1, -1 };
enum Adjust {
class Pipe {
// keys are which keys are being pressed.
uint16_t Keys;
uint16_t KeysLast;
float KeyPressure[NUM_KEYS];
// note holds the note being played, according to the fingering chart.
Note CurrentNote;
// glissandoNote is the note that would be played if partially open keys were fully open.
Note GlissandoNote;
// glissandoPressure is how "closed" the holes are in the direction away from the glissandoNote.
float GlissandoPressure;
// silent is true if all keys and the knee are closed.
bool Silent;
// bag is true if the bag is being squished.
bool Bag;
// altFingering is true if the "alternate fingering" is being played.
// This should sound different than the standard fingering.
bool AltFingering;
// Init initializes everything.
// Returns true if it all worked. You can run it again if it didn't.
bool Init();
// Update reads sensors and updates pipe state.
// It should be run once per loop.
void Update();
// Pressed returns whether the given key is pressed.
bool Pressed(uint8_t key);
// JustPressed returns whether the given key was just pressed.
bool JustPressed(uint8_t key);
// 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);
Adafruit_MPR121 capSensor;
bool bag_enabled;
unsigned long nextRepeat[NUM_KEYS];
bool typematicEvent(uint8_t key, uint16_t delay, uint16_t repeat);