Skip to content

Commit

Permalink
Merge pull request surge-synthesizer#323 from baconpaul/init-range-cr…
Browse files Browse the repository at this point in the history
…ash-319

Handle out-of-range Patch.order

Former-commit-id: df357958b49579768463270518cb2b479217563a [formerly cb73cff]
Former-commit-id: 649c1a9f14b0300af5ec32a6fa6cea1cfaa8e59d
Former-commit-id: c5058b9209709ffe404d32431c3e4ecb4d801e19
  • Loading branch information
baconpaul authored Jan 17, 2019
2 parents bccace6 + 316a0ac commit e90eacc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 34 deletions.
22 changes: 15 additions & 7 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,22 @@ int SurgeStorage::getAdjacentWaveTable(int id, bool nextPrev)
if (!n)
return -1;

int order = wt_list[id].order;

if (nextPrev)
order = (order == (n - 1)) ? 0 : order + 1;
// See comment in SurgeSynthesizerIO::incrementPatch and #319
if( id < 0 || id > n-1 )
{
return wtOrdering[0];
}
else
order = (order == 0) ? n - 1 : order - 1;

return wtOrdering[order];
{
int order = wt_list[id].order;

if (nextPrev)
order = (order >= (n - 1)) ? 0 : order + 1; // see comment in incrementPatch for that >= vs ==
else
order = (order <= 0) ? n - 1 : order - 1;

return wtOrdering[order];
}
}

void SurgeStorage::clipboard_copy(int type, int scene, int entry)
Expand Down
86 changes: 59 additions & 27 deletions src/common/SurgeSynthesizerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,46 @@ void SurgeSynthesizer::incrementPatch(bool nextPrev)
if (!n)
return;

int order = storage.patch_list[patchid].order;
int category = storage.patch_list[patchid].category;

if (nextPrev) {
do {
order = (order == (n - 1)) ? 0 : order + 1;
} while (storage.patch_list[storage.patchOrdering[order]].category !=
category);
} else {
do {
order = (order == 0) ? n - 1 : order - 1;
} while (storage.patch_list[storage.patchOrdering[order]].category !=
category);
/*
** Ideally we would never call this with an out
** of range patchid, but the init case where we
** have a non-loaded in memory patch proves that
** false, as may some other cases. So add this
** defensive approach. See #319
*/
if( patchid < 0 || patchid > n-1 )
{
// Find patch 0 category 0 and select it
int ccid = storage.patchCategoryOrdering[0];

int target = n+1;
for(auto &patch : storage.patch_list)
{
if(patch.category == ccid && patch.order < target)
target = patch.order;
}

patchid_queue = storage.patchOrdering[target];
current_category_id = ccid;
}
else
{
int order = storage.patch_list[patchid].order;
int category = storage.patch_list[patchid].category;

if (nextPrev) {
do {
order = (order >= (n - 1)) ? 0 : order + 1;
} while (storage.patch_list[storage.patchOrdering[order]].category !=
category);
} else {
do {
order = (order <= 0) ? n - 1 : order - 1;
} while (storage.patch_list[storage.patchOrdering[order]].category !=
category);
}
patchid_queue = storage.patchOrdering[order];
}

patchid_queue = storage.patchOrdering[order];
processThreadunsafeOperations();
return;
}
Expand All @@ -75,22 +99,30 @@ void SurgeSynthesizer::incrementCategory(bool nextPrev)
if (!n)
return;

int order = storage.patch_category[current_category_id].order;
if (nextPrev)
order = (order == (n - 1)) ? 0 : order + 1;
// See comment above and #319
if(current_category_id < 0 || current_category_id > n-1 )
{
current_category_id = storage.patchCategoryOrdering[0];
}
else
order = (order == 0) ? n - 1 : order - 1;

current_category_id = storage.patchCategoryOrdering[order];

{
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];
}

// Find the first patch within the category.
for (auto p : storage.patchOrdering)
{
if (storage.patch_list[p].category == current_category_id)
{
patchid_queue = p;
processThreadunsafeOperations();
return;
if (storage.patch_list[p].category == current_category_id)
{
patchid_queue = p;
processThreadunsafeOperations();
return;
}
}
}
Expand Down

0 comments on commit e90eacc

Please sign in to comment.