-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpSystem.h
150 lines (101 loc) · 4.26 KB
/
expSystem.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef __exp_system_h__
#define __exp_system_h__
#include "defines.h"
#include <Arduino.h> // for intevalTimer
#define MAX_EXP_PATCHES 10
#define MAX_MODAL_STACK 10
class expSystem;
#define WIN_FLAG_DELETE_ON_END 0x00010000
// window will be deleted after call to endModal
#define WIN_FLAG_OWNER_TITLE 0x00001000
// window calls theSystem.setTitle() itself
class expWindow
// base class for patches, modal windows, and the configSystem
{
public:
expWindow() {m_flags = 0;}
expWindow(uint32_t flags) {m_flags = flags;}
virtual ~expWindow() {}
virtual const char *name() = 0;
// used for titles
virtual const char *short_name() { return ""; };
// only used for patches in config window
virtual uint32_t getId() { return 0; }
protected:
friend class expSystem;
virtual void begin(bool warm);
// warm means that we are coming down the modal window stack
// as opposed to being invoked as a new window
// derived classes should call base class method FIRST
// base class clears all button registrations.
virtual void end() {}
// called when the window is taken out of focus, they
// don't generally need to worry about buttons and LEDs,
// but may want to unregister midi event handlers, etc
virtual bool onRotaryEvent(int num, int val) { return false; }
virtual bool onPedalEvent(int num, int val) { return false; }
// derived classes return true if they handled the event
// otherwise default base class behavior takes place
virtual void onButtonEvent(int row, int col, int event) {}
virtual void updateUI() {}
virtual void timer_handler() {}
virtual void onEndModal(expWindow *win, uint32_t param) {}
// called by expSystem after modal windows close themselves
// with calls to endModal();
virtual void endModal(uint32_t param);
// called by modal windows when they end themselves
uint32_t m_flags;
};
#define MIDI_ACTIVITY_INLINE 1
class expSystem
{
public:
expSystem();
~expSystem() {}
void begin();
void updateUI();
void activatePatch(int i);
int getNumPatches() { return m_num_patches; }
int getCurPatchNum() { return m_cur_patch_num; }
int getPrevConfigNum() { return m_prev_patch_num; }
expWindow *getCurPatch() { return m_patches[m_cur_patch_num]; }
expWindow *getPatch(int i) { return m_patches[i]; }
void pedalEvent(int num, int val);
void rotaryEvent(int num, int val);
void buttonEvent(int row, int col, int event);
void setTitle(const char *title);
void startModal(expWindow *win);
void swapModal(expWindow *win, uint32_t param);
void endModal(expWindow *win, uint32_t param);
expWindow *getTopModalWindow();
#if MIDI_ACTIVITY_INLINE
inline void midiActivity(int port_num) { midi_activity[port_num]=millis(); }
#else
void midiActivity(int port_num);
#endif
int getTempo() { return m_tempo; }
private:
int m_num_patches;
int m_cur_patch_num;
int m_prev_patch_num;
void addPatch(expWindow *pConfig);
int m_num_modals;
expWindow *m_modal_stack[MAX_MODAL_STACK];
expWindow *m_patches[MAX_EXP_PATCHES + 1];
// 1 extra for patch #0 which is overloaded
// as the configSystem window.
IntervalTimer m_timer;
IntervalTimer m_critical_timer;
static void timer_handler();
static void critical_timer_handler();
int last_battery_level;
elapsedMillis battery_time;
bool draw_needed;
const char *m_title;
unsigned midi_activity[NUM_PORTS];
bool last_midi_activity[NUM_PORTS];
int m_tempo;
};
extern expSystem theSystem;
// in teensyExpression.ino
#endif // !__exp_system_h__