Skip to content

Commit c31fafa

Browse files
committed
Added auto-generation options on play or changes
1 parent bb5a692 commit c31fafa

File tree

12 files changed

+362
-289
lines changed

12 files changed

+362
-289
lines changed

UI/MainWindow.cpp

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
#include "ActionCycle.h"
3434

3535

36-
MainWindow::MainWindow(QWidget *parent) :
37-
QMainWindow(parent),
38-
ui(new Ui::MainWindow),
39-
m_dirty(false),
40-
m_dirtyable(false)
36+
MainWindow::MainWindow(QWidget* _parent)
37+
: QMainWindow(_parent)
38+
, ui(new Ui::MainWindow)
39+
, m_dirty(false)
40+
, m_dirtyable(false)
41+
, m_autoGenerateMode(NO_GENERATION)
4142
{
4243
ui->setupUi(this);
4344

@@ -61,14 +62,15 @@ MainWindow::MainWindow(QWidget *parent) :
6162

6263
m_scene = new NodalScene(ui->nodalView);
6364
m_scene->setBackgroundBrush(Qt::black);
65+
connect(m_scene, &NodalScene::dirtyChanged, this, &MainWindow::setDirty);
6466

6567
ui->nodalView->setScene(m_scene);
6668
ui->nodalView->setZoomLimits(0.1, 5.0);
6769
ui->nodalView->init();
6870
ui->nodalView->show();
69-
connect(ui->nodalView, &NodalView::dirtyChanged, this, &MainWindow::setDirty);
7071

7172
m_signal.setComponent(m_scene->getOutput()->component());
73+
connect(m_scene->getOutput(), &NodeItem::outputChanged, this, &MainWindow::onOutputChanged);
7274

7375
// ===== Edit Menu =====
7476

@@ -139,6 +141,13 @@ MainWindow::MainWindow(QWidget *parent) :
139141
act_loop->setCheckable(true);
140142
connect(act_loop, SIGNAL(triggered(bool)), &m_signal, SLOT(loop(bool)));
141143

144+
m_act_autoGenerateGroup = new QActionGroup(this);
145+
m_act_autoGenerateGroup->addAction("No auto-generation")->setCheckable(true);
146+
m_act_autoGenerateGroup->addAction("Auto-generate on play")->setCheckable(true);
147+
m_act_autoGenerateGroup->addAction("Auto-generate on change")->setCheckable(true);
148+
m_act_autoGenerateGroup->actions()[0]->setChecked(true);
149+
connect(m_act_autoGenerateGroup, SIGNAL(triggered(QAction*)), this, SLOT(changeAutoGenerate(QAction*)));
150+
142151
// ===== File Edit =====
143152

144153
QAction* act_newFile = new QAction("New", this);
@@ -205,6 +214,9 @@ MainWindow::MainWindow(QWidget *parent) :
205214
ui->menuAudio->addAction(act_stop);
206215
ui->menuAudio->addAction(act_loop);
207216

217+
QMenu* menu_autoGenerate = ui->menuAudio->addMenu("Auto-Generation");
218+
menu_autoGenerate->addActions(m_act_autoGenerateGroup->actions());
219+
208220
ui->mainToolBar->clear();
209221
ui->mainToolBar->addAction(act_newFile);
210222
ui->mainToolBar->addAction(act_openFile);
@@ -268,23 +280,23 @@ MainWindow::~MainWindow()
268280
delete ui;
269281
}
270282

