Skip to content

Commit

Permalink
Fix category next with nested folders (#534)
Browse files Browse the repository at this point in the history
Nested folders meant parents existed which were valid categories
with no patches. Navigating to them with category +/- gave a very
counterintuitive result of not doing anything when you
arrived at them.  Fix that by accumulating the number of patches
in each category and only doing incrementCategory into a category
with patches.

Closes #533
  • Loading branch information
baconpaul authored Feb 8, 2019
1 parent b80c795 commit c81f446
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void SurgeStorage::refreshPatchlistAddDir(bool userDir, string subdir)
{
PatchCategory c;
c.name = p.generic_string().substr(patchpathSubstrLength);
local_patch_category.push_back(c);
c.numberOfPatchesInCatgory = 0;

for (auto& f : fs::directory_iterator(p))
{
Expand All @@ -354,9 +354,12 @@ void SurgeStorage::refreshPatchlistAddDir(bool userDir, string subdir)
e.name = f.path().filename().generic_string();
e.name = e.name.substr(0, e.name.size() - 4);
patch_list.push_back(e);

c.numberOfPatchesInCatgory ++;
}
}

local_patch_category.push_back(c);
category++;
}

Expand Down
2 changes: 2 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ struct PatchCategory
int order;
std::vector<PatchCategory> children;
bool isRoot;

int numberOfPatchesInCatgory;
};

enum sub3_copysource
Expand Down
18 changes: 12 additions & 6 deletions src/common/SurgeSynthesizerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ void SurgeSynthesizer::incrementCategory(bool nextPrev)
else
{
int order = storage.patch_category[current_category_id].order;
if (nextPrev)
order = (order >= (n - 1)) ? 0 : order + 1;
else
order = (order <= 0) ? n - 1 : order - 1;

current_category_id = storage.patchCategoryOrdering[order];
int orderOrig = order;
do
{
if (nextPrev)
order = (order >= (n - 1)) ? 0 : order + 1;
else
order = (order <= 0) ? n - 1 : order - 1;

current_category_id = storage.patchCategoryOrdering[order];
}
while (storage.patch_category[current_category_id].numberOfPatchesInCatgory == 0 && order != orderOrig);
// That order != orderOrig isn't needed unless we have an entire empty category tree, in which case it stops an inf loop
}

// Find the first patch within the category.
Expand Down

0 comments on commit c81f446

Please sign in to comment.