Skip to content

Commit

Permalink
Merge pull request #2872 from xerus2000/refactor-main
Browse files Browse the repository at this point in the history
Clean up MixxxMainWindow and RecordingManager
  • Loading branch information
Holzhaus committed Jul 12, 2020
2 parents 371c6d9 + 0fd2f07 commit d6e4f3b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 119 deletions.
97 changes: 43 additions & 54 deletions src/mixxx.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
/***************************************************************************
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 <QDesktopWidget>
#include <QFileDialog>
#include <QGLFormat>
#include <QGLWidget>
#include <QGuiApplication>
#include <QInputMethod>
#include <QLocale>
Expand Down Expand Up @@ -90,9 +72,10 @@
#endif

#if defined(Q_OS_LINUX)
#include <QtX11Extras/QX11Info>
#include <X11/Xlib.h>
#include <X11/Xlibint.h>

#include <QtX11Extras/QX11Info>
// Xlibint.h predates C++ and defines macros which conflict
// with references to std::max and std::min
#undef max
Expand Down Expand Up @@ -140,7 +123,7 @@ const int MixxxMainWindow::kMicrophoneCount = 4;
const int MixxxMainWindow::kAuxiliaryCount = 4;

MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args)
: m_pWidgetParent(nullptr),
: m_pCentralWidget(nullptr),
m_pLaunchImage(nullptr),
m_pEffectsManager(nullptr),
m_pEngine(nullptr),
Expand Down Expand Up @@ -191,8 +174,8 @@ MixxxMainWindow::MixxxMainWindow(QApplication* pApp, const CmdlineArgs& args)
// 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);
m_pCentralWidget = (QWidget*)m_pLaunchImage;
setCentralWidget(m_pCentralWidget);

show();
pApp->processEvents();
Expand Down Expand Up @@ -492,7 +475,7 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) {

launchProgress(63);

QWidget* oldWidget = m_pWidgetParent;
QWidget* oldWidget = m_pCentralWidget;

// Load default styles that can be overridden by skins
QFile file(":/skins/default.qss");
Expand All @@ -507,17 +490,18 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) {

// Load skin to a QWidget that we set as the central widget. Assignment
// intentional in next line.
if (!(m_pWidgetParent = m_pSkinLoader->loadConfiguredSkin(this, m_pKeyboard,
m_pPlayerManager,
m_pControllerManager,
m_pLibrary,
m_pVCManager,
m_pEffectsManager,
m_pRecordingManager))) {
m_pCentralWidget = m_pSkinLoader->loadConfiguredSkin(this,
m_pKeyboard,
m_pPlayerManager,
m_pControllerManager,
m_pLibrary,
m_pVCManager,
m_pEffectsManager,
m_pRecordingManager);
if (m_pCentralWidget == nullptr) {
reportCriticalErrorAndQuit(
"default skin cannot be loaded see <b>mixxx</b> trace for more information.");

m_pWidgetParent = oldWidget;
"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
}

Expand Down Expand Up @@ -655,7 +639,7 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) {
// 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);
setCentralWidget(m_pCentralWidget);
// The launch image widget is automatically disposed, but we still have a
// pointer to it.
m_pLaunchImage = nullptr;
Expand Down Expand Up @@ -687,7 +671,7 @@ void MixxxMainWindow::finalize() {

// GUI depends on KeyboardEventFilter, PlayerManager, Library
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting skin";
m_pWidgetParent = nullptr;
m_pCentralWidget = nullptr;
QPointer<QWidget> pSkin(centralWidget());
setCentralWidget(nullptr);
if (!pSkin.isNull()) {
Expand Down Expand Up @@ -1445,11 +1429,11 @@ void MixxxMainWindow::rebootMixxxView() {
// supports since the controls from the previous skin will be left over.
m_pMenuBar->onNewSkinAboutToLoad();

if (m_pWidgetParent) {
m_pWidgetParent->hide();
if (m_pCentralWidget) {
m_pCentralWidget->hide();
WaveformWidgetFactory::instance()->destroyWidgets();
delete m_pWidgetParent;
m_pWidgetParent = NULL;
delete m_pCentralWidget;
m_pCentralWidget = NULL;
}

// Workaround for changing skins while fullscreen, just go out of fullscreen
Expand All @@ -1461,23 +1445,23 @@ void MixxxMainWindow::rebootMixxxView() {

// Load skin to a QWidget that we set as the central widget. Assignment
// intentional in next line.
if (!(m_pWidgetParent = m_pSkinLoader->loadConfiguredSkin(this,
m_pKeyboard,
m_pPlayerManager,
m_pControllerManager,
m_pLibrary,
m_pVCManager,
m_pEffectsManager,
m_pRecordingManager))) {

m_pCentralWidget = m_pSkinLoader->loadConfiguredSkin(this,
m_pKeyboard,
m_pPlayerManager,
m_pControllerManager,
m_pLibrary,
m_pVCManager,
m_pEffectsManager,
m_pRecordingManager);
if (m_pCentralWidget == nullptr) {
QMessageBox::critical(this,
tr("Error in skin file"),
tr("The selected skin cannot be loaded."));
// m_pWidgetParent is NULL, we can't continue.
return;
}

setCentralWidget(m_pWidgetParent);
setCentralWidget(m_pCentralWidget);
#ifdef __LINUX__
// don't adjustSize() on Linux as this wouldn't use the entire available area
// to paint the new skin with X11
Expand All @@ -1490,14 +1474,19 @@ void MixxxMainWindow::rebootMixxxView() {
slotViewFullScreen(true);
} else if (!initSize.isEmpty()) {
// Not all OSs and/or window managers keep the window inside of the screen, so force it.
int newX = initPosition.x() + (initSize.width() - m_pWidgetParent->width()) / 2;
int newY = initPosition.y() + (initSize.height() - m_pWidgetParent->height()) / 2;
int newX = initPosition.x() + (initSize.width() - m_pCentralWidget->width()) / 2;
int newY = initPosition.y() + (initSize.height() - m_pCentralWidget->height()) / 2;

const QScreen* primaryScreen = getPrimaryScreen();
if (primaryScreen) {
newX = std::max(0, std::min(newX, primaryScreen->geometry().width() - m_pWidgetParent->width()));
newY = std::max(0, std::min(newY, primaryScreen->geometry().height() - m_pWidgetParent->height()));
move(newX,newY);
newX = std::max(0,
std::min(newX,
primaryScreen->geometry().width() -
m_pCentralWidget->width()));
newY = std::max(0,
std::min(newY,
primaryScreen->geometry().height() - m_pCentralWidget->height()));
move(newX, newY);
} else {
qWarning() << "Unable to move window inside screen borders.";
}
Expand Down
62 changes: 25 additions & 37 deletions src/mixxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,41 @@
#include "util/parented_ptr.h"
#include "util/timer.h"

class BroadcastManager;
class ChannelHandleFactory;
class ControlPushButton;
class ControllerManager;
class ControlPushButton;
class DlgDeveloperTools;
class DlgPreferences;
class EffectsManager;
class EngineMaster;
class GuiTick;
class VisualsManager;
class KeyboardEventFilter;
class LaunchImage;
class Library;
class TrackCollectionManager;
class KeyboardEventFilter;
class PlayerManager;
class RecordingManager;
class SettingsManager;
class BroadcastManager;
class SkinLoader;
class SoundManager;
class TrackCollectionManager;
class VinylControlManager;
class VisualsManager;
class WMainMenuBar;

typedef QSharedPointer<SettingsManager> SettingsManagerPointer;

// This Class is the base class for Mixxx. It sets up the main
// window and providing a menubar.
// For the main view, an instance of class MixxxView is
// created which creates your view.
/// This Class is the base class for Mixxx.
/// It sets up the main window providing a menubar.
/// For the main view, an instance of class MixxxView is
/// created which creates your view.
class MixxxMainWindow : public QMainWindow {
Q_OBJECT
public:
// Constructor. files is a list of command line arguments
MixxxMainWindow(QApplication *app, const CmdlineArgs& args);
~MixxxMainWindow() override;

void finalize();

// creates the menu_bar and inserts the file Menu
/// creates the menu_bar and inserts the file Menu
void createMenuBar();
void connectMenuBar();
void setInhibitScreensaver(mixxx::ScreenSaverPreference inhibit);
Expand All @@ -67,45 +64,45 @@ class MixxxMainWindow : public QMainWindow {
void rebootMixxxView();

void slotFileLoadSongPlayer(int deck);
// toggle keyboard on-off
/// toggle keyboard on-off
void slotOptionsKeyboard(bool toggle);
// Preference dialog
/// show the preferences dialog
void slotOptionsPreferences();
// shows an about dlg
/// show the about dialog
void slotHelpAbout();
// toggle full screen mode
/// toggle full screen mode
void slotViewFullScreen(bool toggle);
// Open the developer tools dialog.
/// open the developer tools dialog.
void slotDeveloperTools(bool enable);
void slotDeveloperToolsClosed();

void slotUpdateWindowTitle(TrackPointer pTrack);
void slotChangedPlayingDeck(int deck);

// Warn the user when inputs are not configured.
/// warn the user when inputs are not configured.
void slotNoMicrophoneInputConfigured();
void slotNoAuxiliaryInputConfigured();
void slotNoDeckPassthroughInputConfigured();
void slotNoVinylControlInputConfigured();

signals:
void skinLoaded();
// used to uncheck the menu when the dialog of develeoper tools is closed
/// used to uncheck the menu when the dialog of developer tools is closed
void developerToolsDlgClosed(int r);
void closeDeveloperToolsDlgChecked(int r);
void fullScreenChanged(bool fullscreen);

protected:
// Event filter to block certain events (eg. tooltips if tooltips are disabled)
/// Event filter to block certain events (eg. tooltips if tooltips are disabled)
bool eventFilter(QObject *obj, QEvent *event) override;
void closeEvent(QCloseEvent *event) override;
bool event(QEvent* e) override;

private:
void initialize(QApplication *app, const CmdlineArgs& args);

// progresses the launch image progress bar
// this must be called from the GUi thread only
/// progresses the launch image progress bar
/// this must be called from the GUI thread only
void launchProgress(int progress);

void initializeWindow();
Expand All @@ -122,28 +119,22 @@ class MixxxMainWindow : public QMainWindow {
SoundDeviceError err, bool* retryClicked);
QDialog::DialogCode noOutputDlg(bool* continueClicked);

// Pointer to the root GUI widget
QWidget* m_pWidgetParent;
QWidget* m_pCentralWidget;
LaunchImage* m_pLaunchImage;

std::unique_ptr<SettingsManager> m_pSettingsManager;

// The effects processing system
/// The effects processing system
EffectsManager* m_pEffectsManager;

// The mixing engine.
/// The mixing engine
EngineMaster* m_pEngine;

// The skin loader.
// TODO(rryan): doesn't need to be a member variable
SkinLoader* m_pSkinLoader;
SkinLoader* m_pSkinLoader; // TODO(rryan): doesn't need to be a member variable

// The sound manager
SoundManager* m_pSoundManager;

// Keeps track of players
PlayerManager* m_pPlayerManager;
// RecordingManager
RecordingManager* m_pRecordingManager;
#ifdef __BROADCAST__
BroadcastManager* m_pBroadcastManager;
Expand All @@ -157,26 +148,23 @@ class MixxxMainWindow : public QMainWindow {

KeyboardEventFilter* m_pKeyboard;

// The Mixxx database connection pool
mixxx::DbConnectionPoolPtr m_pDbConnectionPool;

TrackCollectionManager* m_pTrackCollectionManager;

// The library management object
Library* m_pLibrary;

parented_ptr<WMainMenuBar> m_pMenuBar;

DlgDeveloperTools* m_pDeveloperToolsDlg;

/** Pointer to preference dialog */
DlgPreferences* m_pPrefDlg;

