Skip to content

Commit

Permalink
Use cdio on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Dec 4, 2024
1 parent 80addf1 commit 4dd6834
Show file tree
Hide file tree
Showing 29 changed files with 289 additions and 853 deletions.
66 changes: 66 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Language: Cpp
IndentWidth: 4
AccessModifierOffset: 4
AlignAfterOpenBracket: DontAlign
PointerBindsToType: true
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: None
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: No
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: After
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterComma
BreakStringLiterals: false
ColumnLimit: 0
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
IndentAccessModifiers: true
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: true
IndentGotoLabels: false
IndentPPDirectives: BeforeHash
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: OuterScope
NamespaceIndentation: All
PointerAlignment: Left
ReferenceAlignment: Left
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptControlMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 4
UseTab: Never
8 changes: 4 additions & 4 deletions application/translations/desktop/com.vicr123.thebeat/en.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"GenericName": {
"message": "Audio Player"
"message": "Audio Player\r"
},
"Keywords": {
"description": "A list of words that can be searched for. Please ensure that the list also ends with a semicolon!",
"message": "audio;music;cd;player;"
"description": "A list of words that can be searched for. Please ensure that the list also ends with a semicolon!\r",
"message": "audio;music;cd;player;\r"
},
"Name": {
"message": "theBeat"
"message": "theBeat\r"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"GenericName": {
"message": "Audio Player"
"message": "Audio Player\r"
},
"Keywords": {
"description": "A list of words that can be searched for. Please ensure that the list also ends with a semicolon!",
"message": "audio;music;cd;player;"
"description": "A list of words that can be searched for. Please ensure that the list also ends with a semicolon!\r",
"message": "audio;music;cd;player;\r"
},
"Name": {
"message": "theBeat Blueprint"
"message": "theBeat Blueprint\r"
}
}
6 changes: 3 additions & 3 deletions libthebeat/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ QMap<QMediaMetaData::Key, QString> Helpers::metadataStrings = {
};

