-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathMixer.cpp
More file actions
826 lines (662 loc) · 19.8 KB
/
Mixer.cpp
File metadata and controls
826 lines (662 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
/*
* Mixer.cpp - effect mixer for LMMS
*
* Copyright (c) 2008-2011 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.
*
*/
#include <QDomElement>
#include "AudioEngine.h"
#include "AudioEngineWorkerThread.h"
#include "Mixer.h"
#include "MixHelpers.h"
#include "Song.h"
#include "InstrumentTrack.h"
#include "PatternStore.h"
#include "SampleTrack.h"
#include "TrackContainer.h" // For TrackContainer::TrackList typedef
namespace lmms
{
MixerRoute::MixerRoute( MixerChannel * from, MixerChannel * to, float amount ) :
m_from( from ),
m_to( to ),
m_amount(amount, 0, 1, 0.001f, nullptr,
tr("Amount to send from channel %1 to channel %2").arg(m_from->index()).arg(m_to->index()))
{
//qDebug( "created: %d to %d", m_from->m_channelIndex, m_to->m_channelIndex );
// create send amount model
}
void MixerRoute::updateName()
{
m_amount.setDisplayName(
tr("Amount to send from channel %1 to channel %2").arg(m_from->index()).arg(m_to->index()));
}
MixerChannel::MixerChannel( int idx, Model * _parent ) :
m_fxChain( nullptr ),
m_stillRunning( false ),
m_peakLeft( 0.0f ),
m_peakRight( 0.0f ),
m_buffer(Engine::audioEngine()->framesPerPeriod()),
m_muteModel( false, _parent ),
m_soloModel( false, _parent ),
m_volumeModel(1.f, 0.f, 2.f, 0.001f, _parent),
m_name(),
m_lock(),
m_queued( false ),
m_dependenciesMet(0),
m_channelIndex(idx),
m_useCount(0)
{
m_buffer.allocateInterleavedBuffer();
}
MixerChannel::~MixerChannel()
{
}
inline void MixerChannel::processed()
{
for( const MixerRoute * receiverRoute : m_sends )
{
if( receiverRoute->receiver()->m_muted == false )
{
receiverRoute->receiver()->incrementDeps();
}
}
}
void MixerChannel::incrementDeps()
{
const auto i = m_dependenciesMet++ + 1;
if( i >= m_receives.size() && ! m_queued )
{
m_queued = true;
AudioEngineWorkerThread::addJob( this );
}
}
void MixerChannel::unmuteForSolo()
{
m_muteModel.setValue(false);
// if channel is not master, unmute also every channel it sends to/receives from
if (!isMaster())
{
for (const MixerRoute* sendsRoute : m_sends)
{
sendsRoute->receiver()->unmuteSenderForSolo();
}
for (const MixerRoute* receiverRoute : m_receives)
{
receiverRoute->sender()->unmuteReceiverForSolo();
}
}
}
void MixerChannel::unmuteSenderForSolo()
{
m_muteModel.setValue(false);
// if channel is not master, unmute every channel it sends to
if (!isMaster())
{
for (const MixerRoute* sendsRoute : m_sends)
{
sendsRoute->receiver()->unmuteSenderForSolo();
}
}
}
void MixerChannel::unmuteReceiverForSolo()
{
m_muteModel.setValue(false);
// if channel is not master, unmute every channel it receives from, and of those, unmute the channels they send to
if (!isMaster())
{
for (const MixerRoute* receiverRoute : m_receives)
{
receiverRoute->sender()->unmuteReceiverForSolo();
}
for (const MixerRoute* sendsRoute : m_sends)
{
sendsRoute->receiver()->unmuteSenderForSolo();
}
}
}
void MixerChannel::doProcessing()
{
const f_cnt_t fpp = Engine::audioEngine()->framesPerPeriod();
if( m_muted == false )
{
for( MixerRoute * senderRoute : m_receives )
{
MixerChannel * sender = senderRoute->sender();
FloatModel * sendModel = senderRoute->amount();
if( ! sendModel ) qFatal( "Error: no send model found from %d to %d", senderRoute->senderIndex(), m_channelIndex );
if (sender->m_buffer.hasAnySignal() || sender->m_stillRunning)
{
auto buffer = m_buffer.interleavedBuffer().asSampleFrames();
// figure out if we're getting sample-exact input
ValueBuffer * sendBuf = sendModel->valueBuffer();
ValueBuffer * volBuf = sender->m_volumeModel.valueBuffer();
// mix it's output with this one's output
auto ch_buf = sender->m_buffer.interleavedBuffer().asSampleFrames();
// use sample-exact mixing if sample-exact values are available
if( ! volBuf && ! sendBuf ) // neither volume nor send has sample-exact data...
{
const float v = sender->m_volumeModel.value() * sendModel->value();
MixHelpers::addSanitizedMultiplied(buffer.data(), ch_buf.data(), v, fpp);
}
else if( volBuf && sendBuf ) // both volume and send have sample-exact data
{
MixHelpers::addSanitizedMultipliedByBuffers(buffer.data(), ch_buf.data(), volBuf, sendBuf, fpp);
}
else if( volBuf ) // volume has sample-exact data but send does not
{
const float v = sendModel->value();
MixHelpers::addSanitizedMultipliedByBuffer(buffer.data(), ch_buf.data(), v, volBuf, fpp);
}
else // vice versa
{
const float v = sender->m_volumeModel.value();
MixHelpers::addSanitizedMultipliedByBuffer(buffer.data(), ch_buf.data(), v, sendBuf, fpp);
}
toPlanar(m_buffer.interleavedBuffer(), m_buffer.groupBuffers(0));
m_buffer.mixSilenceFlags(sender->m_buffer);
}
}
const float v = m_volumeModel.value();
m_stillRunning = m_fxChain.processAudioBuffer(m_buffer);
const auto peakSamples = SampleFrame{m_buffer.absPeakValue(0), m_buffer.absPeakValue(1)};
m_peakLeft = std::max(m_peakLeft, peakSamples[0] * v);
m_peakRight = std::max(m_peakRight, peakSamples[1] * v);
}
else
{
m_peakLeft = m_peakRight = 0.0f;
}
// increment dependency counter of all receivers
processed();
}
Mixer::Mixer() :
Model( nullptr ),
JournallingObject(),
m_mixerChannels(),
m_lastSoloed(-1)
{
// create master channel
createChannel();
}
Mixer::~Mixer()
{
while (!m_mixerRoutes.empty())
{
deleteChannelSend(m_mixerRoutes.front());
}
while( m_mixerChannels.size() )
{
MixerChannel * f = m_mixerChannels[m_mixerChannels.size() - 1];
m_mixerChannels.pop_back();
delete f;
}
}
int Mixer::createChannel()
{
const int index = m_mixerChannels.size();
// create new channel
m_mixerChannels.push_back( new MixerChannel( index, this ) );
// reset channel state
clearChannel( index );
// if there is a soloed channel, mute the new track
if (m_lastSoloed != -1 && m_mixerChannels[m_lastSoloed]->m_soloModel.value())
{
m_mixerChannels[index]->m_muteBeforeSolo = m_mixerChannels[index]->m_muteModel.value();
m_mixerChannels[index]->m_muteModel.setValue(true);
}
emit channelCreated(index);
return index;
}
void Mixer::activateSolo()
{
for (auto i = std::size_t{1}; i < m_mixerChannels.size(); ++i)
{
m_mixerChannels[i]->m_muteBeforeSolo = m_mixerChannels[i]->m_muteModel.value();
m_mixerChannels[i]->m_muteModel.setValue( true );
}
}
void Mixer::deactivateSolo()
{
for (auto i = std::size_t{1}; i < m_mixerChannels.size(); ++i)
{
m_mixerChannels[i]->m_muteModel.setValue( m_mixerChannels[i]->m_muteBeforeSolo );
}
}
void Mixer::toggledSolo()
{
int soloedChan = -1;
bool resetSolo = m_lastSoloed != -1;
//untoggle if lastsoloed is entered
if (resetSolo)
{
m_mixerChannels[m_lastSoloed]->m_soloModel.setValue( false );
}
//determine the soloed channel
for (auto i = std::size_t{0}; i < m_mixerChannels.size(); ++i)
{
if (m_mixerChannels[i]->m_soloModel.value() == true)
soloedChan = i;
}
// if no channel is soloed, unmute everything, else mute everything
if (soloedChan != -1)
{
if (resetSolo)
{
deactivateSolo();
activateSolo();
} else {
activateSolo();
}
// unmute the soloed chan and every channel it sends to/receives from
m_mixerChannels[soloedChan]->unmuteForSolo();
} else {
deactivateSolo();
}
m_lastSoloed = soloedChan;
}
void Mixer::deleteChannel( int index )
{
// channel deletion is performed between mixer rounds
Engine::audioEngine()->requestChangeInModel();
MixerChannel * ch = m_mixerChannels[index];
// delete all of this channel's sends and receives
while (!ch->m_sends.empty())
{
deleteChannelSend(ch->m_sends.front());
}
while (!ch->m_receives.empty())
{
deleteChannelSend(ch->m_receives.front());
}
// if m_lastSoloed was our index, reset it
if (m_lastSoloed == index) { m_lastSoloed = -1; }
// if m_lastSoloed is > delete index, it will move left
else if (m_lastSoloed > index) { --m_lastSoloed; }
// actually delete the channel
m_mixerChannels.erase(m_mixerChannels.begin() + index);
delete ch;
for (auto i = static_cast<std::size_t>(index); i < m_mixerChannels.size(); ++i)
{
validateChannelName( i, i + 1 );
// set correct channel index
m_mixerChannels[i]->setIndex(i);
// now check all routes and update names of the send models
for( MixerRoute * r : m_mixerChannels[i]->m_sends )
{
r->updateName();
}
for( MixerRoute * r : m_mixerChannels[i]->m_receives )
{
r->updateName();
}
}
emit channelDeleted(index);
Engine::audioEngine()->doneChangeInModel();
}
void Mixer::moveChannelLeft( int index )
{
// can't move master or first channel
if (index <= 1 || static_cast<std::size_t>(index) >= m_mixerChannels.size()) { return; }
// channels to swap
int a = index - 1, b = index;
// check if m_lastSoloed is one of our swaps
if (m_lastSoloed == a) { m_lastSoloed = b; }
else if (m_lastSoloed == b) { m_lastSoloed = a; }
// Swap positions in array
std::swap(m_mixerChannels[index], m_mixerChannels[index - 1]);
// Update m_channelIndex of both channels
m_mixerChannels[index]->setIndex(index);
m_mixerChannels[index - 1]->setIndex(index - 1);
emit channelsSwapped(index, index - 1);
}
void Mixer::moveChannelRight( int index )
{
moveChannelLeft( index + 1 );
}
MixerRoute * Mixer::createChannelSend( mix_ch_t fromChannel, mix_ch_t toChannel,
float amount )
{
// qDebug( "requested: %d to %d", fromChannel, toChannel );
// find the existing connection
MixerChannel * from = m_mixerChannels[fromChannel];
MixerChannel * to = m_mixerChannels[toChannel];
for (const auto& send : from->m_sends)
{
if (send->receiver() == to)
{
// simply adjust the amount
send->amount()->setValue(amount);
return send;
}
}
// connection does not exist. create a new one
return createRoute( from, to, amount );
}
MixerRoute * Mixer::createRoute( MixerChannel * from, MixerChannel * to, float amount )
{
if( from == to )
{
return nullptr;
}
Engine::audioEngine()->requestChangeInModel();
auto route = new MixerRoute(from, to, amount);
// add us to from's sends
from->m_sends.push_back(route);
// add us to to's receives
to->m_receives.push_back(route);
// add us to mixer's list
Engine::mixer()->m_mixerRoutes.push_back(route);
Engine::audioEngine()->doneChangeInModel();
return route;
}
// delete the connection made by createChannelSend
void Mixer::deleteChannelSend( mix_ch_t fromChannel, mix_ch_t toChannel )
{
// delete the send
MixerChannel * from = m_mixerChannels[fromChannel];
MixerChannel * to = m_mixerChannels[toChannel];
// find and delete the send entry
for (const auto& send : from->m_sends)
{
if (send->receiver() == to)
{
deleteChannelSend(send);
break;
}
}
}
void Mixer::deleteChannelSend( MixerRoute * route )
{
Engine::audioEngine()->requestChangeInModel();
auto removeFromMixerRoute = [route](MixerRouteVector& routeVec)
{
auto it = std::find(routeVec.begin(), routeVec.end(), route);
if (it != routeVec.end()) { routeVec.erase(it); }
};
// remove us from from's sends
removeFromMixerRoute(route->sender()->m_sends);
// remove us from to's receives
removeFromMixerRoute(route->receiver()->m_receives);
// remove us from mixer's list
removeFromMixerRoute(Engine::mixer()->m_mixerRoutes);
delete route;
Engine::audioEngine()->doneChangeInModel();
}
bool Mixer::isInfiniteLoop( mix_ch_t sendFrom, mix_ch_t sendTo )
{
if( sendFrom == sendTo ) return true;
MixerChannel * from = m_mixerChannels[sendFrom];
MixerChannel * to = m_mixerChannels[sendTo];
bool b = checkInfiniteLoop( from, to );
return b;
}
bool Mixer::checkInfiniteLoop( MixerChannel * from, MixerChannel * to )
{
// can't send master to anything
if( from == m_mixerChannels[0] )
{
return true;
}
// can't send channel to itself
if( from == to )
{
return true;
}
// follow sendTo's outputs recursively looking for something that sends
// to sendFrom
for (const auto& send : to->m_sends)
{
if (checkInfiniteLoop(from, send->receiver()))
{
return true;
}
}
return false;
}
// how much does fromChannel send its output to the input of toChannel?
FloatModel * Mixer::channelSendModel( mix_ch_t fromChannel, mix_ch_t toChannel )
{
if( fromChannel == toChannel )
{
return nullptr;
}
const MixerChannel * from = m_mixerChannels[fromChannel];
const MixerChannel * to = m_mixerChannels[toChannel];
for( MixerRoute * route : from->m_sends )
{
if( route->receiver() == to )
{
return route->amount();
}
}
return nullptr;
}
void Mixer::mixToChannel(const AudioBuffer& buffer, mix_ch_t dest)
{
const auto channel = m_mixerChannels[dest];
if (!channel->m_muteModel.value())
{
channel->m_lock.lock();
MixHelpers::add(channel->m_buffer.groupBuffers(0), buffer.groupBuffers(0));
// Copy the planar buffer to the temporary interleaved buffer so they stay in sync
toInterleaved(channel->m_buffer.groupBuffers(0), channel->m_buffer.interleavedBuffer());
channel->m_buffer.mixSilenceFlags(buffer);
channel->m_lock.unlock();
}
}
void Mixer::prepareMasterMix()
{
m_mixerChannels[0]->m_buffer.silenceAllChannels();
}
void Mixer::masterMix( SampleFrame* _buf )
{
const int fpp = Engine::audioEngine()->framesPerPeriod();
// add the channels that have no dependencies (no incoming senders, ie.
// no receives) to the jobqueue. The channels that have receives get
// added when their senders get processed, which is detected by
// dependency counting.
// also instantly add all muted channels as they don't need to care
// about their senders, and can just increment the deps of their
// recipients right away.
AudioEngineWorkerThread::resetJobQueue( AudioEngineWorkerThread::JobQueue::OperationMode::Dynamic );
for( MixerChannel * ch : m_mixerChannels )
{
ch->m_muted = ch->m_muteModel.value();
if( ch->m_muted ) // instantly "process" muted channels
{
ch->processed();
ch->done();
}
else if( ch->m_receives.size() == 0 )
{
ch->m_queued = true;
AudioEngineWorkerThread::addJob( ch );
}
}
while (m_mixerChannels[0]->state() != ThreadableJob::ProcessingState::Done)
{
bool found = false;
for( MixerChannel * ch : m_mixerChannels )
{
const auto s = ch->state();
if (s == ThreadableJob::ProcessingState::Queued
|| s == ThreadableJob::ProcessingState::InProgress)
{
found = true;
break;
}
}
if( !found )
{
break;
}
AudioEngineWorkerThread::startAndWaitForJobs();
}
auto buffer = m_mixerChannels[0]->m_buffer.interleavedBuffer().asSampleFrames();
// handle sample-exact data in master volume fader
ValueBuffer * volBuf = m_mixerChannels[0]->m_volumeModel.valueBuffer();
if( volBuf )
{
for( int f = 0; f < fpp; f++ )
{
buffer[f][0] *= volBuf->values()[f];
buffer[f][1] *= volBuf->values()[f];
}
}
const float v = volBuf
? 1.0f
: m_mixerChannels[0]->m_volumeModel.value();
MixHelpers::addSanitizedMultiplied(_buf, buffer.data(), v, fpp);
// clear all channel buffers and
// reset channel process state
for( int i = 0; i < numChannels(); ++i)
{
m_mixerChannels[i]->m_buffer.silenceAllChannels();
m_mixerChannels[i]->reset();
m_mixerChannels[i]->m_queued = false;
m_mixerChannels[i]->m_dependenciesMet = 0;
}
}
void Mixer::clear()
{
while( m_mixerChannels.size() > 1 )
{
deleteChannel(1);
}
clearChannel(0);
}
void Mixer::clearChannel(mix_ch_t index)
{
MixerChannel * ch = m_mixerChannels[index];
ch->m_fxChain.clear();
ch->m_volumeModel.setValue( 1.0f );
ch->m_muteModel.setValue( false );
ch->m_soloModel.setValue( false );
ch->m_name = ( index == 0 ) ? tr( "Master" ) : tr( "Channel %1" ).arg( index );
ch->m_volumeModel.setDisplayName( ch->m_name + ">" + tr( "Volume" ) );
ch->m_muteModel.setDisplayName( ch->m_name + ">" + tr( "Mute" ) );
ch->m_soloModel.setDisplayName( ch->m_name + ">" + tr( "Solo" ) );
ch->setColor(std::nullopt);
// send only to master
if( index > 0)
{
// delete existing sends
while (!ch->m_sends.empty())
{
deleteChannelSend(ch->m_sends.front());
}
// add send to master
createChannelSend( index, 0 );
}
// delete receives
while (!ch->m_receives.empty())
{
deleteChannelSend(ch->m_receives.front());
}
}
void Mixer::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
// save channels
for (auto i = std::size_t{0}; i < m_mixerChannels.size(); ++i)
{
MixerChannel * ch = m_mixerChannels[i];
QDomElement mixch = _doc.createElement( QString( "mixerchannel" ) );
_this.appendChild( mixch );
ch->m_fxChain.saveState( _doc, mixch );
ch->m_volumeModel.saveSettings( _doc, mixch, "volume" );
ch->m_muteModel.saveSettings( _doc, mixch, "muted" );
ch->m_soloModel.saveSettings( _doc, mixch, "soloed" );
mixch.setAttribute("num", static_cast<qulonglong>(i));
mixch.setAttribute( "name", ch->m_name );
if (const auto& color = ch->color()) { mixch.setAttribute("color", color->name()); }
// add the channel sends
for (const auto& send : ch->m_sends)
{
QDomElement sendsDom = _doc.createElement( QString( "send" ) );
mixch.appendChild( sendsDom );
sendsDom.setAttribute("channel", send->receiverIndex());
send->amount()->saveSettings(_doc, sendsDom, "amount");
}
}
}
// make sure we have at least num channels
void Mixer::allocateChannelsTo(int num)
{
if (num <= 0) { return; }
while (static_cast<std::size_t>(num) > m_mixerChannels.size() - 1)
{
createChannel();
// delete the default send to master
deleteChannelSend( m_mixerChannels.size()-1, 0 );
}
}
void Mixer::loadSettings( const QDomElement & _this )
{
clear();
QDomNode node = _this.firstChild();
while( ! node.isNull() )
{
QDomElement mixch = node.toElement();
// index of the channel we are about to load
int num = mixch.attribute( "num" ).toInt();
// allocate enough channels
allocateChannelsTo( num );
m_mixerChannels[num]->m_volumeModel.loadSettings( mixch, "volume" );
m_mixerChannels[num]->m_muteModel.loadSettings( mixch, "muted" );
m_mixerChannels[num]->m_soloModel.loadSettings( mixch, "soloed" );
m_mixerChannels[num]->m_name = mixch.attribute( "name" );
if (mixch.hasAttribute("color"))
{
m_mixerChannels[num]->setColor(QColor{mixch.attribute("color")});
}
m_mixerChannels[num]->m_fxChain.restoreState( mixch.firstChildElement(
m_mixerChannels[num]->m_fxChain.nodeName() ) );
// mixer sends
QDomNodeList chData = mixch.childNodes();
for (auto i = 0; i < chData.length(); ++i)
{
QDomElement chDataItem = chData.at(i).toElement();
if( chDataItem.nodeName() == QString( "send" ) )
{
int sendTo = chDataItem.attribute( "channel" ).toInt();
allocateChannelsTo( sendTo ) ;
MixerRoute * mxr = createChannelSend( num, sendTo, 1.0f );
if( mxr ) mxr->amount()->loadSettings( chDataItem, "amount" );
}
}
node = node.nextSibling();
}
emit dataChanged();
}
void Mixer::validateChannelName( int index, int oldIndex )
{
if( m_mixerChannels[index]->m_name == tr( "Channel %1" ).arg( oldIndex ) )
{
m_mixerChannels[index]->m_name = tr( "Channel %1" ).arg( index );
}
}
bool Mixer::isChannelInUse(int index)
{
assert(index >= 0 && index < m_mixerChannels.size());
// check if the index mixer channel receives audio from any other channel
if (!m_mixerChannels[index]->m_receives.empty()) { return true; }
return m_mixerChannels[index]->useCount() > 0;
}
} // namespace lmms