Skip to content

Commit 20cc544

Browse files
authored
Show MTS Status on the Voice page (#361)
1 parent 03b3872 commit 20cc544

7 files changed

Lines changed: 63 additions & 3 deletions

File tree

libs/MTS-ESP

Submodule MTS-ESP updated 1 file

src/synth/synth.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ template <bool multiOut> void Synth::processInternal(const clap_output_events_t
479479
AudioToUIMsg msg3{AudioToUIMsg::UPDATE_CPU_USAGE, 0, (float)(cpuUsage * 100)};
480480
audioToUi.push(msg3);
481481

482+
AudioToUIMsg msg4{AudioToUIMsg::MTS_POINTER, 0, 0, 0, nullptr,
483+
monoValues.mtsClient};
484+
audioToUi.push(msg4);
485+
482486
lastVuUpdate = 0;
483487
}
484488
else

src/synth/synth.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ struct Synth
425425

426426
SEND_SAMPLE_RATE,
427427
SET_DAW_EXTRA_STATE,
428-
SET_MACRO_NAME // paramId = macro index, patchNamePointer = name buffer
428+
SET_MACRO_NAME, // paramId = macro index, patchNamePointer = name buffer
429+
MTS_POINTER // dawExtraStatePointer = MTSClient* (or nullptr)
429430
} action;
430431
uint32_t paramId{0};
431432
float value{0}, value2{0};

src/ui/playmode-sub-panel.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "playmode-sub-panel.h"
1717
#include <sst/jucegui/layouts/ListLayout.h>
18+
#include "libMTSClient.h"
1819

1920
namespace baconpaul::six_sines::ui
2021
{
@@ -175,6 +176,15 @@ PlayModeSubPanel::PlayModeSubPanel(SixSinesEditor &e) : HasEditor(e)
175176
};
176177
addAndMakeVisible(*voiceLimit);
177178

179+
mtsTitle = std::make_unique<jcmp::RuledLabel>();
180+
mtsTitle->setText("MTS");
181+
addAndMakeVisible(*mtsTitle);
182+
mtsStatusLabel = std::make_unique<jcmp::Label>();
183+
mtsStatusLabel->setText("No MTS");
184+
mtsStatusLabel->setJustification(juce::Justification::centred);
185+
mtsStatusLabel->setEnabled(false);
186+
addAndMakeVisible(*mtsStatusLabel);
187+
178188
panicTitle = std::make_unique<jcmp::RuledLabel>();
179189
panicTitle->setText("Panic");
180190
panicButton = std::make_unique<jcmp::TextPushButton>();
@@ -280,6 +290,8 @@ void PlayModeSubPanel::resized()
280290
col4.add(jlo::Component(*mpeActiveButton).withHeight(uicLabelHeight));
281291
col4.add(jlo::Component(*mpeRange).withHeight(uicLabelHeight));
282292
col4.add(jlo::Component(*mpeRangeL).withHeight(uicLabelHeight));
293+
col4.add(titleLabelGaplessLayout(mtsTitle));
294+
col4.add(jlo::Component(*mtsStatusLabel).withHeight(uicLabelHeight));
283295
col4.add(titleLabelGaplessLayout(panicTitle));
284296
col4.add(jlo::Component(*panicButton).withHeight(uicLabelHeight));
285297
topRow.add(col4);
@@ -494,4 +506,31 @@ void PlayModeSubPanel::setPolyLimit(int plVal)
494506
voiceLimit->repaint();
495507
}
496508

509+
void PlayModeSubPanel::updateMTSStatus()
510+
{
511+
if (++mtsIdleCount < 50)
512+
return;
513+
mtsIdleCount = 0;
514+
515+
auto *cli = editor.mtsClient;
516+
bool connected = cli && MTS_HasMaster(cli);
517+
std::string text;
518+
if (connected)
519+
{
520+
const char *name = MTS_GetScaleName(cli);
521+
text = (name && *name) ? std::string(name) : std::string("Connected");
522+
}
523+
else
524+
{
525+
text = "No MTS";
526+
}
527+
528+
if (connected != mtsConnected || text != mtsStatusLabel->getText())
529+
{
530+
mtsConnected = connected;
531+
mtsStatusLabel->setEnabled(connected);
532+
mtsStatusLabel->setText(text);
533+
}
534+
}
535+
497536
} // namespace baconpaul::six_sines::ui

src/ui/playmode-sub-panel.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ struct PlayModeSubPanel : juce::Component, HasEditor
3737
std::unique_ptr<jcmp::MultiSwitch> playMode;
3838
std::unique_ptr<PatchDiscrete> playModeD;
3939

40-
std::unique_ptr<jcmp::RuledLabel> bendTitle, uniTitle, mpeTitle, tsposeTitle, panicTitle;
40+
std::unique_ptr<jcmp::RuledLabel> bendTitle, uniTitle, mpeTitle, tsposeTitle, panicTitle,
41+
mtsTitle;
42+
std::unique_ptr<jcmp::Label> mtsStatusLabel;
43+
int mtsIdleCount{0};
44+
bool mtsConnected{false};
45+
void updateMTSStatus();
4146

4247
std::unique_ptr<jcmp::Label> bUpL, bDnL;
4348
std::unique_ptr<PatchContinuous> bUpD, bDnD;

src/ui/six-sines-editor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,19 @@ void SixSinesEditor::idle()
392392
{
393393
settingsPanel->setCpuUsage(aum->value);
394394
}
395+
else if (aum->action == Synth::AudioToUIMsg::MTS_POINTER)
396+
{
397+
mtsClient = static_cast<MTSClient *>(const_cast<void *>(aum->dawExtraStatePointer));
398+
}
395399
else
396400
{
397401
SXSNLOG("Ignored patch message " << aum->action);
398402
}
399403
aum = audioToUI.pop();
400404
}
405+
406+
if (playModeSubPanel)
407+
playModeSubPanel->updateMTSStatus();
401408
}
402409

403410
void SixSinesEditor::paint(juce::Graphics &g)

src/ui/six-sines-editor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ struct SixSinesEditor : jcmp::WindowPanel, sst::jucegui::screens::ScreenHolder<S
244244

245245
std::unique_ptr<jcmp::VUMeter> vuMeter;
246246

247+
// Latest MTSClient pointer reported by the audio thread via MTS_POINTER messages.
248+
// Read on the UI thread only; queried by PlayModeSubPanel for connection status.
249+
struct MTSClient *mtsClient{nullptr};
250+
247251
// To turn this on, recompile with it on in six-sines-editor.cpp
248252
void visibilityChanged() override;
249253
void parentHierarchyChanged() override;

0 commit comments

Comments
 (0)