forked from fxsound2/fxsound-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFxModel.h
More file actions
237 lines (193 loc) · 4.69 KB
/
Copy pathFxModel.h
File metadata and controls
237 lines (193 loc) · 4.69 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
FxSound
Copyright (C) 2023 FxSound LLC
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 FXMODEL_H
#define FXMODEL_H
#include <JuceHeader.h>
#include "AudioPassthru.h"
class FxModel final
{
public:
enum Event { Notification=1, Subscription, PresetSelected, PresetListUpdated, PresetModified, OutputSelected, OutputListUpdated, OutputError, Other };
enum PresetType { AppPreset=1, UserPreset=2 };
struct AccountInfo final
{
String email;
String subscription;
bool trial;
};
struct AccountLog final
{
int64_t next_limited_playback_time;
uint32_t playback_duration;
};
struct Preset final
{
String name;
String path;
PresetType type;
};
class Listener
{
public:
Listener() = default;
virtual ~Listener() = default;
virtual void modelChanged(Event) {}
};
static FxModel& getModel()
{
static FxModel model;
return model;
}
FxModel(const FxModel&) = delete;
void operator=(const FxModel&) = delete;
void initOutputs(const std::vector<SoundDevice>& output_devices);
void initPresets(const Array<Preset>& presets);
int addPreset(const Preset& preset);
void removePreset(int preset);
int selectPreset(const String& selected_preset, bool notify=true);
void selectPreset(int selected_preset, bool notify=true);
int getSelectedPreset() const;
int getPresetCount() const;
int getUserPresetCount() const;
Preset getPreset(int preset) const;
bool isPresetModified() const;
void setPresetModified(bool preset_modified);
bool isPresetNameValid(const String& preset_name);
bool getPowerState()
{
return power_state_;
}
void setPowerState(bool power_state)
{
power_state_ = power_state;
notifyListeners();
}
const StringArray& getOutputNames() const
{
return output_names_;
}
int getSelectedOutput()
{
return selected_output_;
}
void setSelectedOutput(int selected_output, const SoundDevice& sound_device)
{
selected_output_ = selected_output;
selected_output_device_ = sound_device;
notifyListeners(Event::OutputSelected);
}
bool isMonoOutputSelected()
{
return selected_output_device_.deviceNumChannel < 2;
}
void notifyOutputError()
{
notifyListeners(Event::OutputError);
}
AccountInfo getAccountInfo() const
{
return account_info_;
}
void setEmail(String email)
{
account_info_.email = email;
}
void setSubscription(String subscription)
{
account_info_.subscription = subscription;
notifyListeners(Event::Subscription);
}
AccountLog getAccountLog() const
{
return account_log_;
}
void setAccountLog(const AccountLog& account_log)
{
account_log_ = account_log;
}
void setTrial(bool trial)
{
account_info_.trial = trial;
}
bool getHotkeySupport()
{
return hotkey_support_;
}
void setHotkeySupport(bool hotkey_support)
{
hotkey_support_ = hotkey_support;
}
bool isMenuClicked()
{
return menu_clicked_;
}
void setMenuClicked(bool clicked)
{
menu_clicked_ = clicked;
}
int getLanguage()
{
return language_;
}
void setLanguage(int language)
{
language_ = language;
}
bool getDebugLogging()
{
return debug_logging_;
}
void setDebugLogging(bool debug_logging)
{
debug_logging_ = debug_logging;
}
void pushMessage(String message, std::pair<String, String> link = {})
{
message_ = message;
message_link_ = link;
notifyListeners(Event::Notification);
}
void popMessage(String& message, std::pair<String, String>& link)
{
message = message_;
link = message_link_;
message_.clear();
message_link_ = { "", "" };
}
void addListener(Listener* l) { listeners_.add(l); }
void removeListener(Listener* l) { listeners_.remove(l); }
void notifyListeners(Event model_event = Event::Other);
private:
FxModel();
bool power_state_;
Array<Preset> presets_;
bool preset_modified_;
StringArray output_names_;
int selected_preset_;
int selected_output_;
bool output_disconnected_;
AccountInfo account_info_;
AccountLog account_log_;
bool hotkey_support_;
bool menu_clicked_;
int language_;
bool debug_logging_;
std::vector<SoundDevice> output_devices_;
SoundDevice selected_output_device_;
String message_;
std::pair<String, String> message_link_;
ListenerList<Listener> listeners_;
};
#endif