/
musescore.cpp
8496 lines (7452 loc) · 315 KB
/
musescore.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2016 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "musescore.h"
#include <fenv.h>
#include <QStyleFactory>
#include <QStandardPaths>
#include <QDir>
#include "config.h"
#include "cloud/loginmanager.h"
#include "cloud/uploadscoredialog.h"
#include "musescoredialogs.h"
#include "scoreview.h"
#include "libmscore/style.h"
#include "libmscore/score.h"
#include "instrdialog.h"
#include "preferences.h"
#include "prefsdialog.h"
#include "realizeharmonydialog.h"
#include "icons.h"
#include "libmscore/xml.h"
#include "seq.h"
#include "libmscore/tempo.h"
#include "libmscore/sym.h"
#include "pagesettings.h"
#include "debugger/debugger.h"
#include "editstyle.h"
#include "playpanel.h"
#include "libmscore/page.h"
#include "mixer/mixer.h"
#include "selectionwindow.h"
#include "palette.h"
#include "palette/palettemodel.h"
#include "palette/palettewidget.h"
#include "palette/paletteworkspace.h"
#include "libmscore/part.h"
#include "libmscore/drumset.h"
#include "libmscore/instrtemplate.h"
#include "libmscore/scoreOrder.h"
#include "libmscore/note.h"
#include "libmscore/staff.h"
#include "libmscore/harmony.h"
#include "zoombox.h"
#include "libmscore/sig.h"
#include "libmscore/undo.h"
#include "synthcontrol.h"
#include "pianoroll/pianoroll.h"
#include "drumroll.h"
#include "scoretab.h"
#include "timedialog.h"
#include "keyedit.h"
#include "harmonyedit.h"
#include "navigator.h"
#include "newwizard.h"
#include "timeline.h"
#include "importmidi_ui/importmidi_panel.h"
#include "importexport/midiimport/importmidi_instrument.h"
#include "importexport/midiimport/importmidi_operations.h"
#include "migration/scoremigrationdialog.h"
#include "scorecmp/scorecmp.h"
#include "script/recorderwidget.h"
#include "libmscore/scorediff.h"
#include "libmscore/chord.h"
#include "libmscore/segment.h"
#include "editraster.h"
#include "pianotools.h"
#include "mediadialog.h"
#include "workspace.h"
#include "workspacecombobox.h"
#include "selectdialog.h"
#include "selectnotedialog.h"
#include "transposedialog.h"
#include "metaedit.h"
#include "inspector/inspector.h"
#ifdef OMR
#include "omrpanel.h"
#endif
#include "shortcut.h"
#ifdef SCRIPT_INTERFACE
#include "plugin/pluginCreator.h"
#include "plugin/pluginManager.h"
#include "plugin/qmlpluginengine.h"
#endif
#include "helpBrowser.h"
#include "drumtools.h"
#include "editstafftype.h"
#include "texttools.h"
#include "textpalette.h"
#include "resourceManager.h"
#include "scoreaccessibility.h"
#include "startupWizard.h"
#include "tourhandler.h"
#include "mssplashscreen.h"
#include "libmscore/mscore.h"
#include "libmscore/system.h"
#include "libmscore/measure.h"
#include "libmscore/chordlist.h"
#include "libmscore/volta.h"
#include "libmscore/lasso.h"
#include "libmscore/excerpt.h"
#include "libmscore/synthesizerstate.h"
#include "libmscore/utils.h"
#include "libmscore/icon.h"
#include "audio/drivers/driver.h"
#include "effects/zita1/zita.h"
#include "effects/compressor/compressor.h"
#include "effects/noeffect/noeffect.h"
#include "audio/midi/synthesizer.h"
#include "audio/midi/synthesizergui.h"
#include "audio/midi/msynthesizer.h"
#include "audio/midi/event.h"
#include "audio/midi/fluid/fluid.h"
#include "plugin/qmlplugin.h"
#include "accessibletoolbutton.h"
#include "toolbuttonmenu.h"
#include "searchComboBox.h"
#include "startcenter.h"
#include "help.h"
#include "awl/aslider.h"
#include "extension.h"
#include "thirdparty/qzip/qzipreader_p.h"
#include "sparkle/autoUpdater.h"
#if defined(WIN_SPARKLE_ENABLED)
#include "sparkle/winSparkleAutoUpdater.h"
#elif defined(MAC_SPARKLE_ENABLED)
#include "sparkle/sparkleAutoUpdater.h"
#endif
#ifdef USE_LAME
#include "audio/exports/exportmp3.h"
#endif
#ifdef Q_OS_MAC
#include "macos/cocoabridge.h"
#endif
#ifdef AEOLUS
extern Ms::Synthesizer* createAeolus();
#endif
#ifdef ZERBERUS
extern Ms::Synthesizer* createZerberus();
#endif
#ifdef QT_NO_DEBUG
Q_LOGGING_CATEGORY(undoRedo, "undoRedo", QtCriticalMsg);
#else
Q_LOGGING_CATEGORY(undoRedo, "undoRedo", QtCriticalMsg);
// Q_LOGGING_CATEGORY(undoRedo, "undoRedo");
#endif
#ifdef BUILD_CRASH_REPORTER
#include "thirdparty/libcrashreporter-qt/src/libcrashreporter-handler/Handler.h"
#endif
#ifndef TELEMETRY_DISABLED
#include "actioneventobserver.h"
#include "widgets/telemetrypermissiondialog.h"
#endif
#include "telemetrymanager.h"
namespace Ms {
MuseScore* mscore;
MasterSynthesizer* synti;
bool enableExperimental = false;
QString dataPath;
QString iconPath;
bool converterMode = false;
static bool rawDiffMode = false;
static bool diffMode = false;
static bool scriptTestMode = false;
bool processJob = false;
bool externalIcons = false;
bool pluginMode = false;
static bool startWithNewScore = false;
double guiScaling = 0.0;
static double userDPI = 0.0;
int trimMargin = -1;
bool noWebView = false;
bool exportScoreParts = false;
bool saveScoreParts = false;
bool ignoreWarnings = false;
bool cliSaveOnline = false;
bool exportScoreMedia = false;
bool exportScoreMeta = false;
bool exportScoreMp3 = false;
bool exportScorePartsPdf = false;
bool needUpdateSource = false;
static bool exportTransposedScore = false;
static QString transposeExportOptions;
static QString highlightConfigPath;
QString mscoreGlobalShare;
static QString outFileName;
static QString jsonFileName;
static QString audioDriver;
static QString pluginName;
static QString styleFile;
static QString extensionName;
static bool scoresOnCommandline { false };
static QList<QTranslator*> translatorList;
bool useFactorySettings = false;
bool deletePreferences = false;
QString styleName;
QString revision;
QErrorMessage* errorMessage;
const char* voiceActions[] = { "voice-1", "voice-2", "voice-3", "voice-4" };
bool mscoreFirstStart = false;
const std::list<const char*> MuseScore::_allNoteInputMenuEntries {
"note-input",
"pad-note-1024",
"pad-note-512",
"pad-note-256",
"pad-note-128",
"pad-note-64",
"pad-note-32",
"pad-note-16",
"pad-note-8",
"pad-note-4",
"pad-note-2",
"pad-note-1",
"note-breve",
"note-longa",
"pad-dot",
"pad-dotdot",
"pad-dot3",
"pad-dot4",
"tie",
"",
"pad-rest",
"",
"sharp2",
"sharp",
"nat",
"flat",
"flat2",
"flip",
"",
"voice-1",
"voice-2",
"voice-3",
"voice-4"
};
const std::list<const char*> MuseScore::_allFileOperationEntries {
"file-new",
"file-open",
"file-save",
"file-save-online",
"print",
"undo",
"redo"
};
const std::list<const char*> MuseScore::_allPlaybackControlEntries {
#ifdef HAS_MIDI
"midi-on",
"",
#endif
"rewind",
"play",
"loop",
"",
"repeat",
"pan",
"metronome",
"countin"
};
extern TextPalette* textPalette;
static const char* saveOnlineMenuItem = "file-save-online";
#ifdef BUILD_TELEMETRY_MODULE
std::unique_ptr<TelemetryManager> TelemetryManager::mgr;
#endif
//---------------------------------------------------------
// cmdInsertMeasure
//---------------------------------------------------------
void MuseScore::cmdInsertMeasures()
{
if (cs) {
if (cs->selection().isNone() && !cs->selection().findMeasure()) {
QMessageBox::warning(0, "MuseScore",
tr("No measure selected:\n" "Please select a measure and try again"));
}
else {
insertMeasuresDialog = new InsertMeasuresDialog;
insertMeasuresDialog->show();
}
}
}
//---------------------------------------------------------
// getSharePath
//---------------------------------------------------------
QString getSharePath()
{
#ifdef Q_OS_WIN
QDir dir(QCoreApplication::applicationDirPath() + QString("/../" INSTALL_NAME));
return dir.absolutePath() + "/";
#else
#ifdef Q_OS_MAC
QDir dir(QCoreApplication::applicationDirPath() + QString("/../Resources"));
return dir.absolutePath() + "/";
#else
// Try relative path (needed for portable AppImage and non-standard installations)
QDir dir(QCoreApplication::applicationDirPath() + QString("/../share/" INSTALL_NAME));
if (dir.exists())
return dir.absolutePath() + "/";
// Otherwise fall back to default location (e.g. if binary has moved relative to share)
return QString( INSTPREFIX "/share/" INSTALL_NAME);
#endif
#endif
}
//---------------------------------------------------------
// localeName
//---------------------------------------------------------
QString localeName()
{
if (useFactorySettings)
return "system";
return preferences.getString(PREF_UI_APP_LANGUAGE);
}
//---------------------------------------------------------
// printVersion
//---------------------------------------------------------
static void printVersion(const char* prog)
{
if (MuseScore::unstable())
fprintf(stderr, "%s: Music Score Editor\nUnstable Prerelease for Version %s; Build %s\n",
prog, VERSION, qPrintable(revision));
else
fprintf(stderr, "%s: Music Score Editor; Version %s; Build %s\n", prog, VERSION, qPrintable(revision));
}
static const int RECENT_LIST_SIZE = 20;
//---------------------------------------------------------
// closeEvent
//---------------------------------------------------------
void MuseScore::closeEvent(QCloseEvent* ev)
{
unloadPlugins();
QList<MasterScore*> removeList;
for (MasterScore* score : scoreList) {
// Prompt the user to save the score if it's "dirty" (has unsaved changes) or if it's newly created but non-empty.
if (checkDirty(score)) {
// The user has canceled out entirely, so ignore the close event.
ev->ignore();
return;
}
// If the score is still flagged as newly created at this point, it means that either it's empty or the user has just
// chosen to discard it, so we need to remove it from the list of scores to be saved to the session file.
if (score->created())
removeList.append(score);
}
// remove all new created/not save score so they are
// note saved as session data
for (MasterScore* score : removeList) {
scoreList.removeAll(score);
scoreWasShown.remove(score);
}
writeSessionFile(true);
for (MasterScore* score : scoreList) {
if (!score->tmpName().isEmpty()) {
QFile f(score->tmpName());
f.remove();
}
}
writeSettings();
ev->accept();
if (Shortcut::dirty)
Shortcut::save();
this->deleteLater(); //this is necessary on windows http://musescore.org/node/16713
qApp->quit();
}
void updateExternalValuesFromPreferences() {
// set values in libmscore
MScore::bgColor = preferences.getColor(PREF_UI_CANVAS_BG_COLOR);
MScore::dropColor = preferences.getColor(PREF_UI_SCORE_NOTE_DROPCOLOR);
MScore::defaultColor = preferences.getColor(PREF_UI_SCORE_DEFAULTCOLOR);
MScore::defaultPlayDuration = preferences.getInt(PREF_SCORE_NOTE_DEFAULTPLAYDURATION);
MScore::panPlayback = preferences.getBool(PREF_APP_PLAYBACK_PANPLAYBACK);
MScore::harmonyPlayDisableCompatibility = preferences.getBool(PREF_SCORE_HARMONY_PLAY_DISABLE_COMPATIBILITY);
MScore::harmonyPlayDisableNew = preferences.getBool(PREF_SCORE_HARMONY_PLAY_DISABLE_NEW);
MScore::playRepeats = preferences.getBool(PREF_APP_PLAYBACK_PLAYREPEATS);
MScore::playbackSpeedIncrement = preferences.getInt(PREF_APP_PLAYBACK_SPEEDINCREMENT);
MScore::warnPitchRange = preferences.getBool(PREF_SCORE_NOTE_WARNPITCHRANGE);
MScore::pedalEventsMinTicks = preferences.getInt(PREF_IO_MIDI_PEDAL_EVENTS_MIN_TICKS);
MScore::layoutBreakColor = preferences.getColor(PREF_UI_SCORE_LAYOUTBREAKCOLOR);
MScore::frameMarginColor = preferences.getColor(PREF_UI_SCORE_FRAMEMARGINCOLOR);
MScore::setVerticalOrientation(preferences.getBool(PREF_UI_CANVAS_SCROLL_VERTICALORIENTATION));
MScore::selectColor[0] = preferences.getColor(PREF_UI_SCORE_VOICE1_COLOR);
MScore::selectColor[1] = preferences.getColor(PREF_UI_SCORE_VOICE2_COLOR);
MScore::selectColor[2] = preferences.getColor(PREF_UI_SCORE_VOICE3_COLOR);
MScore::selectColor[3] = preferences.getColor(PREF_UI_SCORE_VOICE4_COLOR);
MScore::setHRaster(preferences.getInt(PREF_UI_APP_RASTER_HORIZONTAL));
MScore::setVRaster(preferences.getInt(PREF_UI_APP_RASTER_VERTICAL));
MScore::setNudgeStep(.1); // cursor key (default 0.1)
MScore::setNudgeStep10(1.0); // Ctrl + cursor key (default 1.0)
MScore::setNudgeStep50(0.01); // Alt + cursor key (default 0.01)
if (!preferences.getBool(PREF_APP_STARTUP_FIRSTSTART)) {
//Create directories if they are missing
QDir dir;
dir.mkpath(preferences.getString(PREF_APP_PATHS_MYSCORES));
dir.mkpath(preferences.getString(PREF_APP_PATHS_MYSTYLES));
dir.mkpath(preferences.getString(PREF_APP_PATHS_MYIMAGES));
dir.mkpath(preferences.getString(PREF_APP_PATHS_MYTEMPLATES));
dir.mkpath(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS));
dir.mkpath(preferences.getString(PREF_APP_PATHS_MYPLUGINS));
foreach (QString path, preferences.getString(PREF_APP_PATHS_MYSOUNDFONTS).split(";"))
dir.mkpath(path);
}
}
//---------------------------------------------------------
// preferencesChanged
//---------------------------------------------------------
void MuseScore::preferencesChanged(bool fromWorkspace, bool changeUI)
{
updateExternalValuesFromPreferences();
getAction("repeat")->setChecked(MScore::playRepeats);
getAction("pan")->setChecked(MScore::panPlayback);
getAction("follow")->setChecked(preferences.getBool(PREF_APP_PLAYBACK_FOLLOWSONG));
getAction("midi-on")->setChecked(preferences.getBool(PREF_IO_MIDI_ENABLEINPUT));
getAction("toggle-statusbar")->setChecked(preferences.getBool(PREF_UI_APP_SHOWSTATUSBAR));
getAction("show-tours")->setChecked(preferences.getBool(PREF_UI_APP_STARTUP_SHOWTOURS));
_statusBar->setVisible(preferences.getBool(PREF_UI_APP_SHOWSTATUSBAR));
if (!cs)
zoomBox->resetToDefaultLogicalZoom();
if (playPanel)
playPanel->setSpeedIncrement(preferences.getInt(PREF_APP_PLAYBACK_SPEEDINCREMENT));
if (changeUI)
MuseScore::updateUiStyleAndTheme(); // this is a slow operation
updateIcons();
QString fgWallpaper = preferences.getString(PREF_UI_CANVAS_FG_WALLPAPER);
for (int i = 0; i < tab1->count(); ++i) {
ScoreView* canvas = tab1->view(i);
if (canvas == 0)
continue;
if (preferences.getBool(PREF_UI_CANVAS_BG_USECOLOR))
canvas->setBackground(preferences.getColor(PREF_UI_CANVAS_BG_COLOR));
else {
QPixmap* pm = new QPixmap(preferences.getString(PREF_UI_CANVAS_BG_WALLPAPER));
canvas->setBackground(pm);
}
if (preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR))
canvas->setForeground(preferences.getColor(PREF_UI_CANVAS_FG_COLOR));
else {
QPixmap* pm = new QPixmap(fgWallpaper);
if (pm == 0 || pm->isNull())
qDebug("no valid pixmap %s", fgWallpaper.toLatin1().data());
canvas->setForeground(pm);
}
}
if (tab2) {
for (int i = 0; i < tab2->count(); ++i) {
ScoreView* canvas = tab2->view(i);
if (canvas == 0)
continue;
if (preferences.getBool(PREF_UI_CANVAS_BG_USECOLOR))
canvas->setBackground(preferences.getColor(PREF_UI_CANVAS_BG_COLOR));
else {
QPixmap* pm = new QPixmap(preferences.getString(PREF_UI_CANVAS_BG_WALLPAPER));
canvas->setBackground(pm);
}
if (preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR))
canvas->setForeground(preferences.getColor(PREF_UI_CANVAS_FG_COLOR));
else {
QPixmap* pm = new QPixmap(fgWallpaper);
if (pm == 0 || pm->isNull())
qDebug("no valid pixmap %s", fgWallpaper.toLatin1().data());
canvas->setForeground(pm);
}
}
}
transportTools->setEnabled(!noSeq && seq && seq->isRunning());
playId->setEnabled(!noSeq && seq && seq->isRunning());
// change workspace
if (!fromWorkspace && preferences.getString(PREF_APP_WORKSPACE) != WorkspacesManager::currentWorkspace()->name()) {
Workspace* workspace = WorkspacesManager::findByName(preferences.getString(PREF_APP_WORKSPACE));
if (workspace)
mscore->changeWorkspace(workspace);
}
delete newWizard;
newWizard = 0;
reloadInstrumentTemplates();
updateInstrumentDialog();
if (seq)
seq->preferencesChanged();
}
//---------------------------------------------------------
// populateNoteInputMenu
//---------------------------------------------------------
void MuseScore::populateNoteInputMenu()
{
entryTools->clear();
for (const auto s : _noteInputMenuEntries) {
if (!*s)
entryTools->addSeparator();
else {
QAction* a = getAction(s);
QWidget* w;
if (strcmp(s, "note-input") == 0) {
//-----------------------------------------------------------------
// Note Entry Modes menu
// ToolButtonMenu to swap between Note Entry Methods
//-----------------------------------------------------------------
QActionGroup* noteEntryMethods = new QActionGroup(entryTools);
noteEntryMethods->addAction(getAction("note-input-steptime"));
noteEntryMethods->addAction(getAction("note-input-repitch"));
noteEntryMethods->addAction(getAction("note-input-rhythm"));
noteEntryMethods->addAction(getAction("note-input-realtime-auto"));
noteEntryMethods->addAction(getAction("note-input-realtime-manual"));
noteEntryMethods->addAction(getAction("note-input-timewise"));
connect(noteEntryMethods, SIGNAL(triggered(QAction*)), this, SLOT(cmd(QAction*)));
w = new ToolButtonMenu(tr("Note Entry Methods"),
getAction("note-input"),
noteEntryMethods,
this,
false);
w->setObjectName("note-entry-methods");
}
else if (strncmp(s, "voice-", 6) == 0) {
AccessibleToolButton* tb = new AccessibleToolButton(this, a);
tb->setObjectName("voice");
tb->setFocusPolicy(Qt::ClickFocus);
tb->setToolButtonStyle(Qt::ToolButtonTextOnly);
tb->setProperty((QString("voice%1").arg(atoi(s+6))).toUtf8().data(), true);
QPalette p(tb->palette());
int i = atoi(s+6) - 1;
p.setColor(QPalette::Base, MScore::selectColor[i]);
tb->setPalette(p);
a->setCheckable(true);
// tb->setDefaultAction(a);
w = tb;
}
else {
w = new AccessibleToolButton(entryTools, a);
w->setObjectName(s);
}
entryTools->addWidget(w);
}
}
}
//---------------------------------------------------------
// notifyElementDraggedToScoreView
//---------------------------------------------------------
void MuseScore::notifyElementDraggedToScoreView()
{
if (paletteWidget)
paletteWidget->notifyElementDraggedToScoreView();
}
//---------------------------------------------------------
// onLongOperationFinished
//---------------------------------------------------------
void MuseScore::onLongOperationFinished()
{
infoMsgBox->accept();
}
//---------------------------------------------------------
// moveControlCursor
//---------------------------------------------------------
void MuseScore::moveControlCursor()
{
if (!cv)
return;
cv->moveControlCursorNearCursor();
}
//---------------------------------------------------------
// importExtension
//---------------------------------------------------------
bool MuseScore::importExtension(QString path)
{
MQZipReader zipFile(path);
// compute total unzipped size
qint64 totalZipSize = 0;
for (auto fi : zipFile.fileInfoList())
totalZipSize += fi.size;
// check if extension path is writable and has enough space
const QString extensionsPath = preferences.getString(PREF_APP_PATHS_MYEXTENSIONS);
const QFileInfo extensionsDirInfo(extensionsPath);
if (!extensionsDirInfo.isWritable()) {
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("Cannot import extension on read-only storage: %1").arg(extensionsPath)); // TODO: on read-only *directory*
return false;
}
QStorageInfo storage = QStorageInfo(extensionsPath);
if (totalZipSize >= storage.bytesAvailable()) {
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("Cannot import extension: storage %1 is full").arg(storage.displayName()));
return false;
}
// Check structure of the extension
bool hasMetadata = false;
bool hasAlienDirectory = false;
bool hasAlienFiles = false;
QSet<QString> acceptableFolders = { Extension::sfzsDir, Extension::soundfontsDir, Extension::templatesDir, Extension::instrumentsDir, Extension::workspacesDir };
for (auto fi : zipFile.fileInfoList()) {
if (fi.filePath == "metadata.json")
hasMetadata = true;
else {
// get folders
auto fpath = QDir::cleanPath(fi.filePath);
QStringList folders(fpath);
while ((fpath = QFileInfo(fpath).path()).length() < folders.last().length())
folders << fpath;
if (folders.size() < 2) {
hasAlienFiles = true; // in root dir
break;
}
QString rootDir = folders.at(folders.size() - 2);
if (!acceptableFolders.contains(rootDir)) {
hasAlienDirectory = true; // in root dir
break;
}
}
}
if (!hasMetadata) {
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("Corrupted extension: no metadata.json"));
return false;
}
if (hasAlienDirectory) {
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("Corrupted extension: unsupported directories in root directory"));
return false;
}
if (hasAlienFiles) {
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("Corrupted extension: unsupported files in root directory"));
return false;
}
zipFile.close();
MQZipReader zipFile2(path);
// get extension id from metadata.json
QByteArray mdba = zipFile2.fileData("metadata.json");
zipFile2.close();
QJsonDocument loadDoc = QJsonDocument::fromJson(mdba);
QJsonObject mdObject = loadDoc.object();
QString extensionId = mdObject["id"].toString();
QString version = mdObject["version"].toString();
if (extensionId.isEmpty() || version.isEmpty()) {
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("Corrupted extension: corrupted metadata.json"));
return false;
}
// Check if extension is already installed, ask for uninstall
QDir dir(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS));
auto dirList = dir.entryList(QStringList(extensionId), QDir::Dirs | QDir::NoDotAndDotDot);
bool newerVersion = false;
if (dirList.contains(extensionId)) {
QString extDirName = QString("%1/%2").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId);
QDir extDir(extDirName);
auto versionDirList = extDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
if (versionDirList.size() > 0) {
// potentially other versions
// is there a more recent version?
for (auto versionDir : versionDirList) {
if (compareVersion(version, versionDir)) {
qDebug() << "There is a newer version. We don't install";
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("A newer version is already installed"));
newerVersion = true;
return false;
}
}
}
if (!newerVersion) {
qDebug() << "found already install extension without newer version: deleting it";
QDir d(QString("%1/%2").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId));
if (!d.removeRecursively()) {
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("Error while deleting previous version of the extension: %1").arg(extensionId));
return false;
}
}
}
//setup the message box
infoMsgBox = new QMessageBox();
infoMsgBox->setWindowModality(Qt::ApplicationModal);
infoMsgBox->setWindowFlags(Qt::WindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint));
infoMsgBox->setTextFormat(Qt::RichText);
infoMsgBox->setMinimumSize(300, 100);
infoMsgBox->setMaximumSize(300, 100);
infoMsgBox->setStandardButtons({});
infoMsgBox->setText(QString("<p align='center'>") + tr("Please wait; unpacking extension…") + QString("</p>"));
//setup async run of long operations
QFutureWatcher<bool> futureWatcherUnzip;
connect(&futureWatcherUnzip, SIGNAL(finished()), this, SLOT(onLongOperationFinished()));
MQZipReader* zipFile3 = new MQZipReader(path);
// Unzip the extension asynchronously
QFuture<bool> futureUnzip = QtConcurrent::run(zipFile3, &MQZipReader::extractAll, QString("%1/%2/%3").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version));
futureWatcherUnzip.setFuture(futureUnzip);
if (!MScore::noGui)
infoMsgBox->exec();
bool unzipResult = futureUnzip.result();
zipFile3->close();
delete zipFile3;
zipFile3 = nullptr;
if (!unzipResult) {
if (!MScore::noGui)
QMessageBox::critical(mscore, QWidget::tr("Import Extension File"), QWidget::tr("Unable to extract files from the extension"));
return false;
}
delete newWizard;
newWizard = 0;
mscore->reloadInstrumentTemplates();
mscore->updateInstrumentDialog();
auto loadSoundFontAsync = [&]() {
// After install: add sfz to zerberus
QDir sfzDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::sfzsDir));
if (sfzDir.exists()) {
// get all sfz files
QDirIterator it(sfzDir.absolutePath(), QStringList("*.sfz"), QDir::Files, QDirIterator::Subdirectories);
Synthesizer* s = synti->synthesizer("Zerberus");
QStringList sfzs;
while (it.hasNext()) {
it.next();
sfzs.append(it.fileName());
}
sfzs.sort();
for (int sfzNum = 0; sfzNum < sfzs.size(); ++sfzNum)
s->addSoundFont(sfzs[sfzNum]);
if (!sfzs.isEmpty())
synti->storeState();
s->gui()->synthesizerChanged();
}
// After install: add soundfont to fluid
QDir sfDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::soundfontsDir));
if (sfDir.exists()) {
// get all soundfont files
QStringList filters("*.sf2");
filters.append("*.sf3");
QDirIterator it(sfDir.absolutePath(), filters, QDir::Files, QDirIterator::Subdirectories);
QStringList sfs;
while (it.hasNext()) {
it.next();
sfs.append(it.fileInfo().absoluteFilePath());
}
sfs.sort();
Synthesizer* s = synti->synthesizer("Fluid");
for (auto sf : sfs) {
s->addSoundFont(sf);
}
if (!sfs.isEmpty())
synti->storeState();
s->gui()->synthesizerChanged();
}
};
if (!enableExperimental) {
//load soundfonts async
QFuture<void> futureLoadSFs = QtConcurrent::run(loadSoundFontAsync);
QFutureWatcher<void> futureWatcherLoadSFs;
futureWatcherLoadSFs.setFuture(futureLoadSFs);
connect(&futureWatcherLoadSFs, SIGNAL(finished()), this, SLOT(onLongOperationFinished()));
infoMsgBox->setText(QString("<p align='center'>") + tr("Please wait; loading SoundFonts…") + QString("</p>"));
if (!MScore::noGui)
infoMsgBox->exec();
else
futureLoadSFs.waitForFinished();
}
// after install: refresh workspaces if needed
QDir workspacesDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::workspacesDir));
if (workspacesDir.exists() && !MScore::noGui) {
auto wsList = workspacesDir.entryInfoList(QStringList("*.workspace"), QDir::Files);
if (!wsList.isEmpty()) {
WorkspacesManager::refreshWorkspaces();
emit workspacesChanged();
changeWorkspace(WorkspacesManager::workspaces().last());
}
}
return true;
}
//---------------------------------------------------------
// uninstallExtension
//---------------------------------------------------------
bool MuseScore::uninstallExtension(QString extensionId)
{
QString version = Extension::getLatestVersion(extensionId);
// Before install: remove sfz from zerberus
QDir sfzDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::sfzsDir));
if (sfzDir.exists()) {
// get all sfz files
QDirIterator it(sfzDir.absolutePath(), QStringList("*.sfz"), QDir::Files, QDirIterator::Subdirectories);
Synthesizer* s = synti->synthesizer("Zerberus");
bool found = it.hasNext();
while (it.hasNext()) {
it.next();
s->removeSoundFont(it.fileInfo().absoluteFilePath());
}
if (found)
synti->storeState();
s->gui()->synthesizerChanged();
}
// Before install: remove soundfont from fluid
QDir sfDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::soundfontsDir));
if (sfDir.exists()) {
// get all soundfont files
QStringList filters("*.sf2");
filters.append("*.sf3");
QDirIterator it(sfDir.absolutePath(), filters, QDir::Files, QDirIterator::Subdirectories);
Synthesizer* s = synti->synthesizer("Fluid");
bool found = it.hasNext();
while (it.hasNext()) {
it.next();
s->removeSoundFont(it.fileName());
}
if (found)
synti->storeState();
s->gui()->synthesizerChanged();
}
bool refreshWorkspaces = false;
QDir workspacesDir(QString("%1/%2/%3/%4").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId).arg(version).arg(Extension::workspacesDir));
if (workspacesDir.exists()) {
auto wsList = workspacesDir.entryInfoList(QStringList("*.workspace"), QDir::Files);
if (!wsList.isEmpty())
refreshWorkspaces = true;
}
// delete directories
QDir extensionDir(QString("%1/%2").arg(preferences.getString(PREF_APP_PATHS_MYEXTENSIONS)).arg(extensionId));
extensionDir.removeRecursively();
// update UI
delete newWizard;
newWizard = 0;
mscore->reloadInstrumentTemplates();
mscore->updateInstrumentDialog();
if (refreshWorkspaces) {
const auto curWorkspaceName = WorkspacesManager::currentWorkspace()->name();
WorkspacesManager::refreshWorkspaces();
emit workspacesChanged();
auto ws = WorkspacesManager::workspaces();
//If current worksapce is alive, do nothing
//Select first available workspace in the list otherwise
bool curWorkspaceDisappeared = false;
if (WorkspacesManager::findByName(curWorkspaceName))
curWorkspaceDisappeared = true;
if (curWorkspaceDisappeared)
changeWorkspace(WorkspacesManager::workspaces().last());
}
return true;
}
//---------------------------------------------------------
// isInstalled
/// used from javascript in start center webview
//---------------------------------------------------------
bool MuseScore::isInstalledExtension(QString extensionId)
{
return Extension::isInstalled(extensionId);
}
//---------------------------------------------------------
// populateFileOperations
//---------------------------------------------------------
void MuseScore::populateFileOperations()
{
// Save the current zoom and view-mode combobox states. if any.
const auto zoomBoxState = zoomBox
? std::make_pair(zoomBox->currentIndex(), zoomBox->itemText(static_cast<int>(ZoomIndex::ZOOM_FREE)))
: std::make_pair(-1, QString());
const auto viewModeComboIndex = viewModeCombo ? viewModeCombo->currentIndex() : -1;
fileTools->clear();
if (qApp->layoutDirection() == Qt::LayoutDirection::LeftToRight) {
for (auto s : _fileOperationEntries) {
if (!*s)
fileTools->addSeparator();
else
fileTools->addWidget(new AccessibleToolButton(fileTools, getAction(s)));
}
}
else {
_fileOperationEntries.reverse();
for (auto s : _fileOperationEntries) {
if (!*s)
fileTools->addSeparator();
else
fileTools->addWidget(new AccessibleToolButton(fileTools, getAction(s)));
}
_fileOperationEntries.reverse();
}
// Currently not customizable in ToolbarEditor
fileTools->addSeparator();
zoomBox = new ZoomBox;
// Restore the saved zoom combobox index and text, if any.
if (zoomBoxState.first != -1) {
zoomBox->setCurrentIndex(zoomBoxState.first);
zoomBox->setItemText(static_cast<int>(ZoomIndex::ZOOM_FREE), zoomBoxState.second);
}
connect(zoomBox, SIGNAL(zoomChanged(const ZoomIndex, const qreal)), SLOT(zoomBoxChanged(const ZoomIndex, const qreal)));
fileTools->addWidget(zoomBox);
viewModeCombo = new QComboBox(this);
#if defined(Q_OS_MAC)
viewModeCombo->setFocusPolicy(Qt::StrongFocus);
#else
viewModeCombo->setFocusPolicy(Qt::TabFocus);
#endif
viewModeCombo->setFixedHeight(preferences.getInt(PREF_UI_THEME_ICONHEIGHT) + 8); // hack