From a55e6953d95f21b0a3d577adf9ea0d729c28fee1 Mon Sep 17 00:00:00 2001 From: Jared Bruni Date: Tue, 7 Jan 2020 07:35:31 -0800 Subject: [PATCH] added custom cycle mode --- src/main_window.cpp | 13 +++++++++++-- src/main_window.h | 2 ++ src/options_window.cpp | 19 ++++++++++++++++--- src/options_window.h | 1 + src/playback_thread.cpp | 36 ++++++++++++++++++++++++++++++++---- src/playback_thread.h | 5 +++++ 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/main_window.cpp b/src/main_window.cpp index c220ec9..3f38e84 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -425,13 +425,17 @@ void AC_MainWindow::createMenu() { repeat_v->setCheckable(true); repeat_v->setChecked(false); + cycle_custom = new QAction(tr("Cycle Custom"), this); + cycle_custom->setCheckable(true); + cycle_custom->setChecked(false); + fade_on = new QAction(tr("Fade"), this); fade_on->setCheckable(true); fade_on->setChecked(true); options->addAction(fade_on); options->addAction(repeat_v); - - + options->addAction(cycle_custom); + connect(cycle_custom, SIGNAL(triggered()), this, SLOT(setCustomCycle_Menu())); connect(fade_on, SIGNAL(triggered()), this, SLOT(setFade())); connect(repeat_v, SIGNAL(triggered()), this, SLOT(repeat_vid())); connect(clear_image, SIGNAL(triggered()), this, SLOT(clear_img())); @@ -1685,3 +1689,8 @@ void AC_MainWindow::setRandomFilterValue() { int filter_index = ac::filter_map[filter_name]; filters->setCurrentIndex(filter_index); } + +void AC_MainWindow::setCustomCycle_Menu() { + bool chk = cycle_custom->isChecked(); + playback->setCustomCycle(chk); +} diff --git a/src/main_window.h b/src/main_window.h index 5511be1..ad07fac 100644 --- a/src/main_window.h +++ b/src/main_window.h @@ -60,6 +60,7 @@ public: QAction *show_options_window; QAction *show_control_window; QAction *select_random_filter; + QAction *cycle_custom; double speed_actions[7]; QRadioButton *filter_single, *filter_custom; void updateList(); @@ -128,6 +129,7 @@ public slots: void showImageWindow(); void showPrefWindow(); void setRandomFilterValue(); + void setCustomCycle_Menu(); private: void createControls(); void createMenu(); diff --git a/src/options_window.cpp b/src/options_window.cpp index d891bfc..1d73e50 100644 --- a/src/options_window.cpp +++ b/src/options_window.cpp @@ -2,7 +2,7 @@ OptionsWindow::OptionsWindow(QWidget *parent) : QDialog(parent) { - setFixedSize(170, 150); + setFixedSize(170, 180); createControls(); } @@ -19,9 +19,17 @@ void OptionsWindow::createControls() { label_z->setGeometry(10, 70, 100, 25); op_max_frames = new QLineEdit("1500", this); op_max_frames->setGeometry(110,70, 50, 25); + + QLabel *label_q = new QLabel(tr("Delay: "), this); + label_q->setGeometry(10, 100, 100, 25); + + fps_delay = new QLineEdit("60", this); + fps_delay->setGeometry(110, 100, 50, 25); + op_setpref = new QPushButton(tr("Set"), this); - op_setpref->setGeometry(10, 110, 100, 25); + op_setpref->setGeometry(10, 140, 100, 25); connect(op_setpref, SIGNAL(clicked()), this, SLOT(setValues())); + } void OptionsWindow::setValues() { @@ -41,10 +49,15 @@ void OptionsWindow::setValues() { QMessageBox::information(this, tr("Error Requires Max"), tr("Required Max Frames must be greater than 300")); return; } + + int delay_value = atoi(fps_delay->text().toStdString().c_str()); + if(delay_value > 0) + playback->setCustomCycleDelay(delay_value); + ac::setMaxAllocated(max_frames); QString text; QTextStream stream(&text); - stream << tr("Thread Count set to: ") << thread_count << tr(" and Intensity set to: ") << intensity << tr("\nMaximum Stored Frames: ") << max_frames << tr("\n"); + stream << tr("Thread Count set to: ") << thread_count << tr(" and Intensity set to: ") << intensity << tr("\nMaximum Stored Frames: ") << max_frames << tr("\n") << tr("Delay: ") << delay_value << "\n";; QMessageBox::information(this, tr("Pref Value Set"), text); } diff --git a/src/options_window.h b/src/options_window.h index b8b0463..a7672d9 100644 --- a/src/options_window.h +++ b/src/options_window.h @@ -19,6 +19,7 @@ private: QPushButton *op_setpref; Playback *playback; QLineEdit *op_max_frames; + QLineEdit *fps_delay; }; #endif diff --git a/src/playback_thread.cpp b/src/playback_thread.cpp index d4e604a..4f8e9ae 100644 --- a/src/playback_thread.cpp +++ b/src/playback_thread.cpp @@ -22,6 +22,18 @@ Playback::Playback(QObject *parent) : QThread(parent) { cycle_on = 0; cycle_index = 0; frame_num = 0; + _custom_cycle = false; + _custom_cycle_index = 0; + fps_delay = 60; +} + +void Playback::setCustomCycle(bool b) { + _custom_cycle = b; + _custom_cycle_index = 0; +} + +void Playback::setCustomCycleDelay(int delay) { + fps_delay = delay; } void Playback::Play() { @@ -333,13 +345,29 @@ void Playback::run() { } else if(cur.size()>0) { mutex.lock(); ac::in_custom = true; - for(unsigned int i = 0; i < cur.size(); ++i) { - if(i == cur.size()-1) - ac::in_custom = false; - drawFilter(frame, cur[i]); + if(_custom_cycle == false) { + for(unsigned int i = 0; i < cur.size(); ++i) { + if(i == cur.size()-1) + ac::in_custom = false; + drawFilter(frame, cur[i]); + msleep(duration/2); + } + } else { + if(_custom_cycle_index > static_cast(cur.size())) + _custom_cycle_index = 0; + + drawFilter(frame, cur[_custom_cycle_index]); msleep(duration/2); } drawEffects(frame); + static int delay_counter = 0; + ++delay_counter; + if(delay_counter > (fps_delay * static_cast(ac::fps))) { + delay_counter = 0; + ++_custom_cycle_index; + if(_custom_cycle_index > static_cast(cur.size())) + _custom_cycle_index = 0; + } mutex.unlock(); } else { msleep(duration); diff --git a/src/playback_thread.h b/src/playback_thread.h index 93eddf3..8877803 100644 --- a/src/playback_thread.h +++ b/src/playback_thread.h @@ -44,6 +44,9 @@ private: int cycle_on; int cycle_index; int frame_num; + bool _custom_cycle; + int _custom_cycle_index; + int fps_delay; public: Playback(QObject *parent = 0); ~Playback(); @@ -80,6 +83,8 @@ public: void setCycle(int type, int frame_skip, std::vector &val); void setCycle(int type); void setPref(int thread_count, int intense); + void setCustomCycle(bool b); + void setCustomCycleDelay(int delay); signals: void procImage(const QImage image); void stopRecording();