-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMADI.cpp
343 lines (281 loc) · 7.87 KB
/
MADI.cpp
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*! \file MADI.cpp
*! \brief RME HDSPe MADI panel and control.
* 20211207 - [email protected] */
#include <thread>
#include <iostream>
#include "SndControl.h"
#include "MADI.h"
#include "MADIPanel.h"
#include "HDSPeConf.h"
#define SET_CB(prop) card->prop.callOnValueChange(POSTCB(update_##prop,#prop))
class MyMADIPanel: public MADIPanel {
protected:
class MADICard* card { nullptr };
constexpr static const double UNSET_PITCH { -1.0 };
double newPitch = UNSET_PITCH;
public:
MyMADIPanel(MADICard* _card, wxWindow* parent)
: MADIPanel(parent, wxID_ANY)
, card(_card)
{
fwVersionLabel->SetLabelText(std::to_string(card->fwBuild));
SET_CB(running);
SET_CB(bufferSize);
SET_CB(clockMode);
SET_CB(internalFreq);
SET_CB(preferredRef);
SET_CB(syncRef);
SET_CB(syncStatus);
SET_CB(syncFreq);
SET_CB(sampleRate);
SET_CB(externalFreq);
SET_CB(preferredInput);
SET_CB(currentInput);
SET_CB(autoselectInput);
SET_CB(rx64ch);
SET_CB(tx64ch);
SET_CB(doubleWire);
SET_CB(singleSpeedWclkOut);
SET_CB(clrTms);
currentMadiInputBox->Enable(false);
}
void update_running(void)
{
internalFreqLabel->Show(card->running);
internalFreqLabel->SetLabelText(card->internalFreq.label());
internalFreqChoice->Show(!card->running);
internalFreqChoice->SetSelection(card->internalFreq.value());
}
void update_bufferSize(void)
{
bufferSizeLabel->SetLabelText(std::to_string(card->bufferSize));
}
void update_clockMode(void)
{
setClockSourceLabel();
setSyncButtonState();
}
void update_syncRef(void)
{
setClockSourceLabel();
}
void update_preferredRef(void)
{
setSyncButtonState();
}
void update_internalFreq(void)
{
internalFreqLabel->SetLabelText(card->internalFreq.label());
internalFreqChoice->SetSelection(card->internalFreq.value());
checkFreqs();
}
void update_syncFreq(void)
{
wclkFreqLabel->SetLabelText(card->syncFreq.label(0));
madiFreqLabel->SetLabelText(card->syncFreq.label(1));
tcoFreqLabel->SetLabelText(card->syncFreq.label(2));
syncInFreqLabel->SetLabelText(card->syncFreq.label(3));
checkFreqs();
}
void update_sampleRate(void)
{
int rate = (int)round(card->getSystemSampleRate());
sampleRateLabel->SetLabelText(std::to_string(rate));
sampleRateLabel->SetBackgroundColour(card->isStandardSampleRate(rate)
? wxNullColour : wxColour(0xff, 0xc6, 0x00));
pitchSlider->Enable(card->isMaster());
pitchSlider->SetValue(card->getPitch() * 1e6); // display pitch in PPM
checkFreqs();
}
void setClockSourceLabel(void)
{
clockSourceLabel->SetLabelText(card->isMaster() ? "Master" :
card->syncRef.label());
}
void setSyncButtonState(void)
{
wclkSyncButton->SetValue(false);
madiSyncButton->SetValue(false);
tcoSyncButton->SetValue(false);
syncInSyncButton->SetValue(false);
masterButton->SetValue(card->isMaster());
if (!card->isMaster()) {
switch (card->preferredRef) {
case 0: wclkSyncButton->SetValue(true); break;
case 1: madiSyncButton->SetValue(true); break;
case 2: tcoSyncButton->SetValue(true); break;
case 3: syncInSyncButton->SetValue(true); break;
}
}
}
void checkFreqs(void)
{
internalWarn->Show(card->internalRateDeviates());
unsigned* f = card->syncFreq.values();
wclkWarn->Show(!card->isClockCompatible(f[0]));
madiWarn->Show(!card->isClockCompatible(f[1]));
tcoWarn->Show(!card->isClockCompatible(f[2]));
syncInWarn->Show(!card->isClockCompatible(f[3]));
}
void enableSyncButtons(void)
{
unsigned* s = card->syncStatus.values();
wclkSyncButton->Enable(s[0] != 3);
madiSyncButton->Enable(s[1] != 3);
tcoSyncButton->Enable(s[2] != 3);
syncInSyncButton->Enable(s[3] != 3);
}
void update_syncStatus(void)
{
wclkStatusLabel->SetLabelText(card->syncStatus.label(0));
madiStatusLabel->SetLabelText(card->syncStatus.label(1));
tcoStatusLabel->SetLabelText(card->syncStatus.label(2));
syncInStatusLabel->SetLabelText(card->syncStatus.label(3));
enableSyncButtons();
}
void update_externalFreq(void)
{
// std::cerr << __func__ << ": externalFreq=" << card->externalFreq << "\n";
}
void update_preferredInput(void)
{
madiInputBox->SetSelection(card->preferredInput.value());
}
void update_currentInput(void)
{
currentMadiInputBox->SetSelection(card->currentInput.value());
}
void update_autoselectInput(void)
{
autoselectInputButton->SetValue(card->autoselectInput.value());
}
void update_rx64ch(void)
{
rx64chButton->SetValue(card->rx64ch.value());
}
void update_tx64ch(void)
{
tx64chButton->SetValue(card->tx64ch.value());
}
void update_doubleWire(void)
{
doubleWireButton->SetValue(card->doubleWire.value());
}
void update_singleSpeedWclkOut(void)
{
if (card->hasTco()) { /* TCO is always single speed word clock out */
singleSpeedWclkButton->Disable();
singleSpeedWclkButton->SetValue(true);
} else {
singleSpeedWclkButton->Enable();
singleSpeedWclkButton->SetValue(card->singleSpeedWclkOut);
}
}
void update_clrTms(void)
{
tmsButton->SetValue(!card->clrTms);
}
void internalFreqCB(wxCommandEvent &event) override
{
card->internalFreq.set(event.GetInt());
}
void masterCB(wxCommandEvent &event) override
{
card->clockMode.set(1);
}
void wclkSyncCB(wxCommandEvent &event) override
{
card->preferredRef.set(0);
card->clockMode.set(0);
}
void madiSyncCB(wxCommandEvent &event) override
{
card->preferredRef.set(1);
card->clockMode.set(0);
}
void tcoSyncCB(wxCommandEvent &event) override
{
card->preferredRef.set(2);
card->clockMode.set(0);
}
void syncInSyncCB(wxCommandEvent &event) override
{
card->preferredRef.set(3);
card->clockMode.set(0);
}
void pitchDownCB(wxScrollEvent &event) override
{
newPitch = card->upPitch(); // no mistake ... arrow buttons are reversed
}
void pitchUpCB(wxScrollEvent &event) override
{
newPitch = card->downPitch();
}
void pitchPrevCB(wxScrollEvent &event) override
{
newPitch = card->prevPitch();
}
void pitchNextCB(wxScrollEvent &event) override
{
newPitch = card->nextPitch();
}
void pitchSliderCB(wxCommandEvent &event) override
{
if (newPitch == UNSET_PITCH)
newPitch = (double)event.GetInt() * 1e-6;
else
pitchSlider->SetValue(newPitch * 1e6);
card->setPitch(newPitch);
newPitch = UNSET_PITCH;
}
void madiInputCB(wxCommandEvent &event) override
{
card->preferredInput.set(event.GetInt());
}
void autoselectInputCB(wxCommandEvent &event) override
{
card->autoselectInput.set(event.GetInt());
}
void tx64chCB(wxCommandEvent &event) override
{
card->tx64ch.set(event.GetInt());
}
void doubleWireCB(wxCommandEvent& event) override
{
card->doubleWire.set(event.GetInt());
}
void singleSpeedWclkOutCB(wxCommandEvent &event) override
{
card->singleSpeedWclkOut.set(event.GetInt());
}
void tmsCB(wxCommandEvent &event) override
{
card->clrTms.set(!event.GetInt());
}
};
MADICard::MADICard(int index)
: HDSPeCard(index)
, externalFreq(this, "External Frequency")
, preferredInput(this, "Preferred Input")
, currentInput(this, "Current Input")
, autoselectInput(this, "Autoselect Input")
, rx64ch(this, "RX 64 Channels Mode")
, tx64ch(this, "TX 64 Channels Mode")
, doubleWire(this, "Double Wire Mode")
, singleSpeedWclkOut(this, "Single Speed WordClk Out")
, clrTms(this, "Clear TMS")
{
modelName = "MADI";
tcoSyncChoice = 2;
}
MADICard::~MADICard()
{
}
class wxPanel* MADICard::makePanel(wxWindow* parent)
{
return panel = new MyMADIPanel(this, parent);
}
int MADICard::getExternalFreq(void) const
{
return externalFreq;
}