Skip to content

Commit

Permalink
qapple to qt6.
Browse files Browse the repository at this point in the history
Initial version: no audio no gamepad.

#203

Signed-off-by: Andrea Odetti <[email protected]>
  • Loading branch information
audetto committed Dec 8, 2024
1 parent a9ae3a1 commit 5bf8d49
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 24 additions & 8 deletions source/frontends/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -17,7 +19,6 @@ set(SOURCE_FILES
preferences.cpp
emulator.cpp
memorycontainer.cpp
gamepadpaddle.cpp
qvideo.cpp
configuration.cpp
options.cpp
Expand All @@ -34,7 +35,6 @@ set(HEADER_FILES
preferences.h
emulator.h
memorycontainer.h
gamepadpaddle.h
qvideo.h
configuration.h
options.h
Expand All @@ -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)
1 change: 0 additions & 1 deletion source/frontends/qt/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "qtframe.h"

#include <QMessageBox>
#include <QGamepad>
#include <QSettings>

namespace
Expand Down
7 changes: 6 additions & 1 deletion source/frontends/qt/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

#include <QFileDialog>
#include <QColorDialog>
#include <QGamepadManager>
#include <QSettings>

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QGamepadManager>
#endif

namespace
{

Expand Down Expand Up @@ -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<int> gamepads = manager->connectedGamepads();

Expand All @@ -179,6 +183,7 @@ void Preferences::populateJoysticks()
const QString name = manager->gamepadName(id);
ui->joystick->addItem(name);
}
#endif
}

void Preferences::setSettings(QSettings & settings)
Expand Down
7 changes: 6 additions & 1 deletion source/frontends/qt/qapple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QMdiSubWindow>
#include <QMessageBox>
#include <QFileDialog>
Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 19 additions & 1 deletion source/frontends/qt/qdirectsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <memory>

#include <QAudioOutput>
#include <QIODevice>
#include <QAudioFormat>

namespace
{
Expand Down Expand Up @@ -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<QAudioOutput>(audioFormat);
#else
audioFormat.setSampleFormat(QAudioFormat::Int16);
#endif
}

DirectSoundGenerator::~DirectSoundGenerator()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
myAudioOutput->stop();
#endif
}

HRESULT DirectSoundGenerator::Release()
Expand All @@ -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())
{
Expand All @@ -82,21 +91,26 @@ namespace
{
myAudioOutput->start(this);
}
#endif
}

HRESULT DirectSoundGenerator::SetVolume( LONG lVolume )
{
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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5bf8d49

Please sign in to comment.