-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
mixxx.cpp
1770 lines (1538 loc) · 63.4 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 "mixxx.h"
#include <QDesktopServices>
#include <QFileDialog>
#include <QGLFormat>
#include <QGLWidget>
#include <QGuiApplication>
#include <QInputMethod>
#include <QLocale>
#include <QScreen>
#include <QStandardPaths>
#include <QUrl>
#include <QtDebug>
#include "defs_urls.h"
#include "dialog/dlgabout.h"
#include "dialog/dlgdevelopertools.h"
#include "effects/builtin/builtinbackend.h"
#include "effects/effectsmanager.h"
#include "engine/enginemaster.h"
#include "moc_mixxx.cpp"
#include "preferences/constants.h"
#include "preferences/dialog/dlgprefeq.h"
#include "preferences/dialog/dlgpreferences.h"
#ifdef __LILV__
#include "effects/lv2/lv2backend.h"
#endif
#include "broadcast/broadcastmanager.h"
#include "control/controlpushbutton.h"
#include "controllers/controllermanager.h"
#include "controllers/keyboard/keyboardeventfilter.h"
#include "database/mixxxdb.h"
#include "library/coverartcache.h"
#include "library/library.h"
#include "library/library_preferences.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "preferences/settingsmanager.h"
#include "recording/recordingmanager.h"
#include "skin/legacy/launchimage.h"
#include "skin/legacy/legacyskinparser.h"
#include "skin/skinloader.h"
#include "soundio/soundmanager.h"
#include "soundio/soundmanagerconfig.h"
#include "sources/soundsourceproxy.h"
#include "track/track.h"
#include "util/db/dbconnectionpooled.h"
#include "util/debug.h"
#include "util/experiment.h"
#include "util/font.h"
#include "util/logger.h"
#include "util/math.h"
#include "util/sandbox.h"
#include "util/screensaver.h"
#include "util/statsmanager.h"
#include "util/time.h"
#include "util/timer.h"
#include "util/translations.h"
#include "util/versionstore.h"
#include "util/widgethelper.h"
#include "waveform/guitick.h"
#include "waveform/sharedglcontext.h"
#include "waveform/visualsmanager.h"
#include "waveform/waveformwidgetfactory.h"
#include "widget/wmainmenubar.h"
#ifdef __VINYLCONTROL__
#include "vinylcontrol/vinylcontrolmanager.h"
#endif
#ifdef __MODPLUG__
#include "preferences/dialog/dlgprefmodplug.h"
#endif
#if defined(Q_OS_LINUX)
#include <QtX11Extras/QX11Info>
#include <X11/Xlib.h>
#include <X11/Xlibint.h>
// Xlibint.h predates C++ and defines macros which conflict
// with references to std::max and std::min
#undef max
#undef min
#endif
namespace {
const mixxx::Logger kLogger("MixxxMainWindow");
// hack around https://gitlab.freedesktop.org/xorg/lib/libx11/issues/25
// https://bugs.launchpad.net/mixxx/+bug/1805559
#if defined(Q_OS_LINUX)
typedef Bool (*WireToErrorType)(Display*, XErrorEvent*, xError*);
const int NUM_HANDLERS = 256;
WireToErrorType __oldHandlers[NUM_HANDLERS] = {nullptr};
Bool __xErrorHandler(Display* display, XErrorEvent* event, xError* error) {
// Call any previous handler first in case it needs to do real work.
auto code = static_cast<int>(event->error_code);
if (__oldHandlers[code] != nullptr) {
__oldHandlers[code](display, event, error);
}
// Always return false so the error does not get passed to the normal
// application defined handler.
return False;
}
#endif
inline QLocale inputLocale() {
// Use the default config for local keyboard
QInputMethod* pInputMethod = QGuiApplication::inputMethod();
return pInputMethod ? pInputMethod->locale() :
QLocale(QLocale::English);
}
} // anonymous namespace
// static
const int MixxxMainWindow::kMicrophoneCount = 4;
// static
const int MixxxMainWindow::kAuxiliaryCount = 4;
MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args)
: m_pWidgetParent(nullptr),
m_pLaunchImage(nullptr),
m_pEffectsManager(nullptr),
m_pEngine(nullptr),
m_pSkinLoader(nullptr),
m_pSoundManager(nullptr),
m_pPlayerManager(nullptr),
m_pRecordingManager(nullptr),
#ifdef __BROADCAST__
m_pBroadcastManager(nullptr),
#endif
m_pControllerManager(nullptr),
m_pGuiTick(nullptr),
#ifdef __VINYLCONTROL__
m_pVCManager(nullptr),
#endif
m_pKeyboard(nullptr),
m_pLibrary(nullptr),
m_pDeveloperToolsDlg(nullptr),
m_pPrefDlg(nullptr),
m_pKbdConfig(nullptr),
m_pKbdConfigEmpty(nullptr),
m_toolTipsCfg(mixxx::TooltipsPreference::TOOLTIPS_ON),
m_runtime_timer("MixxxMainWindow::runtime"),
m_cmdLineArgs(args),
m_pTouchShift(nullptr) {
m_runtime_timer.start();
mixxx::Time::start();
#ifdef __APPLE__
// TODO: At this point it is too late to provide the same settings path to all components
// and too early to log errors and give users advises in their system language.
// Calling this from main.cpp before the QApplication is initialized may cause a crash
// due to potential QMessageBox invocations within migrateOldSettings().
// Solution: Start Mixxx with default settings, migrate the preferences, and then restart
// immediately.
if (!args.getSettingsPathSet()) {
CmdlineArgs::Instance().setSettingsPath(Sandbox::migrateOldSettings());
}
#endif
QString settingsPath = args.getSettingsPath();
mixxx::LogFlags logFlags = mixxx::LogFlag::LogToFile;
if (args.getDebugAssertBreak()) {
logFlags.setFlag(mixxx::LogFlag::DebugAssertBreak);
}
mixxx::Logging::initialize(
settingsPath,
args.getLogLevel(),
args.getLogFlushLevel(),
logFlags);
VERIFY_OR_DEBUG_ASSERT(SoundSourceProxy::registerProviders()) {
qCritical() << "Failed to register any SoundSource providers";
return;
}
VersionStore::logBuildDetails();
// Only record stats in developer mode.
if (m_cmdLineArgs.getDeveloper()) {
StatsManager::createInstance();
}
m_pSettingsManager = std::make_unique<SettingsManager>(settingsPath);
initializeKeyboard();
installEventFilter(m_pKeyboard);
// Menubar depends on translations.
mixxx::Translations::initializeTranslations(
m_pSettingsManager->settings(), pApp, args.getLocale());
createMenuBar();
m_pMenuBar->hide();
initializeWindow();
// First load launch image to show a the user a quick responds
m_pSkinLoader = new SkinLoader(m_pSettingsManager->settings());
m_pLaunchImage = m_pSkinLoader->loadLaunchImage(this);
m_pWidgetParent = (QWidget*)m_pLaunchImage;
setCentralWidget(m_pWidgetParent);
show();
pApp->processEvents();
initialize(pApp, args);
}
MixxxMainWindow::~MixxxMainWindow() {
delete m_pDeveloperToolsDlg;
finalize();
// SkinLoader depends on Config;
delete m_pSkinLoader;
}
void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) {
ScopedTimer t("MixxxMainWindow::initialize");
#if defined(Q_OS_LINUX)
// XESetWireToError will segfault if running as a Wayland client
if (pApp->platformName() == QLatin1String("xcb")) {
for (auto i = 0; i < NUM_HANDLERS; ++i) {
XESetWireToError(QX11Info::display(), i, &__xErrorHandler);
}
}
#endif
UserSettingsPointer pConfig = m_pSettingsManager->settings();
Sandbox::setPermissionsFilePath(QDir(pConfig->getSettingsPath()).filePath("sandbox.cfg"));
// Turn on fullscreen mode
// if we were told to start in fullscreen mode on the command-line
// or if the user chose to always start in fullscreen mode.
// Remember to refresh the Fullscreen menu item after connectMenuBar()
bool fullscreenPref = pConfig->getValue<bool>(
ConfigKey("[Config]", "StartInFullscreen"));
if (args.getStartInFullscreen() || fullscreenPref) {
showFullScreen();
#ifdef __LINUX__
// If the desktop features a global menubar and we go fullscreen during
// startup, move the menubar to the window like in slotViewFullScreen()
if (m_pMenuBar->isNativeMenuBar()) {
m_pMenuBar->setNativeMenuBar(false);
}
#endif
}
QString resourcePath = pConfig->getResourcePath();
FontUtils::initializeFonts(resourcePath); // takes a long time
launchProgress(2);
// Set the visibility of tooltips, default "1" = ON
m_toolTipsCfg = static_cast<mixxx::TooltipsPreference>(
pConfig->getValue(ConfigKey("[Controls]", "Tooltips"),
static_cast<int>(mixxx::TooltipsPreference::TOOLTIPS_ON)));
m_pTouchShift = new ControlPushButton(ConfigKey("[Controls]", "touch_shift"));
m_pDbConnectionPool = MixxxDb(pConfig).connectionPool();
if (!m_pDbConnectionPool) {
// TODO(XXX) something a little more elegant
exit(-1);
}
// Create a connection for the main thread
m_pDbConnectionPool->createThreadLocalConnection();
if (!initializeDatabase()) {
// TODO(XXX) something a little more elegant
exit(-1);
}
auto pChannelHandleFactory = std::make_shared<ChannelHandleFactory>();
// Create the Effects subsystem.
m_pEffectsManager = new EffectsManager(this, pConfig, pChannelHandleFactory);
// Starting the master (mixing of the channels and effects):
m_pEngine = new EngineMaster(
pConfig,
"[Master]",
m_pEffectsManager,
pChannelHandleFactory,
true);
// Create effect backends. We do this after creating EngineMaster to allow
// effect backends to refer to controls that are produced by the engine.
BuiltInBackend* pBuiltInBackend = new BuiltInBackend(m_pEffectsManager);
m_pEffectsManager->addEffectsBackend(pBuiltInBackend);
#ifdef __LILV__
LV2Backend* pLV2Backend = new LV2Backend(m_pEffectsManager);
m_pEffectsManager->addEffectsBackend(pLV2Backend);
#else
LV2Backend* pLV2Backend = nullptr;
#endif
// Sets up the EffectChains and EffectRacks (long)
m_pEffectsManager->setup();
launchProgress(8);
// Although m_pSoundManager is created here, m_pSoundManager->setupDevices()
// needs to be called after m_pPlayerManager registers sound IO for each EngineChannel.
m_pSoundManager = new SoundManager(pConfig, m_pEngine);
m_pEngine->registerNonEngineChannelSoundIO(m_pSoundManager);
m_pRecordingManager = new RecordingManager(pConfig, m_pEngine);
#ifdef __BROADCAST__
m_pBroadcastManager = new BroadcastManager(
m_pSettingsManager.get(),
m_pSoundManager);
#endif
launchProgress(11);
// Needs to be created before CueControl (decks) and WTrackTableView.
m_pGuiTick = new GuiTick();
m_pVisualsManager = new VisualsManager();
#ifdef __VINYLCONTROL__
m_pVCManager = new VinylControlManager(this, pConfig, m_pSoundManager);
#else
m_pVCManager = NULL;
#endif
// Create the player manager. (long)
m_pPlayerManager = new PlayerManager(pConfig, m_pSoundManager,
m_pEffectsManager, m_pVisualsManager, m_pEngine);
connect(m_pPlayerManager,
&PlayerManager::noMicrophoneInputConfigured,
this,
&MixxxMainWindow::slotNoMicrophoneInputConfigured);
connect(m_pPlayerManager,
&PlayerManager::noAuxiliaryInputConfigured,
this,
&MixxxMainWindow::slotNoAuxiliaryInputConfigured);
connect(m_pPlayerManager,
&PlayerManager::noDeckPassthroughInputConfigured,
this,
&MixxxMainWindow::slotNoDeckPassthroughInputConfigured);
connect(m_pPlayerManager,
&PlayerManager::noVinylControlInputConfigured,
this,
&MixxxMainWindow::slotNoVinylControlInputConfigured);
PlayerInfo::create();
for (int i = 0; i < kMicrophoneCount; ++i) {
m_pPlayerManager->addMicrophone();
}
for (int i = 0; i < kAuxiliaryCount; ++i) {
m_pPlayerManager->addAuxiliary();
}
m_pPlayerManager->addConfiguredDecks();
m_pPlayerManager->addSampler();
m_pPlayerManager->addSampler();
m_pPlayerManager->addSampler();
m_pPlayerManager->addSampler();
m_pPlayerManager->addPreviewDeck();
launchProgress(30);
m_pEffectsManager->loadEffectChains();
#ifdef __VINYLCONTROL__
m_pVCManager->init();
#endif
#ifdef __MODPLUG__
// restore the configuration for the modplug library before trying to load a module
DlgPrefModplug* pModplugPrefs = new DlgPrefModplug(nullptr, pConfig);
pModplugPrefs->loadSettings();
pModplugPrefs->applySettings();
delete pModplugPrefs; // not needed anymore
#endif
CoverArtCache::createInstance();
launchProgress(30);
m_pTrackCollectionManager = new TrackCollectionManager(
this,
pConfig,
m_pDbConnectionPool);
launchProgress(35);
m_pLibrary = new Library(
this,
pConfig,
m_pDbConnectionPool,
m_pTrackCollectionManager,
m_pPlayerManager,
m_pRecordingManager);
// Binding the PlayManager to the Library may already trigger
// loading of tracks which requires that the GlobalTrackCache has
// been created. Otherwise Mixxx might hang when accessing
// the uninitialized singleton instance!
m_pPlayerManager->bindToLibrary(m_pLibrary);
launchProgress(40);
// 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
// QStandardPaths::writableLocation(QStandardPaths::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"),
QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
if (!fd.isEmpty()) {
// adds Folder to database.
m_pLibrary->slotRequestAddDir(fd);
hasChanged_MusicDir = true;
}
}
// Call inits to invoke all other construction parts
// 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(pConfig);
launchProgress(47);
// 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.
if (!CmdlineArgs::Instance().getSafeMode() && QGLFormat::hasOpenGL()) {
QGLFormat glFormat;
glFormat.setDirectRendering(true);
glFormat.setDoubleBuffer(true);
glFormat.setDepth(false);
// Disable waiting for vertical Sync
// This can be enabled when using a single Threads for each QGLContext
// Setting 1 causes QGLContext::swapBuffer to sleep until the next VSync
#if defined(__APPLE__)
// On OS X, syncing to vsync has good performance FPS-wise and
// eliminates tearing.
glFormat.setSwapInterval(1);
#else
// Otherwise, turn VSync off because it could cause horrible FPS on
// Linux.
// TODO(XXX): Make this configurable.
// TODO(XXX): What should we do on Windows?
glFormat.setSwapInterval(0);
#endif
glFormat.setRgba(true);
QGLFormat::setDefaultFormat(glFormat);
QGLWidget* pContextWidget = new QGLWidget(this);
pContextWidget->setGeometry(QRect(0, 0, 3, 3));
pContextWidget->hide();
SharedGLContext::setWidget(pContextWidget);
}
WaveformWidgetFactory::createInstance(); // takes a long time
WaveformWidgetFactory::instance()->setConfig(pConfig);
WaveformWidgetFactory::instance()->startVSync(m_pGuiTick, m_pVisualsManager);
launchProgress(52);
connect(this,
&MixxxMainWindow::skinLoaded,
m_pLibrary,
&Library::onSkinLoadFinished);
connect(this,
&MixxxMainWindow::skinLoaded,
WaveformWidgetFactory::instance(),
&WaveformWidgetFactory::slotSkinLoaded);
// Inhibit the screensaver if the option is set. (Do it before creating the preferences dialog)
int inhibit = pConfig->getValue<int>(ConfigKey("[Config]","InhibitScreensaver"),-1);
if (inhibit == -1) {
inhibit = static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_ON);
pConfig->setValue<int>(ConfigKey("[Config]","InhibitScreensaver"), inhibit);
}
m_inhibitScreensaver = static_cast<mixxx::ScreenSaverPreference>(inhibit);
if (m_inhibitScreensaver == mixxx::ScreenSaverPreference::PREVENT_ON) {
mixxx::ScreenSaverHelper::inhibit();
}
// Initialize preference dialog
m_pPrefDlg = new DlgPreferences(
this,
m_pSkinLoader,
m_pSoundManager,
m_pPlayerManager,
m_pControllerManager,
m_pVCManager,
pLV2Backend,
m_pEffectsManager,
m_pSettingsManager.get(),
m_pLibrary);
m_pPrefDlg->setWindowIcon(QIcon(MIXXX_ICON_PATH));
m_pPrefDlg->setHidden(true);
launchProgress(60);
// Connect signals to the menubar. Should be done before emit newSkinLoaded.
connectMenuBar();
// Refresh the Fullscreen checkbox for the case we went fullscreen earlier
emit fullScreenChanged(isFullScreen());
launchProgress(63);
QWidget* oldWidget = m_pWidgetParent;
// Load default styles that can be overridden by skins
QFile file(":/skins/default.qss");
if (file.open(QIODevice::ReadOnly)) {
QByteArray fileBytes = file.readAll();
QString style = QString::fromLocal8Bit(fileBytes);
setStyleSheet(style);
} else {
qWarning() << "Failed to load default skin styles!";
}
// Load skin to a QWidget that we set as the central widget. Assignment
// intentional in next line.
m_pWidgetParent = m_pSkinLoader->loadConfiguredSkin(this,
&m_skinCreatedControls,
m_pKeyboard,
m_pPlayerManager,
m_pControllerManager,
m_pLibrary,
m_pVCManager,
m_pEffectsManager,
m_pRecordingManager);
if (!m_pWidgetParent) {
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
} else {
m_pMenuBar->setStyleSheet(m_pWidgetParent->styleSheet());
}
// 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
if (!CmdlineArgs::Instance().getSafeMode()) {
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.
emit skinLoaded();
// Wait until all other ControlObjects are set up before initializing
// controllers
m_pControllerManager->setUpDevices();
// Scan the library for new files and directories
bool rescan = pConfig->getValue<bool>(
ConfigKey("[Library]","RescanOnStartup"));
// rescan the library if we get a new plugin
QList<QString> prev_plugins_list =
pConfig->getValueString(
ConfigKey("[Library]", "SupportedFileExtensions"))
.split(',',
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
Qt::SkipEmptyParts);
#else
QString::SkipEmptyParts);
#endif
// TODO: QSet<T>::fromList(const QList<T>&) is deprecated and should be
// replaced with QSet<T>(list.begin(), list.end()).
// However, the proposed alternative has just been introduced in Qt
// 5.14. Until the minimum required Qt version of Mixxx is increased,
// we need a version check here
QSet<QString> prev_plugins =
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QSet<QString>(prev_plugins_list.begin(), prev_plugins_list.end());
#else
QSet<QString>::fromList(prev_plugins_list);
#endif
const QList<QString> curr_plugins_list = SoundSourceProxy::getSupportedFileExtensions();
QSet<QString> curr_plugins =
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QSet<QString>(curr_plugins_list.begin(), curr_plugins_list.end());
#else
QSet<QString>::fromList(curr_plugins_list);
#endif
rescan = rescan || (prev_plugins != curr_plugins);
pConfig->set(ConfigKey("[Library]", "SupportedFileExtensions"), curr_plugins_list.join(","));
// Scan the library directory. Do this after the skinloader has
// loaded a skin, see Bug #1047435
if (rescan || hasChanged_MusicDir || m_pSettingsManager->shouldRescanLibrary()) {
m_pTrackCollectionManager->startLibraryScan();
}
// This has to be done before m_pSoundManager->setupDevices()
// https://bugs.launchpad.net/mixxx/+bug/1758189
m_pPlayerManager->loadSamplers();
// Sound hardware setup
// Try to open configured devices. If that fails, display dialogs
// that allow to either retry, reconfigure devices or exit.
bool retryClicked;
do {
retryClicked = false;
SoundDeviceError result = m_pSoundManager->setupDevices();
if (result == SOUNDDEVICE_ERROR_DEVICE_COUNT ||
result == SOUNDDEVICE_ERROR_EXCESSIVE_OUTPUT_CHANNEL) {
if (soundDeviceBusyDlg(&retryClicked) != QDialog::Accepted) {
exit(0);
}
} else if (result != SOUNDDEVICE_ERROR_OK) {
if (soundDeviceErrorMsgDlg(result, &retryClicked) !=
QDialog::Accepted) {
exit(0);
}
}
} while (retryClicked);
// Test for at least one output device. If none, display another dialog
// that says "mixxx will barely work with no outs".
// In case of persisting errors, the user has already received a message
// above. So we can just check the output count here.
while (m_pSoundManager->getConfig().getOutputs().count() == 0) {
// Exit when we press the Exit button in the noSoundDlg dialog
// only call it if result != OK
bool continueClicked = false;
if (noOutputDlg(&continueClicked) != QDialog::Accepted) {
exit(0);
}
if (continueClicked) {
break;
}
}
// The user has either reconfigured devices or accepted no outputs,
// so it's now safe to write the new config to disk.
m_pSoundManager->getConfig().writeToDisk();
// 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(),
&PlayerInfo::currentPlayingTrackChanged,
this,
&MixxxMainWindow::slotUpdateWindowTitle);
connect(&PlayerInfo::instance(),
&PlayerInfo::currentPlayingDeckChanged,
this,
&MixxxMainWindow::slotChangedPlayingDeck);
// 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);
// Show the menubar after the launch image is replaced by the skin widget,
// otherwise it would shift the launch image shortly before the skin is visible.
m_pMenuBar->show();
// The launch image widget is automatically disposed, but we still have a
// pointer to it.
m_pLaunchImage = nullptr;
}
void MixxxMainWindow::finalize() {
Timer t("MixxxMainWindow::finalize");
t.start();
if (m_inhibitScreensaver != mixxx::ScreenSaverPreference::PREVENT_OFF) {
mixxx::ScreenSaverHelper::uninhibit();
}
// Stop all pending library operations
qDebug() << t.elapsed(false).debugMillisWithUnit() << "stopping pending Library tasks";
m_pTrackCollectionManager->stopLibraryScan();
m_pLibrary->stopPendingTasks();
// Save the current window state (position, maximized, etc)
// Note(ronso0): Unfortunately saveGeometry() also stores the fullscreen state.
// On next start restoreGeometry would enable fullscreen mode even though that
// might not be requested (no '--fullscreen' command line arg and
// [Config],StartInFullscreen is '0'.
// https://bugs.launchpad.net/mixxx/+bug/1882474
// https://bugs.launchpad.net/mixxx/+bug/1909485
// So let's quit fullscreen if StartInFullscreen is not checked in Preferences.
bool fullscreenPref = m_pSettingsManager->settings()->getValue<bool>(
ConfigKey("[Config]", "StartInFullscreen"));
if (isFullScreen() && !fullscreenPref) {
slotViewFullScreen(false);
// After returning from fullscreen the main window incl. window decoration
// may be too large for the screen.
// Maximize the window so we can store a geometry that fits the screen.
showMaximized();
}
m_pSettingsManager->settings()->set(ConfigKey("[MainWindow]", "geometry"),
QString(saveGeometry().toBase64()));
m_pSettingsManager->settings()->set(ConfigKey("[MainWindow]", "state"),
QString(saveState().toBase64()));
qDebug() << "Destroying MixxxMainWindow";
qDebug() << t.elapsed(false).debugMillisWithUnit() << "saving configuration";
m_pSettingsManager->save();
// GUI depends on KeyboardEventFilter, PlayerManager, Library
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting skin";
m_pWidgetParent = nullptr;
QPointer<QWidget> pSkin(centralWidget());
setCentralWidget(nullptr);
if (!pSkin.isNull()) {
QCoreApplication::sendPostedEvents(pSkin, QEvent::DeferredDelete);
}
// Our central widget is now deleted.
VERIFY_OR_DEBUG_ASSERT(pSkin.isNull()) {
qWarning() << "Central widget was not deleted by our sendPostedEvents trick.";
}
// Delete Controls created by skins
qDeleteAll(m_skinCreatedControls);
m_skinCreatedControls.clear();
// TODO() Verify if this comment still applies:
// WMainMenuBar holds references to controls so we need to delete it
// before MixxxMainWindow is destroyed. QMainWindow calls deleteLater() in
// setMenuBar() but we need to delete it now so we can ask for
// DeferredDelete events to be processed for it. Once Mixxx shutdown lives
// outside of MixxxMainWindow the parent relationship will directly destroy
// the WMainMenuBar and this will no longer be a problem.
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting menubar";
QPointer<WMainMenuBar> pMenuBar = m_pMenuBar.toWeakRef();
DEBUG_ASSERT(menuBar() == m_pMenuBar.get());
// We need to reset the parented pointer here that it does not become a
// dangling pointer after the object has been deleted.
m_pMenuBar = nullptr;
setMenuBar(nullptr);
if (!pMenuBar.isNull()) {
QCoreApplication::sendPostedEvents(pMenuBar, QEvent::DeferredDelete);
}
// Our main menu is now deleted.
VERIFY_OR_DEBUG_ASSERT(pMenuBar.isNull()) {
qWarning() << "WMainMenuBar was not deleted by our sendPostedEvents trick.";
}
// SoundManager depend on Engine and Config
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting SoundManager";
delete m_pSoundManager;
// ControllerManager depends on Config
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting ControllerManager";
delete m_pControllerManager;
#ifdef __VINYLCONTROL__
// VinylControlManager depends on a CO the engine owns
// (vinylcontrol_enabled in VinylControlControl)
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting VinylControlManager";
delete m_pVCManager;
#endif
// CoverArtCache is fairly independent of everything else.
CoverArtCache::destroy();
// PlayerManager depends on Engine, SoundManager, VinylControlManager, and Config
// The player manager has to be deleted before the library to ensure
// that all modified track metadata of loaded tracks is saved.
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting PlayerManager";
delete m_pPlayerManager;
// Destroy PlayerInfo explicitly to release the track
// pointers of tracks that were still loaded in decks
// or samplers when PlayerManager was destroyed!
PlayerInfo::destroy();
// Delete the library after the view so there are no dangling pointers to
// the data models.
// Depends on RecordingManager and PlayerManager
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting Library";
delete m_pLibrary;
// RecordingManager depends on config, engine
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting RecordingManager";
delete m_pRecordingManager;
#ifdef __BROADCAST__
// BroadcastManager depends on config, engine
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting BroadcastManager";
delete m_pBroadcastManager;
#endif
// EngineMaster depends on Config and m_pEffectsManager.
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting EngineMaster";
delete m_pEngine;
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting DlgPreferences";
delete m_pPrefDlg;
// Must delete after EngineMaster and DlgPrefEq.
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting EffectsManager";
delete m_pEffectsManager;
delete m_pTouchShift;
WaveformWidgetFactory::destroy();
delete m_pGuiTick;
delete m_pVisualsManager;
// Delete the track collections after all internal track pointers
// in other components have been released by deleting those components
// beforehand!
qDebug() << t.elapsed(false).debugMillisWithUnit() << "detaching all track collections";
delete m_pTrackCollectionManager;
qDebug() << t.elapsed(false).debugMillisWithUnit() << "closing database connection(s)";
m_pDbConnectionPool->destroyThreadLocalConnection();
m_pDbConnectionPool.reset(); // should drop the last reference
// 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_pSettingsManager->save();
// Check for leaked ControlObjects and give warnings.
{
const QList<QSharedPointer<ControlDoublePrivate>> leakedControls =
ControlDoublePrivate::takeAllInstances();
if (!leakedControls.isEmpty()) {
qWarning()
<< "The following"
<< leakedControls.size()
<< "controls were leaked:";
for (auto pCDP : leakedControls) {
ConfigKey key = pCDP->getKey();
qWarning() << key.group << key.item << pCDP->getCreatorCO();
// 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()) {
pCDP->deleteCreatorCO();
}
}
DEBUG_ASSERT(!"Controls were leaked!");
}
// Finally drop all shared pointers by exiting this scope
}
Sandbox::shutdown();
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting SettingsManager";
m_pSettingsManager.reset();
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);
if (m_cmdLineArgs.getDeveloper()) {
StatsManager::destroy();
}
}
bool MixxxMainWindow::initializeDatabase() {
kLogger.info() << "Connecting to database";
QSqlDatabase dbConnection = mixxx::DbConnectionPooled(m_pDbConnectionPool);
if (!dbConnection.isOpen()) {
QMessageBox::critical(nullptr,
tr("Cannot open database"),
tr("Unable to establish a database connection.\n"
"Mixxx requires QT with SQLite support. Please read "
"the Qt SQL driver documentation for information on how "
"to build it.\n\n"
"Click OK to exit."),
QMessageBox::Ok);
return false;
}
kLogger.info() << "Initializing or upgrading database schema";
return MixxxDb::initDatabaseSchema(dbConnection);
}
void MixxxMainWindow::initializeWindow() {
// be sure createMenuBar() is called first
DEBUG_ASSERT(m_pMenuBar);
QPalette Pal(palette());
// safe default QMenuBar background
QColor MenuBarBackground(m_pMenuBar->palette().color(QPalette::Window));
Pal.setColor(QPalette::Window, QColor(0x202020));
setAutoFillBackground(true);
setPalette(Pal);
// restore default QMenuBar background
Pal.setColor(QPalette::Window, MenuBarBackground);
m_pMenuBar->setPalette(Pal);
// Restore the current window state (position, maximized, etc)
restoreGeometry(QByteArray::fromBase64(m_pSettingsManager->settings()->getValueString(
ConfigKey("[MainWindow]", "geometry")).toUtf8()));
restoreState(QByteArray::fromBase64(m_pSettingsManager->settings()->getValueString(
ConfigKey("[MainWindow]", "state")).toUtf8()));
setWindowIcon(QIcon(MIXXX_ICON_PATH));
slotUpdateWindowTitle(TrackPointer());
}
void MixxxMainWindow::initializeKeyboard() {
UserSettingsPointer pConfig = m_pSettingsManager->settings();
QString resourcePath = pConfig->getResourcePath();
// Set the default value in settings file
if (pConfig->getValueString(ConfigKey("[Keyboard]", "Enabled")).length() == 0) {
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(pConfig->getSettingsPath()).filePath("Custom.kbd.cfg");
// Empty keyboard configuration
m_pKbdConfigEmpty = new ConfigObject<ConfigValueKbd>(QString());
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";
qDebug() << "Found and will use default keyboard preset" << defaultKeyboard;
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 = "";