271-
void MainWindow::setFileName(QString fileName)
283+
void MainWindow::setFileName(QString _fileName)
272284
{
273-
m_fileName = fileName;
274-
qDebug() << "FileName:" << fileName;
275-
if(fileName.isNull() || fileName.isEmpty())
285+
m_fileName = _fileName;
286+
qDebug() << "FileName:" << _fileName;
287+
if(_fileName.isNull() || _fileName.isEmpty())
276288
{
277289
m_windowTitle = "Untitled";
278290
}
279291
else
280292
{
281-
m_windowTitle = fileName.mid(fileName.lastIndexOf('/') + 1);
293+
m_windowTitle = _fileName.mid(_fileName.lastIndexOf('/') + 1);
282294

283295
// add new filename in recent files
284296
QSettings settings;
285297
QStringList files = settings.value("recentFileList").toStringList();
286-
files.removeAll(fileName);
287-
files.prepend(fileName);
298+
files.removeAll(_fileName);
299+
files.prepend(_fileName);
288300
while (files.size() > maxRecentFile)
289301
files.removeLast();
290302

@@ -297,7 +309,7 @@ void MainWindow::setFileName(QString fileName)
297309
updateRecentFileActions();
298310
}
299311

300-
void MainWindow::closeEvent(QCloseEvent *event)
312+
void MainWindow::closeEvent(QCloseEvent* _event)
301313
{
302314
QMessageBox::StandardButton reply = askSaveChanges("closing");
303315

@@ -310,11 +322,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
310322
QSettings settings;
311323
settings.setValue("geometry", saveGeometry());
312324
settings.setValue("windowState", saveState());
313-
event->accept();
325+
_event->accept();
314326
}
315327
else
316328
{
317-
event->ignore();
329+
_event->ignore();
318330
}
319331
}
320332

@@ -325,15 +337,15 @@ void MainWindow::readSettings()
325337
restoreState(settings.value("windowState").toByteArray());
326338
}
327339

328-
void MainWindow::mousePressEvent(QMouseEvent *event)
340+
void MainWindow::mousePressEvent(QMouseEvent* _event)
329341
{
330342
QWidget* focusedWidget = qApp->focusWidget();
331-
if(focusedWidget != nullptr && focusedWidget != childAt(event->x(), event->y()))
343+
if(focusedWidget != nullptr && focusedWidget != childAt(_event->x(), _event->y()))
332344
{
333345
focusedWidget->clearFocus();
334346
}
335347

336-
QMainWindow::mousePressEvent(event);
348+
QMainWindow::mousePressEvent(_event);
337349
}
338350

339351
void MainWindow::newFile()
@@ -393,7 +405,7 @@ void MainWindow::open()
393405

