initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -0,0 +1,38 @@
|
||||
# UosMedia: Qt Multimedia equivalent of the "United Openlibraries of Sound"
|
||||
# (uos) Pascal package used by perso/cevo/Music.pas for background music
|
||||
# playback. Unlike uos, Qt Multimedia resolves its codec backend (FFmpeg on
|
||||
# most platforms) automatically, so there is no equivalent to uos's optional
|
||||
# codec plugins (uos_opus, uos_mpg123, uos_libxmp, ...) or its manual
|
||||
# uos_LoadLib runtime library probing.
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Multimedia)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Multimedia)
|
||||
|
||||
set(UOS_MEDIA_HEADERS
|
||||
include/Uos/Uos.h
|
||||
include/Uos/UosPlayer.h
|
||||
)
|
||||
|
||||
set(UOS_MEDIA_SOURCES
|
||||
src/UosPlayer.cpp
|
||||
)
|
||||
|
||||
add_library(uosmedia SHARED ${UOS_MEDIA_SOURCES} ${UOS_MEDIA_HEADERS})
|
||||
|
||||
target_include_directories(uosmedia PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(uosmedia PUBLIC Qt${QT_VERSION_MAJOR}::Multimedia)
|
||||
|
||||
set_target_properties(uosmedia PROPERTIES
|
||||
AUTOMOC ON
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS uosmedia
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/cevo-evo
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/cevo-evo
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
// Convenience umbrella header mirroring uos_flat.pas: `#include
|
||||
// <Uos/Uos.h>` the same way Music.pas did `uses uos_flat`.
|
||||
|
||||
#include "Uos/UosPlayer.h"
|
||||
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMediaPlayer>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
class QAudioOutput;
|
||||
|
||||
namespace Uos {
|
||||
|
||||
// uos_LoadLib / uos_TestLoadLibrary / uosLoadResult: Qt Multimedia resolves
|
||||
// its backend automatically, so there is no equivalent runtime library
|
||||
// probing step. This only checks that a usable audio output device exists,
|
||||
// the one condition that could previously fail via uos_LoadLib's PortAudio
|
||||
// error codes.
|
||||
bool isAudioOutputAvailable();
|
||||
|
||||
// Qt equivalent of a uos_flat "player": one audio input routed to the
|
||||
// default output device. uos_flat's integer PlayerIndex/InputIndex/
|
||||
// OutputIndex handles (uos_CreatePlayer/uos_AddFromFile/uos_AddIntoDevOut)
|
||||
// are replaced by a single object.
|
||||
class Player : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Player(QObject *parent = nullptr);
|
||||
|
||||
// uos_AddFromFile: returns false if the file does not exist.
|
||||
bool addFromFile(const QString &fileName);
|
||||
|
||||
// uos_InputSetPositionEnable: Qt always tracks position, kept only for
|
||||
// API parity with call sites that used to gate it.
|
||||
void setPositionEnable(bool enable) { Q_UNUSED(enable); }
|
||||
// uos_InputLength: duration of the current input, in milliseconds.
|
||||
qint64 inputLength() const;
|
||||
|
||||
// uos_InputAddDSPVolume / uos_InputSetDSPVolume: QAudioOutput exposes a
|
||||
// single volume (0.0-1.0) with no instant/smooth ramp distinction, so
|
||||
// left/right are averaged and "smooth" is accepted but not applied.
|
||||
void setVolume(float left, float right, bool smooth = false);
|
||||
float volume() const;
|
||||
|
||||
// uos_AddIntoDevOut: Qt Multimedia always targets the default output
|
||||
// device; this just reports whether one is available.
|
||||
bool addIntoDevOut();
|
||||
|
||||
// uos_Play / uos_Stop. loopCount <= 1 plays the input once, matching the
|
||||
// uos_Play default of nloop = 0.
|
||||
void play(int loopCount = 0);
|
||||
void stop();
|
||||
bool playing() const;
|
||||
|
||||
// uos_EndProc.
|
||||
std::function<void()> onEnd;
|
||||
|
||||
private:
|
||||
void handleMediaStatusChanged(QMediaPlayer::MediaStatus status);
|
||||
|
||||
QMediaPlayer *m_player;
|
||||
QAudioOutput *m_audioOutput;
|
||||
};
|
||||
|
||||
} // namespace Uos
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "Uos/UosPlayer.h"
|
||||
|
||||
#include <QAudioDevice>
|
||||
#include <QAudioOutput>
|
||||
#include <QFileInfo>
|
||||
#include <QMediaDevices>
|
||||
#include <QUrl>
|
||||
|
||||
namespace Uos {
|
||||
|
||||
bool isAudioOutputAvailable()
|
||||
{
|
||||
return !QMediaDevices::defaultAudioOutput().isNull();
|
||||
}
|
||||
|
||||
Player::Player(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_player = new QMediaPlayer(this);
|
||||
m_audioOutput = new QAudioOutput(this);
|
||||
m_player->setAudioOutput(m_audioOutput);
|
||||
connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &Player::handleMediaStatusChanged);
|
||||
}
|
||||
|
||||
bool Player::addFromFile(const QString &fileName)
|
||||
{
|
||||
if (!QFileInfo::exists(fileName))
|
||||
return false;
|
||||
m_player->setSource(QUrl::fromLocalFile(fileName));
|
||||
return true;
|
||||
}
|
||||
|
||||
qint64 Player::inputLength() const
|
||||
{
|
||||
return m_player->duration();
|
||||
}
|
||||
|
||||
void Player::setVolume(float left, float right, bool smooth)
|
||||
{
|
||||
Q_UNUSED(smooth);
|
||||
m_audioOutput->setVolume((left + right) / 2.0f);
|
||||
}
|
||||
|
||||
float Player::volume() const
|
||||
{
|
||||
return m_audioOutput->volume();
|
||||
}
|
||||
|
||||
bool Player::addIntoDevOut()
|
||||
{
|
||||
return isAudioOutputAvailable();
|
||||
}
|
||||
|
||||
void Player::play(int loopCount)
|
||||
{
|
||||
m_player->setLoops(loopCount <= 1 ? 1 : loopCount);
|
||||
m_player->play();
|
||||
}
|
||||
|
||||
void Player::stop()
|
||||
{
|
||||
m_player->stop();
|
||||
}
|
||||
|
||||
bool Player::playing() const
|
||||
{
|
||||
return m_player->playbackState() == QMediaPlayer::PlayingState;
|
||||
}
|
||||
|
||||
void Player::handleMediaStatusChanged(QMediaPlayer::MediaStatus status)
|
||||
{
|
||||
if (status == QMediaPlayer::EndOfMedia && onEnd)
|
||||
onEnd();
|
||||
}
|
||||
|
||||
} // namespace Uos
|
||||
Reference in new issue
Block a user