LMMS
Loading...
Searching...
No Matches
Mixer.h
Go to the documentation of this file.
1/*
2 * Mixer.h - effect-mixer for LMMS
3 *
4 * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_MIXER_H
26#define LMMS_MIXER_H
27
28#include "AudioBuffer.h"
29#include "EffectChain.h"
30#include "JournallingObject.h"
31#include "Model.h"
32#include "ThreadableJob.h"
33
34#include <atomic>
35#include <optional>
36#include <QColor>
37
38namespace lmms
39{
40
41
42class MixerRoute;
43using MixerRouteVector = std::vector<MixerRoute*>;
44
46{
47public:
48 MixerChannel(int idx, Model* _parent);
49 virtual ~MixerChannel();
50
52
53 // set to true if any effect in the channel is enabled and running
55
63 QString m_name;
64 QMutex m_lock;
65 bool m_queued; // are we queued up for rendering yet?
66 bool m_muted; // are we muted? updated per period so we don't have to call m_muteModel.value() twice
67
68 // pointers to other channels that this one sends to
70
71 // pointers to other channels that send to this one
73
74 int index() const { return m_channelIndex; }
76
77 bool isMaster() { return m_channelIndex == 0; }
78
79 bool requiresProcessing() const override { return true; }
80 void unmuteForSolo();
83
84 auto color() const -> const std::optional<QColor>& { return m_color; }
85 void setColor(const std::optional<QColor>& color) { m_color = color; }
86
87 std::atomic_size_t m_dependenciesMet;
88 void incrementDeps();
89 void processed();
90
91private:
92 void doProcessing() override;
94 std::optional<QColor> m_color;
95};
96
97class MixerRoute : public QObject
98{
99 Q_OBJECT
100public:
101 MixerRoute( MixerChannel * from, MixerChannel * to, float amount );
102 ~MixerRoute() override = default;
103
105 {
106 return m_from->index();
107 }
108
110 {
111 return m_to->index();
112 }
113
115 {
116 return &m_amount;
117 }
118
120 {
121 return m_from;
122 }
123
125 {
126 return m_to;
127 }
128
129 void updateName();
130
131 private:
135};
136
137
138class LMMS_EXPORT Mixer : public Model, public JournallingObject
139{
140 Q_OBJECT
141public:
142 Mixer();
143 ~Mixer() override;
144
145 void mixToChannel(const AudioBuffer& buffer, mix_ch_t dest);
146
147 void prepareMasterMix();
148 void masterMix( SampleFrame* _buf );
149
150 void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
151 void loadSettings( const QDomElement & _this ) override;
152
153 QString nodeName() const override
154 {
155 return "mixer";
156 }
157
159 {
160 return m_mixerChannels[_ch];
161 }
162
163 // make the output of channel fromChannel go to the input of channel toChannel
164 // it is safe to call even if the send already exists
165 MixerRoute * createChannelSend(mix_ch_t fromChannel, mix_ch_t toChannel,
166 float amount = 1.0f);
167 MixerRoute * createRoute( MixerChannel * from, MixerChannel * to, float amount );
168
169 // delete the connection made by createChannelSend
170 void deleteChannelSend(mix_ch_t fromChannel, mix_ch_t toChannel);
171 void deleteChannelSend( MixerRoute * route );
172
173 // determine if adding a send from sendFrom to
174 // sendTo would result in an infinite mixer loop.
175 bool isInfiniteLoop(mix_ch_t fromChannel, mix_ch_t toChannel);
176 bool checkInfiniteLoop( MixerChannel * from, MixerChannel * to );
177
178 // return the FloatModel of fromChannel sending its output to the input of
179 // toChannel. NULL if there is no send.
180 FloatModel * channelSendModel(mix_ch_t fromChannel, mix_ch_t toChannel);
181
182 // add a new channel to the mixer.
183 // returns the index of the channel that was just added
184 int createChannel();
185
186 // delete a channel from the mixer.
187 void deleteChannel(int index);
188
189 // delete all the mixer channels except master and remove all effects
190 void clear();
191
192 // re-arrange channels
193 void moveChannelLeft(int index);
194 void moveChannelRight(int index);
195
196 // reset a channel's name, fx, sends, etc
197 void clearChannel(mix_ch_t channelIndex);
198
199 // rename channels when moving etc. if they still have their original name
200 void validateChannelName( int index, int oldIndex );
201
202 // check if the index channel receives audio from any other channel
203 // or from any instrument or sample track
204 bool isChannelInUse(int index);
205
206 void toggledSolo();
207 void activateSolo();
208 void deactivateSolo();
209
210 inline mix_ch_t numChannels() const
211 {
212 return m_mixerChannels.size();
213 }
214
216
217private:
218 // the mixer channels in the mixer. index 0 is always master.
219 std::vector<MixerChannel*> m_mixerChannels;
220
221 // make sure we have at least num channels
222 void allocateChannelsTo(int num);
223
225} ;
226
227
228} // namespace lmms
229
230#endif // LMMS_MIXER_H
Definition AudioBuffer.h:79
Definition AutomatableModel.h:497
Definition EffectChain.h:48
Definition AutomatableModel.h:463
JournallingObject()
Definition JournallingObject.cpp:36
Definition Mixer.h:46
bool isMaster()
Definition Mixer.h:77
void doProcessing() override
Definition Mixer.cpp:162
AudioBuffer m_buffer
Definition Mixer.h:58
std::atomic_size_t m_dependenciesMet
Definition Mixer.h:87
int index() const
Definition Mixer.h:74
virtual ~MixerChannel()
Definition Mixer.cpp:81
bool m_muted
Definition Mixer.h:66
BoolModel m_soloModel
Definition Mixer.h:61
MixerRouteVector m_sends
Definition Mixer.h:69
void setIndex(int index)
Definition Mixer.h:75
float m_peakRight
Definition Mixer.h:57
auto color() const -> const std::optional< QColor > &
Definition Mixer.h:84
void setColor(const std::optional< QColor > &color)
Definition Mixer.h:85
bool m_muteBeforeSolo
Definition Mixer.h:59
QMutex m_lock
Definition Mixer.h:64
int m_channelIndex
Definition Mixer.h:93
void unmuteSenderForSolo()
Definition Mixer.cpp:126
QString m_name
Definition Mixer.h:63
bool m_queued
Definition Mixer.h:65
void unmuteReceiverForSolo()
Definition Mixer.cpp:141
void unmuteForSolo()
Definition Mixer.cpp:107
BoolModel m_muteModel
Definition Mixer.h:60
float m_peakLeft
Definition Mixer.h:56
void incrementDeps()
Definition Mixer.cpp:97
MixerChannel(int idx, Model *_parent)
Definition Mixer.cpp:60
bool m_stillRunning
Definition Mixer.h:54
EffectChain m_fxChain
Definition Mixer.h:51
MixerRouteVector m_receives
Definition Mixer.h:72
void processed()
Definition Mixer.cpp:86
bool requiresProcessing() const override
Definition Mixer.h:79
std::optional< QColor > m_color
Definition Mixer.h:94
FloatModel m_volumeModel
Definition Mixer.h:62
void allocateChannelsTo(int num)
Definition Mixer.cpp:821
MixerChannel * mixerChannel(int _ch)
Definition Mixer.h:158
QString nodeName() const override
Definition Mixer.h:153
mix_ch_t numChannels() const
Definition Mixer.h:210
void masterMix(SampleFrame *_buf)
Definition Mixer.cpp:666
void prepareMasterMix()
Definition Mixer.cpp:659
void saveSettings(QDomDocument &_doc, QDomElement &_parent) override
Definition Mixer.cpp:790
void loadSettings(const QDomElement &_this) override
Definition Mixer.cpp:834
Mixer()
Definition Mixer.cpp:230
std::vector< MixerChannel * > m_mixerChannels
Definition Mixer.h:219
int m_lastSoloed
Definition Mixer.h:224
MixerRouteVector m_mixerRoutes
Definition Mixer.h:215
void mixToChannel(const AudioBuffer &buffer, mix_ch_t dest)
Definition Mixer.cpp:640
Definition Mixer.h:98
MixerChannel * sender() const
Definition Mixer.h:119
MixerRoute(MixerChannel *from, MixerChannel *to, float amount)
Definition Mixer.cpp:42
FloatModel m_amount
Definition Mixer.h:134
MixerChannel * m_from
Definition Mixer.h:132
~MixerRoute() override=default
FloatModel * amount()
Definition Mixer.h:114
void updateName()
Definition Mixer.cpp:53
mix_ch_t senderIndex() const
Definition Mixer.h:104
MixerChannel * receiver() const
Definition Mixer.h:124
mix_ch_t receiverIndex() const
Definition Mixer.h:109
MixerChannel * m_to
Definition Mixer.h:133
Definition Model.h:37
Model(Model *parent, QString displayName=QString(), bool defaultConstructed=false)
Definition Model.cpp:30
Definition SampleFrame.h:41
ThreadableJob()
Definition ThreadableJob.h:47
Definition AudioAlsa.cpp:35
std::vector< MixerRoute * > MixerRouteVector
Definition Mixer.h:43
std::uint16_t mix_ch_t
Definition LmmsTypes.h:47
Definition juce_Uuid.h:141
#define const
Definition zconf.h:137