gambatte_qt: pass by ref

This commit is contained in:
sinamas 2013-03-29 18:03:00 +01:00
parent fd37168a10
commit b60d88d6be
15 changed files with 444 additions and 426 deletions

View File

@ -19,13 +19,13 @@
#ifndef MAINWINDOW_H #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include "callqueue.h"
#include <vector> #include "pixelbuffer.h"
#include "resinfo.h" #include "resinfo.h"
#include "scalingmethod.h" #include "scalingmethod.h"
#include "uncopyable.h" #include "uncopyable.h"
#include "callqueue.h" #include <QMainWindow>
#include "pixelbuffer.h" #include <vector>
class AudioEngineConf; class AudioEngineConf;
class BlitterConf; class BlitterConf;
@ -37,9 +37,8 @@ class MediaWorker;
class QSize; class QSize;
/** /**
* The MainWindow is one of the two main classes in this framework. * The MainWindow takes a MediaSource and presents the audio/video content
* It takes a MediaSource and presents the audio/video content produced * produced by it to the user.
* by it to the user.
* *
* It calls MediaSource::update to request production of more audio/video content. * It calls MediaSource::update to request production of more audio/video content.
* This happens in a worker thread that is separate from the main (GUI) thread. * This happens in a worker thread that is separate from the main (GUI) thread.
@ -47,25 +46,33 @@ class QSize;
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
/** Can be used to gain frame buffer access outside the MediaSource /**
* Can be used to gain frame buffer access outside the MediaSource
* methods that take the frame buffer as argument. * methods that take the frame buffer as argument.
*/ */
class FrameBuffer { class FrameBuffer {
MediaWidget *const mw;
public: public:
explicit FrameBuffer(MainWindow *const mw) : mw(mw->w_) {} explicit FrameBuffer(MainWindow &mw)
: mw_(mw.w_)
{
}
class Locked : Uncopyable { class Locked : Uncopyable {
MediaWidget *mw;
PixelBuffer pb;
public: public:
Locked(FrameBuffer fb); Locked(FrameBuffer fb);
~Locked(); ~Locked();
const PixelBuffer& get() const { return pb; } PixelBuffer const & get() const { return pb_; }
};
private:
MediaWidget *mw_;
PixelBuffer pb_;
}; };
explicit MainWindow(MediaSource *source); private:
MediaWidget *const mw_;
};
explicit MainWindow(MediaSource &source);
/** Sets the duration in seconds of each video frame. /** Sets the duration in seconds of each video frame.
* Eg. use setFrameTime(1, 60) for 60 fps video. * Eg. use setFrameTime(1, 60) for 60 fps video.
@ -117,12 +124,16 @@ public:
void setAspectRatio(const QSize &ar); void setAspectRatio(const QSize &ar);
void setScalingMethod(ScalingMethod smet); void setScalingMethod(ScalingMethod smet);
/** Sets the size of the video area of the MainWindow when not full screen. /**
* Should be used in place of methods like QMainWindow::resize, because this one doesn't screw up full screen. * Sets the size of the video area of the MainWindow when not full screen.
* Pass sz = QSize(-1,-1) for a variable size, such that the user may adjust the window size. * Should be used in place of methods like QMainWindow::resize, because this
* Otherwise a fixed window size equal to sz will be used. This window size does not include window borders or menus. * one does not screw up full screen.
*
* Pass size = QSize(-1, -1) for a variable size, such that the user may adjust
* the window size. Otherwise a fixed window size equal to size will be used.
* This window size does not include window borders or menus.
*/ */
void setWindowSize(const QSize &sz); void setWindowSize(QSize const &size);
/** Each blitter has some properties that can be accessed through its BlitterConf. */ /** Each blitter has some properties that can be accessed through its BlitterConf. */
const BlitterConf blitterConf(std::size_t blitterNo); const BlitterConf blitterConf(std::size_t blitterNo);

View File

@ -16,24 +16,24 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef SOUNDDIALOG_H #ifndef SOUNDDIALOG_H
#define SOUNDDIALOG_H #define SOUNDDIALOG_H
#include <QDialog>
class MainWindow; class MainWindow;
class QVBoxLayout; class QVBoxLayout;
class QComboBox; class QComboBox;
class QSpinBox; class QSpinBox;
#include <QDialog> /**
* A utility class that can optionally be used to provide a GUI for
/** A utility class that can optionally be used to provide a GUI for * configuring audio settings.
* configuring sound/audio settings.
*/ */
class SoundDialog : public QDialog { class SoundDialog : public QDialog {
Q_OBJECT Q_OBJECT
const MainWindow *const mw; MainWindow const &mw_;
QVBoxLayout *const topLayout; QVBoxLayout *const topLayout;
QComboBox *const engineSelector; QComboBox *const engineSelector;
QComboBox *const resamplerSelector; QComboBox *const resamplerSelector;
@ -53,18 +53,18 @@ private slots:
void rateIndexChange(int index); void rateIndexChange(int index);
public: public:
explicit SoundDialog(const MainWindow *mw, QWidget *parent = 0); explicit SoundDialog(MainWindow const &mw, QWidget *parent = 0);
~SoundDialog(); ~SoundDialog();
int engineIndex() const { return engineIndex_; } int engineIndex() const { return engineIndex_; }
int resamplerNo() const { return resamplerNum; } int resamplerNo() const { return resamplerNum; }
int rate() const { return rate_; } int rate() const { return rate_; }
int latency() const { return latency_; }; int latency() const { return latency_; };
static void applySettings(MainWindow *mw, const SoundDialog *sd);
public slots: public slots:
void accept(); void accept();
void reject(); void reject();
}; };
void applySettings(MainWindow &mw, SoundDialog const &sd);
#endif #endif

View File

@ -35,7 +35,8 @@ class QRadioButton;
class QLabel; class QLabel;
class QBoxLayout; class QBoxLayout;
/** A utility class that can optionally be used to provide a GUI for /**
* A utility class that can optionally be used to provide a GUI for
* configuring video settings. * configuring video settings.
*/ */
class VideoDialog : public QDialog { class VideoDialog : public QDialog {
@ -66,7 +67,7 @@ private:
PersistInt index_; PersistInt index_;
public: public:
explicit EngineSelector(const MainWindow *mw); explicit EngineSelector(MainWindow const &mw);
void addToLayout(QBoxLayout *topLayout); void addToLayout(QBoxLayout *topLayout);
const QComboBox * comboBox() const { return comboBox_; } const QComboBox * comboBox() const { return comboBox_; }
void store(); void store();
@ -104,52 +105,18 @@ private:
int index() const { return index_; } int index() const { return index_; }
}; };
class FullResSelector { class FullResSelector;
QComboBox *const comboBox_; class FullHzSelector;
const QString key_;
int index_;
void fillComboBox(const QSize &sourceSize, const std::vector<ResInfo> &resVector); MainWindow const &mw_;
public:
FullResSelector(const QString &key, int defaultIndex,
const QSize &sourceSize, const std::vector<ResInfo> &resVector);
~FullResSelector();
QWidget * widget();
const QComboBox * comboBox() const { return comboBox_; }
void store();
void restore();
void setSourceSize(const QSize &sourceSize, const std::vector<ResInfo> &resVector);
int index() const { return index_; }
};
class FullHzSelector {
QComboBox *const comboBox_;
const QString key_;
int index_;
public:
FullHzSelector(const QString &key, const std::vector<short> &rates, int defaultIndex);
~FullHzSelector();
QWidget * widget();
const QComboBox * comboBox() const { return comboBox_; }
void store();
void restore();
void setRates(const std::vector<short> &rates);
int index() const { return index_; }
};
const MainWindow *const mw;
QVBoxLayout *const topLayout; QVBoxLayout *const topLayout;
QWidget *engineWidget; QWidget *engineWidget;
EngineSelector engineSelector; EngineSelector engineSelector;
ScalingMethodSelector scalingMethodSelector; ScalingMethodSelector scalingMethodSelector;
SourceSelector sourceSelector; SourceSelector sourceSelector;
const auto_vector<FullResSelector> fullResSelectors; auto_vector<FullResSelector> const fullResSelectors;
const auto_vector<FullHzSelector> fullHzSelectors; auto_vector<FullHzSelector> const fullHzSelectors;
static auto_vector<FullResSelector> makeFullResSelectors(const QSize &sourceSize, const MainWindow *mw);
static auto_vector<FullHzSelector> makeFullHzSelectors(
const auto_vector<FullResSelector> &fullResSelectors, const MainWindow *mw);
void fillFullResSelectors(); void fillFullResSelectors();
void store(); void store();
void restore(); void restore();
@ -160,17 +127,18 @@ private slots:
void sourceChange(int index); void sourceChange(int index);
public: public:
VideoDialog(const MainWindow *mw, VideoDialog(MainWindow const &mw,
const std::vector<VideoSourceInfo> &sourceInfos, std::vector<VideoSourceInfo> const &sourceInfos,
const QString &sourcesLabel, QString const &sourcesLabel,
QWidget *parent = 0); QWidget *parent = 0);
~VideoDialog();
int blitterNo() const; int blitterNo() const;
unsigned fullResIndex(unsigned screen) const; unsigned fullResIndex(unsigned screen) const;
unsigned fullRateIndex(unsigned screen) const; unsigned fullRateIndex(unsigned screen) const;
unsigned sourceIndex() const { return sourceSelector.index(); } unsigned sourceIndex() const { return sourceSelector.index(); }
const QSize sourceSize() const; QSize const sourceSize() const;
void setVideoSources(const std::vector<VideoSourceInfo> &sourceInfos); void setVideoSources(std::vector<VideoSourceInfo> const &sourceInfos);
void setSourceSize(const QSize &sourceSize); void setSourceSize(QSize const &sourceSize);
ScalingMethod scalingMethod() const { return scalingMethodSelector.scalingMethod(); } ScalingMethod scalingMethod() const { return scalingMethodSelector.scalingMethod(); }
public slots: public slots:
@ -178,6 +146,6 @@ public slots:
void reject(); void reject();
}; };
void applySettings(MainWindow *mw, const VideoDialog *vd); void applySettings(MainWindow &mw, VideoDialog const &vd);
#endif #endif

View File

