Skip to content

Commit 95bae61

Browse files
authored
Binaural Monitoring fixes/improvements (#183)
* Inversion controls - closes #177 * Save to config file - closes #182 * More helpful connection error message * Patch JUCE so Win can detect UDP port open fail - don't need to rely on message receipt to confirm successful listen - closes #169 * Don't crash if bin mon receives 0.6.0 metadata - closes #180
1 parent 50d8d9b commit 95bae61

12 files changed

+733
-68
lines changed

ear-production-suite-plugins/lib/include/ui/binaural_monitoring_frontend_backend_connector.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class EAR_PLUGIN_BASE_EXPORT BinauralMonitoringFrontendBackendConnector {
3333
ROLL,
3434
OSC_ENABLE,
3535
OSC_PORT,
36+
OSC_INVERT_YAW,
37+
OSC_INVERT_PITCH,
38+
OSC_INVERT_ROLL,
39+
OSC_INVERT_QUAT_W,
40+
OSC_INVERT_QUAT_X,
41+
OSC_INVERT_QUAT_Y,
42+
OSC_INVERT_QUAT_Z,
3643
};
3744

3845
using ParameterChangedCallback =

ear-production-suite-plugins/lib/src/binaural_monitoring_backend.cpp

+23-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
using std::placeholders::_1;
99
using std::placeholders::_2;
1010

11+
namespace {
12+
template<typename T>
13+
bool vectorContains(std::vector<T> const& v, T k) {
14+
return std::find(v.begin(), v.end(), k) != v.end();
15+
}
16+
17+
bool isValidId(std::string const& id) {
18+
return !(id.empty() || id == "00000000-0000-0000-0000-000000000000");
19+
}
20+
}
21+
1122
namespace ear {
1223
namespace plugin {
1324

@@ -200,7 +211,14 @@ void BinauralMonitoringBackend::onSceneReceived(proto::SceneStore store) {
200211
size_t totalObjChannels = 0;
201212
size_t totalHoaChannels = 0;
202213

214+
std::vector<ConnId> availableItemIds;
215+
availableItemIds.reserve(store.all_available_items_size());
216+
203217
for (const auto& item : store.all_available_items()) {
218+
if(item.has_connection_id() &&
219+
isValidId(item.connection_id())) {
220+
availableItemIds.push_back(item.connection_id());
221+
}
204222
if (item.has_ds_metadata()) {
205223
totalDsChannels += item.ds_metadata().speakers_size();
206224
}
@@ -231,10 +249,11 @@ void BinauralMonitoringBackend::onSceneReceived(proto::SceneStore store) {
231249

232250
for (const auto& item : store.monitoring_items()) {
233251
if (item.has_connection_id() &&
234-
item.connection_id() != "00000000-0000-0000-0000-000000000000" &&
235-
item.connection_id() != "") {
236-
bool newItem = std::find(allActiveIds.begin(), allActiveIds.end(),
237-
item.connection_id()) == allActiveIds.end();
252+
isValidId(item.connection_id()) &&
253+
vectorContains(availableItemIds, item.connection_id())) {
254+
255+
bool newItem = !vectorContains(allActiveIds, item.connection_id());
256+
238257
// clang-format off
239258
if (item.has_hoa_metadata()) {
240259
if(newItem || item.changed()) {

ear-production-suite-plugins/plugins/binaural_monitoring/src/binaural_monitoring_frontend_connector.cpp

+200-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ BinauralMonitoringJuceFrontendConnector::
5252
if (auto oscControl = oscPortControl_.lock()) {
5353
oscControl->removeListener(this);
5454
}
55+
if (auto oscControl = oscInvertYawButton_.lock()) {
56+
oscControl->removeListener(this);
57+
}
58+
if (auto oscControl = oscInvertPitchButton_.lock()) {
59+
oscControl->removeListener(this);
60+
}
61+
if (auto oscControl = oscInvertRollButton_.lock()) {
62+
oscControl->removeListener(this);
63+
}
64+
if (auto oscControl = oscInvertQuatWButton_.lock()) {
65+
oscControl->removeListener(this);
66+
}
67+
if (auto oscControl = oscInvertQuatXButton_.lock()) {
68+
oscControl->removeListener(this);
69+
}
70+
if (auto oscControl = oscInvertQuatYButton_.lock()) {
71+
oscControl->removeListener(this);
72+
}
73+
if (auto oscControl = oscInvertQuatZButton_.lock()) {
74+
oscControl->removeListener(this);
75+
}
5576

5677
if (listenerOrientation) {
5778
listenerOrientation->removeListener(this);
@@ -102,6 +123,55 @@ void BinauralMonitoringJuceFrontendConnector::setOscPortControl(
102123
setOscPort(cachedOscPort_);
103124
}
104125

126+
void BinauralMonitoringJuceFrontendConnector::setOscInvertYawButton(
127+
std::shared_ptr<ToggleButton> button) {
128+
button->addListener(this);
129+
oscInvertYawButton_ = button;
130+
setOscInvertYaw(cachedOscInvertYaw_);
131+
}
132+
133+
void BinauralMonitoringJuceFrontendConnector::setOscInvertPitchButton(
134+
std::shared_ptr<ToggleButton> button) {
135+
button->addListener(this);
136+
oscInvertPitchButton_ = button;
137+
setOscInvertPitch(cachedOscInvertPitch_);
138+
}
139+
140+
void BinauralMonitoringJuceFrontendConnector::setOscInvertRollButton(
141+
std::shared_ptr<ToggleButton> button) {
142+
button->addListener(this);
143+
oscInvertRollButton_ = button;
144+
setOscInvertRoll(cachedOscInvertRoll_);
145+
}
146+
147+
void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatWButton(
148+
std::shared_ptr<ToggleButton> button) {
149+
button->addListener(this);
150+
oscInvertQuatWButton_ = button;
151+
setOscInvertQuatW(cachedOscInvertQuatW_);
152+
}
153+
154+
void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatXButton(
155+
std::shared_ptr<ToggleButton> button) {
156+
button->addListener(this);
157+
oscInvertQuatXButton_ = button;
158+
setOscInvertQuatX(cachedOscInvertQuatX_);
159+
}
160+
161+
void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatYButton(
162+
std::shared_ptr<ToggleButton> button) {
163+
button->addListener(this);
164+
oscInvertQuatYButton_ = button;
165+
setOscInvertQuatY(cachedOscInvertQuatY_);
166+
}
167+
168+
void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatZButton(
169+
std::shared_ptr<ToggleButton> button) {
170+
button->addListener(this);
171+
oscInvertQuatZButton_ = button;
172+
setOscInvertQuatZ(cachedOscInvertQuatZ_);
173+
}
174+
105175
void BinauralMonitoringJuceFrontendConnector::setListenerOrientationInstance(
106176
std::shared_ptr<ListenerOrientation> lo) {
107177
listenerOrientation = lo;
@@ -137,6 +207,7 @@ void BinauralMonitoringJuceFrontendConnector::setEuler(
137207
if (listenerOrientation) {
138208
listenerOrientation->setEuler(euler);
139209
}
210+
140211
}
141212

142213
void BinauralMonitoringJuceFrontendConnector::setQuaternion(
@@ -160,6 +231,55 @@ void BinauralMonitoringJuceFrontendConnector::setOscPort(int port) {
160231
cachedOscPort_ = port;
161232
}
162233

234+
void BinauralMonitoringJuceFrontendConnector::setOscInvertYaw(bool invert) {
235+
if (auto oscInvertButtonLocked = oscInvertYawButton_.lock()) {
236+
oscInvertButtonLocked->setToggleState(invert, dontSendNotification);
237+
}
238+
cachedOscInvertYaw_ = invert;
239+
}
240+
241+
void BinauralMonitoringJuceFrontendConnector::setOscInvertPitch(bool invert) {
242+
if (auto oscInvertButtonLocked = oscInvertPitchButton_.lock()) {
243+
oscInvertButtonLocked->setToggleState(invert, dontSendNotification);
244+
}
245+
cachedOscInvertPitch_ = invert;
246+
}
247+
248+
void BinauralMonitoringJuceFrontendConnector::setOscInvertRoll(bool invert) {
249+
if (auto oscInvertButtonLocked = oscInvertRollButton_.lock()) {
250+
oscInvertButtonLocked->setToggleState(invert, dontSendNotification);
251+
}
252+
cachedOscInvertRoll_ = invert;
253+
}
254+
255+
void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatW(bool invert) {
256+
if (auto oscInvertButtonLocked = oscInvertQuatWButton_.lock()) {
257+
oscInvertButtonLocked->setToggleState(invert, dontSendNotification);
258+
}
259+
cachedOscInvertQuatW_ = invert;
260+
}
261+
262+
void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatX(bool invert) {
263+
if (auto oscInvertButtonLocked = oscInvertQuatXButton_.lock()) {
264+
oscInvertButtonLocked->setToggleState(invert, dontSendNotification);
265+
}
266+
cachedOscInvertQuatX_ = invert;
267+
}
268+
269+
void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatY(bool invert) {
270+
if (auto oscInvertButtonLocked = oscInvertQuatYButton_.lock()) {
271+
oscInvertButtonLocked->setToggleState(invert, dontSendNotification);
272+
}
273+
cachedOscInvertQuatY_ = invert;
274+
}
275+
276+
void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatZ(bool invert) {
277+
if (auto oscInvertButtonLocked = oscInvertQuatZButton_.lock()) {
278+
oscInvertButtonLocked->setToggleState(invert, dontSendNotification);
279+
}
280+
cachedOscInvertQuatZ_ = invert;
281+
}
282+
163283
void BinauralMonitoringJuceFrontendConnector::orientationChange(
164284
ear::plugin::ListenerOrientation::Euler euler) {
165285
// ListenerOrientation callback from backend
@@ -220,6 +340,56 @@ void BinauralMonitoringJuceFrontendConnector::parameterValueChanged(
220340
notifyParameterChanged(ParameterId::OSC_PORT, p_->getOscPort()->get());
221341
setOscPort(p_->getOscPort()->get());
222342
});
343+
344+
} else if (parameterIndex == (int)ParameterId::OSC_INVERT_YAW) {
345+
updater_.callOnMessageThread([this, parameterIndex, newValue]() {
346+
notifyParameterChanged(ParameterId::OSC_INVERT_YAW,
347+
p_->getOscInvertYaw()->get());
348+
setOscInvertYaw(p_->getOscInvertYaw()->get());
349+
});
350+
351+
} else if (parameterIndex == (int)ParameterId::OSC_INVERT_PITCH) {
352+
updater_.callOnMessageThread([this, parameterIndex, newValue]() {
353+
notifyParameterChanged(ParameterId::OSC_INVERT_PITCH,
354+
p_->getOscInvertPitch()->get());
355+
setOscInvertPitch(p_->getOscInvertPitch()->get());
356+
});
357+
358+
} else if (parameterIndex == (int)ParameterId::OSC_INVERT_ROLL) {
359+
updater_.callOnMessageThread([this, parameterIndex, newValue]() {
360+
notifyParameterChanged(ParameterId::OSC_INVERT_ROLL,
361+
p_->getOscInvertRoll()->get());
362+
setOscInvertRoll(p_->getOscInvertRoll()->get());
363+
});
364+
365+
} else if (parameterIndex == (int)ParameterId::OSC_INVERT_QUAT_W) {
366+
updater_.callOnMessageThread([this, parameterIndex, newValue]() {
367+
notifyParameterChanged(ParameterId::OSC_INVERT_QUAT_W,
368+
p_->getOscInvertQuatW()->get());
369+
setOscInvertQuatW(p_->getOscInvertQuatW()->get());
370+
});
371+
372+
} else if (parameterIndex == (int)ParameterId::OSC_INVERT_QUAT_X) {
373+
updater_.callOnMessageThread([this, parameterIndex, newValue]() {
374+
notifyParameterChanged(ParameterId::OSC_INVERT_QUAT_X,
375+
p_->getOscInvertQuatX()->get());
376+
setOscInvertQuatX(p_->getOscInvertQuatX()->get());
377+
});
378+
379+
} else if (parameterIndex == (int)ParameterId::OSC_INVERT_QUAT_Y) {
380+
updater_.callOnMessageThread([this, parameterIndex, newValue]() {
381+
notifyParameterChanged(ParameterId::OSC_INVERT_QUAT_Y,
382+
p_->getOscInvertQuatY()->get());
383+
setOscInvertQuatY(p_->getOscInvertQuatY()->get());
384+
});
385+
386+
} else if (parameterIndex == (int)ParameterId::OSC_INVERT_QUAT_Z) {
387+
updater_.callOnMessageThread([this, parameterIndex, newValue]() {
388+
notifyParameterChanged(ParameterId::OSC_INVERT_QUAT_Z,
389+
p_->getOscInvertQuatZ()->get());
390+
setOscInvertQuatZ(p_->getOscInvertQuatZ()->get());
391+
});
392+
223393
}
224394
}
225395

@@ -270,12 +440,40 @@ void BinauralMonitoringJuceFrontendConnector::orientationDragEnded(
270440
}
271441

272442
void BinauralMonitoringJuceFrontendConnector::buttonClicked(Button* button) {
443+
// note: getToggleState still has the old value for toggle types when this is called
444+
// due to setClickingTogglesState on the button intentionally being false
273445
if (auto oscButton = lockIfSame(oscEnableButton_, button)) {
274-
// note: getToggleState still has the old value when this is called
275-
// due to setClickingTogglesState on the button being false
276446
bool newState = !oscButton->getToggleState();
277447
*(p_->getOscEnable()) = newState;
278448
}
449+
if (auto oscButton = lockIfSame(oscInvertYawButton_, button)) {
450+
bool newState = !oscButton->getToggleState();
451+
*(p_->getOscInvertYaw()) = newState;
452+
}
453+
if (auto oscButton = lockIfSame(oscInvertPitchButton_, button)) {
454+
bool newState = !oscButton->getToggleState();
455+
*(p_->getOscInvertPitch()) = newState;
456+
}
457+
if (auto oscButton = lockIfSame(oscInvertRollButton_, button)) {
458+
bool newState = !oscButton->getToggleState();
459+
*(p_->getOscInvertRoll()) = newState;
460+
}
461+
if (auto oscButton = lockIfSame(oscInvertQuatWButton_, button)) {
462+
bool newState = !oscButton->getToggleState();
463+
*(p_->getOscInvertQuatW()) = newState;
464+
}
465+
if (auto oscButton = lockIfSame(oscInvertQuatXButton_, button)) {
466+
bool newState = !oscButton->getToggleState();
467+
*(p_->getOscInvertQuatX()) = newState;
468+
}
469+
if (auto oscButton = lockIfSame(oscInvertQuatYButton_, button)) {
470+
bool newState = !oscButton->getToggleState();
471+
*(p_->getOscInvertQuatY()) = newState;
472+
}
473+
if (auto oscButton = lockIfSame(oscInvertQuatZButton_, button)) {
474+
bool newState = !oscButton->getToggleState();
475+
*(p_->getOscInvertQuatZ()) = newState;
476+
}
279477
}
280478

281479
void BinauralMonitoringJuceFrontendConnector::sliderValueChanged(

ear-production-suite-plugins/plugins/binaural_monitoring/src/binaural_monitoring_frontend_connector.hpp

+29
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ class BinauralMonitoringJuceFrontendConnector
4444
// OSC Controls
4545
void setOscEnableButton(std::shared_ptr<EarButton> button);
4646
void setOscPortControl(std::shared_ptr<EarSlider> slider);
47+
void setOscInvertYawButton(std::shared_ptr<ToggleButton> button);
48+
void setOscInvertPitchButton(std::shared_ptr<ToggleButton> button);
49+
void setOscInvertRollButton(std::shared_ptr<ToggleButton> button);
50+
void setOscInvertQuatWButton(std::shared_ptr<ToggleButton> button);
51+
void setOscInvertQuatXButton(std::shared_ptr<ToggleButton> button);
52+
void setOscInvertQuatYButton(std::shared_ptr<ToggleButton> button);
53+
void setOscInvertQuatZButton(std::shared_ptr<ToggleButton> button);
4754

4855
// Listener Orientation Object
4956
void setListenerOrientationInstance(std::shared_ptr<ListenerOrientation> lo);
@@ -57,6 +64,13 @@ class BinauralMonitoringJuceFrontendConnector
5764

5865
void setOscEnable(bool enable);
5966
void setOscPort(int port);
67+
void setOscInvertYaw(bool invert);
68+
void setOscInvertPitch(bool invert);
69+
void setOscInvertRoll(bool invert);
70+
void setOscInvertQuatW(bool invert);
71+
void setOscInvertQuatX(bool invert);
72+
void setOscInvertQuatY(bool invert);
73+
void setOscInvertQuatZ(bool invert);
6074

6175
protected:
6276
// Orientation::Listener
@@ -90,10 +104,25 @@ class BinauralMonitoringJuceFrontendConnector
90104
// OSC Controls
91105
std::weak_ptr<EarButton> oscEnableButton_;
92106
std::weak_ptr<EarSlider> oscPortControl_;
107+
std::weak_ptr<ToggleButton> oscInvertYawButton_;
108+
std::weak_ptr<ToggleButton> oscInvertPitchButton_;
109+
std::weak_ptr<ToggleButton> oscInvertRollButton_;
110+
std::weak_ptr<ToggleButton> oscInvertQuatWButton_;
111+
std::weak_ptr<ToggleButton> oscInvertQuatXButton_;
112+
std::weak_ptr<ToggleButton> oscInvertQuatYButton_;
113+
std::weak_ptr<ToggleButton> oscInvertQuatZButton_;
93114

94115
// Values
95116
bool cachedOscEnable_;
96117
int cachedOscPort_;
118+
bool cachedOscInvertYaw_;
119+
bool cachedOscInvertPitch_;
120+
bool cachedOscInvertRoll_;
121+
bool cachedOscInvertQuatW_;
122+
bool cachedOscInvertQuatX_;
123+
bool cachedOscInvertQuatY_;
124+
bool cachedOscInvertQuatZ_;
125+
97126
/// Listener Orientation Object
98127
std::shared_ptr<ListenerOrientation> listenerOrientation;
99128

0 commit comments

Comments
 (0)