|
|
|
@ -37,36 +37,30 @@ Tmr Tmr1s = { .Period = 1000 };
|
|
|
|
|
/***************************************************************************//**
|
|
|
|
|
* @brief Button - port assignment
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
const uint8_t pinBtnChOn1 = 2;
|
|
|
|
|
const uint8_t pinBtnChOn2 = 3;
|
|
|
|
|
|
|
|
|
|
const uint8_t pinBtnInc1 = 8;
|
|
|
|
|
const uint8_t pinBtnDec1 = 9;
|
|
|
|
|
const uint8_t pinBtnInc2 = 10;
|
|
|
|
|
const uint8_t pinBtnDec2 = 11;
|
|
|
|
|
const uint8_t pinBtnChOn1 = 12;
|
|
|
|
|
const uint8_t pinBtnChOn2 = 13;
|
|
|
|
|
|
|
|
|
|
/***************************************************************************//**
|
|
|
|
|
* @brief Button codes
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
enum _BTN_CODES {
|
|
|
|
|
BTN_INC1 = 0,
|
|
|
|
|
BTN_DEC1,
|
|
|
|
|
BTN_INC2,
|
|
|
|
|
BTN_DEC2,
|
|
|
|
|
BTN_CH_ON1,
|
|
|
|
|
BTN_CH_ON2,
|
|
|
|
|
|
|
|
|
|
BTN_MAX
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***************************************************************************//**
|
|
|
|
|
* @brief LED
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
TimedPin LedBoard(LED_BUILTIN);
|
|
|
|
|
TimedPin LedChOn1(2);
|
|
|
|
|
TimedPin LedChOn2(3);
|
|
|
|
|
TimedPin LedChOn1(A0, true);
|
|
|
|
|
TimedPin LedChOn2(A1, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MidiCfgTxOnly; /// duplex or only tx configuration (without MIDI rx line)
|
|
|
|
|
|
|
|
|
|
MixerMuteState AirMutes[2] = {
|
|
|
|
|
//MixerMuteState(23, &LedBoard),
|
|
|
|
|
MixerMuteState(21, &LedChOn1, BTN_CH_ON1, EV_UI_RX_MUTE_CH1_ON, EV_UI_RX_MUTE_CH1_OFF),
|
|
|
|
|
MixerMuteState(22, &LedChOn2, BTN_CH_ON2, EV_UI_RX_MUTE_CH2_ON, EV_UI_RX_MUTE_CH2_OFF)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***************************************************************************//**
|
|
|
|
|
* @brief MIDI instance (serial port)
|
|
|
|
@ -74,19 +68,21 @@ TimedPin LedChOn2(3);
|
|
|
|
|
MIDI_CREATE_DEFAULT_INSTANCE();
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// This function will be automatically called when a NoteOn is received.
|
|
|
|
|
// It must be a void-returning function with the correct parameters, see documentation here:
|
|
|
|
|
// https://github.com/FortySevenEffects/arduino_midi_library/wiki/Using-Callbacks
|
|
|
|
|
void handleNoteOn(byte channel, byte pitch, byte velocity) {
|
|
|
|
|
// Do whatever you want when a note is pressed.
|
|
|
|
|
|
|
|
|
|
// Try to keep your callbacks short (no delays ect) otherwise it would slow down the loop() and have a bad impact on real-time performance.
|
|
|
|
|
void MidiCCHandler(byte channel, byte ctrl_no, byte val) {
|
|
|
|
|
if (channel == 2) { // Mutes: ch=2
|
|
|
|
|
for (uint_fast8_t i=0; i<ELEMCNT(AirMutes); i++) {
|
|
|
|
|
MixerMuteState& mute = AirMutes[i];
|
|
|
|
|
if (ctrl_no == mute.MidiCtrlNr) {
|
|
|
|
|
mute.MuteMixer = (val >= 64);
|
|
|
|
|
mute.MuteLocal = mute.MuteMixer;
|
|
|
|
|
mute.Led->Set(!mute.MuteMixer);
|
|
|
|
|
UI_EventProc(mute.MuteMixer ? mute.UiEventOff : mute.UiEventOn);
|
|
|
|
|
LedBoard.OnTimed(200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleNoteOff(byte channel, byte pitch, byte velocity) {
|
|
|
|
|
// Do something when the note is released. Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
@ -102,10 +98,9 @@ void setup() {
|
|
|
|
|
LedChOn1.begin();
|
|
|
|
|
LedChOn2.begin();
|
|
|
|
|
|
|
|
|
|
// Connect the handleNoteOn function to the library, so it is called upon reception of a NoteOn.
|
|
|
|
|
MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function
|
|
|
|
|
MIDI.setHandleNoteOff(handleNoteOff); // Do the same for NoteOffs
|
|
|
|
|
MIDI.setHandleControlChange(MidiCCHandler);
|
|
|
|
|
MIDI.begin(MIDI_CHANNEL_OMNI); // Initiate MIDI communications, listen to all channels
|
|
|
|
|
MIDI.turnThruOff();
|
|
|
|
|
|
|
|
|
|
UI_Init(); // Start user interface (main state machine)
|
|
|
|
|
}
|
|
|
|
@ -119,29 +114,31 @@ void loop() {
|
|
|
|
|
uint32_t t = millis();
|
|
|
|
|
// execute every 10ms *******************************************************
|
|
|
|
|
if (Tmr10ms.Check(t)) {
|
|
|
|
|
static uint8_t BtnPrev = 0xFF;
|
|
|
|
|
static uint8_t BtnPrev = 0x00;
|
|
|
|
|
static uint8_t BtnNew = 0;
|
|
|
|
|
static uint8_t BtnRel = 0;
|
|
|
|
|
uint8_t btn = (digitalRead(pinBtnInc1) ? (1 << BTN_INC1 ) : 0)
|
|
|
|
|
| (digitalRead(pinBtnDec1) ? (1 << BTN_DEC1 ) : 0)
|
|
|
|
|
| (digitalRead(pinBtnInc2) ? (1 << BTN_INC2 ) : 0)
|
|
|
|
|
| (digitalRead(pinBtnInc2) ? (1 << BTN_DEC2 ) : 0)
|
|
|
|
|
| (digitalRead(pinBtnChOn1) ? (1 << BTN_CH_ON1) : 0)
|
|
|
|
|
| (digitalRead(pinBtnChOn1) ? (1 << BTN_CH_ON2) : 0);
|
|
|
|
|
BtnNew |= (~btn) & BtnPrev;
|
|
|
|
|
BtnRel |= btn & (~BtnPrev);
|
|
|
|
|
uint8_t btn = (digitalRead(pinBtnInc1) ? 0: (1 << BTN_INC1 ))
|
|
|
|
|
| (digitalRead(pinBtnDec1) ? 0: (1 << BTN_DEC1 ))
|
|
|
|
|
| (digitalRead(pinBtnInc2) ? 0: (1 << BTN_INC2 ))
|
|
|
|
|
| (digitalRead(pinBtnDec2) ? 0: (1 << BTN_DEC2 ))
|
|
|
|
|
| (digitalRead(pinBtnChOn1) ? 0: (1 << BTN_CH_ON1))
|
|
|
|
|
| (digitalRead(pinBtnChOn2) ? 0: (1 << BTN_CH_ON2));
|
|
|
|
|
BtnNew |= btn & (~BtnPrev);
|
|
|
|
|
BtnRel |= (~btn) & BtnPrev;
|
|
|
|
|
BtnPrev = btn;
|
|
|
|
|
uint8_t mask = 1;
|
|
|
|
|
if (BtnNew) {
|
|
|
|
|
for (uint_fast8_t i = 0; i < BTN_MAX; i++) {
|
|
|
|
|
for (uint_fast8_t i = 0; i < 8; i++) {
|
|
|
|
|
if (BtnNew & mask) {
|
|
|
|
|
BtnNew &= ~mask; // Bit clr
|
|
|
|
|
UI_EventProc(EV_UI_KEY_PRESS + i);
|
|
|
|
|
LedBoard.OnTimed(50);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
mask <<= 1;
|
|
|
|
|
}
|
|
|
|
|
}else if (BtnRel) { // released button
|
|
|
|
|
for (uint_fast8_t i = 0; i < BTN_MAX; i++) {
|
|
|
|
|
for (uint_fast8_t i = 0; i < 8; i++) {
|
|
|
|
|
if (BtnRel & mask) {
|
|
|
|
|
BtnRel &= ~mask; // Bit clr
|
|
|
|
|
UI_EventProc(EV_UI_KEY_REL + i);
|
|
|
|
|