Keyswitch name display

This commit is contained in:
Jean Pierre Cimalando 2021-02-25 10:09:22 +01:00
parent 49fa746286
commit a39e1f8e2e
3 changed files with 69 additions and 5 deletions

View file

@ -60,9 +60,9 @@ widget_class mainView {open
xywh {195 11 250 31} labelsize 20 align 20 xywh {195 11 250 31} labelsize 20 align 20
class ClickableLabel class ClickableLabel
} }
Fl_Box {} { Fl_Box keyswitchLabel_ {
label {Key switch:} label {Key switch:} selected
xywh {195 44 250 30} labelsize 20 align 20 xywh {195 44 360 30} labelsize 20 align 20
class Label class Label
} }
Fl_Box {} { Fl_Box {} {
@ -221,7 +221,7 @@ widget_class mainView {open
class LogicalGroup class LogicalGroup
} { } {
Fl_Group {} { Fl_Group {} {
label Engine open selected label Engine open
xywh {305 135 195 100} box ROUNDED_BOX labelsize 12 align 17 xywh {305 135 195 100} box ROUNDED_BOX labelsize 12 align 17
class TitleGroup class TitleGroup
} { } {

View file

@ -20,6 +20,7 @@
#include <ghc/fs_std.hpp> #include <ghc/fs_std.hpp>
#include <array> #include <array>
#include <queue> #include <queue>
#include <unordered_map>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <type_traits> #include <type_traits>
@ -49,6 +50,10 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
std::string userFilesDir_; std::string userFilesDir_;
std::string fallbackFilesDir_; std::string fallbackFilesDir_;
int currentKeyswitch_ = -1;
std::unordered_map<unsigned, std::string> keyswitchNames_;
std::string keyswitchLabelPrefix_;
SharedPointer<CVSTGUITimer> memQueryTimer_; SharedPointer<CVSTGUITimer> memQueryTimer_;
enum { enum {
@ -102,6 +107,7 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
CTextLabel* tuningFrequencyLabel_ = nullptr; CTextLabel* tuningFrequencyLabel_ = nullptr;
CControl *stretchedTuningSlider_ = nullptr; CControl *stretchedTuningSlider_ = nullptr;
CTextLabel* stretchedTuningLabel_ = nullptr; CTextLabel* stretchedTuningLabel_ = nullptr;
CTextLabel* keyswitchLabel_ = nullptr;
STitleContainer* userFilesGroup_ = nullptr; STitleContainer* userFilesGroup_ = nullptr;
STextButton* userFilesDirButton_ = nullptr; STextButton* userFilesDirButton_ = nullptr;
@ -170,12 +176,17 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
void updateTuningFrequencyLabel(float tuningFrequency); void updateTuningFrequencyLabel(float tuningFrequency);
void updateStretchedTuningLabel(float stretchedTuning); void updateStretchedTuningLabel(float stretchedTuning);
absl::string_view getCurrentKeyswitchName() const;
void updateKeyswitchNameLabel();
void updateKeyUsed(unsigned key, bool used); void updateKeyUsed(unsigned key, bool used);
void updateKeyswitchUsed(unsigned key, bool used); void updateKeyswitchUsed(unsigned key, bool used);
void updateCCUsed(unsigned cc, bool used); void updateCCUsed(unsigned cc, bool used);
void updateCCValue(unsigned cc, float value); void updateCCValue(unsigned cc, float value);
void updateCCDefaultValue(unsigned cc, float value); void updateCCDefaultValue(unsigned cc, float value);
void updateCCLabel(unsigned cc, const char* label); void updateCCLabel(unsigned cc, const char* label);
void updateSWLastCurrent(int sw);
void updateSWLastLabel(unsigned sw, const char* label);
void updateMemoryUsed(uint64_t mem); void updateMemoryUsed(uint64_t mem);
// edition of CC by UI // edition of CC by UI
@ -436,7 +447,13 @@ void Editor::Impl::uiReceiveMessage(const char* path, const char* sig, const sfi
for (unsigned key = 0; key < 128; ++key) { for (unsigned key = 0; key < 128; ++key) {
bool used = key < numBits && bits.test(key); bool used = key < numBits && bits.test(key);
updateKeyswitchUsed(key, used); updateKeyswitchUsed(key, used);
if (used) {
char pathBuf[256];
sprintf(pathBuf, "/sw/last/%u/label", key);
sendQueuedOSC(pathBuf, "", nullptr);
}
} }
sendQueuedOSC("/sw/last/current", "", nullptr);
} }
else if (Messages::matchOSC("/cc/slots", path, indices) && !strcmp(sig, "b")) { else if (Messages::matchOSC("/cc/slots", path, indices) && !strcmp(sig, "b")) {
size_t numBits = 8 * args[0].b->size; size_t numBits = 8 * args[0].b->size;
@ -476,6 +493,12 @@ void Editor::Impl::uiReceiveMessage(const char* path, const char* sig, const sfi
else if (Messages::matchOSC("/cc&/label", path, indices) && !strcmp(sig, "s")) { else if (Messages::matchOSC("/cc&/label", path, indices) && !strcmp(sig, "s")) {
updateCCLabel(indices[0], args[0].s); updateCCLabel(indices[0], args[0].s);
} }
else if (Messages::matchOSC("/sw/last/current", path, indices) && !strcmp(sig, "i")) {
updateSWLastCurrent(args[0].i);
}
else if (Messages::matchOSC("/sw/last/&/label", path, indices) && !strcmp(sig, "s")) {
updateSWLastLabel(indices[0], args[0].s);
}
else if (Messages::matchOSC("/mem/buffers", path, indices) && !strcmp(sig, "h")) { else if (Messages::matchOSC("/mem/buffers", path, indices) && !strcmp(sig, "h")) {
updateMemoryUsed(args[0].h); updateMemoryUsed(args[0].h);
} }
@ -808,6 +831,10 @@ void Editor::Impl::createFrameContents()
mainView_ = owned(mainView); mainView_ = owned(mainView);
} }
///
if (keyswitchLabel_)
keyswitchLabelPrefix_ = std::string(keyswitchLabel_->getText()) + ' ';
/// ///
SharedPointer<SFileDropTarget> fileDropTarget = owned(new SFileDropTarget); SharedPointer<SFileDropTarget> fileDropTarget = owned(new SFileDropTarget);
@ -1347,6 +1374,27 @@ void Editor::Impl::updateStretchedTuningLabel(float stretchedTuning)
label->setText(text); label->setText(text);
} }
absl::string_view Editor::Impl::getCurrentKeyswitchName() const
{
int sw = currentKeyswitch_;
if (sw == -1)
return {};
auto it = keyswitchNames_.find(static_cast<unsigned>(sw));
if (it == keyswitchNames_.end())
return {};
return it->second;
}
void Editor::Impl::updateKeyswitchNameLabel()
{
if (CTextLabel* label = keyswitchLabel_) {
std::string name { getCurrentKeyswitchName() };
label->setText((keyswitchLabelPrefix_ + name).c_str());
}
}
void Editor::Impl::updateKeyUsed(unsigned key, bool used) void Editor::Impl::updateKeyUsed(unsigned key, bool used)
{ {
if (SPiano* piano = piano_) if (SPiano* piano = piano_)
@ -1383,6 +1431,21 @@ void Editor::Impl::updateCCLabel(unsigned cc, const char* label)
panel->setControlLabelText(cc, label); panel->setControlLabelText(cc, label);
} }
void Editor::Impl::updateSWLastCurrent(int sw)
{
if (currentKeyswitch_ == sw)
return;
currentKeyswitch_ = sw;
updateKeyswitchNameLabel();
}
void Editor::Impl::updateSWLastLabel(unsigned sw, const char* label)
{
keyswitchNames_[sw].assign(label);
if ((unsigned)currentKeyswitch_ == sw)
updateKeyswitchNameLabel();
}
void Editor::Impl::updateMemoryUsed(uint64_t mem) void Editor::Impl::updateMemoryUsed(uint64_t mem)
{ {
if (CTextLabel* label = memoryLabel_) { if (CTextLabel* label = memoryLabel_) {

View file

@ -25,7 +25,8 @@ view__8->addView(view__10);
auto* const view__11 = createClickableLabel(CRect(10, 6, 260, 37), kTagLoadSfzFile, "DefaultInstrument.sfz", kLeftText, 20); auto* const view__11 = createClickableLabel(CRect(10, 6, 260, 37), kTagLoadSfzFile, "DefaultInstrument.sfz", kLeftText, 20);
sfzFileLabel_ = view__11; sfzFileLabel_ = view__11;
view__8->addView(view__11); view__8->addView(view__11);
auto* const view__12 = createLabel(CRect(10, 39, 260, 69), -1, "Key switch:", kLeftText, 20); auto* const view__12 = createLabel(CRect(10, 39, 370, 69), -1, "Key switch:", kLeftText, 20);
keyswitchLabel_ = view__12;
view__8->addView(view__12); view__8->addView(view__12);
auto* const view__13 = createLabel(CRect(10, 71, 70, 96), -1, "Voices:", kRightText, 12); auto* const view__13 = createLabel(CRect(10, 71, 70, 96), -1, "Voices:", kRightText, 12);
view__8->addView(view__13); view__8->addView(view__13);