Skip to content

Disentangle midi play from audio io - #1637

Merged
Paul-Licameli merged 20 commits into
audacity:masterfrom
Paul-Licameli:Disentangle-MIDI-play-from-AudioIO
Sep 23, 2021
Merged

Paul-Licameli merged 20 commits into
audacity:masterfrom
Paul-Licameli:Disentangle-MIDI-play-from-AudioIO

Conversation

@Paul-Licameli

@Paul-Licameli Paul-Licameli commented Sep 8, 2021 •

Copy link
Copy Markdown
Collaborator

Resolves: #1581

Next refactoring steps for AudioIO.

All of the logic specific to MIDI playback is removed from AudioIO.cpp, and invoked instead through an abstract base class AudioIOExt. A new, separate file MIDIPlay.cpp registers its extension policy with AudioIO.

These steps shrink the big file AudioIO.cpp from 4797 to 3596 lines, and are also preparations for putting Note track into its own optional extension module.

The unnecessary separate thread for MIDI playback is removed for simplicity, and some callbacks happen directly in the Portaudio thread. That means some memory allocations may happen on that thread, when MIDI plays! (See PrepareMidiIterator().) But future refactorings will correct that.

The dependency of lib-audio-devices on portmidi is severed.

A few other changes remove some dependencies on NoteTrack, and use Settings objects from Prefs.cpp to eliminate some duplicated literals and direct use of gPrefs in MIDIPlay.cpp.

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

Recommended:

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

@Paul-Licameli
Paul-Licameli requested a review from crsib September 8, 2021 01:10
@Paul-Licameli Paul-Licameli mentioned this pull request Sep 8, 2021
6 tasks done
@Paul-Licameli
Paul-Licameli force-pushed the Disentangle-MIDI-play-from-AudioIO branch 3 times, most recently from ce43b70 to 1e86096 Compare September 15, 2021 14:48
@Paul-Licameli
Paul-Licameli force-pushed the Disentangle-MIDI-play-from-AudioIO branch 3 times, most recently from 0586c40 to 73ee6d6 Compare September 21, 2021 00:18
@Paul-Licameli

Copy link
Copy Markdown
Collaborator Author

Now rebased, with build fixes, and also removing use of deprecated std::iterator.

Comment thread src/AudioIOExt.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we should something else in place of Other? Like ExtensionStream or whatever?

@crsib crsib left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MidiCode is much easier to understand now!

... so it might be called from the same low-latency thread as
AudioIoCallback::AudioCallback
... And certain variables that no longer communicate inter-thread lose their
volatile qualifier (which wasn't even proper use of volatile anyway)
...duplicating mUsingAlsa

The move of the call to ComputeOtherTimings is allowable because the override
does not use the number of pause frames

For the moved data members:  remove unused mSeq, added in-class initializers,
modernized some casting
... And AudioIO does not depend on portmidi.h
@Paul-Licameli
Paul-Licameli force-pushed the Disentangle-MIDI-play-from-AudioIO branch from 73ee6d6 to f891676 Compare September 23, 2021 03:09
@Paul-Licameli
Paul-Licameli merged commit 819faf3 into audacity:master Sep 23, 2021
@Paul-Licameli
Paul-Licameli deleted the Disentangle-MIDI-play-from-AudioIO branch September 23, 2021 03:09
kryksyh added a commit that referenced this pull request Aug 19, 2026
…11696)

Resolves: #11664
Resolves: #2359

When the playback is restarted with a click on a timeline, it stops all
streams first. During stop we wait for all midi events to be drained.

But if the playback is restarted twice in quick succession, the first
midi playback doesnt have time to fully initialize which results in a
1000s wait. Introduced in #1637

Call stack:
```
(anonymous namespace)::MIDIPlay::MidiTime() (libraries/lib-note-track/MIDIPlay.cpp:1059)
(anonymous namespace)::MIDIPlay::StopOtherStream() (libraries/lib-note-track/MIDIPlay.cpp:760)
AudioIO::StopStream() (libraries/lib-audio-io/AudioIO.cpp:1535)
ProjectAudioManager::Stop(bool) (src/ProjectAudioManager.cpp:531)
AdornedRulerPanel::StartQPPlay(bool, bool, double const*) (src/AdornedRulerPanel.cpp:2111)
AdornedRulerPanel::CommonRulerHandle::StartPlay(AudacityProject&, wxMouseEvent const&) (src/AdornedRulerPanel.cpp:192)
AdornedRulerPanel::PlayRegionAdjustingHandle::Release(TrackPanelMouseEvent const&, AudacityProject*, wxWindow*) (src/AdornedRulerPanel.cpp:296)
CellularPanel::OnMouseEvent(wxMouseEvent&) (src/CellularPanel.cpp:814)
wxAppConsoleBase::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&), wxEvent&) const (.conan2/p/b/wxwid222b45a67b428/b/src/src/common/appbase.cpp:657)
wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) const 
```

<!-- 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.

Disentangle MIDI play steps from AudioIO

2 participants