Skip to content

refactor: get rid of TimelineKind#499

Open
FelipeDefensor wants to merge 5 commits into
devfrom
cleanup/timeline-kind-removal
Open

refactor: get rid of TimelineKind#499
FelipeDefensor wants to merge 5 commits into
devfrom
cleanup/timeline-kind-removal

Conversation

@FelipeDefensor

@FelipeDefensor FelipeDefensor commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Removes the TimelineKind enum in favor of direct Timeline subclass references throughout command/menu registries and timeline lookups. This leverages the fact that, in Python, classes are first-class citizens and reduces duplication. It also makes it easier to introduce new timeline types, as less code that is outside the timeline module needs to be touched.

This was done in preparation for range timelines, and the range timeline PR (#501) is stacked on top of this one.

@FelipeDefensor FelipeDefensor force-pushed the cleanup/timeline-kind-removal branch from b1cf402 to 9af2da3 Compare May 4, 2026 07:52

@FelipeDefensor FelipeDefensor left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review for Claude.

Comment thread tests/ui/cli/components/test_cli_components_add.py Outdated
Comment thread tests/ui/timelines/test_timelineui_collection.py Outdated
Comment thread tilia/parsers/__init__.py Outdated
Comment thread tilia/timelines/base/timeline.py
Comment thread tilia/timelines/collection/collection.py
Comment thread tilia/ui/timelines/collection/collection.py
Comment thread tilia/ui/timelines/collection/import_.py Outdated
Comment thread tilia/ui/timelines/collection/import_.py Outdated
Comment thread tilia/ui/qtui.py Outdated
Comment thread tilia/app.py Outdated
Comment thread tilia/timelines/base/timeline.py Outdated
Comment thread tilia/ui/timelines/collection/import_.py Outdated
@FelipeDefensor FelipeDefensor force-pushed the cleanup/timeline-kind-removal branch from 98f7e90 to e1f2273 Compare May 4, 2026 17:19
@FelipeDefensor FelipeDefensor requested a review from azfoo May 4, 2026 17:20
@FelipeDefensor FelipeDefensor marked this pull request as ready for review May 4, 2026 17:20
@FelipeDefensor FelipeDefensor added this to the 0.7.0 milestone May 4, 2026
@azfoo azfoo force-pushed the cleanup/timeline-kind-removal branch 2 times, most recently from c6b760a to 8efc99e Compare May 13, 2026 18:54
Replace the TimelineKind enum with direct Timeline subclass references.
The enum was an extra layer between component classes and the dispatch
sites that used them; using classes as first-class citizens removes a
parallel taxonomy and lets isinstance / equality checks express intent
directly.

Also fixes the fallout from this refactor at sites that started comparing
backend Timeline classes against UI TimelineUI classes (always False —
silently breaking dynamic dispatch):

- Beat-timeline creation no longer prompted for a beat pattern, because
  on_timeline_add's hasattr() check for get_additional_args_for_creation
  was looking at the backend class (passed via functools.partial), but
  the hook lives on the UI class. Look the UI class up via
  get_timeline_ui_class to consult it.
- Per-kind submenus under Timelines hid themselves whenever any timeline
  was created, because update_dynamic_menus compared a UI class against
  backend classes in instanced_kinds. Bridge through ui_cls.timeline_class
  so the comparison is backend-vs-backend.
- _setup_commands had the same UI-vs-backend bug for SliderTimeline /
  HarmonyTimeline / PdfTimeline / ScoreTimeline checks (Slider was
  incorrectly registering an Add command, and Harmony / PDF lost their
  custom keyboard accelerators).
Filed #507 for moving CSV/MusicXML importers onto the timeline classes
so this central dispatch can go away. Reference it from the TODO so the
rationale (and the issue) is one click away.
The `&` placement (and the harmony / PDF special cases) is opaque
without context. Spell out that they are Qt menu accelerators and why
each branch deviates.
SliderTimeline doesn't set COMPONENT_MANAGER_CLASS, so its
component_manager is None. Without this guard, len(slider_tl) crashes.
@azfoo azfoo force-pushed the cleanup/timeline-kind-removal branch from 8efc99e to 66544b6 Compare June 2, 2026 09:58
Comment thread tilia/clipboard.py
class ClipboardContents(TypedDict):
components: dict[str, dict]
timeline_kind: TimelineKind | None
timeline_type: Optional[type(Timeline)]

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.

I think a previous PR cleaned out all Optionals for | None. Let's keep that consistent here too.

Comment on lines +233 to +234
# TiLiA < 0.7 serialised the kind as e.g. "MARKER_TIMELINE";
# strip the suffix so files saved by older versions still load.

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.

Considering that we don't technically have a "stable" version yet, this might need to be removed in the future. Maybe have some kind of version converter?

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