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

Slightly improve our borked Program Change implementation #6987

Closed
mkruselj opened this issue Apr 23, 2023 · 7 comments
Closed

Slightly improve our borked Program Change implementation #6987

mkruselj opened this issue Apr 23, 2023 · 7 comments
Labels
Feature Request New feature request MIDI MIDI support related
Milestone

Comments

@mkruselj
Copy link
Collaborator

So the way it works currently it just goes from first factory patch if Program Change 0 is sent, onwards, alphabetically as sorted in the patch browser menu.

Let's change this so that it first searches for a user category called "MIDI Programs", if that is not found start from first user patch instead.

@mkruselj mkruselj added Feature Request New feature request MIDI MIDI support related labels Apr 23, 2023
@mkruselj mkruselj added this to the Surge XT 1.3 milestone Apr 23, 2023
@baconpaul
Copy link
Collaborator

void SurgeSynthesizer::programChange(char channel, int value)
{
    auto ignorePC = Surge::Storage::getUserDefaultValue(
        &(storage), Surge::Storage::IgnoreMIDIProgramChange, false);

    if (ignorePC)
        return;

    PCH = value;
    // load_patch((CC0<<7) + PCH);
    patchid_queue = (CC0 << 7) + PCH;
}

so I think you change this to

void SurgeSynthesizer::programChange(char channel, int value)
{
    auto ignorePC = Surge::Storage::getUserDefaultValue(
        &(storage), Surge::Storage::IgnoreMIDIProgramChange, false);

    if (ignorePC)
        return;

    PCH = value;
    // load_patch((CC0<<7) + PCH);
    auto nextPatch = (CC0 << 7) + PCH;
    // traverse here
}

that traversal is a bit painful but this is an infrequent operation

basically you travers categories in order starting at the first user vcategory
then you traverse all patches looking for that category
and if you find it increase a counter
when the counter hits the number, that's the id you want

ugh i will write this up more properly if you get stuck. look at the Patch Selector for the data structures

@mkruselj
Copy link
Collaborator Author

mkruselj commented Apr 23, 2023

Big brain thinking: shall we store a list of patches found in "MIDI Programs" folder in a list when we refresh patch browser instead? Cache it so then it's O(1)?

Then if folder not found just fill it with first 128 ordered patches to keep things O(1).

@baconpaul
Copy link
Collaborator

Who really cares about the order - this is an infrequent thing. But I like the idea of looking for a midi category

@mkruselj
Copy link
Collaborator Author

mkruselj commented Apr 23, 2023

Dunno I think caching is a good idea just to be on the safe side... Also, u-he does it too. Haha. 😛

Can never know if somebody creates a garbled mess of incoming MIDI. Or realtime editing a program change event in a host can be sent in realtime too (esp on mousewheel gesture etc)...

@baconpaul
Copy link
Collaborator

so the traversal is the same one we do on every menu build and mouse wheel
as a first pass, i would just make it do the easy thing
then if that doesn't work
we can do the hard thing

alternately we could, in the surge storage scan, build the cache if you want. that's fine too! Just rebuild it in refresh_patch_list and make it a member on storage. midi number to patch id.

@baconpaul
Copy link
Collaborator

Link to #576

@baconpaul
Copy link
Collaborator

Since there's good action in #576 from 3f72558 I'm gonna close this basically dup (which roughly does what I outlined above, just a bit smarter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature request MIDI MIDI support related
Projects
None yet
Development

No branches or pull requests

2 participants