forked from pichenettes/eurorack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.h
executable file
·104 lines (81 loc) · 2.53 KB
/
ui.h
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
// Copyright 2012 Emilie Gillet.
//
// Author: Emilie Gillet ([email protected])
//
// 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/>.
//
// User interface handling.
#ifndef EDGES_UI_H_
#define EDGES_UI_H_
#include "avrlibx/avrlibx.h"
#include "edges/hardware_config.h"
#include "edges/settings.h"
namespace edges {
enum Mode {
MODE_NORMAL,
MODE_MENU,
MODE_CALIBRATE_1,
MODE_CALIBRATE_2,
MODE_RECORDING,
MODE_LEARNING_MIDI_CHANNEL
};
static const uint8_t kNumSwitches = 6;
class Ui {
public:
Ui() { }
~Ui() { }
void Init();
static void set_gate(uint8_t gate) { gate_ = gate; }
static void set_cv(uint8_t channel, uint16_t cv) {
if (mode_ >= MODE_CALIBRATE_1 &&
mode_ <= MODE_CALIBRATE_2 &&
channel == edited_channel_) {
calibration_cv_[mode_ - MODE_CALIBRATE_1] = cv;
}
cv_[channel] = cv;
}
static uint16_t cv(uint8_t channel) {
if (mode_ == MODE_RECORDING && channel == edited_channel_) {
return root_cv_;
} else {
return cv_[channel];
}
}
static void Poll();
static uint8_t gate() { return gate_; }
static Mode mode() { return mode_; }
static inline MidiMode midi_mode() {
return static_cast<MidiMode>(settings.midi_mode());
}
private:
static void OnSwitchHeld(uint8_t index);
static void OnSwitchReleased(uint8_t index);
static uint8_t edited_channel_;
static Mode mode_;
static uint8_t gate_;
// Used for dimming LEDs.
static uint16_t leds_pwm_counter_;
// Used for detecting long switch pressed.
static uint16_t switch_time_counter_;
static uint16_t calibration_cv_[2];
static uint16_t root_cv_;
static uint16_t cv_[2 * kNumChannels];
static Leds leds_;
static Switches switches_;
static Gpio<PortC, 1> midi_learn_switch_;
static Gpio<PortC, 3> midi_mode_switch_;
static uint8_t debounce_history_[kNumSwitches];
DISALLOW_COPY_AND_ASSIGN(Ui);
};
extern Ui ui;
} // namespace edges
#endif // EDGES_UI_H_