Skip to content

Beat timeline from bpm - #568

Open
minamouse wants to merge 3 commits into
TimeLineAnnotator:mainfrom
minamouse:beat_timeline_from_bpm
Open

Beat timeline from bpm#568
minamouse wants to merge 3 commits into
TimeLineAnnotator:mainfrom
minamouse:beat_timeline_from_bpm

Conversation

@minamouse

Copy link
Copy Markdown

Summary

Adds option to fill beat timeline using the BPM

Screenshot 2026-08-21 at 15 29 13

Test plan

Create a beat timeline, click on the menu option to fill the beat timeline with beats. 3 options should show up, including fill by bpm.

@FelipeDefensor FelipeDefensor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good idea and solid implementation.

Only a few code style issues, and most where there to begin with, but I think adding a new option crosses the threshold and makes it worth the refactor worth it. Let me know if the comments are not clear enough.

The only necessary thing missing are tests, and I think the existing ones for filling the timeline via other methods can easily be adapted.

There are a couple edge cases that could optionally be better covered, like the "freeze" resulting from inputting a huge BPM or the 0 beats that result from, say, choosing 1 BPM in a 10-second media. Your call whether to handle them.

Comment thread tilia/ui/windows/fill_beat_timeline.py Outdated
Comment on lines 37 to 39
self._by_interval_edit.value() if checked_option == 1
else self._by_bpm_edit.value() if checked_option == 2
else self._by_amount_edit.value()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since we have more than two options now, I think it is worth replacing this with a dict lookup.

Comment thread tilia/ui/windows/fill_beat_timeline.py Outdated
def __init__(self):
def get_result():
checked_option = self._options.checkedId() % 2
checked_option = self._options.checkedId() % 3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we can use the legth of a dict instead of hard-coding the number here?

Comment thread tilia/ui/windows/fill_beat_timeline.py Outdated
self._by_amount_edit.setRange(1, 2147483647)
self._by_amount_edit.setSuffix(BEAT_TIMELINE_BY_AMOUNT_SUFFIX)
self._by_amount_edit.setValue(1)
self._by_bpm_edit.setRange(1, 2147483647)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Extract 2147483647 into a constant. I think it is used elsehwere in the codebase, so maybe tilia.consts is the place for it.

@@ -655,6 +655,7 @@ def delete_components(self, components: list[TC]) -> None:
class FillMethod(Enum):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Making this into a StrEnum would probably make the code-style fixes fill_with_beast easier.

Comment thread tilia/timelines/beat/timeline.py Outdated
for i in range(math.floor(duration / value)):
self.create_component(ComponentKind.BEAT, i * value)
elif method == BeatTimeline.FillMethod.BY_BPM:
interval_value = float(60) / float(value)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need for the float wrappers here, / always returns a float.

@minamouse

Copy link
Copy Markdown
Author

@FelipeDefensor I went through and addressed your comments in the latest commit. Rather than use a dict, I used the enum values to map from the FillMethod to the int value, let me know if that's alright.

@FelipeDefensor FelipeDefensor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the changes! Looks good now. Just missing the tests, and then I can approve.

Comment thread tilia/ui/consts.py
Comment on lines +2 to +3
BY_AMOUNT_RANGE = 2147483647
BY_BPM_RANGE = 300

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, but the idea was slightly different here.

I think 2147483647 is the max value for a QRadioButton, so my idea was to extract this here into something named Q_RADIO_BUTTON_MAX and refactor the remaining uses in the codebase. No need to do that, but if you don't, both of these variables should live in fill_beat_timeline.py, as they are specific to that module.

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.

2 participants