LMMS / lmms

Cross-platform music production software
https://lmms.io
GNU General Public License v2.0
8.14k stars 1.01k forks source link

Engine decoupling proposal #2387

Open M374LX opened 9 years ago

M374LX commented 9 years ago

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:

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:

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:

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

Rossmaxx commented 6 months ago

@sakertooth might wanna look at this.