Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: fix sorting of patches in submenus to be A->Z? #183

Closed
esaruoho opened this issue Dec 29, 2018 · 37 comments
Closed

Suggestion: fix sorting of patches in submenus to be A->Z? #183

esaruoho opened this issue Dec 29, 2018 · 37 comments
Labels
Feature Request New feature request
Milestone

Comments

@esaruoho
Copy link
Collaborator

the patch loading submenus are not A-to-Z, instead whatever goes wherever. Surely something like that could be fixed, or what do you think @inigokennedy ?

fullscreen_29_12_2018__12_56

@baconpaul
Copy link
Collaborator

They are just in whatever order readdir returns. A sort is a good idea and easy enough.

@baconpaul
Copy link
Collaborator

@jsakkine you were looking for a way to get into the ui. This one is pretty easy. There’s a vector ctge assembled in CPatchBrowser.cpp in the onmousedown. Apply the right flavor of std::sort to it before the subgroup iteration and this should be fixed.

@baconpaul
Copy link
Collaborator

Or I can do it in the new year. But just thought this may be an easier approach to Mac dev and test than the other harder one with parameter invalidation

@baconpaul
Copy link
Collaborator

Also looking at that screenshot we may want to adjust the split to submenu threshold

@baconpaul
Copy link
Collaborator

Oh and don’t forget to remap indices. Alternately you could sort the entire structure when it is loaded in surgestorage. That way you can sort categories too. But then you need to adjust when you save one as a user. Not sure which I would do - would want to stare at code a minute more

@jarkkojs
Copy link
Collaborator

jarkkojs commented Dec 31, 2018

Working on this now. Yeah, sorry had a busy weekend. Promised a bit too much when it comes to time. Nothing particularly hard in parameter validation. It is just that for yet unknown reason I cannot access any of the Surge's parameters from Ableton.

@jarkkojs
Copy link
Collaborator

jarkkojs commented Dec 31, 2018

Ugh, did not understand how deep in the code category array indexes are used as global identifiers, so yeah, doing something simpler while still trying to also clean up thinks just a bit.

@jarkkojs
Copy link
Collaborator

jarkkojs commented Dec 31, 2018

PR done. Next time I will do something to this will be after NYE.

@baconpaul baconpaul added the Feature Request New feature request label Jan 3, 2019
@baconpaul baconpaul added this to the 1.6 milestone Jan 3, 2019
@baconpaul
Copy link
Collaborator

https://github.com/kurasu/surge/pull/187#issuecomment-451442633 let me just link that here since it contains a design idea we should probably have over here on the issue rather than the PR.

baconpaul added a commit that referenced this issue Jan 4, 2019
#183 ("Suggestion: fix sorting of patches in submenus to be A->Z?")
@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 5, 2019

Thanks for linking that! Just starting work on this.

@esaruoho
Copy link
Collaborator Author

esaruoho commented Jan 5, 2019

fingers crossed!

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 5, 2019

@baconpaul, just detailing a bit #183 to check that I've not missed something.

To the class SurgeStorage we add:

std::vector<int> categoryOrdering;
std::vector<int> patchOrdering;

I think these are more descriptive names than patch_traversal_map.

These must be generated in the tail of SurgeStorage::refresh_patchlist() . Is it too intrusive to rename this function as refreshPatchList()?