QImage findAlbumArtWorker(QUrl url) {
auto extractID3v2 = [](TagLib::ID3v2::Tag* tag) {
auto extractID3v2 = [](TagLib::ID3v2::Tag * tag) {
TagLib::ID3v2::FrameList frameList = tag->frameListMap()["APIC"];
if (frameList.isEmpty()) return QImage();

Expand All @@ -87,7 +87,7 @@ QImage findAlbumArtWorker(QUrl url) {
return QImage();
};

auto extractXiph = [](TagLib::Ogg::XiphComment* xiph) {
auto extractXiph = [](TagLib::Ogg::XiphComment * xiph) {
for (TagLib::FLAC::Picture* picture : xiph->pictureList()) {
if (picture->type() == TagLib::FLAC::Picture::FrontCover) {
return QImage::fromData(reinterpret_cast<const uchar*>(picture->data().data()), picture->data().size());
Expand Down Expand Up @@ -160,7 +160,7 @@ QCoro::Task<QImage> Helpers::albumArt(QUrl url) {
co_return artCache.object(url)->copy();
}

QImage art = co_await QtConcurrent::run([=]() {
QImage art = co_await QtConcurrent::run([ = ]() {
return findAlbumArtWorker(url);
});

Expand Down
9 changes: 5 additions & 4 deletions libthebeat/musicbrainzclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#include <QAbstractListModel>
#include <QCoroTask>
#include "libthebeat_global.h"

struct MusicBrainzClientPrivate;
class MusicBrainzClient : public QAbstractListModel {
class LIBTHEBEAT_EXPORT MusicBrainzClient : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(QString albumName READ albumName NOTIFY albumNameChanged FINAL)
Q_PROPERTY(QImage albumArt READ albumArt NOTIFY albumArtChanged FINAL)
Expand All @@ -17,9 +18,9 @@ class MusicBrainzClient : public QAbstractListModel {
~MusicBrainzClient();

struct MusicBrainzTrack {
QString title;
QStringList artists;
QString album;
QString title;
QStringList artists;
QString album;
};

enum Role {
Expand Down
3 changes: 1 addition & 2 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
add_subdirectory(InternetRadioPlugin)
add_subdirectory(PodcastPlugin)
add_subdirectory(LastFmPlugin)
add_subdirectory(ParanoiaPlugin)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# add_subdirectory(AvFoundationPlugin)
add_subdirectory(MacIntegration)
ENDIF()

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_subdirectory(CdrdaoPlugin)
add_subdirectory(LinuxIntegration)
add_subdirectory(GstPlugin)
add_subdirectory(ParanoiaPlugin)
ENDIF()

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
Expand Down
21 changes: 18 additions & 3 deletions plugins/ParanoiaPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets DBus)
find_package(libcontemporary)

find_package(PkgConfig REQUIRED)
find_package(libthefrisbee)
pkg_check_modules(cdio IMPORTED_TARGET libcdio++)
pkg_check_modules(MusicBrainz IMPORTED_TARGET libmusicbrainz5)
pkg_check_modules(cdio-paranoia IMPORTED_TARGET libcdio_paranoia)

IF(NOT ${cdio-paranoia_FOUND})
return()
ENDIF()

set(SOURCES
cdmonitor.cpp
plugin.cpp
)

set(HEADERS
cdmonitor.h
plugin.h
)

Expand Down Expand Up @@ -42,7 +45,19 @@ qt_add_qml_module(plugin-paranoia
SOURCES paranoiamediaitem.h paranoiamediaitem.cpp
)

target_link_libraries(plugin-paranoia PRIVATE Qt::Widgets Qt::DBus PkgConfig::cdio PkgConfig::cdio-paranoia libcontemporary libthefrisbee libthebeat)
target_link_libraries(plugin-paranoia PRIVATE Qt::Widgets Qt::DBus PkgConfig::cdio PkgConfig::cdio-paranoia libcontemporary libthebeat)

IF(${libthefrisbee_FOUND})
target_sources(plugin-paranoia PRIVATE cdmonitor.cpp cdmonitor.h)
target_link_libraries(plugin-paranoia PRIVATE libthefrisbee)
target_compile_definitions(plugin-paranoia PUBLIC HAVE_THEFRISBEE)
ENDIF()


IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_sources(plugin-paranoia PRIVATE wincdmonitor.h wincdmonitor.cpp)
target_link_libraries(plugin-paranoia PRIVATE comsuppwd)
ENDIF()

IF(${MusicBrainz_FOUND})
target_link_libraries(plugin-paranoia PRIVATE PkgConfig::MusicBrainz)
Expand Down
6 changes: 3 additions & 3 deletions plugins/ParanoiaPlugin/cdmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <statemanager.h>

struct CdMonitorPrivate {
QMap<DiskObject*, ParanoiaCdController*> panes;
QMap<DiskObject*, ParanoiaCdController*> panes;
};

CdMonitor::CdMonitor(QObject* parent) :
Expand All @@ -18,7 +18,7 @@ CdMonitor::CdMonitor(QObject* parent) :
for (auto drive : DriveObjectManager::drives()) {
connect(drive, &DriveInterface::changed, this, &CdMonitor::updateDisks);
}
connect(DriveObjectManager::instance(), &DriveObjectManager::driveAdded, this, [this](DriveInterface* drive) {
connect(DriveObjectManager::instance(), &DriveObjectManager::driveAdded, this, [this](DriveInterface * drive) {
connect(drive, &DriveInterface::changed, this, &CdMonitor::updateDisks);
});
QTimer::singleShot(0, this, &CdMonitor::updateDisks);
Expand All @@ -37,7 +37,7 @@ void CdMonitor::updateDisks() {
if (drive->audioTracks() == 0) continue;

if (!d->panes.contains(disk)) {
auto widget = new ParanoiaCdController(disk);
auto widget = new ParanoiaCdController(disk->interface<BlockInterface>()->blockName());
d->panes.insert(disk, widget);
}

Expand Down
54 changes: 29 additions & 25 deletions plugins/ParanoiaPlugin/paranoiacdcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
#include "paranoiamediaitem.h"
#include "paranoiaplayer.h"
#include "paranoiatrackinfo.h"
#include <DriveObjects/blockinterface.h>
#include <DriveObjects/diskobject.h>
#include <DriveObjects/driveinterface.h>
// #include <mediaitem/paranoiacdplayback.h>
#include <musicbrainzclient.h>
#include <pluginmediasource.h>
#include <sourcemanager.h>
#include <QTimer>
#include <statemanager.h>

#include <QAudioSink>
Expand All @@ -19,35 +17,30 @@
#include <cdio++/cdio.hpp>

struct ParanoiaCdControllerPrivate {
PluginMediaSource* source;
DiskObject* disk;
ParanoiaPlayer* player = nullptr;
QAudioSink* sink = nullptr;
QIODevice* sinkOutput = nullptr;
MusicBrainzClient* musicBrainzClient = nullptr;

QString albumName;
QList<ParanoiaTrackInfoPtr> trackInfo;
CdioDevice device;
PluginMediaSource* source;
ParanoiaPlayer* player = nullptr;
QAudioSink* sink = nullptr;
QIODevice* sinkOutput = nullptr;
MusicBrainzClient* musicBrainzClient = nullptr;

QString albumName;
QList<ParanoiaTrackInfoPtr> trackInfo;
CdioDevice device;
};

ParanoiaCdController::ParanoiaCdController(DiskObject* disk, QWidget* parent) :
ParanoiaCdController::ParanoiaCdController(QString deviceDescriptor, QWidget* parent) :
QAbstractListModel(parent) {
d = new ParanoiaCdControllerPrivate();
d->disk = disk;

d->albumName = tr("CD");

d->source = new ParanoiaCdPluginMediaSource(this);
d->source->setIcon(QIcon::fromTheme("media-optical-audio"));

auto drive = d->disk->interface<BlockInterface>()->drive();
for (auto i = 0; i < drive->audioTracks(); i++) {
d->trackInfo.append(ParanoiaTrackInfoPtr(new ParanoiaTrackInfo(i)));
if (d->device.open(deviceDescriptor.toUtf8().constData(), DRIVER_DEVICE)) {
readCd();
}

readCd();

QAudioFormat format;
format.setChannelCount(2);
format.setSampleRate(44100);
Expand All @@ -58,7 +51,9 @@ ParanoiaCdController::ParanoiaCdController(DiskObject* disk, QWidget* parent) :
d->sink->suspend();
connect(d->player, &ParanoiaPlayer::frameAvailable, this, &ParanoiaCdController::feedSink);
connect(d->player, &ParanoiaPlayer::epochChanged, this, [this] {
d->sinkOutput = d->sink->start();
if (d->sink->state() != QAudio::SuspendedState) {
d->sinkOutput = d->sink->start();
}
});

QTimer* sinkFeedTimer = new QTimer(this);
Expand All @@ -84,8 +79,10 @@ MusicBrainzClient* ParanoiaCdController::musicBrainzClient() {
}

QCoro::Task<> ParanoiaCdController::eject() {
auto drive = d->disk->interface<BlockInterface>()->drive();
co_await drive->eject();
// auto drive = d->disk->interface<BlockInterface>()->drive();
// co_await drive->eject();
d->device.ejectMedia();
co_return;
}

MediaItem* ParanoiaCdController::mediaItem(int row) {
Expand All @@ -95,7 +92,14 @@ MediaItem* ParanoiaCdController::mediaItem(int row) {
}

void ParanoiaCdController::readCd() {
if (!d->device.open(d->disk->interface<BlockInterface>()->blockName().toUtf8().constData(), DRIVER_DEVICE)) return;
// if (!d->device.open(d->disk->interface<BlockInterface>()->blockName().toUtf8().constData(), DRIVER_DEVICE)) return;

auto firstTrack = d->device.getFirstTrackNum();
auto lastTrack = d->device.getLastTrackNum();
// auto drive = d->disk->interface<BlockInterface>()->drive();
for (auto i = firstTrack; i <= lastTrack; i++) {
d->trackInfo.append(ParanoiaTrackInfoPtr(new ParanoiaTrackInfo(i - 1)));
}

this->setCdTextMetadata();
d->player = new ParanoiaPlayer(&d->device, this);
Expand Down Expand Up @@ -127,7 +131,7 @@ void ParanoiaCdController::readCd() {
}

void ParanoiaCdController::feedSink() {
while (d->sink->bytesFree() >= 2342 && d->player->isFrameAvailable()) {
while (d->sink->bytesFree() >= 2342 && d->player->isFrameAvailable() && d->sink->state() != QAudio::SuspendedState) {
d->sinkOutput->write(d->player->nextFrame(1));
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/ParanoiaPlugin/paranoiacdcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
#include <QAbstractListModel>
#include <QCoroTask>
#include <QWidget>
#include <cdio++/cdio.hpp>
#include <musicbrainzclient.h>

class MediaItem;
class DiskObject;
struct ParanoiaCdControllerPrivate;
class ParanoiaCdController : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(QString albumName READ albumName NOTIFY albumNameChanged FINAL)
Q_PROPERTY(MusicBrainzClient* musicBrainzClient READ musicBrainzClient NOTIFY musicBrainzClientChanged FINAL)

public:
explicit ParanoiaCdController(DiskObject* disk, QWidget* parent = nullptr);
explicit ParanoiaCdController(QString deviceDescriptor, QWidget* parent = nullptr);
~ParanoiaCdController();

enum Roles {
Expand Down
Loading

0 comments on commit 4dd6834

Please sign in to comment.