-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmainwindow.cpp
executable file
·148 lines (130 loc) · 4.34 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWidgets>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
mainTab = new TabMainWidget(this);
ui->tabWidget->addTab(mainTab, tr("Octatrack slices"));
gridTab = new TabGridWidget(this);
ui->tabWidget->addTab(gridTab, tr("Evenly spaced grid"));
stepsTab = new TabStepsWidget(this);
ui->tabWidget->addTab(stepsTab, tr("Slice per x step of BPM"));
megabreakTab = new TabMegabreakWidget(this);
ui->tabWidget->addTab(megabreakTab, tr("Megabreak"));
// Set action shortcuts.
ui->actionNew->setShortcut(QKeySequence::New);
ui->actionSave->setShortcut(QKeySequence::Save);
ui->openProject->setShortcut(QKeySequence::Open);
setAcceptDrops(true);
readOptions();
clearProject();
}
MainWindow::~MainWindow()
{
delete mainTab;
delete gridTab;
delete megabreakTab;
delete ui;
}
void MainWindow::on_actionSave_triggered()
{
QString destinationFile = QFileDialog::getSaveFileName(this, "Save as...", _defaultPathProjects, "OctaChainer project (*.ocp)");
if (!destinationFile.isEmpty())
{
ProjectSettings ps;
if (ui->tabWidget->currentIndex() == 0)
mainTab->updateCurrentSettings(ps);
else if (ui->tabWidget->currentIndex() == 1)
gridTab->updateCurrentSettings(ps);
else if (ui->tabWidget->currentIndex() == 2)
stepsTab->updateCurrentSettings(ps);
else if (ui->tabWidget->currentIndex() == 3)
megabreakTab->updateCurrentSettings(ps);
ps.saveProjectSettings(destinationFile);
}
}
void MainWindow::on_openProject_triggered()
{
QString fileName = QFileDialog::getOpenFileName(this, "Select project file", _defaultPathProjects, "Octachainer project file (*.ocp)");
if (!fileName.isEmpty())
{
clearProject();
ProjectSettings ps;
ps.loadProjectSettings(fileName);
if (ps.modeName == ps.ModeName_Main)
{
mainTab->configure(ps);
ui->tabWidget->setCurrentIndex(0);
}
else if (ps.modeName == ps.ModeName_Grid)
{
gridTab->configure(ps);
ui->tabWidget->setCurrentIndex(1);
}
else if (ps.modeName == ps.ModeName_Steps)
{
stepsTab->configure(ps);
ui->tabWidget->setCurrentIndex(2);
}
else if (ps.modeName == ps.ModeName_Megabreak)
{
megabreakTab->configure(ps);
ui->tabWidget->setCurrentIndex(3);
}
}
}
void MainWindow::on_actionNew_triggered()
{
clearProject();
}
void MainWindow::clearProject()
{
mainTab->reset();
gridTab->reset();
stepsTab->reset();
megabreakTab->reset();
}
void MainWindow::on_menuAudioPath_triggered()
{
_defaultPathAudio = QFileDialog::getExistingDirectory();
writeOptions();
}
void MainWindow::writeOptions()
{
QFile file("options.txt");
file.open( QIODevice::WriteOnly );
QTextStream stream( &file );
stream << _defaultPathProjects << "\n";
stream << _defaultPathAudio << "\n";
stream << _defaultPathOutput << "\n";
file.close();
}
void MainWindow::readOptions()
{
QFile file("options.txt");
if (file.open (QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream (&file);
_defaultPathProjects = stream.readLine();
_defaultPathAudio = stream.readLine();
_defaultPathOutput = stream.readLine();
file.close();
}
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, "OctaChainer v1.3", "Freeware tool for the Elektron Octatrack and Rytm. Created by Kai Drange of Tic Tic.\n\nVisit www.ticticelectro.com for usage instructions, bug reports or feature requests.\n\nWhile there, feel free to check out our music as well. Facebook or Soundcloud followers, shares etc. are all much appreciated.");
}
void MainWindow::on_actionSet_projects_default_path_triggered()
{
_defaultPathProjects = QFileDialog::getExistingDirectory();
writeOptions();
}
void MainWindow::on_actionSet_output_default_path_triggered()
{
_defaultPathOutput = QFileDialog::getExistingDirectory();
writeOptions();
}