Browse Source

Cache deviceId in MidiDeviceChoice::step() to avoid redundant calls to getDeviceName()

pull/1647/head
rhrhunter 5 years ago
parent
commit
9fa2b155ac
1 changed files with 7 additions and 0 deletions
  1. +7
    -0
      src/app/MidiWidget.cpp

+ 7
- 0
src/app/MidiWidget.cpp View File

@@ -53,6 +53,7 @@ struct MidiDeviceItem : ui::MenuItem {


struct MidiDeviceChoice : LedDisplayChoice { struct MidiDeviceChoice : LedDisplayChoice {
midi::Port* port; midi::Port* port;
int chosenDeviceId;
void onAction(const event::Action& e) override { void onAction(const event::Action& e) override {
if (!port) if (!port)
return; return;
@@ -77,12 +78,18 @@ struct MidiDeviceChoice : LedDisplayChoice {
} }
} }
void step() override { void step() override {
// cache the device name until the deviceId changes.
if (!text.empty() && port && chosenDeviceId == port->deviceId)
return;

text = port ? port->getDeviceName(port->deviceId) : ""; text = port ? port->getDeviceName(port->deviceId) : "";
if (text.empty()) { if (text.empty()) {
text = "(No device)"; text = "(No device)";
chosenDeviceId = NULL;
color.a = 0.5f; color.a = 0.5f;
} }
else { else {
chosenDeviceId = port->deviceId;
color.a = 1.f; color.a = 1.f;
} }
} }


Loading…
Cancel
Save