mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-26 09:29:45 +00:00
Apply de minimis adaptations to get to build under Qt6.
This commit is contained in:
parent
74bee31a78
commit
09059ab869
@ -1,4 +1,4 @@
|
||||
QT += core gui multimedia widgets
|
||||
QT += core gui multimedia widgets openglwidgets
|
||||
|
||||
# Be specific about C++17 but also try the vaguer C++1z for older
|
||||
# versions of Qt.
|
||||
@ -24,10 +24,10 @@ DEFINES += TARGET_QT
|
||||
DEFINES += IGNORE_APPLE
|
||||
QMAKE_CXXFLAGS_RELEASE += -DNDEBUG
|
||||
|
||||
# Generate warnings for any use of APIs deprecated prior to Qt 6.0.0.
|
||||
# Development was performed against Qt 5.14.
|
||||
# Generate warnings for any use of APIs deprecated prior to Qt 7.0.0.
|
||||
# Development was performed against Qt 6.6.1.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
|
||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x070000
|
||||
|
||||
SRC = $$PWD/../..
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include <QObject>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <QAudioDevice>
|
||||
#include <QMediaDevices>
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QtGlobal>
|
||||
|
||||
@ -314,24 +317,24 @@ void MainWindow::launchMachine() {
|
||||
static constexpr size_t samplesPerBuffer = 256; // TODO: select this dynamically.
|
||||
const auto speaker = audio_producer->get_speaker();
|
||||
if(speaker) {
|
||||
const QAudioDeviceInfo &defaultDeviceInfo = QAudioDeviceInfo::defaultOutputDevice();
|
||||
if(!defaultDeviceInfo.isNull()) {
|
||||
QAudioFormat idealFormat = defaultDeviceInfo.preferredFormat();
|
||||
QAudioDevice device(QMediaDevices::defaultAudioOutput());
|
||||
if(true) { // TODO: how to check that audio output is available in Qt6?
|
||||
QAudioFormat idealFormat = device.preferredFormat();
|
||||
|
||||
// Use the ideal format's sample rate, provide stereo as long as at least two channels
|
||||
// are available, and — at least for now — assume a good buffer size.
|
||||
audioIsStereo = (idealFormat.channelCount() > 1) && speaker->get_is_stereo();
|
||||
audioIs8bit = idealFormat.sampleSize() < 16;
|
||||
audioIs8bit = idealFormat.sampleFormat() == QAudioFormat::UInt8;
|
||||
idealFormat.setChannelCount(1 + int(audioIsStereo));
|
||||
idealFormat.setSampleSize(audioIs8bit ? 8 : 16);
|
||||
idealFormat.setSampleFormat(audioIs8bit ? QAudioFormat::UInt8 : QAudioFormat::Int16);
|
||||
|
||||
speaker->set_output_rate(idealFormat.sampleRate(), samplesPerBuffer, audioIsStereo);
|
||||
speaker->set_delegate(this);
|
||||
|
||||
audioThread.start();
|
||||
audioThread.performAsync([this, idealFormat] {
|
||||
audioThread.performAsync([&] {
|
||||
// Create an audio output.
|
||||
audioOutput = std::make_unique<QAudioOutput>(idealFormat);
|
||||
audioOutput = std::make_unique<QAudioSink>(device, idealFormat);
|
||||
|
||||
// Start the output. The additional `audioBuffer` is meant to minimise latency,
|
||||
// believe it or not, given Qt's semantics.
|
||||
@ -373,13 +376,13 @@ void MainWindow::launchMachine() {
|
||||
QAction *const asKeyboardAction = new QAction(tr("Use Keyboard as Keyboard"), this);
|
||||
asKeyboardAction->setCheckable(true);
|
||||
asKeyboardAction->setChecked(true);
|
||||
asKeyboardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
|
||||
// asKeyboardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
|
||||
inputMenu->addAction(asKeyboardAction);
|
||||
|
||||
QAction *const asJoystickAction = new QAction(tr("Use Keyboard as Joystick"), this);
|
||||
asJoystickAction->setCheckable(true);
|
||||
asJoystickAction->setChecked(false);
|
||||
asJoystickAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
|
||||
// asJoystickAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
|
||||
inputMenu->addAction(asJoystickAction);
|
||||
|
||||
connect(asKeyboardAction, &QAction::triggered, this, [=] {
|
||||
|
@ -1,12 +1,11 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QAudioOutput>
|
||||
#include <QAudioSink>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
|
||||
#include "audiobuffer.h"
|
||||
#include "timer.h"
|
||||
@ -71,7 +70,7 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
|
||||
std::unique_ptr<Machine::DynamicMachine> machine;
|
||||
std::mutex machineMutex;
|
||||
|
||||
std::unique_ptr<QAudioOutput> audioOutput;
|
||||
std::unique_ptr<QAudioSink> audioOutput;
|
||||
bool audioIs8bit = false, audioIsStereo = false;
|
||||
void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector<int16_t> &buffer) override;
|
||||
AudioBuffer audioBuffer;
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <QApplication>
|
||||
#include <QCursor>
|
||||
#include <QDebug>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGuiApplication>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
@ -30,10 +29,7 @@ void ScanTargetWidget::paintGL() {
|
||||
requestedRedrawTime = 0;
|
||||
}
|
||||
|
||||
// TODO: if Qt 5.14 can be guaranteed, just use window()->screen().
|
||||
const auto screenNumber = QApplication::desktop()->screenNumber(this);
|
||||
QScreen *const screen = QGuiApplication::screens()[screenNumber];
|
||||
|
||||
QScreen *const screen = window()->screen();
|
||||
const float newOutputScale = float(screen->devicePixelRatio());
|
||||
if(outputScale != newOutputScale) {
|
||||
outputScale = newOutputScale;
|
||||
|
Loading…
Reference in New Issue
Block a user