Qt: Allow setting of audio channels and video layers while games are not running
Jeffrey Pfau jeffrey@endrift.com
Sun, 02 Aug 2015 12:46:23 -0700
3 files changed,
66 insertions(+),
10 deletions(-)
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -47,6 +47,8 @@ , m_turbo(false)
, m_turboForced(false) , m_turboSpeed(-1) , m_wasPaused(false) + , m_audioChannels{ true, true, true, true, true, true } + , m_videoLayers{ true, true, true, true, true } , m_inputController(nullptr) , m_multiplayer(nullptr) , m_stateSlot(1)@@ -90,6 +92,17 @@ GBARTCGenericSourceInit(&controller->m_rtc, context->gba);
context->gba->rtcSource = &controller->m_rtc.d; context->gba->rumble = controller->m_inputController->rumble(); context->gba->rotationSource = controller->m_inputController->rotationSource(); + context->gba->audio.forceDisableCh[0] = !controller->m_audioChannels[0]; + context->gba->audio.forceDisableCh[1] = !controller->m_audioChannels[1]; + context->gba->audio.forceDisableCh[2] = !controller->m_audioChannels[2]; + context->gba->audio.forceDisableCh[3] = !controller->m_audioChannels[3]; + context->gba->audio.forceDisableChA = !controller->m_audioChannels[4]; + context->gba->audio.forceDisableChB = !controller->m_audioChannels[5]; + context->gba->video.renderer->disableBG[0] = !controller->m_videoLayers[0]; + context->gba->video.renderer->disableBG[1] = !controller->m_videoLayers[1]; + context->gba->video.renderer->disableBG[2] = !controller->m_videoLayers[2]; + context->gba->video.renderer->disableBG[3] = !controller->m_videoLayers[3]; + context->gba->video.renderer->disableOBJ = !controller->m_videoLayers[4]; controller->m_fpsTarget = context->fpsTarget; if (GBALoadState(context, context->stateDir, 0)) {@@ -576,6 +589,49 @@ threadInterrupt();
redoSamples(samples); threadContinue(); QMetaObject::invokeMethod(m_audioProcessor, "setBufferSamples", Q_ARG(int, samples)); +} + +void GameController::setAudioChannelEnabled(int channel, bool enable) { + if (channel > 5 || channel < 0) { + return; + } + m_audioChannels[channel] = enable; + if (m_gameOpen) { + switch (channel) { + case 0: + case 1: + case 2: + case 3: + m_threadContext.gba->audio.forceDisableCh[channel] = !enable; + break; + case 4: + m_threadContext.gba->audio.forceDisableChA = !enable; + break; + case 5: + m_threadContext.gba->audio.forceDisableChB = !enable; + break; + } + } +} + +void GameController::setVideoLayerEnabled(int layer, bool enable) { + if (layer > 4 || layer < 0) { + return; + } + m_videoLayers[layer] = enable; + if (m_gameOpen) { + switch (layer) { + case 0: + case 1: + case 2: + case 3: + m_threadContext.gba->video.renderer->disableBG[layer] = !enable; + break; + case 4: + m_threadContext.gba->video.renderer->disableOBJ = !enable; + break; + } + } } void GameController::setFPSTarget(float fps) {
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -117,6 +117,8 @@ void keyPressed(int key);
void keyReleased(int key); void clearKeys(); void setAudioBufferSamples(int samples); + void setAudioChannelEnabled(int channel, bool enable = true); + void setVideoLayerEnabled(int layer, bool enable = true); void setFPSTarget(float fps); void loadState(int slot = 0); void saveState(int slot = 0);@@ -192,6 +194,9 @@ bool m_turboForced;
float m_turboSpeed; QTimer m_rewindTimer; bool m_wasPaused; + + bool m_audioChannels[6]; + bool m_videoLayers[5]; int m_stateSlot; GBASerializedState* m_backupLoadState;
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -1011,16 +1011,14 @@ for (int i = 0; i < 4; ++i) {
QAction* enableBg = new QAction(tr("Background %0").arg(i), videoLayers); enableBg->setCheckable(true); enableBg->setChecked(true); - connect(enableBg, &QAction::triggered, [this, i](bool enable) { m_controller->thread()->gba->video.renderer->disableBG[i] = !enable; }); - m_gameActions.append(enableBg); + connect(enableBg, &QAction::triggered, [this, i](bool enable) { m_controller->setVideoLayerEnabled(i, enable); }); addControlledAction(videoLayers, enableBg, QString("enableBG%0").arg(i)); } QAction* enableObj = new QAction(tr("OBJ (sprites)"), videoLayers); enableObj->setCheckable(true); enableObj->setChecked(true); - connect(enableObj, &QAction::triggered, [this](bool enable) { m_controller->thread()->gba->video.renderer->disableOBJ = !enable; }); - m_gameActions.append(enableObj); + connect(enableObj, &QAction::triggered, [this](bool enable) { m_controller->setVideoLayerEnabled(4, enable); }); addControlledAction(videoLayers, enableObj, "enableOBJ"); QMenu* audioChannels = avMenu->addMenu(tr("Audio channels"));@@ -1029,23 +1027,20 @@ for (int i = 0; i < 4; ++i) {
QAction* enableCh = new QAction(tr("Channel %0").arg(i + 1), audioChannels); enableCh->setCheckable(true); enableCh->setChecked(true); - connect(enableCh, &QAction::triggered, [this, i](bool enable) { m_controller->thread()->gba->audio.forceDisableCh[i] = !enable; }); - m_gameActions.append(enableCh); + connect(enableCh, &QAction::triggered, [this, i](bool enable) { m_controller->setAudioChannelEnabled(i, enable); }); addControlledAction(audioChannels, enableCh, QString("enableCh%0").arg(i + 1)); } QAction* enableChA = new QAction(tr("Channel A"), audioChannels); enableChA->setCheckable(true); enableChA->setChecked(true); - connect(enableChA, &QAction::triggered, [this, i](bool enable) { m_controller->thread()->gba->audio.forceDisableChA = !enable; }); - m_gameActions.append(enableChA); + connect(enableChA, &QAction::triggered, [this, i](bool enable) { m_controller->setAudioChannelEnabled(4, enable); }); addControlledAction(audioChannels, enableChA, QString("enableChA")); QAction* enableChB = new QAction(tr("Channel B"), audioChannels); enableChB->setCheckable(true); enableChB->setChecked(true); - connect(enableChB, &QAction::triggered, [this, i](bool enable) { m_controller->thread()->gba->audio.forceDisableChB = !enable; }); - m_gameActions.append(enableChB); + connect(enableChB, &QAction::triggered, [this, i](bool enable) { m_controller->setAudioChannelEnabled(5, enable); }); addControlledAction(audioChannels, enableChB, QString("enableChB")); QMenu* toolsMenu = menubar->addMenu(tr("&Tools"));