Skip to content

Commit

Permalink
Initial Qt6 port.
Browse files Browse the repository at this point in the history
  • Loading branch information
chirs241097 committed May 14, 2024
1 parent cf74d30 commit 5d837ae
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ add_subdirectory(thtk EXCLUDE_FROM_ALL)
#they assumed their project is the root project...
target_include_directories(thtk PUBLIC thtk/)

find_package(Qt5 REQUIRED COMPONENTS Widgets Multimedia)
find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia)
find_package(ICU COMPONENTS uc i18n REQUIRED)
find_package(ECM 5.83.0 NO_MODULE)

set(CMAKE_AUTOMOC ON)
Expand Down Expand Up @@ -58,7 +59,7 @@ add_dependencies(thplayer thtk)
get_property(thtk_bindir DIRECTORY thtk/ PROPERTY BINARY_DIR)
target_include_directories(thplayer PRIVATE ${thtk_bindir})

target_link_libraries(thplayer thtk Qt5::Widgets Qt5::Multimedia)
target_link_libraries(thplayer thtk Qt6::Widgets Qt6::Multimedia ICU::uc ICU::i18n)

if(WIN32)
set_property(TARGET thplayer PROPERTY WIN32_EXECUTABLE True)
Expand Down
20 changes: 9 additions & 11 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QMimeData>
#include <QRegularExpression>
#include <QFontDatabase>
#include <QMediaDevices>

#include "outputselectiondialog.hpp"
#include "loopedpcmstreamer.hpp"
Expand Down Expand Up @@ -63,9 +64,9 @@ bool MainWindow::args(QCommandLineParser &p)
printf("List of available output devices:\n");
printf("Device ID\tDevice Name\n");
int id = 0;
for (auto &di : QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
for (auto &di : QMediaDevices::audioOutputs())
{
printf("%d \t%s\n", id++, di.deviceName().toStdString().c_str());
printf("%d \t%s\n", id++, di.description().toStdString().c_str());
}
return true;
}
Expand All @@ -78,7 +79,7 @@ bool MainWindow::args(QCommandLineParser &p)
printf("--device: Number expected.\n");
return true;
}
if (t >= QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).size() || t < 0)
if (t >= QMediaDevices::audioOutputs().size() || t < 0)
{
printf("--device: device ID out of range.\n");
return true;
Expand Down Expand Up @@ -241,12 +242,9 @@ void MainWindow::seek()
QAudioFormat MainWindow::getAudioFormat(unsigned rate)
{
QAudioFormat audioFormat;
audioFormat.setCodec("audio/pcm");
audioFormat.setChannelCount(2);
audioFormat.setSampleRate(rate);
audioFormat.setSampleSize(16);
audioFormat.setSampleType(QAudioFormat::SignedInt);
audioFormat.setByteOrder(QAudioFormat::LittleEndian);
audioFormat.setSampleFormat(QAudioFormat::SampleFormat::Int16);
return audioFormat;
}

Expand Down Expand Up @@ -293,16 +291,16 @@ void MainWindow::play(int index)
// audio playback:
QAudioFormat desiredFormat1 = getAudioFormat(songs.songs[songIdx].rate);

QAudioDeviceInfo info1(
~devi ? QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)[devi]
: QAudioDeviceInfo::defaultOutputDevice());
QAudioDevice info1(
~devi ? QMediaDevices::audioOutputs()[devi]
: QMediaDevices::defaultAudioOutput());
if (!info1.isFormatSupported(desiredFormat1))
{
qWarning() << "Default format not supported, trying to use the nearest.";
desiredFormat1 = info1.preferredFormat();
}
stop();
audioOutput = new QAudioOutput(info1, desiredFormat1, this);
audioOutput = new QAudioSink(info1, desiredFormat1, this);
audioOutput->setVolume(1.0);
fs::path srcfile = qstring_to_path(songs.thbgmFilePath);
if (thver == 6)
Expand Down
5 changes: 3 additions & 2 deletions mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <QMainWindow>
#include <QDragEnterEvent>
#include <QAudioFormat>
#include <QAudioOutput>
#include <QAudioDevice>
#include <QAudioSink>
#include <QBuffer>
#include <QTimer>
#include <QSlider>
Expand Down Expand Up @@ -56,7 +57,7 @@ class MainWindow : public QMainWindow
SongList songs;
song_t cursong;
LoopedPCMStreamer *st = nullptr;
QAudioOutput *audioOutput = nullptr;
QAudioSink *audioOutput = nullptr;
QAudioFormat getAudioFormat(unsigned rate);
QTimer *timer;
thDatWrapper *datw;
Expand Down
8 changes: 5 additions & 3 deletions outputselectiondialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "outputselectiondialog.hpp"
#include "ui_outputselectiondialog.h"

#include <QAudioDevice>

OutputSelectionDialog::OutputSelectionDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::OutputSelectionDialog)
Expand All @@ -15,12 +17,12 @@ OutputSelectionDialog::~OutputSelectionDialog()

void OutputSelectionDialog::init(int curout)
{
QList<QAudioDeviceInfo> dl = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
QList<QAudioDevice> dl = QMediaDevices::audioOutputs();
if (curout < 0 || curout >= dl.size())curout = 0;
ui->label->setText(QString("The current audio output '%1' didn't work, please choose another one below.").arg(dl[curout].deviceName()));
ui->label->setText(QString("The current audio output '%1' didn't work, please choose another one below.").arg(dl[curout].description()));
_selection = -1;
ui->comboBox->clear();
for (auto di : dl)ui->comboBox->addItem(di.deviceName());
for (auto di : dl)ui->comboBox->addItem(di.description());
}
void OutputSelectionDialog::on_buttonBox_accepted()
{
Expand Down
2 changes: 1 addition & 1 deletion outputselectiondialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define OUTPUTSELECTIONDIALOG_H

#include <QDialog>
#include <QAudioDeviceInfo>
#include <QMediaDevices>

namespace Ui
{
Expand Down
8 changes: 6 additions & 2 deletions songlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#include <QFileInfo>
#include <QDebug>
#include <QByteArray>
#include <QTextCodec>
#include <QRegularExpression>
#include <unicode/ustring.h>
#include <unicode/unistr.h>
#include <unicode/ucnv.h>
#include <map>
#include <fstream>

Expand Down Expand Up @@ -82,7 +84,9 @@ void SongList::LoadComment(thDatWrapper *datw)
QByteArray *arr = new QByteArray((int)(scmt + 1), '\0');
char *dat = arr->data();
datw->getFile(isTrial ? "musiccmt_tr.txt" : "musiccmt.txt", dat);
QString s = QTextCodec::codecForName("Shift-JIS")->toUnicode(*arr);
icu::UnicodeString us(dat, "sjis");
std::string r;
QString s = QString::fromUtf8(us.toUTF8String(r).c_str());
std::map<QString, std::pair<QString, QString>> map;
QStringList sl = s.split('\n');
for (auto &i : sl)i = i.trimmed();
Expand Down

0 comments on commit 5d837ae

Please sign in to comment.