-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
178 lines (146 loc) · 6.35 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
gravel - live coding music system -
Copyright (C) 2022-2024 Malte Steiner
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "QtCore/QDebug"
#include "dialogaudiosetup.h"
#include "syncsetup.h"
#include "samplemapper.h"
#include <QMessageBox>
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
qDebug()<< "main "<< QApplication::instance()->thread();
ui->setupUi(this);
highlighter = new class Highlighter(ui->textEdit->document());
// setting up the sound core to run in its own thread
// so the sequencer clock doesn't get interrupted by the gui
// csound itself runs in its own, separate thread
QThread *soundThread = new QThread();
this->soundThread = soundThread;
soundEngine = new SoundEngine();
soundEngine->moveToThread(soundThread);
QObject::connect(soundThread, SIGNAL(started()), soundEngine, SLOT(process()), Qt::QueuedConnection);
soundThread->start(QThread::TimeCriticalPriority);
csoundParser = new CsoundParser();
QObject::connect(csoundParser,SIGNAL(display(QString)),ui->console,SLOT(append(QString)));
parser = new Parser();
QObject::connect(ui->textEdit, &Coder::evaluation, this, &MainWindow::evaluate);
QObject::connect(parser,SIGNAL(display(QString)),ui->console,SLOT(append(QString)));
QObject::connect(soundEngine,SIGNAL(display(QString)),ui->console,SLOT(append(QString)));
QObject::connect(soundEngine,SIGNAL(parseCsound(QString)),csoundParser,SLOT(parseCsound(QString)));
QObject::connect(csoundParser,SIGNAL(setInstrumentDefinitions(QMap<QString,InstrumentDefinition>)),parser,SLOT(setInstrumentDefinitions(QMap<QString,InstrumentDefinition>)));
QObject::connect(csoundParser,SIGNAL(setInstrumentDefinitions(QMap<QString,InstrumentDefinition>)),soundEngine,SLOT(setInstrumentDefinitions(QMap<QString,InstrumentDefinition>)));
QObject::connect(parser,SIGNAL(status(QString)),statusBar(),SLOT(showMessage(QString)));
QObject::connect(parser,SIGNAL(setBPM(int)),soundEngine,SLOT(setBPM(int)));
QObject::connect(this, SIGNAL(stop()),soundEngine,SLOT(stop()));
}
MainWindow::~MainWindow()
{
this->soundThread->quit();
this->soundThread->wait();
delete soundThread;
delete soundEngine;
delete ui;
}
void MainWindow::evaluate() {
QString code = ui->textEdit->textCursor().selectedText();
//ui->console->clear();
ui->console->append("parsing:");
ui->console->append(code);
/*
QList<int> seq = parser->parseCode(code);
soundEngine->setPattern(seq);
QStringList listString;
QString outString;
for(int i =0; i < seq.length(); i++)
{
listString << QString::number(seq.at(i));
}
outString = listString.join("\n");
ui->console->append(outString);
*/
parser->tracks.swap(soundEngine->parsedTracks); // get the current track state from the soundengine
parser->parseCode(code);
soundEngine->parsedTracks.swap(parser->tracks);
soundEngine->tempTracks = soundEngine->parsedTracks;
soundEngine->tempTracks.detach(); // force deep copy
soundEngine->hasParsedTracks = true;
}
void MainWindow::on_actionAbout_gravel_triggered()
{
QMessageBox::about(this, tr("gravel"),
tr("<h2>g<span style='color:#666;'>rave</span>l</h2><h3>live coding music system</h3>\
<p>© 2022 - 2025 by Malte Steiner and<br>Tina Mariane Krogh Madsen</p>\
<p>see also <a href='https://www.block4.com'>https://www.block4.com</a></p>\
<p>gravel is free open source software distributed under GPL3 license</p>\
<p>it uses QT 6.4.1 which can be obtained at <a href='https://www.qt.io'>https://www.qt.io</a></p>\
<p>the audio synthesis is implemented with <a href='https://csound.com'>Csound</a></p>\
<p>version 0.31 beta use on your own risk</p>"));
}
void MainWindow::on_actionAudio_setup_triggered()
{
DialogAudioSetup *dialogSetup = new DialogAudioSetup(this);
QObject::connect(dialogSetup,SIGNAL(audioSet()),soundEngine,SLOT(audioSet()));
dialogSetup->show();
}
void MainWindow::on_actionSync_setup_triggered()
{
Syncsetup *syncSetup = new Syncsetup(this);
QObject::connect(syncSetup,SIGNAL(syncSend(int)),soundEngine,SLOT(syncSend(int)));
QObject::connect(syncSetup,SIGNAL(syncListen(int)),soundEngine,SLOT(syncListen(int)));
QObject::connect(syncSetup,SIGNAL(syncStop()),soundEngine,SLOT(syncStop()));
syncSetup->show();
}
void MainWindow::on_actionSample_Mapper_triggered()
{
SampleMapper *sampleMapper = new SampleMapper(this);
QObject::connect(sampleMapper,SIGNAL(activateMap(SampleListModel*)),soundEngine,SLOT(activateMap(SampleListModel*)));
sampleMapper->show();
}
void MainWindow::on_actionsave_code_triggered()
{
QString fileName = QFileDialog::getSaveFileName(this,tr("Save Code"),QDir::homePath(), tr("Text files (*.txt)"));
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&file);
out << ui->textEdit->toPlainText();
file.close();
}
void MainWindow::on_actionopen_code_triggered()
{
loadCode(false);
}
void MainWindow::on_actionmerge_code_triggered()
{
loadCode(true);
}
void MainWindow::loadCode(bool merge){
QString fileName = QFileDialog::getOpenFileName(this,tr("Load Code"),QDir::homePath(), tr("Text files (*.txt)"));
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
QString code = in.readAll();
if (!merge) ui->textEdit->clear();
ui->textEdit->append(code);
file.close();
}
void MainWindow::closeEvent(QCloseEvent *event){
emit stop();
}