forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasetrackplayer.cpp
690 lines (596 loc) · 24.7 KB
/
basetrackplayer.cpp
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
#include "mixer/basetrackplayer.h"
#include <QMessageBox>
#include "control/controlobject.h"
#include "control/controlpotmeter.h"
#include "effects/effectsmanager.h"
#include "engine/channels/enginedeck.h"
#include "engine/controls/enginecontrol.h"
#include "engine/engine.h"
#include "engine/enginebuffer.h"
#include "engine/enginemaster.h"
#include "engine/sync/enginesync.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "sources/soundsourceproxy.h"
#include "track/beatgrid.h"
#include "track/track.h"
#include "util/compatibility.h"
#include "util/platform.h"
#include "util/sandbox.h"
#include "vinylcontrol/defs_vinylcontrol.h"
#include "waveform/renderers/waveformwidgetrenderer.h"
#include "waveform/visualsmanager.h"
namespace {
const double kNoTrackColor = -1;
const double kShiftCuesOffsetMillis = 10;
const double kShiftCuesOffsetSmallMillis = 1;
inline double trackColorToDouble(mixxx::RgbColor::optional_t color) {
return (color ? static_cast<double>(*color) : kNoTrackColor);
}
}
BaseTrackPlayer::BaseTrackPlayer(QObject* pParent, const QString& group)
: BasePlayer(pParent, group) {
}
BaseTrackPlayerImpl::BaseTrackPlayerImpl(QObject* pParent,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
VisualsManager* pVisualsManager,
EngineChannel::ChannelOrientation defaultOrientation,
const QString& group,
bool defaultMaster,
bool defaultHeadphones,
bool primaryDeck)
: BaseTrackPlayer(pParent, group),
m_pConfig(pConfig),
m_pEngineMaster(pMixingEngine),
m_pLoadedTrack(),
m_replaygainPending(false),
m_pChannelToCloneFrom(nullptr) {
ChannelHandleAndGroup channelGroup =
pMixingEngine->registerChannelGroup(group);
m_pChannel = new EngineDeck(channelGroup, pConfig, pMixingEngine, pEffectsManager, defaultOrientation, primaryDeck);
m_pInputConfigured = std::make_unique<ControlProxy>(group, "input_configured", this);
#ifdef __VINYLCONTROL__
m_pVinylControlEnabled = std::make_unique<ControlProxy>(group, "vinylcontrol_enabled", this);
m_pVinylControlEnabled->connectValueChanged(this, &BaseTrackPlayerImpl::slotVinylControlEnabled);
m_pVinylControlStatus = std::make_unique<ControlProxy>(group, "vinylcontrol_status", this);
#endif
EngineBuffer* pEngineBuffer = m_pChannel->getEngineBuffer();
pMixingEngine->addChannel(m_pChannel);
// Set the routing option defaults for the master and headphone mixes.
m_pChannel->setMaster(defaultMaster);
m_pChannel->setPfl(defaultHeadphones);
// Connect our signals and slots with the EngineBuffer's signals and
// slots. This will let us know when the reader is done loading a track, and
// let us request that the reader load a track.
connect(pEngineBuffer, SIGNAL(trackLoaded(TrackPointer, TrackPointer)),
this, SLOT(slotTrackLoaded(TrackPointer, TrackPointer)));
connect(pEngineBuffer, SIGNAL(trackLoadFailed(TrackPointer, QString)),
this, SLOT(slotLoadFailed(TrackPointer, QString)));
// Get loop point control objects
m_pLoopInPoint = std::make_unique<ControlProxy>(
getGroup(), "loop_start_position", this);
m_pLoopOutPoint = std::make_unique<ControlProxy>(
getGroup(), "loop_end_position", this);
// Duration of the current song, we create this one because nothing else does.
m_pDuration = std::make_unique<ControlObject>(
ConfigKey(getGroup(), "duration"));
// Track color of the current track
m_pTrackColor = std::make_unique<ControlObject>(
ConfigKey(getGroup(), "track_color"));
m_pTrackColor->set(kNoTrackColor);
m_pTrackColor->connectValueChangeRequest(
this, &BaseTrackPlayerImpl::slotTrackColorChangeRequest);
// Deck cloning
m_pCloneFromDeck = std::make_unique<ControlObject>(
ConfigKey(getGroup(), "CloneFromDeck"),
false);
connect(m_pCloneFromDeck.get(),
&ControlObject::valueChanged,
this,
&BaseTrackPlayerImpl::slotCloneFromDeck);
// Waveform controls
// This acts somewhat like a ControlPotmeter, but the normal _up/_down methods
// do not work properly with this CO.
m_pWaveformZoom =
std::make_unique<ControlObject>(ConfigKey(group, "waveform_zoom"));
m_pWaveformZoom->connectValueChangeRequest(this,
&BaseTrackPlayerImpl::slotWaveformZoomValueChangeRequest,
Qt::DirectConnection);
m_pWaveformZoom->set(1.0);
m_pWaveformZoomUp = std::make_unique<ControlPushButton>(
ConfigKey(group, "waveform_zoom_up"));
connect(m_pWaveformZoomUp.get(),
SIGNAL(valueChanged(double)),
this,
SLOT(slotWaveformZoomUp(double)));
m_pWaveformZoomDown = std::make_unique<ControlPushButton>(
ConfigKey(group, "waveform_zoom_down"));
connect(m_pWaveformZoomDown.get(),
SIGNAL(valueChanged(double)),
this,
SLOT(slotWaveformZoomDown(double)));
m_pWaveformZoomSetDefault = std::make_unique<ControlPushButton>(
ConfigKey(group, "waveform_zoom_set_default"));
connect(m_pWaveformZoomSetDefault.get(),
SIGNAL(valueChanged(double)),
this,
SLOT(slotWaveformZoomSetDefault(double)));
m_pPreGain = std::make_unique<ControlProxy>(group, "pregain", this);
m_pShiftCuesEarlier = std::make_unique<ControlPushButton>(
ConfigKey(group, "shift_cues_earlier"));
connect(m_pShiftCuesEarlier.get(),
&ControlObject::valueChanged,
this,
[this](double value) { slotShiftCuesMillisButton(value, -kShiftCuesOffsetMillis); });
m_pShiftCuesLater = std::make_unique<ControlPushButton>(
ConfigKey(group, "shift_cues_later"));
connect(m_pShiftCuesLater.get(),
&ControlObject::valueChanged,
this,
[this](double value) { slotShiftCuesMillisButton(value, kShiftCuesOffsetMillis); });
m_pShiftCuesEarlierSmall = std::make_unique<ControlPushButton>(
ConfigKey(group, "shift_cues_earlier_small"));
connect(m_pShiftCuesEarlierSmall.get(),
&ControlObject::valueChanged,
this,
[this](double value) {
slotShiftCuesMillisButton(value, -kShiftCuesOffsetSmallMillis);
});
m_pShiftCuesLaterSmall = std::make_unique<ControlPushButton>(
ConfigKey(group, "shift_cues_later_small"));
connect(m_pShiftCuesLaterSmall.get(),
&ControlObject::valueChanged,
this,
[this](double value) {
slotShiftCuesMillisButton(value, kShiftCuesOffsetSmallMillis);
});
m_pShiftCues = std::make_unique<ControlObject>(
ConfigKey(group, "shift_cues"));
connect(m_pShiftCues.get(),
&ControlObject::valueChanged,
this,
&BaseTrackPlayerImpl::slotShiftCuesMillis);
// BPM of the current song
m_pFileBPM = std::make_unique<ControlObject>(ConfigKey(group, "file_bpm"));
m_pKey = std::make_unique<ControlProxy>(group, "file_key", this);
m_pReplayGain = std::make_unique<ControlProxy>(group, "replaygain", this);
m_pPlay = std::make_unique<ControlProxy>(group, "play", this);
m_pPlay->connectValueChanged(this, &BaseTrackPlayerImpl::slotPlayToggled);
pVisualsManager->addDeck(group);
}
BaseTrackPlayerImpl::~BaseTrackPlayerImpl() {
unloadTrack();
}
TrackPointer BaseTrackPlayerImpl::loadFakeTrack(bool bPlay, double filebpm) {
TrackPointer pTrack(Track::newTemporary());
pTrack->setAudioProperties(
mixxx::kEngineChannelCount,
mixxx::audio::SampleRate(44100),
mixxx::audio::Bitrate(),
mixxx::Duration::fromSeconds(10));
if (filebpm > 0) {
pTrack->setBpm(filebpm);
}
TrackPointer pOldTrack = m_pLoadedTrack;
m_pLoadedTrack = pTrack;
if (m_pLoadedTrack) {
// Listen for updates to the file's BPM
connect(m_pLoadedTrack.get(),
&Track::bpmUpdated,
m_pFileBPM.get(),
QOverload<double>::of(&ControlObject::set));
connect(m_pLoadedTrack.get(),
&Track::keyUpdated,
m_pKey.get(),
&ControlProxy::set);
// Listen for updates to the file's Replay Gain
connect(m_pLoadedTrack.get(),
&Track::replayGainUpdated,
this,
&BaseTrackPlayerImpl::slotSetReplayGain);
connect(m_pLoadedTrack.get(),
&Track::colorUpdated,
this,
&BaseTrackPlayerImpl::slotSetTrackColor);
}
// Request a new track from EngineBuffer
EngineBuffer* pEngineBuffer = m_pChannel->getEngineBuffer();
pEngineBuffer->loadFakeTrack(pTrack, bPlay);
// await slotTrackLoaded()/slotLoadFailed()
emit loadingTrack(pTrack, pOldTrack);
return pTrack;
}
void BaseTrackPlayerImpl::loadTrack(TrackPointer pTrack) {
DEBUG_ASSERT(!m_pLoadedTrack);
m_pLoadedTrack = std::move(pTrack);
if (!m_pLoadedTrack) {
// nothing to
return;
}
// Clear loop
// It seems that the trick is to first clear the loop out point, and then
// the loop in point. If we first clear the loop in point, the loop out point
// does not get cleared.
m_pLoopOutPoint->set(kNoTrigger);
m_pLoopInPoint->set(kNoTrigger);
// The loop in and out points must be set here and not in slotTrackLoaded
// so LoopingControl::trackLoaded can access them.
if (!m_pChannelToCloneFrom) {
const QList<CuePointer> trackCues(m_pLoadedTrack->getCuePoints());
QListIterator<CuePointer> it(trackCues);
CuePointer pLoopCue;
// Restore loop from the first loop cue with minimum hotcue number.
// For the volatile "most recent loop" the hotcue number will be -1.
// If no such loop exists, restore a saved loop cue.
while (it.hasNext()) {
CuePointer pCue(it.next());
if (pCue->getType() != mixxx::CueType::Loop) {
continue;
}
if (pLoopCue && pLoopCue->getHotCue() <= pCue->getHotCue()) {
continue;
}
pLoopCue = pCue;
}
if (pLoopCue) {
double loopStart = pLoopCue->getPosition();
double loopEnd = loopStart + pLoopCue->getLength();
if (loopStart != kNoTrigger && loopEnd != kNoTrigger && loopStart <= loopEnd) {
m_pLoopInPoint->set(loopStart);
m_pLoopOutPoint->set(loopEnd);
}
}
} else {
// copy loop in and out points from other deck because any new loops
// won't be saved yet
m_pLoopInPoint->set(ControlObject::get(
ConfigKey(m_pChannelToCloneFrom->getGroup(), "loop_start_position")));
m_pLoopOutPoint->set(ControlObject::get(
ConfigKey(m_pChannelToCloneFrom->getGroup(), "loop_end_position")));
}
connectLoadedTrack();
}
TrackPointer BaseTrackPlayerImpl::unloadTrack() {
if (!m_pLoadedTrack) {
// nothing to do
return TrackPointer();
}
// Save the loops that are currently set in a loop cue. If no loop cue is
// currently on the track, then create a new one.
double loopStart = m_pLoopInPoint->get();
double loopEnd = m_pLoopOutPoint->get();
if (loopStart != kNoTrigger && loopEnd != kNoTrigger && loopStart <= loopEnd) {
CuePointer pLoopCue;
QList<CuePointer> cuePoints(m_pLoadedTrack->getCuePoints());
QListIterator<CuePointer> it(cuePoints);
while (it.hasNext()) {
CuePointer pCue(it.next());
if (pCue->getType() == mixxx::CueType::Loop && pCue->getHotCue() == Cue::kNoHotCue) {
pLoopCue = pCue;
break;
}
}
if (!pLoopCue) {
pLoopCue = m_pLoadedTrack->createAndAddCue();
pLoopCue->setType(mixxx::CueType::Loop);
}
pLoopCue->setStartPosition(loopStart);
pLoopCue->setEndPosition(loopEnd);
}
disconnectLoadedTrack();
// Do not reset m_pReplayGain here, because the track might be still
// playing and the last buffer will be processed.
m_pPlay->set(0.0);
TrackPointer pUnloadedTrack(std::move(m_pLoadedTrack));
DEBUG_ASSERT(!m_pLoadedTrack);
return pUnloadedTrack;
}
void BaseTrackPlayerImpl::connectLoadedTrack() {
connect(m_pLoadedTrack.get(),
&Track::bpmUpdated,
m_pFileBPM.get(),
QOverload<double>::of(&ControlObject::set));
connect(m_pLoadedTrack.get(),
&Track::keyUpdated,
m_pKey.get(),
&ControlProxy::set);
connect(m_pLoadedTrack.get(),
&Track::replayGainUpdated,
this,
&BaseTrackPlayerImpl::slotSetReplayGain);
connect(m_pLoadedTrack.get(),
&Track::colorUpdated,
this,
&BaseTrackPlayerImpl::slotSetTrackColor);
}
void BaseTrackPlayerImpl::disconnectLoadedTrack() {
// WARNING: Never. Ever. call bare disconnect() on an object. Mixxx
// relies on signals and slots to get tons of things done. Don't
// randomly disconnect things.
disconnect(m_pLoadedTrack.get(), 0, m_pFileBPM.get(), 0);
disconnect(m_pLoadedTrack.get(), 0, this, 0);
disconnect(m_pLoadedTrack.get(), 0, m_pKey.get(), 0);
}
void BaseTrackPlayerImpl::slotLoadTrack(TrackPointer pNewTrack, bool bPlay) {
qDebug() << "BaseTrackPlayerImpl::slotLoadTrack" << getGroup();
// Before loading the track, ensure we have access. This uses lazy
// evaluation to make sure track isn't NULL before we dereference it.
if (pNewTrack && !Sandbox::askForAccess(pNewTrack->getCanonicalLocation())) {
// We don't have access.
return;
}
auto pOldTrack = unloadTrack();
loadTrack(pNewTrack);
// Request a new track from EngineBuffer
EngineBuffer* pEngineBuffer = m_pChannel->getEngineBuffer();
pEngineBuffer->loadTrack(pNewTrack, bPlay);
// await slotTrackLoaded()/slotLoadFailed()
emit loadingTrack(pNewTrack, pOldTrack);
}
void BaseTrackPlayerImpl::slotLoadFailed(TrackPointer pTrack, QString reason) {
// Note: This slot can be a load failure from the current track or a
// a delayed signal from a previous load.
// We have probably received a slotTrackLoaded signal, of an old track that
// was loaded before. Here we must unload the
// We must unload the track m_pLoadedTrack as well
if (pTrack == m_pLoadedTrack) {
qDebug() << "Failed to load track" << pTrack->getFileInfo() << reason;
slotTrackLoaded(TrackPointer(), pTrack);
} else if (pTrack) {
qDebug() << "Stray failed to load track" << pTrack->getFileInfo() << reason;
} else {
qDebug() << "Failed to load track (NULL track object)" << reason;
}
m_pChannelToCloneFrom = nullptr;
// Alert user.
QMessageBox::warning(NULL, tr("Couldn't load track."), reason);
}
void BaseTrackPlayerImpl::slotTrackLoaded(TrackPointer pNewTrack,
TrackPointer pOldTrack) {
qDebug() << "BaseTrackPlayerImpl::slotTrackLoaded";
if (!pNewTrack &&
pOldTrack &&
pOldTrack == m_pLoadedTrack) {
// eject Track
unloadTrack();
// Causes the track's data to be saved back to the library database and
// for all the widgets to change the track and update themselves.
emit loadingTrack(pNewTrack, pOldTrack);
m_pDuration->set(0);
m_pFileBPM->set(0);
m_pKey->set(0);
setReplayGain(0);
slotSetTrackColor(std::nullopt);
m_pLoopInPoint->set(kNoTrigger);
m_pLoopOutPoint->set(kNoTrigger);
m_pLoadedTrack.reset();
emit playerEmpty();
} else if (pNewTrack && pNewTrack == m_pLoadedTrack) {
// NOTE(uklotzde): In a previous version track metadata was reloaded
// from the source file at this point again. This is no longer necessary
// since track objects will always be created in a controlled manner
// and populated from the database and their source file as required
// before handing them out to application code.
// TODO(XXX): Don't hesitate to delete the preceding NOTE if you think
// that it is not needed anymore.
// Update the BPM and duration values that are stored in ControlObjects
m_pDuration->set(m_pLoadedTrack->getDuration());
m_pFileBPM->set(m_pLoadedTrack->getBpm());
m_pKey->set(m_pLoadedTrack->getKey());
setReplayGain(m_pLoadedTrack->getReplayGain().getRatio());
slotSetTrackColor(m_pLoadedTrack->getColor());
if(m_pConfig->getValue(
ConfigKey("[Mixer Profile]", "EqAutoReset"), false)) {
if (m_pLowFilter != NULL) {
m_pLowFilter->set(1.0);
}
if (m_pMidFilter != NULL) {
m_pMidFilter->set(1.0);
}
if (m_pHighFilter != NULL) {
m_pHighFilter->set(1.0);
}
if (m_pLowFilterKill != NULL) {
m_pLowFilterKill->set(0.0);
}
if (m_pMidFilterKill != NULL) {
m_pMidFilterKill->set(0.0);
}
if (m_pHighFilterKill != NULL) {
m_pHighFilterKill->set(0.0);
}
}
if (m_pConfig->getValue(
ConfigKey("[Mixer Profile]", "GainAutoReset"), false)) {
m_pPreGain->set(1.0);
}
if (!m_pChannelToCloneFrom) {
int reset = m_pConfig->getValue<int>(
ConfigKey("[Controls]", "SpeedAutoReset"), RESET_PITCH);
if (reset == RESET_SPEED || reset == RESET_PITCH_AND_SPEED) {
// Avoid resetting speed if master sync is enabled and other decks with sync enabled
// are playing, as this would change the speed of already playing decks.
if (!m_pEngineMaster->getEngineSync()->otherSyncedPlaying(getGroup())) {
if (m_pRateRatio != NULL) {
m_pRateRatio->set(1.0);
}
}
}
if (reset == RESET_PITCH || reset == RESET_PITCH_AND_SPEED) {
if (m_pPitchAdjust != NULL) {
m_pPitchAdjust->set(0.0);
}
}
} else {
// perform a clone of the given channel
// copy rate
if (m_pRateRatio != nullptr) {
m_pRateRatio->set(ControlObject::get(ConfigKey(m_pChannelToCloneFrom->getGroup(), "rate_ratio")));
}
// copy pitch
if (m_pPitchAdjust != nullptr) {
m_pPitchAdjust->set(ControlObject::get(ConfigKey(m_pChannelToCloneFrom->getGroup(), "pitch_adjust")));
}
// copy play state
ControlObject::set(ConfigKey(getGroup(), "play"),
ControlObject::get(ConfigKey(m_pChannelToCloneFrom->getGroup(), "play")));
// copy the play position
m_pChannel->getEngineBuffer()->requestClonePosition(m_pChannelToCloneFrom);
// copy the loop state
if (ControlObject::get(ConfigKey(m_pChannelToCloneFrom->getGroup(), "loop_enabled")) == 1.0) {
ControlObject::set(ConfigKey(getGroup(), "reloop_toggle"), 1.0);
}
}
emit newTrackLoaded(m_pLoadedTrack);
} else {
// this is the result from an outdated load or unload signal
// A new load is already pending
// Ignore this signal and wait for the new one
qDebug() << "stray BaseTrackPlayerImpl::slotTrackLoaded()";
}
m_pChannelToCloneFrom = nullptr;
// Update the PlayerInfo class that is used in EngineBroadcast to replace
// the metadata of a stream
PlayerInfo::instance().setTrackInfo(getGroup(), m_pLoadedTrack);
}
TrackPointer BaseTrackPlayerImpl::getLoadedTrack() const {
return m_pLoadedTrack;
}
void BaseTrackPlayerImpl::slotCloneDeck() {
Syncable* syncable = m_pEngineMaster->getEngineSync()->pickNonSyncSyncTarget(m_pChannel);
slotCloneChannel(syncable->getChannel());
}
void BaseTrackPlayerImpl::slotCloneFromGroup(const QString& group) {
EngineChannel* pChannel = m_pEngineMaster->getChannel(group);
if (!pChannel) {
return;
}
slotCloneChannel(pChannel);
}
void BaseTrackPlayerImpl::slotCloneFromDeck(double d) {
int deck = std::lround(d);
if (deck < 1) {
slotCloneDeck();
} else {
slotCloneFromGroup(PlayerManager::groupForDeck(deck-1));
}
}
void BaseTrackPlayerImpl::slotCloneChannel(EngineChannel* pChannel) {
// don't clone from ourselves
if (pChannel == m_pChannel) {
return;
}
m_pChannelToCloneFrom = pChannel;
if (!m_pChannelToCloneFrom) {
return;
}
TrackPointer pTrack = m_pChannelToCloneFrom->getEngineBuffer()->getLoadedTrack();
if (!pTrack) {
m_pChannelToCloneFrom = nullptr;
return;
}
slotLoadTrack(pTrack, false);
}
void BaseTrackPlayerImpl::slotSetReplayGain(mixxx::ReplayGain replayGain) {
// Do not change replay gain when track is playing because
// this may lead to an unexpected volume change
if (m_pPlay->get() == 0.0) {
setReplayGain(replayGain.getRatio());
} else {
m_replaygainPending = true;
}
}
void BaseTrackPlayerImpl::slotSetTrackColor(mixxx::RgbColor::optional_t color) {
m_pTrackColor->forceSet(trackColorToDouble(color));
}
void BaseTrackPlayerImpl::slotTrackColorChangeRequest(double v) {
if (!m_pLoadedTrack) {
return;
}
mixxx::RgbColor::optional_t color = std::nullopt;
if (v != kNoTrackColor) {
auto colorCode = static_cast<mixxx::RgbColor::code_t>(v);
if (!mixxx::RgbColor::isValidCode(colorCode)) {
return;
}
color = mixxx::RgbColor::optional(colorCode);
}
m_pTrackColor->setAndConfirm(trackColorToDouble(color));
m_pLoadedTrack->setColor(color);
}
void BaseTrackPlayerImpl::slotPlayToggled(double v) {
if (!v && m_replaygainPending) {
setReplayGain(m_pLoadedTrack->getReplayGain().getRatio());
}
}
EngineDeck* BaseTrackPlayerImpl::getEngineDeck() const {
return m_pChannel;
}
void BaseTrackPlayerImpl::setupEqControls() {
const QString group = getGroup();
m_pLowFilter = std::make_unique<ControlProxy>(group, "filterLow", this);
m_pMidFilter = std::make_unique<ControlProxy>(group, "filterMid", this);
m_pHighFilter = std::make_unique<ControlProxy>(group, "filterHigh", this);
m_pLowFilterKill = std::make_unique<ControlProxy>(group, "filterLowKill", this);
m_pMidFilterKill = std::make_unique<ControlProxy>(group, "filterMidKill", this);
m_pHighFilterKill = std::make_unique<ControlProxy>(group, "filterHighKill", this);
m_pRateRatio = std::make_unique<ControlProxy>(group, "rate_ratio", this);
m_pPitchAdjust = std::make_unique<ControlProxy>(group, "pitch_adjust", this);
}
void BaseTrackPlayerImpl::slotVinylControlEnabled(double v) {
#ifdef __VINYLCONTROL__
bool configured = m_pInputConfigured->toBool();
bool vinylcontrol_enabled = v > 0.0;
// Warn the user if they try to enable vinyl control on a player with no
// configured input.
if (!configured && vinylcontrol_enabled) {
m_pVinylControlEnabled->set(0.0);
m_pVinylControlStatus->set(VINYL_STATUS_DISABLED);
emit noVinylControlInputConfigured();
}
#endif
}
void BaseTrackPlayerImpl::slotWaveformZoomValueChangeRequest(double v) {
if (v <= WaveformWidgetRenderer::s_waveformMaxZoom
&& v >= WaveformWidgetRenderer::s_waveformMinZoom) {
m_pWaveformZoom->setAndConfirm(v);
}
}
void BaseTrackPlayerImpl::slotWaveformZoomUp(double pressed) {
if (pressed <= 0.0) {
return;
}
m_pWaveformZoom->set(m_pWaveformZoom->get() + 1.0);
}
void BaseTrackPlayerImpl::slotWaveformZoomDown(double pressed) {
if (pressed <= 0.0) {
return;
}
m_pWaveformZoom->set(m_pWaveformZoom->get() - 1.0);
}
void BaseTrackPlayerImpl::slotWaveformZoomSetDefault(double pressed) {
if (pressed <= 0.0) {
return;
}
double defaultZoom = m_pConfig->getValue(ConfigKey("[Waveform]","DefaultZoom"),
WaveformWidgetRenderer::s_waveformDefaultZoom);
m_pWaveformZoom->set(defaultZoom);
}
void BaseTrackPlayerImpl::slotShiftCuesMillis(double milliseconds) {
if (!m_pLoadedTrack) {
return;
}
m_pLoadedTrack->shiftCuePositionsMillis(milliseconds);
}
void BaseTrackPlayerImpl::slotShiftCuesMillisButton(double value, double milliseconds) {
if (value <= 0) {
return;
}
slotShiftCuesMillis(milliseconds);
}
void BaseTrackPlayerImpl::setReplayGain(double value) {
m_pReplayGain->set(value);
m_replaygainPending = false;
}