forked from mixxxdj/mixxx
/
mixxxmainwindow.cpp
1265 lines (1136 loc) · 46.4 KB
/
mixxxmainwindow.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
#include "mixxxmainwindow.h"
#include <QDesktopServices>
#include <QFileDialog>
#include "widget/wglwidget.h"
#ifdef MIXXX_USE_QOPENGL
#include "widget/tooltipqopengl.h"
#include "widget/winitialglwidget.h"
#else
#include <QGLFormat>
#endif
#include <QUrl>
#ifdef __LINUX__
#include <QtDBus>
#endif
#include <QtDebug>
#include "dialog/dlgabout.h"
#include "dialog/dlgdevelopertools.h"
#include "dialog/dlgkeywheel.h"
#include "effects/effectsmanager.h"
#include "moc_mixxxmainwindow.cpp"
#include "preferences/constants.h"
#include "preferences/dialog/dlgpreferences.h"
#ifdef __BROADCAST__
#include "broadcast/broadcastmanager.h"
#endif
#include "control/controlindicatortimer.h"
#include "controllers/controllermanager.h"
#include "controllers/keyboard/keyboardeventfilter.h"
#include "database/mixxxdb.h"
#include "library/library.h"
#include "library/library_prefs.h"
#ifdef __ENGINEPRIME__
#include "library/export/libraryexporter.h"
#endif
#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/skinloader.h"
#include "soundio/soundmanager.h"
#include "sources/soundsourceproxy.h"
#include "track/track.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/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
#if defined(Q_OS_LINUX)
#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
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtX11Extras/QX11Info>
#endif
#endif
namespace {
#ifdef __LINUX__
// Detect if the desktop supports a global menu to decide whether we need to rebuild
// and reconnect the menu bar when switching to/from fullscreen mode.
// Compared to QMenuBar::isNativeMenuBar() (requires a set menu bar) and
// Qt::AA_DontUseNativeMenuBar, which may both change, this is way more reliable
// since it's rather unlikely that the Appmenu.Registrar service is unloaded/stopped
// while Mixxx is running.
// This is a reimplementation of QGenericUnixTheme > checkDBusGlobalMenuAvailable()
inline bool supportsGlobalMenu() {
#ifndef QT_NO_DBUS
QDBusConnection conn = QDBusConnection::sessionBus();
if (const auto* pIface = conn.interface()) {
return pIface->isServiceRegistered("com.canonical.AppMenu.Registrar");
}
#endif
return false;
}
#endif
} // namespace
MixxxMainWindow::MixxxMainWindow(std::shared_ptr<mixxx::CoreServices> pCoreServices)
: m_pCoreServices(pCoreServices),
m_pCentralWidget(nullptr),
m_pLaunchImage(nullptr),
m_pGuiTick(nullptr),
#ifdef __LINUX__
m_supportsGlobalMenuBar(supportsGlobalMenu()),
#endif
m_pDeveloperToolsDlg(nullptr),
m_pPrefDlg(nullptr),
m_toolTipsCfg(mixxx::TooltipsPreference::TOOLTIPS_ON) {
DEBUG_ASSERT(pCoreServices);
// These depend on the settings
#ifdef __LINUX__
// If the desktop features a global menubar and we'll go fullscreen during
// startup, set Qt::AA_DontUseNativeMenuBar so the menubar is placed in the
// window like it's done in slotViewFullScreen(). On other desktops this
// attribute has no effect. This is a safe alternative to setNativeMenuBar()
// which can cause a crash when using menu shortcuts like Alt+F after resetting
// the menubar. See https://github.com/mixxxdj/mixxx/issues/11320
if (m_supportsGlobalMenuBar) {
bool fullscreenPref = m_pCoreServices->getSettings()->getValue<bool>(
ConfigKey("[Config]", "StartInFullscreen"));
QApplication::setAttribute(
Qt::AA_DontUseNativeMenuBar,
CmdlineArgs::Instance().getStartInFullscreen() || fullscreenPref);
}
#endif // __LINUX__
createMenuBar();
m_pMenuBar->hide();
initializeWindow();
// Show launch image immediately so the user knows Mixxx is starting
m_pSkinLoader = std::make_unique<mixxx::skin::SkinLoader>(m_pCoreServices->getSettings());
m_pLaunchImage = m_pSkinLoader->loadLaunchImage(this);
m_pCentralWidget = (QWidget*)m_pLaunchImage;
setCentralWidget(m_pCentralWidget);
show();
m_pGuiTick = new GuiTick();
m_pVisualsManager = new VisualsManager();
}
#ifdef MIXXX_USE_QOPENGL
void MixxxMainWindow::initializeQOpenGL() {
if (!CmdlineArgs::Instance().getSafeMode()) {
// This widget and its QOpenGLWindow will be used to query QOpenGL
// information (version, driver, etc) in WaveformWidgetFactory.
// The "SharedGLContext" terminology here doesn't really apply,
// but allows us to take advantage of the existing classes.
WInitialGLWidget* widget = new WInitialGLWidget(this);
widget->setGeometry(QRect(0, 0, 3, 3));
SharedGLContext::setWidget(widget);
// When the widget's QOpenGLWindow has been initialized, we continue
// with the actual initialization
connect(widget, &WInitialGLWidget::onInitialized, this, &MixxxMainWindow::initialize);
widget->show();
// note: the format is set in the WGLWidget's OpenGLWindow constructor
} else {
initialize();
}
}
#endif
void MixxxMainWindow::initialize() {
m_pCoreServices->getControlIndicatorTimer()->setLegacyVsyncEnabled(true);
UserSettingsPointer pConfig = m_pCoreServices->getSettings();
// 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)));
#ifdef MIXXX_USE_QOPENGL
ToolTipQOpenGL::singleton().setActive(m_toolTipsCfg == mixxx::TooltipsPreference::TOOLTIPS_ON);
#endif
#ifdef __ENGINEPRIME__
// Initialise library exporter
// This has to be done before switching to fullscreen
m_pLibraryExporter = m_pCoreServices->getLibrary()->makeLibraryExporter(this);
connect(m_pCoreServices->getLibrary().get(),
&Library::exportLibrary,
m_pLibraryExporter.get(),
&mixxx::LibraryExporter::slotRequestExport);
connect(m_pCoreServices->getLibrary().get(),
&Library::exportCrate,
m_pLibraryExporter.get(),
&mixxx::LibraryExporter::slotRequestExportWithInitialCrate);
#endif
// 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 = m_pCoreServices->getSettings()->getValue<bool>(
ConfigKey("[Config]", "StartInFullscreen"));
if (CmdlineArgs::Instance().getStartInFullscreen() || fullscreenPref) {
showFullScreen();
}
initializationProgressUpdate(65, tr("skin"));
// Install an event filter to catch certain QT events, such as tooltips.
// This allows us to turn off tooltips.
installEventFilter(m_pCoreServices->getKeyboardEventFilter().get());
auto pPlayerManager = m_pCoreServices->getPlayerManager();
DEBUG_ASSERT(pPlayerManager);
const QStringList visualGroups = pPlayerManager->getVisualPlayerGroups();
for (const QString& group : visualGroups) {
m_pVisualsManager->addDeck(group);
}
connect(pPlayerManager.get(),
&PlayerManager::numberOfDecksChanged,
this,
[this](int decks) {
for (int i = 0; i < decks; ++i) {
QString group = PlayerManager::groupForDeck(i);
m_pVisualsManager->addDeckIfNotExist(group);
}
});
#ifndef MIXXX_USE_QOPENGL
// 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);
WGLWidget* pContextWidget = new WGLWidget(this);
pContextWidget->setGeometry(QRect(0, 0, 3, 3));
pContextWidget->hide();
SharedGLContext::setWidget(pContextWidget);
}
#endif
WaveformWidgetFactory::createInstance(); // takes a long time
WaveformWidgetFactory::instance()->setConfig(m_pCoreServices->getSettings());
WaveformWidgetFactory::instance()->startVSync(m_pGuiTick, m_pVisualsManager);
connect(this,
&MixxxMainWindow::skinLoaded,
m_pCoreServices->getLibrary().get(),
&Library::onSkinLoadFinished);
connect(this,
&MixxxMainWindow::skinLoaded,
WaveformWidgetFactory::instance(),
&WaveformWidgetFactory::slotSkinLoaded);
// Initialize preference dialog
m_pPrefDlg = new DlgPreferences(
m_pCoreServices->getScreensaverManager(),
m_pSkinLoader,
m_pCoreServices->getSoundManager(),
m_pCoreServices->getControllerManager(),
m_pCoreServices->getVinylControlManager(),
m_pCoreServices->getEffectsManager(),
m_pCoreServices->getSettingsManager(),
m_pCoreServices->getLibrary());
m_pPrefDlg->setWindowIcon(QIcon(MIXXX_ICON_PATH));
m_pPrefDlg->setHidden(true);
connect(m_pPrefDlg,
&DlgPreferences::tooltipModeChanged,
this,
&MixxxMainWindow::slotTooltipModeChanged);
connect(m_pPrefDlg,
&DlgPreferences::reloadUserInterface,
this,
&MixxxMainWindow::rebootMixxxView,
Qt::DirectConnection);
// Connect signals to the menubar. Should be done before emit newSkinLoaded.
connectMenuBar();
QWidget* oldWidget = m_pCentralWidget;
// 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!";
}
if (!loadConfiguredSkin()) {
reportCriticalErrorAndQuit(
"default skin cannot be loaded - see <b>mixxx</b> trace for more information");
m_pCentralWidget = oldWidget;
//TODO (XXX) add dialog to warn user and launch skin choice page
} else {
m_pMenuBar->setStyleSheet(m_pCentralWidget->styleSheet());
}
// Check direct rendering and warn user if they don't have it
if (!CmdlineArgs::Instance().getSafeMode()) {
checkDirectRendering();
}
// 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;
SoundDeviceStatus result = m_pCoreServices->getSoundManager()->setupDevices();
if (result == SoundDeviceStatus::ErrorDeviceCount ||
result == SoundDeviceStatus::ErrorExcessiveOutputChannel) {
if (soundDeviceBusyDlg(&retryClicked) != QDialog::Accepted) {
exit(0);
}
} else if (result != SoundDeviceStatus::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_pCoreServices->getSoundManager()->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_pCoreServices->getSoundManager()->getConfig().writeToDisk();
// 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_pCentralWidget);
// 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;
connect(pPlayerManager.get(),
&PlayerManager::noMicrophoneInputConfigured,
this,
&MixxxMainWindow::slotNoMicrophoneInputConfigured);
connect(pPlayerManager.get(),
&PlayerManager::noAuxiliaryInputConfigured,
this,
&MixxxMainWindow::slotNoAuxiliaryInputConfigured);
connect(pPlayerManager.get(),
&PlayerManager::noDeckPassthroughInputConfigured,
this,
&MixxxMainWindow::slotNoDeckPassthroughInputConfigured);
connect(pPlayerManager.get(),
&PlayerManager::noVinylControlInputConfigured,
this,
&MixxxMainWindow::slotNoVinylControlInputConfigured);
connect(&PlayerInfo::instance(),
&PlayerInfo::currentPlayingTrackChanged,
this,
&MixxxMainWindow::slotUpdateWindowTitle);
}
MixxxMainWindow::~MixxxMainWindow() {
Timer t("~MixxxMainWindow");
t.start();
// 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://github.com/mixxxdj/mixxx/issues/10005
// So let's quit fullscreen if StartInFullscreen is not checked in Preferences.
bool fullscreenPref = m_pCoreServices->getSettings()->getValue<bool>(
ConfigKey("[Config]", "StartInFullscreen"));
if (isFullScreen() && !fullscreenPref) {
// Simply maximize the window so we can store a geometry that fits the screen.
// Don't call slotViewFullScreen(false) (calls showNormal()) because that
// can make the main window incl. window decoration too large for the screen.
showMaximized();
}
m_pCoreServices->getSettings()->set(ConfigKey("[MainWindow]", "geometry"),
QString(saveGeometry().toBase64()));
m_pCoreServices->getSettings()->set(ConfigKey("[MainWindow]", "state"),
QString(saveState().toBase64()));
// GUI depends on KeyboardEventFilter, PlayerManager, Library
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting skin";
m_pCentralWidget = 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.";
}
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting DeveloperToolsDlg";
delete m_pDeveloperToolsDlg;
#ifdef __ENGINEPRIME__
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting LibraryExporter";
m_pLibraryExporter.reset();
#endif
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting DlgPreferences";
delete m_pPrefDlg;
m_pCoreServices->getControlIndicatorTimer()->setLegacyVsyncEnabled(false);
WaveformWidgetFactory::destroy();
delete m_pGuiTick;
delete m_pVisualsManager;
}
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_pCoreServices->getSettings()
->getValueString(ConfigKey("[MainWindow]", "geometry"))
.toUtf8()));
restoreState(QByteArray::fromBase64(
m_pCoreServices->getSettings()
->getValueString(ConfigKey("[MainWindow]", "state"))
.toUtf8()));
setWindowIcon(QIcon(MIXXX_ICON_PATH));
slotUpdateWindowTitle(TrackPointer());
}
QDialog::DialogCode MixxxMainWindow::soundDeviceErrorDlg(
const QString &title, const QString &text, bool* retryClicked) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setWindowTitle(title);
msgBox.setText(text);
QPushButton* retryButton =
msgBox.addButton(tr("Retry"), QMessageBox::ActionRole);
QPushButton* reconfigureButton =
msgBox.addButton(tr("Reconfigure"), QMessageBox::ActionRole);
QPushButton* wikiButton =
msgBox.addButton(tr("Help"), QMessageBox::ActionRole);
QPushButton* exitButton =
msgBox.addButton(tr("Exit"), QMessageBox::ActionRole);
while (true)
{
msgBox.exec();
if (msgBox.clickedButton() == retryButton) {
m_pCoreServices->getSoundManager()->clearAndQueryDevices();
*retryClicked = true;
return QDialog::Accepted;
} else if (msgBox.clickedButton() == wikiButton) {
QDesktopServices::openUrl(QUrl(MIXXX_WIKI_TROUBLESHOOTING_SOUND_URL));
wikiButton->setEnabled(false);
} else if (msgBox.clickedButton() == reconfigureButton) {
msgBox.hide();
m_pCoreServices->getSoundManager()->clearAndQueryDevices();
// This way of opening the dialog allows us to use it synchronously
m_pPrefDlg->setWindowModality(Qt::ApplicationModal);
// Open preferences, sound hardware page is selected (default on first call)
m_pPrefDlg->exec();
if (m_pPrefDlg->result() == QDialog::Accepted) {
return QDialog::Accepted;
}
msgBox.show();
} else if (msgBox.clickedButton() == exitButton) {
// Will finally quit Mixxx
return QDialog::Rejected;
}
}
}
QDialog::DialogCode MixxxMainWindow::soundDeviceBusyDlg(bool* retryClicked) {
QString title(tr("Sound Device Busy"));
QString text(
"<html> <p>" %
tr("Mixxx was unable to open all the configured sound devices.") +
"</p> <p>" %
m_pCoreServices->getSoundManager()->getErrorDeviceName() %
" is used by another application or not plugged in."
"</p><ul>"
"<li>" %
tr("<b>Retry</b> after closing the other application "
"or reconnecting a sound device") %
"</li>"
"<li>" %
tr("<b>Reconfigure</b> Mixxx's sound device settings.") %
"</li>"
"<li>" %
tr("Get <b>Help</b> from the Mixxx Wiki.") %
"</li>"
"<li>" %
tr("<b>Exit</b> Mixxx.") %
"</li>"
"</ul></html>");
return soundDeviceErrorDlg(title, text, retryClicked);
}
QDialog::DialogCode MixxxMainWindow::soundDeviceErrorMsgDlg(
SoundDeviceStatus status, bool* retryClicked) {
QString title(tr("Sound Device Error"));
QString text("<html> <p>" %
tr("Mixxx was unable to open all the configured sound "
"devices.") +
"</p> <p>" %
m_pCoreServices->getSoundManager()
->getLastErrorMessage(status)
.replace("\n", "<br/>") %
"</p><ul>"
"<li>" %
tr("<b>Retry</b> after fixing an issue") %
"</li>"
"<li>" %
tr("<b>Reconfigure</b> Mixxx's sound device settings.") %
"</li>"
"<li>" %
tr("Get <b>Help</b> from the Mixxx Wiki.") %
"</li>"
"<li>" %
tr("<b>Exit</b> Mixxx.") %
"</li>"
"</ul></html>");
return soundDeviceErrorDlg(title, text, retryClicked);
}
QDialog::DialogCode MixxxMainWindow::noOutputDlg(bool* continueClicked) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setWindowTitle(tr("No Output Devices"));
msgBox.setText(
"<html>" + tr("Mixxx was configured without any output sound devices. "
"Audio processing will be disabled without a configured output device.") +
"<ul>"
"<li>" +
tr("<b>Continue</b> without any outputs.") +
"</li>"
"<li>" +
tr("<b>Reconfigure</b> Mixxx's sound device settings.") +
"</li>"
"<li>" +
tr("<b>Exit</b> Mixxx.") +
"</li>"
"</ul></html>"
);
QPushButton* continueButton =
msgBox.addButton(tr("Continue"), QMessageBox::ActionRole);
QPushButton* reconfigureButton =
msgBox.addButton(tr("Reconfigure"), QMessageBox::ActionRole);
QPushButton* exitButton =
msgBox.addButton(tr("Exit"), QMessageBox::ActionRole);
while (true)
{
msgBox.exec();
if (msgBox.clickedButton() == continueButton) {
*continueClicked = true;
return QDialog::Accepted;
} else if (msgBox.clickedButton() == reconfigureButton) {
msgBox.hide();
// This way of opening the dialog allows us to use it synchronously
m_pPrefDlg->setWindowModality(Qt::ApplicationModal);
m_pPrefDlg->exec();
if (m_pPrefDlg->result() == QDialog::Accepted) {
return QDialog::Accepted;
}
msgBox.show();
} else if (msgBox.clickedButton() == exitButton) {
// Will finally quit Mixxx
return QDialog::Rejected;
}
}
}
void MixxxMainWindow::slotUpdateWindowTitle(TrackPointer pTrack) {
QString appTitle = VersionStore::applicationName();
// If we have a track, use getInfo() to format a summary string and prepend
// it to the title.
// TODO(rryan): Does this violate Mac App Store policies?
if (pTrack) {
QString trackInfo = pTrack->getInfo();
if (!trackInfo.isEmpty()) {
appTitle = QString("%1 | %2").arg(trackInfo, appTitle);
}
}
this->setWindowTitle(appTitle);
}
void MixxxMainWindow::createMenuBar() {
ScopedTimer t(u"MixxxMainWindow::createMenuBar");
DEBUG_ASSERT(m_pCoreServices->getKeyboardConfig());
m_pMenuBar = make_parented<WMainMenuBar>(
this, m_pCoreServices->getSettings(), m_pCoreServices->getKeyboardConfig().get());
if (m_pCentralWidget) {
m_pMenuBar->setStyleSheet(m_pCentralWidget->styleSheet());
}
setMenuBar(m_pMenuBar);
}
void MixxxMainWindow::connectMenuBar() {
// This function might be invoked multiple times on startup
// so all connections must be unique!
ScopedTimer t(u"MixxxMainWindow::connectMenuBar");
connect(this,
&MixxxMainWindow::skinLoaded,
m_pMenuBar,
&WMainMenuBar::onNewSkinLoaded,
Qt::UniqueConnection);
// Misc
connect(m_pMenuBar,
&WMainMenuBar::quit,
this,
&MixxxMainWindow::close,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::showPreferences,
this,
&MixxxMainWindow::slotOptionsPreferences,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::loadTrackToDeck,
this,
&MixxxMainWindow::slotFileLoadSongPlayer,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::showKeywheel,
this,
&MixxxMainWindow::slotShowKeywheel);
// Fullscreen
connect(m_pMenuBar,
&WMainMenuBar::toggleFullScreen,
this,
&MixxxMainWindow::slotViewFullScreen,
Qt::UniqueConnection);
connect(this,
&MixxxMainWindow::fullScreenChanged,
m_pMenuBar,
&WMainMenuBar::onFullScreenStateChange,
Qt::UniqueConnection);
// Refresh the Fullscreen checkbox for the case we went fullscreen earlier
m_pMenuBar->onFullScreenStateChange(isFullScreen());
// Keyboard shortcuts
connect(m_pMenuBar,
&WMainMenuBar::toggleKeyboardShortcuts,
m_pCoreServices.get(),
&mixxx::CoreServices::slotOptionsKeyboard,
Qt::UniqueConnection);
// Help
connect(m_pMenuBar,
&WMainMenuBar::showAbout,
this,
&MixxxMainWindow::slotHelpAbout,
Qt::UniqueConnection);
// Developer
connect(m_pMenuBar,
&WMainMenuBar::reloadSkin,
this,
&MixxxMainWindow::rebootMixxxView,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::toggleDeveloperTools,
this,
&MixxxMainWindow::slotDeveloperTools,
Qt::UniqueConnection);
if (m_pCoreServices->getRecordingManager()) {
connect(m_pCoreServices->getRecordingManager().get(),
&RecordingManager::isRecording,
m_pMenuBar,
&WMainMenuBar::onRecordingStateChange,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::toggleRecording,
m_pCoreServices->getRecordingManager().get(),
&RecordingManager::slotSetRecording,
Qt::UniqueConnection);
m_pMenuBar->onRecordingStateChange(
m_pCoreServices->getRecordingManager()->isRecordingActive());
}
#ifdef __BROADCAST__
if (m_pCoreServices->getBroadcastManager()) {
connect(m_pCoreServices->getBroadcastManager().get(),
&BroadcastManager::broadcastEnabled,
m_pMenuBar,
&WMainMenuBar::onBroadcastingStateChange,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::toggleBroadcasting,
m_pCoreServices->getBroadcastManager().get(),
&BroadcastManager::setEnabled,
Qt::UniqueConnection);
m_pMenuBar->onBroadcastingStateChange(m_pCoreServices->getBroadcastManager()->isEnabled());
}
#endif
#ifdef __VINYLCONTROL__
if (m_pCoreServices->getVinylControlManager()) {
connect(m_pMenuBar,
&WMainMenuBar::toggleVinylControl,
m_pCoreServices->getVinylControlManager().get(),
&VinylControlManager::toggleVinylControl,
Qt::UniqueConnection);
connect(m_pCoreServices->getVinylControlManager().get(),
&VinylControlManager::vinylControlDeckEnabled,
m_pMenuBar,
&WMainMenuBar::onVinylControlDeckEnabledStateChange,
Qt::UniqueConnection);
}
#endif
auto pPlayerManager = m_pCoreServices->getPlayerManager();
if (pPlayerManager) {
connect(pPlayerManager.get(),
&PlayerManager::numberOfDecksChanged,
m_pMenuBar,
&WMainMenuBar::onNumberOfDecksChanged,
Qt::UniqueConnection);
m_pMenuBar->onNumberOfDecksChanged(pPlayerManager->numberOfDecks());
}
if (m_pCoreServices->getTrackCollectionManager()) {
connect(m_pMenuBar,
&WMainMenuBar::rescanLibrary,
m_pCoreServices->getTrackCollectionManager().get(),
&TrackCollectionManager::startLibraryScan,
Qt::UniqueConnection);
connect(m_pCoreServices->getTrackCollectionManager().get(),
&TrackCollectionManager::libraryScanStarted,
m_pMenuBar,
&WMainMenuBar::onLibraryScanStarted,
Qt::UniqueConnection);
connect(m_pCoreServices->getTrackCollectionManager().get(),
&TrackCollectionManager::libraryScanFinished,
m_pMenuBar,
&WMainMenuBar::onLibraryScanFinished,
Qt::UniqueConnection);
}
if (m_pCoreServices->getLibrary()) {
connect(m_pMenuBar,
&WMainMenuBar::createCrate,
m_pCoreServices->getLibrary().get(),
&Library::slotCreateCrate,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::createPlaylist,
m_pCoreServices->getLibrary().get(),
&Library::slotCreatePlaylist,
Qt::UniqueConnection);
}
#ifdef __ENGINEPRIME__
DEBUG_ASSERT(m_pLibraryExporter);
connect(m_pMenuBar,
&WMainMenuBar::exportLibrary,
m_pLibraryExporter.get(),
&mixxx::LibraryExporter::slotRequestExport,
Qt::UniqueConnection);
#endif
}
void MixxxMainWindow::slotFileLoadSongPlayer(int deck) {
QString group = PlayerManager::groupForDeck(deck - 1);
QString loadTrackText = tr("Load track to Deck %1").arg(QString::number(deck));
QString deckWarningMessage = tr("Deck %1 is currently playing a track.")
.arg(QString::number(deck));
QString areYouSure = tr("Are you sure you want to load a new track?");
if (ControlObject::get(ConfigKey(group, "play")) > 0.0) {
int ret = QMessageBox::warning(this,
VersionStore::applicationName(),
deckWarningMessage + "\n" + areYouSure,
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (ret != QMessageBox::Yes) {
return;
}
}
UserSettingsPointer pConfig = m_pCoreServices->getSettings();
QString trackPath =
QFileDialog::getOpenFileName(
this,
loadTrackText,
pConfig->getValueString(mixxx::library::prefs::kLegacyDirectoryConfigKey),
QString("Audio (%1)")
.arg(SoundSourceProxy::getSupportedFileNamePatterns().join(" ")));
if (!trackPath.isNull()) {
// The user has picked a file via a file dialog. This means the system
// sandboxer (if we are sandboxed) has granted us permission to this
// folder. Create a security bookmark while we have permission so that
// we can access the folder on future runs. We need to canonicalize the
// path so we first wrap the directory string with a QDir.
mixxx::FileInfo fileInfo(trackPath);
Sandbox::createSecurityToken(&fileInfo);
m_pCoreServices->getPlayerManager()->slotLoadToDeck(trackPath, deck);
}
}
void MixxxMainWindow::slotDeveloperTools(bool visible) {
if (visible) {
if (m_pDeveloperToolsDlg == nullptr) {
UserSettingsPointer pConfig = m_pCoreServices->getSettings();
m_pDeveloperToolsDlg = new DlgDeveloperTools(this, pConfig);
connect(m_pDeveloperToolsDlg,
&DlgDeveloperTools::destroyed,
this,
&MixxxMainWindow::slotDeveloperToolsClosed);
connect(this,
&MixxxMainWindow::closeDeveloperToolsDlgChecked,
m_pDeveloperToolsDlg,
&DlgDeveloperTools::done);
connect(m_pDeveloperToolsDlg,
&DlgDeveloperTools::destroyed,
m_pMenuBar,
&WMainMenuBar::onDeveloperToolsHidden);
}
m_pMenuBar->onDeveloperToolsShown();
m_pDeveloperToolsDlg->show();
m_pDeveloperToolsDlg->activateWindow();
} else {
emit closeDeveloperToolsDlgChecked(0);
}
}
void MixxxMainWindow::slotDeveloperToolsClosed() {
m_pDeveloperToolsDlg = nullptr;
}
void MixxxMainWindow::slotViewFullScreen(bool toggle) {
if (isFullScreen() == toggle) {
return;
}
if (toggle) {
showFullScreen();
#ifdef __LINUX__
// Fix for "No menu bar with ubuntu unity in full screen mode" (issues
// #6072 and #6689. Before touching anything here, please read
// those bugs.
// Set this attribute instead of calling setNativeMenuBar(false), see
// https://github.com/mixxxdj/mixxx/issues/11320
if (m_supportsGlobalMenuBar) {
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
createMenuBar();
connectMenuBar();
}
#endif
} else {
#ifdef __LINUX__
if (m_supportsGlobalMenuBar) {
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, false);
createMenuBar();
connectMenuBar();
}
#endif
showNormal();
}
emit fullScreenChanged(toggle);
}
void MixxxMainWindow::slotOptionsPreferences() {
m_pPrefDlg->show();
m_pPrefDlg->raise();
m_pPrefDlg->activateWindow();
}
void MixxxMainWindow::slotNoVinylControlInputConfigured() {
QMessageBox::StandardButton btn = QMessageBox::warning(
this,
VersionStore::applicationName(),
tr("There is no input device selected for this vinyl control.\n"
"Please select an input device in the sound hardware preferences first."),
QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::Cancel);
if (btn == QMessageBox::Ok) {
m_pPrefDlg->show();
m_pPrefDlg->showSoundHardwarePage();
}
}
void MixxxMainWindow::slotNoDeckPassthroughInputConfigured() {
QMessageBox::StandardButton btn = QMessageBox::warning(
this,
VersionStore::applicationName(),
tr("There is no input device selected for this passthrough control.\n"
"Please select an input device in the sound hardware preferences first."),
QMessageBox::Ok | QMessageBox::Cancel,
QMessageBox::Cancel);
if (btn == QMessageBox::Ok) {
m_pPrefDlg->show();
m_pPrefDlg->showSoundHardwarePage();
}