urinieto / msaf

Music Structure Analysis Framework
MIT License
501 stars 79 forks source link

Provide example of how to add a custom segmenter implementation from outside the package #152

Closed carlthome closed 12 months ago

carlthome commented 1 year ago

Assume the original idea was "drop in your folder with a Segmenter here and it will be auto-discovered by the parent package".

However, it's not possible to extend the available segmenter/labeler algorithms without mutating the source (I think?).

It would be nicer if msaf.algorithms worked in the same way as msaf.features, in that it's easily extendable from the outside, without having to mutate site-packages/msaf.

I'm intending to fix that, but first order of business would be to replace the dynamic importing with regular import statements.

urinieto commented 1 year ago

This is great, thanks. And that is exactly right: the intention is that it is easy to extend MSAF with additional features and algorithms.

carlthome commented 1 year ago

Expanded the scope of this PR to include the same setup as for features so one can add a new SegmenterInterface implementation from the outside.

Would need to digest this a bit since there might be something I've missed, but overall I think this looks pretty decent.

carlthome commented 1 year ago

Sorry for the back and forth on this PR. I've been exploring a nice way to make this work.

Although people rightfully have opinions on monkey patching being overly dynamic and hard to grok, I still think the new example/custom_segmenter.py is good since it doesn't require any source modifications and thus can't break any past behaviour.

IMO this is good to go in now.

urinieto commented 12 months ago

Ooh this looks fantastic, I really like the simplicity of it. Thanks, I'll merge away.