From 890fadc8f66ff91f3e74791a845e6607e112cf2c Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 22 May 2024 19:08:38 +0200 Subject: [PATCH] removal of magic numbers --- include/constants.h | 52 ++++++++++++++++++++ src/pots.cpp | 114 ++++++++++++++++++++++---------------------- 2 files changed, 109 insertions(+), 57 deletions(-) diff --git a/include/constants.h b/include/constants.h index 56c4a43..90bebd7 100644 --- a/include/constants.h +++ b/include/constants.h @@ -5,6 +5,58 @@ #ifndef MEGAFM_CONSTANTS_H #define MEGAFM_CONSTANTS_H +#define KNOB_ARP_RATE 6 +#define KNOB_ARP_RANGE 5 +#define KNOB_LFO1_RATE 15 +#define KNOB_LFO2_RATE 10 +#define KNOB_LFO3_RATE 14 +#define KNOB_LFO1_DEPTH 12 +#define KNOB_LFO2_DEPTH 9 +#define KNOB_LFO3_DEPTH 2 +#define KNOB_VIB_RATE 48 +#define KNOB_VIB_DEPTH 13 +#define KNOB_FAT 28 +#define KNOB_VOLUME 1 +#define KNOB_FEEDBACK 3 +#define KNOB_ALGO 4 + +#define FADER_DETUNE_1 18 +#define FADER_MULT_1 27 +#define FADER_LEVEL_1 19 +#define FADER_ATTACK_1 29 +#define FADER_DECAY_1 21 +#define FADER_SUSTAIN_1 25 +#define FADER_SUSTAIN_RATE_1 17 +#define FADER_RELEASE_1 30 + +#define FADER_DETUNE_2 31 +#define FADER_MULT_2 32 +#define FADER_LEVEL_2 40 +#define FADER_ATTACK_2 36 +#define FADER_DECAY_2 44 +#define FADER_SUSTAIN_2 42 +#define FADER_SUSTAIN_RATE_2 34 +#define FADER_RELEASE_2 11 + +#define FADER_DETUNE_3 20 +#define FADER_MULT_3 24 +#define FADER_LEVEL_3 16 +#define FADER_ATTACK_3 8 +#define FADER_DECAY_3 0 +#define FADER_SUSTAIN_3 7 +#define FADER_SUSTAIN_RATE_3 45 +#define FADER_RELEASE_3 37 + +#define FADER_DETUNE_4 47 +#define FADER_MULT_4 39 +#define FADER_LEVEL_4 38 +#define FADER_ATTACK_4 46 +#define FADER_DECAY_4 33 +#define FADER_SUSTAIN_4 41 +#define FADER_SUSTAIN_RATE_4 43 +#define FADER_RELEASE_4 35 + + const byte kVersion0 = 4; const byte kVersion1 = 0; diff --git a/src/pots.cpp b/src/pots.cpp index fcb94b8..e4df184 100644 --- a/src/pots.cpp +++ b/src/pots.cpp @@ -23,7 +23,7 @@ void movedPot(byte number, byte data, bool isMidi) { switch (number) { - case 6: + case KNOB_ARP_RATE: setupChanged = true; if (data > 127) { arpClockEnable = 1; @@ -35,7 +35,7 @@ void movedPot(byte number, byte data, bool isMidi) { digit(1, 12); } break; // arp rate - case 15: + case KNOB_LFO1_RATE: setupChanged = true; if (data > 127) { lfoClockEnable[0] = 1; @@ -47,7 +47,7 @@ void movedPot(byte number, byte data, bool isMidi) { digit(1, 12); } break; // lfo 1 rate - case 10: + case KNOB_LFO2_RATE: setupChanged = true; if (data > 127) { lfoClockEnable[1] = 1; @@ -59,7 +59,7 @@ void movedPot(byte number, byte data, bool isMidi) { digit(1, 12); } break; // lfo 2 rate - case 14: + case KNOB_LFO3_RATE: setupChanged = true; if (data > 127) { lfoClockEnable[2] = 1; @@ -71,7 +71,7 @@ void movedPot(byte number, byte data, bool isMidi) { digit(1, 12); } break; // lfo 3 rate - case 48: + case KNOB_VIB_RATE: setupChanged = true; if (data > 127) { vibratoClockEnable = 1; @@ -85,7 +85,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // vib rate - case 12: + case KNOB_LFO1_DEPTH: setupChanged = true; if (data > 127) { lfoVel = 1; @@ -111,7 +111,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // lfo 1 depth - case 9: + case KNOB_LFO2_DEPTH: setupChanged = true; if (data > 127) { lfoMod = 1; @@ -137,7 +137,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // lfo 2 depth - case 2: + case KNOB_LFO3_DEPTH: setupChanged = true; if (data > 127) { lfoAt = 1; @@ -163,7 +163,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // lfo 3 depth - case 28: + case KNOB_FAT: setupChanged = true; if (data < 128) { fatMode = FAT_MODE_SEMITONE; @@ -176,7 +176,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // fat - case 1: + case KNOB_VOLUME: setupChanged = true; if (data > 127) { ignoreVolume = 0; @@ -189,7 +189,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // volume preset - case 13: + case KNOB_VIB_DEPTH: byte brightness = data >> 4; if (brightness > 15) brightness = 10; // default; @@ -210,7 +210,7 @@ void movedPot(byte number, byte data, bool isMidi) { switch (number) { // OP1 - case 18: + case FADER_DETUNE_1: showPickupAnimation = false; if (loopHeld) { loopChanged = true; @@ -233,7 +233,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // detune - case 27: + case FADER_MULT_1: showPickupAnimation = false; fmBase[1] = data; updateFMifNecessary(1); @@ -244,7 +244,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // multiple - case 19: + case FADER_LEVEL_1: showPickupAnimation = false; fmBase[2] = data; updateFMifNecessary(2); @@ -255,7 +255,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // op level - case 29: + case FADER_ATTACK_1: showPickupAnimation = false; fmBase[4] = data; updateFMifNecessary(4); @@ -266,7 +266,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // attack - case 21: + case FADER_DECAY_1: showPickupAnimation = false; fmBase[5] = data; updateFMifNecessary(5); @@ -277,7 +277,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // decay1 - case 25: + case FADER_SUSTAIN_1: showPickupAnimation = false; fmBase[7] = data; updateFMifNecessary(7); @@ -288,7 +288,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // sustain - case 17: + case FADER_SUSTAIN_RATE_1: showPickupAnimation = false; fmBase[6] = data; updateFMifNecessary(9); @@ -299,7 +299,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // sustain rate - case 30: + case FADER_RELEASE_1: showPickupAnimation = false; fmBase[8] = data; updateFMifNecessary(8); @@ -312,7 +312,7 @@ void movedPot(byte number, byte data, bool isMidi) { break; // release // OP2 - case 31: + case FADER_DETUNE_2: showPickupAnimation = false; if (loopHeld) { loopChanged = true; @@ -334,7 +334,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // detune - case 32: + case FADER_MULT_2: showPickupAnimation = false; fmBase[19] = data; updateFMifNecessary(19); @@ -345,7 +345,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // multiple - case 40: + case FADER_LEVEL_2: showPickupAnimation = false; fmBase[20] = data; updateFMifNecessary(20); @@ -356,7 +356,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // op level - case 36: + case FADER_ATTACK_2: showPickupAnimation = false; fmBase[22] = data; updateFMifNecessary(22); @@ -367,7 +367,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // attack WAS 59 - case 44: + case FADER_DECAY_2: showPickupAnimation = false; fmBase[23] = data; updateFMifNecessary(23); @@ -378,7 +378,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // decay1 WAS 50 - case 42: + case FADER_SUSTAIN_2: showPickupAnimation = false; fmBase[25] = data; updateFMifNecessary(25); @@ -389,7 +389,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // sustain WAS 60 - case 34: + case FADER_SUSTAIN_RATE_2: showPickupAnimation = false; fmBase[24] = data; updateFMifNecessary(24); @@ -400,7 +400,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // sustain rate WAS 55 - case 11: + case FADER_RELEASE_2: showPickupAnimation = false; fmBase[26] = data; updateFMifNecessary(26); @@ -413,7 +413,7 @@ void movedPot(byte number, byte data, bool isMidi) { break; // release WAS 52 // OP3 - case 20: + case FADER_DETUNE_3: showPickupAnimation = false; if (loopHeld) { @@ -436,7 +436,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // detune - case 24: + case FADER_MULT_3: showPickupAnimation = false; fmBase[10] = data; updateFMifNecessary(10); @@ -447,7 +447,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // multiple - case 16: + case FADER_LEVEL_3: showPickupAnimation = false; fmBase[11] = data; updateFMifNecessary(11); @@ -458,7 +458,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // op level - case 8: + case FADER_ATTACK_3: showPickupAnimation = false; fmBase[13] = data; updateFMifNecessary(13); @@ -469,7 +469,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(49, data >> 1); } break; // attack - case 0: + case FADER_DECAY_3: showPickupAnimation = false; fmBase[14] = data; updateFMifNecessary(14); @@ -480,7 +480,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(50, data >> 1); } break; // decay1 - case 7: + case FADER_SUSTAIN_3: showPickupAnimation = false; fmBase[16] = data; updateFMifNecessary(16); @@ -491,7 +491,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(51, data >> 1); } break; // sustain - case 45: + case FADER_SUSTAIN_RATE_3: showPickupAnimation = false; fmBase[15] = data; updateFMifNecessary(15); @@ -502,7 +502,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // sustain rate - case 37: + case FADER_RELEASE_3: showPickupAnimation = false; fmBase[17] = data; updateFMifNecessary(17); @@ -515,7 +515,7 @@ void movedPot(byte number, byte data, bool isMidi) { break; // release // OP4 - case 47: + case FADER_DETUNE_4: showPickupAnimation = false; if (loopHeld) { loopChanged = true; @@ -538,7 +538,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // detune - case 39: + case FADER_MULT_4: showPickupAnimation = false; fmBase[28] = data; updateFMifNecessary(28); @@ -549,7 +549,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // multiple - case 38: + case FADER_LEVEL_4: showPickupAnimation = false; fmBase[29] = data; updateFMifNecessary(29); @@ -560,7 +560,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // op level - case 46: + case FADER_ATTACK_4: showPickupAnimation = false; fmBase[31] = data; updateFMifNecessary(31); @@ -571,7 +571,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // attack - case 33: + case FADER_DECAY_4: showPickupAnimation = false; fmBase[32] = data; updateFMifNecessary(32); @@ -582,7 +582,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // decay1 - case 41: + case FADER_SUSTAIN_4: showPickupAnimation = false; fmBase[34] = data; updateFMifNecessary(34); @@ -593,7 +593,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // sustain - case 43: + case FADER_SUSTAIN_RATE_4: showPickupAnimation = false; fmBase[33] = data; updateFMifNecessary(33); @@ -604,7 +604,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // sustain rate - case 35: + case FADER_RELEASE_4: showPickupAnimation = false; fmBase[35] = data; updateFMifNecessary(35); @@ -616,7 +616,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // release - case 1: + case KNOB_VOLUME: showPickupAnimation = false; setupCounter = 0; // prevent entering setup if (voiceHeld) { @@ -646,7 +646,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // volume - case 4: + case KNOB_ALGO: showPickupAnimation = false; if (isMidi) { data -= 1; @@ -660,7 +660,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // algo - case 3: + case KNOB_FEEDBACK: showPickupAnimation = false; fmBase[43] = data; updateFMifNecessary(43); @@ -671,7 +671,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // feedback - case 28: + case KNOB_FAT: showPickupAnimation = false; setupCounter = 0; // prevent entering setup @@ -699,7 +699,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // fat 1-127 - case 15: + case KNOB_LFO1_RATE: showPickupAnimation = false; fmBase[36] = data; if (data < 5 && lfoVel) { @@ -742,7 +742,7 @@ void movedPot(byte number, byte data, bool isMidi) { } } break; // lfo 1 rate - case 12: + case KNOB_LFO1_DEPTH: showPickupAnimation = false; fmBase[37] = data; updateFMifNecessary(37); @@ -754,7 +754,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // lfo 1 depth - case 10: + case KNOB_LFO2_RATE: showPickupAnimation = false; fmBase[38] = data; updateFMifNecessary(38); @@ -775,7 +775,7 @@ void movedPot(byte number, byte data, bool isMidi) { } } break; // lfo 2 rate - case 9: + case KNOB_LFO2_DEPTH: showPickupAnimation = false; fmBase[39] = data; updateFMifNecessary(39); @@ -787,7 +787,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // lfo 2 depth - case 14: + case KNOB_LFO3_RATE: showPickupAnimation = false; fmBase[40] = data; updateFMifNecessary(40); @@ -813,7 +813,7 @@ void movedPot(byte number, byte data, bool isMidi) { } } break; // lfo 3 rate - case 2: + case KNOB_LFO3_DEPTH: showPickupAnimation = false; fmBase[41] = data; updateFMifNecessary(41); @@ -825,7 +825,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // lfo 3 depth - case 6: + case KNOB_ARP_RATE: showPickupAnimation = false; fmBase[46] = data; updateFMifNecessary(46); @@ -841,7 +841,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; /// arp rate - case 5: + case KNOB_ARP_RANGE: showPickupAnimation = false; if (isMidi) { data = data << 6; @@ -855,7 +855,7 @@ void movedPot(byte number, byte data, bool isMidi) { } break; // arp range - case 48: + case KNOB_VIB_RATE: showPickupAnimation = false; fmBase[48] = data; updateFMifNecessary(48); @@ -870,7 +870,7 @@ void movedPot(byte number, byte data, bool isMidi) { sendCC(number, data >> 1); } break; // vibrato rate WAS 7 - case 13: + case KNOB_VIB_DEPTH: showPickupAnimation = false; fmBase[49] = data; updateFMifNecessary(49);