@ -23,18 +23,22 @@
#include <QLayout> #include <QLayout>
#include <QtGlobal> // for Q_WS_WIN define #include <QtGlobal> // for Q_WS_WIN define
MainWindow::FrameBuffer::Locked::Locked(FrameBuffer fb) : mw(0), pb() { MainWindow::FrameBuffer::Locked::Locked(FrameBuffer fb)
if (fb.mw->tryLockFrameBuf(pb)) : mw_(), pb_()
mw = fb.mw; {
if (fb.mw_->tryLockFrameBuf(pb_))
mw_ = fb.mw_;
} }
MainWindow::FrameBuffer::Locked::~Locked() { MainWindow::FrameBuffer::Locked::~Locked() {
if (mw) if (mw_)
mw->unlockFrameBuf(); mw_->unlockFrameBuf();
} }
MainWindow::MainWindow(MediaSource *const source) MainWindow::MainWindow(MediaSource &source)
: w_(new MediaWidget(source, *this)), winSize_(-1, -1), fullscreen_(false) : w_(new MediaWidget(source, *this))
, winSize_(-1, -1)
, fullscreen_(false)
{ {
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
setCentralWidget(w_->widget()); setCentralWidget(w_->widget());

View File

@ -209,7 +209,7 @@ void MediaWidget::WorkerCallback::consumeBlitRequest() {
BlitterWidget *const blitter = mw.blitterContainer->blitter(); BlitterWidget *const blitter = mw.blitterContainer->blitter();
MediaWorker *const worker = mw.worker; MediaWorker *const worker = mw.worker;
worker->source()->generateVideoFrame(blitter->inBuffer()); worker->source().generateVideoFrame(blitter->inBuffer());
blitter->blit(); blitter->blit();
base = synctimebase; base = synctimebase;
@ -256,7 +256,7 @@ static auto_vector<AudioEngine> makeAudioEngines(const WId winId) {
return audioEngines; return audioEngines;
} }
MediaWidget::MediaWidget(MediaSource *const source, QWidget &parent) MediaWidget::MediaWidget(MediaSource &source, QWidget &parent)
: QObject(&parent), : QObject(&parent),
vbmut(), vbmut(),
blitterContainer(new BlitterContainer(&parent)), blitterContainer(new BlitterContainer(&parent)),
@ -264,7 +264,7 @@ MediaWidget::MediaWidget(MediaSource *const source, QWidget &parent)
blitters(makeBlitterWidgets(VideoBufferLocker(vbmut), DwmControlHwndChange(dwmControl_))), blitters(makeBlitterWidgets(VideoBufferLocker(vbmut), DwmControlHwndChange(dwmControl_))),
fullModeToggler(getFullModeToggler(parent.winId())), fullModeToggler(getFullModeToggler(parent.winId())),
workerCallback_(new WorkerCallback(*this)), workerCallback_(new WorkerCallback(*this)),
worker(new MediaWorker(source, audioEngines.back(), 48000, 100, 1, worker(new MediaWorker(source, *audioEngines.back(), 48000, 100, 1,
*workerCallback_, this)), *workerCallback_, this)),
frameRateControl(*worker, blitters.back()), frameRateControl(*worker, blitters.back()),
cursorTimer(new QTimer(this)), cursorTimer(new QTimer(this)),
@ -446,7 +446,7 @@ void MediaWidget::keyPressEvent(QKeyEvent *e) {
e->ignore(); e->ignore();
if (running && !e->isAutoRepeat()) { if (running && !e->isAutoRepeat()) {
worker->source()->keyPressEvent(e); worker->source().keyPressEvent(e);
blitterContainer->hideCursor(); blitterContainer->hideCursor();
} }
} }
@ -455,7 +455,7 @@ void MediaWidget::keyReleaseEvent(QKeyEvent *e) {
e->ignore(); e->ignore();
if (running && !e->isAutoRepeat()) if (running && !e->isAutoRepeat())
worker->source()->keyReleaseEvent(e); worker->source().keyReleaseEvent(e);
} }
void MediaWidget::setFrameTime(long num, long denom) { void MediaWidget::setFrameTime(long num, long denom) {
@ -491,7 +491,7 @@ struct MediaWidget::FrameStepFun {
if (mw.running && mw.worker->frameStep()) { if (mw.running && mw.worker->frameStep()) {
BlitterWidget *const blitter = mw.blitterContainer->blitter(); BlitterWidget *const blitter = mw.blitterContainer->blitter();
mw.worker->source()->generateVideoFrame(blitter->inBuffer()); mw.worker->source().generateVideoFrame(blitter->inBuffer());
blitter->blit(); blitter->blit();
blitter->draw(); blitter->draw();

View File

@ -102,7 +102,7 @@ private slots:
void updateJoysticks(); void updateJoysticks();
public: public:
MediaWidget(MediaSource *source, QWidget &parent); MediaWidget(MediaSource &source, QWidget &parent);
~MediaWidget(); ~MediaWidget();
QWidget* widget() const { return blitterContainer; } QWidget* widget() const { return blitterContainer; }
@ -130,7 +130,7 @@ public:
void unlockFrameBuf() { vbmut.unlock(); } void unlockFrameBuf() { vbmut.unlock(); }
const QSize& videoSize() const { return blitterContainer->sourceSize(); } QSize const videoSize() const { return blitterContainer->sourceSize(); }
void setFrameTime(long num, long denom); void setFrameTime(long num, long denom);
void setSamplesPerFrame(long num, long denom = 1) { worker->setSamplesPerFrame(Rational(num, denom)); } void setSamplesPerFrame(long num, long denom = 1) { worker->setSamplesPerFrame(Rational(num, denom)); }
@ -187,7 +187,7 @@ public:
std::size_t numAudioEngines() const { return audioEngines.size(); } std::size_t numAudioEngines() const { return audioEngines.size(); }
void setAudioOut(std::size_t engineNo, unsigned srateHz, unsigned msecLatency, std::size_t resamplerNo) { void setAudioOut(std::size_t engineNo, unsigned srateHz, unsigned msecLatency, std::size_t resamplerNo) {
worker->setAudioOut(audioEngines[engineNo], srateHz, msecLatency, resamplerNo); worker->setAudioOut(*audioEngines[engineNo], srateHz, msecLatency, resamplerNo);
} }
std::size_t numResamplers() const { return ResamplerInfo::num(); } std::size_t numResamplers() const { return ResamplerInfo::num(); }

View File

@ -128,15 +128,18 @@ void MediaWorker::PauseVar::waitWhilePaused(MediaWorker::Callback &cb, AudioOut
waiting = false; waiting = false;
} }
MediaWorker::MediaWorker(MediaSource *source, AudioEngine *ae, int aerate, MediaWorker::MediaWorker(MediaSource &source,
int aelatency, std::size_t resamplerNo, Callback &callback, QObject *parent) AudioEngine &ae, int aerate, int aelatency,
std::size_t resamplerNo,
Callback &callback,
QObject *parent)
: QThread(parent), : QThread(parent),
callback(callback), callback(callback),
meanQueue(0, 0), meanQueue(0, 0),
frameTimeEst(0), frameTimeEst(0),
doneVar(true), doneVar(true),
sampleBuffer(source), sampleBuffer(source),
ao_(new AudioOut(*ae, aerate, aelatency, resamplerNo)), ao_(new AudioOut(ae, aerate, aelatency, resamplerNo)),
usecft(0) usecft(0)
{ {
} }
@ -191,19 +194,19 @@ void MediaWorker::resetAudio() {
} }
struct MediaWorker::SetAudioOut { struct MediaWorker::SetAudioOut {
MediaWorker &w; AudioEngine *const ae; const int rate; const int latency; MediaWorker &w; AudioEngine &ae; const int rate; const int latency;
const std::size_t resamplerNo; const std::size_t resamplerNo;
void operator()() const { void operator()() const {
const bool inited = w.ao_->initialized(); const bool inited = w.ao_->initialized();
w.ao_.reset(); w.ao_.reset();
w.ao_.reset(new AudioOut(*ae, rate, latency, resamplerNo)); w.ao_.reset(new AudioOut(ae, rate, latency, resamplerNo));
if (inited) if (inited)
w.initAudioEngine(); w.initAudioEngine();
} }
}; };
void MediaWorker::setAudioOut(AudioEngine *newAe, int rate, int latency, std::size_t resamplerNo) { void MediaWorker::setAudioOut(AudioEngine &newAe, int rate, int latency, std::size_t resamplerNo) {
const SetAudioOut setAudioOutStruct = { *this, newAe, rate, latency, resamplerNo }; const SetAudioOut setAudioOutStruct = { *this, newAe, rate, latency, resamplerNo };
pushCall(setAudioOutStruct); pushCall(setAudioOutStruct);
} }
@ -255,7 +258,7 @@ void MediaWorker::updateJoysticks() {
SDL_Event ev; SDL_Event ev;
while (pollJsEvent(&ev)) while (pollJsEvent(&ev))
source()->joystickEvent(ev); source().joystickEvent(ev);
JoystickLock::unlock(); JoystickLock::unlock();
} }

View File

@ -32,6 +32,8 @@
#include <QWaitCondition> #include <QWaitCondition>
#include <deque> #include <deque>
class AudioEngine;
class MediaWorker : private QThread { class MediaWorker : private QThread {
public: public:
class Callback { class Callback {
@ -39,7 +41,6 @@ public:
virtual void paused() = 0; virtual void paused() = 0;
virtual void blit(usec_t synctimebase, usec_t synctimeinc) = 0; virtual void blit(usec_t synctimebase, usec_t synctimeinc) = 0;
virtual bool cancelBlit() = 0; virtual bool cancelBlit() = 0;
// virtual void sync() = 0;
virtual void audioEngineFailure() = 0; virtual void audioEngineFailure() = 0;
virtual bool tryLockVideoBuffer(PixelBuffer &pb) = 0; virtual bool tryLockVideoBuffer(PixelBuffer &pb) = 0;
virtual void unlockVideoBuffer() = 0; virtual void unlockVideoBuffer() = 0;
@ -139,10 +140,10 @@ protected:
void run(); void run();
public: public:
MediaWorker(MediaSource *source, class AudioEngine *ae, int aerate, int aelatency, MediaWorker(MediaSource &source, AudioEngine &ae, int aerate, int aelatency,
std::size_t resamplerNo, Callback &callback, QObject *parent = 0); std::size_t resamplerNo, Callback &callback, QObject *parent = 0);
MediaSource* source() /*const */{ return sampleBuffer.source(); } MediaSource & source() const { return sampleBuffer.source(); }
SyncVar& waitingForSync() /*const */{ return waitingForSync_; } SyncVar & waitingForSync() { return waitingForSync_; }
void start(); void start();
void stop(); void stop();
void pause(); void pause();
@ -153,11 +154,11 @@ public:
bool paused() const { return pauseVar.waitingForUnpause(); } bool paused() const { return pauseVar.waitingForUnpause(); }
void resetAudio(); void resetAudio();
void setAudioOut(class AudioEngine *newAe, int rate, int latency, std::size_t resamplerNo); void setAudioOut(AudioEngine &newAe, int rate, int latency, std::size_t resamplerNo);
void setFrameTime(Rational ft); void setFrameTime(Rational ft);
void setSamplesPerFrame(Rational spf); void setSamplesPerFrame(Rational spf);
void setFrameTimeEstimate(const long ftest) { AtomicVar<long>::Locked(frameTimeEst).set(ftest); } void setFrameTimeEstimate(long ftest) { AtomicVar<long>::Locked(frameTimeEst).set(ftest); }
bool frameStep(); bool frameStep();
void setFastForwardSpeed(unsigned speed) { turboSkip.setSpeed(speed); } void setFastForwardSpeed(unsigned speed) { turboSkip.setSpeed(speed); }

View File

@ -26,7 +26,7 @@ static T * ptr_cast(void *p) { return static_cast<T *>(p); }
void SampleBuffer::reset() { void SampleBuffer::reset() {
const long insrate = static_cast<long>(ft_.reciprocal().toFloat() * spf_.toFloat() + 0.5f); const long insrate = static_cast<long>(ft_.reciprocal().toFloat() * spf_.toFloat() + 0.5f);
const long maxin = spf_.ceiled() + source_->overupdate; const long maxin = spf_.ceiled() + source_.overupdate;
sndInBuffer_.reset(0); sndInBuffer_.reset(0);
resampler_.reset(); resampler_.reset();
@ -40,7 +40,7 @@ void SampleBuffer::reset() {
long SampleBuffer::update(const PixelBuffer &pb) { long SampleBuffer::update(const PixelBuffer &pb) {
long insamples = sndInBuffer_.size() - samplesBuffered_; long insamples = sndInBuffer_.size() - samplesBuffered_;
const long res = source_->update(pb, ptr_cast<qint16>(sndInBuffer_ + samplesBuffered_), const long res = source_.update(pb, ptr_cast<qint16>(sndInBuffer_ + samplesBuffered_),
insamples); insamples);
samplesBuffered_ += insamples; samplesBuffered_ += insamples;
return res < 0 ? res : samplesBuffered_ - insamples + res; return res < 0 ? res : samplesBuffered_ - insamples + res;

View File

@ -19,17 +19,17 @@
#ifndef SAMPLEBUFFER_H #ifndef SAMPLEBUFFER_H
#define SAMPLEBUFFER_H #define SAMPLEBUFFER_H
class MediaSource;
struct PixelBuffer;
#include "array.h" #include "array.h"
#include "rational.h" #include "rational.h"
#include "resample/resampler.h" #include "resample/resampler.h"
#include "scoped_ptr.h" #include "scoped_ptr.h"
#include <QtGlobal> #include <QtGlobal>
class MediaSource;
struct PixelBuffer;
class SampleBuffer : Uncopyable { class SampleBuffer : Uncopyable {
MediaSource *const source_; MediaSource &source_;
scoped_ptr<Resampler> resampler_; scoped_ptr<Resampler> resampler_;
Array<quint32> sndInBuffer_; Array<quint32> sndInBuffer_;
long samplesBuffered_; long samplesBuffered_;
@ -41,7 +41,7 @@ class SampleBuffer : Uncopyable {
void reset(); void reset();
public: public:
explicit SampleBuffer(MediaSource *source) explicit SampleBuffer(MediaSource &source)
: source_(source) : source_(source)
, spf_(0) , spf_(0)
, ft_(1, 0) , ft_(1, 0)
@ -65,10 +65,9 @@ public:
void setOutSampleRate(long outsrate) { setOutSampleRate(outsrate, resamplerNo_); } void setOutSampleRate(long outsrate) { setOutSampleRate(outsrate, resamplerNo_); }
long maxOut() const { return resampler_ ? resampler_->maxOut(sndInBuffer_.size()) : 0; } long maxOut() const { return resampler_ ? resampler_->maxOut(sndInBuffer_.size()) : 0; }
MediaSource* source() { return source_; } MediaSource & source() const { return source_; }
const MediaSource* source() const { return source_; } Rational spf() const { return spf_; }
const Rational& spf() const { return spf_; } Rational ft() const { return ft_; }
const Rational& ft() const { return ft_; }
long resamplerOutRate() const { return resampler_->outRate(); } long resamplerOutRate() const { return resampler_->outRate(); }
void adjustResamplerOutRate(long outRate) { resampler_->adjustRate(resampler_->inRate(), outRate); } void adjustResamplerOutRate(long outRate) { resampler_->adjustRate(resampler_->inRate(), outRate); }
}; };

View File

@ -1,5 +1,5 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s * * Copyright (C) 2007 by Sindre Aamås *
* sinamas@users.sourceforge.net * * sinamas@users.sourceforge.net *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
@ -17,18 +17,18 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "sounddialog.h" #include "sounddialog.h"
#include "mainwindow.h"
#include "audioengineconf.h" #include "audioengineconf.h"
#include "mainwindow.h"
#include "resample/resamplerinfo.h" #include "resample/resamplerinfo.h"
#include <QComboBox> #include <QComboBox>
#include <QSpinBox>
#include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QInputDialog>
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QSettings> #include <QSettings>
#include <QSize> #include <QSize>
#include <QInputDialog> #include <QSpinBox>
#include <QVBoxLayout>
#include <cassert> #include <cassert>
namespace { namespace {
@ -114,19 +114,19 @@ static void setRate(QComboBox *rateSelector, const int r) {
} }
SoundDialog::SoundDialog(const MainWindow *const mw, QWidget *const parent) : SoundDialog::SoundDialog(MainWindow const &mw, QWidget *const parent)
QDialog(parent), : QDialog(parent)
mw(mw), , mw_(mw)
topLayout(new QVBoxLayout), , topLayout(new QVBoxLayout)
engineSelector(new QComboBox(this)), , engineSelector(new QComboBox(this))
resamplerSelector(new QComboBox(this)), , resamplerSelector(new QComboBox(this))
rateSelector(new QComboBox(this)), , rateSelector(new QComboBox(this))
latencySelector(new QSpinBox(this)), , latencySelector(new QSpinBox(this))
engineWidget(NULL), , engineWidget()
engineIndex_(0), , engineIndex_(0)
resamplerNum(1), , resamplerNum(1)
rate_(0), , rate_(0)
latency_(68) , latency_(68)
{ {
setWindowTitle(tr("Sound Settings")); setWindowTitle(tr("Sound Settings"));
@ -136,8 +136,8 @@ SoundDialog::SoundDialog(const MainWindow *const mw, QWidget *const parent) :
QHBoxLayout *const hLayout = new QHBoxLayout; QHBoxLayout *const hLayout = new QHBoxLayout;
hLayout->addWidget(new QLabel(tr("Sound engine:"))); hLayout->addWidget(new QLabel(tr("Sound engine:")));
for (std::size_t i = 0; i < mw->numAudioEngines(); ++i) for (std::size_t i = 0; i < mw.numAudioEngines(); ++i)
engineSelector->addItem(mw->audioEngineConf(i).nameString()); engineSelector->addItem(mw.audioEngineConf(i).nameString());
hLayout->addWidget(engineSelector); hLayout->addWidget(engineSelector);
topLayout->addLayout(hLayout); topLayout->addLayout(hLayout);
@ -227,7 +227,7 @@ void SoundDialog::engineChange(int index) {
engineWidget->setParent(NULL); engineWidget->setParent(NULL);
} }
if ((engineWidget = mw->audioEngineConf(index).settingsWidget())) if ((engineWidget = mw_.audioEngineConf(index).settingsWidget()))
topLayout->insertWidget(1, engineWidget); topLayout->insertWidget(1, engineWidget);
} }
@ -255,8 +255,8 @@ void SoundDialog::store() {
} }
void SoundDialog::restore() { void SoundDialog::restore() {
for (std::size_t i = 0; i < mw->numAudioEngines(); ++i) for (std::size_t i = 0; i < mw_.numAudioEngines(); ++i)
mw->audioEngineConf(i).rejectSettings(); mw_.audioEngineConf(i).rejectSettings();
engineSelector->setCurrentIndex(engineIndex_); engineSelector->setCurrentIndex(engineIndex_);
resamplerSelector->setCurrentIndex(resamplerNum); resamplerSelector->setCurrentIndex(resamplerNum);
@ -274,9 +274,9 @@ void SoundDialog::reject() {
QDialog::reject(); QDialog::reject();
} }
void SoundDialog::applySettings(MainWindow *const mw, const SoundDialog *const sd) { void applySettings(MainWindow &mw, SoundDialog const &sd) {
for (std::size_t i = 0; i < mw->numAudioEngines(); ++i) for (std::size_t i = 0; i < mw.numAudioEngines(); ++i)
mw->audioEngineConf(i).acceptSettings(); mw.audioEngineConf(i).acceptSettings();
mw->setAudioOut(sd->engineIndex(), sd->rate(), sd->latency(), sd->resamplerNo()); mw.setAudioOut(sd.engineIndex(), sd.rate(), sd.latency(), sd.resamplerNo());
} }

View File

@ -17,23 +17,22 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "videodialog.h" #include "videodialog.h"
#include "mainwindow.h"
#include "blitterconf.h" #include "blitterconf.h"
#include "mainwindow.h"
#include <QPushButton>
#include <QComboBox>
#include <QRadioButton>
#include <QString>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QSettings>
#include <QGroupBox>
#include <QApplication> #include <QApplication>
#include <QComboBox>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QSettings>
#include <QString>
#include <QVBoxLayout>
#include <functional> #include <functional>
static int filterValue(const int value, const int upper, const int lower = 0, const int fallback = 0) { static int filterValue(int value, int upper, int lower = 0, int fallback = 0) {
if (value >= upper || value < lower) if (value >= upper || value < lower)
return fallback; return fallback;
@ -50,11 +49,12 @@ VideoDialog::PersistInt::~PersistInt() {
settings.setValue(key_, i_); settings.setValue(key_, i_);
} }
VideoDialog::EngineSelector::EngineSelector(const MainWindow *const mw) VideoDialog::EngineSelector::EngineSelector(MainWindow const &mw)
: comboBox_(new QComboBox), index_("video/engineIndex", mw->numBlitters()) : comboBox_(new QComboBox)
, index_("video/engineIndex", mw.numBlitters())
{ {
for (std::size_t i = 0; i < mw->numBlitters(); ++i) for (std::size_t i = 0; i < mw.numBlitters(); ++i)
comboBox_->addItem(mw->blitterConf(i).nameString()); comboBox_->addItem(mw.blitterConf(i).nameString());
restore(); restore();
} }
@ -150,61 +150,82 @@ void VideoDialog::SourceSelector::setVideoSources(const std::vector<VideoSourceI
} }
} }
VideoDialog::FullResSelector::FullResSelector( class VideoDialog::FullResSelector {
const QString &key, const int defaultIndex, public:
const QSize &sourceSize, const std::vector<ResInfo> &resVector) ~FullResSelector();
: comboBox_(new QComboBox), key_(key), index_(defaultIndex) QWidget * widget() const { return comboBox_; }
QComboBox const * comboBox() const { return comboBox_; }
void store() { index_ = comboBox_->currentIndex(); }
void restore() { comboBox_->setCurrentIndex(index_); }
void setSourceSize(QSize const &sourceSize, std::vector<ResInfo> const &resVector);
int index() const { return index_; }
static auto_vector<FullResSelector> createSelectors(QSize const &sourceSize,
MainWindow const &mw)
{
auto_vector<FullResSelector> v(mw.screens());
for (std::size_t i = 0; i < v.size(); ++i) {
v.reset(i, new FullResSelector("video/fullRes" + QString::number(i),
mw.currentResIndex(i), sourceSize,
mw.modeVector(i)));
}
return v;
}
private:
QComboBox *const comboBox_;
QString const key_;
int index_;
FullResSelector(QString const &key,
int const defaultIndex,
QSize const &sourceSize,
std::vector<ResInfo> const &resVector)
: comboBox_(new QComboBox)
, key_(key)
, index_(defaultIndex)
{ {
fillComboBox(sourceSize, resVector); fillComboBox(sourceSize, resVector);
index_ = filterValue(comboBox_->findText(QSettings().value(key).toString()), index_ = filterValue(comboBox_->findText(QSettings().value(key).toString()),
comboBox_->count(), 0, index_); comboBox_->count(), 0, index_);
restore(); restore();
} }
void fillComboBox(QSize const &sourceSize, std::vector<ResInfo> const &resVector);
};
VideoDialog::FullResSelector::~FullResSelector() { VideoDialog::FullResSelector::~FullResSelector() {
QSettings settings; QSettings settings;
settings.setValue(key_, comboBox_->itemText(index_)); settings.setValue(key_, comboBox_->itemText(index_));
} }
QWidget* VideoDialog::FullResSelector::widget() { void VideoDialog::FullResSelector::setSourceSize(
return comboBox_; QSize const &sourceSize, std::vector<ResInfo> const &resVector) {
} QString const oldtext(comboBox_->itemText(comboBox_->currentIndex()));
void VideoDialog::FullResSelector::store() {
index_ = comboBox_->currentIndex();
}
void VideoDialog::FullResSelector::restore() {
comboBox_->setCurrentIndex(index_);
}
void VideoDialog::FullResSelector::setSourceSize(const QSize &sourceSize, const std::vector<ResInfo> &resVector) {
const QString oldtext(comboBox_->itemText(comboBox_->currentIndex()));
comboBox_->clear(); comboBox_->clear();
fillComboBox(sourceSize, resVector); fillComboBox(sourceSize, resVector);
const int newIndex = comboBox_->findText(oldtext); int newIndex = comboBox_->findText(oldtext);
if (newIndex >= 0) if (newIndex >= 0)
comboBox_->setCurrentIndex(newIndex); comboBox_->setCurrentIndex(newIndex);
} }
void VideoDialog::FullResSelector::fillComboBox(const QSize &sourceSize, const std::vector<ResInfo> &resVector) { void VideoDialog::FullResSelector::fillComboBox(
QSize const &sourceSize, std::vector<ResInfo> const &resVector) {
long maxArea = 0; long maxArea = 0;
std::size_t maxAreaI = 0; std::size_t maxAreaI = 0;
for (std::size_t i = 0; i < resVector.size(); ++i) { for (std::size_t i = 0; i < resVector.size(); ++i) {
const int hres = resVector[i].w; int const hres = resVector[i].w;
const int vres = resVector[i].h; int const vres = resVector[i].h;
if (hres >= sourceSize.width() && vres >= sourceSize.height()) { if (hres >= sourceSize.width() && vres >= sourceSize.height()) {
comboBox_->addItem(QString::number(hres) + QString("x") + QString::number(vres), static_cast<uint>(i)); comboBox_->addItem(QString::number(hres) + QString("x") + QString::number(vres),
static_cast<uint>(i));
} else { } else {
const long area = static_cast<long>(std::min(hres, sourceSize.width())) * std::min(vres, sourceSize.height()); long area = long(std::min(hres, sourceSize.width()))
* std::min(vres, sourceSize.height());
if (area > maxArea) { if (area > maxArea) {
maxArea = area; maxArea = area;
maxAreaI = i; maxAreaI = i;
@ -213,99 +234,103 @@ void VideoDialog::FullResSelector::fillComboBox(const QSize &sourceSize, const s
} }
// add resolution giving maximal area if all resolutions are too small. // add resolution giving maximal area if all resolutions are too small.
if (comboBox_->count() < 1 && maxArea) if (comboBox_->count() < 1 && maxArea) {
comboBox_->addItem(QString::number(resVector[maxAreaI].w) + "x" + QString::number(resVector[maxAreaI].h), static_cast<uint>(maxAreaI)); comboBox_->addItem(QString::number(resVector[maxAreaI].w)
+ "x" + QString::number(resVector[maxAreaI].h),
static_cast<uint>(maxAreaI));
}
} }
VideoDialog::FullHzSelector::FullHzSelector(const QString &key, const std::vector<short> &rates, const int defaultIndex) class VideoDialog::FullHzSelector {
: comboBox_(new QComboBox), key_(key), index_(0) public:
~FullHzSelector();
QWidget * widget() const { return comboBox_; }
QComboBox const * comboBox() const { return comboBox_; }
void store() { index_ = comboBox_->currentIndex(); }
void restore() { comboBox_->setCurrentIndex(index_); }
void setRates(std::vector<short> const &rates);
int index() const { return index_; }
static auto_vector<FullHzSelector> createSelectors(
auto_vector<FullResSelector> const &fullResSelectors,
MainWindow const &mw)
{
auto_vector<FullHzSelector> v(fullResSelectors.size());
for (std::size_t i = 0; i < v.size(); ++i) {
int const resindex = fullResSelectors[i]->comboBox()->currentIndex();
std::vector<short> const &rates = resindex >= 0
? mw.modeVector(i)[resindex].rates
: std::vector<short>();
int defaultRateIndex = resindex == static_cast<int>(mw.currentResIndex(i))
? mw.currentRateIndex(i)
: 0;
v.reset(i, new FullHzSelector("video/hz" + QString::number(i),
rates, defaultRateIndex));
}
return v;
}
private:
QComboBox *const comboBox_;
QString const key_;
int index_;
FullHzSelector(QString const &key,
std::vector<short> const &rates,
int const defaultIndex)
: comboBox_(new QComboBox)
, key_(key)
, index_(0)
{ {
setRates(rates); setRates(rates);
index_ = filterValue(comboBox_->findText(QSettings().value(key).toString()),
index_ = filterValue(
comboBox_->findText(QSettings().value(key).toString()),
comboBox_->count(), comboBox_->count(),
0, 0,
defaultIndex); defaultIndex);
restore(); restore();
} }
};
VideoDialog::FullHzSelector::~FullHzSelector() { VideoDialog::FullHzSelector::~FullHzSelector() {
QSettings settings; QSettings settings;
settings.setValue(key_, comboBox_->itemText(index_)); settings.setValue(key_, comboBox_->itemText(index_));
} }
QWidget* VideoDialog::FullHzSelector::widget() { void VideoDialog::FullHzSelector::setRates(std::vector<short> const &rates) {
return comboBox_;
}
void VideoDialog::FullHzSelector::store() {
index_ = comboBox_->currentIndex();
}
void VideoDialog::FullHzSelector::restore() {
comboBox_->setCurrentIndex(index_);
}
void VideoDialog::FullHzSelector::setRates(const std::vector<short> &rates) {
comboBox_->clear(); comboBox_->clear();
for (std::size_t i = 0; i < rates.size(); ++i) {
for (std::size_t i = 0; i < rates.size(); ++i) comboBox_->addItem(QString::number(rates[i] / 10.0) + QString(" Hz"),
comboBox_->addItem(QString::number(rates[i] / 10.0) + QString(" Hz"), static_cast<uint>(i)); static_cast<uint>(i));
}
} }
auto_vector<VideoDialog::FullResSelector> VideoDialog::makeFullResSelectors( VideoDialog::VideoDialog(MainWindow const &mw,
const QSize &sourceSize, const MainWindow *const mw) std::vector<VideoSourceInfo> const &sourceInfos,
{ QString const &sourcesLabel,
auto_vector<FullResSelector> v(mw->screens());
for (std::size_t i = 0; i < v.size(); ++i) {
v.reset(i, new FullResSelector("video/fullRes" + QString::number(i),
mw->currentResIndex(i), sourceSize,
mw->modeVector(i)));
}
return v;
}
auto_vector<VideoDialog::FullHzSelector> VideoDialog::makeFullHzSelectors(
const auto_vector<FullResSelector> &fullResSelectors, const MainWindow *const mw)
{
auto_vector<FullHzSelector> v(fullResSelectors.size());
for (std::size_t i = 0; i < v.size(); ++i) {
const int index = fullResSelectors[i]->comboBox()->currentIndex();
v.reset(i, new FullHzSelector("video/hz" + QString::number(i),
index >= 0 ? mw->modeVector(i)[index].rates : std::vector<short>(),
index == static_cast<int>(mw->currentResIndex(i)) ? mw->currentRateIndex(i) : 0));
}
return v;
}
VideoDialog::VideoDialog(const MainWindow *const mw,
const std::vector<VideoSourceInfo> &sourceInfos,
const QString &sourcesLabel,
QWidget *parent) QWidget *parent)
: QDialog(parent), : QDialog(parent)
mw(mw), , mw_(mw)
topLayout(new QVBoxLayout), , topLayout(new QVBoxLayout)
engineWidget(0), , engineWidget(0)
engineSelector(mw), , engineSelector(mw)
sourceSelector(sourcesLabel, sourceInfos), , sourceSelector(sourcesLabel, sourceInfos)
fullResSelectors(makeFullResSelectors(sourceSelector.comboBox()->itemData(sourceSelector.comboBox()->currentIndex()).toSize(), mw)), , fullResSelectors(FullResSelector::createSelectors(
fullHzSelectors(makeFullHzSelectors(fullResSelectors, mw)) sourceSelector.comboBox()->itemData(sourceSelector.comboBox()->currentIndex()).toSize(),
mw))
, fullHzSelectors(FullHzSelector::createSelectors(fullResSelectors, mw))
{ {
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout); setLayout(mainLayout);
engineSelector.addToLayout(topLayout); engineSelector.addToLayout(topLayout);
if ((engineWidget = mw->blitterConf(engineSelector.comboBox()->currentIndex()).settingsWidget())) if ((engineWidget = mw.blitterConf(engineSelector.comboBox()->currentIndex()).settingsWidget()))
topLayout->addWidget(engineWidget); topLayout->addWidget(engineWidget);
for (std::size_t i = 0; i < fullResSelectors.size(); ++i) { for (std::size_t i = 0; i < fullResSelectors.size(); ++i) {
QHBoxLayout *const hLayout = new QHBoxLayout; QHBoxLayout *const hLayout = new QHBoxLayout;
QLabel *const label = new QLabel("Full screen mode (" + mw->screenName(i) + "):"); QLabel *const label = new QLabel("Full screen mode (" + mw.screenName(i) + "):");
hLayout->addWidget(label); hLayout->addWidget(label);
QHBoxLayout *const hhLayout = new QHBoxLayout; QHBoxLayout *const hhLayout = new QHBoxLayout;
@ -314,7 +339,7 @@ VideoDialog::VideoDialog(const MainWindow *const mw,
hLayout->addLayout(hhLayout); hLayout->addLayout(hhLayout);
topLayout->addLayout(hLayout); topLayout->addLayout(hLayout);
if (mw->modeVector(i).empty()) { if (mw.modeVector(i).empty()) {
label->hide(); label->hide();
fullResSelectors[i]->widget()->hide(); fullResSelectors[i]->widget()->hide();
fullHzSelectors[i]->widget()->hide(); fullHzSelectors[i]->widget()->hide();
@ -339,7 +364,8 @@ VideoDialog::VideoDialog(const MainWindow *const mw,
connect(engineSelector.comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(engineChange(int))); connect(engineSelector.comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(engineChange(int)));
for (std::size_t i = 0; i < fullResSelectors.size(); ++i) { for (std::size_t i = 0; i < fullResSelectors.size(); ++i) {
connect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(fullresChange(int))); connect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)),
this, SLOT(fullresChange(int)));
} }
connect(sourceSelector.comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(sourceChange(int))); connect(sourceSelector.comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(sourceChange(int)));
@ -349,27 +375,31 @@ VideoDialog::VideoDialog(const MainWindow *const mw,
setWindowTitle(tr("Video Settings")); setWindowTitle(tr("Video Settings"));
} }
VideoDialog::~VideoDialog() {
}
void VideoDialog::fillFullResSelectors() { void VideoDialog::fillFullResSelectors() {
const QSize &sourceSize = sourceSelector.comboBox()->itemData(sourceSelector.comboBox()->currentIndex()).toSize(); QSize const &sourceSize =
sourceSelector.comboBox()->itemData(sourceSelector.comboBox()->currentIndex()).toSize();
for (std::size_t i = 0; i < fullResSelectors.size(); ++i) { for (std::size_t i = 0; i < fullResSelectors.size(); ++i) {
const int oldResIndex = fullResSelectors[i]->comboBox()->currentIndex(); int const oldResIndex = fullResSelectors[i]->comboBox()->currentIndex();
disconnect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(fullresChange(int))); disconnect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)),
fullResSelectors[i]->setSourceSize(sourceSize, mw->modeVector(i)); this, SLOT(fullresChange(int)));
connect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(fullresChange(int))); fullResSelectors[i]->setSourceSize(sourceSize, mw_.modeVector(i));
connect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)),
this, SLOT(fullresChange(int)));
const int newResIndex = fullResSelectors[i]->comboBox()->currentIndex(); int const newResIndex = fullResSelectors[i]->comboBox()->currentIndex();
if (newResIndex != oldResIndex) {
if (newResIndex != oldResIndex) fullHzSelectors[i]->setRates(newResIndex >= 0
fullHzSelectors[i]->setRates(newResIndex >= 0 ? mw->modeVector(i)[newResIndex].rates : std::vector<short>()); ? mw_.modeVector(i)[newResIndex].rates
: std::vector<short>());
}
} }
} }
void VideoDialog::store() { void VideoDialog::store() {
// for (std::size_t i = 0; i < mw->numBlitters(); ++i)
// mw->blitterConf(i).acceptSettings();
engineSelector.store(); engineSelector.store();
scalingMethodSelector.store(); scalingMethodSelector.store();
sourceSelector.store(); sourceSelector.store();
@ -378,8 +408,8 @@ void VideoDialog::store() {
} }
void VideoDialog::restore() { void VideoDialog::restore() {
for (std::size_t i = 0; i < mw->numBlitters(); ++i) for (std::size_t i = 0; i < mw_.numBlitters(); ++i)
mw->blitterConf(i).rejectSettings(); mw_.blitterConf(i).rejectSettings();
engineSelector.restore(); engineSelector.restore();
scalingMethodSelector.restore(); scalingMethodSelector.restore();
@ -394,14 +424,16 @@ void VideoDialog::engineChange(int index) {
engineWidget->setParent(0); engineWidget->setParent(0);
} }
if ((engineWidget = mw->blitterConf(index).settingsWidget())) if ((engineWidget = mw_.blitterConf(index).settingsWidget()))
topLayout->insertWidget(1, engineWidget); topLayout->insertWidget(1, engineWidget);
} }
void VideoDialog::fullresChange(const int index) { void VideoDialog::fullresChange(int const index) {
for (std::size_t i = 0; i < fullResSelectors.size(); ++i) { for (std::size_t i = 0; i < fullResSelectors.size(); ++i) {
if (sender() == fullResSelectors[i]->comboBox()) { if (sender() == fullResSelectors[i]->comboBox()) {
fullHzSelectors[i]->setRates(index >= 0 ? mw->modeVector(i)[index].rates : std::vector<short>()); fullHzSelectors[i]->setRates(index >= 0
? mw_.modeVector(i)[index].rates
: std::vector<short>());
break; break;
} }
} }
@ -447,22 +479,21 @@ void VideoDialog::reject() {
QDialog::reject(); QDialog::reject();
} }
void applySettings(MainWindow *const mw, const VideoDialog *const vd) { void applySettings(MainWindow &mw, VideoDialog const &vd) {
{ {
const BlitterConf curBlitter = mw->currentBlitterConf(); BlitterConf const curBlitter = mw.currentBlitterConf();
for (std::size_t i = 0; i < mw.numBlitters(); ++i) {
for (std::size_t i = 0; i < mw->numBlitters(); ++i) { if (mw.blitterConf(i) != curBlitter)
if (mw->blitterConf(i) != curBlitter) mw.blitterConf(i).acceptSettings();
mw->blitterConf(i).acceptSettings();
} }
const QSize &srcSz = vd->sourceSize(); QSize const srcSz = vd.sourceSize();
mw->setVideoFormatAndBlitter(srcSz.width(), srcSz.height(), vd->blitterNo()); mw.setVideoFormatAndBlitter(srcSz.width(), srcSz.height(), vd.blitterNo());
curBlitter.acceptSettings(); curBlitter.acceptSettings();
} }
mw->setScalingMethod(vd->scalingMethod()); mw.setScalingMethod(vd.scalingMethod());
for (std::size_t i = 0; i < mw->screens(); ++i) for (std::size_t i = 0; i < mw.screens(); ++i)
mw->setFullScreenMode(i, vd->fullResIndex(i), vd->fullRateIndex(i)); mw.setFullScreenMode(i, vd.fullResIndex(i), vd.fullRateIndex(i));
} }

View File

@ -38,17 +38,17 @@ static QString const strippedName(QString const &fullFileName) {
} }
struct TmpPauser : private Uncopyable { struct TmpPauser : private Uncopyable {
MainWindow *const mw; MainWindow &mw;
unsigned const inc; unsigned const inc;
explicit TmpPauser(MainWindow *mw, unsigned inc = 4) explicit TmpPauser(MainWindow &mw, unsigned inc = 4)
: mw(mw), inc(inc) : mw(mw), inc(inc)
{ {
mw->incPause(inc); mw.incPause(inc);
} }
~TmpPauser() { ~TmpPauser() {
mw->decPause(inc); mw.decPause(inc);
} }
}; };
@ -272,16 +272,17 @@ static void printUsage(char const *const arg0, QList<QAction *> const &actions)
} }
} }
GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, GambatteMenuHandler::GambatteMenuHandler(MainWindow &mw,
GambatteSource *const source, GambatteSource &source,
int const argc, int const argc,
char const *const argv[]) char const *const argv[])
: mw_(mw) : mw_(mw)
, source_(source) , source_(source)
, soundDialog_(new SoundDialog(mw, mw)) , soundDialog_(new SoundDialog(mw, &mw))
, videoDialog_(new VideoDialog(mw, source->generateVideoSourceInfos(), QString("Video filter:"), mw)) , videoDialog_(new VideoDialog(mw, source.generateVideoSourceInfos(),
, miscDialog_(new MiscDialog(settingsPath() + "/saves", mw)) QString("Video filter:"), &mw))
, cheatDialog_(new CheatDialog(settingsPath() + "/cheats.ini", mw)) , miscDialog_(new MiscDialog(settingsPath() + "/saves", &mw))
, cheatDialog_(new CheatDialog(settingsPath() + "/cheats.ini", &mw))
, recentFileActs_() , recentFileActs_()
, pauseAction_() , pauseAction_()
, syncFrameRateAction_() , syncFrameRateAction_()
@ -291,35 +292,35 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw,
, recentMenu_() , recentMenu_()
, globalPaletteDialog_() , globalPaletteDialog_()
, romPaletteDialog_() , romPaletteDialog_()
, stateSlotGroup_(new QActionGroup(mw)) , stateSlotGroup_(new QActionGroup(&mw))
, windowSizeMenu_(*mw, *videoDialog_) , windowSizeMenu_(mw, *videoDialog_)
, pauseInc_(4) , pauseInc_(4)
{ {
mw->setWindowTitle("Gambatte"); mw.setWindowTitle("Gambatte");
source->inputDialog()->setParent(mw, source->inputDialog()->windowFlags()); source.inputDialog()->setParent(&mw, source.inputDialog()->windowFlags());
{ {
QString const &settingspath = settingsPath(); QString const &settingspath = settingsPath();
QString const &palpath = settingspath + "/palettes"; QString const &palpath = settingspath + "/palettes";
QDir::root().mkpath(settingspath + "/saves"); QDir::root().mkpath(settingspath + "/saves");
QDir::root().mkpath(palpath); QDir::root().mkpath(palpath);
globalPaletteDialog_ = new PaletteDialog(palpath, 0, mw); globalPaletteDialog_ = new PaletteDialog(palpath, 0, &mw);
romPaletteDialog_ = new PaletteDialog(palpath, globalPaletteDialog_, mw); romPaletteDialog_ = new PaletteDialog(palpath, globalPaletteDialog_, &mw);
connect(globalPaletteDialog_, SIGNAL(accepted()), this, SLOT(globalPaletteChange())); connect(globalPaletteDialog_, SIGNAL(accepted()), this, SLOT(globalPaletteChange()));
connect(romPaletteDialog_, SIGNAL(accepted()), this, SLOT(romPaletteChange())); connect(romPaletteDialog_, SIGNAL(accepted()), this, SLOT(romPaletteChange()));
} }
QActionGroup *const romLoadedActions = new QActionGroup(mw); QActionGroup *const romLoadedActions = new QActionGroup(&mw);
romLoadedActions->setExclusive(false); romLoadedActions->setExclusive(false);
{ {
for (int i = 0; i < max_recent_files; ++i) { for (int i = 0; i < max_recent_files; ++i) {
recentFileActs_[i] = new QAction(mw); recentFileActs_[i] = new QAction(&mw);
recentFileActs_[i]->setVisible(false); recentFileActs_[i]->setVisible(false);
connect(recentFileActs_[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); connect(recentFileActs_[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
} }
QMenu *fileMenu = mw->menuBar()->addMenu(tr("&File")); QMenu *fileMenu = mw.menuBar()->addMenu(tr("&File"));
fileMenu->addAction(tr("&Open..."), this, SLOT(open()), tr("Ctrl+O")); fileMenu->addAction(tr("&Open..."), this, SLOT(open()), tr("Ctrl+O"));
recentMenu_ = fileMenu->addMenu(tr("Open Re&cent")); recentMenu_ = fileMenu->addMenu(tr("Open Re&cent"));
@ -362,11 +363,11 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw,
updateRecentFileActions(); updateRecentFileActions();
} }
FrameRateAdjuster *const frameRateAdjuster = new FrameRateAdjuster(*miscDialog_, *mw, this); FrameRateAdjuster *const frameRateAdjuster = new FrameRateAdjuster(*miscDialog_, mw, this);
QList<QAction *> cmdactions; QList<QAction *> cmdactions;
{ {
QMenu *const playm = mw->menuBar()->addMenu(tr("&Play")); QMenu *const playm = mw.menuBar()->addMenu(tr("&Play"));
romLoadedActions->addAction(pauseAction_ = playm->addAction( romLoadedActions->addAction(pauseAction_ = playm->addAction(
tr("&Pause"), this, SLOT(pauseChange()), QString("Ctrl+P"))); tr("&Pause"), this, SLOT(pauseChange()), QString("Ctrl+P")));
pauseAction_->setCheckable(true); pauseAction_->setCheckable(true);
@ -378,7 +379,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw,
connect(syncFrameRateAction_, SIGNAL(triggered(bool)), connect(syncFrameRateAction_, SIGNAL(triggered(bool)),
frameRateAdjuster, SLOT(setDisabled(bool))); frameRateAdjuster, SLOT(setDisabled(bool)));
connect(syncFrameRateAction_, SIGNAL(triggered(bool)), connect(syncFrameRateAction_, SIGNAL(triggered(bool)),
mw, SLOT(setSyncToRefreshRate(bool))); &mw, SLOT(setSyncToRefreshRate(bool)));
foreach (QAction *action, frameRateAdjuster->actions()) foreach (QAction *action, frameRateAdjuster->actions())
playm->addAction(romLoadedActions->addAction(action)); playm->addAction(romLoadedActions->addAction(action));
@ -386,7 +387,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw,
cmdactions += playm->actions(); cmdactions += playm->actions();
} }
QMenu *const settingsm = mw->menuBar()->addMenu(tr("&Settings")); QMenu *const settingsm = mw.menuBar()->addMenu(tr("&Settings"));
settingsm->addAction(tr("&Input..."), this, SLOT(execInputDialog())); settingsm->addAction(tr("&Input..."), this, SLOT(execInputDialog()));
settingsm->addAction(tr("&Miscellaneous..."), this, SLOT(execMiscDialog())); settingsm->addAction(tr("&Miscellaneous..."), this, SLOT(execMiscDialog()));
settingsm->addAction(tr("&Sound..."), this, SLOT(execSoundDialog())); settingsm->addAction(tr("&Sound..."), this, SLOT(execSoundDialog()));
@ -414,47 +415,47 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw,
fsAct_->setCheckable(true); fsAct_->setCheckable(true);
cmdactions += settingsm->actions(); cmdactions += settingsm->actions();
romLoadedActions->addAction(mw->menuBar()->addMenu(tr("&Tools"))->addAction(tr("&Cheats..."), romLoadedActions->addAction(mw.menuBar()->addMenu(tr("&Tools"))->addAction(tr("&Cheats..."),
cheatDialog_, SLOT(exec()))); cheatDialog_, SLOT(exec())));
romLoadedActions->setEnabled(false); romLoadedActions->setEnabled(false);
mw->menuBar()->addSeparator(); mw.menuBar()->addSeparator();
QMenu *const helpMenu = mw->menuBar()->addMenu(tr("&Help")); QMenu *const helpMenu = mw.menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(tr("&About"), this, SLOT(about())); helpMenu->addAction(tr("&About"), this, SLOT(about()));
mw->addActions(mw->menuBar()->actions()); mw.addActions(mw.menuBar()->actions());
{ {
QAction *escAct = new QAction(mw); QAction *escAct = new QAction(&mw);
escAct->setShortcut(tr("Esc")); escAct->setShortcut(tr("Esc"));
connect(escAct, SIGNAL(triggered()), this, SLOT(escPressed())); connect(escAct, SIGNAL(triggered()), this, SLOT(escPressed()));
mw->addAction(escAct); mw.addAction(escAct);
} }
mw->setSamplesPerFrame(35112); mw.setSamplesPerFrame(35112);
connect(source, SIGNAL(setTurbo(bool)), mw, SLOT(setFastForward(bool))); connect(&source, SIGNAL(setTurbo(bool)), &mw, SLOT(setFastForward(bool)));
connect(source, SIGNAL(togglePause()), pauseAction_, SLOT(trigger())); connect(&source, SIGNAL(togglePause()), pauseAction_, SLOT(trigger()));
connect(source, SIGNAL(frameStep()), this, SLOT(frameStep())); connect(&source, SIGNAL(frameStep()), this, SLOT(frameStep()));
connect(source, SIGNAL(decFrameRate()), frameRateAdjuster, SLOT(decFrameRate())); connect(&source, SIGNAL(decFrameRate()), frameRateAdjuster, SLOT(decFrameRate()));
connect(source, SIGNAL(incFrameRate()), frameRateAdjuster, SLOT(incFrameRate())); connect(&source, SIGNAL(incFrameRate()), frameRateAdjuster, SLOT(incFrameRate()));
connect(source, SIGNAL(resetFrameRate()), frameRateAdjuster, SLOT(resetFrameRate())); connect(&source, SIGNAL(resetFrameRate()), frameRateAdjuster, SLOT(resetFrameRate()));
connect(source, SIGNAL(prevStateSlot()), this, SLOT(prevStateSlot())); connect(&source, SIGNAL(prevStateSlot()), this, SLOT(prevStateSlot()));
connect(source, SIGNAL(nextStateSlot()), this, SLOT(nextStateSlot())); connect(&source, SIGNAL(nextStateSlot()), this, SLOT(nextStateSlot()));
connect(source, SIGNAL(saveStateSignal()), this, SLOT(saveState())); connect(&source, SIGNAL(saveStateSignal()), this, SLOT(saveState()));
connect(source, SIGNAL(loadStateSignal()), this, SLOT(loadState())); connect(&source, SIGNAL(loadStateSignal()), this, SLOT(loadState()));
connect(source, SIGNAL(quit()), qApp, SLOT(closeAllWindows())); connect(&source, SIGNAL(quit()), qApp, SLOT(closeAllWindows()));
connect(videoDialog_, SIGNAL(accepted()), this, SLOT(videoDialogChange())); connect(videoDialog_, SIGNAL(accepted()), this, SLOT(videoDialogChange()));
connect(soundDialog_, SIGNAL(accepted()), this, SLOT(soundDialogChange())); connect(soundDialog_, SIGNAL(accepted()), this, SLOT(soundDialogChange()));
connect(miscDialog_, SIGNAL(accepted()), this, SLOT(miscDialogChange())); connect(miscDialog_, SIGNAL(accepted()), this, SLOT(miscDialogChange()));
connect(cheatDialog_, SIGNAL(accepted()), this, SLOT(cheatDialogChange())); connect(cheatDialog_, SIGNAL(accepted()), this, SLOT(cheatDialogChange()));
connect(mw, SIGNAL(videoBlitterFailure()), this, SLOT(videoBlitterFailure())); connect(&mw, SIGNAL(videoBlitterFailure()), this, SLOT(videoBlitterFailure()));
connect(mw, SIGNAL(audioEngineFailure()), this, SLOT(audioEngineFailure())); connect(&mw, SIGNAL(audioEngineFailure()), this, SLOT(audioEngineFailure()));
connect(mw, SIGNAL(closing()), this, SLOT(saveWindowSizeIfNotFullScreen())); connect(&mw, SIGNAL(closing()), this, SLOT(saveWindowSizeIfNotFullScreen()));
connect(mw, SIGNAL(dwmCompositionChange()), this, SLOT(reconsiderSyncFrameRateActionEnable())); connect(&mw, SIGNAL(dwmCompositionChange()), this, SLOT(reconsiderSyncFrameRateActionEnable()));
connect(this, SIGNAL(romLoaded(bool)), romLoadedActions, SLOT(setEnabled(bool))); connect(this, SIGNAL(romLoaded(bool)), romLoadedActions, SLOT(setEnabled(bool)));
connect(this, SIGNAL(romLoaded(bool)), stateSlotGroup_->actions().at(0), SLOT(setChecked(bool))); connect(this, SIGNAL(romLoaded(bool)), stateSlotGroup_->actions().at(0), SLOT(setChecked(bool)));
mw->setAspectRatio(QSize(160, 144)); mw.setAspectRatio(QSize(160, 144));
videoDialogChange(); videoDialogChange();
soundDialogChange(); soundDialogChange();
miscDialogChange(); miscDialogChange();
@ -481,7 +482,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw,
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
if (argv[i][0] != '-') { if (argv[i][0] != '-') {
if (fsAct_->isChecked()) if (fsAct_->isChecked())
mw->menuBar()->hide(); mw.menuBar()->hide();
loadFile(QFileInfo(QString(argv[i])).absoluteFilePath()); loadFile(QFileInfo(QString(argv[i])).absoluteFilePath());
break; break;
@ -529,66 +530,66 @@ void GambatteMenuHandler::loadFile(QString const &fileName) {
TmpPauser tmpPauser(mw_, 4); TmpPauser tmpPauser(mw_, 4);
pauseAction_->setChecked(false); pauseAction_->setChecked(false);
pauseChange(); pauseChange();
mw_->waitUntilPaused(); mw_.waitUntilPaused();
if (gambatte::LoadRes const error = if (gambatte::LoadRes const error =
source_->load(fileName.toLocal8Bit().constData(), source_.load(fileName.toLocal8Bit().constData(),
gbaCgbAction_->isChecked() * gambatte::GB::GBA_CGB gbaCgbAction_->isChecked() * gambatte::GB::GBA_CGB
+ forceDmgAction_->isChecked() * gambatte::GB::FORCE_DMG + forceDmgAction_->isChecked() * gambatte::GB::FORCE_DMG
+ miscDialog_->multicartCompat() * gambatte::GB::MULTICART_COMPAT)) { + miscDialog_->multicartCompat() * gambatte::GB::MULTICART_COMPAT)) {
mw_->stop(); mw_.stop();
emit dmgRomLoaded(false); emit dmgRomLoaded(false);
emit romLoaded(false); emit romLoaded(false);
QMessageBox::critical( QMessageBox::critical(
mw_, &mw_,
tr("File Load Error"), tr("File Load Error"),
tr("Failed to load file\n") + fileName + ".\n\n" tr("Failed to load file\n") + fileName + ".\n\n"
+ gambatte::to_string(error).c_str() + "."); + gambatte::to_string(error).c_str() + ".");
return; return;
} }
QString const &romTitle = QString::fromStdString(source_->romTitle()).trimmed(); QString const &romTitle = QString::fromStdString(source_.romTitle()).trimmed();
cheatDialog_->setGameName(romTitle.isEmpty() ? QFileInfo(fileName).completeBaseName() : romTitle); cheatDialog_->setGameName(romTitle.isEmpty() ? QFileInfo(fileName).completeBaseName() : romTitle);
cheatDialogChange(); cheatDialogChange();
if (!source_->isCgb()) { if (!source_.isCgb()) {
romPaletteDialog_->setSettingsFile( romPaletteDialog_->setSettingsFile(
QFileInfo(fileName).completeBaseName() + ".pal", QFileInfo(fileName).completeBaseName() + ".pal",
romTitle); romTitle);
setDmgPaletteColors(); setDmgPaletteColors();
} }
gambatte::PakInfo const &pak = source_->pakInfo(); gambatte::PakInfo const &pak = source_.pakInfo();
std::cout << romTitle.toStdString() << '\n' std::cout << romTitle.toStdString() << '\n'
<< "GamePak type: " << pak.mbc() << "GamePak type: " << pak.mbc()
<< " rambanks: " << pak.rambanks() << " rambanks: " << pak.rambanks()
<< " rombanks: " << pak.rombanks() << '\n' << " rombanks: " << pak.rombanks() << '\n'
<< "header checksum: " << (pak.headerChecksumOk() ? "ok" : "bad") << '\n' << "header checksum: " << (pak.headerChecksumOk() ? "ok" : "bad") << '\n'
<< "cgb: " << source_->isCgb() << std::endl; << "cgb: " << source_.isCgb() << std::endl;
mw_->setWindowTitle(strippedName(fileName) + (pak.headerChecksumOk() ? "" : " [bad]") + " - Gambatte"); mw_.setWindowTitle(strippedName(fileName) + (pak.headerChecksumOk() ? "" : " [bad]") + " - Gambatte");
setCurrentFile(fileName); setCurrentFile(fileName);
emit romLoaded(true); emit romLoaded(true);
emit dmgRomLoaded(!source_->isCgb()); emit dmgRomLoaded(!source_.isCgb());
mw_->resetAudio(); mw_.resetAudio();
mw_->run(); mw_.run();
} }
void GambatteMenuHandler::open() { void GambatteMenuHandler::open() {
TmpPauser tmpPauser(mw_, 4); TmpPauser tmpPauser(mw_, 4);
mw_->waitUntilPaused(); mw_.waitUntilPaused();
QString const &fileName = QFileDialog::getOpenFileName( QString const &fileName = QFileDialog::getOpenFileName(
mw_, tr("Open"), recentFileActs_[0]->data().toString(), &mw_, tr("Open"), recentFileActs_[0]->data().toString(),
tr("Game Boy ROM Images (*.dmg *.gb *.gbc *.sgb *.zip *.gz);;All Files (*)")); tr("Game Boy ROM Images (*.dmg *.gb *.gbc *.sgb *.zip *.gz);;All Files (*)"));
if (!fileName.isEmpty()) if (!fileName.isEmpty())
loadFile(fileName); loadFile(fileName);
// giving back focus after getOpenFileName seems to fail at times, which // giving back focus after getOpenFileName seems to fail at times, which
// can be problematic with current exclusive mode handling. // can be problematic with current exclusive mode handling.
mw_->setFocus(); mw_.setFocus();
} }
void GambatteMenuHandler::openRecentFile() { void GambatteMenuHandler::openRecentFile() {
@ -599,7 +600,7 @@ void GambatteMenuHandler::openRecentFile() {
void GambatteMenuHandler::about() { void GambatteMenuHandler::about() {
TmpPauser tmpPauser(mw_, pauseInc_); TmpPauser tmpPauser(mw_, pauseInc_);
QMessageBox::about( QMessageBox::about(
mw_, &mw_,
"About Gambatte", "About Gambatte",
QString::fromUtf8( QString::fromUtf8(
"<h3>Gambatte Qt (git)</h3>" "<h3>Gambatte Qt (git)</h3>"
@ -631,18 +632,18 @@ void GambatteMenuHandler::romPaletteChange() {
namespace { namespace {
struct SetDmgPaletteColorFun { struct SetDmgPaletteColorFun {
GambatteSource *source; unsigned palnum; unsigned colornum; unsigned rgb32; GambatteSource &source; unsigned palnum; unsigned colornum; unsigned rgb32;
void operator()() const { source->setDmgPaletteColor(palnum, colornum, rgb32); } void operator()() const { source.setDmgPaletteColor(palnum, colornum, rgb32); }
}; };
struct SetVideoSourceFun { struct SetVideoSourceFun {
GambatteSource *source; unsigned sourceIndex; GambatteSource &source; unsigned sourceIndex;
void operator()() const { source->setVideoSource(sourceIndex); } void operator()() const { source.setVideoSource(sourceIndex); }
}; };
struct SetSaveDirFun { struct SetSaveDirFun {
GambatteSource *source; QString path; GambatteSource &source; QString path;
void operator()() const { source->setSavedir(path.toLocal8Bit().constData()); } void operator()() const { source.setSavedir(path.toLocal8Bit().constData()); }
}; };
} // anon ns } // anon ns
@ -652,31 +653,31 @@ void GambatteMenuHandler::setDmgPaletteColors() {
for (unsigned colornum = 0; colornum < 4; ++colornum) { for (unsigned colornum = 0; colornum < 4; ++colornum) {
SetDmgPaletteColorFun fun = { source_, palnum, colornum, SetDmgPaletteColorFun fun = { source_, palnum, colornum,
romPaletteDialog_->color(palnum, colornum) }; romPaletteDialog_->color(palnum, colornum) };
mw_->callInWorkerThread(fun); mw_.callInWorkerThread(fun);
} }
} }
void GambatteMenuHandler::videoDialogChange() { void GambatteMenuHandler::videoDialogChange() {
{ {
SetVideoSourceFun fun = { source_, videoDialog_->sourceIndex() }; SetVideoSourceFun fun = { source_, videoDialog_->sourceIndex() };
mw_->callInWorkerThread(fun); mw_.callInWorkerThread(fun);
} }
applySettings(mw_, videoDialog_); applySettings(mw_, *videoDialog_);
windowSizeMenu_.videoDialogChange(*videoDialog_); windowSizeMenu_.videoDialogChange(*videoDialog_);
reconsiderSyncFrameRateActionEnable(); reconsiderSyncFrameRateActionEnable();
} }
void GambatteMenuHandler::soundDialogChange() { void GambatteMenuHandler::soundDialogChange() {
SoundDialog::applySettings(mw_, soundDialog_); applySettings(mw_, *soundDialog_);
} }
void GambatteMenuHandler::miscDialogChange() { void GambatteMenuHandler::miscDialogChange() {
SetSaveDirFun const setSaveDirFun = { source_, miscDialog_->savePath() }; SetSaveDirFun const setSaveDirFun = { source_, miscDialog_->savePath() };
mw_->callInWorkerThread(setSaveDirFun); mw_.callInWorkerThread(setSaveDirFun);
mw_->setDwmTripleBuffer(miscDialog_->dwmTripleBuf()); mw_.setDwmTripleBuffer(miscDialog_->dwmTripleBuf());
mw_->setFastForwardSpeed(miscDialog_->turboSpeed()); mw_.setFastForwardSpeed(miscDialog_->turboSpeed());
mw_->setPauseOnFocusOut(miscDialog_->pauseOnFocusOut() ? 2 : 0); mw_.setPauseOnFocusOut(miscDialog_->pauseOnFocusOut() ? 2 : 0);
pauseInc_ = miscDialog_->pauseOnDialogs() ? 4 : 0; pauseInc_ = miscDialog_->pauseOnDialogs() ? 4 : 0;
} }
@ -691,12 +692,12 @@ void GambatteMenuHandler::cheatDialogChange() {
gameSharkCodes += s.toStdString() + ";"; gameSharkCodes += s.toStdString() + ";";
} }
source_->setGameGenie(gameGenieCodes); source_.setGameGenie(gameGenieCodes);
source_->setGameShark(gameSharkCodes); source_.setGameShark(gameSharkCodes);
} }
void GambatteMenuHandler::reconsiderSyncFrameRateActionEnable() { void GambatteMenuHandler::reconsiderSyncFrameRateActionEnable() {
if (mw_->blitterConf(videoDialog_->blitterNo()).maxSwapInterval() if (mw_.blitterConf(videoDialog_->blitterNo()).maxSwapInterval()
&& !MainWindow::isDwmCompositionEnabled()) { && !MainWindow::isDwmCompositionEnabled()) {
syncFrameRateAction_->setEnabled(true); syncFrameRateAction_->setEnabled(true);
} else { } else {
@ -719,7 +720,7 @@ void GambatteMenuHandler::execRomPaletteDialog() {
void GambatteMenuHandler::execInputDialog() { void GambatteMenuHandler::execInputDialog() {
TmpPauser tmpPauser(mw_, pauseInc_); TmpPauser tmpPauser(mw_, pauseInc_);
source_->inputDialog()->exec(); source_.inputDialog()->exec();
} }
void GambatteMenuHandler::execSoundDialog() { void GambatteMenuHandler::execSoundDialog() {
@ -738,56 +739,56 @@ void GambatteMenuHandler::execMiscDialog() {
} }
void GambatteMenuHandler::prevStateSlot() { void GambatteMenuHandler::prevStateSlot() {
stateSlotGroup_->actions().at(source_->currentState() < 2 stateSlotGroup_->actions().at(source_.currentState() < 2
? source_->currentState() + 8 ? source_.currentState() + 8
: source_->currentState() - 2)->trigger(); : source_.currentState() - 2)->trigger();
} }
void GambatteMenuHandler::nextStateSlot() { void GambatteMenuHandler::nextStateSlot() {
stateSlotGroup_->actions().at(source_->currentState())->trigger(); stateSlotGroup_->actions().at(source_.currentState())->trigger();
} }
namespace { namespace {
struct SelectStateFun { struct SelectStateFun {
GambatteSource *source; int i; GambatteSource &source; int i;
void operator()() const { source->selectState(i); } void operator()() const { source.selectState(i); }
}; };
struct SaveStateFun { struct SaveStateFun {
GambatteSource *source; GambatteSource &source;
MainWindow::FrameBuffer fb; MainWindow::FrameBuffer fb;
void operator()() const { void operator()() const {
source->saveState(MainWindow::FrameBuffer::Locked(fb).get()); source.saveState(MainWindow::FrameBuffer::Locked(fb).get());
} }
}; };
struct LoadStateFun { struct LoadStateFun {
GambatteSource *source; GambatteSource &source;
void operator()() const { source->loadState(); } void operator()() const { source.loadState(); }
}; };
struct SaveStateAsFun { struct SaveStateAsFun {
GambatteSource *source; GambatteSource &source;
MainWindow::FrameBuffer fb; MainWindow::FrameBuffer fb;
QString fileName; QString fileName;
void operator()() const { void operator()() const {
source->saveState(MainWindow::FrameBuffer::Locked(fb).get(), source.saveState(MainWindow::FrameBuffer::Locked(fb).get(),
fileName.toLocal8Bit().constData()); fileName.toLocal8Bit().constData());
} }
}; };
struct LoadStateFromFun { struct LoadStateFromFun {
GambatteSource *source; GambatteSource &source;
QString fileName; QString fileName;
void operator()() const { void operator()() const {
source->loadState(fileName.toLocal8Bit().constData()); source.loadState(fileName.toLocal8Bit().constData());
} }
}; };
struct ResetFun { struct ResetFun {
GambatteSource *source; GambatteSource &source;
void operator()() const { source->reset(); } void operator()() const { source.reset(); }
}; };
} // anon ns } // anon ns
@ -795,61 +796,61 @@ struct ResetFun {
void GambatteMenuHandler::selectStateSlot() { void GambatteMenuHandler::selectStateSlot() {
if (QAction *action = stateSlotGroup_->checkedAction()) { if (QAction *action = stateSlotGroup_->checkedAction()) {
SelectStateFun fun = { source_, action->data().toInt() }; SelectStateFun fun = { source_, action->data().toInt() };
mw_->callInWorkerThread(fun); mw_.callInWorkerThread(fun);
} }
} }
void GambatteMenuHandler::saveState() { void GambatteMenuHandler::saveState() {
SaveStateFun fun = { source_, MainWindow::FrameBuffer(mw_) }; SaveStateFun fun = { source_, MainWindow::FrameBuffer(mw_) };
mw_->callInWorkerThread(fun); mw_.callInWorkerThread(fun);
} }
void GambatteMenuHandler::loadState() { void GambatteMenuHandler::loadState() {
LoadStateFun fun = { source_ }; LoadStateFun fun = { source_ };
mw_->callInWorkerThread(fun); mw_.callInWorkerThread(fun);
} }
void GambatteMenuHandler::saveStateAs() { void GambatteMenuHandler::saveStateAs() {
TmpPauser tmpPauser(mw_, 4); TmpPauser tmpPauser(mw_, 4);
mw_->waitUntilPaused(); mw_.waitUntilPaused();
QString const &fileName = QFileDialog::getSaveFileName( QString const &fileName = QFileDialog::getSaveFileName(
mw_, tr("Save State"), QString(), &mw_, tr("Save State"), QString(),
tr("Gambatte Quick Save Files (*.gqs);;All Files (*)")); tr("Gambatte Quick Save Files (*.gqs);;All Files (*)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
SaveStateAsFun fun = { source_, MainWindow::FrameBuffer(mw_), fileName }; SaveStateAsFun fun = { source_, MainWindow::FrameBuffer(mw_), fileName };
mw_->callInWorkerThread(fun); mw_.callInWorkerThread(fun);
} }
} }
void GambatteMenuHandler::loadStateFrom() { void GambatteMenuHandler::loadStateFrom() {
TmpPauser tmpPauser(mw_, 4); TmpPauser tmpPauser(mw_, 4);
mw_->waitUntilPaused(); mw_.waitUntilPaused();
QString const &fileName = QFileDialog::getOpenFileName( QString const &fileName = QFileDialog::getOpenFileName(
mw_, tr("Load State"), QString(), &mw_, tr("Load State"), QString(),
tr("Gambatte Quick Save Files (*.gqs);;All Files (*)")); tr("Gambatte Quick Save Files (*.gqs);;All Files (*)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
LoadStateFromFun fun = { source_, fileName }; LoadStateFromFun fun = { source_, fileName };
mw_->callInWorkerThread(fun); mw_.callInWorkerThread(fun);
} }
} }
void GambatteMenuHandler::reset() { void GambatteMenuHandler::reset() {
ResetFun fun = { source_ }; ResetFun fun = { source_ };
mw_->callInWorkerThread(fun); mw_.callInWorkerThread(fun);
} }
void GambatteMenuHandler::pauseChange() { void GambatteMenuHandler::pauseChange() {
if (pauseAction_->isChecked()) if (pauseAction_->isChecked())
mw_->pause(); mw_.pause();
else else
mw_->unpause(); mw_.unpause();
} }
void GambatteMenuHandler::frameStep() { void GambatteMenuHandler::frameStep() {
if (pauseAction_->isChecked()) if (pauseAction_->isChecked())
mw_->frameStep(); mw_.frameStep();
else else
pauseAction_->trigger(); pauseAction_->trigger();
} }
@ -859,35 +860,35 @@ void GambatteMenuHandler::escPressed() {
if (fsAct_->isChecked()) if (fsAct_->isChecked())
fsAct_->trigger(); fsAct_->trigger();
#else #else
mw_->menuBar()->setVisible(!mw_->menuBar()->isVisible()); mw_.menuBar()->setVisible(!mw_.menuBar()->isVisible());
if (!mw_->menuBar()->isVisible()) if (!mw_.menuBar()->isVisible())
mw_->hideCursor(); mw_.hideCursor();
#endif #endif
} }
void GambatteMenuHandler::videoBlitterFailure() { void GambatteMenuHandler::videoBlitterFailure() {
TmpPauser tmpPauser(mw_, pauseInc_); TmpPauser tmpPauser(mw_, pauseInc_);
QMessageBox::critical(mw_, tr("Video engine failure"), QMessageBox::critical(&mw_, tr("Video engine failure"),
tr("Failed to update video output. This may be fixed by changing the video engine settings.")); tr("Failed to update video output. This may be fixed by changing the video engine settings."));
videoDialog_->exec(); videoDialog_->exec();
} }
void GambatteMenuHandler::audioEngineFailure() { void GambatteMenuHandler::audioEngineFailure() {
TmpPauser tmpPauser(mw_, pauseInc_); TmpPauser tmpPauser(mw_, pauseInc_);
QMessageBox::critical(mw_, tr("Sound engine failure"), QMessageBox::critical(&mw_, tr("Sound engine failure"),
tr("Failed to output audio. This may be fixed by changing the sound settings.")); tr("Failed to output audio. This may be fixed by changing the sound settings."));
soundDialog_->exec(); soundDialog_->exec();
} }
void GambatteMenuHandler::toggleFullScreen() { void GambatteMenuHandler::toggleFullScreen() {
saveWindowSizeIfNotFullScreen(); saveWindowSizeIfNotFullScreen();
mw_->toggleFullScreen(); mw_.toggleFullScreen();
} }
void GambatteMenuHandler::saveWindowSizeIfNotFullScreen() { void GambatteMenuHandler::saveWindowSizeIfNotFullScreen() {
if (!mw_->isFullScreen()) { if (!mw_.isFullScreen()) {
QSettings settings; QSettings settings;
settings.setValue("mainwindow/size", mw_->size()); settings.setValue("mainwindow/size", mw_.size());
} }
} }

View File

@ -24,17 +24,17 @@
#include <QObject> #include <QObject>
#include <QSize> #include <QSize>
class MainWindow; class CheatDialog;
class GambatteSource; class GambatteSource;
class QAction; class MainWindow;
class MiscDialog;
class PaletteDialog; class PaletteDialog;
class QString; class QAction;
class QActionGroup; class QActionGroup;
class QMenu; class QMenu;
class QString;
class SoundDialog; class SoundDialog;
class VideoDialog; class VideoDialog;
class MiscDialog;
class CheatDialog;
class FrameRateAdjuster : public QObject { class FrameRateAdjuster : public QObject {
public: public:
@ -121,7 +121,7 @@ private slots:
class GambatteMenuHandler : public QObject { class GambatteMenuHandler : public QObject {
public: public:
GambatteMenuHandler(MainWindow *mw, GambatteSource *source, GambatteMenuHandler(MainWindow &mw, GambatteSource &source,
int argc, char const *const argv[]); int argc, char const *const argv[]);
~GambatteMenuHandler(); ~GambatteMenuHandler();
@ -130,8 +130,8 @@ private:
enum { max_recent_files = 9 }; enum { max_recent_files = 9 };
MainWindow *const mw_; MainWindow &mw_;
GambatteSource *const source_; GambatteSource &source_;
SoundDialog *const soundDialog_; SoundDialog *const soundDialog_;
VideoDialog *const videoDialog_; VideoDialog *const videoDialog_;
MiscDialog *const miscDialog_; MiscDialog *const miscDialog_;

View File

@ -28,8 +28,8 @@ int main(int argc, char *argv[]) {
QCoreApplication::setApplicationName("gambatte_qt"); QCoreApplication::setApplicationName("gambatte_qt");
GambatteSource source; GambatteSource source;
MainWindow mw(&source); MainWindow mw(source);
GambatteMenuHandler mh(&mw, &source, argc, argv); GambatteMenuHandler mh(mw, source, argc, argv);
mw.show(); mw.show();
return app.exec(); return app.exec();
} }