-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgramSelector.hpp
More file actions
109 lines (78 loc) · 2 KB
/
Copy pathProgramSelector.hpp
File metadata and controls
109 lines (78 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Noise Plethora
// Copyright (c) 2021 Befaco / Jeremy Bernstein
// Open-source software
// Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
// See LICENSE.txt for the complete license text
#pragma once
#include "Banks.hpp"
#define CLAMP(x, a, b) (x) < (a) ? (a) : (x) > (b) ? (b) : (x);
enum {
PROG_A = 0,
PROG_B
};
class Selection {
public:
Selection(int numPrograms = programsPerBank)
: value(0)
, min(0)
, max(numPrograms - 1)
{}
int getValue() {
return value;
}
int setValue(int val, int numValues = -1) {
if (numValues == -1) numValues = max + 1;
val = CLAMP(val, min, numValues - 1);
value = val;
return value;
}
void setMin(int v) {
min = v;
}
void setMax(int v) {
max = v;
}
private:
int value;
int min;
int max;
};
class ProgramSelection {
public:
int getBank() { return bank.getValue(); }
int getProgram() { return program.getValue(); }
int setBank(int b) {
if (getBankForIndex(b).getSize()) { // assumed that only top bank can be empty
return bank.setValue(b);
}
return getBank();
}
int setProgram(int p) {
return program.setValue(p, getBankForIndex(getBank()).getSize());
}
const char* getCurrentProgramName() {
return getBankForIndex(getBank()).getProgramName(getProgram());
}
float getCurrentProgramGain() {
return getBankForIndex(getBank()).getProgramGain(getProgram());
}
private:
Selection bank{numBanks};
Selection program;
};
class ProgramSelector {
public:
ProgramSelector()
: currentProgram(PROG_A)
{}
~ProgramSelector() {}
ProgramSelection& getCurrent() { return currentProgram == PROG_A ? progA : progB; }
ProgramSelection& getA() { return progA; }
ProgramSelection& getB() { return progB; }
unsigned int getMode() { return currentProgram; }
void setMode(unsigned int current) { currentProgram = current ? PROG_B : PROG_A; }
private:
ProgramSelection progA;
ProgramSelection progB;
unsigned int currentProgram;
};