Skip to content

Commit cd8250b

Browse files
committed
Fix #52 Fix #54
1 parent 6a25302 commit cd8250b

File tree

8 files changed

+160
-58
lines changed

8 files changed

+160
-58
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Tabliato 1.3.5
2+
3+
- Bug: #52 ajout d'une option pour les machines très lentes.
4+
- Amélioration: tabliato n'est plus bloqué quand on lance la compilation. La fenêtre reste réactive.
5+
16
## Tabliato 1.3.4
27

38
- New: Affichage d’une infobulle au survol de certains mots-clés du code pour aider l’utilisateur.

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: tabliato
2-
Version: 1.3.4
2+
Version: 1.3.5
33
Section: sound
44
Maintainer: Jean-Romain Roussel <jromain.roussel@gmail.com>
55
Homepage: https://jean-romain.github.io/Tabliato/

header/mainwindow.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class MainWindow : public QMainWindow
3838
//void systemcallFinished(int exit);
3939

4040
void compile();
41+
void scoreCompilerFinished(int);
4142
void midi2audio();
42-
void midi2audioReadyRead();
4343
void midi2audioFinished(int);
4444

4545
void save();
@@ -73,7 +73,8 @@ class MainWindow : public QMainWindow
7373
Ui::MainWindow *ui;
7474
Highlighter *highlighterTab;
7575
QMediaPlayer *music;
76-
QProcess *midi2audioCall;
76+
QProcess *score_compiler;
77+
QProcess *midi_converter;
7778
PdfViewer *pdf;
7879
QVector<qreal> scaleFactors;
7980
QTimer *timer;

src/main.cpp

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include "filedownloader.h"
1515
#include "lilypond.h"
1616

