You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MiniDexed/src/uibuttons.h

190 lines
4.7 KiB

//
// uibuttons.h
//
// MiniDexed - Dexed FM synthesizer for bare metal Raspberry Pi
// Copyright (C) 2022 The MiniDexed Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _uibuttons_h
#define _uibuttons_h
#include <circle/gpiopin.h>
#include <circle/types.h>
#include "midipin.h"
#include "config.h"
#define BUTTONS_UPDATE_NUM_TICKS 100
Squashed commit of the following: commit a2a4f183786296682105517abd6eaefd61db1e4f Author: Javier Nonis <javiernonis@gmail.com> Date: Thu Aug 8 20:32:38 2024 -0300 Fix for Midi Clock Sync commit 20eeb54ba2f7d8b9a2dffc05c8243d1c6a2a93c5 Author: Javier Nonis <javiernonis@gmail.com> Date: Sat Aug 3 23:06:17 2024 -0300 Added Flanger commit 7f21a03dacb4fdead39efdc1773c60438a1140ae Author: Javier Nonis <javiernonis@gmail.com> Date: Sat Aug 3 15:16:42 2024 -0300 UI improvements commit 8538869d11c8d55d2de3c1467badb044f18dc3d1 Author: Javier Nonis <javiernonis@gmail.com> Date: Sat Aug 3 00:24:45 2024 -0300 Fix for FX UI commit 035b3104f7e9c27722b9232f35f35573988fba48 Author: Javier Nonis <javiernonis@gmail.com> Date: Fri Aug 2 20:39:44 2024 -0300 Fix for RPi 1 Stereo output commit bd31b249d24aebed6066a71e3f45d99b1a000d02 Author: Javier Nonis <javiernonis@gmail.com> Date: Tue Jul 30 22:42:36 2024 -0300 Fix for MVerb port commit f7d3baf901bd69994a5b9290097f95439d3f583d Author: Javier Nonis <javiernonis@gmail.com> Date: Tue Jul 30 18:27:39 2024 -0300 Fix for Reverb backward compatibility commit d695762f1e49411869c491d3aca6a59259d53e81 Author: Javier Nonis <javiernonis@gmail.com> Date: Sun Jul 28 18:46:59 2024 -0300 Fix for A Phaser parameters commit 38f9f5f05c38916ed95217ee3688572acddab99c Author: Javier Nonis <javiernonis@gmail.com> Date: Sat Jul 27 16:16:49 2024 -0300 AudioEffect refactor commit 17f6fc9ccf61c1776f977353cddf0236a2e39b7f Author: Javier Nonis <javiernonis@gmail.com> Date: Fri Jul 26 20:47:27 2024 -0300 Fix missing Send FX setup for Phasers commit aae85e5f85662be1a6250b73db62906eb6657dba Author: Javier Nonis <javiernonis@gmail.com> Date: Wed Jul 24 18:11:43 2024 -0300 Added RKR / Zynaddsubfx Phasers commit f0e2593e8155e5ac61eeb760766ea5f7bde83c5d Author: Javier Nonis <javiernonis@gmail.com> Date: Tue Jul 23 13:12:29 2024 -0300 Fix for MVerb commit 2d19311269571c99bcd42cc91a6bbf9e81d48374 Author: Javier Nonis <javiernonis@gmail.com> Date: Mon Jul 22 19:59:15 2024 -0300 Refactor Effect directory commit 37c152d2c8ab995c45d733ba964c24e376e91e6f Merge: 9c55aa6 d6fbbb5 Author: jnonis <jnonis@users.noreply.github.com> Date: Mon Jul 22 18:59:55 2024 -0300 Merge pull request #1 from jnonis/arp Merge Arp branch to FX branch commit d6fbbb508dca345df91fd1cdb465150c58747952 Author: Javier Nonis <javiernonis@gmail.com> Date: Mon Jul 22 18:18:08 2024 -0300 Added 3 Band EQ commit 6d673aa8be20b2c4ee20ed575101784dda15b131 Author: Javier Nonis <javiernonis@gmail.com> Date: Mon Jul 22 16:46:33 2024 -0300 Added MVerb effect commit bf30d1a1c95ccef846f8c4bd14b8de66fdd6f17b Author: Javier Nonis <javiernonis@gmail.com> Date: Sat Jul 20 20:15:13 2024 -0300 UI fix for Tempo display commit d7336ee180f195b59df2edadb898e4240917d13d Author: Javier Nonis <javiernonis@gmail.com> Date: Sat Jul 20 20:14:08 2024 -0300 Save Tempo into Performance commit 652db3e05f1e00b30d8b9c80dd403b62c4d2efca Author: Javier Nonis <javiernonis@gmail.com> Date: Sat Jul 20 17:49:53 2024 -0300 Store Midi FX settings into performance commit 6cd3a82253254521260410bb53538784903f44ff Author: Javier Nonis <javiernonis@gmail.com> Date: Sat Jul 20 16:21:47 2024 -0300 Handle Arp as a Midi FX commit 8f597543fc97275624265cd3042cfe887c4fb20e Author: jnonis <jnonis@users.noreply.github.com> Date: Fri Jul 19 16:41:09 2024 +0000 Arp fixes commit 61f66848dcd6b28734aca597eeac5dd72a9d4a71 Author: jnonis <jnonis@users.noreply.github.com> Date: Fri Jul 19 04:56:58 2024 +0000 Added Arp to TG menu commit b2dcc29d73b897b81a40988e0b346af0261743f9 Author: jnonis <jnonis@users.noreply.github.com> Date: Thu Jul 18 04:34:13 2024 +0000 Removed log from Arp commit d4f99f88ae6b7f17df7152252397ba366c970fb2 Author: jnonis <jnonis@users.noreply.github.com> Date: Thu Jul 18 04:31:42 2024 +0000 Almost working Arp commit 0cb0553f25f5815e57da98d9cafde804da352c5b Author: jnonis <jnonis@users.noreply.github.com> Date: Thu Jul 18 04:15:19 2024 +0000 Not working Arp commit 9c55aa6a46210f3773f71972eb836478edb70754 Author: jnonis <jnonis@users.noreply.github.com> Date: Sun Jul 14 22:19:46 2024 +0000 Delay FX: Support for tempo sync commit bed555fcfbf57e5ab54ab01bd63c1a19f0770b90 Author: jnonis <jnonis@users.noreply.github.com> Date: Sun Jul 14 16:11:36 2024 +0000 Fix for FX Params commit 0a68eb577f29e8e2f909e7da33fda5b9b870fce5 Author: jnonis <jnonis@users.noreply.github.com> Date: Wed Jul 10 04:24:55 2024 +0000 Handle Midi clock and resolve BPM commit cd785aa046d4a3c267a00ec288b5b518685fcba9 Author: jnonis <jnonis@users.noreply.github.com> Date: Tue Jul 9 23:01:24 2024 +0000 Added Backward compatibility for performances commit fc6f7152f05c0e16503ed49c1a039282cf2ce686 Author: jnonis <jnonis@users.noreply.github.com> Date: Tue Jul 9 04:47:42 2024 +0000 Adapted Plate Reverb as AudioEffect commit 751b69da3f7f4018004eb216882eec9c74d8dfd3 Author: jnonis <jnonis@users.noreply.github.com> Date: Mon Jul 8 22:35:56 2024 +0000 Save Send FX configuration in performance commit 7c2638cd7f8bca920de3643921de65695d978d44 Author: jnonis <jnonis@users.noreply.github.com> Date: Sun Jul 7 04:56:43 2024 +0000 WIP: Added Send FX commit 17105a9c42d01119961e021371e108a8477fd255 Author: jnonis <jnonis@users.noreply.github.com> Date: Sat Jul 6 22:00:33 2024 +0000 Code clean up commit 509155573cb0c4887ebfd2f8f6d4d8b00ae0f602 Author: jnonis <jnonis@users.noreply.github.com> Date: Sat Jul 6 21:37:29 2024 +0000 Fixes for Tal Reverb 3 paramteres commit 002c2b985ced72af1a35e98b1479527540581f3a Author: jnonis <jnonis@users.noreply.github.com> Date: Sat Jul 6 21:07:16 2024 +0000 Added Ping Pong Mode and Mix control to Delay FX commit 897c35aad0380b346a392b98e5738fb8eff95642 Author: jnonis <jnonis@users.noreply.github.com> Date: Fri Jul 5 06:00:33 2024 +0000 Insert FX UI improvements commit 881149e11901a52ea44c9aa4eafb7f5adf1670b6 Author: jnonis <jnonis@users.noreply.github.com> Date: Wed Jul 3 04:36:32 2024 +0000 Process TG in stereo commit e034e66f8736679d4c6b8bfeafb6bcce5f67ea87 Author: jnonis <jnonis@users.noreply.github.com> Date: Fri Jun 28 00:24:57 2024 +0000 Added Tal Reverb 3 commit 116881b3a59c9ac6d9ddca2f8a9b040024e3c7a9 Author: jnonis <jnonis@users.noreply.github.com> Date: Thu Jun 27 04:02:08 2024 +0000 Fix for distortions commit 6f05c233a6d61e161d4a942c9134aadadf2c8def Author: jnonis <jnonis@users.noreply.github.com> Date: Thu Jun 27 03:48:02 2024 +0000 Added Mod Distortions DS1 and BigMuff commit 2d854393a49b3d1d552ba2341443a48f66141a76 Author: jnonis <jnonis@users.noreply.github.com> Date: Wed Jun 26 22:52:30 2024 +0000 Fix for Bypass and Removed Logs commit 172c651aa5b6f006ddcdb72d845685910de2d2c1 Author: jnonis <jnonis@users.noreply.github.com> Date: Wed Jun 26 04:40:15 2024 +0000 Added Bypass to FX Parameters commit 8ca21774fba2777896711dba18de6004d7ec3d3a Author: jnonis <jnonis@users.noreply.github.com> Date: Wed Jun 26 04:12:58 2024 +0000 Fix for Insert FX paramters ui commit 7c8dc6f147ab76bb739a2ddf72a82d8b4447731f Author: jnonis <jnonis@users.noreply.github.com> Date: Wed Jun 26 03:45:03 2024 +0000 Save Insert FX parameters into performance commit 7f110b284d74614e3d39a5224072fa6a8b63c4ac Author: jnonis <jnonis@users.noreply.github.com> Date: Mon Jun 24 02:40:47 2024 +0000 Added generic fx paramters handling commit 9b1ea33966c7e7efad51eb4e5eaf54a97451c31a Author: jnonis <jnonis@users.noreply.github.com> Date: Sun Jun 23 18:53:29 2024 +0000 Added LP Filter Effect commit 75f4333831164a199aa25fe87f02684ec962cf3b Author: jnonis <jnonis@users.noreply.github.com> Date: Sun Jun 23 08:11:36 2024 +0000 Added delay implementation commit 7bcba9183ad6b418320f5bcea2159d1c1e3b8ec3 Author: jnonis <jnonis@users.noreply.github.com> Date: Sun Jun 23 02:06:54 2024 +0000 Added lock to inser FXs to avoid crashes. Code clean up. commit d98c7cf7019532a139ef6bba7b22aa546adaed6f Author: jnonis <jnonis@users.noreply.github.com> Date: Sat Jun 22 04:43:23 2024 +0000 Added Insert FX and Juno Chorus
3 months ago
#define DEBOUNCE_TIME 300
#define MAX_GPIO_BUTTONS 11 // 5 UI buttons, 6 Program/Bank/TG Select buttons
#define MAX_MIDI_BUTTONS 11
#define MAX_BUTTONS (MAX_GPIO_BUTTONS+MAX_MIDI_BUTTONS)
class CUIButtons;
class CUIButton
{
public:
enum BtnTrigger
{
BtnTriggerNone = 0,
BtnTriggerClick = 1,
BtnTriggerDoubleClick = 2,
BtnTriggerLongPress = 3
};
enum BtnEvent
{
BtnEventNone = 0,
BtnEventPrev = 1,
BtnEventNext = 2,
BtnEventBack = 3,
BtnEventSelect = 4,
BtnEventHome = 5,
BtnEventPgmUp = 6,
BtnEventPgmDown = 7,
BtnEventBankUp = 8,
BtnEventBankDown = 9,
BtnEventTGUp = 10,
BtnEventTGDown = 11,
BtnEventUnknown = 12
};
CUIButton (void);
~CUIButton (void);
void reset (void);
boolean Initialize (unsigned pinNumber, unsigned doubleClickTimeout, unsigned longPressTimeout);
void setClickEvent(BtnEvent clickEvent);
void setDoubleClickEvent(BtnEvent doubleClickEvent);
void setLongPressEvent(BtnEvent longPressEvent);
unsigned getPinNumber(void);
BtnTrigger ReadTrigger (void);
BtnEvent Read (void);
void Write (unsigned nValue); // MIDI buttons only!
static BtnTrigger triggerTypeFromString(const char* triggerString);
private:
// Pin number
unsigned m_pinNumber;
// GPIO pin
CGPIOPin *m_pin;
// MIDI pin
CMIDIPin *m_midipin;
// The value of the pin at the end of the last loop
unsigned m_lastValue;
// Set to 0 on press, increment each read, use to trigger events
uint16_t m_timer;
// Debounce timer
uint16_t m_debounceTimer;
// Number of clicks recorded since last timer reset
uint8_t m_numClicks;
// Event to fire on click
BtnEvent m_clickEvent;
// Event to fire on double click
BtnEvent m_doubleClickEvent;
// Event to fire on long press
BtnEvent m_longPressEvent;
// Timeout for double click in tenths of a millisecond
unsigned m_doubleClickTimeout;
// Timeout for long press in tenths of a millisecond
unsigned m_longPressTimeout;
};
class CUIButtons
{
public:
typedef void BtnEventHandler (CUIButton::BtnEvent Event, void *param);
public:
CUIButtons (CConfig *pConfig);
~CUIButtons (void);
boolean Initialize (void);
void RegisterEventHandler (BtnEventHandler *handler, void *param = 0);
void Update (void);
void ResetButton (unsigned pinNumber);
void BtnMIDICmdHandler (unsigned nMidiCmd, unsigned nMidiData1, unsigned nMidiData2);
private:
CConfig *m_pConfig;
// Array of normal GPIO buttons and "MIDI buttons"
CUIButton m_buttons[MAX_BUTTONS];
// Timeout for double click in tenths of a millisecond
unsigned m_doubleClickTimeout;
// Timeout for long press in tenths of a millisecond
unsigned m_longPressTimeout;
// Configuration for buttons
unsigned m_prevPin;
CUIButton::BtnTrigger m_prevAction;
unsigned m_nextPin;
CUIButton::BtnTrigger m_nextAction;
unsigned m_backPin;
CUIButton::BtnTrigger m_backAction;
unsigned m_selectPin;
CUIButton::BtnTrigger m_selectAction;
unsigned m_homePin;
CUIButton::BtnTrigger m_homeAction;
// Program and TG Selection buttons
unsigned m_pgmUpPin;
CUIButton::BtnTrigger m_pgmUpAction;
unsigned m_pgmDownPin;
CUIButton::BtnTrigger m_pgmDownAction;
unsigned m_BankUpPin;
CUIButton::BtnTrigger m_BankUpAction;
unsigned m_BankDownPin;
CUIButton::BtnTrigger m_BankDownAction;
unsigned m_TGUpPin;
CUIButton::BtnTrigger m_TGUpAction;
unsigned m_TGDownPin;
CUIButton::BtnTrigger m_TGDownAction;
// MIDI button configuration
unsigned m_notesMidi;
unsigned m_prevMidi;
unsigned m_nextMidi;
unsigned m_backMidi;
unsigned m_selectMidi;
unsigned m_homeMidi;
unsigned m_pgmUpMidi;
unsigned m_pgmDownMidi;
unsigned m_BankUpMidi;
unsigned m_BankDownMidi;
unsigned m_TGUpMidi;
unsigned m_TGDownMidi;
BtnEventHandler *m_eventHandler;
void *m_eventParam;
unsigned m_lastTick;
void bindButton(unsigned pinNumber, CUIButton::BtnTrigger trigger, CUIButton::BtnEvent event);
};
#endif