-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
mixxx.cpp
2380 lines (2065 loc) · 93 KB
/
mixxx.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
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
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
mixxx.cpp - description
-------------------
begin : Mon Feb 18 09:48:17 CET 2002
copyright : (C) 2002 by Tue and Ken Haste Andersen
email :
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <QtDebug>
#include <QTranslator>
#include <QMenu>
#include <QMenuBar>
#include <QFileDialog>
#include <QDesktopWidget>
#include <QDesktopServices>
#include <QUrl>
#include "mixxx.h"
#include "analyserqueue.h"
#include "controlpotmeter.h"
#include "controlobjectslave.h"
#include "deck.h"
#include "defs_urls.h"
#include "dlgabout.h"
#include "dlgpreferences.h"
#include "dlgprefeq.h"
#include "dlgdevelopertools.h"
#include "engine/enginemaster.h"
#include "engine/enginemicrophone.h"
#include "effects/effectsmanager.h"
#include "effects/native/nativebackend.h"
#include "engine/engineaux.h"
#include "library/coverartcache.h"
#include "library/library.h"
#include "library/library_preferences.h"
#include "library/scanner/libraryscanner.h"
#include "library/librarytablemodel.h"
#include "controllers/controllermanager.h"
#include "mixxxkeyboard.h"
#include "playermanager.h"
#include "recording/defs_recording.h"
#include "recording/recordingmanager.h"
#include "shoutcast/shoutcastmanager.h"
#include "skin/legacyskinparser.h"
#include "skin/skinloader.h"
#include "soundmanager.h"
#include "soundmanagerutil.h"
#include "soundsourceproxy.h"
#include "trackinfoobject.h"
#include "upgrade.h"
#include "waveform/waveformwidgetfactory.h"
#include "widget/wwaveformviewer.h"
#include "widget/wwidget.h"
#include "widget/wspinny.h"
#include "sharedglcontext.h"
#include "util/debug.h"
#include "util/statsmanager.h"
#include "util/timer.h"
#include "util/time.h"
#include "util/version.h"
#include "controlpushbutton.h"
#include "util/compatibility.h"
#include "util/sandbox.h"
#include "playerinfo.h"
#include "waveform/guitick.h"
#include "util/math.h"
#include "util/experiment.h"
#include "util/font.h"
#include "skin/launchimage.h"
#ifdef __VINYLCONTROL__
#include "vinylcontrol/defs_vinylcontrol.h"
#include "vinylcontrol/vinylcontrolmanager.h"
#endif
#ifdef __MODPLUG__
#include "dlgprefmodplug.h"
#endif
// static
const int MixxxMainWindow::kMicrophoneCount = 4;
// static
const int MixxxMainWindow::kAuxiliaryCount = 4;
MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args)
: m_pWidgetParent(NULL),
m_pSoundManager(NULL),
m_pRecordingManager(NULL),
#ifdef __SHOUTCAST__
m_pShoutcastManager(NULL),
#endif
m_pControllerManager(NULL),
m_pDeveloperToolsDlg(NULL),
#ifdef __VINYLCONTROL__
m_pShowVinylControl(NULL),
#endif
m_pShowSamplers(NULL),
m_pShowMicrophone(NULL),
m_pShowPreviewDeck(NULL),
m_pShowEffects(NULL),
m_pShowCoverArt(NULL),
m_pPrefDlg(NULL),
m_runtime_timer("MixxxMainWindow::runtime"),
m_cmdLineArgs(args),
m_iNumConfiguredDecks(0) {
logBuildDetails();
initMenuBar();
initializeWindow();
// Check to see if this is the first time this version of Mixxx is run
// after an upgrade and make any needed changes.
m_pUpgrader = new Upgrade;
m_pConfig = m_pUpgrader->versionUpgrade(args.getSettingsPath());
ControlDoublePrivate::setUserConfig(m_pConfig);
// First load launch image to show a the user a quick responds
m_pSkinLoader = new SkinLoader(m_pConfig);
m_pLaunchImage = m_pSkinLoader->loadLaunchImage(this);
m_pWidgetParent = (QWidget*)m_pLaunchImage;
setCentralWidget(m_pWidgetParent);
// move the app in the center of the primary screen
slotToCenterOfPrimaryScreen();
show();
#if defined(Q_WS_X11)
// In asynchronous X11, the window will be mapped to screen
// some time after being asked to show itself on the screen.
extern void qt_x11_wait_for_window_manager(QWidget *mainWin);
qt_x11_wait_for_window_manager(this);
#endif
pApp->processEvents();
initalize(pApp, args);
}
MixxxMainWindow::~MixxxMainWindow() {
delete m_pUpgrader;
// SkinLoader depends on Config;
delete m_pSkinLoader;
}
void MixxxMainWindow::initalize(QApplication* pApp, const CmdlineArgs& args) {
// We use QSet<int> in signals in the library.
qRegisterMetaType<QSet<int> >("QSet<int>");
ScopedTimer t("MixxxMainWindow::MixxxMainWindow");
m_runtime_timer.start();
Time::start();
Sandbox::initialize(QDir(m_pConfig->getSettingsPath()).filePath("sandbox.cfg"));
// Only record stats in developer mode.
if (m_cmdLineArgs.getDeveloper()) {
StatsManager::create();
}
QString resourcePath = m_pConfig->getResourcePath();
initializeTranslations(pApp);
initializeFonts(); // takes a long time
launchProgress(2);
// Set the visibility of tooltips, default "1" = ON
m_toolTipsCfg = m_pConfig->getValueString(ConfigKey("[Controls]", "Tooltips"), "1").toInt();
// Store the path in the config database
m_pConfig->set(ConfigKey("[Config]", "Path"), ConfigValue(resourcePath));
setAttribute(Qt::WA_AcceptTouchEvents);
m_pTouchShift = new ControlPushButton(ConfigKey("[Controls]", "touch_shift"));
// Create the Effects subsystem.
m_pEffectsManager = new EffectsManager(this, m_pConfig);
// Starting the master (mixing of the channels and effects):
m_pEngine = new EngineMaster(m_pConfig, "[Master]", m_pEffectsManager,
true, true);
// Create effect backends. We do this after creating EngineMaster to allow
// effect backends to refer to controls that are produced by the engine.
NativeBackend* pNativeBackend = new NativeBackend(m_pEffectsManager);
m_pEffectsManager->addEffectsBackend(pNativeBackend);
// Sets up the default EffectChains and EffectRacks (long)
m_pEffectsManager->setupDefaults();
launchProgress(8);
// Initialize player device
// while this is created here, setupDevices needs to be called sometime
// after the players are added to the engine (as is done currently) -- bkgood
// (long)
m_pSoundManager = new SoundManager(m_pConfig, m_pEngine);
m_pRecordingManager = new RecordingManager(m_pConfig, m_pEngine);
#ifdef __SHOUTCAST__
m_pShoutcastManager = new ShoutcastManager(m_pConfig, m_pSoundManager);
#endif
launchProgress(11);
// TODO(rryan): Fold microphone and aux creation into a manager
// (e.g. PlayerManager, though they aren't players).
ControlObject* pNumMicrophones = new ControlObject(ConfigKey("[Master]", "num_microphones"));
pNumMicrophones->setParent(this);
for (int i = 0; i < kMicrophoneCount; ++i) {
QString group("[Microphone]");
if (i > 0) {
group = QString("[Microphone%1]").arg(i + 1);
}
ChannelHandleAndGroup channelGroup =
m_pEngine->registerChannelGroup(group);
EngineMicrophone* pMicrophone =
new EngineMicrophone(channelGroup, m_pEffectsManager);
// What should channelbase be?
AudioInput micInput = AudioInput(AudioPath::MICROPHONE, 0, 0, i);
m_pEngine->addChannel(pMicrophone);
m_pSoundManager->registerInput(micInput, pMicrophone);
pNumMicrophones->set(pNumMicrophones->get() + 1);
}
m_pNumAuxiliaries = new ControlObject(ConfigKey("[Master]", "num_auxiliaries"));
m_PassthroughMapper = new QSignalMapper(this);
connect(m_PassthroughMapper, SIGNAL(mapped(int)),
this, SLOT(slotControlPassthrough(int)));
m_AuxiliaryMapper = new QSignalMapper(this);
connect(m_AuxiliaryMapper, SIGNAL(mapped(int)),
this, SLOT(slotControlAuxiliary(int)));
for (int i = 0; i < kAuxiliaryCount; ++i) {
QString group = QString("[Auxiliary%1]").arg(i + 1);
ChannelHandleAndGroup channelGroup = m_pEngine->registerChannelGroup(group);
EngineAux* pAux = new EngineAux(channelGroup, m_pEffectsManager);
// What should channelbase be?
AudioInput auxInput = AudioInput(AudioPath::AUXILIARY, 0, 0, i);
m_pEngine->addChannel(pAux);
m_pSoundManager->registerInput(auxInput, pAux);
m_pNumAuxiliaries->set(m_pNumAuxiliaries->get() + 1);
m_pAuxiliaryPassthrough.push_back(
new ControlObjectSlave(group, "passthrough"));
ControlObjectSlave* auxiliary_passthrough =
m_pAuxiliaryPassthrough.back();
// These non-vinyl passthrough COs have their index offset by the max
// number of vinyl inputs.
m_AuxiliaryMapper->setMapping(auxiliary_passthrough, i);
auxiliary_passthrough->connectValueChanged(m_AuxiliaryMapper,
SLOT(map()));
}
// Do not write meta data back to ID3 when meta data has changed
// Because multiple TrackDao objects can exists for a particular track
// writing meta data may ruin your MP3 file if done simultaneously.
// see Bug #728197
// For safety reasons, we deactivate this feature.
m_pConfig->set(ConfigKey("[Library]","WriteAudioTags"), ConfigValue(0));
// library dies in seemingly unrelated qtsql error about not having a
// sqlite driver if this path doesn't exist. Normally config->Save()
// above would make it but if it doesn't get run for whatever reason
// we get hosed -- bkgood
if (!QDir(args.getSettingsPath()).exists()) {
QDir().mkpath(args.getSettingsPath());
}
// Register TrackPointer as a metatype since we use it in signals/slots
// regularly.
qRegisterMetaType<TrackPointer>("TrackPointer");
m_pGuiTick = new GuiTick();
#ifdef __VINYLCONTROL__
m_pVCManager = new VinylControlManager(this, m_pConfig, m_pSoundManager);
#else
m_pVCManager = NULL;
#endif
// Create the player manager. (long)
m_pPlayerManager = new PlayerManager(m_pConfig, m_pSoundManager,
m_pEffectsManager, m_pEngine);
m_pPlayerManager->addConfiguredDecks();
m_pPlayerManager->addSampler();
m_pPlayerManager->addSampler();
m_pPlayerManager->addSampler();
m_pPlayerManager->addSampler();
m_pPlayerManager->addPreviewDeck();
launchProgress(30);
#ifdef __VINYLCONTROL__
m_pVCManager->init();
#endif
m_pNumDecks = new ControlObjectSlave(ConfigKey("[Master]", "num_decks"));
m_pNumDecks->connectValueChanged(this, SLOT(slotNumDecksChanged(double)));
#ifdef __MODPLUG__
// restore the configuration for the modplug library before trying to load a module
DlgPrefModplug* pModplugPrefs = new DlgPrefModplug(0, m_pConfig);
pModplugPrefs->loadSettings();
pModplugPrefs->applySettings();
delete pModplugPrefs; // not needed anymore
#endif
CoverArtCache::create();
// (long)
m_pLibrary = new Library(this, m_pConfig,
m_pPlayerManager,
m_pRecordingManager);
m_pPlayerManager->bindToLibrary(m_pLibrary);
launchProgress(35);
// Get Music dir
bool hasChanged_MusicDir = false;
QStringList dirs = m_pLibrary->getDirs();
if (dirs.size() < 1) {
// TODO(XXX) this needs to be smarter, we can't distinguish between an empty
// path return value (not sure if this is normally possible, but it is
// possible with the Windows 7 "Music" library, which is what
// QDesktopServices::storageLocation(QDesktopServices::MusicLocation)
// resolves to) and a user hitting 'cancel'. If we get a blank return
// but the user didn't hit cancel, we need to know this and let the
// user take some course of action -- bkgood
QString fd = QFileDialog::getExistingDirectory(
this, tr("Choose music library directory"),
QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
if (!fd.isEmpty()) {
// adds Folder to database.
m_pLibrary->slotRequestAddDir(fd);
hasChanged_MusicDir = true;
}
}
// Call inits to invoke all other construction parts
// Intialize default BPM system values
if (m_pConfig->getValueString(ConfigKey("[BPM]", "BPMRangeStart"))
.length() < 1) {
m_pConfig->set(ConfigKey("[BPM]", "BPMRangeStart"),ConfigValue(65));
}
if (m_pConfig->getValueString(ConfigKey("[BPM]", "BPMRangeEnd"))
.length() < 1) {
m_pConfig->set(ConfigKey("[BPM]", "BPMRangeEnd"),ConfigValue(135));
}
if (m_pConfig->getValueString(ConfigKey("[BPM]", "AnalyzeEntireSong"))
.length() < 1) {
m_pConfig->set(ConfigKey("[BPM]", "AnalyzeEntireSong"),ConfigValue(1));
}
// Initialize controller sub-system,
// but do not set up controllers until the end of the application startup
// (long)
qDebug() << "Creating ControllerManager";
m_pControllerManager = new ControllerManager(m_pConfig);
launchProgress(47);
WaveformWidgetFactory::create(); // takes a long time
WaveformWidgetFactory::instance()->startVSync(this);
WaveformWidgetFactory::instance()->setConfig(m_pConfig);
launchProgress(52);
connect(this, SIGNAL(newSkinLoaded()),
this, SLOT(onNewSkinLoaded()));
connect(this, SIGNAL(newSkinLoaded()),
m_pLibrary, SLOT(onSkinLoadFinished()));
// Initialize preference dialog
m_pPrefDlg = new DlgPreferences(this, m_pSkinLoader, m_pSoundManager, m_pPlayerManager,
m_pControllerManager, m_pVCManager, m_pEffectsManager,
m_pConfig, m_pLibrary);
m_pPrefDlg->setWindowIcon(QIcon(":/images/ic_mixxx_window.png"));
m_pPrefDlg->setHidden(true);
launchProgress(60);
initializeKeyboard();
initActions();
populateMenuBar(); // already inited in the constructor
// Before creating the first skin we need to create a QGLWidget so that all
// the QGLWidget's we create can use it as a shared QGLContext.
QGLWidget* pContextWidget = new QGLWidget(this);
pContextWidget->hide();
SharedGLContext::setWidget(pContextWidget);
launchProgress(63);
QWidget* oldWidget = m_pWidgetParent;
// Load skin to a QWidget that we set as the central widget. Assignment
// intentional in next line.
if (!(m_pWidgetParent = m_pSkinLoader->loadDefaultSkin(this, m_pKeyboard,
m_pPlayerManager,
m_pControllerManager,
m_pLibrary,
m_pVCManager,
m_pEffectsManager))) {
reportCriticalErrorAndQuit(
"default skin cannot be loaded see <b>mixxx</b> trace for more information.");
m_pWidgetParent = oldWidget;
//TODO (XXX) add dialog to warn user and launch skin choice page
}
// Fake a 100 % progress here.
// At a later place it will newer shown up, since it is
// immediately replaced by the real widget.
launchProgress(100);
// Check direct rendering and warn user if they don't have it
checkDirectRendering();
// Install an event filter to catch certain QT events, such as tooltips.
// This allows us to turn off tooltips.
pApp->installEventFilter(this); // The eventfilter is located in this
// Mixxx class as a callback.
// If we were told to start in fullscreen mode on the command-line or if
// user chose always starts in fullscreen mode, then turn on fullscreen
// mode.
bool fullscreenPref = m_pConfig->getValueString(
ConfigKey("[Config]", "StartInFullscreen"), "0").toInt();
if (args.getStartInFullscreen() || fullscreenPref) {
slotViewFullScreen(true);
}
emit(newSkinLoaded());
// Wait until all other ControlObjects are set up before initializing
// controllers
m_pControllerManager->setUpDevices();
// Scan the library for new files and directories
bool rescan = m_pConfig->getValueString(
ConfigKey("[Library]","RescanOnStartup")).toInt();
// rescan the library if we get a new plugin
QSet<QString> prev_plugins = QSet<QString>::fromList(
m_pConfig->getValueString(
ConfigKey("[Library]", "SupportedFileExtensions")).split(
",", QString::SkipEmptyParts));
QSet<QString> curr_plugins = QSet<QString>::fromList(
SoundSourceProxy::supportedFileExtensions());
rescan = rescan || (prev_plugins != curr_plugins);
m_pConfig->set(ConfigKey("[Library]", "SupportedFileExtensions"),
QStringList(SoundSourceProxy::supportedFileExtensions()).join(","));
// Scan the library directory. Initialize this after the skinloader has
// loaded a skin, see Bug #1047435
m_pLibraryScanner = new LibraryScanner(this,
m_pLibrary->getTrackCollection(),
m_pConfig);
connect(m_pLibraryScanner, SIGNAL(scanFinished()),
this, SLOT(slotEnableRescanLibraryAction()));
// Refresh the library models when the library (re)scan is finished.
connect(m_pLibraryScanner, SIGNAL(scanFinished()),
m_pLibrary, SLOT(slotRefreshLibraryModels()));
if (rescan || hasChanged_MusicDir || m_pUpgrader->rescanLibrary()) {
m_pLibraryScanner->scan();
}
slotNumDecksChanged(m_pNumDecks->get());
// Try open player device If that fails, the preference panel is opened.
int setupDevices = m_pSoundManager->setupDevices();
unsigned int numDevices = m_pSoundManager->getConfig().getOutputs().count();
// test for at least one out device, if none, display another dlg that
// says "mixxx will barely work with no outs"
while (setupDevices != OK || numDevices == 0) {
// Exit when we press the Exit button in the noSoundDlg dialog
// only call it if setupDevices != OK
if (setupDevices != OK) {
if (noSoundDlg() != 0) {
exit(0);
}
} else if (numDevices == 0) {
bool continueClicked = false;
int noOutput = noOutputDlg(&continueClicked);
if (continueClicked) break;
if (noOutput != 0) {
exit(0);
}
}
numDevices = m_pSoundManager->getConfig().getOutputs().count();
}
// Load tracks in args.qlMusicFiles (command line arguments) into player
// 1 and 2:
const QList<QString>& musicFiles = args.getMusicFiles();
for (int i = 0; i < (int)m_pPlayerManager->numDecks()
&& i < musicFiles.count(); ++i) {
if (SoundSourceProxy::isFilenameSupported(musicFiles.at(i))) {
m_pPlayerManager->slotLoadToDeck(musicFiles.at(i), i+1);
}
}
connect(&PlayerInfo::instance(),
SIGNAL(currentPlayingTrackChanged(TrackPointer)),
this, SLOT(slotUpdateWindowTitle(TrackPointer)));
// this has to be after the OpenGL widgets are created or depending on a
// million different variables the first waveform may be horribly
// corrupted. See bug 521509 -- bkgood ?? -- vrince
setCentralWidget(m_pWidgetParent);
// The old central widget is automatically disposed.
}
void MixxxMainWindow::finalize() {
// TODO(rryan): Get rid of QTime here.
QTime qTime;
qTime.start();
Timer t("MixxxMainWindow::~finalize");
t.start();
setCentralWidget(NULL);
qDebug() << "Destroying MixxxMainWindow";
qDebug() << "save config " << qTime.elapsed();
m_pConfig->Save();
// SoundManager depend on Engine and Config
qDebug() << "delete soundmanager " << qTime.elapsed();
delete m_pSoundManager;
// GUI depends on MixxxKeyboard, PlayerManager, Library
qDebug() << "delete view " << qTime.elapsed();
delete m_pWidgetParent;
// ControllerManager depends on Config
qDebug() << "delete ControllerManager " << qTime.elapsed();
delete m_pControllerManager;
#ifdef __VINYLCONTROL__
// VinylControlManager depends on a CO the engine owns
// (vinylcontrol_enabled in VinylControlControl)
qDebug() << "delete vinylcontrolmanager " << qTime.elapsed();
delete m_pVCManager;
qDeleteAll(m_pVinylControlEnabled);
delete m_VCControlMapper;
delete m_VCCheckboxMapper;
#endif
delete m_PassthroughMapper;
delete m_AuxiliaryMapper;
delete m_TalkoverMapper;
// LibraryScanner depends on Library
qDebug() << "delete library scanner " << qTime.elapsed();
delete m_pLibraryScanner;
// CoverArtCache is fairly independent of everything else.
CoverArtCache::destroy();
// Delete the library after the view so there are no dangling pointers to
// the data models.
// Depends on RecordingManager and PlayerManager
qDebug() << "delete library " << qTime.elapsed();
delete m_pLibrary;
// PlayerManager depends on Engine, SoundManager, VinylControlManager, and Config
qDebug() << "delete playerManager " << qTime.elapsed();
delete m_pPlayerManager;
// RecordingManager depends on config, engine
qDebug() << "delete RecordingManager " << qTime.elapsed();
delete m_pRecordingManager;
#ifdef __SHOUTCAST__
// ShoutcastManager depends on config, engine
qDebug() << "delete ShoutcastManager " << qTime.elapsed();
delete m_pShoutcastManager;
#endif
// Delete ControlObjectSlaves we created for checking passthrough and
// talkover status.
qDeleteAll(m_pAuxiliaryPassthrough);
qDeleteAll(m_pPassthroughEnabled);
qDeleteAll(m_micTalkoverControls);
// EngineMaster depends on Config and m_pEffectsManager.
qDebug() << "delete m_pEngine " << qTime.elapsed();
delete m_pEngine;
qDebug() << "deleting preferences, " << qTime.elapsed();
delete m_pPrefDlg;
// Must delete after EngineMaster and DlgPrefEq.
qDebug() << "deleting effects manager, " << qTime.elapsed();
delete m_pEffectsManager;
delete m_pTouchShift;
PlayerInfo::destroy();
WaveformWidgetFactory::destroy();
delete m_pGuiTick;
delete m_pShowVinylControl;
delete m_pShowSamplers;
delete m_pShowMicrophone;
delete m_pShowPreviewDeck;
delete m_pShowEffects;
delete m_pShowCoverArt;
delete m_pNumAuxiliaries;
delete m_pNumDecks;
// Check for leaked ControlObjects and give warnings.
QList<QSharedPointer<ControlDoublePrivate> > leakedControls;
QList<ConfigKey> leakedConfigKeys;
ControlDoublePrivate::getControls(&leakedControls);
if (leakedControls.size() > 0) {
qDebug() << "WARNING: The following" << leakedControls.size()
<< "controls were leaked:";
foreach (QSharedPointer<ControlDoublePrivate> pCDP, leakedControls) {
if (pCDP.isNull()) {
continue;
}
ConfigKey key = pCDP->getKey();
qDebug() << key.group << key.item << pCDP->getCreatorCO();
leakedConfigKeys.append(key);
}
// Deleting leaked objects helps to satisfy valgrind.
// These delete calls could cause crashes if a destructor for a control
// we thought was leaked is triggered after this one exits.
// So, only delete so if developer mode is on.
if (CmdlineArgs::Instance().getDeveloper()) {
foreach (ConfigKey key, leakedConfigKeys) {
// A deletion early in the list may trigger a destructor
// for a control later in the list, so we check for a null
// pointer each time.
ControlObject* pCo = ControlObject::getControl(key, false);
if (pCo) {
delete pCo;
}
}
}
leakedControls.clear();
}
// HACK: Save config again. We saved it once before doing some dangerous
// stuff. We only really want to save it here, but the first one was just
// a precaution. The earlier one can be removed when stuff is more stable
// at exit.
m_pConfig->Save();
qDebug() << "delete config " << qTime.elapsed();
Sandbox::shutdown();
ControlDoublePrivate::setUserConfig(NULL);
delete m_pConfig;
delete m_pKeyboard;
delete m_pKbdConfig;
delete m_pKbdConfigEmpty;
t.elapsed(true);
// Report the total time we have been running.
m_runtime_timer.elapsed(true);
StatsManager::destroy();
}
bool MixxxMainWindow::loadTranslations(const QLocale& systemLocale, QString userLocale,
const QString& translation, const QString& prefix,
const QString& translationPath, QTranslator* pTranslator) {
if (userLocale.size() == 0) {
#if QT_VERSION >= 0x040800
QStringList uiLanguages = systemLocale.uiLanguages();
if (uiLanguages.size() > 0 && uiLanguages.first() == "en") {
// Don't bother loading a translation if the first ui-langauge is
// English because the interface is already in English. This fixes
// the case where the user's install of Qt doesn't have an explicit
// English translation file and the fact that we don't ship a
// mixxx_en.qm.
return false;
}
return pTranslator->load(systemLocale, translation, prefix, translationPath);
#else
userLocale = systemLocale.name();
#endif // QT_VERSION
}
return pTranslator->load(translation + prefix + userLocale, translationPath);
}
void MixxxMainWindow::logBuildDetails() {
QString version = Version::version();
QString buildBranch = Version::developmentBranch();
QString buildRevision = Version::developmentRevision();
QString buildFlags = Version::buildFlags();
QStringList buildInfo;
if (!buildBranch.isEmpty() && !buildRevision.isEmpty()) {
buildInfo.append(
QString("git %1 r%2").arg(buildBranch, buildRevision));
} else if (!buildRevision.isEmpty()) {
buildInfo.append(
QString("git r%2").arg(buildRevision));
}
#ifndef DISABLE_BUILDTIME // buildtime=1, on by default
buildInfo.append("built on: " __DATE__ " @ " __TIME__);
#endif
if (!buildFlags.isEmpty()) {
buildInfo.append(QString("flags: %1").arg(buildFlags.trimmed()));
}
QString buildInfoFormatted = QString("(%1)").arg(buildInfo.join("; "));
// This is the first line in mixxx.log
qDebug() << "Mixxx" << version << buildInfoFormatted << "is starting...";
QStringList depVersions = Version::dependencyVersions();
qDebug() << "Library versions:";
foreach (const QString& depVersion, depVersions) {
qDebug() << qPrintable(depVersion);
}
qDebug() << "QDesktopServices::storageLocation(HomeLocation):"
<< QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
qDebug() << "QDesktopServices::storageLocation(DataLocation):"
<< QDesktopServices::storageLocation(QDesktopServices::DataLocation);
qDebug() << "QCoreApplication::applicationDirPath()"
<< QCoreApplication::applicationDirPath();
}
void MixxxMainWindow::initializeWindow() {
// be sure initMenuBar() is called first
QPalette Pal(palette());
// safe default QMenuBar background
QColor MenuBarBackground(m_pMenuBar->palette().color(QPalette::Background));
Pal.setColor(QPalette::Background, QColor(0x202020));
setAutoFillBackground(true);
setPalette(Pal);
// restore default QMenuBar background
Pal.setColor(QPalette::Background, MenuBarBackground);
m_pMenuBar->setPalette(Pal);
setWindowIcon(QIcon(":/images/ic_mixxx_window.png"));
slotUpdateWindowTitle(TrackPointer());
}
void MixxxMainWindow::initializeFonts() {
QDir fontsDir(m_pConfig->getResourcePath());
if (!fontsDir.cd("fonts")) {
qWarning("MixxxMainWindow::initializeFonts: cd fonts failed");
return;
}
QList<QFileInfo> files = fontsDir.entryInfoList(
QDir::NoDotAndDotDot | QDir::Files | QDir::Readable);
foreach (const QFileInfo& file, files) {
const QString& path = file.filePath();
// Skip text files (e.g. license files). For all others we let Qt tell
// us whether the font format is supported since there is no way to
// check other than adding.
if (path.endsWith(".txt", Qt::CaseInsensitive)) {
continue;
}
FontUtils::addFont(path);
}
}
void MixxxMainWindow::initializeTranslations(QApplication* pApp) {
QString resourcePath = m_pConfig->getResourcePath();
QString translationsFolder = resourcePath + "translations/";
// Load Qt base translations
QString userLocale = m_cmdLineArgs.getLocale();
QLocale systemLocale = QLocale::system();
// Attempt to load user locale from config
if (userLocale.isEmpty()) {
userLocale = m_pConfig->getValueString(ConfigKey("[Config]","Locale"));
}
if (userLocale.isEmpty()) {
QLocale::setDefault(QLocale(systemLocale));
} else {
QLocale::setDefault(QLocale(userLocale));
}
// source language
if (userLocale == "en_US") {
return;
}
// Load Qt translations for this locale from the system translation
// path. This is the lowest precedence QTranslator.
QTranslator* qtTranslator = new QTranslator(pApp);
if (loadTranslations(systemLocale, userLocale, "qt", "_",
QLibraryInfo::location(QLibraryInfo::TranslationsPath),
qtTranslator)) {
pApp->installTranslator(qtTranslator);
} else {
delete qtTranslator;
}
// Load Qt translations for this locale from the Mixxx translations
// folder.
QTranslator* mixxxQtTranslator = new QTranslator(pApp);
if (loadTranslations(systemLocale, userLocale, "qt", "_",
translationsFolder,
mixxxQtTranslator)) {
pApp->installTranslator(mixxxQtTranslator);
} else {
delete mixxxQtTranslator;
}
// Load Mixxx specific translations for this locale from the Mixxx
// translations folder.
QTranslator* mixxxTranslator = new QTranslator(pApp);
bool mixxxLoaded = loadTranslations(systemLocale, userLocale, "mixxx", "_",
translationsFolder, mixxxTranslator);
qDebug() << "Loading translations for locale"
<< (userLocale.size() > 0 ? userLocale : systemLocale.name())
<< "from translations folder" << translationsFolder << ":"
<< (mixxxLoaded ? "success" : "fail");
if (mixxxLoaded) {
pApp->installTranslator(mixxxTranslator);
} else {
delete mixxxTranslator;
}
}
void MixxxMainWindow::initializeKeyboard() {
QString resourcePath = m_pConfig->getResourcePath();
// Set the default value in settings file
if (m_pConfig->getValueString(ConfigKey("[Keyboard]","Enabled")).length() == 0)
m_pConfig->set(ConfigKey("[Keyboard]","Enabled"), ConfigValue(1));
// Read keyboard configuration and set kdbConfig object in WWidget
// Check first in user's Mixxx directory
QString userKeyboard = QDir(m_cmdLineArgs.getSettingsPath()).filePath("Custom.kbd.cfg");
//Empty keyboard configuration
m_pKbdConfigEmpty = new ConfigObject<ConfigValueKbd>("");
if (QFile::exists(userKeyboard)) {
qDebug() << "Found and will use custom keyboard preset" << userKeyboard;
m_pKbdConfig = new ConfigObject<ConfigValueKbd>(userKeyboard);
} else {
// Default to the locale for the main input method (e.g. keyboard).
QLocale locale = inputLocale();
// check if a default keyboard exists
QString defaultKeyboard = QString(resourcePath).append("keyboard/");
defaultKeyboard += locale.name();
defaultKeyboard += ".kbd.cfg";
if (!QFile::exists(defaultKeyboard)) {
qDebug() << defaultKeyboard << " not found, using en_US.kbd.cfg";
defaultKeyboard = QString(resourcePath).append("keyboard/").append("en_US.kbd.cfg");
if (!QFile::exists(defaultKeyboard)) {
qDebug() << defaultKeyboard << " not found, starting without shortcuts";
defaultKeyboard = "";
}
}
m_pKbdConfig = new ConfigObject<ConfigValueKbd>(defaultKeyboard);
}
// TODO(XXX) leak pKbdConfig, MixxxKeyboard owns it? Maybe roll all keyboard
// initialization into MixxxKeyboard
// Workaround for today: MixxxKeyboard calls delete
bool keyboardShortcutsEnabled = m_pConfig->getValueString(
ConfigKey("[Keyboard]", "Enabled")) == "1";
m_pKeyboard = new MixxxKeyboard(keyboardShortcutsEnabled ? m_pKbdConfig : m_pKbdConfigEmpty);
}
void toggleVisibility(ConfigKey key, bool enable) {
qDebug() << "Setting visibility for" << key.group << key.item << enable;
ControlObject::set(key, enable ? 1.0 : 0.0);
}
void MixxxMainWindow::slotViewShowSamplers(bool enable) {
toggleVisibility(ConfigKey("[Samplers]", "show_samplers"), enable);
}
void MixxxMainWindow::slotViewShowVinylControl(bool enable) {
toggleVisibility(ConfigKey(VINYL_PREF_KEY, "show_vinylcontrol"), enable);
}
void MixxxMainWindow::slotViewShowMicrophone(bool enable) {
toggleVisibility(ConfigKey("[Microphone]", "show_microphone"), enable);
}
void MixxxMainWindow::slotViewShowPreviewDeck(bool enable) {
toggleVisibility(ConfigKey("[PreviewDeck]", "show_previewdeck"), enable);
}
void MixxxMainWindow::slotViewShowEffects(bool enable) {
toggleVisibility(ConfigKey("[EffectRack1]", "show"), enable);
}
void MixxxMainWindow::slotViewShowCoverArt(bool enable) {
toggleVisibility(ConfigKey("[Library]", "show_coverart"), enable);
}
void MixxxMainWindow::slotViewMaximizeLibrary(bool enable) {
toggleVisibility(ConfigKey("[Master]", "maximize_library"), enable);
}
void setVisibilityOptionState(QAction* pAction, ConfigKey key) {
ControlObject* pVisibilityControl = ControlObject::getControl(key);
pAction->setEnabled(pVisibilityControl != NULL);
pAction->setChecked(pVisibilityControl != NULL ? pVisibilityControl->get() > 0.0 : false);
}
void MixxxMainWindow::updateCheckedMenuAction(QAction* menuAction, ConfigKey key) {
menuAction->blockSignals(true);
menuAction->setChecked(ControlObject::get(key));
menuAction->blockSignals(false);
}
void MixxxMainWindow::slotToggleCheckedVinylControl() {
ConfigKey key(VINYL_PREF_KEY, "show_vinylcontrol");
updateCheckedMenuAction(m_pViewVinylControl, key);
}
void MixxxMainWindow::slotToggleCheckedSamplers() {
ConfigKey key("[Samplers]", "show_samplers");
updateCheckedMenuAction(m_pViewShowSamplers, key);
}
void MixxxMainWindow::slotToggleCheckedMicrophone() {
ConfigKey key("[Microphone]", "show_microphone");
updateCheckedMenuAction(m_pViewShowMicrophone, key);
}
void MixxxMainWindow::slotToggleCheckedPreviewDeck() {
ConfigKey key("[PreviewDeck]", "show_previewdeck");
updateCheckedMenuAction(m_pViewShowPreviewDeck, key);
}
void MixxxMainWindow::slotToggleCheckedEffects() {
ConfigKey key("[EffectRack1]", "show");
updateCheckedMenuAction(m_pViewShowEffects, key);
}
void MixxxMainWindow::slotToggleCheckedCoverArt() {
ConfigKey key("[Library]", "show_coverart");
updateCheckedMenuAction(m_pViewShowCoverArt, key);
}
void MixxxMainWindow::linkSkinWidget(ControlObjectSlave** pCOS,
ConfigKey key, const char* slot) {
if (!*pCOS) {
*pCOS = new ControlObjectSlave(key, this);
(*pCOS)->connectValueChanged(slot);
}
}
void MixxxMainWindow::onNewSkinLoaded() {
#ifdef __VINYLCONTROL__
setVisibilityOptionState(m_pViewVinylControl,
ConfigKey(VINYL_PREF_KEY, "show_vinylcontrol"));
#endif
setVisibilityOptionState(m_pViewShowSamplers,
ConfigKey("[Samplers]", "show_samplers"));
setVisibilityOptionState(m_pViewShowMicrophone,
ConfigKey("[Microphone]", "show_microphone"));
setVisibilityOptionState(m_pViewShowPreviewDeck,
ConfigKey("[PreviewDeck]", "show_previewdeck"));
setVisibilityOptionState(m_pViewShowEffects,
ConfigKey("[EffectRack1]", "show"));
setVisibilityOptionState(m_pViewShowCoverArt,
ConfigKey("[Library]", "show_coverart"));
setVisibilityOptionState(m_pViewMaximizeLibrary,
ConfigKey("[Master]", "maximize_library"));
#ifdef __VINYLCONTROL__