Skip to content

Commit

Permalink
Merge pull request #1368 from Igevorse/bugs1
Browse files Browse the repository at this point in the history
fix #34296: Crash on switching from uninitialized driver
  • Loading branch information
lasconic committed Oct 11, 2014
2 parents 7cf8c32 + 38b7d05 commit a7dab0a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
31 changes: 15 additions & 16 deletions mscore/musescore.cpp
Expand Up @@ -354,8 +354,8 @@ void MuseScore::preferencesChanged()
}
}

transportTools->setEnabled(!noSeq);
playId->setEnabled(!noSeq);
transportTools->setEnabled(!noSeq && seq && seq->isRunning());
playId->setEnabled(!noSeq && seq && seq->isRunning());

getAction("midi-on")->setEnabled(preferences.enableMidiInput);
_statusBar->setVisible(preferences.showStatusBar);
Expand Down Expand Up @@ -1778,7 +1778,7 @@ void MuseScore::showElementContext(Element* el)

void MuseScore::showPlayPanel(bool visible)
{
if (noSeq)
if (noSeq || !(seq && seq->isRunning()))
return;
if (playPanel == 0) {
if (!visible)
Expand Down Expand Up @@ -2627,7 +2627,7 @@ void MuseScore::changeState(ScoreState val)

menuWorkspaces->setEnabled(enable);

transportTools->setEnabled(enable && !noSeq);
transportTools->setEnabled(enable && !noSeq && seq && seq->isRunning());
cpitchTools->setEnabled(enable);
mag->setEnabled(enable);
entryTools->setEnabled(enable);
Expand Down Expand Up @@ -2830,7 +2830,7 @@ void MuseScore::readSettings()

void MuseScore::play(Element* e) const
{
if (noSeq || !mscore->playEnabled())
if (noSeq || !(seq && seq->isRunning()) || !mscore->playEnabled())
return;

if (e->type() == Element::Type::NOTE) {
Expand All @@ -2854,7 +2854,7 @@ void MuseScore::play(Element* e) const

void MuseScore::play(Element* e, int pitch) const
{
if (noSeq)
if (noSeq || !(seq && seq->isRunning()))
return;
if (mscore->playEnabled() && e->type() == Element::Type::NOTE) {
Note* note = static_cast<Note*>(e);
Expand Down Expand Up @@ -4002,7 +4002,7 @@ void MuseScore::endCmd()
excerptsChanged(cs->rootScore());
cs->rootScore()->setExcerptsChanged(false);
}
if (!noSeq && cs->instrumentsChanged()) {
if (!noSeq && !(seq && seq->isRunning()) && cs->instrumentsChanged()) {
seq->initInstruments();
cs->setInstrumentsChanged(false);
}
Expand Down Expand Up @@ -4918,21 +4918,22 @@ int main(int argc, char* av[])
seq = new Seq();
MScore::seq = seq;
Driver* driver = driverFactory(seq, audioDriver);
synti = synthesizerFactory();
if (driver) {
synti = synthesizerFactory();
MScore::sampleRate = driver->sampleRate();
synti->setSampleRate(MScore::sampleRate);
synti->init();

seq->setDriver(driver);
seq->setMasterSynthesizer(synti);
}
else {
delete seq;
MScore::seq = 0;
seq = 0;
noSeq = true;
// 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();
}
seq->setMasterSynthesizer(synti);
}
else
noSeq = true;
Expand Down Expand Up @@ -4974,10 +4975,8 @@ int main(int argc, char* av[])
gscore->setNoteHeadWidth(scoreFont->width(SymId::noteheadBlack, gscore->spatium()) / (MScore::DPI * SPATIUM20));

if (!noSeq) {
if (!seq->init()) {
if (!seq->init())
qDebug("sequencer init failed");
noSeq = true;
}
}

//read languages list
Expand Down
10 changes: 9 additions & 1 deletion mscore/preferences.cpp
Expand Up @@ -43,6 +43,7 @@
#include "pathlistdialog.h"
#include "mstyle/mconfig.h"
#include "resourceManager.h"
#include "synthesizer/msynthesizer.h"

namespace Ms {

Expand Down Expand Up @@ -1319,7 +1320,14 @@ void PreferenceDialog::apply()
preferences = prefs;
Driver* driver = driverFactory(seq, "");
if (seq) {
seq->setDriver(driver);
if (driver) {
// Updating synthesizer's sample rate
if (seq->synti()) {
seq->synti()->setSampleRate(driver->sampleRate());
seq->synti()->init();
}
seq->setDriver(driver);
}
if (!seq->init())
qDebug("sequencer init failed");
}
Expand Down
1 change: 1 addition & 0 deletions mscore/seq.cpp
Expand Up @@ -228,6 +228,7 @@ bool Seq::init(bool hotPlug)
{
if (!_driver || !_driver->start(hotPlug)) {
qDebug("Cannot start I/O");
running = false;
return false;
}
running = true;
Expand Down

0 comments on commit a7dab0a

Please sign in to comment.