Browse Source

Add string::ellipsizePrefix. Use kHz instead of Hz for sample rate displays.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
3b70a5697f
5 changed files with 19 additions and 6 deletions
  1. +1
    -0
      include/string.hpp
  2. +2
    -2
      src/app/AudioWidget.cpp
  3. +5
    -1
      src/app/ModuleWidget.cpp
  4. +4
    -3
      src/app/Toolbar.cpp
  5. +7
    -0
      src/string.cpp

+ 1
- 0
include/string.hpp View File

@@ -24,6 +24,7 @@ std::string uppercase(const std::string &s);
std::string trim(const std::string &s);
/** Truncates and adds "..." to a string, not exceeding `len` characters */
std::string ellipsize(const std::string &s, size_t len);
std::string ellipsizePrefix(const std::string &s, size_t len);
bool startsWith(const std::string &str, const std::string &prefix);
bool endsWith(const std::string &str, const std::string &suffix);
/** Extracts portions of a path */


+ 2
- 2
src/app/AudioWidget.cpp View File

@@ -124,14 +124,14 @@ struct AudioSampleRateChoice : LedDisplayChoice {
AudioSampleRateItem *item = new AudioSampleRateItem;
item->port = port;
item->sampleRate = sampleRate;
item->text = string::f("%d Hz", sampleRate);
item->text = string::f("%g kHz", sampleRate / 1000.0);
item->rightText = CHECKMARK(item->sampleRate == port->sampleRate);
menu->addChild(item);
}
}
void step() override {
if (port)
text = string::f("%g kHz", port->sampleRate / 1000.f);
text = string::f("%g kHz", port->sampleRate / 1000.0);
else
text = "44.1 kHz";
}


+ 5
- 1
src/app/ModuleWidget.cpp View File

@@ -44,6 +44,10 @@ struct ModulePluginItem : ui::MenuItem {
ui::Menu *createChildMenu() override {
ui::Menu *menu = new ui::Menu;

ui::MenuLabel *pluginLabel = new ui::MenuLabel;
pluginLabel->text = plugin->name;
menu->addChild(pluginLabel);

ui::MenuLabel *versionLabel = new ui::MenuLabel;
versionLabel->text = "v" + plugin->version;
menu->addChild(versionLabel);
@@ -774,7 +778,7 @@ void ModuleWidget::createContextMenu() {
menu->addChild(modelLabel);

ModulePluginItem *pluginItem = new ModulePluginItem;
pluginItem->text = model->plugin->name;
pluginItem->text = "Plugin";
pluginItem->rightText = RIGHT_ARROW;
pluginItem->plugin = model->plugin;
menu->addChild(pluginItem);


+ 4
- 3
src/app/Toolbar.cpp View File

@@ -300,10 +300,11 @@ struct SampleRateItem : ui::MenuItem {

SampleRateValueItem *item = new SampleRateValueItem;
item->sampleRate = sampleRate;
item->text = string::f("%.0f Hz", sampleRate);
item->text = string::f("%g kHz", sampleRate / 1000.0);
if (oversample > 1)
item->text += string::f(" (%dx)", oversample);
item->rightText = CHECKMARK(APP->engine->getSampleRate() == sampleRate);
item->rightText += string::f("(%dx)", oversample);
item->rightText += " ";
item->rightText += CHECKMARK(APP->engine->getSampleRate() == sampleRate);
menu->addChild(item);
}
}


+ 7
- 0
src/string.cpp View File

@@ -67,6 +67,13 @@ std::string ellipsize(const std::string &s, size_t len) {
return s.substr(0, len - 3) + "...";
}

std::string ellipsizePrefix(const std::string &s, size_t len) {
if (s.size() <= len)
return s;
else
return "..." + s.substr(s.size() - (len - 3));
}

bool startsWith(const std::string &str, const std::string &prefix) {
return str.substr(0, prefix.size()) == prefix;
}


Loading…
Cancel
Save