Browse Source

Remove favorites from settings and favorite scoring in Module Browser.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
93a2a480f6
3 changed files with 1 additions and 61 deletions
  1. +0
    -2
      include/settings.hpp
  2. +1
    -17
      src/app/ModuleBrowser.cpp
  3. +0
    -42
      src/settings.cpp

+ 0
- 2
include/settings.hpp View File

@@ -39,8 +39,6 @@ extern bool frameRateSync;
extern float autosavePeriod;
extern bool skipLoadOnLaunch;
extern std::string patchPath;
// (plugin, model) -> score
extern std::map<std::tuple<std::string, std::string>, float> favoriteScores;
extern std::vector<NVGcolor> cableColors;

json_t *toJson();


+ 1
- 17
src/app/ModuleBrowser.cpp View File

@@ -81,16 +81,6 @@ static bool isModelVisible(plugin::Model *model, const std::string &search, cons
return true;
}

static void stepFavoriteScore(const std::string &plugin, const std::string &model) {
// Decay all scores
const float decayLambda = 0.1;
for (auto &it : settings::favoriteScores) {
it.second *= 1 - decayLambda;
}
// Increment favorite score by 1
settings::favoriteScores[std::make_tuple(plugin, model)] += 1;
}

static ModuleWidget *chooseModel(plugin::Model *model) {
// Create module
ModuleWidget *moduleWidget = model->createModuleWidget();
@@ -103,9 +93,6 @@ static ModuleWidget *chooseModel(plugin::Model *model) {
h->setModule(moduleWidget);
APP->history->push(h);

// Step favorite
stepFavoriteScore(model->plugin->slug, model->slug);

// Hide Module Browser
APP->scene->moduleBrowser->hide();

@@ -506,13 +493,10 @@ struct ModuleBrowser : widget::OpaqueWidget {
}

// Sort ModelBoxes
// Sort by favorite score and then name
modelContainer->children.sort([&](Widget *w1, Widget *w2) {
ModelBox *m1 = dynamic_cast<ModelBox*>(w1);
ModelBox *m2 = dynamic_cast<ModelBox*>(w2);
// Sort by favorite score if either is available
// float score1 = get_default(settings::favoriteScores, std::make_tuple(m1->model->plugin->slug, m1->model->slug), 0.f);
// float score2 = get_default(settings::favoriteScores, std::make_tuple(m2->model->plugin->slug, m2->model->slug), 0.f);
// Sort by (modifiedTimestamp descending, plugin brand, model name)
auto t1 = std::make_tuple(-m1->model->plugin->modifiedTimestamp, m1->model->plugin->brand, m1->model->name);
auto t2 = std::make_tuple(-m2->model->plugin->modifiedTimestamp, m2->model->plugin->brand, m2->model->name);
return t1 < t2;


+ 0
- 42
src/settings.cpp View File

@@ -34,7 +34,6 @@ bool frameRateSync = true;
float autosavePeriod = 15.0;
bool skipLoadOnLaunch = false;
std::string patchPath;
std::map<std::tuple<std::string, std::string>, float> favoriteScores;
std::vector<NVGcolor> cableColors = {
nvgRGB(0xc9, 0xb7, 0x0e), // yellow
nvgRGB(0x0c, 0x8e, 0x15), // green
@@ -88,19 +87,6 @@ json_t *toJson() {

json_object_set_new(rootJ, "patchPath", json_string(patchPath.c_str()));

json_t *favoriteModelsJ = json_array();
for (auto &pair : favoriteScores) {
const std::string &plugin = std::get<0>(pair.first);
const std::string &model = std::get<1>(pair.first);
float score = pair.second;
json_t *favoriteJ = json_object();
json_object_set_new(favoriteJ, "plugin", json_string(plugin.c_str()));
json_object_set_new(favoriteJ, "model", json_string(model.c_str()));
json_object_set_new(favoriteJ, "score", json_real(score));
json_array_append_new(favoriteModelsJ, favoriteJ);
}
json_object_set_new(rootJ, "favoriteModels", favoriteModelsJ);

json_t *cableColorsJ = json_array();
for (NVGcolor cableColor : cableColors) {
std::string colorStr = color::toHexString(cableColor);
@@ -194,34 +180,6 @@ void fromJson(json_t *rootJ) {
if (patchPathJ)
patchPath = json_string_value(patchPathJ);

json_t *favoriteModelsJ = json_object_get(rootJ, "favoriteModels");
// Legacy: "favorites" was defined under "moduleBrowser" until 1.0.
if (!favoriteModelsJ) {
json_t *moduleBrowserJ = json_object_get(rootJ, "moduleBrowser");
if (moduleBrowserJ)
favoriteModelsJ = json_object_get(rootJ, "favorites");
}
if (favoriteModelsJ) {
favoriteScores.clear();
size_t i;
json_t *favoriteJ;
json_array_foreach(favoriteModelsJ, i, favoriteJ) {
json_t *pluginJ = json_object_get(favoriteJ, "plugin");
json_t *modelJ = json_object_get(favoriteJ, "model");
if (!pluginJ || !modelJ)
continue;
std::string plugin = json_string_value(pluginJ);
std::string model = json_string_value(modelJ);
// Set default score when migrating favorites from v0.6
float score = 1.f;
json_t *scoreJ = json_object_get(favoriteJ, "score");
if (scoreJ)
score = json_number_value(scoreJ);

favoriteScores[std::make_tuple(plugin, model)] = score;
}
}

json_t *cableColorsJ = json_object_get(rootJ, "cableColors");
if (cableColorsJ) {
cableColors.clear();


Loading…
Cancel
Save