394406
void MainWindow::openRecent()
395407
{
396-
QAction *action = qobject_cast<QAction *>(sender());
408+
QAction* action = qobject_cast<QAction*>(sender());
397409
if (action)
398410
{
399411
openFile(action->data().toString());
@@ -467,6 +479,11 @@ void MainWindow::quit()
467479

468480
void MainWindow::playPause(int _index)
469481
{
482+
if(m_autoGenerateMode == GENERATE_ON_PLAY)
483+
{
484+
m_signal.generate();
485+
}
486+
470487
switch(_index)
471488
{
472489
case 0:
@@ -490,14 +507,37 @@ void MainWindow::setDirty()
490507
}
491508
}
492509

493-
void MainWindow::changeVolume(int value)
510+
void MainWindow::changeVolume(int _value)
511+
{
512+
m_signal.setVolume(qreal(_value) / 100.0);
513+
}
514+
515+
void MainWindow::changeDuration(qreal _value)
516+
{
517+
m_signal.setDuration(_value);
518+
}
519+
520+
void MainWindow::changeAutoGenerate(QAction* _action)
494521
{
495-
m_signal.setVolume(qreal(value) / 100.0);
522+
int actionIndex = -1;
523+
for(int i = 0; i < m_act_autoGenerateGroup->actions().size(); ++i)
524+
{
525+
if(_action == m_act_autoGenerateGroup->actions()[i])
526+
{
527+
actionIndex = i;
528+
}
529+
}
530+
531+
Q_ASSERT(actionIndex >= 0 && actionIndex < AUTO_GENERATION_MODE_COUNT);
532+
m_autoGenerateMode = static_cast<AutoGenerationMode>(actionIndex);
496533
}
497534

498-
void MainWindow::changeDuration(qreal value)
535+
void MainWindow::onOutputChanged()
499536
{
500-
m_signal.setDuration(value);
537+
if(m_autoGenerateMode == GENERATE_ON_CHANGE)
538+
{
539+
m_signal.generate();
540+
}
501541
}
502542

503543
void MainWindow::createActions()
@@ -510,31 +550,31 @@ void MainWindow::createMenus()
510550

511551
}
512552

513-
void MainWindow::openFile(QString fileName)
553+
void MainWindow::openFile(QString _fileName)
514554
{
515-
if(QFile::exists(fileName))
555+
if(QFile::exists(_fileName))
516556
{
517557
m_dirtyable = false;
518558
qreal duration;
519-
m_scene->load(fileName, duration);
559+
m_scene->load(_fileName, duration);
520560
m_signal.setDuration(duration);
521561
m_dirtyable = true;
522-
setFileName(fileName);
562+
setFileName(_fileName);
523563
}
524564
}
525565

526-
void MainWindow::saveFile(QString fileName)
566+
void MainWindow::saveFile(QString _fileName)
527567
{
528-
setFileName(fileName);
568+
setFileName(_fileName);
529569
m_dirtyable = false;
530-
m_scene->save(fileName, m_signal.duration());
570+
m_scene->save(_fileName, m_signal.duration());
531571
m_dirtyable = true;
532572
}
533573

534-
QMessageBox::StandardButton MainWindow::askSaveChanges(QString action)
574+
QMessageBox::StandardButton MainWindow::askSaveChanges(QString _action)
535575
{
536576
return (!m_dirty) ? QMessageBox::Ignore
537-
: QMessageBox::question(this, "Save your work!", "Some changes in your work are not saved.\nDo you want to save before " + action + "?",
577+
: QMessageBox::question(this, "Save your work!", "Some changes in your work are not saved.\nDo you want to save before " + _action + "?",
538578
QMessageBox::Save|QMessageBox::Ignore|QMessageBox::Cancel);
539579
}
540580

UI/MainWindow.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,25 @@ class MainWindow : public QMainWindow
3838
Q_OBJECT
3939

4040
public:
41-
explicit MainWindow(QWidget *parent = nullptr);
41+
enum AutoGenerationMode
42+
{
43+
NO_GENERATION,
44+
GENERATE_ON_PLAY,
45+
GENERATE_ON_CHANGE,
46+
AUTO_GENERATION_MODE_COUNT // this value if error
47+
};
48+
49+
public:
50+
explicit MainWindow(QWidget* _parent = nullptr);
4251
virtual ~MainWindow() override;
4352

4453
QString fileName() { return m_fileName; }
45-
void setFileName(QString fileName);
54+
void setFileName(QString _fileName);
4655
void readSettings();
4756

4857
protected:
49-
virtual void closeEvent(QCloseEvent* event) override;
50-
virtual void mousePressEvent(QMouseEvent* event) override;
58+
virtual void closeEvent(QCloseEvent* _event) override;
59+
virtual void mousePressEvent(QMouseEvent* _event) override;
5160

5261
public slots:
5362
// actions
@@ -63,15 +72,17 @@ public slots:
6372
void playPause(int _index);
6473
// other
6574
void setDirty();
66-
void changeVolume(int value);
67-
void changeDuration(qreal value);
75+
void changeVolume(int _value);
76+
void changeDuration(qreal _value);
77+
void changeAutoGenerate(QAction* _action);
78+
void onOutputChanged();
6879

6980
private:
7081
void createActions();
7182
void createMenus();
72-
void openFile(QString fileName);
73-
void saveFile(QString fileName);
74-
QMessageBox::StandardButton askSaveChanges(QString action);
83+
void openFile(QString _fileName);
84+
void saveFile(QString _fileName);
85+
QMessageBox::StandardButton askSaveChanges(QString _action);
7586
void updateWindowTitle();
7687
void updateRecentFileActions();
7788

@@ -88,9 +99,11 @@ public slots:
8899
bool m_dirtyable;
89100

90101
QString m_windowTitle;
102+
AutoGenerationMode m_autoGenerateMode;
91103

92104
QAction* recentFileActs[maxRecentFile];
93105
QMenu* menu_openRecentFile;
106+
QActionGroup* m_act_autoGenerateGroup;
94107
};
95108

96109
#endif // MAINWINDOW_H

0 commit comments

Comments
 (0)