LMMS / LMMS/lmms

Engine decoupling proposal

Open
#2,387 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

core enhancement
Dominant language
C++
Stars
10.4k
Forks
1.3k
Avg merge
2d 13h
Merged PRs (30d)
7

Description

I have a proposal for a large step to reduce the coupling between components managed by `Engine`.

Certain components currently managed by `Mixer` could be managed by `Engine` directly: the audio and MIDI devices, `MixerProfiler`, `fifo`, and `FifoWriter`. `Engine` would also check for metronome samples and manage the song playing position (`PlayPos`), as the metronome also needs it.

The core method for buffer rendering (`Mixer::renderNextBuffer()`) would also be moved to `Engine`, while the parts of the rendering process handled by `Mixer` would be split into two methods (`startNextBuffer()` and `finishBuffer()`). Here is a pseudocode illustrating the new method:

``` C++
void Engine::renderNextBuffer()
{
mixerProfiler.startPeriod();

mixer->startNextBuffer();
song->processNextBuffer(m_playPos[m_playMode]); //The argument is a reference
checkForMetronome(); //Decide if a metronome sample needs to be played
mixer->finishBuffer();

EnvelopeAndLfoParameters::instances()->trigger();
Controller::triggerFrameCounter();
AutomatableModel::incrementPeriodCounter();

BufferManager::refresh();

mixerProfiler.finishPeriod();
}
```

Similarly, `Engine` would look like:

``` C++
class Engine
{
public:
getNextBuffer(); //Decide between reading from the FIFO or calling renderNextBuffer(). Used by the audio device

/// [...]

private:
renderNextBuffer();

m_playPos;
m_playMode;

m_song;
m_bbTrackContainer;
m_dummyTrackContainer;

m_fxMixer;
m_mixer;

m_fifo;
m_fifoWriter;

m_ladspaManager;

m_audioDevice;
m_oldAudioDevice;

m_midiDevice;

m_instanceOfMe;
}
```

There are still other coupling problems, but these can be solved later. These include:
- The dependency of many objects on `Mixer` methods providing information, like `framesPerPeriod()`, `baseSampleRate()`, and `processingSampleRate()`, which are accessible globally.
- Similarly, we have the methods `addPlayHandle()` and `removePlayHandle()`. A possibility is to create a `PlayHandleManager` and free `Mixer` from the task of managing play handles.

In case no one has objections, I can start writing the new code and create a pull request.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by mapping Engine and Mixer, especially Mixer::renderNextBuffer() and the proposed getNextBuffer(), startNextBuffer(), and finishBuffer() entry points. Trace ownership of the listed devices, FIFO components, profiler, play position, and metronome handling. Done means the proposed responsibilities are separated without breaking buffer rendering or the remaining Mixer dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
audio-video-rtc, desktop
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.