ConfigObject<ConfigValueKbd>* m_pKbdConfig;
ConfigObject<ConfigValueKbd>* m_pKbdConfigEmpty;

mixxx::TooltipsPreference m_toolTipsCfg;
// Timer that tracks how long Mixxx has been running.
/// tracks how long Mixxx has been running
Timer m_runtime_timer;

const CmdlineArgs& m_cmdLineArgs;
Expand Down
12 changes: 3 additions & 9 deletions src/recording/recordingmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Created 03/26/2011 by Tobias Rafreider
#include "recording/recordingmanager.h"

#include <QMutex>
#include <QDir>
#include <QtDebug>
#include <QDebug>
#include <QMessageBox>
#include <QMutex>
#include <QStorageInfo>

#include <climits>

#include "control/controlproxy.h"
Expand All @@ -16,10 +13,8 @@
#include "engine/sidechain/enginesidechain.h"
#include "errordialoghandler.h"
#include "recording/defs_recording.h"
#include "recording/recordingmanager.h"

// one gibibyte
#define MIN_DISK_FREE 1024 * 1024 * 1024ll
#define MIN_DISK_FREE 1024 * 1024 * 1024ll // one gibibyte

RecordingManager::RecordingManager(UserSettingsPointer pConfig, EngineMaster* pEngine)
: m_pConfig(pConfig),
Expand All @@ -46,7 +41,6 @@ RecordingManager::RecordingManager(UserSettingsPointer pConfig, EngineMaster* pE
m_split_size = getFileSplitSize();
m_split_time = getFileSplitSeconds();


// Register EngineRecord with the engine sidechain.
EngineSideChain* pSidechain = pEngine->getSideChain();
if (pSidechain) {
Expand Down
Loading

0 comments on commit d6e4f3b

Please sign in to comment.