Files
lmms/include/Mixer.h
saker 9a0add49fb Core Refactor: Replace `QVector with std::vector` (#6477)
* Replace QVector with std::vector in AudioEngine

* Replace QVector with std::vector in AudioEngineWorkerThread

* Replace QVector with std::vector in AudioJack

* Replace QVector with std::vector in AutomatableModel

* Replace QVector with std::vector in AutomationClip

* Replace QVector with std::vector in AutomationEditor

* Replace QVector with std::vector in ConfigManager

* Replace QVector with std::vector in Controller

* Replace QVector with std::vector in ControllerConnection

* Replace QVector with std::vector in EffectChain

* Replace QVector with std::vector in EnvelopeAndLfoParameters

* Replace QVector with std::vector in InstrumentFunctions

* Replace QVector with std::vector in MidiClient

* Replace QVector with std::vector in Mixer

* Replace QVector with std::vector in Note

* Replace QVector with std::vector in PeakController

* Replace QVector with std::vector in PianoRoll

* Replace QVector with std::vector in PluginFactory

* Replace QVector with std::vector in RenderManager

* Replace QVector with std::vector in StepRecorder

* Replace QVector with std::vector in Track

* Replace QVector with std::vector in TrackContainer

* Replace QVector with std::vector in Song

* Adapt QVector to std::vector changes in ControllerConnectionDialog

* Phase 2: Use std::abs in panning.h
Without this, the QVector changes will make the code not compile.

* Phase 2: Replace QVector with std::vector in PeakControllerEffect

* Phase 2: Replace QVector with std::vector in AutomatableModel

* Phase 2: Replace QVector with std::vector in AutomationClip

* Phase 2: Replace QVector with std::vector in ControllerConnection

* Phase 2: Replace QVector with std::vector in EffectChain

* Phase 2: Replace QVector with std::vector in Mixer

* Phase 2: Replace QVector with std::vector in PeakController

* Phase 2: Replace QVector with std::vector in RenderManager

* Phase 2: Replace QVector with std::vector in Song

* Phase 2: Replace QVector with std::vector in StepRecorder

* Phase 2: Replace QVector with std::vector in Track

* Phase 2: Replace QVector with std::vector in TrackContainer

* Phase 2: Adapt QVector changes in EffectRackView

* Phase 2: Adapt QVector changes in AutomationClipView

* Phase 2: Adapt QVector changes in ClipView

* Phase 2: Adapt QVector changes in AutomationEditor

* Phase 2: Adapt QVector changes in PianoRoll

* Phase 2: Adapt QVector changes in TrackContainerView

* Phase 2: Adapt QVector changes in TrackContentWidget

* Phase 2: Adapt QVector changes in InstrumentTrack

* Phase 2: Adapt QVector changes in MidiClip

* Phase 2: Adapt QVector changes in SampleTrack

* Fix segmentation fault in ConfigManager::value

* Fix unintended faulty std::vector insert in AutomationClip::resolveAllIDs

* Resolve trailing whitespace in src/core/StepRecorder.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Use std::next and std::prev in EffectChain::moveUp/moveDown

* Introduce static "combineAllTracks" function in AutomationClip

* Adjust variable name in Song::automatedValuesAt

* Adjust removal of long step notes in StepRecorder::removeNotesReleasedForTooLong

* Iterate over m_chords by const reference in src/core/InstrumentFunctions.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Fix StepRecorder::removeNotesReleasedForTooLong again

* Combine the ConfigManager::value overloads using std::optional

* Revise StepRecorder::removeNotesReleasedForTooLong

* Remove redundant std::optional in ConfigManager::value

* Remove trailing whitespace in ConfigManager::value

* Fix: Prevent incorrect use of std::distance when element not found

* Chore: Remove trailing whitespace in edited files

* Only set the id attribute if the controller was found

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Remove extra indents from 84b8fe8a559855ed263b74cc582eab3655250c5f

* Fix compilation issues

* Add LMMS_ prefix for header guard in Track.h

* Undo changes made to MixerView::deleteUnusedChannels

* Simplify code to handle failure of finding tracks
Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Split ternary operator into separate if statement
Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Undo changes to indentation in MixerRoute

* Do general clean-up
Some of the changes made:
+ Use auto where benefical
+ Fix bug in AutomatableModel::globalAutomationValueAt (for loop should be looping over clips variable, not clipsInRange)
+ Undo out of focus whitespace changes

* Always assign to m_steps regardless if clip is found or not
Even when the clip is not found (i.e., currentClip is -1), m_steps still
gets assigned to.

* Insert at the end of tracks vector in src/core/Mixer.cpp

Co-authored-by: Dominic Clark <mrdomclark@gmail.com>

* Insert at the end of tracks vector in src/core/Mixer.cpp (2)

Co-authored-by: Dominic Clark <mrdomclark@gmail.com>

* Remove redundant template parameter

* Use std::array for zoomLevels

---------

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: Dominic Clark <mrdomclark@gmail.com>
2023-08-22 12:08:56 +09:00

234 lines
5.5 KiB
C++

/*
* Mixer.h - effect-mixer for LMMS
*
* Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef LMMS_MIXER_H
#define LMMS_MIXER_H
#include "Model.h"
#include "EffectChain.h"
#include "JournallingObject.h"
#include "ThreadableJob.h"
#include <atomic>
#include <QColor>
namespace lmms
{
class MixerRoute;
using MixerRouteVector = std::vector<MixerRoute*>;
class MixerChannel : public ThreadableJob
{
public:
MixerChannel( int idx, Model * _parent );
virtual ~MixerChannel();
EffectChain m_fxChain;
// set to true when input fed from mixToChannel or child channel
bool m_hasInput;
// set to true if any effect in the channel is enabled and running
bool m_stillRunning;
float m_peakLeft;
float m_peakRight;
sampleFrame * m_buffer;
bool m_muteBeforeSolo;
BoolModel m_muteModel;
BoolModel m_soloModel;
FloatModel m_volumeModel;
QString m_name;
QMutex m_lock;
int m_channelIndex; // what channel index are we
bool m_queued; // are we queued up for rendering yet?
bool m_muted; // are we muted? updated per period so we don't have to call m_muteModel.value() twice
// pointers to other channels that this one sends to
MixerRouteVector m_sends;
// pointers to other channels that send to this one
MixerRouteVector m_receives;
bool requiresProcessing() const override { return true; }
void unmuteForSolo();
void setColor (QColor newColor)
{
m_color = newColor;
m_hasColor = true;
}
// TODO C++17 and above: use std::optional instead
QColor m_color;
bool m_hasColor;
std::atomic_int m_dependenciesMet;
void incrementDeps();
void processed();
private:
void doProcessing() override;
};
class MixerRoute : public QObject
{
Q_OBJECT
public:
MixerRoute( MixerChannel * from, MixerChannel * to, float amount );
~MixerRoute() override = default;
mix_ch_t senderIndex() const
{
return m_from->m_channelIndex;
}
mix_ch_t receiverIndex() const
{
return m_to->m_channelIndex;
}
FloatModel * amount()
{
return &m_amount;
}
MixerChannel * sender() const
{
return m_from;
}
MixerChannel * receiver() const
{
return m_to;
}
void updateName();
private:
MixerChannel * m_from;
MixerChannel * m_to;
FloatModel m_amount;
};
class LMMS_EXPORT Mixer : public Model, public JournallingObject
{
Q_OBJECT
public:
Mixer();
~Mixer() override;
void mixToChannel( const sampleFrame * _buf, mix_ch_t _ch );
void prepareMasterMix();
void masterMix( sampleFrame * _buf );
void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
void loadSettings( const QDomElement & _this ) override;
QString nodeName() const override
{
return "mixer";
}
MixerChannel * mixerChannel( int _ch )
{
return m_mixerChannels[_ch];
}
// make the output of channel fromChannel go to the input of channel toChannel
// it is safe to call even if the send already exists
MixerRoute * createChannelSend(mix_ch_t fromChannel, mix_ch_t toChannel,
float amount = 1.0f);
MixerRoute * createRoute( MixerChannel * from, MixerChannel * to, float amount );
// delete the connection made by createChannelSend
void deleteChannelSend(mix_ch_t fromChannel, mix_ch_t toChannel);
void deleteChannelSend( MixerRoute * route );
// determine if adding a send from sendFrom to
// sendTo would result in an infinite mixer loop.
bool isInfiniteLoop(mix_ch_t fromChannel, mix_ch_t toChannel);
bool checkInfiniteLoop( MixerChannel * from, MixerChannel * to );
// return the FloatModel of fromChannel sending its output to the input of
// toChannel. NULL if there is no send.
FloatModel * channelSendModel(mix_ch_t fromChannel, mix_ch_t toChannel);
// add a new channel to the mixer.
// returns the index of the channel that was just added
int createChannel();
// delete a channel from the mixer.
void deleteChannel(int index);
// delete all the mixer channels except master and remove all effects
void clear();
// re-arrange channels
void moveChannelLeft(int index);
void moveChannelRight(int index);
// reset a channel's name, fx, sends, etc
void clearChannel(mix_ch_t channelIndex);
// rename channels when moving etc. if they still have their original name
void validateChannelName( int index, int oldIndex );
// check if the index channel receives audio from any other channel
// or from any instrument or sample track
bool isChannelInUse(int index);
void toggledSolo();
void activateSolo();
void deactivateSolo();
inline mix_ch_t numChannels() const
{
return m_mixerChannels.size();
}
MixerRouteVector m_mixerRoutes;
private:
// the mixer channels in the mixer. index 0 is always master.
std::vector<MixerChannel*> m_mixerChannels;
// make sure we have at least num channels
void allocateChannelsTo(int num);
int m_lastSoloed;
} ;
} // namespace lmms
#endif // LMMS_MIXER_H