Skip to content

Commit

Permalink
Fix single-note dynamics on rendering scores via a command line
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrio95 authored and anatoly-os committed Oct 26, 2019
1 parent 76348a7 commit cf84ff0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
28 changes: 22 additions & 6 deletions mscore/exportaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace Ms {

///
/// \brief Function to synthesize audio and output it into a generic QIODevice
/// \param The score to output
/// \param The output device
/// \param An optional callback function that will be notified with the progress in range [0, 1]
/// \param score The score to output
/// \param device The output device
/// \param updateProgress An optional callback function that will be notified with the progress in range [0, 1]
/// \return True on success, false otherwise.
///
/// If the callback function is non zero an returns false the export will be canceled.
Expand All @@ -53,9 +53,15 @@ bool MuseScore::saveAudio(Score* score, QIODevice *device, std::function<bool(fl
}

EventMap events;
score->renderMidi(&events, synthesizerState());
if(events.size() == 0)
return false;
// In non-GUI mode current synthesizer settings won't
// allow single note dynamics. See issue #289947.
const bool useCurrentSynthesizerState = !MScore::noGui;

if (useCurrentSynthesizerState) {
score->renderMidi(&events, synthesizerState());
if (events.empty())
return false;
}

MasterSynthesizer* synth = synthesizerFactory();
synth->init();
Expand All @@ -72,6 +78,16 @@ bool MuseScore::saveAudio(Score* score, QIODevice *device, std::function<bool(fl
synth->init();
}

if (!useCurrentSynthesizerState) {
score->masterScore()->rebuildAndUpdateExpressive(synth->synthesizer("Fluid"));
score->renderMidi(&events, score->synthesizerState());
if (synti)
score->masterScore()->rebuildAndUpdateExpressive(synti->synthesizer("Fluid"));

if (events.empty())
return false;
}

int oldSampleRate = MScore::sampleRate;
MScore::sampleRate = sampleRate;

Expand Down
22 changes: 19 additions & 3 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6881,9 +6881,15 @@ bool MuseScore::saveMp3(Score* score, QIODevice* device, bool& wasCanceled)
return false;
#else
EventMap events;
score->renderMidi(&events, synthesizerState());
if(events.size() == 0)
return false;
// In non-GUI mode current synthesizer settings won't
// allow single note dynamics. See issue #289947.
const bool useCurrentSynthesizerState = !MScore::noGui;

if (useCurrentSynthesizerState) {
score->renderMidi(&events, synthesizerState());
if (events.empty())
return false;
}

MP3Exporter exporter;
if (!exporter.loadLibrary(MP3Exporter::AskUser::MAYBE)) {
Expand Down Expand Up @@ -6955,6 +6961,16 @@ bool MuseScore::saveMp3(Score* score, QIODevice* device, bool& wasCanceled)

MScore::sampleRate = sampleRate;

if (!useCurrentSynthesizerState) {
score->masterScore()->rebuildAndUpdateExpressive(synth->synthesizer("Fluid"));
score->renderMidi(&events, score->synthesizerState());
if (synti)
score->masterScore()->rebuildAndUpdateExpressive(synti->synthesizer("Fluid"));

if (events.empty())
return false;
}

QProgressDialog progress(this);
progress.setWindowFlags(Qt::WindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint));
progress.setWindowModality(Qt::ApplicationModal);
Expand Down

0 comments on commit cf84ff0

Please sign in to comment.