From 5bf8d49c2c3749f6c4bdf15238d43dd72ac9724b Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Sun, 8 Dec 2024 10:25:53 +0000 Subject: [PATCH] qapple to qt6. Initial version: no audio no gamepad. https://github.com/audetto/AppleWin/issues/203 Signed-off-by: Andrea Odetti --- CMakeLists.txt | 4 ++++ source/frontends/qt/CMakeLists.txt | 32 +++++++++++++++++++++------- source/frontends/qt/options.cpp | 1 - source/frontends/qt/preferences.cpp | 7 +++++- source/frontends/qt/qapple.cpp | 7 +++++- source/frontends/qt/qdirectsound.cpp | 20 ++++++++++++++++- 6 files changed, 59 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bf6b3a86..10b396df2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,10 @@ execute_process(COMMAND uname -m OUTPUT_VARIABLE UNAME OUTPUT_STRIP_TRAILING_WHITESPACE) +execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json +) + include_directories(source) add_subdirectory(source) diff --git a/source/frontends/qt/CMakeLists.txt b/source/frontends/qt/CMakeLists.txt index 846203665..c2f679ae4 100644 --- a/source/frontends/qt/CMakeLists.txt +++ b/source/frontends/qt/CMakeLists.txt @@ -4,9 +4,11 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) -find_package(Qt5 REQUIRED - COMPONENTS Widgets Gamepad Multimedia - ) +find_package(Qt6 COMPONENTS Widgets Multimedia OpenGLWidgets) + +if(NOT Qt6_FOUND) + find_package(Qt5 REQUIRED COMPONENTS Widgets Gamepad Multimedia) +endif() add_subdirectory(QHexView) @@ -17,7 +19,6 @@ set(SOURCE_FILES preferences.cpp emulator.cpp memorycontainer.cpp - gamepadpaddle.cpp qvideo.cpp configuration.cpp options.cpp @@ -34,7 +35,6 @@ set(HEADER_FILES preferences.h emulator.h memorycontainer.h - gamepadpaddle.h qvideo.h configuration.h options.h @@ -51,13 +51,29 @@ add_executable(qapple ) target_link_libraries(qapple PRIVATE - Qt5::Widgets - Qt5::Gamepad - Qt5::Multimedia + Qt::Widgets + Qt::Multimedia appleii QHexView windows ) +if(Qt5_FOUND) + target_sources(qapple PRIVATE + gamepadpaddle.cpp + gamepadpaddle.h + ) + + target_link_libraries(qapple PRIVATE + Qt::Gamepad + ) +endif() + +if(Qt6_FOUND) + target_link_libraries(qapple PRIVATE + Qt::OpenGLWidgets + ) +endif() + install(TARGETS qapple DESTINATION bin) diff --git a/source/frontends/qt/options.cpp b/source/frontends/qt/options.cpp index 367e3d113..ee6587b87 100644 --- a/source/frontends/qt/options.cpp +++ b/source/frontends/qt/options.cpp @@ -17,7 +17,6 @@ #include "qtframe.h" #include -#include #include namespace diff --git a/source/frontends/qt/preferences.cpp b/source/frontends/qt/preferences.cpp index 0ab41a878..58ee0e783 100644 --- a/source/frontends/qt/preferences.cpp +++ b/source/frontends/qt/preferences.cpp @@ -9,9 +9,12 @@ #include #include -#include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#include +#endif + namespace { @@ -171,6 +174,7 @@ void Preferences::populateJoysticks() ui->joystick->clear(); ui->joystick->addItem("None"); // index = 0 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QGamepadManager * manager = QGamepadManager::instance(); const QList gamepads = manager->connectedGamepads(); @@ -179,6 +183,7 @@ void Preferences::populateJoysticks() const QString name = manager->gamepadName(id); ui->joystick->addItem(name); } +#endif } void Preferences::setSettings(QSettings & settings) diff --git a/source/frontends/qt/qapple.cpp b/source/frontends/qt/qapple.cpp index a5348a83e..194ac69d4 100644 --- a/source/frontends/qt/qapple.cpp +++ b/source/frontends/qt/qapple.cpp @@ -18,12 +18,15 @@ #include "emulator.h" #include "memorycontainer.h" #include "qdirectsound.h" -#include "gamepadpaddle.h" #include "preferences.h" #include "configuration.h" #include "audioinfo.h" #include "qtframe.h" +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#include "gamepadpaddle.h" +#endif + #include #include #include @@ -346,8 +349,10 @@ void QApple::reloadOptions() { myFrame->FrameRefreshStatus(DRAW_TITLE); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) Paddle::instance = GamepadPaddle::fromName(myOptions.gamepadName); Paddle::setSquaring(myOptions.gamepadSquaring); +#endif QDirectSound::setOptions(myOptions.msAudioBuffer); } diff --git a/source/frontends/qt/qdirectsound.cpp b/source/frontends/qt/qdirectsound.cpp index d3da7e563..c46b64433 100644 --- a/source/frontends/qt/qdirectsound.cpp +++ b/source/frontends/qt/qdirectsound.cpp @@ -7,6 +7,8 @@ #include #include +#include +#include namespace { @@ -43,17 +45,23 @@ namespace QAudioFormat audioFormat; audioFormat.setSampleRate(mySampleRate); audioFormat.setChannelCount(myChannels); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) audioFormat.setSampleSize(myBitsPerSample); audioFormat.setCodec(QString::fromUtf8("audio/pcm")); audioFormat.setByteOrder(QAudioFormat::LittleEndian); audioFormat.setSampleType(QAudioFormat::SignedInt); - myAudioOutput = std::make_shared(audioFormat); +#else + audioFormat.setSampleFormat(QAudioFormat::Int16); +#endif } DirectSoundGenerator::~DirectSoundGenerator() { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) myAudioOutput->stop(); +#endif } HRESULT DirectSoundGenerator::Release() @@ -64,6 +72,7 @@ namespace void DirectSoundGenerator::setOptions(const qint64 duration) // in ms { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) const qint64 buffer = myAudioOutput->format().bytesForDuration(duration * 1000); if (buffer == myAudioOutput->bufferSize()) { @@ -82,6 +91,7 @@ namespace { myAudioOutput->start(this); } +#endif } HRESULT DirectSoundGenerator::SetVolume( LONG lVolume ) @@ -89,14 +99,18 @@ namespace const HRESULT res = IDirectSoundBuffer::SetVolume(lVolume); const qreal logVolume = GetLogarithmicVolume(); const qreal linVolume = QAudio::convertVolume(logVolume, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) myAudioOutput->setVolume(linVolume); +#endif return res; } HRESULT DirectSoundGenerator::Stop() { const HRESULT res = IDirectSoundBuffer::Stop(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) myAudioOutput->stop(); +#endif QIODevice::close(); return res; } @@ -105,7 +119,9 @@ namespace { const HRESULT res = IDirectSoundBuffer::Play(dwReserved1, dwReserved2, dwFlags); QIODevice::open(ReadOnly); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) myAudioOutput->start(this); +#endif return res; } @@ -140,10 +156,12 @@ namespace if (info.running) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) const DWORD bytesInBuffer = GetBytesInBuffer(); const auto & format = myAudioOutput->format(); info.buffer = format.durationForBytes(bytesInBuffer) / 1000; info.size = format.durationForBytes(myBufferSize) / 1000; +#endif } return info;