For categories the correct index is mapped here in CPatchBrowser::onMouseDown():

   for (int c = 0; c < storage->patch_category.size(); c++)
   {
      int c2 = storage->categoryOrdering[c];

For patches the index is mapped in this sub-loop of the former:

         for (int p = 0; p < storage->patch_list.size(); p++)
         {
            int p2 = storage->patchOrdering[p];
            if (storage->patch_list[p2].category == c)
            {
               ctge.push_back(p2);
            }
         }

I think these changes should guarantee that:

  1. Orderings are re-generated whatever situation patches are updated.
  2. Orderings are accounted whenever the menu is built.

I though to check the design before sending PRs.

@baconpaul
Copy link
Collaborator

Your name is better than patch_traversal_map tho

I would not rename refresh_patchlist at this point, since it will make the textual diff bigger than the semantic diff

I would probably not use p and p2; rather I’d use names like “patchIndex” and “patchSortedIndex”

Also it’s weird to iterate over patch list size and then get from patch ordering. Why wouldn’’t

for (int p = 0; p < storage->patch_list.size(); p++)
         {
            int p2 = storage->patchOrdering[p];

Just be

  For ( auto p : storage->patchOrdering )

Instead?

But looks like the right path!

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 5, 2019

OK, cool.

Then what about splitting a category into multiple submenus? I remember that from earlier review. That'd probably be anyway a commit of its own so I'll go ahead and write the first patch.

@baconpaul
Copy link
Collaborator

There’s code there that does that already. I just think the constant is set wrong. But yeah two steps is fine.

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

Is this how it should look like (sort-patch-list branch in my GIT):

image

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

I've chosen to prefix everything with std:: because generally it is considered an anti-pattern to import a whole namespace in a header file (e.g. globals.h). And using it actually makes the code more readable than not using it (short prefix and functions like std::iota() would look cryptic without that prefix).

@baconpaul
Copy link
Collaborator

That looks great!

Wonder if you should apply the same to wavetables while you are in there?

And yeah I use std:: everywhere and also looked sideways a little at the use namespace std in globals.h. Fine with me.

@baconpaul
Copy link
Collaborator

Oh and you are case insensitive sorting right? Polysynth has all sorts of case conventions on the patches.

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

I can show my lambda for patches:

   auto patchCompare =
      [this](const int &i1, const int &i2) -> bool
      {
         return _stricmp(patch_list[i1].name.c_str(),
                         patch_list[i2].name.c_str()) < 0;
      };

similar for categories.

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

And yes, I can do the same for WT's.

@baconpaul
Copy link
Collaborator

Oh and in your tests, perhaps save a patch and see if it pops up in the right place. And also remember to save a patch with a factory category name (which now works; and should give you that category both in the first section and third section).

Thanks for doing this!

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

Tried that now without my commit applied (i.e. master branch) with the latest changes from mainline. I saved a patch named as Jarkko's Test with the category Pad.

The result is that I can see the patch in a Pad category in user patches group but I cannot see it in factory patches group. Are you sure that this should work?

@baconpaul
Copy link
Collaborator

I just tried with my master and yes I see Pad in both places.

Xcode cleans "poorly". Generally when I switch branches I do a ./build-osx.sh --clean-all. Maybe you had a remnant of your branch in your build assets? But it is definitely the case that user patch categories matching factory patch categories show up twice.

screen shot 2019-01-06 at 8 41 43 am

@baconpaul
Copy link
Collaborator

Without looking at your code, maybe what's happening is since you sort on name, two categories with the same name are ambiguous. Perhaps patch_category needs an id which gets incremented when created and you check if that's distinct.

And your patch sort lambda - does that need to compare categories before names? Or do you apply that sort on a per-category basis?

Again just thinking out loud.

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

OK, I might gotten this wrong what you said earlier. I see the Pad category twice exactly as in your screenshot with and without my commit. But I cannot find Jarkko's Test in both
Pad-menus. Nothing to do with my commit per se.

@baconpaul
Copy link
Collaborator

Oh that’s right. It will only appear in user
If you take a factory preset and store it without changing name same category same name should appear twice

If you rename it the new one only appears once

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

OK, then it works as expected and my commit does not break anything :) I'll do the WT-part and send a PR.

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

Proof:

image

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

And this:

image

I'll prepare a PR now.

@baconpaul
Copy link
Collaborator

Yay great! I’m out and about today but I will look at the pr in detail either tonight nyc time or tomorrow morning. Thank you

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

@esaruoho, do you have capacity to test the PR at some point?

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

@baconpaul, sure no worries!

@esaruoho
Copy link
Collaborator Author

esaruoho commented Jan 6, 2019

@jsakkine yeah just hook me up with how i get the code from your repo.

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 6, 2019

@esaruoho, I guess you can ack this now?

@esaruoho
Copy link
Collaborator Author

esaruoho commented Jan 6, 2019

I tried it and on the surface everything looks fine. I have not saved a patch tho cos feel like that is a way huger thing to bugshoot

@baconpaul
Copy link
Collaborator

Thanks @jsakkine - all great stuff! I just merged it. Closing this issue.

baconpaul added a commit to baconpaul/surge that referenced this issue Jul 10, 2019
surge-synthesizer#183 ("Suggestion: fix sorting of patches in submenus to be A->Z?")

Former-commit-id: ffff327
Former-commit-id: b8c629458958c509a0bae923e9a2eb26ec772646
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature request
Projects
None yet
Development

No branches or pull requests

3 participants