MuseScore/mscore/musescore.cpp

5047 lines
173 KiB
C++
Raw Normal View History

2012-05-26 14:49:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
2012-12-06 14:21:53 +01:00
// Copyright (C) 2002-2012 Werner Schweer
2012-05-26 14:49:10 +02:00
//
// This program is free software; you can redistribute it and/or modify
2012-12-06 14:21:53 +01:00
// 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
2012-05-26 14:49:10 +02:00
//=============================================================================
#include <fenv.h>
#include "palettebox.h"
#include "config.h"
2012-05-26 14:49:10 +02:00
#include "musescore.h"
#include "scoreview.h"
#include "libmscore/style.h"
#include "libmscore/score.h"
#include "instrdialog.h"
#include "preferences.h"
#include "prefsdialog.h"
#include "icons.h"
#include "textstyle.h"
#include "libmscore/xml.h"
#include "seq.h"
#include "libmscore/tempo.h"
#include "libmscore/sym.h"
#include "pagesettings.h"
2013-06-10 11:03:34 +02:00
#include "debugger/debugger.h"
2012-05-26 14:49:10 +02:00
#include "editstyle.h"
#include "playpanel.h"
#include "libmscore/page.h"
#include "mixer.h"
2014-06-02 12:12:53 +02:00
#include "selectionwindow.h"
2012-05-26 14:49:10 +02:00
#include "palette.h"
2013-02-10 14:50:18 +01:00
#include "palettebox.h"
2012-05-26 14:49:10 +02:00
#include "libmscore/part.h"
#include "libmscore/drumset.h"
#include "libmscore/instrtemplate.h"
#include "libmscore/note.h"
#include "libmscore/staff.h"
#include "driver.h"
#include "libmscore/harmony.h"
#include "magbox.h"
#include "libmscore/sig.h"
#include "libmscore/undo.h"
#include "synthcontrol.h"
#include "pianoroll.h"
#include "drumroll.h"
#include "scoretab.h"
#include "timedialog.h"
#include "keyedit.h"
#include "harmonyedit.h"
#include "navigator.h"
2013-04-28 21:29:12 +02:00
#include "importmidi_panel.h"
2012-05-26 14:49:10 +02:00
#include "libmscore/chord.h"
#include "mstyle/mstyle.h"
#include "mstyle/mconfig.h"
2012-05-26 14:49:10 +02:00
#include "libmscore/segment.h"
#include "editraster.h"
#include "pianotools.h"
#include "mediadialog.h"
2013-02-06 16:43:25 +01:00
#include "workspace.h"
2012-05-26 14:49:10 +02:00
#include "webpage.h"
#include "selectdialog.h"
#include "transposedialog.h"
#include "metaedit.h"
2013-06-10 11:03:34 +02:00
#include "inspector/inspector.h"
2012-05-26 14:49:10 +02:00
#include "omrpanel.h"
#include "shortcut.h"
2012-07-02 18:05:10 +02:00
#include "pluginCreator.h"
#include "pluginManager.h"
2014-04-25 18:43:25 +02:00
// #include "plugins.h"
#include "helpBrowser.h"
#include "drumtools.h"
#include "editstafftype.h"
2013-02-15 22:39:56 +01:00
#include "texttools.h"
#include "textpalette.h"
#include "resourceManager.h"
#include "scoreaccessibility.h"
2012-05-26 14:49:10 +02:00
#include "libmscore/mscore.h"
#include "libmscore/system.h"
#include "libmscore/measurebase.h"
#include "libmscore/chordlist.h"
#include "libmscore/volta.h"
2012-07-12 15:35:35 +02:00
#include "libmscore/lasso.h"
#include "driver.h"
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
// #include "effects/freeverb/freeverb.h"
#include "effects/zita1/zita.h"
#include "effects/noeffect/noeffect.h"
2013-03-26 19:59:51 +01:00
#include "synthesizer/synthesizer.h"
2013-04-03 12:13:23 +02:00
#include "synthesizer/synthesizergui.h"
#include "synthesizer/msynthesizer.h"
#include "fluid/fluid.h"
#include "qmlplugin.h"
#include "accessibletoolbutton.h"
2013-05-13 18:49:17 +02:00
#ifdef AEOLUS
extern Ms::Synthesizer* createAeolus();
#endif
#ifdef ZERBERUS
extern Ms::Synthesizer* createZerberus();
#endif
namespace Ms {
2012-05-26 14:49:10 +02:00
MuseScore* mscore;
2012-12-10 09:15:50 +01:00
MuseScoreCore* mscoreCore;
2013-03-26 19:59:51 +01:00
MasterSynthesizer* synti;
2012-05-26 14:49:10 +02:00
bool enableExperimental = false;
bool enableTestMode = false;
2012-05-26 14:49:10 +02:00
QString dataPath;
QString iconPath;
2012-05-26 14:49:10 +02:00
bool converterMode = false;
bool externalIcons = false;
static bool pluginMode = false;
static bool startWithNewScore = false;
double converterDpi = 0;
QString mscoreGlobalShare;
static QStringList recentScores;
static QString outFileName;
static QString audioDriver;
2012-05-26 14:49:10 +02:00
static QString pluginName;
static QString styleFile;
QString localeName;
2012-05-26 14:49:10 +02:00
bool useFactorySettings = false;
bool deletePreferences = false;
2012-05-26 14:49:10 +02:00
QString styleName;
QString revision;
2013-07-17 14:36:34 +02:00
QErrorMessage* errorMessage;
const char* voiceActions[] = { "voice-1", "voice-2", "voice-3", "voice-4" };
2012-05-26 14:49:10 +02:00
2014-07-13 18:33:26 +02:00
extern bool savePositions(Score*, const QString& name, bool segments );
2013-02-25 21:57:11 +01:00
extern TextPalette* textPalette;
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
// cmdInsertMeasure
//---------------------------------------------------------
void MuseScore::cmdInsertMeasures()
{
if (cs) {
2014-05-24 12:53:50 +02:00
if (cs->selection().isNone() && !cs->selection().findMeasure()) {
QMessageBox::warning(0, "MuseScore",
tr("No measure selected:\n" "Please select a measure and try again"));
2012-05-26 14:49:10 +02:00
}
else {
insertMeasuresDialog = new InsertMeasuresDialog;
insertMeasuresDialog->show();
}
}
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// InsertMeasuresDialog
//---------------------------------------------------------
InsertMeasuresDialog::InsertMeasuresDialog(QWidget* parent)
: QDialog(parent)
{
setupUi(this);
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
insmeasures->selectAll();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// Insert Measure --> accept
//---------------------------------------------------------
void InsertMeasuresDialog::accept()
{
2013-04-28 21:29:12 +02:00
int n = insmeasures->value();
if (mscore->currentScore())
mscore->currentScoreView()->cmdInsertMeasures(n, Element::Type::MEASURE);
2013-04-28 21:29:12 +02:00
done(1);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// getSharePath
//---------------------------------------------------------
static QString getSharePath()
{
#ifdef Q_OS_WIN
2012-05-26 14:49:10 +02:00
QDir dir(QCoreApplication::applicationDirPath() + QString("/../" INSTALL_NAME));
return dir.absolutePath() + "/";
#else
#ifdef Q_OS_MAC
2012-05-26 14:49:10 +02:00
QDir dir(QCoreApplication::applicationDirPath() + QString("/../Resources"));
return dir.absolutePath() + "/";
#else
return QString( INSTPREFIX "/share/" INSTALL_NAME);
#endif
#endif
}
//---------------------------------------------------------
// printVersion
//---------------------------------------------------------
static void printVersion(const char* prog)
{
#ifdef MSCORE_UNSTABLE
qDebug("%s: Music Score Editor\nUnstable Prerelease for Version %s; Build %s",
prog, VERSION, qPrintable(revision));
#else
qDebug("%s: Music Score Editor; Version %s; Build %s", prog, VERSION, qPrintable(revision));
#endif
}
static const int RECENT_LIST_SIZE = 10;
//---------------------------------------------------------
// closeEvent
//---------------------------------------------------------
void MuseScore::closeEvent(QCloseEvent* ev)
{
unloadPlugins();
QList<Score*> removeList;
foreach(Score* score, scoreList) {
if (score->created() && !score->dirty())
removeList.append(score);
else {
if (checkDirty(score)) { // ask user if file is dirty
ev->ignore();
return;
}
//
// if score is still dirty, then the user has discarded the
// score and we can remove it from the list
//
if (score->created() && score->dirty())
removeList.append(score);
}
}
// remove all new created/not save score so they are
// note saved as session data
foreach(Score* score, removeList)
scoreList.removeAll(score);
writeSessionFile(true);
foreach(Score* score, scoreList) {
if (!score->tmpName().isEmpty()) {
QFile f(score->tmpName());
f.remove();
}
}
// save score list
QSettings settings;
for (int i = 0; i < RECENT_LIST_SIZE; ++i)
settings.setValue(QString("recent-%1").arg(i), recentScores.value(i));
settings.setValue("scores", scoreList.size());
int curScore = scoreList.indexOf(cs);
if (curScore == -1) // cs removed if new created and not modified
curScore = 0;
settings.setValue("currentScore", curScore);
for (int idx = 0; idx < scoreList.size(); ++idx)
settings.setValue(QString("score-%1").arg(idx), scoreList[idx]->fileInfo()->absoluteFilePath());
2012-05-26 14:49:10 +02:00
settings.setValue("lastSaveCopyDirectory", lastSaveCopyDirectory);
settings.setValue("lastSaveDirectory", lastSaveDirectory);
// if (playPanel)
// preferences.playPanelPos = playPanel->pos();
2012-05-26 14:49:10 +02:00
writeSettings();
if (debugger)
debugger->writeSettings();
2012-07-09 14:50:03 +02:00
#ifdef SCRIPT_INTERFACE
2014-08-29 19:18:39 +02:00
if (_pluginCreator)
_pluginCreator->writeSettings();
2012-07-09 14:16:27 +02:00
#endif
if (synthControl)
synthControl->writeSettings();
2013-07-16 18:30:31 +02:00
if (mixer)
mixer->writeSettings();
if (seq) {
2013-04-12 10:56:17 +02:00
seq->stopWait();
seq->exit();
}
2013-10-01 16:22:06 +02:00
if (instrList)
instrList->writeSettings();
if (pianorollEditor)
pianorollEditor->writeSettings();
if (drumrollEditor)
drumrollEditor->writeSettings();
2013-04-12 10:56:17 +02:00
2012-05-26 14:49:10 +02:00
ev->accept();
if (preferences.dirty)
preferences.write();
this->deleteLater(); //this is necessary on windows http://musescore.org/node/16713
2012-05-26 14:49:10 +02:00
qApp->quit();
}
//---------------------------------------------------------
// preferencesChanged
//---------------------------------------------------------
void MuseScore::preferencesChanged()
{
for (int i = 0; i < tab1->count(); ++i) {
ScoreView* canvas = tab1->view(i);
if (canvas == 0)
continue;
if (preferences.bgUseColor)
canvas->setBackground(MScore::bgColor);
else {
QPixmap* pm = new QPixmap(preferences.bgWallpaper);
canvas->setBackground(pm);
}
if (preferences.fgUseColor)
canvas->setForeground(preferences.fgColor);
else {
QPixmap* pm = new QPixmap(preferences.fgWallpaper);
if (pm == 0 || pm->isNull())
qDebug("no valid pixmap %s", preferences.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.bgUseColor)
canvas->setBackground(MScore::bgColor);
else {
QPixmap* pm = new QPixmap(preferences.bgWallpaper);
canvas->setBackground(pm);
}
if (preferences.fgUseColor)
canvas->setForeground(preferences.fgColor);
else {
QPixmap* pm = new QPixmap(preferences.fgWallpaper);
if (pm == 0 || pm->isNull())
qDebug("no valid pixmap %s", preferences.fgWallpaper.toLatin1().data());
canvas->setForeground(pm);
}
}
}
transportTools->setEnabled(!noSeq && seq && seq->isRunning());
playId->setEnabled(!noSeq && seq && seq->isRunning());
2012-05-26 14:49:10 +02:00
getAction("midi-on")->setEnabled(preferences.enableMidiInput);
2012-05-31 16:24:35 +02:00
_statusBar->setVisible(preferences.showStatusBar);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// MuseScore
//---------------------------------------------------------
MuseScore::MuseScore()
: QMainWindow()
{
_sstate = STATE_INIT;
setWindowTitle(QString("MuseScore"));
setIconSize(QSize(preferences.iconWidth, preferences.iconHeight));
ucheck = new UpdateChecker();
setAcceptDrops(true);
cs = 0;
lastOpenPath = preferences.myScoresPath;
2014-11-10 10:05:25 +01:00
2012-05-26 14:49:10 +02:00
_mediaDialog = 0;
_drumTools = 0;
pianorollEditor = 0;
drumrollEditor = 0;
_splitScreen = false;
_horizontalSplit = true;
chordStyleEditor = 0;
albumManager = 0;
loadScoreDialog = 0;
saveScoreDialog = 0;
loadStyleDialog = 0;
saveStyleDialog = 0;
saveImageDialog = 0;
loadSoundFontDialog = 0;
2013-03-26 19:59:51 +01:00
loadSfzFileDialog = 0;
2012-05-26 14:49:10 +02:00
loadBackgroundDialog = 0;
loadScanDialog = 0;
loadAudioDialog = 0;
loadChordStyleDialog = 0;
saveChordStyleDialog = 0;
loadDrumsetDialog = 0;
2012-07-02 18:05:10 +02:00
loadPluginDialog = 0;
2012-05-26 14:49:10 +02:00
loadPaletteDialog = 0;
savePaletteDialog = 0;
saveDrumsetDialog = 0;
2012-07-02 18:05:10 +02:00
savePluginDialog = 0;
2012-05-26 14:49:10 +02:00
editRasterDialog = 0;
inChordEditor = false;
networkManager = 0;
2013-02-08 11:36:50 +01:00
workspaces = 0;
2012-05-26 14:49:10 +02:00
_midiRecordId = -1;
_fullscreen = false;
lastCmd = 0;
lastShortcut = 0;
importmidiPanel = 0;
this->setFocusPolicy(Qt::NoFocus);
2012-05-26 14:49:10 +02:00
if (!preferences.styleName.isEmpty()) {
QFile f(preferences.styleName);
if (f.open(QIODevice::ReadOnly)) {
MScore::defaultStyle()->load(&f);
f.close();
}
}
_positionLabel = new QLabel;
_positionLabel->setObjectName("decoration widget"); // this prevents animations
2014-10-15 20:43:06 +02:00
_positionLabel->setToolTip(tr("Measure:Beat:Tick"));
2012-05-26 14:49:10 +02:00
_modeText = new QLabel;
2013-07-04 21:07:38 +02:00
_modeText->setAutoFillBackground(false);
_modeText->setObjectName("modeLabel");
2012-05-26 14:49:10 +02:00
_statusBar = new QStatusBar;
2012-05-26 14:49:10 +02:00
hRasterAction = getAction("hraster");
hRasterAction->setCheckable(true);
vRasterAction = getAction("vraster");
vRasterAction->setCheckable(true);
2013-07-31 19:47:33 +02:00
loopAction = getAction("loop");
loopAction->setCheckable(true);
loopAction->setChecked(false);
2013-08-19 08:53:30 +02:00
loopInAction = getAction("loop-in");
loopInAction->setCheckable(false);
//loopInAction->setChecked(false);
2013-08-19 08:53:30 +02:00
loopOutAction = getAction("loop-out");
loopOutAction->setCheckable(false);
//loopOutAction->setChecked(false);
2012-05-26 14:49:10 +02:00
metronomeAction = getAction("metronome");
metronomeAction->setCheckable(true);
metronomeAction->setChecked(false);
countInAction = getAction("countin");
countInAction->setCheckable(true);
countInAction->setChecked(false);
2012-05-26 14:49:10 +02:00
_statusBar->addPermanentWidget(new QWidget(this), 2);
_statusBar->addPermanentWidget(new QWidget(this), 100);
_statusBar->addPermanentWidget(_modeText, 0);
if (enableExperimental) {
layerSwitch = new QComboBox(this);
2014-10-15 20:43:06 +02:00
layerSwitch->setToolTip(tr("Switch layer"));
connect(layerSwitch, SIGNAL(activated(const QString&)), SLOT(switchLayer(const QString&)));
playMode = new QComboBox(this);
playMode->addItem(tr("synthesizer"));
playMode->addItem(tr("audio track"));
2014-10-15 20:43:06 +02:00
playMode->setToolTip(tr("Switch play mode"));
connect(playMode, SIGNAL(activated(int)), SLOT(switchPlayMode(int)));
_statusBar->addPermanentWidget(playMode);
_statusBar->addPermanentWidget(layerSwitch);
}
2012-05-26 14:49:10 +02:00
_statusBar->addPermanentWidget(_positionLabel, 0);
setStatusBar(_statusBar);
ScoreAccessibility::createInstance(this);
2012-05-26 14:49:10 +02:00
_progressBar = 0;
// otherwise unused actions:
// must be added somewere to work
QActionGroup* ag = Shortcut::getActionGroupForWidget(MsWidget::MAIN_WINDOW);
ag->setParent(this);
this->addActions(ag->actions());
2012-05-26 14:49:10 +02:00
connect(ag, SIGNAL(triggered(QAction*)), SLOT(cmd(QAction*)));
mainWindow = new QSplitter;
2013-05-08 10:54:06 +02:00
mainWindow->setChildrenCollapsible(false);
2012-05-26 14:49:10 +02:00
mainWindow->setOrientation(Qt::Vertical);
2013-05-08 10:54:06 +02:00
2012-05-26 14:49:10 +02:00
QWidget* mainScore = new QWidget;
mainScore->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mainWindow->addWidget(mainScore);
layout = new QVBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
mainScore->setLayout(layout);
_navigator = new NScrollArea;
_navigator->setFocusPolicy(Qt::NoFocus);
2012-05-26 14:49:10 +02:00
mainWindow->addWidget(_navigator);
showNavigator(preferences.showNavigator);
2013-05-09 18:46:51 +02:00
mainWindow->setStretchFactor(0, 1);
mainWindow->setStretchFactor(1, 0);
{
QList<int> sizes;
sizes << 500 << 50; // initial size of score canvas relative to navigator
mainWindow->setSizes(sizes);
}
QSplitter* envelope = new QSplitter;
envelope->setChildrenCollapsible(false);
envelope->setOrientation(Qt::Vertical);
envelope->addWidget(mainWindow);
importmidiPanel = new ImportMidiPanel(this);
importmidiPanel->setVisible(false);
envelope->addWidget(importmidiPanel);
{
importmidiShowPanel = new QFrame;
QHBoxLayout *hl = new QHBoxLayout;
hl->setMargin(0);
hl->setSpacing(0);
importmidiShowPanel->setLayout(hl);
QPushButton *b = new QPushButton(tr("Show MIDI import panel"));
b->setFocusPolicy(Qt::ClickFocus);
importmidiShowPanel->setVisible(false);
connect(b, SIGNAL(clicked()), SLOT(showMidiImportPanel()));
connect(importmidiPanel, SIGNAL(closeClicked()), importmidiShowPanel, SLOT(show()));
hl->addWidget(b);
QSpacerItem *item = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
hl->addSpacerItem(item);
envelope->addWidget(importmidiShowPanel);
}
2013-04-28 21:29:12 +02:00
2013-05-09 18:46:51 +02:00
{
2012-05-26 14:49:10 +02:00
QList<int> sizes;
2013-05-09 18:46:51 +02:00
sizes << 550 << 180; // initial size of score canvas relative to midi panel
envelope->setSizes(sizes);
}
2012-05-26 14:49:10 +02:00
splitter = new QSplitter;
tab1 = new ScoreTab(&scoreList, this);
2012-05-26 14:49:10 +02:00
tab1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(tab1, SIGNAL(currentScoreViewChanged(ScoreView*)), SLOT(setCurrentScoreView(ScoreView*)));
connect(tab1, SIGNAL(tabCloseRequested(int)), SLOT(removeTab(int)));
connect(tab1, SIGNAL(actionTriggered(QAction*)), SLOT(cmd(QAction*)));
2012-05-26 14:49:10 +02:00
splitter->addWidget(tab1);
if (splitScreen()) {
tab2 = new ScoreTab(&scoreList, this);
2012-05-26 14:49:10 +02:00
tab2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(tab2, SIGNAL(currentScoreViewChanged(ScoreView*)), SLOT(setCurrentScoreView(ScoreView*)));
connect(tab2, SIGNAL(tabCloseRequested(int)), SLOT(removeTab(int)));
connect(tab2, SIGNAL(actionTriggered(QAction*)), SLOT(cmd(QAction*)));
2012-05-26 14:49:10 +02:00
splitter->addWidget(tab2);
tab2->setVisible(false);
}
else
tab2 = 0;
layout->addWidget(splitter);
_searchDialog = 0;
2012-05-26 14:49:10 +02:00
//---------------------------------------------------
// Transport Action
//---------------------------------------------------
QAction* a;
#ifdef HAS_MIDI
a = getAction("midi-on");
a->setCheckable(true);
a->setEnabled(preferences.enableMidiInput);
a->setChecked(_midiinEnabled);
#endif
getAction("play")->setCheckable(true);
a = getAction("repeat");
a->setCheckable(true);
a->setChecked(true);
panAction = getAction("pan");
panAction->setCheckable(true);
panAction->setChecked(true);
//---------------------------------------------------
// File Action
//---------------------------------------------------
//---------------------
// Tool Bar
//---------------------
fileTools = addToolBar(tr("File Operations"));
fileTools->setObjectName("file-operations");
fileTools->addWidget(new AccessibleToolButton(fileTools, getAction("file-new")));
fileTools->addWidget(new AccessibleToolButton(fileTools, getAction("file-open")));
fileTools->addWidget(new AccessibleToolButton(fileTools, getAction("file-save")));
fileTools->addWidget(new AccessibleToolButton(fileTools, getAction("print")));
fileTools->addWidget(new AccessibleToolButton(fileTools, getAction("musescore-connect")));
2012-05-26 14:49:10 +02:00
fileTools->addSeparator();
a = getAction("undo");
a->setEnabled(false);
fileTools->addWidget(new AccessibleToolButton(fileTools, a));
2012-05-26 14:49:10 +02:00
a = getAction("redo");
a->setEnabled(false);
fileTools->addWidget(new AccessibleToolButton(fileTools, a));
2012-05-26 14:49:10 +02:00
fileTools->addSeparator();
mag = new MagBox;
mag->setFocusPolicy(Qt::StrongFocus);
mag->setAccessibleName(tr("Zoom"));
mag->setFixedHeight(preferences.iconHeight + 10); // hack
connect(mag, SIGNAL(magChanged(int)), SLOT(magChanged(int)));
fileTools->addWidget(mag);
viewModeCombo = new QComboBox(this);
#if defined(Q_OS_MAC)
viewModeCombo->setFocusPolicy(Qt::StrongFocus);
#else
viewModeCombo->setFocusPolicy(Qt::TabFocus);
#endif
viewModeCombo->setAccessibleName(tr("View Mode"));
viewModeCombo->setFixedHeight(preferences.iconHeight + 8); // hack
viewModeCombo->addItem(tr("Page View"));
viewModeCombo->addItem(tr("Continuous View"));
connect(viewModeCombo, SIGNAL(activated(int)), SLOT(switchLayoutMode(int)));
fileTools->addWidget(viewModeCombo);
2012-05-26 14:49:10 +02:00
transportTools = addToolBar(tr("Transport Tools"));
transportTools->setObjectName("transport-tools");
#ifdef HAS_MIDI
transportTools->addWidget(new AccessibleToolButton(transportTools, getAction("midi-on")));
2012-05-26 14:49:10 +02:00
#endif
transportTools->addSeparator();
transportTools->addWidget(new AccessibleToolButton(transportTools, getAction("rewind")));
2013-08-19 08:53:30 +02:00
//transportTools->addAction(getAction("loop-in"));
transportTools->addWidget(new AccessibleToolButton(transportTools, getAction("play")));
transportTools->addWidget(new AccessibleToolButton(transportTools, getAction("loop")));
2013-08-19 08:53:30 +02:00
//transportTools->addAction(getAction("loop-out"));
2012-05-26 14:49:10 +02:00
transportTools->addSeparator();
a = getAction("repeat");
a->setChecked(MScore::playRepeats);
transportTools->addWidget(new AccessibleToolButton(transportTools, a));
2012-05-26 14:49:10 +02:00
a = getAction("pan");
a->setChecked(MScore::panPlayback);
transportTools->addWidget(new AccessibleToolButton(transportTools, a));
2012-05-26 14:49:10 +02:00
transportTools->addWidget(new AccessibleToolButton(transportTools, metronomeAction));
2012-05-26 14:49:10 +02:00
cpitchTools = addToolBar(tr("Concert Pitch"));
cpitchTools->setObjectName("pitch-tools");
cpitchTools->addWidget(new AccessibleToolButton( cpitchTools, getAction("concert-pitch")));
2012-05-26 14:49:10 +02:00
QToolBar* foto = addToolBar(tr("Screenshot Mode"));
2012-05-26 14:49:10 +02:00
foto->setObjectName("foto-tools");
a = getAction("fotomode");
a->setCheckable(true);
foto->addWidget(new AccessibleToolButton(foto, a));
2012-05-26 14:49:10 +02:00
2013-07-04 21:07:38 +02:00
addToolBarBreak();
2012-05-26 14:49:10 +02:00
//-------------------------------
// Note Entry Tool Bar
//-------------------------------
entryTools = addToolBar(tr("Note Entry"));
entryTools->setObjectName("entry-tools");
a = getAction("note-input");
a->setCheckable(true);
entryTools->addAction(a);
2013-05-31 17:48:47 +02:00
static const char* sl1[] = {
"repitch", "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", "tie", "pad-rest"
};
for (const char* s : sl1) {
QAction* a = getAction(s);
if (strcmp(s, "tie") != 0)
2012-05-26 14:49:10 +02:00
a->setCheckable(true);
2013-05-31 17:48:47 +02:00
entryTools->addAction(a);
if (strcmp(s, "tie") == 0 || strcmp(s, "pad-rest") == 0)
2012-05-26 14:49:10 +02:00
entryTools->addSeparator();
}
2013-05-31 17:48:47 +02:00
static const char* sl2[] = { "sharp2", "sharp", "nat", "flat", "flat2" };
for (const char* s : sl2)
entryTools->addAction(getAction(s));
2012-05-26 14:49:10 +02:00
static const char* sl4[] = {
2014-04-23 18:07:38 +02:00
"appoggiatura", "acciaccatura", "grace4", "grace16", "grace32", "grace8after", "grace16after", "grace32after",
2013-05-31 17:48:47 +02:00
"beam-start", "beam-mid", "no-beam", "beam32", "auto-beam",
"show-invisible", "show-unprintable", "show-frames", "show-pageborders"
};
for (const char* s : sl4)
getAction(s)->setCheckable(true);
2012-05-26 14:49:10 +02:00
a = getAction("flip");
entryTools->addAction(a);
entryTools->addSeparator();
for (int i = 0; i < VOICES; ++i) {
2013-07-03 16:32:38 +02:00
QToolButton* tb = new QToolButton(this);
tb->setToolButtonStyle(Qt::ToolButtonTextOnly);
QPalette p(tb->palette());
p.setColor(QPalette::Base, MScore::selectColor[i]);
tb->setPalette(p);
QAction* a = getAction(voiceActions[i]);
2013-05-31 17:48:47 +02:00
a->setCheckable(true);
2013-07-03 16:32:38 +02:00
tb->setDefaultAction(a);
tb->setFocusPolicy(Qt::ClickFocus);
2013-07-03 16:32:38 +02:00
entryTools->addWidget(tb);
2013-05-31 17:48:47 +02:00
}
2012-05-26 14:49:10 +02:00
//---------------------
// Menus
//---------------------
QMenuBar* mb = menuBar();
//---------------------
// Menu File
//---------------------
_fileMenu = mb->addMenu(tr("&File"));
_fileMenu->setObjectName("File");
_fileMenu->addAction(getAction("file-new"));
_fileMenu->addAction(getAction("file-open"));
2013-05-12 10:28:07 +02:00
openRecent = _fileMenu->addMenu(tr("Open &Recent"));
2012-05-26 14:49:10 +02:00
connect(openRecent, SIGNAL(aboutToShow()), SLOT(openRecentMenu()));
connect(openRecent, SIGNAL(triggered(QAction*)), SLOT(selectScore(QAction*)));
_fileMenu->addSeparator();
_fileMenu->addAction(getAction("file-save"));
_fileMenu->addAction(getAction("file-save-as"));
_fileMenu->addAction(getAction("file-save-a-copy"));
_fileMenu->addAction(getAction("file-save-selection"));
_fileMenu->addAction(getAction("file-export"));
_fileMenu->addAction(getAction("file-part-export"));
_fileMenu->addSeparator();
_fileMenu->addAction(getAction("file-close"));
_fileMenu->addSeparator();
_fileMenu->addAction(getAction("parts"));
_fileMenu->addAction(getAction("album"));
if (enableExperimental)
_fileMenu->addAction(getAction("layer"));
2012-05-26 14:49:10 +02:00
_fileMenu->addSeparator();
_fileMenu->addAction(getAction("edit-info"));
2013-05-24 16:35:48 +02:00
if (enableExperimental)
_fileMenu->addAction(getAction("media"));
2012-05-26 14:49:10 +02:00
_fileMenu->addSeparator();
_fileMenu->addAction(getAction("print"));
#ifndef Q_OS_MAC
2012-05-26 14:49:10 +02:00
_fileMenu->addSeparator();
_fileMenu->addAction(getAction("quit"));
#endif
2012-05-26 14:49:10 +02:00
//---------------------
// Menu Edit
//---------------------
2012-05-26 14:49:10 +02:00
menuEdit = mb->addMenu(tr("&Edit"));
menuEdit->setObjectName("Edit");
menuEdit->addAction(getAction("undo"));
menuEdit->addAction(getAction("redo"));
menuEdit->addSeparator();
menuEdit->addAction(getAction("cut"));
menuEdit->addAction(getAction("copy"));
a = getAction("paste");
a->setEnabled(false);
menuEdit->addAction(a);
2014-05-26 13:21:04 +02:00
selectionChanged(SelState::NONE);
2012-09-12 16:19:03 +02:00
2012-05-26 14:49:10 +02:00
menuEdit->addSeparator();
menuEdit->addAction(getAction("select-all"));
menuEdit->addAction(getAction("select-section"));
menuEdit->addAction(getAction("find"));
2012-09-12 16:19:03 +02:00
menuEdit->addSeparator();
2012-05-26 14:49:10 +02:00
QMenu* menuMeasure = new QMenu(tr("&Measure"));
menuMeasure->addAction(getAction("delete-measures"));
menuMeasure->addAction(getAction("split-measure"));
menuMeasure->addAction(getAction("join-measure"));
menuEdit->addMenu(menuMeasure);
2012-05-26 14:49:10 +02:00
menuEdit->addSeparator();
QMenu* menuVoices = new QMenu(tr("&Voices"));
menuVoices->addAction(getAction("voice-x12"));
menuVoices->addAction(getAction("voice-x13"));
menuVoices->addAction(getAction("voice-x14"));
menuVoices->addAction(getAction("voice-x23"));
menuVoices->addAction(getAction("voice-x24"));
menuVoices->addAction(getAction("voice-x34"));
menuEdit->addMenu(menuVoices);
2014-10-31 14:11:53 +01:00
#ifdef NDEBUG
if (enableExperimental) {
2014-10-31 14:11:53 +01:00
#endif
menuEdit->addSeparator();
menuEdit->addAction(getAction("debugger"));
2014-10-31 14:11:53 +01:00
#ifdef NDEBUG
}
2014-10-31 14:11:53 +01:00
#endif
2012-05-26 14:49:10 +02:00
2012-09-12 16:19:03 +02:00
menuEdit->addSeparator();
2013-02-06 16:43:25 +01:00
menuWorkspaces = new QMenu(tr("W&orkspaces"));
connect(menuWorkspaces, SIGNAL(aboutToShow()), SLOT(showWorkspaceMenu()));
menuEdit->addMenu(menuWorkspaces);
2012-05-26 14:49:10 +02:00
QAction* pref = menuEdit->addAction(tr("&Preferences..."), this, SLOT(startPreferenceDialog()));
pref->setMenuRole(QAction::PreferencesRole);
//---------------------
// Menu View
//---------------------
menuView = mb->addMenu(tr("&View"));
menuView->setObjectName("View");
2014-11-10 10:05:25 +01:00
a = getAction("startcenter");
a->setCheckable(true);
menuView->addAction(a);
a = getAction("toggle-palette");
a->setCheckable(true);
menuView->addAction(a);
a = getAction("masterpalette");
a->setCheckable(true);
menuView->addAction(a);
a = getAction("inspector");
a->setCheckable(true);
menuView->addAction(a);
#ifdef OMR
a = getAction("omr");
a->setCheckable(true);
menuView->addAction(a);
#endif
playId = getAction("toggle-playpanel");
playId->setCheckable(true);
menuView->addAction(playId);
a = getAction("toggle-navigator");
a->setCheckable(true);
a->setChecked(preferences.showNavigator);
menuView->addAction(a);
a = getAction("toggle-mixer");
a->setCheckable(true);
menuView->addAction(a);
a = getAction("synth-control");
a->setCheckable(true);
menuView->addAction(a);
2014-06-02 12:12:53 +02:00
a = getAction("toggle-selection-window");
a->setCheckable(true);
menuView->addAction(a);
a = getAction("toogle-piano");
a->setCheckable(true);
menuView->addAction(a);
a = getAction("musescore-connect");
a->setCheckable(true);
menuView->addAction(a);
menuView->addSeparator();
menuView->addAction(getAction("zoomin"));
menuView->addAction(getAction("zoomout"));
menuView->addSeparator();
a = getAction("toggle-transport");
a->setCheckable(true);
a->setChecked(transportTools->isVisible());
menuView->addAction(a);
a = getAction("toggle-noteinput");
a->setCheckable(true);
a->setChecked(true);
menuView->addAction(a);
a = getAction("toggle-statusbar");
a->setCheckable(true);
a->setChecked(true);
menuView->addAction(a);
menuView->addSeparator();
a = getAction("split-h");
a->setCheckable(true);
a->setChecked(false);
menuView->addAction(a);
a = getAction("split-v");
a->setCheckable(true);
a->setChecked(false);
menuView->addAction(a);
menuView->addSeparator();
menuView->addAction(getAction("show-invisible"));
menuView->addAction(getAction("show-unprintable"));
menuView->addAction(getAction("show-frames"));
menuView->addAction(getAction("show-pageborders"));
menuView->addSeparator();
a = getAction("fullscreen");
a->setCheckable(true);
a->setChecked(false);
menuView->addAction(a);
2012-05-26 14:49:10 +02:00
//---------------------
// Menu Create
//---------------------
mb->addMenu(genCreateMenu(mb));
2012-05-26 14:49:10 +02:00
//---------------------
// Menu Notes
//---------------------
menuNotes = mb->addMenu(qApp->translate("MenuNotes", "&Notes"));
menuNotes->setObjectName("Notes");
menuNotes->addAction(getAction("note-input"));
menuNotes->addAction(getAction("pitch-spell"));
menuNotes->addSeparator();
QMenu* menuAddPitch = new QMenu(tr("Add N&ote"));
for (int i = 0; i < 7; ++i) {
char buffer[8];
sprintf(buffer, "note-%c", "cdefgab"[i]);
a = getAction(buffer);
menuAddPitch->addAction(a);
}
menuNotes->addMenu(menuAddPitch);
for (int i = 0; i < 7; ++i) {
char buffer[8];
sprintf(buffer, "chord-%c", "cdefgab"[i]);
a = getAction(buffer);
menuAddPitch->addAction(a);
}
QMenu* menuAddInterval = new QMenu(tr("Add &Interval"));
for (int i = 1; i < 10; ++i) {
char buffer[16];
sprintf(buffer, "interval%d", i);
a = getAction(buffer);
menuAddInterval->addAction(a);
}
menuAddInterval->addSeparator();
for (int i = 2; i < 10; ++i) {
char buffer[16];
sprintf(buffer, "interval-%d", i);
a = getAction(buffer);
menuAddInterval->addAction(a);
}
menuNotes->addMenu(menuAddInterval);
QMenu* menuNtole = new QMenu(tr("T&uplets"));
menuNtole->addAction(getAction("duplet"));
menuNtole->addAction(getAction("triplet"));
menuNtole->addAction(getAction("quadruplet"));
menuNtole->addAction(getAction("quintuplet"));
menuNtole->addAction(getAction("sextuplet"));
menuNtole->addAction(getAction("septuplet"));
menuNtole->addAction(getAction("octuplet"));
menuNtole->addAction(getAction("nonuplet"));
menuNtole->addAction(getAction("tuplet-dialog"));
menuNotes->addMenu(menuNtole);
menuNotes->addSeparator();
menuNotes->addAction(getAction("transpose"));
a = getAction("concert-pitch");
a->setCheckable(true);
menuNotes->addAction(a);
//---------------------
// Menu Layout
//---------------------
menuLayout = mb->addMenu(tr("&Layout"));
menuLayout->setObjectName("Layout");
menuLayout->addAction(getAction("page-settings"));
menuLayout->addAction(getAction("reset"));
menuLayout->addAction(getAction("stretch+"));
menuLayout->addAction(getAction("stretch-"));
menuLayout->addAction(getAction("reset-stretch"));
menuLayout->addAction(getAction("reset-beammode"));
2013-10-18 16:36:17 +02:00
// menuLayout->addAction(tr("Breaks && Spacers..."), this, SLOT(showLayoutBreakPalette()));
2012-05-26 14:49:10 +02:00
//---------------------
// Menu Style
//---------------------
menuStyle = mb->addMenu(tr("&Style"));
menuStyle->setObjectName("Style");
menuStyle->addAction(getAction("edit-style"));
menuStyle->addAction(getAction("edit-text-style"));
if (enableExperimental)
menuStyle->addAction(getAction("edit-harmony"));
2012-10-29 16:37:24 +01:00
2012-05-26 14:49:10 +02:00
menuStyle->addSeparator();
menuStyle->addAction(getAction("load-style"));
menuStyle->addAction(getAction("save-style"));
2012-07-13 13:08:54 +02:00
//---------------------
// Menu Plugins
//---------------------
QMenu* menuPlugins = mb->addMenu(tr("&Plugins"));
menuPlugins->setObjectName("Plugins");
2013-10-05 12:03:30 +02:00
menuPlugins->addAction(getAction("plugin-manager"));
2012-07-13 13:08:54 +02:00
a = getAction("plugin-creator");
a->setCheckable(true);
menuPlugins->addAction(a);
2012-07-13 13:08:54 +02:00
menuPlugins->addSeparator();
2012-07-19 16:47:23 +02:00
2012-05-26 14:49:10 +02:00
//---------------------
// Menu Help
//---------------------
mb->addSeparator();
QMenu* menuHelp = mb->addMenu(tr("&Help"));
menuHelp->setObjectName("Help");
if (enableExperimental)
menuHelp->addAction(getAction("local-help"));
2012-05-26 14:49:10 +02:00
menuHelp->addAction(tr("&Online Handbook"), this, SLOT(helpBrowser1()));
menuHelp->addSeparator();
QAction *aboutAction = new QAction(tr("&About"), 0);
2012-05-26 14:49:10 +02:00
aboutAction->setMenuRole(QAction::AboutRole);
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
menuHelp->addAction(aboutAction);
QAction *aboutQtAction = new QAction(tr("About &Qt"), 0);
aboutQtAction->setMenuRole(QAction::AboutQtRole);
connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(aboutQt()));
menuHelp->addAction(aboutQtAction);
2012-05-26 14:49:10 +02:00
QAction *aboutMusicXMLAction = new QAction(tr("About &MusicXML"), 0);
aboutMusicXMLAction->setMenuRole(QAction::ApplicationSpecificRole);
connect(aboutMusicXMLAction, SIGNAL(triggered()), this, SLOT(aboutMusicXML()));
menuHelp->addAction(aboutMusicXMLAction);
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
2012-05-26 14:49:10 +02:00
menuHelp->addAction(tr("Check for &Update"), this, SLOT(checkForUpdate()));
#endif
#ifdef MSCORE_UNSTABLE
menuHelp->addSeparator();
menuHelp->addAction(tr("Report a Bug"), this, SLOT(reportBug()));
#endif
menuHelp->addSeparator();
menuHelp->addAction(getAction("resource-manager"));
//accessibility for menus
foreach (QMenu* menu, mb->findChildren<QMenu*>()) {
menu->setAccessibleName(menu->objectName());
menu->setAccessibleDescription(Shortcut::getMenuShortcutString(menu));
}
2013-05-09 18:46:51 +02:00
setCentralWidget(envelope);
// load cascading instrument templates
loadInstrumentTemplates(preferences.instrumentList1);
if (!preferences.instrumentList2.isEmpty())
loadInstrumentTemplates(preferences.instrumentList2);
2012-05-26 14:49:10 +02:00
preferencesChanged();
if (seq) {
connect(seq, SIGNAL(started()), SLOT(seqStarted()));
connect(seq, SIGNAL(stopped()), SLOT(seqStopped()));
}
loadScoreList();
showPlayPanel(preferences.showPlayPanel);
QClipboard* cb = QApplication::clipboard();
connect(cb, SIGNAL(dataChanged()), SLOT(clipboardChanged()));
connect(cb, SIGNAL(selectionChanged()), SLOT(clipboardChanged()));
autoSaveTimer = new QTimer(this);
autoSaveTimer->setSingleShot(true);
connect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSaveTimerTimeout()));
initOsc();
startAutoSave();
if (enableExperimental) {
cornerLabel = new QLabel(this);
cornerLabel->setScaledContents(true);
cornerLabel->setPixmap(QPixmap(":/data/mscore.png"));
cornerLabel->setGeometry(width() - 48, 0, 48, 48);
}
}
//---------------------------------------------------------
// resizeEvent
//---------------------------------------------------------
void MuseScore::resizeEvent(QResizeEvent*)
{
if (enableExperimental) {
cornerLabel->setGeometry(width() - 48, 0, 48, 48);
}
}
//---------------------------------------------------------
// MuseScore
//---------------------------------------------------------
MuseScore::~MuseScore()
{
}
//---------------------------------------------------------
// startAutoSave
//---------------------------------------------------------
void MuseScore::startAutoSave()
{
if (preferences.autoSave) {
int t = preferences.autoSaveTime * 60 * 1000;
autoSaveTimer->start(t);
}
else
autoSaveTimer->stop();
}
//---------------------------------------------------------
// getLocaleISOCode
//---------------------------------------------------------
QString MuseScore::getLocaleISOCode() const
2012-05-26 14:49:10 +02:00
{
QString lang;
if (localeName.toLower() == "system")
lang = QLocale::system().name();
else
lang = localeName;
return lang;
}
//---------------------------------------------------------
// helpBrowser
// show local help
//---------------------------------------------------------
2013-10-16 18:09:26 +02:00
void MuseScore::helpBrowser(QString tag) const
2012-05-26 14:49:10 +02:00
{
QString lang = getLocaleISOCode();
if (lang == "en_US") // HACK
lang = "en";
2012-05-26 14:49:10 +02:00
if (MScore::debugMode)
qDebug("open handbook for language <%s>", qPrintable(lang));
2013-10-16 18:09:26 +02:00
QString path(mscoreGlobalShare + "manual/reference-" + lang + ".pdf");
if (!QFile::exists(path))
path = mscoreGlobalShare + "manual/reference-en" + ".pdf";
qDebug("helpBrowser::load <%s>", qPrintable(path));
2013-10-16 18:09:26 +02:00
QUrl url(QUrl::fromLocalFile(path));
if (!tag.isEmpty())
url.setFragment(tag);
if (enableExperimental)
helpBrowser(url);
}
void MuseScore::helpBrowser(const QUrl& url) const
{
2013-10-16 18:09:26 +02:00
QDesktopServices::openUrl(url);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// helpBrowser1
// show online help
//---------------------------------------------------------
void MuseScore::helpBrowser1() const
2012-05-26 14:49:10 +02:00
{
QString lang = getLocaleISOCode();
if (MScore::debugMode)
qDebug("open online handbook for language <%s>", qPrintable(lang));
2014-10-15 18:46:42 +02:00
QString help("http://musescore.org/en/handbook-2.0");
2012-05-26 14:49:10 +02:00
//try to find an exact match
bool found = false;
foreach (LanguageItem item, _languages) {
if (item.key == lang) {
2012-05-26 14:49:10 +02:00
QString handbook = item.handbook;
if (!handbook.isNull()) {
help = item.handbook;
found = true;
}
break;
}
}
//try a to find a match on first two letters
if (!found && lang.size() > 2) {
lang = lang.left(2);
foreach (LanguageItem item, _languages) {
if (item.key == lang){
QString handbook = item.handbook;
if (!handbook.isNull())
help = item.handbook;
break;
}
}
}
//track visits. see: http://www.google.com/support/googleanalytics/bin/answer.py?answer=55578
help += QString("?utm_source=software&utm_medium=menu&utm_content=r%1&utm_campaign=MuseScore%2").arg(rev.trimmed()).arg(QString(VERSION));
2013-10-16 18:09:26 +02:00
helpBrowser(QUrl(help));
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// aboutQt
//---------------------------------------------------------
void MuseScore::aboutQt()
{
QMessageBox::aboutQt(this, QString("About Qt"));
}
//---------------------------------------------------------
// aboutMusicXML
//---------------------------------------------------------
void MuseScore::aboutMusicXML()
{
AboutMusicXMLBoxDialog ab;
ab.show();
ab.exec();
}
//---------------------------------------------------------
// selectScore
// "open recent"
//---------------------------------------------------------
void MuseScore::selectScore(QAction* action)
{
QString a = action->data().toString();
if (!a.isEmpty()) {
if (a == "clear-recent") {
recentScores.clear();
}
else {
2012-09-29 16:46:45 +02:00
Score* score = readScore(a);
if (score) {
setCurrentScoreView(appendScore(score));
updateRecentScores(score);
writeSessionFile(false);
}
}
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
// selectionChanged
//---------------------------------------------------------
void MuseScore::selectionChanged(SelState selectionState)
2012-05-26 14:49:10 +02:00
{
2014-05-26 13:21:04 +02:00
bool enable = selectionState != SelState::NONE;
2012-05-26 14:49:10 +02:00
getAction("cut")->setEnabled(enable);
getAction("copy")->setEnabled(enable);
2014-07-14 13:24:47 +02:00
getAction("select-similar-range")->setEnabled(selectionState == SelState::RANGE);
2012-05-26 14:49:10 +02:00
if (pianorollEditor)
pianorollEditor->changeSelection(selectionState);
2012-05-26 14:49:10 +02:00
if (drumrollEditor)
drumrollEditor->changeSelection(selectionState);
2012-07-12 15:35:35 +02:00
updateInspector();
}
//---------------------------------------------------------
// updateInspector
//---------------------------------------------------------
void MuseScore::updateInspector()
{
2014-08-29 19:18:39 +02:00
if (!_inspector)
2012-07-12 15:35:35 +02:00
return;
if (cs) {
if (state() == STATE_EDIT)
2014-08-29 19:18:39 +02:00
_inspector->setElement(cv->getEditObject());
2012-07-12 15:35:35 +02:00
else if (state() == STATE_FOTO)
2014-08-29 19:18:39 +02:00
_inspector->setElement(cv->fotoLasso());
2012-07-12 15:35:35 +02:00
else {
2014-08-29 19:18:39 +02:00
_inspector->setElements(cs->selection().elements());
2012-05-26 14:49:10 +02:00
}
}
2012-07-12 15:35:35 +02:00
else
2014-08-29 19:18:39 +02:00
_inspector->setElement(0);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// appendScore
// append score to project list
//---------------------------------------------------------
int MuseScore::appendScore(Score* score)
{
int index = scoreList.size();
for (int i = 0; i < scoreList.size(); ++i) {
if (scoreList[i]->filePath() == score->filePath() && score->fileInfo()->exists()) {
2012-05-26 14:49:10 +02:00
removeTab(i);
index = i;
break;
}
}
scoreList.insert(index, score);
tab1->blockSignals(true);
if (tab2)
tab2->blockSignals(true);
tab1->insertTab(score);
if (tab2)
tab2->insertTab(score);
tab1->blockSignals(false);
if (tab2)
tab2->blockSignals(false);
return index;
}
//---------------------------------------------------------
// updateRecentScores
//---------------------------------------------------------
void MuseScore::updateRecentScores(Score* score)
{
QString path = score->fileInfo()->absoluteFilePath();
recentScores.removeAll(path);
recentScores.prepend(path);
if(recentScores.size() > RECENT_LIST_SIZE) {
2012-07-09 14:16:27 +02:00
recentScores.removeLast();
}
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// updateTabNames
//---------------------------------------------------------
void MuseScore::updateTabNames()
{
for (int i = 0; i < tab1->count(); ++i) {
ScoreView* view = tab1->view(i);
if (view)
tab1->setTabText(i, view->score()->name());
}
if (tab2) {
for (int i = 0; i < tab2->count(); ++i) {
ScoreView* view = tab2->view(i);
if (view)
tab2->setTabText(i, view->score()->name());
}
}
}
//---------------------------------------------------------
// usage
//---------------------------------------------------------
static void usage()
{
printVersion("MuseScore");
2014-05-17 13:03:57 +02:00
fprintf(stderr, "Usage: mscore flags scorefile\n"
2014-03-04 16:48:06 +01:00
" Flags:\n"
2012-05-26 14:49:10 +02:00
" -v print version\n"
" -d debug mode\n"
" -L layout debug\n"
" -s no internal synthesizer\n"
" -m no midi\n"
" -a driver use audio driver: jack alsa pulse portaudio\n"
2012-05-26 14:49:10 +02:00
" -n start with new score\n"
" -I dump midi input\n"
" -O dump midi output\n"
" -o file export to 'file'; format depends on file extension\n"
" -r dpi set output resolution for image export\n"
" -S style load style file\n"
" -p name execute named plugin\n"
" -F use factory settings\n"
" -R revert to default preferences\n"
2012-05-26 14:49:10 +02:00
" -i load icons from INSTALLPATH/icons\n"
" -e enable experimental features\n"
" -c dir override config/settings folder\n"
" -t set testMode flag for all files\n"
" -M file specify MIDI import operations file\n"
2014-05-17 13:03:57 +02:00
);
2014-06-03 15:28:10 +02:00
2012-05-26 14:49:10 +02:00
exit(-1);
}
//---------------------------------------------------------
// loadScoreList
// read list of "Recent Scores"
//---------------------------------------------------------
void MuseScore::loadScoreList()
{
if (useFactorySettings)
return;
QSettings s;
for (int i = RECENT_LIST_SIZE-1; i >= 0; --i) {
QString path = s.value(QString("recent-%1").arg(i),"").toString();
if (!path.isEmpty() && QFileInfo(path).exists()) {
recentScores.removeAll(path);
recentScores.prepend(path);
}
}
}
//---------------------------------------------------------
// openRecentMenu
//---------------------------------------------------------
void MuseScore::openRecentMenu()
{
openRecent->clear();
bool one = false;
2012-05-26 14:49:10 +02:00
foreach(QString s, recentScores) {
if (s.isEmpty())
break;
QString data(s);
QFileInfo fi(s);
if(fi.exists()) {
2014-05-02 10:43:43 +02:00
QAction* action = openRecent->addAction(fi.fileName().replace("&", "&&")); // show filename only
action->setData(data);
action->setToolTip(s);
one = true;
}
}
if (one) {
openRecent->addSeparator();
QAction* action = openRecent->addAction(tr("Clear Recent Files"));
action->setData("clear-recent");
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
// setCurrentView
//---------------------------------------------------------
void MuseScore::setCurrentScoreView(int idx)
{
setCurrentView(0, idx);
if (tab2)
setCurrentView(1, idx);
2012-05-26 14:49:10 +02:00
}
void MuseScore::setCurrentView(int tabIdx, int idx)
{
if (idx == -1)
2013-02-15 22:39:56 +01:00
setCurrentScoreView(nullptr);
2012-05-26 14:49:10 +02:00
else {
ScoreTab* tab = tabIdx ? tab2 : tab1;
2013-02-15 22:39:56 +01:00
if (tab)
2012-05-26 14:49:10 +02:00
tab->setCurrentIndex(idx);
}
}
//---------------------------------------------------------
// setCurrentScoreView
//---------------------------------------------------------
void MuseScore::setCurrentScoreView(ScoreView* view)
{
cv = view;
if (cv) {
2014-07-28 10:56:50 +02:00
if (cv->score() && (cs != cv->score())) {
// exit note entry mode
if (cv->noteEntryMode()) {
cv->cmd(getAction("escape"));
qApp->processEvents();
}
2012-05-26 14:49:10 +02:00
updateInputState(cv->score());
2014-07-28 10:56:50 +02:00
}
2012-05-26 14:49:10 +02:00
cs = cv->score();
view->setFocusRect();
}
else
cs = 0;
// set midi import panel
QString fileName = cs ? cs->importedFilePath() : "";
midiPanelOnSwitchToFile(fileName);
if (enableExperimental) {
updateLayer();
updatePlayMode();
}
2012-05-26 14:49:10 +02:00
if (seq)
seq->setScoreView(cv);
if (playPanel)
playPanel->setScore(cs);
if (synthControl)
synthControl->setScore(cs);
if (selectionWindow)
selectionWindow->setScore(cs);
2013-04-03 12:13:23 +02:00
if (mixer)
mixer->updateAll(cs);
2012-05-26 14:49:10 +02:00
#ifdef OMR
if (omrPanel) {
if (cv && cv->omrView())
omrPanel->setOmrView(cv->omrView());
else
omrPanel->setOmrView(0);
}
#endif
if (!cs) {
setWindowTitle("MuseScore");
if (_navigator && _navigator->widget()) {
navigator()->setScoreView(view);
2013-05-08 10:54:06 +02:00
navigator()->setScore(0);
}
2014-08-29 19:18:39 +02:00
if (_inspector)
_inspector->setElement(0);
2012-05-26 14:49:10 +02:00
viewModeCombo->setEnabled(false);
2013-02-25 21:57:11 +01:00
if (_textTools) {
2013-02-15 22:39:56 +01:00
_textTools->hide();
2013-02-25 21:57:11 +01:00
if (textPalette)
textPalette->hide();
}
2013-02-15 22:39:56 +01:00
if (_pianoTools)
_pianoTools->hide();
if (_drumTools)
_drumTools->hide();
changeState(STATE_DISABLED);
2012-05-26 14:49:10 +02:00
return;
}
viewModeCombo->setEnabled(true);
if (cs->layoutMode() == LayoutMode::PAGE)
2012-05-26 14:49:10 +02:00
viewModeCombo->setCurrentIndex(0);
else
viewModeCombo->setCurrentIndex(1);
selectionChanged(cs->selection().state());
2013-02-15 22:39:56 +01:00
_sstate = STATE_DISABLED; // defeat optimization
2012-05-26 14:49:10 +02:00
changeState(view->mscoreState());
view->setFocus(Qt::OtherFocusReason);
getAction("file-save")->setEnabled(cs->isSavable());
getAction("show-invisible")->setChecked(cs->showInvisible());
getAction("show-unprintable")->setChecked(cs->showUnprintable());
getAction("show-frames")->setChecked(cs->showFrames());
getAction("show-pageborders")->setChecked(cs->showPageborders());
updateUndoRedo();
if (view->magIdx() == MagIdx::MAG_FREE)
2012-05-26 14:49:10 +02:00
mag->setMag(view->mag());
else
mag->setCurrentIndex(int(view->magIdx()));
2012-05-26 14:49:10 +02:00
setWindowTitle("MuseScore: " + cs->name());
QAction* a = getAction("concert-pitch");
2014-05-26 15:31:36 +02:00
a->setChecked(cs->styleB(StyleIdx::concertPitch));
2012-05-26 14:49:10 +02:00
setPos(cs->inputPos());
//showMessage(cs->filePath(), 2000);
2012-05-26 14:49:10 +02:00
if (_navigator && _navigator->widget())
2013-05-08 10:54:06 +02:00
navigator()->setScoreView(view);
ScoreAccessibility::instance()->updateAccessibilityInfo();
2012-05-26 14:49:10 +02:00
}
2013-05-24 18:40:15 +02:00
//---------------------------------------------------------
// showMessage
//---------------------------------------------------------
void MuseScore::showMessage(const QString& s, int timeout)
{
_statusBar->showMessage(s, timeout);
}
2013-05-17 20:11:36 +02:00
//---------------------------------------------------------
// midiPanel
2013-05-17 20:11:36 +02:00
//---------------------------------------------------------
void MuseScore::midiPanelOnSwitchToFile(const QString &file)
2013-05-17 20:11:36 +02:00
{
bool isMidiFile = ImportMidiPanel::isMidiFile(file);
if (isMidiFile) {
importmidiPanel->setMidiFile(file);
2014-07-29 21:58:36 +02:00
if (importmidiPanel->isPreferredVisible())
importmidiPanel->setVisible(true);
2013-05-17 20:11:36 +02:00
}
else
importmidiPanel->setVisible(false);
2014-07-29 21:58:36 +02:00
importmidiShowPanel->setVisible(!importmidiPanel->isPreferredVisible() && isMidiFile);
}
void MuseScore::midiPanelOnCloseFile(const QString &file)
{
if (ImportMidiPanel::isMidiFile(file))
importmidiPanel->excludeMidiFile(file);
}
void MuseScore::allowShowMidiPanel(const QString &file)
{
if (ImportMidiPanel::isMidiFile(file))
2014-07-29 21:58:36 +02:00
importmidiPanel->setPreferredVisible(true);
2013-05-17 20:11:36 +02:00
}
2014-07-29 21:58:36 +02:00
void MuseScore::setMidiReopenInProgress(const QString &file)
2013-07-23 13:05:19 +02:00
{
if (ImportMidiPanel::isMidiFile(file))
importmidiPanel->setReopenInProgress();
}
void MuseScore::showMidiImportPanel()
{
2014-07-29 21:58:36 +02:00
importmidiPanel->setPreferredVisible(true);
QString fileName = cs ? cs->importedFilePath() : "";
if (ImportMidiPanel::isMidiFile(fileName))
importmidiPanel->setVisible(true);
importmidiShowPanel->hide();
2013-07-23 13:05:19 +02:00
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
// dragEnterEvent
//---------------------------------------------------------
void MuseScore::dragEnterEvent(QDragEnterEvent* event)
{
const QMimeData* data = event->mimeData();
if (data->hasUrls()) {
QList<QUrl>ul = event->mimeData()->urls();
foreach(const QUrl& u, ul) {
if (MScore::debugMode)
2014-10-16 18:12:58 +02:00
qDebug("drag Url: %s scheme <%s>", qPrintable(u.toString()), qPrintable(u.scheme()));
2012-05-26 14:49:10 +02:00
if (u.scheme() == "file") {
2014-10-16 18:12:58 +02:00
// QFileInfo fi(u.toLocalFile());
2012-05-26 14:49:10 +02:00
event->acceptProposedAction();
break;
}
}
}
}
//---------------------------------------------------------
// dropEvent
//---------------------------------------------------------
void MuseScore::dropEvent(QDropEvent* event)
{
const QMimeData* data = event->mimeData();
if (data->hasUrls()) {
int view = -1;
foreach(const QUrl& u, event->mimeData()->urls()) {
if (u.scheme() == "file") {
2013-04-28 21:29:12 +02:00
QString file = u.toLocalFile();
Score* score = readScore(file);
2012-09-29 16:46:45 +02:00
if (score) {
2012-05-26 14:49:10 +02:00
view = appendScore(score);
updateRecentScores(score);
}
2012-05-26 14:49:10 +02:00
}
}
2014-10-16 18:12:58 +02:00
if (view != -1) {
2012-05-26 14:49:10 +02:00
setCurrentScoreView(view);
writeSessionFile(false);
}
2012-05-26 14:49:10 +02:00
else {
QMessageBox::critical(0,
tr("MuseScore: Load Error"),
tr("Open failed: Unknown file extension or broken file"));
2012-05-26 14:49:10 +02:00
}
event->acceptProposedAction();
}
}
//---------------------------------------------------------
// showPageSettings
//---------------------------------------------------------
void MuseScore::showPageSettings()
{
if (pageSettings == 0)
pageSettings = new PageSettings();
pageSettings->setScore(cs);
pageSettings->show();
pageSettings->raise();
}
//---------------------------------------------------------
// startDebugger
//---------------------------------------------------------
void MuseScore::startDebugger()
{
if (!cs)
return;
if (debugger == 0)
debugger = new Debugger(this);
debugger->updateList(cs);
debugger->show();
}
//---------------------------------------------------------
// showElementContext
//---------------------------------------------------------
void MuseScore::showElementContext(Element* el)
{
if (el == 0)
return;
startDebugger();
debugger->setElement(el);
}
//---------------------------------------------------------
// showPlayPanel
//---------------------------------------------------------
void MuseScore::showPlayPanel(bool visible)
{
if (noSeq || !(seq && seq->isRunning()))
2012-05-26 14:49:10 +02:00
return;
if (playPanel == 0) {
if (!visible)
return;
playPanel = new PlayPanel(this);
2013-04-03 12:49:55 +02:00
connect(playPanel, SIGNAL(gainChange(float)), synti, SLOT(setGain(float)));
2012-05-26 14:49:10 +02:00
connect(playPanel, SIGNAL(relTempoChanged(double)),seq, SLOT(setRelTempo(double)));
connect(playPanel, SIGNAL(posChange(int)), seq, SLOT(seek(int)));
connect(playPanel, SIGNAL(closed(bool)), playId, SLOT(setChecked(bool)));
2013-04-03 12:49:55 +02:00
connect(synti, SIGNAL(gainChanged(float)), playPanel, SLOT(setGain(float)));
2012-05-26 14:49:10 +02:00
2013-04-03 12:49:55 +02:00
playPanel->setGain(synti->gain());
2012-05-26 14:49:10 +02:00
playPanel->setScore(cs);
// playPanel->move(preferences.playPanelPos);
2012-05-26 14:49:10 +02:00
}
playPanel->setVisible(visible);
playId->setChecked(visible);
}
//---------------------------------------------------------
// cmdAppendMeasures
//---------------------------------------------------------
void MuseScore::cmdAppendMeasures()
{
if (cs) {
2013-04-28 21:29:12 +02:00
if (measuresDialog == 0)
2012-05-26 14:49:10 +02:00
measuresDialog = new MeasuresDialog;
measuresDialog->show();
}
}
//---------------------------------------------------------
// MeasuresDialog
//---------------------------------------------------------
MeasuresDialog::MeasuresDialog(QWidget* parent)
: QDialog(parent)
{
2012-05-26 14:49:10 +02:00
setupUi(this);
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
measures->selectAll();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// accept
//---------------------------------------------------------
void MeasuresDialog::accept()
2013-04-28 21:29:12 +02:00
{
int n = measures->value();
2012-05-26 14:49:10 +02:00
if (mscore->currentScore())
mscore->currentScoreView()->cmdAppendMeasures(n, Element::Type::MEASURE);
2012-05-26 14:49:10 +02:00
done(1);
2013-04-28 21:29:12 +02:00
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
// midiinToggled
//---------------------------------------------------------
void MuseScore::midiinToggled(bool val)
{
_midiinEnabled = val;
}
//---------------------------------------------------------
// midiinEnabled
//---------------------------------------------------------
bool MuseScore::midiinEnabled() const
{
return preferences.enableMidiInput && _midiinEnabled;
}
//---------------------------------------------------------
// processMidiRemote
// return if midi remote command detected
//---------------------------------------------------------
bool MuseScore::processMidiRemote(MidiRemoteType type, int data)
{
if (!preferences.useMidiRemote)
return false;
for (int i = 0; i < MIDI_REMOTES; ++i) {
if (preferences.midiRemote[i].type == type && preferences.midiRemote[i].data == data) {
if (cv == 0)
return false;
QAction* a = 0;
switch (i) {
case RMIDI_REWIND: a = getAction("rewind"); break;
case RMIDI_TOGGLE_PLAY: a = getAction("play"); break;
case RMIDI_PLAY:
a = getAction("play");
if (a->isChecked())
return true;
break;
case RMIDI_STOP:
a = getAction("play");
if (!a->isChecked())
return true;
break;
case RMIDI_NOTE1: a = getAction("pad-note-1"); break;
case RMIDI_NOTE2: a = getAction("pad-note-2"); break;
case RMIDI_NOTE4: a = getAction("pad-note-4"); break;
case RMIDI_NOTE8: a = getAction("pad-note-8"); break;
case RMIDI_NOTE16: a = getAction("pad-note-16"); break;
case RMIDI_NOTE32: a = getAction("pad-note-32"); break;
case RMIDI_NOTE64: a = getAction("pad-note-64"); break;
case RMIDI_REST: a = getAction("rest"); break;
case RMIDI_DOT: a = getAction("dot"); break;
case RMIDI_DOTDOT: a = getAction("dotdot"); break;
case RMIDI_TIE: a = getAction("tie"); break;
case RMIDI_NOTE_EDIT_MODE: a = getAction("note-input"); break;
}
if (a)
a->trigger();
return true;
}
}
return false;
}
//---------------------------------------------------------
// midiNoteReceived
//---------------------------------------------------------
void MuseScore::midiNoteReceived(int channel, int pitch, int velo)
{
static const int THRESHOLD = 3; // iterations required before consecutive drum notes
// are not considered part of a chord
static int active = 0;
static int iter = 0;
if (!midiinEnabled())
return;
// qDebug("midiNoteReceived %d %d %d", channel, pitch, velo);
if (_midiRecordId != -1) {
preferences.midiRemote[_midiRecordId].type = MIDI_REMOTE_TYPE_NOTEON;
preferences.midiRemote[_midiRecordId].data = pitch;
_midiRecordId = -1;
if (preferenceDialog)
preferenceDialog->updateRemote();
return;
}
2012-10-29 16:37:24 +01:00
if (velo && processMidiRemote(MIDI_REMOTE_TYPE_NOTEON, pitch)) {
2012-05-26 14:49:10 +02:00
active = 0;
return;
}
2012-10-29 16:37:24 +01:00
2012-05-26 14:49:10 +02:00
QWidget* w = QApplication::activeModalWidget();
if (!cv || w) {
active = 0;
return;
}
if (velo) {
/*
* Since some drum modules do not overlap note on / off messages
* we need to take a bit of a different tactic to allow chords
* to be entered.
*
* Rather than decrement active for drums (midi on ch10),
* we'll just assume that if read() has been called a couple
* times in a row without a drum note, that this note is not
* part of a cord.
*/
if (channel == 0x09) {
if (iter >= THRESHOLD)
active = 0;
iter = 0;
}
// qDebug(" midiNoteReceived %d active %d", pitch, active);
cv->midiNoteReceived(pitch, active > 0);
2012-05-26 14:49:10 +02:00
++active;
}
else {
if (channel != 0x09)
--active;
}
}
//---------------------------------------------------------
// midiCtrlReceived
//---------------------------------------------------------
void MuseScore::midiCtrlReceived(int controller, int /*value*/)
{
if (!midiinEnabled())
return;
if (_midiRecordId != -1) {
preferences.midiRemote[_midiRecordId].type = MIDI_REMOTE_TYPE_CTRL;
preferences.midiRemote[_midiRecordId].data = controller;
_midiRecordId = -1;
if (preferenceDialog)
preferenceDialog->updateRemote();
return;
}
if (processMidiRemote(MIDI_REMOTE_TYPE_CTRL, controller))
return;
}
//---------------------------------------------------------
// playEnabled
//---------------------------------------------------------
bool MuseScore::playEnabled() const
{
return preferences.playNotes;
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// removeTab
//---------------------------------------------------------
void MuseScore::removeTab()
{
int n = scoreList.indexOf(cs);
if (n == -1) {
qDebug("removeTab: %p not found", cs);
return;
}
removeTab(n);
}
void MuseScore::removeTab(int i)
{
Score* score = scoreList.value(i);
2012-09-12 16:19:03 +02:00
2012-05-26 14:49:10 +02:00
if (score == 0)
return;
QString tmpName = score->tmpName();
2012-05-26 14:49:10 +02:00
if (checkDirty(score))
return;
if (seq && seq->score() == score) {
seq->stopWait();
2012-05-26 14:49:10 +02:00
seq->setScoreView(0);
2013-02-07 00:19:53 +01:00
}
2012-05-26 14:49:10 +02:00
int idx1 = tab1->currentIndex();
bool firstTab = tab1->view(idx1) == cv;
midiPanelOnCloseFile(score->importedFilePath());
2012-05-26 14:49:10 +02:00
scoreList.removeAt(i);
2012-05-26 14:49:10 +02:00
tab1->blockSignals(true);
tab1->removeTab(i);
tab1->blockSignals(false);
if (tab2) {
tab2->blockSignals(true);
tab2->removeTab(i);
tab2->blockSignals(false);
}
cs = 0;
cv = 0;
int n = scoreList.size();
2013-02-15 22:39:56 +01:00
if (n == 0)
setCurrentScoreView(nullptr);
else
2012-05-26 14:49:10 +02:00
setCurrentScoreView((firstTab ? tab1 : tab2)->view());
writeSessionFile(false);
if (!tmpName.isEmpty()) {
QFile f(tmpName);
2012-05-26 14:49:10 +02:00
f.remove();
}
delete score;
// Shouldn't be necessary... but fix #21841
update();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// loadTranslation
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
void loadTranslation(QString filename, QString localeName)
2012-05-26 14:49:10 +02:00
{
static QList<QTranslator*> translatorList;
QTranslator* translator = new QTranslator;
QString userPrefix = dataPath + "/locale/"+ filename +"_";
QString defaultPrefix = mscoreGlobalShare + "locale/"+ filename +"_";
QString userlp = userPrefix + localeName;
QString defaultlp = defaultPrefix + localeName;
QString lp = defaultlp;
QFileInfo userFi(userlp + ".qm");
QFileInfo defaultFi(defaultlp + ".qm");
if(!defaultFi.exists()) { // try with a shorter locale name
QString shortLocaleName = localeName.left(localeName.lastIndexOf("_"));
QString shortDefaultlp = defaultPrefix + shortLocaleName;
QFileInfo shortDefaultFi(shortDefaultlp + ".qm");
if(shortDefaultFi.exists()) {
userlp = userPrefix + shortLocaleName;
userFi = QFileInfo(userlp + ".qm");
defaultFi = shortDefaultFi;
defaultlp = shortDefaultlp;
}
2014-09-06 07:52:20 +02:00
}
// qDebug() << userFi.exists();
// qDebug() << userFi.lastModified() << defaultFi.lastModified();
2014-08-28 14:50:17 +02:00
if (userFi.exists()) {
if (userFi.lastModified() > defaultFi.lastModified())
lp = userlp;
else
QFile::remove(userlp + ".qm");
}
if (MScore::debugMode) qDebug("load translator <%s>", qPrintable(lp));
bool success = translator->load(lp);
if (!success && MScore::debugMode) {
qDebug("load translator <%s> failed", qPrintable(lp));
}
if(success) {
qApp->installTranslator(translator);
translatorList.append(translator);
}
}
//---------------------------------------------------------
// setLocale
//---------------------------------------------------------
void setMscoreLocale(QString localeName)
{
static QList<QTranslator*> translatorList;
foreach(QTranslator* t, translatorList) {
qApp->removeTranslator(t);
delete t;
}
translatorList.clear();
if (MScore::debugMode)
qDebug("configured localeName <%s>", qPrintable(localeName));
if (localeName.toLower() == "system") {
localeName = QLocale::system().name();
if (MScore::debugMode)
qDebug("real localeName <%s>", qPrintable(localeName));
}
2012-05-26 14:49:10 +02:00
// find the most recent translation file
// try to replicate QTranslator.load algorithm in our particular case
loadTranslation("mscore", localeName);
loadTranslation("instruments", localeName);
2012-05-26 14:49:10 +02:00
QString resourceDir;
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
2012-05-26 14:49:10 +02:00
resourceDir = mscoreGlobalShare + "locale/";
#else
resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
#endif
QTranslator* qtTranslator = new QTranslator;
if (MScore::debugMode)
qDebug("load translator <qt_%s> from <%s>",
qPrintable(localeName), qPrintable(resourceDir));
if (!qtTranslator->load(QLatin1String("qt_") + localeName, resourceDir) && MScore::debugMode)
qDebug("load translator <qt_%s> failed", qPrintable(localeName));
else {
qApp->installTranslator(qtTranslator);
translatorList.append(qtTranslator);
}
2013-10-08 19:25:04 +02:00
QLocale::setDefault(QLocale(localeName));
2012-05-26 14:49:10 +02:00
// initShortcuts();
}
//---------------------------------------------------------
// loadScores
// load scores for a new session
//---------------------------------------------------------
static void loadScores(const QStringList& argv)
{
int currentScoreView = 0;
if (argv.isEmpty()) {
if (startWithNewScore)
mscore->newFile();
else {
switch (preferences.sessionStart) {
2014-07-01 14:44:45 +02:00
case SessionStart::LAST:
2012-05-26 14:49:10 +02:00
{
QSettings settings;
int n = settings.value("scores", 0).toInt();
int c = settings.value("currentScore", 0).toInt();
for (int i = 0; i < n; ++i) {
QString s = settings.value(QString("score-%1").arg(i),"").toString();
2012-09-29 16:46:45 +02:00
Score* score = mscore->readScore(s);
if (score) {
2012-05-26 14:49:10 +02:00
int view = mscore->appendScore(score);
if (i == c)
currentScoreView = view;
}
}
}
break;
2014-07-01 14:44:45 +02:00
case SessionStart::EMPTY:
2012-05-26 14:49:10 +02:00
break;
2014-07-01 14:44:45 +02:00
case SessionStart::NEW:
2012-05-26 14:49:10 +02:00
mscore->newFile();
break;
2014-07-01 14:44:45 +02:00
case SessionStart::SCORE:
2012-05-26 14:49:10 +02:00
{
2012-09-29 16:46:45 +02:00
Score* score = mscore->readScore(preferences.startScore);
if (preferences.startScore.startsWith(":/"))
score->setCreated(true);
if (score == 0) {
score = mscore->readScore(":/data/My_First_Score.mscx");
score->setCreated(true);
}
2012-09-29 16:46:45 +02:00
if (score)
2012-05-26 14:49:10 +02:00
currentScoreView = mscore->appendScore(score);
}
break;
}
}
}
else {
foreach(const QString& name, argv) {
if (name.isEmpty())
continue;
2012-09-29 16:46:45 +02:00
Score* score = mscore->readScore(name);
if (score) {
2012-05-26 14:49:10 +02:00
mscore->appendScore(score);
2014-02-28 11:14:43 +01:00
if(!MScore::noGui) {
mscore->updateRecentScores(score);
mscore->writeSessionFile(false);
}
2012-05-26 14:49:10 +02:00
}
}
}
if (mscore->noScore())
currentScoreView = -1;
mscore->setCurrentView(0, currentScoreView);
mscore->setCurrentView(1, currentScoreView);
}
//---------------------------------------------------------
// processNonGui
//---------------------------------------------------------
static bool processNonGui()
{
if (pluginMode) {
QString pn(pluginName);
bool res = false;
if (mscore->loadPlugin(pn)){
Score* cs = mscore->currentScore();
if (!styleFile.isEmpty()) {
QFile f(styleFile);
if (f.open(QIODevice::ReadOnly))
cs->style()->load(&f);
}
cs->startCmd();
cs->setLayoutAll(true);
cs->endCmd();
mscore->pluginTriggered(0);
res = true;
}
if (!converterMode)
return res;
}
if (converterMode) {
QString fn(outFileName);
Score* cs = mscore->currentScore();
if (!styleFile.isEmpty()) {
QFile f(styleFile);
if (f.open(QIODevice::ReadOnly)) {
cs->style()->load(&f);
}
}
if (fn.endsWith(".mscx")) {
QFileInfo fi(fn);
try {
cs->saveFile(fi);
}
catch(QString) {
return false;
}
return true;
}
if (fn.endsWith(".mscz")) {
QFileInfo fi(fn);
try {
cs->saveCompressedFile(fi, false);
}
catch(QString) {
return false;
}
return true;
}
if (fn.endsWith(".xml"))
2012-09-27 21:34:36 +02:00
return saveXml(cs, fn);
2012-05-26 14:49:10 +02:00
if (fn.endsWith(".mxl"))
2012-09-27 21:34:36 +02:00
return saveMxl(cs, fn);
2012-05-26 14:49:10 +02:00
if (fn.endsWith(".mid"))
return mscore->saveMidi(cs, fn);
2012-05-26 14:49:10 +02:00
if (fn.endsWith(".pdf"))
return mscore->savePdf(fn);
2012-05-26 14:49:10 +02:00
if (fn.endsWith(".png"))
return mscore->savePng(cs, fn);
if (fn.endsWith(".svg"))
return mscore->saveSvg(cs, fn);
2013-06-12 14:23:57 +02:00
// if (fn.endsWith(".ly"))
// return mscore->saveLilypond(cs, fn);
2012-05-26 14:49:10 +02:00
#ifdef HAS_AUDIOFILE
if (fn.endsWith(".wav"))
return mscore->saveAudio(cs, fn, "wav");
if (fn.endsWith(".ogg"))
return mscore->saveAudio(cs, fn, "ogg");
if (fn.endsWith(".flac"))
return mscore->saveAudio(cs, fn, "flac");
#endif
if (fn.endsWith(".mp3"))
return mscore->saveMp3(cs, fn);
2014-07-13 18:33:26 +02:00
if (fn.endsWith(".spos"))
return savePositions(cs, fn, true);
if (fn.endsWith(".mpos"))
return savePositions(cs, fn, false);
2012-05-26 14:49:10 +02:00
else {
qDebug("dont know how to convert to %s", qPrintable(outFileName));
return false;
}
}
return true;
}
//---------------------------------------------------------
// StartDialog
//---------------------------------------------------------
StartDialog::StartDialog(QWidget* parent)
: QDialog(parent)
{
setupUi(this);
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
2012-05-26 14:49:10 +02:00
setWindowTitle(tr("MuseScore Startup Dialog"));
connect(createScore, SIGNAL(clicked()), SLOT(createScoreClicked()));
connect(loadScore, SIGNAL(clicked()), SLOT(loadScoreClicked()));
}
//---------------------------------------------------------
// createScoreClicked
//---------------------------------------------------------
void StartDialog::createScoreClicked()
{
done(1);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// loadScoreClicked
//---------------------------------------------------------
void StartDialog::loadScoreClicked()
{
done(2);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// Message handler
//---------------------------------------------------------
#if defined(QT_DEBUG) && defined(Q_OS_WIN)
static void mscoreMessageHandler(QtMsgType type, const QMessageLogContext &context,const QString &msg)
2012-05-26 14:49:10 +02:00
{
QTextStream cerr(stderr);
QByteArray localMsg = msg.toLocal8Bit();
2014-02-28 14:25:47 +01:00
2012-05-26 14:49:10 +02:00
switch (type) {
case QtDebugMsg:
cerr << "Debug: " << localMsg.constData() << " (" << context.file << ":" << context.line << ", " << context.function << ")" << endl;
2012-05-26 14:49:10 +02:00
break;
case QtWarningMsg:
cerr << "Warning: " << localMsg.constData() << " (" << context.file << ":" << context.line << ", " << context.function << ")" << endl;
2012-05-26 14:49:10 +02:00
break;
case QtCriticalMsg:
cerr << "Critical: " << localMsg.constData() << " (" << context.file << ":" << context.line << ", " << context.function << ")" << endl;
2012-05-26 14:49:10 +02:00
break;
case QtFatalMsg: // set your breakpoint here, if you want to catch the abort
cerr << "Fatal: " << localMsg.constData() << " (" << context.file << ":" << context.line << ", " << context.function << ")" << endl;
2012-05-26 14:49:10 +02:00
abort();
}
}
#endif
//---------------------------------------------------------
// synthesizerFactory
// create and initialize the master synthesizer
//---------------------------------------------------------
MasterSynthesizer* synthesizerFactory()
{
MasterSynthesizer* ms = new MasterSynthesizer();
2013-04-03 12:13:23 +02:00
FluidS::Fluid* fluid = new FluidS::Fluid();
ms->registerSynthesizer(fluid);
2013-04-03 20:20:36 +02:00
#ifdef AEOLUS
2013-05-13 18:49:17 +02:00
ms->registerSynthesizer(::createAeolus());
2013-04-03 20:20:36 +02:00
#endif
#ifdef ZERBERUS
ms->registerSynthesizer(createZerberus());
2013-04-03 20:20:36 +02:00
#endif
ms->registerEffect(0, new NoEffect);
ms->registerEffect(0, new ZitaReverb);
2013-05-13 18:49:17 +02:00
// ms->registerEffect(0, new Freeverb);
ms->registerEffect(1, new NoEffect);
ms->registerEffect(1, new ZitaReverb);
2013-05-13 18:49:17 +02:00
// ms->registerEffect(1, new Freeverb);
ms->setEffect(0, 1);
ms->setEffect(1, 0);
return ms;
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// unstable
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
bool MuseScore::unstable()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
#ifdef MSCORE_UNSTABLE
return true;
2012-05-26 14:49:10 +02:00
#else
2013-05-13 18:49:17 +02:00
return false;
2012-05-26 14:49:10 +02:00
#endif
2013-05-13 18:49:17 +02:00
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// MuseScoreApplication::event (mac only)
//---------------------------------------------------------
2013-04-17 14:00:26 +02:00
2013-05-13 18:49:17 +02:00
bool MuseScoreApplication::event(QEvent *event)
{
switch(event->type()) {
case QEvent::FileOpen:
2013-06-24 22:07:44 +02:00
// store names of files requested to be loaded by OS X to be handled later
// this event is generated when a file is dragged onto the MuseScore icon
// in the dock and MuseScore is not running yet
2013-05-13 18:49:17 +02:00
paths.append(static_cast<QFileOpenEvent *>(event)->file());
return true;
default:
return QtSingleApplication::event(event);
2013-05-08 15:27:43 +02:00
}
2013-05-13 18:49:17 +02:00
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// eventFilter (mac only)
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
bool MuseScore::eventFilter(QObject *obj, QEvent *event)
{
switch(event->type()) {
case QEvent::FileOpen:
2013-06-24 22:07:44 +02:00
// open files requested to be loaded by OS X
// this event is generated when a file is dragged onto the MuseScore icon
// in the dock when MuseScore is already running
2013-05-13 18:49:17 +02:00
handleMessage(static_cast<QFileOpenEvent *>(event)->file());
return true;
default:
return QMainWindow::eventFilter(obj, event);
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// hasToCheckForUpdate
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
bool MuseScore::hasToCheckForUpdate()
{
if (ucheck)
return ucheck->hasToCheck();
else
return false;
}
2013-03-01 17:14:21 +01:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// checkForUpdate
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
void MuseScore::checkForUpdate()
{
if (ucheck)
ucheck->check(revision(), sender() != 0);
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// readLanguages
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
bool MuseScore::readLanguages(const QString& path)
{
2014-02-24 22:42:07 +01:00
//: The default language of the operating system. NOT a music system.
_languages.append(LanguageItem("system", tr("System")));
2013-05-13 18:49:17 +02:00
QFile qf(path);
if (qf.exists()){
QDomDocument doc;
int line, column;
QString err;
if (!doc.setContent(&qf, false, &err, &line, &column)) {
QString error;
error.sprintf(qPrintable(tr("Error reading language file %s at line %d column %d: %s\n")),
2013-05-13 18:49:17 +02:00
qPrintable(qf.fileName()), line, column, qPrintable(err));
QMessageBox::warning(0,
QWidget::tr("MuseScore: Load Languages Failed:"),
2013-05-13 18:49:17 +02:00
error,
QString::null, QWidget::tr("Quit"), QString::null, 0, 1);
return false;
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
for (QDomElement e = doc.documentElement(); !e.isNull(); e = e.nextSiblingElement()) {
if(e.tagName() == "languages") {
for (e = e.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
if (e.tagName() == "language") {
QString code = e.attribute(QString("code"));
QString name = e.attribute(QString("name"));
QString handbook = e.attribute(QString("handbook"));
_languages.append(LanguageItem(code, name, handbook));
}
}
}
}
return true;
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
return false;
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// clipboardChanged
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
void MuseScore::clipboardChanged()
{
#if 0
const QMimeData* ms = QApplication::clipboard()->mimeData();
QStringList formats = ms->formats();
2012-06-11 14:38:33 +02:00
2013-05-13 18:49:17 +02:00
bool flag = ms->hasFormat(mimeSymbolFormat)
|| ms->hasFormat(mimeStaffListFormat)
|| ms->hasFormat(mimeSymbolListFormat)
|| ms->hasText();
// TODO: depends on selection state
#endif
2012-06-11 14:38:33 +02:00
2013-05-13 18:49:17 +02:00
bool flag = true;
getAction("paste")->setEnabled(flag);
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// showModeText
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
void MuseScore::showModeText(const QString& s)
{
_modeText->setText(s);
_modeText->show();
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// changeState
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::changeState(ScoreState val)
{
// printf("MuseScore::changeState: %s\n", stateName(val));
if (MScore::debugMode)
qDebug("MuseScore::changeState: %s", stateName(val));
2013-05-13 18:49:17 +02:00
// if (_sstate == val)
// return;
static const char* stdNames[] = {
"note-longa", "note-breve", "pad-note-1", "pad-note-2", "pad-note-4",
"pad-note-8", "pad-note-16", "pad-note-32", "pad-note-64", "pad-note-128", "pad-rest", "rest"};
2013-05-13 18:49:17 +02:00
static const char* tabNames[] = {
"note-longa-TAB", "note-breve-TAB", "pad-note-1-TAB", "pad-note-2-TAB", "pad-note-4-TAB",
"pad-note-8-TAB", "pad-note-16-TAB", "pad-note-32-TAB", "pad-note-64-TAB", "pad-note-128-TAB", "pad-rest-TAB", "rest-TAB"};
2013-05-13 18:49:17 +02:00
bool intoTAB = (_sstate != STATE_NOTE_ENTRY_TAB) && (val == STATE_NOTE_ENTRY_TAB);
bool fromTAB = (_sstate == STATE_NOTE_ENTRY_TAB) && (val != STATE_NOTE_ENTRY_TAB);
// if activating TAB note entry, swap "pad-note-...-TAB" shorctuts into "pad-note-..." actions
if (intoTAB) {
for (unsigned i = 0; i < sizeof(stdNames)/sizeof(char*); ++i) {
QAction* act = getAction(stdNames[i]);
Shortcut* srt = Shortcut::getShortcut(tabNames[i]);
act->setShortcuts(srt->keys());
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
}
// if de-ativating TAB note entry, restore shortcuts for "pad-note-..." actions
else if (fromTAB) {
for (unsigned i = 0; i < sizeof(stdNames)/sizeof(char*); ++i) {
QAction* act = getAction(stdNames[i]);
Shortcut* srt = Shortcut::getShortcut(stdNames[i]);
act->setShortcuts(srt->keys());
}
}
2013-10-05 14:03:34 +02:00
bool enable = (val != STATE_DISABLED) && (val != STATE_LOCK);
2013-05-13 18:49:17 +02:00
foreach (const Shortcut* s, Shortcut::shortcuts()) {
QAction* a = s->action();
if (!a)
continue;
if (enable && s->key() == "undo")
2013-05-13 18:49:17 +02:00
a->setEnabled((s->state() & val) && (cs ? cs->undo()->canUndo() : false));
else if (enable && s->key() == "redo")
2013-05-13 18:49:17 +02:00
a->setEnabled((s->state() & val) && (cs ? cs->undo()->canRedo() : false));
else if (enable && s->key() == "cut")
a->setEnabled(cs && cs->selection().state() != SelState::NONE);
else if (enable && s->key() == "copy")
a->setEnabled(cs && cs->selection().state() != SelState::NONE);
else if (enable && s->key() == "select-similar-range")
2014-07-14 13:24:47 +02:00
a->setEnabled(cs && cs->selection().state() == SelState::RANGE);
else if (enable && s->key() == "synth-control") {
2013-05-13 18:49:17 +02:00
Driver* driver = seq ? seq->driver() : 0;
// a->setEnabled(driver && driver->getSynth());
if (MScore::debugMode)
qDebug("disable synth control");
a->setEnabled(driver);
2013-04-12 10:21:13 +02:00
}
else {
a->setEnabled(s->state() & val);
2013-04-12 10:21:13 +02:00
}
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
// disabling top level menu entries does not
// work for MAC
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
QList<QObject*> ol = menuBar()->children();
foreach(QObject* o, ol) {
QMenu* menu = qobject_cast<QMenu*>(o);
if (!menu)
continue;
QString s(menu->objectName());
if (s == "File" || s == "Help" || s == "Edit" || s == "Plugins")
continue;
menu->setEnabled(enable);
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
menuWorkspaces->setEnabled(enable);
2012-05-26 14:49:10 +02:00
transportTools->setEnabled(enable && !noSeq && seq && seq->isRunning());
2013-05-13 18:49:17 +02:00
cpitchTools->setEnabled(enable);
mag->setEnabled(enable);
entryTools->setEnabled(enable);
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
if (_sstate == STATE_FOTO)
updateInspector();
if (_sstate == STATE_NOTE_ENTRY_DRUM)
showDrumTools(0, 0);
2013-03-01 17:14:21 +01:00
2013-05-13 18:49:17 +02:00
switch(val) {
case STATE_DISABLED:
showModeText(tr("no score"));
if (debugger)
debugger->hide();
showPianoKeyboard(false);
break;
case STATE_NORMAL:
_modeText->hide();
break;
case STATE_NOTE_ENTRY_PITCHED:
showModeText(tr("NOTE entry mode"));
break;
case STATE_NOTE_ENTRY_DRUM:
{
showModeText(tr("DRUM entry mode"));
InputState& is = cs->inputState();
showDrumTools(is.drumset(), cs->staff(is.track() / VOICES));
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
break;
case STATE_NOTE_ENTRY_TAB:
showModeText(tr("TAB entry mode"));
break;
case STATE_EDIT:
showModeText(tr("edit mode"));
break;
case STATE_TEXT_EDIT:
showModeText(tr("text edit mode"));
break;
case STATE_LYRICS_EDIT:
showModeText(tr("lyrics edit mode"));
break;
case STATE_HARMONY_FIGBASS_EDIT:
2013-11-03 16:49:02 +01:00
showModeText(tr("chord symbol/figured bass edit mode"));
2013-05-13 18:49:17 +02:00
break;
case STATE_PLAY:
showModeText(tr("play"));
break;
case STATE_FOTO:
showModeText(tr("screenshot mode"));
2013-05-13 18:49:17 +02:00
updateInspector();
break;
case STATE_LOCK:
showModeText(tr("score locked"));
2013-05-13 18:49:17 +02:00
break;
default:
qFatal("MuseScore::changeState: illegal state %d", val);
break;
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
if (paletteBox)
paletteBox->setDisabled(val == STATE_PLAY || val == STATE_DISABLED);
if (selectionWindow)
selectionWindow->setDisabled(val == STATE_PLAY || val == STATE_DISABLED);
2013-05-13 18:49:17 +02:00
QAction* a = getAction("note-input");
bool noteEntry = val == STATE_NOTE_ENTRY_PITCHED || val == STATE_NOTE_ENTRY_TAB || val == STATE_NOTE_ENTRY_DRUM;
a->setChecked(noteEntry);
_sstate = val;
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
Element* e = 0;
if (_sstate & STATE_ALLTEXTUAL_EDIT || _sstate == STATE_EDIT) {
2013-05-13 18:49:17 +02:00
if (cv)
e = cv->getEditObject();
}
if (!e) {
textTools()->hide();
if (textPalette)
textPalette->hide();
2012-05-26 14:49:10 +02:00
}
else {
2013-05-13 18:49:17 +02:00
if (e->isText()) {
textTools()->setText(static_cast<Text*>(e));
textTools()->updateTools();
if (e->type() != Element::Type::FIGURED_BASS && e->type() != Element::Type::HARMONY) // do not show text tools for f.b.
2014-03-28 10:49:19 +01:00
textTools()->show();
}
2014-08-29 19:18:39 +02:00
if (_inspector)
_inspector->setElement(e);
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// writeSettings
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::writeSettings()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
QSettings settings;
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.setValue("maximized", isMaximized());
settings.setValue("showPanel", paletteBox && paletteBox->isVisible());
2014-08-29 19:18:39 +02:00
settings.setValue("showInspector", _inspector && _inspector->isVisible());
2013-05-13 18:49:17 +02:00
settings.setValue("showPianoKeyboard", _pianoTools && _pianoTools->isVisible());
settings.setValue("showSelectionWindow", selectionWindow && selectionWindow->isVisible());
2013-05-13 18:49:17 +02:00
settings.setValue("state", saveState());
settings.setValue("splitScreen", _splitScreen);
settings.setValue("debuggerSplitter", mainWindow->saveState());
// if (_splitScreen) {
settings.setValue("split", _horizontalSplit);
settings.setValue("splitter", splitter->saveState());
// }
settings.endGroup();
Workspace::currentWorkspace->save();
if (keyEditor && keyEditor->dirty())
keyEditor->save();
if (chordStyleEditor)
chordStyleEditor->save();
if (loadScoreDialog)
settings.setValue("loadScoreDialog", loadScoreDialog->saveState());
if (saveScoreDialog)
settings.setValue("saveScoreDialog", saveScoreDialog->saveState());
if (loadStyleDialog)
settings.setValue("loadStyleDialog", loadStyleDialog->saveState());
if (saveStyleDialog)
settings.setValue("saveStyleDialog", saveStyleDialog->saveState());
if (saveImageDialog)
settings.setValue("saveImageDialog", saveImageDialog->saveState());
if (loadChordStyleDialog)
settings.setValue("loadChordStyleDialog", loadChordStyleDialog->saveState());
if (saveChordStyleDialog)
settings.setValue("saveChordStyleDialog", saveChordStyleDialog->saveState());
if (loadSoundFontDialog)
settings.setValue("loadSoundFontDialog", loadSoundFontDialog->saveState());
if (loadScanDialog)
settings.setValue("loadScanDialog", loadScanDialog->saveState());
if (loadAudioDialog)
settings.setValue("loadAudioDialog", loadAudioDialog->saveState());
if (loadDrumsetDialog)
settings.setValue("loadDrumsetDialog", loadDrumsetDialog->saveState());
if (loadPaletteDialog)
settings.setValue("loadPaletteDialog", loadPaletteDialog->saveState());
if (saveDrumsetDialog)
settings.setValue("saveDrumsetDialog", saveDrumsetDialog->saveState());
if (savePaletteDialog)
settings.setValue("savePaletteDialog", savePaletteDialog->saveState());
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// readSettings
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::readSettings()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (useFactorySettings) {
resize(QSize(1024, 768));
QList<int> sizes;
sizes << 500 << 100;
mainWindow->setSizes(sizes);
mscore->showPalette(true);
return;
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
QSettings settings;
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(1024, 768)).toSize());
mainWindow->restoreState(settings.value("debuggerSplitter").toByteArray());
mainWindow->setOpaqueResize(false);
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
move(settings.value("pos", QPoint(10, 10)).toPoint());
//for some reason when MuseScore starts maximized the screen-reader
//doesn't respond to QAccessibleEvents
if (settings.value("maximized", false).toBool() && !QAccessible::isActive())
2013-05-13 18:49:17 +02:00
showMaximized();
mscore->showPalette(settings.value("showPanel", "1").toBool());
mscore->showInspector(settings.value("showInspector", "0").toBool());
mscore->showPianoKeyboard(settings.value("showPianoKeyboard", "0").toBool());
mscore->showSelectionWindow(settings.value("showSelectionWindow", "0").toBool());
2013-05-13 18:49:17 +02:00
restoreState(settings.value("state").toByteArray());
_horizontalSplit = settings.value("split", true).toBool();
bool splitScreen = settings.value("splitScreen", false).toBool();
if (splitScreen) {
splitWindow(_horizontalSplit);
QAction* a = getAction(_horizontalSplit ? "split-h" : "split-v");
a->setChecked(true);
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
splitter->restoreState(settings.value("splitter").toByteArray());
settings.endGroup();
QAction* a = getAction("toggle-transport");
a->setChecked(!transportTools->isHidden());
a = getAction("toggle-noteinput");
a->setChecked(!entryTools->isHidden());
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// play
// play note for preferences.defaultPlayDuration
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::play(Element* e) const
2012-05-26 14:49:10 +02:00
{
if (noSeq || !(seq && seq->isRunning()) || !mscore->playEnabled())
2013-05-13 18:49:17 +02:00
return;
2012-05-26 14:49:10 +02:00
if (e->type() == Element::Type::NOTE) {
2013-05-13 18:49:17 +02:00
Note* note = static_cast<Note*>(e);
play(e, note->ppitch());
}
else if (e->type() == Element::Type::CHORD) {
2013-05-13 18:49:17 +02:00
seq->stopNotes();
Chord* c = static_cast<Chord*>(e);
Part* part = c->staff()->part();
int tick = c->segment() ? c->segment()->tick() : 0;
seq->seek(tick);
Instrument* instr = part->instr(tick);
foreach(Note* n, c->notes()) {
const Channel& channel = instr->channel(n->subchannel());
seq->startNote(channel.channel, n->ppitch(), 80, n->tuning());
}
seq->startNoteTimer(MScore::defaultPlayDuration);
2012-05-26 14:49:10 +02:00
}
}
2013-05-13 18:49:17 +02:00
void MuseScore::play(Element* e, int pitch) const
2012-05-26 14:49:10 +02:00
{
if (noSeq || !(seq && seq->isRunning()))
2013-10-29 09:54:53 +01:00
return;
if (mscore->playEnabled() && e->type() == Element::Type::NOTE) {
2013-05-13 18:49:17 +02:00
Note* note = static_cast<Note*>(e);
int tick = note->chord()->tick();
if (tick < 0)
tick = 0;
Part* part = note->staff()->part();
Instrument* instr = part->instr(tick);
const Channel& channel = instr->channel(note->subchannel());
seq->startNote(channel.channel, pitch, 80, MScore::defaultPlayDuration, note->tuning());
}
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// reportBug
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::reportBug()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
QString url("http://musescore.org/en/node/add/project-issue/musescore?sha=");
url += revision();
QDesktopServices::openUrl(QUrl(url.trimmed()));
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// about
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::about()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
AboutBoxDialog ab;
ab.show();
ab.exec();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// AboutBoxDialog
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
AboutBoxDialog::AboutBoxDialog()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
setupUi(this);
if (preferences.globalStyle == MuseScoreStyleType::DARK)
museLogo->setPixmap(QPixmap(":/data/musescore_logo_full1.png"));
else
museLogo->setPixmap(QPixmap(":/data/musescore_logo_full.png"));
2013-05-13 18:49:17 +02:00
#ifdef MSCORE_UNSTABLE
versionLabel->setText(tr("Unstable Prerelease for Version: ") + VERSION);
#else
versionLabel->setText(tr("Version: ") + VERSION);
#endif
revisionLabel->setText(tr("Revision: %1").arg(revision));
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
#ifdef MSCORE_UNSTABLE
copyRevisionButton->setIcon(*icons[int(Icons::copy_ICON)]);
2013-05-13 18:49:17 +02:00
connect(copyRevisionButton, SIGNAL(clicked()), this, SLOT(copyRevisionToClipboard()));
#else
copyRevisionButton->hide();
2012-05-26 14:49:10 +02:00
#endif
2013-05-13 18:49:17 +02:00
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// copyRevisionToClipboard
//---------------------------------------------------------
void AboutBoxDialog::copyRevisionToClipboard()
{
QClipboard* cb = QApplication::clipboard();
cb->setText(QString("github-musescore-musescore-") + revision);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// AboutBoxDialog
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
AboutMusicXMLBoxDialog::AboutMusicXMLBoxDialog()
{
2013-05-13 18:49:17 +02:00
setupUi(this);
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// dirtyChanged
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::dirtyChanged(Score* s)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
Score* score = s->rootScore();
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
int idx = scoreList.indexOf(score);
if (idx == -1) {
qDebug("score not in list");
return;
}
2013-05-13 18:49:17 +02:00
QString label(score->name());
if (score->dirty())
label += "*";
tab1->setTabText(idx, label);
if (tab2)
tab2->setTabText(idx, label);
}
//---------------------------------------------------------
// magChanged
//---------------------------------------------------------
2014-07-17 16:52:27 +02:00
void MuseScore::magChanged(int idx)
2013-05-13 18:49:17 +02:00
{
if (cv)
2014-07-17 16:52:27 +02:00
cv->setMag((MagIdx)idx, mag->getMag(cv));
2013-05-13 18:49:17 +02:00
}
//---------------------------------------------------------
// incMag
//---------------------------------------------------------
void MuseScore::incMag()
{
if (cv) {
qreal _mag = cv->mag() * 1.7;
if (_mag > 16.0)
_mag = 16.0;
cv->setMag(MagIdx::MAG_FREE, _mag);
2013-05-13 18:49:17 +02:00
setMag(_mag);
}
2013-05-13 18:49:17 +02:00
}
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// decMag
//---------------------------------------------------------
void MuseScore::decMag()
{
if (cv) {
qreal _mag = cv->mag() / 1.7;
if (_mag < 0.05)
_mag = 0.05;
cv->setMag(MagIdx::MAG_FREE, _mag);
2013-05-13 18:49:17 +02:00
setMag(_mag);
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// getMag
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
double MuseScore::getMag(ScoreView* canvas) const
{
return mag->getMag(canvas);
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// setMag
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
void MuseScore::setMag(double d)
{
mag->setMag(d);
mag->setMagIdx(MagIdx::MAG_FREE);
2013-05-13 18:49:17 +02:00
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// setPos
// set position label
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
void MuseScore::setPos(int t)
{
if (cs == 0 || t < 0)
return;
2012-07-12 15:35:35 +02:00
2013-05-13 18:49:17 +02:00
TimeSigMap* s = cs->sigmap();
int bar, beat, tick;
s->tickValues(t, &bar, &beat, &tick);
_positionLabel->setText(QString("%1:%2:%3")
2013-05-13 18:49:17 +02:00
.arg(bar + 1, 3, 10, QLatin1Char(' '))
.arg(beat + 1, 2, 10, QLatin1Char('0'))
2013-05-13 18:49:17 +02:00
.arg(tick, 3, 10, QLatin1Char('0'))
);
}
2013-02-15 22:39:56 +01:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// undo
//---------------------------------------------------------
void MuseScore::undo()
{
if (_sstate == STATE_EDIT
|| _sstate == STATE_LYRICS_EDIT
|| _sstate == STATE_HARMONY_FIGBASS_EDIT
|| _sstate == STATE_TEXT_EDIT) {
cv->postCmd("escape");
qApp->processEvents();
2013-02-15 22:39:56 +01:00
}
2013-05-13 18:49:17 +02:00
if (cv)
cv->startUndoRedo();
if (cs)
cs->undo()->undo();
if (cv) {
if (cs->inputState().segment())
setPos(cs->inputState().tick());
if (cs->noteEntryMode() && !cv->noteEntryMode()) {
// enter note entry mode
cv->postCmd("note-input");
2013-02-15 22:39:56 +01:00
}
2013-10-24 12:09:00 +02:00
else if (!cs->noteEntryMode() && cv->noteEntryMode()) {
2013-05-13 18:49:17 +02:00
// leave note entry mode
cv->postCmd("escape");
2013-02-15 22:39:56 +01:00
}
2013-05-13 18:49:17 +02:00
cs->endUndoRedo();
updateInputState(cs);
2013-02-15 22:39:56 +01:00
}
2013-05-13 18:49:17 +02:00
endCmd();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// redo
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::redo()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (_sstate == STATE_EDIT
|| _sstate == STATE_TEXT_EDIT
|| _sstate == STATE_HARMONY_FIGBASS_EDIT
|| _sstate == STATE_LYRICS_EDIT) {
cv->postCmd("escape");
qApp->processEvents();
}
if (cv)
cv->startUndoRedo();
if (cs)
cs->undo()->redo();
if (cv) {
if (cs->inputState().segment())
setPos(cs->inputState().tick());
if (cs->noteEntryMode() && !cv->noteEntryMode()) {
// enter note entry mode
cv->postCmd("note-input");
}
2013-10-24 12:09:00 +02:00
else if (!cs->noteEntryMode() && cv->noteEntryMode()) {
2013-05-13 18:49:17 +02:00
// leave note entry mode
cv->postCmd("escape");
}
cs->endUndoRedo();
updateInputState(cs);
}
endCmd();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// showProgressBar
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
QProgressBar* MuseScore::showProgressBar()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (_progressBar == 0)
_progressBar = new QProgressBar(this);
_statusBar->addWidget(_progressBar);
_progressBar->show();
return _progressBar;
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//---------------------------------------------------------
// hideProgressBar
//---------------------------------------------------------
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
void MuseScore::hideProgressBar()
{
if (_progressBar)
_statusBar->removeWidget(_progressBar);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// searchTextChanged
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::searchTextChanged(const QString& s)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (cv == 0)
2013-04-25 14:35:32 +02:00
return;
2013-05-13 18:49:17 +02:00
cv->search(s);
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// endSearch
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::endSearch()
2012-05-26 14:49:10 +02:00
{
_searchDialog->hide();
2013-05-13 18:49:17 +02:00
if (cv)
cv->setFocus();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// handleMessage
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::handleMessage(const QString& message)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (message.isEmpty())
return;
((QtSingleApplication*)(qApp))->activateWindow();
Score* score = readScore(message);
if (score) {
setCurrentScoreView(appendScore(score));
updateRecentScores(score);
writeSessionFile(false);
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// editInPianoroll
//---------------------------------------------------------
2013-01-22 12:30:51 +01:00
2013-05-13 18:49:17 +02:00
void MuseScore::editInPianoroll(Staff* staff)
{
2013-05-13 18:49:17 +02:00
if (pianorollEditor == 0)
pianorollEditor = new PianorollEditor;
pianorollEditor->setScore(staff->score());
pianorollEditor->setStaff(staff);
pianorollEditor->show();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// editInDrumroll
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::editInDrumroll(Staff* staff)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (drumrollEditor == 0)
drumrollEditor = new DrumrollEditor;
drumrollEditor->setStaff(staff);
drumrollEditor->show();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// writeSessionFile
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::writeSessionFile(bool cleanExit)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
// qDebug("write session file");
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
QDir dir;
dir.mkpath(dataPath);
QFile f(dataPath + "/session");
if (!f.open(QIODevice::WriteOnly)) {
qDebug("cannot create session file <%s>", qPrintable(f.fileName()));
2012-05-26 14:49:10 +02:00
return;
}
2013-05-13 18:49:17 +02:00
Xml xml(&f);
xml.header();
xml.stag("museScore version=\"" MSC_VERSION "\"");
xml.tagE(cleanExit ? "clean" : "dirty");
foreach(Score* score, scoreList) {
xml.stag("Score");
xml.tag("created", score->created());
xml.tag("dirty", score->dirty());
if (cleanExit || score->tmpName().isEmpty()) {
2013-05-13 18:49:17 +02:00
xml.tag("path", score->fileInfo()->absoluteFilePath());
}
else {
xml.tag("name", score->fileInfo()->absoluteFilePath());
xml.tag("path", score->tmpName());
}
xml.etag();
}
int tab = 0;
int idx = 0;
for (int i = 0; i < tab1->count(); ++i) {
ScoreView* v = tab1->view(i);
if (v) {
if (v == cv) {
tab = 0;
idx = i;
}
xml.stag("ScoreView");
xml.tag("tab", tab); // 0 instead of "tab" does not work
xml.tag("idx", i);
if (v->magIdx() == MagIdx::MAG_FREE)
2013-05-13 18:49:17 +02:00
xml.tag("mag", v->mag());
else
xml.tag("magIdx", int(v->magIdx()));
2013-05-13 18:49:17 +02:00
xml.tag("x", v->xoffset() / MScore::DPMM);
xml.tag("y", v->yoffset() / MScore::DPMM);
xml.etag();
}
}
if (splitScreen()) {
for (int i = 0; i < tab2->count(); ++i) {
ScoreView* v = tab2->view(i);
if (v) {
if (v == cv) {
tab = 1;
idx = i;
}
xml.stag("ScoreView");
xml.tag("tab", 1);
xml.tag("idx", i);
if (v->magIdx() == MagIdx::MAG_FREE)
2013-05-13 18:49:17 +02:00
xml.tag("mag", v->mag());
else
xml.tag("magIdx", int(v->magIdx()));
2013-05-13 18:49:17 +02:00
xml.tag("x", v->xoffset() / MScore::DPMM);
xml.tag("y", v->yoffset() / MScore::DPMM);
xml.etag();
}
}
}
xml.tag("tab", tab);
xml.tag("idx", idx);
xml.etag();
f.close();
if (cleanExit) {
// TODO: remove all temporary session backup files
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// removeSessionFile
// remove temp files and session file
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::removeSessionFile()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
QFile f(dataPath + "/session");
if (!f.exists())
return;
if (!f.remove()) {
qDebug("cannot remove session file <%s>", qPrintable(f.fileName()));
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// autoSaveTimerTimeout
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::autoSaveTimerTimeout()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
bool sessionChanged = false;
2014-08-26 19:31:04 +02:00
foreach (Score* s, scoreList) {
2013-05-13 18:49:17 +02:00
if (s->autosaveDirty()) {
QString tmp = s->tmpName();
if (!tmp.isEmpty()) {
QFileInfo fi(tmp);
// TODO: cannot catch exeption here:
2014-08-26 19:31:04 +02:00
s->saveCompressedFile(fi, false);
2013-05-13 18:49:17 +02:00
}
else {
QDir dir;
dir.mkpath(dataPath);
QTemporaryFile tf(dataPath + "/scXXXXXX.mscz");
tf.setAutoRemove(false);
if (!tf.open()) {
qDebug("autoSaveTimerTimeout(): create temporary file failed");
return;
}
s->setTmpName(tf.fileName());
QFileInfo info(tf.fileName());
s->saveCompressedFile(&tf, info, false);
tf.close();
sessionChanged = true;
}
s->setAutosaveDirty(false);
}
}
if (sessionChanged)
writeSessionFile(false);
if (preferences.autoSave) {
int t = preferences.autoSaveTime * 60 * 1000;
autoSaveTimer->start(t);
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// restoreSession
// Restore last session. If "always" is true, then restore
// last session even on a clean exit else only if last
// session ended abnormal.
// Return true if a session was found and restored.
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
bool MuseScore::restoreSession(bool always)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
QFile f(dataPath + "/session");
if (!f.exists())
return false;
if (!f.open(QIODevice::ReadOnly)) {
qDebug("Cannot open session file <%s>", qPrintable(f.fileName()));
2013-05-13 18:49:17 +02:00
return false;
}
XmlReader e(&f);
int tab = 0;
int idx = -1;
bool cleanExit = false;
while (e.readNextStartElement()) {
if (e.name() == "museScore") {
/* QString version = e.attribute(QString("version"));
QStringList sl = version.split('.');
int v = sl[0].toInt() * 100 + sl[1].toInt();
*/
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "clean") {
if (!always)
return false;
cleanExit = true;
e.readNext();
}
else if (tag == "dirty") {
QMessageBox::StandardButton b = QMessageBox::question(0,
tr("MuseScore"),
tr("The previous session quit unexpectedly.\n\nRestore session?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
);
if (b != QMessageBox::Yes)
return false;
e.readNext();
}
else if (tag == "Score") {
QString name;
bool created = false;
bool dirty = false;
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "name")
name = e.readElementText();
else if (tag == "created")
created = e.readInt();
else if (tag == "dirty")
dirty = e.readInt();
else if (tag == "path") {
Score* score = readScore(e.readElementText());
if (score) {
if (!name.isEmpty())
score->setName(name);
if (cleanExit) {
// override if last session did a clean exit
dirty = false;
created = false;
}
appendScore(score);
score->setDirty(dirty);
score->setCreated(created);
}
}
else {
e.unknown();
return false;
}
}
}
else if (tag == "ScoreView") {
double x = .0, y = .0, vmag = .0;
MagIdx magIdx = MagIdx::MAG_FREE;
2013-05-13 18:49:17 +02:00
int tab = 0, idx = 0;
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "tab")
tab = e.readInt();
else if (tag == "idx")
idx = e.readInt();
else if (tag == "mag")
vmag = e.readDouble();
else if (tag == "magIdx")
magIdx = MagIdx(e.readInt());
2013-05-13 18:49:17 +02:00
else if (tag == "x")
x = e.readDouble() * MScore::DPMM;
else if (tag == "y")
y = e.readDouble() * MScore::DPMM;
else {
e.unknown();
return false;
}
}
if (magIdx != MagIdx::MAG_FREE)
2013-05-13 18:49:17 +02:00
vmag = mag->getMag(cv);
(tab == 0 ? tab1 : tab2)->initScoreView(idx, vmag, magIdx, x, y);
}
else if (tag == "tab")
tab = e.readInt();
else if (tag == "idx")
idx = e.readInt();
else {
e.unknown();
return false;
}
}
}
else {
e.unknown();
return false;
}
}
setCurrentView(tab, idx);
return true;
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// splitWindow
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::splitWindow(bool horizontal)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (!_splitScreen) {
if (tab2 == 0) {
tab2 = new ScoreTab(&scoreList, this);
2013-05-13 18:49:17 +02:00
tab2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(tab2, SIGNAL(currentScoreViewChanged(ScoreView*)), SLOT(setCurrentScoreView(ScoreView*)));
connect(tab2, SIGNAL(tabCloseRequested(int)), SLOT(removeTab(int)));
connect(tab2, SIGNAL(actionTriggered(QAction*)), SLOT(cmd(QAction*)));
2013-05-13 18:49:17 +02:00
splitter->addWidget(tab2);
}
tab2->setVisible(true);
_splitScreen = true;
_horizontalSplit = horizontal;
splitter->setOrientation(_horizontalSplit ? Qt::Horizontal : Qt::Vertical);
if (!scoreList.isEmpty()) {
tab2->setCurrentIndex(0);
Score* s = scoreList[0];
s->setLayoutAll(true);
s->end();
setCurrentView(1, 0);
}
}
else {
if (_horizontalSplit == horizontal) {
_splitScreen = false;
tab2->setVisible(false);
}
else {
_horizontalSplit = horizontal;
QAction* a;
if (_horizontalSplit)
a = getAction("split-v");
else
a = getAction("split-h");
a->setChecked(false);
splitter->setOrientation(_horizontalSplit ? Qt::Horizontal : Qt::Vertical);
}
}
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// stateName
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
const char* stateName(ScoreState s)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
switch(s) {
case STATE_DISABLED: return "STATE_DISABLED";
case STATE_NORMAL: return "STATE_NORMAL";
case STATE_NOTE_ENTRY_PITCHED: return "STATE_NOTE_ENTRY_PITCHED";
case STATE_NOTE_ENTRY_DRUM: return "STATE_NOTE_ENTRY_DRUM";
case STATE_NOTE_ENTRY_TAB: return "STATE_NOTE_ENTRY_TAB";
case STATE_NOTE_ENTRY: return "STATE_NOTE_ENTRY";
case STATE_EDIT: return "STATE_EDIT";
case STATE_TEXT_EDIT: return "STATE_TEXT_EDIT";
case STATE_LYRICS_EDIT: return "STATE_LYRICS_EDIT";
case STATE_HARMONY_FIGBASS_EDIT: return "STATE_HARMONY_FIGBASS_EDIT";
case STATE_PLAY: return "STATE_PLAY";
case STATE_FOTO: return "STATE_FOTO";
default: return "??";
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// excerptsChanged
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::excerptsChanged(Score* s)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (tab2) {
// ScoreView* v = tab2->view();
// if (v && v->score() == s) {
tab2->updateExcerpts();
// }
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
if (tab1) {
ScoreView* v = tab1->view();
if (v && v->score()->rootScore() == s) {
tab1->updateExcerpts();
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
else if (v == 0) {
tab1->setExcerpt(0);
tab1->updateExcerpts();
2012-05-26 14:49:10 +02:00
}
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// editRaster
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::editRaster()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (editRasterDialog == 0) {
editRasterDialog = new EditRaster(this);
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
if (editRasterDialog->exec()) {
qDebug("=====accept config raster");
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// showPianoKeyboard
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::showPianoKeyboard(bool on)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (_pianoTools == 0) {
QAction* a = getAction("toogle-piano");
_pianoTools = new PianoTools(this);
addDockWidget(Qt::BottomDockWidgetArea, _pianoTools);
connect(_pianoTools, SIGNAL(keyPressed(int, bool)), SLOT(midiNoteReceived(int, bool)));
connect(_pianoTools, SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool)));
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
if (on) {
_pianoTools->show();
}
else {
if (_pianoTools)
_pianoTools->hide();
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// showWeb
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::showWebPanel(bool on)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
QAction* a = getAction("musescore-connect");
if (on) {
if (_webPage == 0) {
_webPage = new WebPageDockWidget(this, this);
connect(_webPage, SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool)));
addDockWidget(Qt::RightDockWidgetArea, _webPage);
}
_webPage->show();
}
else {
if (_webPage)
_webPage->hide();
}
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// showPluginCreator
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::showPluginCreator(QAction* a)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
#ifdef SCRIPT_INTERFACE
bool on = a->isChecked();
if (on) {
2014-08-29 19:18:39 +02:00
if (_pluginCreator == 0) {
_pluginCreator = new PluginCreator(0);
connect(_pluginCreator, SIGNAL(closed(bool)), a, SLOT(setChecked(bool)));
2013-05-13 18:49:17 +02:00
}
2014-08-29 19:18:39 +02:00
_pluginCreator->show();
2013-05-13 18:49:17 +02:00
}
else {
2014-08-29 19:18:39 +02:00
if (_pluginCreator)
_pluginCreator->hide();
2013-05-13 18:49:17 +02:00
}
#endif
2012-05-26 14:49:10 +02:00
}
2013-10-05 12:03:30 +02:00
//---------------------------------------------------------
// showPluginManager
//---------------------------------------------------------
2014-09-01 22:35:04 +02:00
void MuseScore::showPluginManager()
2013-10-05 12:03:30 +02:00
{
#ifdef SCRIPT_INTERFACE
if (!pluginManager)
pluginManager = new PluginManager(0);
pluginManager->init();
pluginManager->show();
2013-10-05 12:03:30 +02:00
#endif
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// showMediaDialog
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::showMediaDialog()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (_mediaDialog == 0)
_mediaDialog = new MediaDialog(this);
_mediaDialog->setScore(cs);
_mediaDialog->exec();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// getPaletteBox
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
PaletteBox* MuseScore::getPaletteBox()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (paletteBox == 0) {
paletteBox = new PaletteBox(this);
QAction* a = getAction("toggle-palette");
connect(paletteBox, SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool)));
addDockWidget(Qt::LeftDockWidgetArea, paletteBox);
}
return paletteBox;
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// midiNoteReceived
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::midiNoteReceived(int pitch, bool ctrl)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (cv)
cv->midiNoteReceived(pitch, ctrl);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// switchLayer
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::switchLayer(const QString& s)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (cs->switchLayer(s)) {
cs->setLayoutAll(true);
cs->update();
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// switchPlayMode
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::switchPlayMode(int mode)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (cs)
cs->setPlayMode(PlayMode(mode));
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// networkFinished
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::networkFinished(QNetworkReply* reply)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (reply->error() != QNetworkReply::NoError) {
qDebug("Error while checking update [%s]", qPrintable(reply->errorString()));
2012-05-26 14:49:10 +02:00
return;
}
2013-05-13 18:49:17 +02:00
QByteArray ha = reply->rawHeader("Content-Disposition");
QString s(ha);
QString name;
QRegExp re(".*filename=\"(.*)\"");
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
if (!s.isEmpty() && re.indexIn(s) != -1) {
name = re.cap(1);
}
else {
QUrl url = reply->url();
QString path = url.path();
qDebug("Path <%s>", qPrintable(path));
QFileInfo fi(path);
name = fi.fileName();
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
qDebug("header <%s>", qPrintable(s));
qDebug("name <%s>", qPrintable(name));
QByteArray data = reply->readAll();
QString tmpName = QDir::tempPath () + "/"+ name;
QFile f(tmpName);
f.open(QIODevice::WriteOnly);
f.write(data);
2012-05-26 14:49:10 +02:00
f.close();
2013-05-13 18:49:17 +02:00
Score* score = readScore(tmpName);
if (!score) {
qDebug("readScore failed");
return;
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
score->setCreated(true);
score->setDirty(true);
setCurrentScoreView(appendScore(score));
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// loadFile
// load file from url
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::loadFile(const QString& s)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
loadFile(QUrl(s));
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
void MuseScore::loadFile(const QUrl& url)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (!networkManager) {
networkManager = new QNetworkAccessManager(this);
connect(networkManager, SIGNAL(finished(QNetworkReply*)),
SLOT(networkFinished(QNetworkReply*)));
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
networkManager->get(QNetworkRequest(url));
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// selectSimilar
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::selectSimilar(Element* e, bool sameStaff)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
Score* score = e->score();
score->selectSimilar(e, sameStaff);
2012-05-26 14:49:10 +02:00
if (score->selectionChanged()) {
score->setSelectionChanged(false);
SelState ss = score->selection().state();
selectionChanged(ss);
}
2012-05-26 14:49:10 +02:00
}
2014-07-14 13:24:47 +02:00
void MuseScore::selectSimilarInRange(Element* e)
{
Score* score = e->score();
score->selectSimilarInRange(e);
2014-07-14 13:24:47 +02:00
if (score->selectionChanged()) {
score->setSelectionChanged(false);
SelState ss = score->selection().state();
selectionChanged(ss);
}
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// selectElementDialog
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::selectElementDialog(Element* e)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
Score* score = e->score();
SelectDialog sd(e, 0);
if (sd.exec()) {
ElementPattern pattern;
sd.setPattern(&pattern);
if (sd.isInSelection())
score->scanElementsInRange(&pattern, Score::collectMatch);
else
score->scanElements(&pattern, Score::collectMatch);
2013-05-13 18:49:17 +02:00
if (sd.doReplace()) {
score->select(0, SelectType::SINGLE, 0);
2013-05-13 18:49:17 +02:00
foreach(Element* ee, pattern.el)
score->select(ee, SelectType::ADD, 0);
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
else if (sd.doSubtract()) {
QList<Element*> sl(score->selection().elements());
foreach(Element* ee, pattern.el)
sl.removeOne(ee);
score->select(0, SelectType::SINGLE, 0);
2013-05-13 18:49:17 +02:00
foreach(Element* ee, sl)
score->select(ee, SelectType::ADD, 0);
2013-05-13 18:49:17 +02:00
}
else if (sd.doAdd()) {
QList<Element*> sl(score->selection().elements());
foreach(Element* ee, pattern.el) {
if(!sl.contains(ee))
score->select(ee, SelectType::ADD, 0);
2013-05-13 18:49:17 +02:00
}
2012-05-26 14:49:10 +02:00
}
if (score->selectionChanged()) {
score->setSelectionChanged(false);
SelState ss = score->selection().state();
selectionChanged(ss);
}
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// RecordButton
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
RecordButton::RecordButton(QWidget* parent)
: SimpleButton(":/data/recordOn.svg", ":/data/recordOff.svg", parent)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
setCheckable(true);
defaultAction()->setCheckable(true);
2014-10-15 20:43:06 +02:00
setToolTip(qApp->translate("RecordButton", "Record"));
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// GreendotButton
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
GreendotButton::GreendotButton(QWidget* parent)
: SimpleButton(":/data/greendot.svg", ":/data/darkgreendot.svg", parent)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
setCheckable(true);
2014-10-15 20:43:06 +02:00
setToolTip(qApp->translate("GreendotButton", "Record"));
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// drawHandle
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
QRectF drawHandle(QPainter& p, const QPointF& pos, bool active)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
p.save();
2013-07-04 21:07:38 +02:00
p.setPen(QPen(QColor(MScore::selectColor[0]), 2.0/p.matrix().m11()));
2013-05-13 18:49:17 +02:00
if (active)
2013-07-04 21:07:38 +02:00
p.setBrush(MScore::selectColor[0]);
2013-05-13 18:49:17 +02:00
else
p.setBrush(Qt::NoBrush);
qreal w = 8.0 / p.matrix().m11();
qreal h = 8.0 / p.matrix().m22();
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
QRectF r(-w/2, -h/2, w, h);
r.translate(pos);
p.drawRect(r);
p.restore();
return r;
2012-05-26 14:49:10 +02:00
}
2012-07-02 18:05:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// transpose
2012-07-02 18:05:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::transpose()
2012-07-02 18:05:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (cs->last() == 0) // empty score?
return;
2014-05-24 12:53:50 +02:00
if (!cs->selection().isRange()) {
2013-05-13 18:49:17 +02:00
QMessageBox::StandardButton sb = QMessageBox::question(mscore,
tr("MuseScore: Transpose"),
tr("There is nothing selected. Transpose whole score?"),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Yes
);
if (sb == QMessageBox::Cancel)
return;
//
// select all
//
cs->cmdSelectAll();
2012-07-02 18:05:10 +02:00
}
2014-05-24 12:53:50 +02:00
bool rangeSelection = cs->selection().isRange();
2013-05-13 18:49:17 +02:00
TransposeDialog td;
2012-07-02 18:05:10 +02:00
2014-05-26 13:21:04 +02:00
// TRANSPOSE_BY_KEY and "transpose keys" is only possible if selection state is SelState::RANGE
2013-05-13 18:49:17 +02:00
td.enableTransposeKeys(rangeSelection);
td.enableTransposeByKey(rangeSelection);
2012-07-02 18:05:10 +02:00
2013-05-13 18:49:17 +02:00
int startStaffIdx = 0;
int startTick = 0;
if (rangeSelection) {
startStaffIdx = cs->selection().staffStart();
startTick = cs->selection().tickStart();
2012-05-26 14:49:10 +02:00
}
2014-06-03 15:28:10 +02:00
td.setKey(cs->staff(startStaffIdx)->key(startTick));
2013-05-13 18:49:17 +02:00
if (!td.exec())
return;
cs->transpose(td.mode(), td.direction(), td.transposeKey(), td.transposeInterval(),
td.getTransposeKeys(), td.getTransposeChordNames(), td.useDoubleSharpsFlats());
2012-07-02 18:05:10 +02:00
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// cmd
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::cmd(QAction* a)
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (inChordEditor) // HACK
return;
2013-05-13 18:49:17 +02:00
QString cmdn(a->data().toString());
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
if (MScore::debugMode)
qDebug("MuseScore::cmd <%s>", cmdn.toLatin1().data());
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
Shortcut* sc = Shortcut::getShortcut(cmdn.toLatin1().data());
if (sc == 0) {
qDebug("MuseScore::cmd(): unknown action <%s>", qPrintable(cmdn));
2012-05-26 14:49:10 +02:00
return;
}
2013-05-13 18:49:17 +02:00
if (cs && (sc->state() & _sstate) == 0) {
QMessageBox::warning(0,
QWidget::tr("MuseScore: Invalid Command"),
2013-05-13 18:49:17 +02:00
QString("Command %1 not valid in current state").arg(cmdn));
2012-05-26 14:49:10 +02:00
return;
}
2013-05-13 18:49:17 +02:00
if (cmdn == "repeat-cmd") {
a = lastCmd;
sc = lastShortcut;
if (a == 0)
2012-05-26 14:49:10 +02:00
return;
2013-05-13 18:49:17 +02:00
cmdn = a->data().toString();
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
else {
lastCmd = a;
lastShortcut = sc;
2012-05-26 14:49:10 +02:00
}
if ((sc->flags() & ShortcutFlags::A_SCORE) && ! cs) {
2013-05-13 18:49:17 +02:00
qDebug("no score");
return;
}
if (sc->flags() & ShortcutFlags::A_CMD) {
2013-05-13 18:49:17 +02:00
if (!cv->editMode())
cs->startCmd();
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
cmd(a, cmdn);
if (lastShortcut->flags() & ShortcutFlags::A_CMD)
2013-05-13 18:49:17 +02:00
cs->endCmd();
endCmd();
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// endCmd
// called after every command action (including every
// mouse action)
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::endCmd()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
if (cs) {
setPos(cs->inputState().tick());
updateInputState(cs);
updateUndoRedo();
cs->setDirty(!cs->undo()->isClean());
dirtyChanged(cs);
Element* e = cs->selection().element();
if (e && cs->playNote()) {
play(e);
cs->setPlayNote(false);
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
if (cs->rootScore()->excerptsChanged()) {
//Q_ASSERT(cs == cs->rootScore());
excerptsChanged(cs->rootScore());
cs->rootScore()->setExcerptsChanged(false);
2012-05-26 14:49:10 +02:00
}
if (!noSeq && !(seq && seq->isRunning()) && cs->instrumentsChanged()) {
2013-05-13 18:49:17 +02:00
seq->initInstruments();
cs->setInstrumentsChanged(false);
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
if (cs->selectionChanged()) {
cs->setSelectionChanged(false);
SelState ss = cs->selection().state();
selectionChanged(ss);
}
2014-05-26 15:31:36 +02:00
getAction("concert-pitch")->setChecked(cs->styleB(StyleIdx::concertPitch));
2012-05-26 14:49:10 +02:00
2013-10-24 12:09:00 +02:00
if (e == 0 && cs->noteEntryMode())
2013-05-13 18:49:17 +02:00
e = cs->inputState().cr();
cs->end();
ScoreAccessibility::instance()->updateAccessibilityInfo();
2012-05-26 14:49:10 +02:00
}
else {
2014-08-29 19:18:39 +02:00
if (_inspector)
_inspector->setElement(0);
2014-05-26 13:21:04 +02:00
selectionChanged(SelState::NONE);
2012-05-26 14:49:10 +02:00
}
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// updateUndoRedo
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::updateUndoRedo()
2012-05-26 14:49:10 +02:00
{
2013-05-13 18:49:17 +02:00
QAction* a = getAction("undo");
a->setEnabled(cs ? cs->undo()->canUndo() : false);
a = getAction("redo");
a->setEnabled(cs ? cs->undo()->canRedo() : false);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
// cmd
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::cmd(QAction* a, const QString& cmd)
2012-05-26 14:49:10 +02:00
{
if (cmd == "instruments") {
editInstrList();
2013-04-03 12:13:23 +02:00
if (mixer)
mixer->updateAll(cs);
2012-05-26 14:49:10 +02:00
}
else if (cmd == "rewind") {
seq->rewindStart();
if (playPanel)
playPanel->heartBeat(0, 0, 0);
2012-05-26 14:49:10 +02:00
}
else if (cmd == "play-next-measure")
seq->nextMeasure();
else if (cmd == "play-next-chord")
seq->nextChord();
else if (cmd == "play-prev-measure")
seq->prevMeasure();
else if (cmd == "play-prev-chord")
seq->prevChord();
else if (cmd == "seek-begin")
seq->rewindStart();
else if (cmd == "seek-end")
seq->seekEnd();
else if (cmd == "keys")
showKeyEditor();
else if (cmd == "file-open")
loadFiles();
else if (cmd == "file-save")
saveFile();
else if (cmd == "file-export")
exportFile();
else if (cmd == "file-part-export")
exportParts();
else if (cmd == "file-close")
closeScore(cs);
else if (cmd == "file-save-as")
2012-05-26 14:49:10 +02:00
saveAs(cs, false);
else if (cmd == "file-save-selection")
2012-05-26 14:49:10 +02:00
saveSelection(cs);
else if (cmd == "file-save-a-copy")
2012-05-26 14:49:10 +02:00
saveAs(cs, true);
else if (cmd == "file-new")
newFile();
else if (cmd == "quit")
2012-05-26 14:49:10 +02:00
close();
else if (cmd == "masterpalette")
showMasterPalette();
else if (cmd == "key-signatures")
showMasterPalette(tr("Key Signatures"));
else if (cmd == "time-signatures")
showMasterPalette(tr("Time Signatures"));
else if (cmd == "symbols")
showMasterPalette(tr("Symbols"));
2012-05-26 14:49:10 +02:00
else if (cmd == "toggle-statusbar") {
preferences.showStatusBar = a->isChecked();
2012-05-31 16:24:35 +02:00
_statusBar->setVisible(preferences.showStatusBar);
2012-05-26 14:49:10 +02:00
preferences.write();
}
else if (cmd == "append-measures")
cmdAppendMeasures();
else if (cmd == "insert-measures")
cmdInsertMeasures();
else if (cmd == "debugger")
startDebugger();
else if (cmd == "album")
showAlbumManager();
else if (cmd == "layer")
showLayerManager();
else if (cmd == "backspace") {
if ( _sstate != STATE_NORMAL )
undo();
#ifdef Q_OS_MAC
else if ( cs )
cs->cmdDeleteSelection();
#endif
}
2012-05-26 14:49:10 +02:00
else if (cmd == "zoomin")
incMag();
else if (cmd == "zoomout")
decMag();
else if (cmd == "midi-on")
midiinToggled(a->isChecked());
else if (cmd == "undo") {
undo();
2014-08-29 19:18:39 +02:00
if (_inspector)
_inspector->reset();
2012-05-26 14:49:10 +02:00
}
else if (cmd == "redo") {
redo();
2014-08-29 19:18:39 +02:00
if (_inspector)
_inspector->reset();
2012-05-26 14:49:10 +02:00
}
else if (cmd == "toggle-palette")
showPalette(a->isChecked());
2014-11-10 10:05:25 +01:00
else if (cmd == "startcenter")
showStartcenter(a->isChecked());
2012-05-26 14:49:10 +02:00
else if (cmd == "inspector")
showInspector(a->isChecked());
#ifdef OMR
else if (cmd == "omr")
showOmrPanel(a->isChecked());
#endif
else if (cmd == "toggle-playpanel")
showPlayPanel(a->isChecked());
else if (cmd == "toggle-navigator")
showNavigator(a->isChecked());
2013-04-28 21:29:12 +02:00
else if (cmd == "toggle-midiimportpanel")
importmidiPanel->setVisible(a->isChecked());
2012-05-26 14:49:10 +02:00
else if (cmd == "toggle-mixer")
showMixer(a->isChecked());
else if (cmd == "synth-control")
2013-04-24 12:41:38 +02:00
showSynthControl(a->isChecked());
2014-06-02 12:12:53 +02:00
else if (cmd == "toggle-selection-window")
showSelectionWindow(a->isChecked());
2012-05-26 14:49:10 +02:00
else if (cmd == "show-keys")
;
else if (cmd == "toggle-transport")
transportTools->setVisible(!transportTools->isVisible());
else if (cmd == "toggle-noteinput")
entryTools->setVisible(!entryTools->isVisible());
else if (cmd == "local-help")
helpBrowser();
else if (cmd == "follow")
preferences.followSong = a->isChecked();
else if (cmd == "split-h")
splitWindow(true);
else if (cmd == "split-v")
splitWindow(false);
else if (cmd == "edit-harmony")
editChordStyle();
else if (cmd == "parts")
startExcerptsDialog();
else if (cmd == "fullscreen") {
_fullscreen = a->isChecked();
if (_fullscreen)
showFullScreen();
else
showNormal();
#ifdef Q_OS_MAC
2012-05-26 14:49:10 +02:00
// Qt Bug: Toolbar goes into unified mode
// after switching back from fullscreen
setUnifiedTitleAndToolBarOnMac(false);
#endif
}
else if (cmd == "config-raster")
editRaster();
else if (cmd == "hraster" || cmd == "vraster") // value in [hv]RasterAction already set
;
else if (cmd == "toogle-piano")
showPianoKeyboard(a->isChecked());
else if (cmd == "musescore-connect")
showWebPanel(a->isChecked());
2012-07-02 18:05:10 +02:00
else if (cmd == "plugin-creator")
showPluginCreator(a);
2013-10-05 12:03:30 +02:00
else if (cmd == "plugin-manager")
2014-09-01 22:35:04 +02:00
showPluginManager();
else if(cmd == "resource-manager"){
ResourceManager r(0);
r.exec();
}
2012-05-26 14:49:10 +02:00
else if (cmd == "media")
showMediaDialog();
else if (cmd == "page-settings")
showPageSettings();
else if (cmd == "next-score")
changeScore(1);
2012-05-26 14:49:10 +02:00
else if (cmd == "previous-score")
changeScore(1);
2012-05-26 14:49:10 +02:00
else if (cmd == "transpose")
transpose();
else if (cmd == "save-style") {
QString name = getStyleFilename(false);
if (!name.isEmpty()) {
if (!cs->saveStyle(name)) {
QMessageBox::critical(this,
tr("MuseScore: Save Style"), MScore::lastError);
2012-05-26 14:49:10 +02:00
}
}
}
2014-01-30 13:10:45 +01:00
#if 0
2012-05-26 14:49:10 +02:00
else if (cmd == "save-default-style") {
QString name = getStyleFilename(false);
if (!name.isEmpty()) {
if (!cs->saveStyle(name)) {
QMessageBox::critical(this,
tr("MuseScore: Save Style"), MScore::lastError);
2012-05-26 14:49:10 +02:00
}
else {
QFileInfo info(name);
if (info.suffix().isEmpty())
info.setFile(info.filePath() + ".mss");
preferences.defaultStyleFile = info.filePath();
}
}
}
2014-01-30 13:10:45 +01:00
#endif
2012-05-26 14:49:10 +02:00
else if (cmd == "load-style") {
QString name = mscore->getStyleFilename(true);
if (!name.isEmpty()) {
cs->startCmd();
if (!cs->loadStyle(name)) {
QMessageBox::critical(this,
tr("MuseScore: Load Style"), MScore::lastError);
2012-05-26 14:49:10 +02:00
}
cs->endCmd();
endCmd();
}
}
else if (cmd == "edit-style") {
EditStyle es(cs, this);
es.exec();
}
else if (cmd == "edit-text-style") {
TextStyleDialog es(0, cs);
es.exec();
}
else if (cmd == "edit-info") {
MetaEditDialog med(cs, 0);
med.exec();
}
else if (cmd == "print")
printFile();
else if (cmd == "repeat") {
MScore::playRepeats = !MScore::playRepeats;
cs->updateRepeatList(MScore::playRepeats);
emit cs->playlistChanged();
2012-05-26 14:49:10 +02:00
}
else if (cmd == "pan")
MScore::panPlayback = !MScore::panPlayback;
else if (cmd == "show-invisible")
cs->setShowInvisible(a->isChecked());
else if (cmd == "show-unprintable")
cs->setShowUnprintable(a->isChecked());
else if (cmd == "show-frames")
cs->setShowFrames(getAction(cmd.toLatin1().data())->isChecked());
else if (cmd == "show-pageborders")
cs->setShowPageborders(getAction(cmd.toLatin1().data())->isChecked());
else if (cmd == "tempo")
addTempo();
else if (cmd == "loop") {
if (loop()) {
2014-05-24 12:53:50 +02:00
if (cs->selection().isRange())
seq->setLoopSelection();
2013-08-19 08:53:30 +02:00
}
}
else if (cmd == "loop-in") {
seq->setLoopIn();
2013-10-18 12:21:01 +02:00
loopAction->setChecked(true);
2013-08-19 08:53:30 +02:00
}
else if (cmd == "loop-out") {
seq->setLoopOut();
2013-10-18 12:21:01 +02:00
loopAction->setChecked(true);
2013-08-19 08:53:30 +02:00
}
2012-05-26 14:49:10 +02:00
else if (cmd == "metronome") // no action
;
else if (cmd == "countin") // no action
;
2012-05-26 14:49:10 +02:00
else if (cmd == "viewmode") {
if (cs) {
if (cs->layoutMode() == LayoutMode::PAGE) {
cs->setLayoutMode(LayoutMode::LINE);
2012-05-26 14:49:10 +02:00
viewModeCombo->setCurrentIndex(1);
}
else {
cs->setLayoutMode(LayoutMode::PAGE);
2012-05-26 14:49:10 +02:00
viewModeCombo->setCurrentIndex(0);
}
cs->doLayout();
cs->setUpdateAll(true);
2012-05-26 14:49:10 +02:00
}
}
else if (cmd == "lock") {
if (_sstate == STATE_LOCK)
changeState(STATE_NORMAL);
else
changeState(STATE_LOCK);
}
else if (cmd == "find")
showSearchDialog();
else if (cmd == "text-b") {
if (_textTools)
_textTools->toggleBold();
}
else if (cmd == "text-i") {
if (_textTools)
_textTools->toggleItalic();
}
else if (cmd == "text-u") {
if (_textTools)
_textTools->toggleUnderline();
}
2012-05-26 14:49:10 +02:00
else {
if (cv) {
//isAncestorOf is called to see if a widget from inspector has focus
//if so, the focus doesn't get shifted to the score, unless escape is
//pressed, or the user clicks in the score
2014-08-29 19:18:39 +02:00
if(!inspector()->isAncestorOf(qApp->focusWidget()) || cmd == "escape")
cv->setFocus();
2012-05-26 14:49:10 +02:00
cv->cmd(a);
}
else
qDebug("2:unknown cmd <%s>", qPrintable(cmd));
}
if (debugger)
debugger->reloadClicked();
}
//---------------------------------------------------------
// openExternalLink
//---------------------------------------------------------
void MuseScore::openExternalLink(const QString& url)
{
QDesktopServices::openUrl(url);
}
//---------------------------------------------------------
// closeWebPanelPermanently
//---------------------------------------------------------
void MuseScore::closeWebPanelPermanently()
{
showWebPanel(false);
preferences.showWebPanel = false;
preferences.dirty = true;
}
//---------------------------------------------------------
// navigator
//---------------------------------------------------------
Navigator* MuseScore::navigator() const
{
return _navigator ? static_cast<Navigator*>(_navigator->widget()) : 0;
}
//---------------------------------------------------------
// getSearchDialog
//---------------------------------------------------------
QWidget* MuseScore::searchDialog() const
{
return _searchDialog;
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
// updateLayer
//---------------------------------------------------------
void MuseScore::updateLayer()
{
layerSwitch->clear();
bool enable;
if (cs) {
enable = cs->layer().size() > 1;
if (enable) {
foreach(const Layer& l, cs->layer())
layerSwitch->addItem(l.name);
layerSwitch->setCurrentIndex(cs->currentLayer());
}
}
else
enable = false;
layerSwitch->setVisible(enable);
}
//---------------------------------------------------------
// updatePlayMode
//---------------------------------------------------------
void MuseScore::updatePlayMode()
{
bool enable = false;
if (cs) {
enable = cs->audio() != 0;
playMode->setCurrentIndex(int(cs->playMode()));
}
playMode->setVisible(enable);
}
//---------------------------------------------------------
// closeScore
//---------------------------------------------------------
void MuseScore::closeScore(Score* score)
{
removeTab(scoreList.indexOf(score->rootScore()));
}
//---------------------------------------------------------
// noteTooShortForTupletDialog
//---------------------------------------------------------
2013-05-13 18:49:17 +02:00
void MuseScore::noteTooShortForTupletDialog()
{
QMessageBox::warning(this, tr("MuseScore: Warning"),
tr("Cannot create tuplet: Note value is too short")
2013-05-13 18:49:17 +02:00
);
}
//---------------------------------------------------------
// instrumentChanged
//---------------------------------------------------------
void MuseScore::instrumentChanged()
{
if (mixer)
mixer->updateAll(cs);
}
//---------------------------------------------------------
// changeScore
// switch current score
// step = 1 switch to next score
// step = -1 switch to previous score
//---------------------------------------------------------
void MuseScore::changeScore(int step)
{
int index = tab1->currentIndex();
int n = tab1->count();
if (n == 1)
return;
index += step;
if (index >= n)
index = 0;
if (index < 0)
index = n - 1;
setCurrentScoreView(index);
}
//---------------------------------------------------------
// switchLayoutMode
//---------------------------------------------------------
void MuseScore::switchLayoutMode(int val)
{
if (cs) {
if (val == 0)
cs->setLayoutMode(LayoutMode::PAGE);
2013-05-13 18:49:17 +02:00
else
cs->setLayoutMode(LayoutMode::LINE);
2013-05-13 18:49:17 +02:00
cs->doLayout();
cs->setUpdateAll(true);
cv->update();
cv->loopUpdate(getAction("loop")->isChecked());
2013-05-13 18:49:17 +02:00
}
}
//---------------------------------------------------------
// showDrumTools
//---------------------------------------------------------
void MuseScore::showDrumTools(Drumset* drumset, Staff* staff)
{
if (drumset) {
if (!_drumTools) {
_drumTools = new DrumTools(this);
addDockWidget(Qt::BottomDockWidgetArea, _drumTools);
}
_drumTools->setDrumset(cs, staff, drumset);
_drumTools->show();
}
else {
if (_drumTools)
_drumTools->hide();
}
}
//---------------------------------------------------------
// updateDrumTools
//---------------------------------------------------------
void MuseScore::updateDrumTools()
{
if (_drumTools)
_drumTools->updateDrumset();
}
//---------------------------------------------------------
// showSearchDialog
//---------------------------------------------------------
void MuseScore::showSearchDialog()
{
if (_searchDialog == 0) {
_searchDialog = new QWidget;
_searchDialog->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
2013-05-13 18:49:17 +02:00
QHBoxLayout* searchDialogLayout = new QHBoxLayout;
_searchDialog->setLayout(searchDialogLayout);
layout->insertWidget(2, _searchDialog);
2013-05-13 18:49:17 +02:00
QToolButton* searchExit = new QToolButton;
2013-05-09 18:46:51 +02:00
searchExit->setAutoRaise(true);
searchExit->setIcon(*icons[int(Icons::close_ICON)]);
2013-05-13 18:49:17 +02:00
connect(searchExit, SIGNAL(clicked()), SLOT(endSearch()));
searchDialogLayout->addWidget(searchExit);
2013-05-09 18:46:51 +02:00
searchDialogLayout->addSpacing(10);
2013-05-13 18:49:17 +02:00
searchDialogLayout->addWidget(new QLabel(tr("Go To: ")));
searchCombo = new QComboBox;
searchCombo->setEditable(true);
searchCombo->setInsertPolicy(QComboBox::InsertAtTop);
searchDialogLayout->addWidget(searchCombo);
searchDialogLayout->addStretch(10);
_searchDialog->hide();
2013-05-13 18:49:17 +02:00
2014-03-04 16:48:06 +01:00
qDebug("Line edit %p", searchCombo->lineEdit());
2013-05-13 18:49:17 +02:00
// does not work: connect(searchCombo->lineEdit(), SIGNAL(returnPressed()), SLOT(endSearch()));
connect(searchCombo->lineEdit(), SIGNAL(editingFinished()), SLOT(endSearch()));
connect(searchCombo, SIGNAL(editTextChanged(const QString&)),
SLOT(searchTextChanged(const QString&)));
}
searchCombo->clearEditText();
searchCombo->setFocus();
_searchDialog->show();
2013-05-13 18:49:17 +02:00
}
#ifndef SCRIPT_INTERFACE
void MuseScore::pluginTriggered(int) {}
void MuseScore::loadPlugins() {}
bool MuseScore::loadPlugin(const QString&) { return false;}
void MuseScore::unloadPlugins() {}
2013-05-16 17:06:31 +02:00
QQmlEngine* MuseScore::qml() { return 0; }
2013-05-13 18:49:17 +02:00
#endif
}
2014-01-22 15:50:01 +01:00
2013-05-13 18:49:17 +02:00
using namespace Ms;
//---------------------------------------------------------
// main
//---------------------------------------------------------
int main(int argc, char* av[])
{
#if defined(QT_DEBUG) && defined(Q_OS_WIN)
qInstallMessageHandler(mscoreMessageHandler);
2013-05-13 18:49:17 +02:00
#endif
QFile f(":/revision.h");
f.open(QIODevice::ReadOnly);
revision = QString(f.readAll()).trimmed();
f.close();
#ifdef Q_OS_MAC
2013-05-13 18:49:17 +02:00
MuseScoreApplication* app = new MuseScoreApplication("mscore-dev", argc, av);
#else
2013-07-10 17:00:21 +02:00
QtSingleApplication* app = new QtSingleApplication("mscore-dev", argc, av);
2013-05-13 18:49:17 +02:00
#endif
QCoreApplication::setOrganizationName("MuseScore");
QCoreApplication::setOrganizationDomain("musescore.org");
QCoreApplication::setApplicationName("MuseScoreDevelopment");
QAccessible::installFactory(AccessibleScoreView::ScoreViewFactory);
2013-05-13 18:49:17 +02:00
Q_INIT_RESOURCE(zita);
2013-07-10 21:59:00 +02:00
Q_INIT_RESOURCE(noeffect);
2013-05-13 18:49:17 +02:00
// Q_INIT_RESOURCE(freeverb);
#ifndef Q_OS_MAC
2013-05-13 18:49:17 +02:00
// Save the preferences in QSettings::NativeFormat
QSettings::setDefaultFormat(QSettings::IniFormat);
#endif
if (!QFontDatabase::supportsThreadedFontRendering()) {
qDebug("Your computer does not support threaded font rendering!");
exit(-1);
}
QStringList argv = QCoreApplication::arguments();
argv.removeFirst();
for (int i = 0; i < argv.size();) {
QString s = argv[i];
if (s[0] != '-') {
++i;
continue;
}
switch (s[1].toLatin1()) {
case 'v':
printVersion("MuseScore");
return 0;
case 'd':
MScore::debugMode = true;
break;
case 'L':
MScore::layoutDebug = true;
break;
case 's':
noSeq = true;
break;
case 'm':
noMidi = true;
break;
case 'a':
if (argv.size() - i < 2)
usage();
audioDriver = argv.takeAt(i + 1);
break;
case 'n':
startWithNewScore = true;
break;
case 'i':
externalIcons = true;
break;
case 'I':
midiInputTrace = true;
break;
case 'O':
midiOutputTrace = true;
break;
case 'o':
converterMode = true;
2014-02-28 11:14:43 +01:00
MScore::noGui = true;
2013-05-13 18:49:17 +02:00
if (argv.size() - i < 2)
usage();
outFileName = argv.takeAt(i + 1);
break;
case 'p':
pluginMode = true;
2014-02-28 11:14:43 +01:00
MScore::noGui = true;
2013-05-13 18:49:17 +02:00
if (argv.size() - i < 2)
usage();
pluginName = argv.takeAt(i + 1);
break;
case 'r':
if (argv.size() - i < 2)
usage();
converterDpi = argv.takeAt(i + 1).toDouble();
break;
case 'S':
if (argv.size() - i < 2)
usage();
styleFile = argv.takeAt(i + 1);
break;
case 'F':
useFactorySettings = true;
deletePreferences = true;
break;
case 'R':
2013-05-13 18:49:17 +02:00
useFactorySettings = true;
break;
case 'e':
enableExperimental = true;
break;
case 'c':
{
if (argv.size() - i < 2)
usage();
QString path = argv.takeAt(i + 1);
QDir dir;
if (dir.exists(path)) {
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, path);
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, path);
dataPath = path;
}
}
break;
case 't':
{
enableTestMode = true;
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
break;
case 'M':
{
if (argv.size() - i < 2)
usage();
preferences.midiImportOperations.setOperationsFile(argv.takeAt(i + 1));
}
break;
2013-05-13 18:49:17 +02:00
default:
usage();
}
2013-05-13 18:49:17 +02:00
argv.removeAt(i);
}
2013-05-13 18:49:17 +02:00
mscoreGlobalShare = getSharePath();
iconPath = externalIcons ? mscoreGlobalShare + QString("icons/") : QString(":/data/icons/");
2013-05-13 18:49:17 +02:00
if (!converterMode) {
if (!argv.isEmpty()) {
int ok = true;
foreach(QString message, argv) {
QFileInfo fi(message);
if (!app->sendMessage(fi.absoluteFilePath())) {
ok = false;
break;
}
}
if (ok)
return 0;
2012-05-26 14:49:10 +02:00
}
else
2013-05-13 18:49:17 +02:00
if (app->sendMessage(QString(""))) {
return 0;
}
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
/**/
if (dataPath.isEmpty())
dataPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
2014-06-03 15:28:10 +02:00
if (deletePreferences) {
QDir(dataPath).removeRecursively();
QSettings settings;
QFile::remove(settings.fileName());
}
2014-06-03 15:28:10 +02:00
2013-05-13 18:49:17 +02:00
// create local plugin directory
// if not already there:
QDir dir;
dir.mkpath(dataPath + "/plugins");
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
if (MScore::debugMode)
qDebug("global share: <%s>", qPrintable(mscoreGlobalShare));
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
// set translator before preferences are read to get
// translations for all shortcuts
//
if (useFactorySettings)
localeName = "system";
2012-05-26 14:49:10 +02:00
else {
2013-05-13 18:49:17 +02:00
QSettings s;
localeName = s.value("language", "system").toString();
2012-05-26 14:49:10 +02:00
}
2014-06-03 15:28:10 +02:00
2013-05-13 18:49:17 +02:00
setMscoreLocale(localeName);
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
Shortcut::init();
preferences.init();
2012-05-26 14:49:10 +02:00
QNetworkProxyFactory::setUseSystemConfiguration(true);
2013-10-07 14:32:42 +02:00
QScreen* screen = QGuiApplication::primaryScreen();
MScore::PDPI = screen->physicalDotsPerInch(); // physical resolution
//MScore::DPI = MScore::PDPI; // logical drawing resolution
MScore::DPI = screen->logicalDotsPerInch(); // logical drawing resolution
MScore::init(); // initialize libmscore
if (!MScore::testMode) {
QSizeF psf = QPrinter().paperSize(QPrinter::Inch);
PaperSize ps("system", psf.width(), psf.height());
PageFormat pf;
pf.setSize(&ps);
MScore::defaultStyle()->setPageFormat(pf);
}
2012-05-26 14:49:10 +02:00
#ifdef SCRIPT_INTERFACE
qmlRegisterType<QmlPlugin> ("MuseScore", 1, 0, "MuseScore");
#endif
2013-10-30 09:42:08 +01:00
if (MScore::debugMode) {
2013-05-13 18:49:17 +02:00
qDebug("DPI %f", MScore::DPI);
2012-05-26 14:49:10 +02:00
2013-10-30 09:42:08 +01:00
qDebug() << "Information for screen:" << screen->name();
qDebug() << " Available geometry:" << screen->availableGeometry().x() << screen->availableGeometry().y() << screen->availableGeometry().width() << "x" << screen->availableGeometry().height();
qDebug() << " Available size:" << screen->availableSize().width() << "x" << screen->availableSize().height();
qDebug() << " Available virtual geometry:" << screen->availableVirtualGeometry().x() << screen->availableVirtualGeometry().y() << screen->availableVirtualGeometry().width() << "x" << screen->availableVirtualGeometry().height();
qDebug() << " Available virtual size:" << screen->availableVirtualSize().width() << "x" << screen->availableVirtualSize().height();
qDebug() << " Depth:" << screen->depth() << "bits";
qDebug() << " Geometry:" << screen->geometry().x() << screen->geometry().y() << screen->geometry().width() << "x" << screen->geometry().height();
qDebug() << " Logical DPI:" << screen->logicalDotsPerInch();
qDebug() << " Logical DPI X:" << screen->logicalDotsPerInchX();
qDebug() << " Logical DPI Y:" << screen->logicalDotsPerInchY();
qDebug() << " Physical DPI:" << screen->physicalDotsPerInch();
qDebug() << " Physical DPI X:" << screen->physicalDotsPerInchX();
qDebug() << " Physical DPI Y:" << screen->physicalDotsPerInchY();
qDebug() << " Physical size:" << screen->physicalSize().width() << "x" << screen->physicalSize().height() << "mm";
qDebug() << " Refresh rate:" << screen->refreshRate() << "Hz";
qDebug() << " Size:" << screen->size().width() << "x" << screen->size().height();
qDebug() << " Virtual geometry:" << screen->virtualGeometry().x() << screen->virtualGeometry().y() << screen->virtualGeometry().width() << "x" << screen->virtualGeometry().height();
qDebug() << " Virtual size:" << screen->virtualSize().width() << "x" << screen->virtualSize().height();
}
2013-10-08 20:03:34 +02:00
2013-05-13 18:49:17 +02:00
if (!useFactorySettings)
preferences.read();
2012-05-26 14:49:10 +02:00
preferences.readDefaultStyle();
2013-05-13 18:49:17 +02:00
if (converterDpi == 0)
converterDpi = preferences.pngResolution;
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
QSplashScreen* sc = 0;
2014-11-10 10:05:25 +01:00
QTimer* stimer = 0;
2014-02-28 11:14:43 +01:00
if (!MScore::noGui && preferences.showSplashScreen) {
2013-05-13 18:49:17 +02:00
QPixmap pm(":/data/splash.jpg");
sc = new QSplashScreen(pm);
sc->setWindowTitle(QString("MuseScore Startup"));
#ifdef Q_OS_MAC // to have session dialog on top of splashscreen on mac
sc->setWindowFlags(Qt::FramelessWindowHint);
#endif
2014-06-03 15:28:10 +02:00
2014-11-10 10:05:25 +01:00
stimer = new QTimer(0);
qApp->connect(stimer, SIGNAL(timeout()), sc, SLOT(close()));
stimer->start(5000);
2013-05-13 18:49:17 +02:00
sc->show();
qApp->processEvents();
2012-05-26 14:49:10 +02:00
}
2013-05-13 18:49:17 +02:00
if (!converterMode) {
switch(preferences.globalStyle) {
case MuseScoreStyleType::DARK: {
2013-05-13 18:49:17 +02:00
MgStyle* st = new MgStyle;
QApplication::setStyle(st);
QPalette p(QApplication::palette());
QSettings s;
p.setColor(QPalette::Window, QColor(s.value("WindowColor", "#525252").toString()));
p.setColor(QPalette::WindowText, QColor(s.value("WindowTextColor", "#FFFFFF").toString()));
p.setColor(QPalette::Base, QColor(s.value("BaseColor", "#424242").toString()));
p.setColor(QPalette::AlternateBase, QColor(s.value("AlternateBaseColor", "#626262").toString()));
p.setColor(QPalette::Text, QColor(s.value("TextColor", "#FFFFFF").toString()));
p.setColor(QPalette::Button, QColor(s.value("ButtonColor", "#525252").toString()));
p.setColor(QPalette::ButtonText, QColor(s.value("ButtonTextColor", "#FFFFFF").toString()));
p.setColor(QPalette::BrightText, QColor(s.value("BrightTextColor", "#000000").toString()));
2013-05-13 18:49:17 +02:00
QApplication::setPalette(p);
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
QPalette palette = QToolTip::palette();
palette.setBrush(QPalette::ToolTipBase, QBrush(QColor(s.value("ToolTipBaseColor", "#808080").toString())));
2013-07-09 18:08:49 +02:00
palette.setColor(QPalette::ToolTipText, QColor(s.value("ToolTipTextColor", "#000000").toString()));
2013-05-13 18:49:17 +02:00
QToolTip::setPalette(palette);
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
break;
}
case MuseScoreStyleType::LIGHT:
MgStyle* st = new MgStyle;
QApplication::setStyle(st);
QPalette p(QApplication::palette());
QSettings s;
p.setColor(QPalette::Window, QColor(s.value("WindowColor", "#e3e3e3").toString()));
p.setColor(QPalette::WindowText, QColor(s.value("WindowTextColor", "#333333").toString()));
p.setColor(QPalette::Base, QColor(s.value("BaseColor", "#f9f9f9").toString()));
p.setColor(QPalette::AlternateBase, QColor(s.value("AlternateBaseColor", "#eeeeee").toString()));
p.setColor(QPalette::Text, QColor(s.value("TextColor", "#333333").toString()));
p.setColor(QPalette::Button, QColor(s.value("ButtonColor", "#c9c9c9").toString()));
p.setColor(QPalette::ButtonText, QColor(s.value("ButtonTextColor", "#333333").toString()));
p.setColor(QPalette::BrightText, QColor(s.value("BrightTextColor", "#000000").toString()));
QApplication::setPalette(p);
2013-07-09 18:08:49 +02:00
QPalette palette(p); // = QToolTip::palette();
2014-11-10 11:40:28 +01:00
palette.setBrush(QPalette::ToolTipBase, QBrush(QColor(s.value("ToolTipBaseColor", "#FEFAC2").toString())));
2013-07-09 18:08:49 +02:00
palette.setColor(QPalette::ToolTipText, QColor(s.value("ToolTipTextColor", "#000000").toString()));
QToolTip::setPalette(palette);
break;
2013-05-13 18:49:17 +02:00
}
qApp->setStyleSheet(
"*:disabled {\n"
" color: gray\n"
"}\n"
"QGroupBox {\n"
"font-weight: bold;\n"
"}\n"
"QGroupBox::title {\n"
" subcontrol-origin: margin; subcontrol-position: top left; padding: 5px 5px;\n"
2014-09-12 11:34:57 +02:00
"}\n"
"QDockWidget {\n"
" border: 1px solid lightgray;\n"
" titlebar-close-icon: url(:/data/icons/png/window-close.png);\n"
" titlebar-normal-icon: url(:/data/icons/png/window-float.png);\n"
" }\n"
"QTabBar::close-button {\n"
" image: url(:/data/icons/png/window-close.png);\n"
" }\n"
2014-09-12 11:34:57 +02:00
"QTabBar::close-button:hover {\n"
" image: url(:/data/icons/png/window-close-hover.png);\n"
" }");
MgStyleConfigData::animationsEnabled = preferences.animations;
2014-03-14 15:39:37 +01:00
qApp->setAttribute(Qt::AA_UseHighDpiPixmaps);
}
else
noSeq = true;
2013-07-16 18:16:16 +02:00
// Do not create sequencer and audio drivers if run with '-s'
if (!noSeq) {
2013-05-13 18:49:17 +02:00
seq = new Seq();
MScore::seq = seq;
Driver* driver = driverFactory(seq, audioDriver);
synti = synthesizerFactory();
2013-05-13 18:49:17 +02:00
if (driver) {
MScore::sampleRate = driver->sampleRate();
synti->setSampleRate(MScore::sampleRate);
synti->init();
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
seq->setDriver(driver);
}
else {
// Do not delete the sequencer If we can't load driver.
// Allow user to select the working driver later.
MScore::sampleRate = 44100; // Would be changed when user changes driver
synti->setSampleRate(MScore::sampleRate);
synti->init();
2013-05-13 18:49:17 +02:00
}
seq->setMasterSynthesizer(synti);
2013-05-13 18:49:17 +02:00
}
else {
seq = 0;
MScore::seq = 0;
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
//
// avoid font problems by overriding the environment
// fall back to "C" locale
//
2012-05-26 14:49:10 +02:00
2013-10-08 19:25:04 +02:00
//#ifndef Q_OS_WIN
//setenv("LANG", "C", 1);
//#endif
//QLocale::setDefault(QLocale(QLocale::C));
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
if (MScore::debugMode) {
QStringList sl(QCoreApplication::libraryPaths());
foreach(const QString& s, sl)
qDebug("LibraryPath: <%s>", qPrintable(s));
}
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
// rastral size of font is 20pt = 20/72 inch = 20*DPI/72 dots
// staff has 5 lines = 4 * _spatium
// _spatium = SPATIUM20 * DPI; // 20.0 / 72.0 * DPI / 4.0;
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
genIcons();
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
if (!converterMode)
qApp->setWindowIcon(*icons[int(Icons::window_ICON)]);
2013-05-13 18:49:17 +02:00
Workspace::initWorkspace();
mscore = new MuseScore();
mscoreCore = mscore;
2014-07-23 17:08:48 +02:00
// create a score for internal use
// gscore = new Score(MScore::defaultStyle());
gscore = new Score(MScore::baseStyle());
gscore->style()->set(StyleIdx::MusicalTextFont, QString("Bravura Text"));
ScoreFont* scoreFont = ScoreFont::fontFactory("Bravura");
gscore->setScoreFont(scoreFont);
gscore->setNoteHeadWidth(scoreFont->width(SymId::noteheadBlack, gscore->spatium()) / (MScore::DPI * SPATIUM20));
2012-05-26 14:49:10 +02:00
2013-05-13 18:49:17 +02:00
if (!noSeq) {
if (!seq->init())
2013-05-13 18:49:17 +02:00
qDebug("sequencer init failed");
}
2013-05-13 18:49:17 +02:00
//read languages list
mscore->readLanguages(mscoreGlobalShare + "locale/languages.xml");
#ifdef Q_OS_MAC
2013-05-13 18:49:17 +02:00
QApplication::instance()->installEventFilter(mscore);
#endif
mscore->setRevision(revision);
2013-05-13 18:49:17 +02:00
int files = 0;
2014-02-28 11:14:43 +01:00
if (MScore::noGui) {
#ifdef Q_OS_MAC
// see issue #28706: Hangup in converter mode with MusicXML source
qApp->processEvents();
#endif
2013-05-13 18:49:17 +02:00
loadScores(argv);
exit(processNonGui() ? 0 : -1);
}
else {
mscore->readSettings();
QObject::connect(qApp, SIGNAL(messageReceived(const QString&)),
mscore, SLOT(handleMessage(const QString&)));
2013-05-13 18:49:17 +02:00
mscore->showWebPanel(preferences.showWebPanel);
2013-07-10 17:00:21 +02:00
static_cast<QtSingleApplication*>(qApp)->setActivationWindow(mscore, false);
2013-06-24 22:07:44 +02:00
// count filenames specified on the command line
// these are the non-empty strings remaining in argv
2013-05-13 18:49:17 +02:00
foreach(const QString& name, argv) {
if (!name.isEmpty())
++files;
}
#ifdef Q_WS_MAC
2013-06-24 22:07:44 +02:00
// app->paths contains files requested to be loaded by OS X
// append these to argv and update file count
foreach(const QString& name, app->paths) {
if (!name.isEmpty()) {
argv << name;
++files;
}
2013-05-13 18:49:17 +02:00
}
2013-06-24 22:07:44 +02:00
#endif
2013-05-13 18:49:17 +02:00
//
// TODO: delete old session backups
//
2014-07-01 14:44:45 +02:00
if (!mscore->restoreSession((preferences.sessionStart == SessionStart::LAST) && (files == 0)) || files)
2013-05-13 18:49:17 +02:00
loadScores(argv);
}
2013-07-17 14:36:34 +02:00
errorMessage = new QErrorMessage(mscore);
2013-05-13 18:49:17 +02:00
mscore->loadPlugins();
mscore->writeSessionFile(false);
#ifdef Q_OS_MAC
2013-05-13 18:49:17 +02:00
// there's a bug in Qt showing the toolbar unified after switching showFullScreen(), showMaximized(),
// showNormal()...
mscore->setUnifiedTitleAndToolBarOnMac(false);
#endif
2013-05-13 18:49:17 +02:00
mscore->changeState(mscore->noScore() ? STATE_DISABLED : STATE_NORMAL);
mscore->show();
2014-11-10 10:05:25 +01:00
// if (sc)
// sc->finish(mscore);
2013-05-13 18:49:17 +02:00
if (mscore->hasToCheckForUpdate())
mscore->checkForUpdate();
2014-08-26 09:13:29 +02:00
#if 0
2014-07-01 14:44:45 +02:00
if (preferences.sessionStart == SessionStart::EMPTY && files == 0) {
2013-05-13 18:49:17 +02:00
QDialog* start = new StartDialog(0);
switch(start->exec()) {
case 1:
mscore->newFile();
break;
case 2:
mscore->loadFiles();
break;
}
}
2014-08-26 09:13:29 +02:00
#endif
2014-11-10 10:05:25 +01:00
if (preferences.showStartcenter)
mscore->showStartcenter(true);
2013-05-13 18:49:17 +02:00
return qApp->exec();
}
2012-07-09 14:16:27 +02:00