From 5f365afb9c682ea3f9ef18419bd631d46da1d172 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 26 Sep 2022 19:20:30 +0200 Subject: [PATCH] make the camera settings dialog not suck balls --- src/frontend/qt_sdl/CameraManager.cpp | 17 +++++++++++------ src/frontend/qt_sdl/CameraManager.h | 1 + src/frontend/qt_sdl/CameraSettingsDialog.cpp | 4 +++- src/frontend/qt_sdl/CameraSettingsDialog.h | 2 +- src/frontend/qt_sdl/main.cpp | 20 +++++++++++++++++++- src/frontend/qt_sdl/main.h | 5 +++-- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/frontend/qt_sdl/CameraManager.cpp b/src/frontend/qt_sdl/CameraManager.cpp index 45776391..2ca441e1 100644 --- a/src/frontend/qt_sdl/CameraManager.cpp +++ b/src/frontend/qt_sdl/CameraManager.cpp @@ -169,9 +169,9 @@ void CameraManager::deInit() } void CameraManager::start() -{printf("[%d] [%d] START\n", num, startNum); - startNum++; - if (startNum > 1) return; +{ + if (startNum == 1) return; + startNum = 1; if (inputType == 2) { @@ -180,9 +180,9 @@ void CameraManager::start() } void CameraManager::stop() -{printf("[%d] [%d] STOP\n", num, startNum-1); - startNum--; - if (startNum > 0) return; +{ + if (startNum == 0) return; + startNum = 0; if (inputType == 2) { @@ -190,6 +190,11 @@ void CameraManager::stop() } } +bool CameraManager::isStarted() +{ + return startNum != 0; +} + void CameraManager::camStart() { camDevice->start(); diff --git a/src/frontend/qt_sdl/CameraManager.h b/src/frontend/qt_sdl/CameraManager.h index 53688068..58a34a89 100644 --- a/src/frontend/qt_sdl/CameraManager.h +++ b/src/frontend/qt_sdl/CameraManager.h @@ -56,6 +56,7 @@ public: void start(); void stop(); + bool isStarted(); void captureFrame(u32* frame, int width, int height, bool yuv); diff --git a/src/frontend/qt_sdl/CameraSettingsDialog.cpp b/src/frontend/qt_sdl/CameraSettingsDialog.cpp index e7642baa..65d60361 100644 --- a/src/frontend/qt_sdl/CameraSettingsDialog.cpp +++ b/src/frontend/qt_sdl/CameraSettingsDialog.cpp @@ -154,8 +154,10 @@ void CameraSettingsDialog::on_cbCameraSel_currentIndexChanged(int id) currentId = id; currentCfg = &Config::Camera[id]; - currentCam = camManager[id]; + //currentCam = camManager[id]; + currentCam = nullptr; populateCamControls(id); + currentCam = camManager[id]; previewPanel->setCurrentCam(currentCam); currentCam->start(); diff --git a/src/frontend/qt_sdl/CameraSettingsDialog.h b/src/frontend/qt_sdl/CameraSettingsDialog.h index f1739cc2..8311cae1 100644 --- a/src/frontend/qt_sdl/CameraSettingsDialog.h +++ b/src/frontend/qt_sdl/CameraSettingsDialog.h @@ -71,7 +71,7 @@ public: } currentDlg = new CameraSettingsDialog(parent); - currentDlg->show(); + currentDlg->open(); return currentDlg; } static void closeDlg() diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 22edab11..3c8bef9f 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -118,6 +118,7 @@ u32 micWavLength; s16* micWavBuffer; CameraManager* camManager[2]; +bool camStarted[2]; const struct { int id; float ratio; const char* label; } aspectRatios[] = { @@ -2805,8 +2806,23 @@ void MainWindow::onOpenVideoSettings() void MainWindow::onOpenCameraSettings() { + emuThread->emuPause(); + + camStarted[0] = camManager[0]->isStarted(); + camStarted[1] = camManager[1]->isStarted(); + if (camStarted[0]) camManager[0]->stop(); + if (camStarted[1]) camManager[1]->stop(); + CameraSettingsDialog* dlg = CameraSettingsDialog::openDlg(this); - //connect(dlg, &CameraSettingsDialog::updateCameraSettings, this, &MainWindow::onUpdateCameraSettings); + connect(dlg, &CameraSettingsDialog::finished, this, &MainWindow::onCameraSettingsFinished); +} + +void MainWindow::onCameraSettingsFinished(int res) +{ + if (camStarted[0]) camManager[0]->start(); + if (camStarted[1]) camManager[1]->start(); + + emuThread->emuUnpause(); } void MainWindow::onOpenAudioSettings() @@ -3257,6 +3273,8 @@ int main(int argc, char** argv) micExtBufferWritePos = 0; micWavBuffer = nullptr; + camStarted[0] = false; + camStarted[1] = false; camManager[0] = new CameraManager(0, 640, 480, true); camManager[1] = new CameraManager(1, 640, 480, true); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 515ddd77..b62619bb 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -267,11 +267,12 @@ private slots: void onInputConfigFinished(int res); void onOpenVideoSettings(); void onOpenCameraSettings(); + void onCameraSettingsFinished(int res); void onOpenAudioSettings(); - void onOpenFirmwareSettings(); - void onOpenPathSettings(); void onUpdateAudioSettings(); void onAudioSettingsFinished(int res); + void onOpenFirmwareSettings(); + void onOpenPathSettings(); void onOpenMPSettings(); void onMPSettingsFinished(int res); void onOpenWifiSettings();