-
Notifications
You must be signed in to change notification settings - Fork 246
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
Refactor of sffile and defsfont code, including some bugfixes #823
Conversation
Those fields are not used anywhere, so let's simply remove them.
Not really necessary, checking against Gen_Last is just as understandable and removes a macro.
The previous implementation used 0 as end-of-list sentinel value. But 0 is also the id of the first generator in the invalid_preset_gen list. This effectively prevented checks for invalid preset generators. Also contains some code cleanup to make the check for invalid instrument generators similar to invalid preset generators. Fixes #821
We already have an enum for all generator values, so there is no need to define another list in the loader code.
Presets should not contain sampleid generators, instruments should not contain instrument generators.
This change removes the need for the instsamp hack in instrument and preset zones. The sampleid and instrument generators are treated as any other generator and simply passed to the defsfont import functions. Those read the two generators and use the index to look up valid samples and instruments. Both generators are then reset to GEN_UNUSED again, just to make sure that the rest of FluidSynth doesn't get confused. But that might not be necessary.
Cleanup of the code structure and fix of the ineffective check for global zones that are not first in list. Fixes #813
This pull request fixes 1 alert when merging 0f8e2c7 into 8413c35 - view on LGTM.com fixed alerts:
|
Looking after |
Suggestion: in 16d2f43 struct _SFPhdr, perhaps could we add a little comment to indicate that library, genre and morphology aren't not used ?. |
About change in |
Thanks for the review JJC!
I don't see duplicate code in those two functions. What do you mean exactly?
We could do. I'm just wondering what the purpose would be. There is a comment in sffile where we skip those thields, but why would we (or somebody working on FS in the future) need an additional comment in SFPhdr? i think the statement in the SF2 specs about "preserving" those three values means that software that loads and then writes SF2 files should keep the content of those fields untouched. But we will never write SF2 files...
It does increase loading time a tiny bit. Here are the timings for loading 10 instances of the FluidR3 soundfont on my machine:
If we think that slowdown is too much, then I think we could easily find some places for optimiziation. Like using
Or, if we didn't want to change the order or samples in the list, we could simply keep track of the added last_list element when appending to lists in sffile, reducing the O(n) complexity everywhere to O(1). That would probably give an even greater speedup. |
Using prepend both in sffile and defsfont reduces insert complexity to O(1) and does not affect the final order of the sample list, as the reversed order of the samples in sffile is reversed again in defsfont.
Wrong thinking on my part... using fluid_list_prepend in both places preserves the original order, of course. So that is an easy optimisation without side-effects. I've added the change to this PR. |
This pull request fixes 1 alert when merging 5ebd4d3 into 8413c35 - view on LGTM.com fixed alerts:
|
Please don't mind about that. Ignore my comment.
Ah yes. That is sufficient. Please don't mind.
This augmentation seems negligible. Thanks for all the cleanup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me as well. I am getting a bit cold feet when looking at the changes in load_pgen
and load_igen
though. So I would suggest the following procedure:
- Release 2.2.0 on easter
- Get Marcus' integration test ready
- Get my
zone-validation-test
ready - Test this PR against both tests
- Merge this PR
Sounds good to me. But I would add another point to the list:
In case you haven't written the zone unit tests yet: I do have some small (1.5k) soundfonts created during the fuzzing that trigger the invalid zone handling. So we could simply use those as test cases and check them against the expected defsfont state with the dump_sfont tool. |
I have a few tests, also the broken soundfont from 808 has a test case. It's quite a lot copy pasted. Unfortunately I don't see how to make it much better without loosing too much flexibility while putting in too much effort. (it's checked in) |
This pull request fixes 1 alert when merging 28890df into ddb13e3 - view on LGTM.com fixed alerts:
|
When the integration test is ready, I would merge master back in and resolve conflicts. |
28890df
to
aa937cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! As expected, the only detected behaviour change is that GEN_INSTRUMENT
is no longer allowed in load_igen
. Once CI is green, we can merge this as well.
aa937cc
to
d275402
Compare
Yeah... I wondered if that is actually a good thing to add. Yet another SoundFont validity check that FluidSynth doesn't need (because it can cope with this defect). But maybe it will help to improve other SoundFont implementations out there... ;-) |
SonarCloud Quality Gate failed. |
This pull request fixes 1 alert when merging d275402 into 487156c - view on LGTM.com fixed alerts:
|
I'm very confident that it won't hurt. Whereas fluidsynth previously added a useless instrument generator it now simply skips that generator. Loading is not affected. The user doesn't even see a message, that it had been skipped. That's just fine. It's the correct behaviour. |
If a generator is skipped, then we warn that "Some invalid generators were discarded". But of course you are right... it's only a warning, not a hard failure. |
Ah, sry, I was only looking at the unit test before and afterwards and didn't recognize it. |
Looks good, so I would merge this in the next hour (unless you shout stop before :-) |
This PR makes a few refactoring changes to the the fluid_sffile and fluid_defsfont code and also includes fixes for #821 and #813.
The most important refactorings are:
SFZone->inststamp
pointer by treating the GEN_INSTRUMENT and GEN_SAMPLEID generators like any other generators and resolving the indices in the defsfont import functions insteadI developed it on top of the defsfont-integration-test branch to make sure it doesn't introduce new behaviour. So to test this PR, I would suggest to merge it locally with defsfont-integration-test. I could also rebase it onto that branch, if it would help with review.
With the integration test, I'm fairly certain that this PR doesn't introduce any unwanted effects or new behaviour, but as it's touching such a core part of FluidSynth I would really welcome a very thorough review from both of you. Both about the code changes themselves, but also about the refactorings as a whole. As they touch very old and often used code code paths, the risk of breaking stuff is obviously quite high, even with the integration test as a safety net.