Skip to content

Commit

Permalink
Port application to Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed May 6, 2024
1 parent 63e1b29 commit f9a5129
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Engine/API/Abstract/abstractrhxcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ AbstractRHXController::AbstractRHXController(ControllerType type_, AmplifierSamp
pipeReadErrorCode(0)
{
usbBufferSize = MaxNumBlocksToRead * BytesPerWord * RHXDataBlock::dataBlockSizeInWords(type, maxNumDataStreams());
cout << "RHXController: Allocating " << usbBufferSize / 1.0e6 << " MBytes for USB buffer.\n";
std::cout << "RHXController: Allocating " << usbBufferSize / 1.0e6 << " MBytes for USB buffer." << std::endl;
usbBuffer = nullptr;
usbBuffer = new uint8_t [usbBufferSize];
numDataStreams = 0;
Expand Down
2 changes: 1 addition & 1 deletion Engine/API/Synthetic/synthdatablockgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ SynthDataBlockGenerator::SynthDataBlockGenerator(ControllerType type_, double sa
{
int bufferSizeInWords = MaxNumBlocksToRead *
RHXDataBlock::dataBlockSizeInWords(type, AbstractRHXController::maxNumDataStreams(type));
cout << "SynthDataBlockGenerator: Allocating " << BytesPerWord * bufferSizeInWords / 1.0e6 << " MBytes for synthetic USB data generator.\n";
std::cout << "SynthDataBlockGenerator: Allocating " << BytesPerWord * bufferSizeInWords / 1.0e6 << " MBytes for synthetic USB data generator." << std::endl;
usbWords = nullptr;
usbWords = new uint16_t [bufferSizeInWords];
dataBlockPeriodInNsec = 1.0e9 * ((double)RHXDataBlock::samplesPerDataBlock(type)) / sampleRate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <QFileInfo>
#include <iostream>
#include <thread>
#include "rhxglobals.h"
#include "datafilereader.h"
#include "fileperchannelmanager.h"
Expand Down
6 changes: 3 additions & 3 deletions Engine/Processing/datastreamfifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ DataStreamFifo::DataStreamFifo(int bufferSize_, int maxReadLength_) :
{
int bufferSizeWithExtra = bufferSize + maxReadLength;
memoryNeededGB = sizeof(uint16_t) * bufferSizeWithExtra / (1024.0 * 1024.0 * 1024.0);
cout << "DataStreamFifo: Allocating " << 2 * bufferSizeWithExtra / 1.0e6 << " MBytes for FIFO buffer." << '\n';
std::cout << "DataStreamFifo: Allocating " << 2 * bufferSizeWithExtra / 1.0e6 << " MBytes for FIFO buffer." << std::endl;
buffer = nullptr;

memoryAllocated = true;
try {
buffer = new uint16_t [bufferSizeWithExtra];
} catch (std::bad_alloc&) {
memoryAllocated = false;
cerr << "Error: DataStreamFifo constructor could not allocate " << memoryNeededGB << " GB of memory." << '\n';
std::cerr << "Error: DataStreamFifo constructor could not allocate " << memoryNeededGB << " GB of memory." << std::endl;
}

if (!buffer) {
cerr << "Error: DataStreamFifo constructor could not allocate " << 2 * bufferSizeWithExtra << " bytes of memory." << '\n';
std::cerr << "Error: DataStreamFifo constructor could not allocate " << 2 * bufferSizeWithExtra << " bytes of memory." << std::endl;
}
resetBuffer();
}
Expand Down
20 changes: 10 additions & 10 deletions Engine/Processing/xmlinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ bool XMLInterface::checkConsistentChannels(const QByteArray &byteArray, QString
while (!stream.atEnd()) {

// Make sure we enter at least the first SignalGroup element. If we've gone past all the SignalGroups and are at the end of the document, just return
while (stream.name() != "SignalGroup") {
while (stream.name() != QStringLiteral("SignalGroup")) {
QXmlStreamReader::TokenType token = stream.readNext();

// Handle if no signal groups at all are present by giving a warning and returning
Expand Down Expand Up @@ -504,7 +504,7 @@ bool XMLInterface::checkConsistentChannels(const QByteArray &byteArray, QString
while (!stream.atEnd()) {

// Make sure we enter at least the first Channel element. If we've gone past all the Channels and are at the end of the document, just return.
while (stream.name() != "Channel") {
while (stream.name() != QStringLiteral("Channel")) {
QXmlStreamReader::TokenType token = stream.readNext();
if (token == QXmlStreamReader::EndDocument) {

Expand Down Expand Up @@ -594,7 +594,7 @@ bool XMLInterface::parseGeneralConfig(const QByteArray &byteArray, QString &erro
if (!validDocumentStart) return false;

// Parse GeneralConfig
while (stream.name() != "GeneralConfig") {
while (stream.name() != QStringLiteral("GeneralConfig")) {
stream.readNextStartElement();
if (stream.atEnd()) return true;
}
Expand Down Expand Up @@ -697,7 +697,7 @@ bool XMLInterface::parseSignalGroups(const QByteArray &byteArray, QString &error
while (!stream.atEnd()) {

// Make sure we enter at least the first SignalGroup element. If we've gone past all the SignalGroups and are at the end of the document, just return.
while (stream.name() != "SignalGroup") {
while (stream.name() != QStringLiteral("SignalGroup")) {
QXmlStreamReader::TokenType token = stream.readNext();
if (token == QXmlStreamReader::EndDocument) {
return true;
Expand Down Expand Up @@ -797,7 +797,7 @@ bool XMLInterface::parseSignalGroups(const QByteArray &byteArray, QString &error
while (!stream.atEnd()) {

// Make sure we enter at least the first Channel element. If we've gone past all the Channels and are at the end of the document, just return.
while (stream.name() != "Channel") {
while (stream.name() != QStringLiteral("Channel")) {
QXmlStreamReader::TokenType token = stream.readNext();
if (token == QXmlStreamReader::EndDocument) {
return true;
Expand Down Expand Up @@ -889,7 +889,7 @@ bool XMLInterface::parseStimParameters(const QByteArray &byteArray, QString &err
if (!validDocumentStart) return false;

// Parse StimParameters.
while (stream.name() != "StimParameters") {
while (stream.name() != QStringLiteral("StimParameters")) {
stream.readNextStartElement();
if (stream.atEnd()) return true;
}
Expand All @@ -898,7 +898,7 @@ bool XMLInterface::parseStimParameters(const QByteArray &byteArray, QString &err
while (!stream.atEnd()) {

// Make sure we enter at least the first StimChannel element. If we've gone past all the StimChannels and are at the end of the document, just return.
while (stream.name() != "StimChannel") {
while (stream.name() != QStringLiteral("StimChannel")) {
QXmlStreamReader::TokenType token = stream.readNext();
if (token == QXmlStreamReader::EndDocument) {
return true;
Expand All @@ -911,7 +911,7 @@ bool XMLInterface::parseStimParameters(const QByteArray &byteArray, QString &err
// Try to find the StimChannel's name.
QString nativeChannelName("");
for (auto attribute : attributes) {
if (attribute.name().toString().toLower() == "nativechannelname") {
if (attribute.name().toString().toLower() == QStringLiteral("nativechannelname")) {
nativeChannelName = attribute.value().toString();
break;
}
Expand Down Expand Up @@ -962,7 +962,7 @@ bool XMLInterface::parseStimParameters(const QByteArray &byteArray, QString &err
bool XMLInterface::parseStimLegacy(const QByteArray &byteArray, QString &errorMessage) const
{
QXmlStreamReader stream(byteArray);
if (!stream.readNextStartElement() || stream.name() != "xstim" || stream.attributes().value("", "version").toString() != "1.0") {
if (!stream.readNextStartElement() || stream.name() != QStringLiteral("xstim") || stream.attributes().value("", "version").toString() != "1.0") {
errorMessage.append("Error: invalid xstim element and version attribute");
return false;
}
Expand All @@ -971,7 +971,7 @@ bool XMLInterface::parseStimLegacy(const QByteArray &byteArray, QString &errorMe

state->holdUpdate();

while (stream.readNextStartElement() && stream.name() == "channel") {
while (stream.readNextStartElement() && stream.name() == QStringLiteral("channel")) {

QString channelName = stream.attributes().value("", "name").toString();
channel = state->signalSources->channelByName(channelName);
Expand Down
58 changes: 29 additions & 29 deletions Engine/Threads/audiothread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
//
//------------------------------------------------------------------------------

#include <QAudioDeviceInfo>
#include "signalsources.h"
#include "audiothread.h"

#include <QMediaDevices>

AudioThread::AudioThread(SystemState *state_, WaveformFifo *waveformFifo_, const double sampleRate_, QObject *parent) :
QThread(parent),
state(state_),
Expand All @@ -52,7 +53,6 @@ AudioThread::AudioThread(SystemState *state_, WaveformFifo *waveformFifo_, const
void AudioThread::initialize()
{
// Initialize variables.
mDevice = QAudioDeviceInfo::defaultOutputDevice();
currentValue = 0.0F;
nextValue = 0.0F;
interpRatio = 0.0;
Expand Down Expand Up @@ -87,21 +87,19 @@ void AudioThread::initialize()
// Set up audio format.
mFormat.setSampleRate(44100);
mFormat.setChannelCount(1);
mFormat.setSampleSize(16);
mFormat.setCodec("audio/pcm");
mFormat.setByteOrder(QAudioFormat::LittleEndian);
mFormat.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info(mDevice);
if (!info.isFormatSupported(mFormat)) {
qWarning() << "Default format not supported - trying to use nearest";
mFormat = info.nearestFormat(mFormat);
mFormat.setSampleFormat(QAudioFormat::Int16);

QAudioDevice defaultDevice(QMediaDevices::defaultAudioOutput());
if (!defaultDevice.isFormatSupported(mFormat)) {
qWarning() << "Default format not supported - trying to use preferred";
mFormat = defaultDevice.preferredFormat();
mFormat.setChannelCount(1);
}

// Create audio IO and output device.
buf = new QByteArray();
s = new QDataStream(buf, QIODevice::ReadWrite);
mAudioOutput = new QAudioOutput(mDevice, mFormat);
connect(mAudioOutput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(catchError()));
mAudioSink = std::make_unique<QAudioSink>(defaultDevice, mFormat);
mAudioSink->setBufferSize(NumSoundBytes);
connect(mAudioSink.get(), SIGNAL(stateChanged(QAudio::State)), this, SLOT(catchError()));
}

void AudioThread::run()
Expand All @@ -113,8 +111,16 @@ void AudioThread::run()
// Any 'start up' code goes here.
initialize();

QDataStream *s = nullptr;
while (keepGoing && !stopThread) {

// Start audio (if it's not started already)
if (mAudioSink->state() != QAudio::ActiveState || s == nullptr) {
if (s)
delete s;
s = new QDataStream(mAudioSink->start());
}

// Wait for samples to arrive from WaveformFifo (enough where, when scaled to 44.1 kHz audio, NumSoundSamples can be written)
if (waveformFifo->requestReadNewData(WaveformFifo::ReaderAudio, rawBlockSampleSize)) {
s->device()->seek(0);
Expand All @@ -130,27 +136,22 @@ void AudioThread::run()
// Populate finalSoundBytesBuffer from rawData
processAudioData();

// Start audio (if it's not started already)
if (mAudioOutput->state() != QAudio::ActiveState) {
mAudioOutput->start(s->device());
}
qApp->processEvents();

} else {
// Probably could sleep here for a while
qApp->processEvents();
}
}

// Any 'finish up' code goes here.
mAudioOutput->stop();
mAudioSink->stop();

if (s)
delete s;

delete [] rawData;
delete [] interpFloats;
delete [] interpInts;
delete [] finalSoundBytesBuffer;
delete s;
delete buf;

running = false;
} else {
Expand Down Expand Up @@ -223,7 +224,6 @@ void AudioThread::processAudioData()
originalSamplesCopied = 0;
soundSamplesCopied = 0;
while (originalSamplesCopied < rawBlockSampleSize) {
qApp->processEvents();
currentValue = nextValue;
nextValue = rawData[originalSamplesCopied];

Expand Down Expand Up @@ -282,21 +282,21 @@ void AudioThread::processAudioData()

void AudioThread::catchError()
{
QAudio::Error errorValue = mAudioOutput->error();
QAudio::Error errorValue = mAudioSink->error();
switch (errorValue) {
case QAudio::NoError:
break;
case QAudio::OpenError:
qDebug() << "Open Error";
qDebug().noquote() << "rhx-audio: Open Error";
break;
case QAudio::IOError:
qDebug() << "IO Error";
qDebug().noquote() << "rhx-audio: IO Error";
break;
case QAudio::UnderrunError:
qDebug() << "Underrun Error";
qDebug().noquote() << "rhx-audio: Underrun Error";
break;
case QAudio::FatalError:
qDebug() << "Fatal Error";
qDebug().noquote() << "rhx-audio: Fatal Error";
break;
}
}
15 changes: 7 additions & 8 deletions Engine/Threads/audiothread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#define AUDIOTHREAD_H

#include <QThread>
#include <QAudioOutput>
#include <QAudioSink>
#include <QAudioFormat>
#include <cstdint>
#include <mutex>
#include "systemstate.h"
Expand Down Expand Up @@ -94,20 +95,18 @@ private slots:
int originalSamplesCopied;
int soundSamplesCopied;

volatile bool keepGoing;
volatile bool running;
volatile bool stopThread;
std::atomic_bool keepGoing;
std::atomic_bool running;
std::atomic_bool stopThread;

float currentValue;
float nextValue;
double interpRatio;
int interpLength;

QAudioDeviceInfo mDevice;
QByteArray* buf;
QDataStream* s;
QAudioOutput* mAudioOutput;
QAudioFormat mFormat;
std::unique_ptr<QAudioSink> mAudioSink;
QDataStream* s;

QString currentChannelString;

Expand Down
4 changes: 2 additions & 2 deletions Engine/Threads/usbdatathread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ USBDataThread::USBDataThread(AbstractRHXController* controller_, DataStreamFifo*
bufferSize = (BufferSizeInBlocks + 1) * BytesPerWord *
RHXDataBlock::dataBlockSizeInWords(controller->getType(), controller->maxNumDataStreams());
memoryNeededGB = sizeof(uint8_t) * bufferSize / (1024.0 * 1024.0 * 1024.0);
cout << "USBDataThread: Allocating " << bufferSize / 1.0e6 << " MBytes for USB buffer." << '\n';
std::cout << "USBDataThread: Allocating " << bufferSize / 1.0e6 << " MBytes for USB buffer." << std::endl;
usbBuffer = nullptr;

memoryAllocated = true;
try {
usbBuffer = new uint8_t [bufferSize];
} catch (std::bad_alloc&) {
memoryAllocated = false;
cerr << "Error: USBDataThread constructor could not allocate " << memoryNeededGB << " GB of memory." << '\n';
std::cerr << "Error: USBDataThread constructor could not allocate " << memoryNeededGB << " GB of memory." << std::endl;
}

// cout << "Ideal thread count: " << QThread::idealThreadCount() << EndOfLine;
Expand Down
3 changes: 0 additions & 3 deletions GUI/Dialogs/boardselectdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@ BoardSelectDialog::BoardSelectDialog(QWidget *parent) :
QCoreApplication::setOrganizationDomain(OrganizationDomain);
QCoreApplication::setApplicationName(ApplicationName);

// Globally disable unused Context Help buttons from windows/dialogs
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);

// Initialize Board Identifier.
boardIdentifier = new BoardIdentifier(this);

Expand Down
7 changes: 5 additions & 2 deletions GUI/Dialogs/renamechanneldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "renamechanneldialog.h"

#include <QRegularExpressionValidator>

RenameChannelDialog::RenameChannelDialog(const QString& nativeName, const QString& oldName, QWidget* parent) :
QDialog(parent)
{
Expand All @@ -40,8 +42,9 @@ RenameChannelDialog::RenameChannelDialog(const QString& nativeName, const QStrin
oldNameLayout->addWidget(new QLabel(tr("Old channel name: ") + oldName + addNativeName, this));

nameLineEdit = new QLineEdit;
QRegExp regExp("[\\w-\\+\\./]{1,16}"); // Name must be 1-16 characters, alphanumeric or _-+./
nameLineEdit->setValidator(new QRegExpValidator(regExp, this));
QRegularExpression regExp("[\\w-\\+\\./]{1,16}"); // Name must be 1-16 characters, alphanumeric or _-+./
auto reValidator = new QRegularExpressionValidator(regExp, this);
nameLineEdit->setValidator(reValidator);

connect(nameLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(onLineEditTextChanged()));
Expand Down
8 changes: 4 additions & 4 deletions GUI/Widgets/filterdisplayselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ FilterDisplaySelector::FilterDisplaySelector(SystemState* state_, QWidget* paren
connect(order3CheckBox, SIGNAL(clicked(bool)), this, SLOT(filterOrderChanged()));
connect(order4CheckBox, SIGNAL(clicked(bool)), this, SLOT(filterOrderChanged()));

connect(order1ButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(filterOrderChanged()));
connect(order2ButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(filterOrderChanged()));
connect(order3ButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(filterOrderChanged()));
connect(order4ButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(filterOrderChanged()));
connect(order1ButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(filterOrderChanged()));
connect(order2ButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(filterOrderChanged()));
connect(order3ButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(filterOrderChanged()));
connect(order4ButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(filterOrderChanged()));

order1CheckBox->setChecked(true);
order2CheckBox->setChecked(false);
Expand Down
Loading

0 comments on commit f9a5129

Please sign in to comment.