Skip to content

Commit

Permalink
Merge pull request #4996 from mattmcclinch/synthesizer
Browse files Browse the repository at this point in the history
Remove "synthesizer/msynthesizer.h" dependency from libmscore.
  • Loading branch information
anatoly-os committed May 8, 2019
2 parents 2279c06 + be64d8c commit c066b6b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 30 deletions.
17 changes: 8 additions & 9 deletions libmscore/instrument.cpp
Expand Up @@ -20,7 +20,6 @@
#include "mscore.h"
#include "part.h"
#include "score.h"
#include "synthesizer/msynthesizer.h"
#include "synthesizer/synthesizer.h"
#include "synthesizer/midipatch.h"

Expand Down Expand Up @@ -799,13 +798,13 @@ void Channel::read(XmlReader& e, Part* part)
// This works only with MuseScore General soundfont
//---------------------------------------------------------

void Channel::switchExpressive(MasterSynthesizer* m, bool expressive, bool force /* = false */)
void Channel::switchExpressive(Synthesizer* synth, bool expressive, bool force /* = false */)
{
if ((_userBankController && !force) || !m)
if ((_userBankController && !force) || !synth)
return;

// Check that we're actually changing the MuseScore General soundfont
const auto fontsInfo = m->synthesizer("Fluid")->soundFontsInfo();
const auto fontsInfo = synth->soundFontsInfo();
if (fontsInfo.empty())
return;
const auto& info = fontsInfo.front();
Expand Down Expand Up @@ -841,7 +840,7 @@ void Channel::switchExpressive(MasterSynthesizer* m, bool expressive, bool force

// Floor bank num to multiple of 129 and add new num to get bank num of new patch
searchBankNum = (bank() / 129) * 129 + newBankNum;
const auto& pl = m->getPatchInfo();
const auto& pl = synth->getPatchInfo();
for (const MidiPatch* p : pl) {
if (p->synti == "Fluid") {
if (searchBankNum == p->bank && program() == p->prog) {
Expand Down Expand Up @@ -1115,16 +1114,16 @@ void Instrument::updateGateTime(int* gateTime, int /*channelIdx*/, const QString
// updateGateTime
//---------------------------------------------------------

void Instrument::switchExpressive(MasterScore* score, MasterSynthesizer* m, bool expressive, bool force /* = false */)
void Instrument::switchExpressive(MasterScore* score, Synthesizer* synth, bool expressive, bool force /* = false */)
{
// Only switch to expressive where necessary
if (!m || (expressive && !singleNoteDynamics()))
if (!synth || (expressive && !singleNoteDynamics()))
return;

for (Channel* c : channel()) {
c->switchExpressive(m, expressive, force);
c->switchExpressive(synth, expressive, force);
if (score->playbackChannel(c))
score->playbackChannel(c)->switchExpressive(m, expressive, force);
score->playbackChannel(c)->switchExpressive(synth, expressive, force);
}
}

Expand Down
6 changes: 3 additions & 3 deletions libmscore/instrument.h
Expand Up @@ -31,7 +31,7 @@ class XmlReader;
class Drumset;
class StringData;
class ChannelListener;
class MasterSynthesizer;
class Synthesizer;

//---------------------------------------------------------
// StaffName
Expand Down Expand Up @@ -195,7 +195,7 @@ class Channel {
void addListener(ChannelListener* l);
void removeListener(ChannelListener* l);

void switchExpressive(MasterSynthesizer* m, bool expressive, bool force = false);
void switchExpressive(Synthesizer* synth, bool expressive, bool force = false);
};

//---------------------------------------------------------
Expand Down Expand Up @@ -340,7 +340,7 @@ class Instrument {
void setSingleNoteDynamics(bool val) { _singleNoteDynamics = val; }
void setSingleNoteDynamicsFromTemplate();
bool getSingleNoteDynamicsFromTemplate() const;
void switchExpressive(MasterScore* score, MasterSynthesizer* m, bool expressive, bool force = false);
void switchExpressive(MasterScore* score, Synthesizer* synth, bool expressive, bool force = false);
};

//---------------------------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions libmscore/score.cpp
Expand Up @@ -4630,7 +4630,7 @@ void MasterScore::setLayout(const Fraction& t)
// the value of the expressive parameter.
//---------------------------------------------------------

void MasterScore::updateExpressive(MasterSynthesizer* m)
void MasterScore::updateExpressive(Synthesizer* synth)
{
SynthesizerState s = synthesizerState();
SynthesizerGroup g = s.group("master");
Expand All @@ -4643,13 +4643,13 @@ void MasterScore::updateExpressive(MasterSynthesizer* m)
}
}

updateExpressive(m, (method != 0));
updateExpressive(synth, (method != 0));
}


void MasterScore::updateExpressive(MasterSynthesizer* m, bool expressive, bool force /* = false */)
void MasterScore::updateExpressive(Synthesizer* synth, bool expressive, bool force /* = false */)
{
if (!m)
if (!synth)
return;

if (!force) {
Expand All @@ -4669,7 +4669,7 @@ void MasterScore::updateExpressive(MasterSynthesizer* m, bool expressive, bool f
const InstrumentList* il = p->instruments();
for (auto it = il->begin(); it != il->end(); it++) {
Instrument* i = it->second;
i->switchExpressive(this, m, expressive, force);
i->switchExpressive(this, synth, expressive, force);
}
}

Expand All @@ -4681,12 +4681,12 @@ void MasterScore::updateExpressive(MasterSynthesizer* m, bool expressive, bool f
// just updateExpressive, in most cases.
//---------------------------------------------------------

void MasterScore::rebuildAndUpdateExpressive(MasterSynthesizer* m)
void MasterScore::rebuildAndUpdateExpressive(Synthesizer* synth)
{
// Rebuild midi mappings to make sure we have playback channels
rebuildMidiMapping();

updateExpressive(m);
updateExpressive(synth);

// Rebuild midi mappings again to be safe
rebuildMidiMapping();
Expand Down
6 changes: 3 additions & 3 deletions libmscore/score.h
Expand Up @@ -1321,9 +1321,9 @@ class MasterScore : public Score {
int getNextFreeDrumMidiMapping();
void enqueueMidiEvent(MidiInputEvent ev) { _midiInputQueue.enqueue(ev); }
void updateChannel();
void rebuildAndUpdateExpressive(MasterSynthesizer* m);
void updateExpressive(MasterSynthesizer* m);
void updateExpressive(MasterSynthesizer* m, bool expressive, bool force = false);
void rebuildAndUpdateExpressive(Synthesizer* synth);
void updateExpressive(Synthesizer* synth);
void updateExpressive(Synthesizer* synth, bool expressive, bool force = false);
void setSoloMute();

void addExcerpt(Excerpt*);
Expand Down
2 changes: 1 addition & 1 deletion mscore/editstaff.cpp
Expand Up @@ -384,7 +384,7 @@ void EditStaff::apply()

score->update();
score->masterScore()->updateChannel();
staff->score()->masterScore()->rebuildAndUpdateExpressive(synti);
staff->score()->masterScore()->rebuildAndUpdateExpressive(MuseScore::synthesizer("Fluid"));
}

//---------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions mscore/file.cpp
Expand Up @@ -764,7 +764,7 @@ MasterScore* MuseScore::getNewFile()
score->setSynthesizerState(synti->state());

// Call this even if synti doesn't exist - we need to rebuild either way
score->rebuildAndUpdateExpressive(synti);
score->rebuildAndUpdateExpressive(MuseScore::synthesizer("Fluid"));

{
ScoreLoad sl;
Expand Down Expand Up @@ -2340,7 +2340,7 @@ Score::FileError readScore(MasterScore* score, QString name, bool ignoreVersionE
s->setLayoutAll();
}
score->updateChannel();
score->updateExpressive(synti);
score->updateExpressive(MuseScore::synthesizer("Fluid"));
score->setSaved(false);
score->update();

Expand Down
2 changes: 1 addition & 1 deletion mscore/instrdialog.cpp
Expand Up @@ -532,7 +532,7 @@ void MuseScore::editInstrList()

masterScore->setLayoutAll();
masterScore->endCmd();
masterScore->rebuildAndUpdateExpressive(synti);
masterScore->rebuildAndUpdateExpressive(MuseScore::synthesizer("Fluid"));
seq->initInstruments();
}

Expand Down
9 changes: 9 additions & 0 deletions mscore/musescore.cpp
Expand Up @@ -6656,6 +6656,15 @@ SynthesizerState MuseScore::synthesizerState() const
return synti ? synti->state() : state;
}

//---------------------------------------------------------
// synthesizer
//---------------------------------------------------------

Synthesizer* MuseScore::synthesizer(const QString& name)
{
return synti ? synti->synthesizer(name) : nullptr;
}

//---------------------------------------------------------
// canSaveMp3
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions mscore/musescore.h
Expand Up @@ -752,6 +752,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
void addMetronome();

SynthesizerState synthesizerState() const;
static Synthesizer* synthesizer(const QString& name);

Q_INVOKABLE QString getLocaleISOCode() const;
Navigator* navigator() const;
Expand Down
8 changes: 4 additions & 4 deletions mscore/synthcontrol.cpp
Expand Up @@ -281,7 +281,7 @@ void SynthControl::ccToUseChanged(int val)

void SynthControl::switchExprButtonClicked()
{
_score->masterScore()->updateExpressive(synti, true, true);
_score->masterScore()->updateExpressive(MuseScore::synthesizer("Fluid"), true, true);
setAllUserBankController(true);
updateMixer();
}
Expand All @@ -292,7 +292,7 @@ void SynthControl::switchExprButtonClicked()

void SynthControl::switchNonExprButtonClicked()
{
_score->masterScore()->updateExpressive(synti, false, true);
_score->masterScore()->updateExpressive(MuseScore::synthesizer("Fluid"), false, true);
setAllUserBankController(true);
updateMixer();
}
Expand All @@ -304,7 +304,7 @@ void SynthControl::switchNonExprButtonClicked()
void SynthControl::resetExprButtonClicked()
{
setAllUserBankController(false);
_score->masterScore()->updateExpressive(synti);
_score->masterScore()->updateExpressive(MuseScore::synthesizer("Fluid"));
updateMixer();
}

Expand Down Expand Up @@ -459,7 +459,7 @@ void SynthControl::updateGui()

void SynthControl::updateExpressivePatches()
{
_score->masterScore()->rebuildAndUpdateExpressive(synti);
_score->masterScore()->rebuildAndUpdateExpressive(MuseScore::synthesizer("Fluid"));
updateMixer();
}

Expand Down

0 comments on commit c066b6b

Please sign in to comment.