Browse Source

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

tags/v1.0.0
Andrew Belt 6 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); std::string trim(const std::string &s);
/** Truncates and adds "..." to a string, not exceeding `len` characters */ /** Truncates and adds "..." to a string, not exceeding `len` characters */
std::string ellipsize(const std::string &s, size_t len); 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 startsWith(const std::string &str, const std::string &prefix);
bool endsWith(const std::string &str, const std::string &suffix); bool endsWith(const std::string &str, const std::string &suffix);
/** Extracts portions of a path */ /** Extracts portions of a path */


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

@@ -124,14 +124,14 @@ struct AudioSampleRateChoice : LedDisplayChoice {
AudioSampleRateItem *item = new AudioSampleRateItem; AudioSampleRateItem *item = new AudioSampleRateItem;
item->port = port; item->port = port;
item->sampleRate = sampleRate; 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); item->rightText = CHECKMARK(item->sampleRate == port->sampleRate);
menu->addChild(item); menu->addChild(item);
} }
} }
void step() override { void step() override {
if (port) if (port)
text = string::f("%g kHz", port->sampleRate / 1000.f);
text = string::f("%g kHz", port->sampleRate / 1000.0);
else else
text = "44.1 kHz"; 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 *createChildMenu() override {
ui::Menu *menu = new ui::Menu; 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; ui::MenuLabel *versionLabel = new ui::MenuLabel;
versionLabel->text = "v" + plugin->version; versionLabel->text = "v" + plugin->version;
menu->addChild(versionLabel); menu->addChild(versionLabel);
@@ -774,7 +778,7 @@ void ModuleWidget::createContextMenu() {
menu->addChild(modelLabel); menu->addChild(modelLabel);


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


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

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


SampleRateValueItem *item = new SampleRateValueItem; SampleRateValueItem *item = new SampleRateValueItem;
item->sampleRate = sampleRate; item->sampleRate = sampleRate;
item->text = string::f("%.0f Hz", sampleRate);
item->text = string::f("%g kHz", sampleRate / 1000.0);
if (oversample > 1) 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); 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) + "..."; 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) { bool startsWith(const std::string &str, const std::string &prefix) {
return str.substr(0, prefix.size()) == prefix; return str.substr(0, prefix.size()) == prefix;
} }


Loading…
Cancel
Save