From 5ea746a0531903334afe87e1736d52ef1c48a653 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 26 Jul 2018 16:40:08 +0100 Subject: [PATCH] mildly better threading and fixed redo bug --- mainwindow.cpp | 4 +++- mainwindow.ui | 4 ++-- project/clip.cpp | 11 ++++++----- ui/viewerwidget.cpp | 20 ++++++++++---------- ui/viewerwidget.h | 1 - 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 7ff8fc31c..ad6aab62d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -253,12 +253,14 @@ void MainWindow::editMenu_About_To_Be_Shown() { void MainWindow::on_action_Undo_triggered() { undo_stack.undo(); + editMenu_About_To_Be_Shown(); panel_timeline->redraw_all_clips(true); } void MainWindow::on_action_Redo_triggered() { undo_stack.redo(); + editMenu_About_To_Be_Shown(); panel_timeline->redraw_all_clips(true); } @@ -478,7 +480,7 @@ void MainWindow::on_actionGo_to_Next_Cut_triggered() void MainWindow::on_actionPreferences_triggered() { PreferencesDialog pd(this); - pd.setup_kbd_shortcuts(this->menuBar()); + pd.setup_kbd_shortcuts(menuBar()); pd.exec(); } diff --git a/mainwindow.ui b/mainwindow.ui index 7e0f78bf4..f5bdadc25 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -24,7 +24,7 @@ 0 0 653 - 29 + 17 @@ -223,7 +223,7 @@ &Redo - Ctrl+Shift+Z, Ctrl+Y + Ctrl+Shift+Z diff --git a/project/clip.cpp b/project/clip.cpp index e435c04a4..1f7fc3513 100644 --- a/project/clip.cpp +++ b/project/clip.cpp @@ -77,17 +77,18 @@ void Clip::reset() { codecCtx = NULL; texture = NULL; cache_A.frames = NULL; - cache_B.frames = NULL; + cache_B.frames = NULL; } Clip::~Clip() { if (open) { close_clip(this); - } - // make sure clip has closed before clip is destroyed - open_lock.lock(); - open_lock.unlock(); + // make sure clip has closed before clip is destroyed + if (multithreaded) { + cacher->wait(); + } + } if (opening_transition != NULL) delete opening_transition; if (closing_transition != NULL) delete closing_transition; diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index b72309ff0..dc20761ad 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -30,7 +30,6 @@ ViewerWidget::ViewerWidget(QWidget *parent) : QOpenGLWidget(parent) { setFormat(format); // start audio sending thread - connect(&audio_sender_thread, SIGNAL(finished()), &audio_sender_thread, SLOT(deleteLater())); audio_sender_thread.start(); // error handler - retries after 250ms if we couldn't get the entire image @@ -41,8 +40,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) : QOpenGLWidget(parent) { ViewerWidget::~ViewerWidget() { audio_sender_thread.close = true; audio_sender_thread.cond.wakeAll(); - audio_sender_thread.lock.lock(); - audio_sender_thread.lock.unlock(); + audio_sender_thread.wait(); } void ViewerWidget::deleteFunction() { @@ -234,27 +232,29 @@ void ViewerWidget::paintGL() { } AudioSenderThread::AudioSenderThread() : close(false) { - lock.lock(); -} - -AudioSenderThread::~AudioSenderThread() { - lock.unlock(); + connect(this, SIGNAL(finished()), this, SLOT(deleteLater())); } void AudioSenderThread::run() { + lock.lock(); while (true) { cond.wait(&lock); if (close) { break; } else { + int written_bytes = 0; + int adjusted_read_index = audio_ibuffer_read%audio_ibuffer_size; int max_write = audio_ibuffer_size - adjusted_read_index; - if (send_audio_to_output(adjusted_read_index, max_write) == max_write) { + int actual_write = send_audio_to_output(adjusted_read_index, max_write); + written_bytes += actual_write; + if (actual_write == max_write) { // got all the bytes, write again - send_audio_to_output(0, audio_ibuffer_size); + written_bytes += send_audio_to_output(0, audio_ibuffer_size); } } } + lock.unlock(); } int AudioSenderThread::send_audio_to_output(int offset, int max) { diff --git a/ui/viewerwidget.h b/ui/viewerwidget.h index 2acf6de94..8ba9c6a49 100644 --- a/ui/viewerwidget.h +++ b/ui/viewerwidget.h @@ -16,7 +16,6 @@ struct Sequence; class AudioSenderThread : public QThread { public: AudioSenderThread(); - ~AudioSenderThread(); void run(); QWaitCondition cond; bool close;