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

Fix autobpm and improve its docs #5389

Merged
merged 9 commits into from
Aug 26, 2024

Conversation

snejus
Copy link
Member

@snejus snejus commented Aug 16, 2024

Description

Fixes #5289 and #5185

Tried using the autobpm plugin and found a couple of issues:

  1. Crash in autobpm plugin / Docs incomplete #5185 librosa dependency was missing in pyproject.toml
  2. Simply including the plugin in the configuration made beet take over 4 seconds to start up.
  3. BPM detection failed due to another missing dependency, resampy
  4. Error in autobpm module (at least with Python 3.7) #5289 Librosa beat_track function returned unexpected type which made the plugin and the entire import process fail.

Addressed each of the above, slightly refactored the plugin and added tests.

To Do

  • Documentation. (If you've added a new command-line flag, for example, find the appropriate page under docs/ to describe it.)
  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)
  • Tests. (Very much encouraged but not strictly required.)

@snejus snejus self-assigned this Aug 16, 2024
@snejus snejus linked an issue Aug 16, 2024 that may be closed by this pull request
@snejus snejus requested a review from bal-e August 16, 2024 13:22
@snejus snejus linked an issue Aug 16, 2024 that may be closed by this pull request
@snejus snejus requested a review from Serene-Arc August 16, 2024 13:24
@snejus snejus force-pushed the autobpm-fix-and-improve-docs branch from 238ba9c to 16736db Compare August 16, 2024 13:30
Copy link
Member

@bal-e bal-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used this feature myself, but this looks really good, @snejus! I'm particularly happy about the use of pytest and pathlib :)

beets/library.py Show resolved Hide resolved
docs/changelog.rst Outdated Show resolved Hide resolved
exc,
)

kwargs = self.config["beat_track_kwargs"].flatten()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking, there's no security considerations here, right? cc @Serene-Arc

"autobpm", help="detect and add bpm from audio using Librosa"
)
cmd.func = self.command
return [cmd]

def command(self, lib, opts, args):
self.calculate_bpm(lib.items(ui.decargs(args)), write=ui.should_write())
def command(self, lib: Library, _, args: list[str]) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the unused arguments should be marked, but I think their names should be preserved, i.e. using _opts instead of just _. It's just a bit clearer, especially since the whole codebase isn't well-typed yet. Also, a type annotation should still be used for the argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree regarding general clarity, but do you reckon this is needed here given that this argument is unused? I find that _ in such case clearly communicates that. I find the presence of the type a bit confusing if the argument is not used.

Note that my opinion here is mostly based on refactoring interfaces like the one that BeetsPlugin provides: in this case using _ notation allows the interface (and the type) to change without the need to update the code here.

Essentially, I'm applying the ISP principle to the function arguments here

Within object-oriented design, interfaces provide layers of abstraction that simplify code and create a barrier preventing coupling to dependencies. A system may become so coupled at multiple levels that it is no longer possible to make a change in one place without necessitating many additional changes.[1] Using an interface or an abstract class can prevent this side effect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I'm just not used to it. Any preference, @Serene-Arc?

@snejus snejus force-pushed the autobpm-fix-and-improve-docs branch 3 times, most recently from 2a7f33d to ca5dd1f Compare August 19, 2024 14:15
@snejus
Copy link
Member Author

snejus commented Aug 19, 2024

@JOJ0 I noticed your comment under #4923 regarding difficulties calculating BPM for offbeaty tracks: I've been having the same issue - I found that adjusting start_bpm parameter in the beat_track call helps to control the 'taggable' BPM range. You can do so using the new configuration option:

autobpm:
  beat_track_kwargs:
    start_bpm: 160

Just giving a shout making sure you're aware!

@snejus snejus force-pushed the autobpm-fix-and-improve-docs branch from ca5dd1f to 111686e Compare August 19, 2024 21:44
@snejus
Copy link
Member Author

snejus commented Aug 25, 2024

@Serene-Arc @bal-e do we think this could be merged?

@snejus snejus merged commit 4416b98 into beetbox:master Aug 26, 2024
12 checks passed
@snejus snejus deleted the autobpm-fix-and-improve-docs branch August 26, 2024 16:18
@beetbox beetbox deleted a comment from codecov bot Aug 27, 2024
@tandy-1000
Copy link
Contributor

thanks for doing this!

@JOJ0
Copy link
Member

JOJ0 commented Aug 29, 2024

Also from my end many thanks @snejus and thanks for the tip with configuring bpm min value. will try that!

@snejus snejus mentioned this pull request Sep 12, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in autobpm module (at least with Python 3.7) Crash in autobpm plugin / Docs incomplete
4 participants