Skip to content

Ensure that a track has access to the project tempo. - #10688

Merged
kryksyh merged 1 commit into
audacity:audacity3from
DavidBailes:projecttempo
Apr 15, 2026
Merged

kryksyh merged 1 commit into
audacity:audacity3from
DavidBailes:projecttempo

Conversation

@DavidBailes

@DavidBailes DavidBailes commented Apr 9, 2026 •

Copy link
Copy Markdown
Collaborator

Resolves: #8440
Resolves: #5790

Problem:
In a newly created wavetrack, the project tempo "setting" of the wavetrack may not have be set before the call to GetProjectTempo(*this) in a call to WaveTrack::ClearAndPaste(), resulting in the thowing of an inconsistency exception. The problem is that this "setting" is set as a result of the call TrackList::AdditionEvent(), which uses CallAfter.

Fix.
In TrackList::AdditionEvent(), don't use CallAfter.

  • [ x] I signed CLA
  • [x ] The title of the pull request describes an issue it addresses
  • [x ] If changes are extensive, then there is a sequence of easily reviewable commits
  • [x ] Each commit's message describes its purpose and effects
  • [x ] There are no behavior changes unnecessary for the stated purpose of the PR

Recommended:

  • [ x] Each commit compiles and runs on my machine without known undesirable changes of behavior

QA:

  • Autobot test cases have been run

@coderabbitai

coderabbitai Bot commented Apr 9, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: c2e92c4d-8205-47ad-b665-b182001d4031

📥 Commits

Reviewing files that changed from the base of the PR and between c6587efe951124fc6dd5cfda854db427729a4e9d and b162533.

📒 Files selected for processing (1)
  • libraries/lib-track/Track.cpp

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved timing of track addition operations in the application.

Walkthrough

The change modifies TrackList::AdditionEvent so the TrackListEvent::ADDITION is constructed locally and published immediately via Publish(std::move(event)) rather than being enqueued via QueueEvent(...) for deferred publication through BasicUI::CallAfter. This changes emission from asynchronous/queued to synchronous/immediate.

Sequence Diagram(s)

sequenceDiagram
    participant TrackList
    participant QueueSystem
    participant BasicUI
    participant Subscribers

    TrackList->>QueueSystem: QueueEvent(ADDITION)
    QueueSystem->>BasicUI: CallAfter(Publish)
    BasicUI->>Subscribers: Publish(ADDITION)  %% event published later on UI thread
Loading
sequenceDiagram
    participant TrackList
    participant Subscribers

    TrackList->>Subscribers: Publish(ADDITION)  %% immediate synchronous publish
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title does not accurately reflect the actual change made. The summary shows changes to TrackList::AdditionEvent to use synchronous publication instead of CallAfter, but the title describes track access to project tempo. Consider revising the title to more clearly reflect the technical change, such as 'Make TrackListEvent publication synchronous instead of deferred' or similar.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses the root cause identified in issue #8440 by ensuring the project tempo setting is initialized synchronously before WaveTrack::ClearAndPaste is called.
Out of Scope Changes check ✅ Passed The change is narrowly focused on TrackList::AdditionEvent to remove CallAfter usage, which is directly aligned with fixing the deferred initialization issue described in the linked issue.
Description check ✅ Passed The PR description is comprehensive, addressing the problem, solution, and including linked issues with clear explanations of both the issue and fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kryksyh kryksyh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@DavidBailes thank you!

Problem:
In a newly created wavetrack, the project tempo "setting" of the wavetrack may not have be set before the call to GetProjectTempo(*this) in a call to WaveTrack::ClearAndPaste(), resulting in the thowing of an inconsistency exception.
The problem is that this "setting" is set as a result of the call TrackList::AdditionEvent(), which uses CallAfter.

Fix.
In TrackList::AdditionEvent(), don't use CallAfter.
@kryksyh
kryksyh merged commit 7cd2889 into audacity:audacity3 Apr 15, 2026
6 of 8 checks passed
kryksyh pushed a commit to DavidBailes/audacity that referenced this pull request Aug 17, 2026
Problem:
After opening a project, clips can have the wrong tempo. The tempo of a clip is the clip's "RawAudioTempo" rather than the project tempo. So when these values are different, a clip has the wrong tempo.

This issue was caused by PR audacity#10688, in which there was a change to publishing a TrackListEvent::ADDITION event immediately, rather than using CallAfter.
When opening a project, ProjectTempoListener::ProjectTempoListener() responds to a TrackListEvent::ADDITION by calling DoProjectTempoChange(*track, tempo), which calls OnProjectTempoChange::Call(group, oldTempo, newTempo), where oldTempo is nullopt, and newTempo is the project tempo. This is an attached virtual function, and there are overrides for each type of track. For wavetracks, this function sets the clip's project tempo. However because of the change in timing of the publishing of the event, the clips have not yet been added to the track, and so their values of project tempo are not set. When the oldTempo is nullopt, the overrides for all the other track types do nothing, and so other tracks are not affected by the change in timing.

Fix:
Add another call to OnProjectTempoChange::Call(group, oldTempo, newTempo), after the clips have been added.
kryksyh added a commit that referenced this pull request Aug 17, 2026
Resolves: #11337

Problem:
After opening a project, clips can have the wrong tempo. The tempo of a
clip is the clip's "RawAudioTempo" rather than the project tempo. So
when these values are different, a clip has the wrong tempo.

This issue was caused by PR #10688, in which there was a change to
publishing a TrackListEvent::ADDITION event immediately, rather than
using CallAfter. When opening a project,
ProjectTempoListener::ProjectTempoListener() responds to a
TrackListEvent::ADDITION by calling DoProjectTempoChange(*track, tempo),
which calls OnProjectTempoChange::Call(group, oldTempo, newTempo), where
oldTempo is nullopt, and newTempo is the project tempo. This is an
attached virtual function, and there are overrides for each type of
track. For wavetracks, this function sets the clip's project tempo.
However because of the change in timing of the publishing of the event,
the clips have not yet been added to the track, and so their values of
project tempo are not set. When the oldTempo is nullopt, the overrides
for all the other track types do nothing, and so other tracks are not
affected by the change in timing.

Fix:
Add another call to OnProjectTempoChange::Call(group, oldTempo,
newTempo), after the clips have been added.


<!-- Use "x" to fill the checkboxes below like [x] -->

- [ x] I signed [CLA](https://www.audacityteam.org/cla/)
- [x ] The title of the pull request describes an issue it addresses
- [x ] If changes are extensive, then there is a sequence of easily
reviewable commits
- [ x] Each commit's message describes its purpose and effects
- [x ] There are no behavior changes unnecessary for the stated purpose
of the PR

Recommended:
- [x ] Each commit compiles and runs on my machine without known
undesirable changes of behavior

QA:

- [ ] Testflow test cases have been run
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.

Internal error at audacity/libraries/lib-wave-track/WaveTrack.cpp line 1232 Internal Error when pasting to new stereo track with macro

2 participants