17+
#define EXITOK 0
18+
#define EXITERROR 1
19+
#define TIMEOUT 2
20+
1721
QCoreApplication* createApplication(int &argc, char *argv[])
1822
{
1923
if (argc > 2){
@@ -28,7 +32,7 @@ int main(int argc, char *argv[])
2832

2933
QCoreApplication::setOrganizationName("tabliato");
3034
QCoreApplication::setApplicationName("tabliato");
31-
QCoreApplication::setApplicationVersion("1.3.4");
35+
QCoreApplication::setApplicationVersion("1.3.5");
3236

3337
APPDIR = QApplication::applicationDirPath();
3438
APPPATH = QApplication::applicationFilePath();
@@ -81,6 +85,9 @@ int main(int argc, char *argv[])
8185
QCommandLineOption opt_sf2("soundfont", "Soundfont to generate audio from midi (implies --ogg)", "file.sf2");
8286
parser.addOption(opt_sf2);
8387

88+
QCommandLineOption opt_slow("slow-machine", "Use this option to increase lilypond and timidity timeout");
89+
parser.addOption(opt_slow);
90+
8491
QCommandLineOption opt_output(QStringList() << "o" << "output", "Write output in file or folder FILE. File extension is automatically added", "FILE");
8592
parser.addOption(opt_output);
8693

@@ -95,6 +102,17 @@ int main(int argc, char *argv[])
95102
bool all = parser.isSet(opt_all);
96103
bool sf2 = parser.isSet(opt_sf2);
97104
bool out = parser.isSet(opt_output);
105+
bool slow = parser.isSet(opt_slow);
106+
107+
int lilypond_timeout = 5000;
108+
int timidity_timeout = 10000;
109+
110+
// See issue #52
111+
if (slow)
112+
{
113+
lilypond_timeout *= 10;
114+
timidity_timeout *= 10;
115+
}
98116

99117
const QStringList args = parser.positionalArguments();
100118

@@ -143,15 +161,15 @@ int main(int argc, char *argv[])
143161
if (new_version > current_version)
144162
{
145163
// Si il n'y a pas de fichier c'est que l'utilisateur n'a jamais cliqué sur Non pour l'update
146-
// donc il on demande s'il veut mettre à jour
164+
// donc on demande s'il veut mettre à jour
147165
bool suggest_update = false;
148166
if (!skip_update.exists())
149167
{
150168
suggest_update = true;
151169
}
152170
// Si le fichier existe c'est que l'utilisateur a dit non pour l'update
153-
// mais quand même ca bloque pour l'éternité. Donc si c'est une version encore
154-
// plus grande que celle refusée par l'utilisateur on propose quand mêm
171+
// mais ca bloque pour l'éternité. Donc si c'est une version encore
172+
// plus grande que celle refusée par l'utilisateur on propose quand même
155173
else
156174
{
157175
QVersionNumber skiped_version = QVersionNumber::fromString(File::read(fileName));
@@ -260,6 +278,12 @@ int main(int argc, char *argv[])
260278

261279
File::write(filebasepath + ".ly", tab.lilypond);
262280

281+
if (!QFile(filebasepath + ".ly").exists())
282+
{
283+
QTextStream(stderr) << QString::fromUtf8("Erreur inconnue: le fichier lilypond n'a pas été produit.");
284+
return 1;
285+
}
286+
263287
QStringList arguments;
264288
if (png) arguments.append("--png");
265289
if (pdf) arguments.append("--pdf");
@@ -268,26 +292,42 @@ int main(int argc, char *argv[])
268292

269293
QString command = Lilypond::get_lilypond_command();
270294

271-
if (verbose) qDebug() << command << " " << arguments;
272-
273295
lilypond.start(command, arguments);
274-
lilypond.waitForFinished(5000);
275-
lilypond.readAllStandardOutput();
276296

277-
if(!QFile(filebasepath + ".pdf").exists() && !QFile(filebasepath + ".png").exists())
297+
if (!lilypond.waitForStarted())
298+
{
299+
QTextStream(stderr) << QString::fromUtf8("Erreur inconnue: lilypond n'a pas été démarré.") << Qt::endl;
300+
return 1;
301+
}
302+
303+
if (!lilypond.waitForFinished(lilypond_timeout))
278304
{
279-
//QTextStream(stderr) << lilypond.readAllStandardError() << endl;
280-
QTextStream(stderr) << QString::fromUtf8("Erreur inconnue: le document n'a pas été compilé. Code probablement incorrect.");
305+
lilypond.kill();
306+
lilypond.waitForFinished();
307+
QTextStream(stderr) << QString::fromUtf8("Temps maximum dépassé pour lilypond. La partition n'a pas été produite. Réessayer avec l'option 'Outils' > 'Configuration' > 'CPU faible performance'.") << Qt::endl;
281308
return 1;
282309
}
283310

284-
if(!ly) QFile::remove(filebasepath + ".ly");
285-
if(!midi)
311+
// Check output files
312+
bool pdfExists = QFile(filebasepath + ".pdf").exists();
313+
bool pngExists = QFile(filebasepath + ".png").exists();
314+
315+
if (!pdfExists && !pngExists)
316+
{
317+
QTextStream(stderr) << QString::fromUtf8("Erreur inconnue: le document n'a pas été compilé. Code probablement incorrect.") << Qt::endl;
318+
return 1;
319+
}
320+
321+
if (!ly)
322+
{
323+
QFile::remove(filebasepath + ".ly");
324+
}
325+
326+
if (!midi)
286327
{
287328
QFile::remove(filebasepath + ".mid");
288329
QFile::remove(filebasepath + ".midi");
289330
}
290-
291331
}
292332

293333
// ---------------------------------------
@@ -319,7 +359,15 @@ int main(int argc, char *argv[])
319359
arguments.append("--output-file=" + ofolder + "/" + ofile + AUDIOEXT);
320360

321361
timidity.start(command, arguments);
322-
timidity.waitForFinished(10000);
362+
363+
if (!timidity.waitForFinished(timidity_timeout))
364+
{
365+
timidity.kill();
366+
timidity.waitForFinished();
367+
QTextStream(stderr) << QString::fromUtf8("Erreur: temps maximum dépassé pour la conversion midi > audio. Le rendu audio n'a pas été produit. ´Réessayer avec l'option 'Outils' > 'Configuration' > 'CPU faible performance'.") << Qt::endl;
368+
return 1;
369+
}
370+
323371
timidity.readAllStandardOutput();
324372

325373
return 0;

src/mainwindow.cpp

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
2828

2929
highlighterTab = new Highlighter(ui->melodie_textarea->document());
3030
music = new QMediaPlayer(this);
31-
midi2audioCall = new QProcess(this);
31+
score_compiler = new QProcess(this);
32+
midi_converter = new QProcess(this);
3233
pdf = new PdfViewer();
3334
timer = new QTimer(this);
3435

@@ -53,6 +54,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
5354
// ==== Trigger rendering ====
5455
connect(ui->actionCompile, SIGNAL(triggered()), this, SLOT(compile()));
5556
connect(ui->actionCompile_tool, SIGNAL(triggered()), this, SLOT(compile()));
57+
connect(score_compiler,SIGNAL(finished(int)),this,SLOT(scoreCompilerFinished(int)));
5658

5759
// ==== Various exernal opening ====
5860
connect(ui->actionHelpTabliato, &QAction::triggered, [=]() { QDesktopServices::openUrl(QUrl("https://jean-romain.github.io/tabliato/doc.html")); });
@@ -104,8 +106,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
104106
connect(music, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(updateMusic(QMediaPlayer::State)));
105107

106108
// ==== Music renderer ====
107-
connect(midi2audioCall,SIGNAL(readyReadStandardOutput()),this,SLOT(midi2audioReadyRead()));
108-
connect(midi2audioCall,SIGNAL(finished(int)),this,SLOT(midi2audioFinished(int)));
109+
connect(midi_converter,SIGNAL(finished(int)), this,SLOT(midi2audioFinished(int)));
109110

110111
// ===- Music download soundfonts ====
111112
connect(ui->actionBallone_Burini, &QAction::triggered, [=]() { this->download_soundfonts("BalloneBurini.sf2"); });
@@ -177,38 +178,41 @@ MainWindow::~MainWindow()
177178
delete ui;
178179
delete highlighterTab;
179180
delete music;
180-
delete midi2audioCall;
181+
delete score_compiler;
182+
delete midi_converter;
181183
delete pdf;
182184
}
183185

184186
void MainWindow::compile()
185187
{
186188
if (!currentOpenedFile.isEmpty()) save();
187189

188-
terminal("Compilation");
189-
190190
if (!Lilypond::is_lilypond_installed())
191191
{
192192
QMessageBox::critical(this, "Erreur", "Impossible de trouver le logicel lilypond sur cet machine. Lilypond ne semble pas avoir été installé.");
193193
return;
194194
}
195195

196+
terminal("Compilation...");
197+
198+
199+
ui->actionCompile->setEnabled(false);
200+
ui->actionCompile_tool->setEnabled(false);
201+
196202
Tabulature tab = readMusicFromUI();
197203

198204
try
199205
{
200-
QElapsedTimer timer;
201-
timer.start();
202-
203206
TabliatoProcessor proc(tab);
204207
m_timeline = proc.m_timeline;
205208
//terminal(proc.get_logs());
206-
terminal("Tablature parsée en " + QString::number(timer.elapsed()) + " milliseconds");
207209
}
208210
catch(const std::exception &e)
209211
{
210212
QMessageBox::critical(this, "Erreur", QString(e.what()));
211213
terminal(e.what());
214+
ui->actionCompile->setEnabled(true);
215+
ui->actionCompile_tool->setEnabled(true);
212216
return;
213217
}
214218

@@ -219,28 +223,34 @@ void MainWindow::compile()
219223
QElapsedTimer timer;
220224
timer.start();
221225

222-
QProcess tabliato;
223226
QStringList arguments;
227+
228+
if (ui->actionSlowCPU->isChecked()) arguments.append("--slow-machine"); // See #52
229+
224230
arguments.append("--png");
225231
arguments.append("--pdf");
226232
arguments.append("--midi");
227233
arguments.append("--ly");
228234
arguments.append(dtb);
229235

230-
tabliato.start(APPPATH, arguments);
231-
tabliato.waitForFinished(5000);
236+
score_compiler->start(APPPATH, arguments);
237+
}
238+
239+
240+
void MainWindow::scoreCompilerFinished(int exit)
241+
{
242+
ui->actionCompile->setEnabled(true);
243+
ui->actionCompile_tool->setEnabled(true);
232244

233-
if (tabliato.exitCode() != 0)
245+
if (exit != 0)
234246
{
235-
QString err = tabliato.readAllStandardError();
236-
QMessageBox::critical(this, "Erreur :", err);
247+
QString errorDetails = score_compiler->readAllStandardError();
248+
if (errorDetails.isEmpty())errorDetails = "La partition n'a pas pu être générée pour une raison inconnue.";
249+
QMessageBox::critical(this, "Erreur", errorDetails);
250+
terminal(errorDetails);
237251
return;
238252
}
239253

240-
if (!tabliato.readAllStandardOutput().isEmpty())
241-
terminal(tabliato.readAllStandardOutput());
242-
243-
terminal("Gravure terminée en " + QString::number(timer.elapsed()) + " milliseconds");
244254
updatePreview(OUTPUT + "/output.pdf");
245255
stopMusic();
246256
midi2audio();
@@ -252,22 +262,26 @@ void MainWindow::midi2audio()
252262
ui->play_pushButton->setEnabled(false);
253263

254264
QStringList arguments;
265+
if (ui->actionSlowCPU->isChecked()) arguments.append("--slow-machine"); // See #52
255266
arguments.append("--soundfont=" + SOUNDFONTS + "/" + ui->sf2_combobox->currentText());
256267
arguments.append(OUTPUT + "/output" + MIDIEXT);
257-
midi2audioCall->start(APPPATH, arguments);
258-
}
259-
260-
void MainWindow::midi2audioReadyRead()
261-
{
262-
terminal(midi2audioCall->readAllStandardOutput());
268+
midi_converter->start(APPPATH, arguments);
263269
}
264270

265271
void MainWindow::midi2audioFinished(int exit)
266272
{
267273
exportFiles();
268-
if (exit) QMessageBox::critical(this, "Erreur", "La musique n'a pas pu être générée pour une raison inconnue");
274+
275+
if (exit != 0)
276+
{
277+
QString errorDetails = midi_converter->readAllStandardError();
278+
if (errorDetails.isEmpty())errorDetails = "La musique n'a pas pu être générée pour une raison inconnue.";
279+
QMessageBox::critical(this, "Erreur", errorDetails);
280+
terminal(errorDetails);
281+
}
282+
269283
ui->play_pushButton->setEnabled(true);
270-
QUrl audio = QUrl::fromLocalFile(OUTPUT+ "/output" + AUDIOEXT);
284+
QUrl audio = QUrl::fromLocalFile(OUTPUT + "/output" + AUDIOEXT);
271285
music->setMedia(QMediaContent());
272286
music->setMedia(audio);
273287
music->setPosition(0);
@@ -771,6 +785,7 @@ void MainWindow::writeSettings()
771785
settings.setValue("previewWidth", ui->previewDock->width());
772786
settings.setValue("editorWidth", ui->centralwidget->width());
773787
settings.setValue("editorFontSize", ui->melodie_textarea->font().pointSize());
788+
settings.setValue("slowcpu", ui->actionSlowCPU->isChecked());
774789
settings.setValue("v110", 0);
775790
}
776791

@@ -800,6 +815,8 @@ void MainWindow::readSettings()
800815
ui->centralwidget->resize(settings.value("editorWidth").toInt(), ui->centralwidget->height());
801816
ui->previewDock->resize(settings.value("previewWidth").toInt(), ui->previewDock->height());
802817

818+
ui->actionSlowCPU->setChecked(settings.value("slowcpu").toBool());
819+
803820
QFont font = ui->melodie_textarea->font();
804821
font.setPointSize(settings.value("editorFontSize").toInt());
805822
ui->melodie_textarea->setFont(font);

src/processor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ void TabliatoProcessor::parseMusic()
475475
{
476476
m_tab->set("hasFingering", "true");
477477
}
478+
else if (symbol == "\\tempo")
479+
{
480+
// The tempo changed, we need to update the timeline speed.
481+
}
478482
else if (symbol == "\\relative")
479483
{
480484
throw std::logic_error("\\relative est une commande lilypond non supportée par tabliato");

0 commit comments

Comments
 (0)