mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-27 00:30:26 +00:00
Corrects attempt at back-to-UI final window SDI behaviour.
Maybe it'll turn out to be not what I want, but at least now it works.
This commit is contained in:
parent
1875a03757
commit
b96f7711e3
@ -42,6 +42,10 @@ class VSyncPredictor {
|
||||
last_vsync_ = vsync_time;
|
||||
}
|
||||
|
||||
void pause() {
|
||||
last_vsync_ = 0;
|
||||
}
|
||||
|
||||
Nanos suggested_draw_time() {
|
||||
// TODO: this is a very simple version of how this calculation
|
||||
// should be made. It's tracking the average amount of time these
|
||||
|
@ -46,7 +46,7 @@ MainWindow::MainWindow(const QString &fileName) {
|
||||
launchFile(fileName);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
void MainWindow::deleteMachine() {
|
||||
// Stop the timer; stopping this first ensures the machine won't attempt
|
||||
// to write to the audioOutput while it is being shut down.
|
||||
timer.reset();
|
||||
@ -62,21 +62,29 @@ MainWindow::~MainWindow() {
|
||||
audioThread.stop();
|
||||
}
|
||||
|
||||
machine.reset();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
deleteMachine();
|
||||
|
||||
// Store the current user selections.
|
||||
storeSelections();
|
||||
|
||||
--mainWindowCount;
|
||||
qDebug() << "Count: " << mainWindowCount;
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
// SDI behaviour, which may or may not be normal (?): if the user is closing a
|
||||
// final window, and it contains a machine, send them back to the machine picker.
|
||||
// i.e. assume they were closing that document, not the application.
|
||||
// if(mainWindowCount == 1 && machine) {
|
||||
// MainWindow *const other = new MainWindow;
|
||||
// other->setAttribute(Qt::WA_DeleteOnClose);
|
||||
// other->show();
|
||||
// }
|
||||
if(mainWindowCount == 1 && machine) {
|
||||
setVisibleWidgetSet(WidgetSet::MachinePicker);
|
||||
deleteMachine();
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
@ -90,8 +98,6 @@ void MainWindow::init() {
|
||||
|
||||
createActions();
|
||||
restoreSelections();
|
||||
|
||||
timer = std::make_unique<Timer>(this);
|
||||
}
|
||||
|
||||
void MainWindow::createActions() {
|
||||
@ -280,6 +286,7 @@ void MainWindow::launchMachine() {
|
||||
// If this is a timed machine, start up the timer.
|
||||
const auto timedMachine = machine->timed_machine();
|
||||
if(timedMachine) {
|
||||
timer = std::make_unique<Timer>(this);
|
||||
timer->startWithMachine(timedMachine, &machineMutex);
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,8 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
|
||||
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
static inline int mainWindowCount = 0;
|
||||
|
||||
void deleteMachine();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -10,9 +10,7 @@ ScanTargetWidget::ScanTargetWidget(QWidget *parent) : QOpenGLWidget(parent) {}
|
||||
ScanTargetWidget::~ScanTargetWidget() {}
|
||||
|
||||
void ScanTargetWidget::initializeGL() {
|
||||
// Retain the default background colour.
|
||||
const QColor backgroundColour = palette().color(QWidget::backgroundRole());
|
||||
glClearColor(backgroundColour.redF(), backgroundColour.greenF(), backgroundColour.blueF(), 1.0);
|
||||
setDefaultClearColour();
|
||||
|
||||
// Follow each swapped frame with an additional update.
|
||||
connect(this, &QOpenGLWidget::frameSwapped, this, &ScanTargetWidget::vsync);
|
||||
@ -56,6 +54,8 @@ void ScanTargetWidget::paintGL() {
|
||||
}
|
||||
|
||||
void ScanTargetWidget::vsync() {
|
||||
if(!isConnected) return;
|
||||
|
||||
vsyncPredictor.announce_vsync();
|
||||
|
||||
const auto time_now = Time::nanos_now();
|
||||
@ -80,4 +80,12 @@ void ScanTargetWidget::stop() {
|
||||
makeCurrent();
|
||||
scanTarget.reset();
|
||||
isConnected = false;
|
||||
setDefaultClearColour();
|
||||
vsyncPredictor.pause();
|
||||
}
|
||||
|
||||
void ScanTargetWidget::setDefaultClearColour() {
|
||||
// Retain the default background colour.
|
||||
const QColor backgroundColour = palette().color(QWidget::backgroundRole());
|
||||
glClearColor(backgroundColour.redF(), backgroundColour.greenF(), backgroundColour.blueF(), 1.0);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ class ScanTargetWidget : public QOpenGLWidget
|
||||
GLuint framebuffer = 0;
|
||||
MachineTypes::ScanProducer *producer = nullptr;
|
||||
|
||||
void setDefaultClearColour();
|
||||
|
||||
private slots:
|
||||
void vsync();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user