Skip to content

Commit

Permalink
import 1.x, 2.x, 3.x scores with expression enabled automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
jthistle committed Jan 26, 2019
1 parent 633d82c commit 3016ae3
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 1 deletion.
67 changes: 67 additions & 0 deletions libmscore/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "mscore.h"
#include "part.h"
#include "score.h"
#include "synthesizer/msynthesizer.h"
#include "synthesizer/midipatch.h"

#include <QList>
namespace Ms {
Expand Down Expand Up @@ -691,9 +693,11 @@ void Channel::read(XmlReader& e, Part* part)
switch (ctrl) {
case CTRL_HBANK:
_bank = (value << 7) + (_bank & 0x7f);
_userBankController = true;
break;
case CTRL_LBANK:
_bank = (_bank & ~0x7f) + (value & 0x7f);
_userBankController = true;
break;
case CTRL_VOLUME:
_volume = value;
Expand Down Expand Up @@ -765,6 +769,69 @@ void Channel::read(XmlReader& e, Part* part)
updateInitList();
}

//---------------------------------------------------------
// switchExpressive
// Switches channel from non-expressive to expressive patch or vice versa
// This works only with MuseScore General soundfont
//---------------------------------------------------------

void Channel::switchExpressive(MasterSynthesizer* m, bool expressive)
{
if (_userBankController)
return;

// Work out where the new expressive patch will be
// All expressive instruments are +1 bank higher than the
// normal counterparts, except on bank 0, where they are placed on bank 17
int searchBankNum;
if (expressive) {
int relativeBank = bank() % 129;
int newBankNum;
if (relativeBank == 0)
newBankNum = 17;
else
newBankNum = relativeBank + 1;

searchBankNum = (bank()/129)*129 + newBankNum;
}
else {
int relativeBank = bank() % 129;
int newBankNum;
if (relativeBank == 17)
newBankNum = 0;
else
newBankNum = relativeBank - 1;

searchBankNum = (bank()/129)*129 + newBankNum;
}


const auto& pl = m->getPatchInfo();
QString containString;
if (expressive)
containString = QString("Expr.");
else {
for (const MidiPatch* p : pl) {
if (p->bank == bank() && p->prog == program() && p->synti == synti()) {
containString = QString(p->name).replace("Expr.", "").trimmed();
break;
}
}
}


for (const MidiPatch* p : pl) {
if (p->synti == "Fluid") {
if (searchBankNum == p->bank && program() == p->prog && p->name.contains(containString)) {
setBank(p->bank);
return;
}
}
}

// qDebug() << "No expressive matches for patch " << channelPatchName;
}

//---------------------------------------------------------
// updateInitList
//---------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions libmscore/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "mscore.h"
#include "notifier.hpp"
#include "synthesizer/event.h"
#include "synthesizer/msynthesizer.h"
#include "interval.h"
#include "clef.h"
#include <QtGlobal>
Expand Down Expand Up @@ -120,6 +121,8 @@ class Channel {
bool _mute;
bool _solo;

bool _userBankController = false;

public:
static const char* DEFAULT_NAME;

Expand Down Expand Up @@ -185,6 +188,8 @@ class Channel {

void addListener(ChannelListener* l);
void removeListener(ChannelListener* l);

void switchExpressive(MasterSynthesizer* m, bool expressive);
};

//---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion libmscore/rendermidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ static void changeCCBetween(EventMap* events, int stick, int etick, int startExp
// FIXED_MAX - default: velocity is fixed at 127
// SEG_START - note-on velocity is the same as the start velocity of the seg
// SPECIFIED_VELOCITY [and playVelocity] - note on velocity is fixed at this value (not used by default)
// TODO: handle dynamic markings with changes
//---------------------------------------------------------

static void collectMeasureEventsDefault(EventMap* events, Measure* m, Staff* staff, int tickOffset, int cc, int playVelocity, DynamicsRenderMethod method)
Expand Down
54 changes: 54 additions & 0 deletions libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "rehearsalmark.h"
#include "breath.h"
#include "instrchange.h"
#include "synthesizer/msynthesizer.h"

namespace Ms {

Expand Down Expand Up @@ -4453,6 +4454,59 @@ void MasterScore::setLayout(int t)
_cmdState.setTick(t);
}

//---------------------------------------------------------
// updateExpressive
// change patches to their expressive equivalent or vica versa, if possible
// This works only with MuseScore general soundfont
//
// The first version of the function decides whether to make patches expressive
// or not, based on the synth settings. The second will switch patches based on
// the value of the expressive parameter.
//---------------------------------------------------------

void MasterScore::updateExpressive(MasterSynthesizer* m)
{
SynthesizerState s = synthesizerState();
SynthesizerGroup g = s.group("master");

int method;
for (IdValue idVal : g) {
if (idVal.id == 4) {
method = idVal.data.toInt();
break;
}
}

if (method == 0)
updateExpressive(m, false);
else
updateExpressive(m, true);
}


void MasterScore::updateExpressive(MasterSynthesizer* m, bool expressive)
{
SynthesizerState s = synthesizerState();
SynthesizerGroup g = s.group("master");

for (IdValue idVal : g) {
if (idVal.id == 4) {
int method = idVal.data.toInt();
if (expressive == (method == 0))
return; // method and expression change don't match, so don't switch
}
}

for (Part* p : parts()) {
const InstrumentList* il = p->instruments();
for (auto it = il->begin(); it != il->end(); it++) {
Instrument* i = it->second;
for (Channel* c : i->channel())
c->switchExpressive(m, expressive);
}
}
}

//---------------------------------------------------------
// isTopScore
//---------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "spannermap.h"
#include "layoutbreak.h"
#include "property.h"
#include "synthesizer/msynthesizer.h"

namespace Ms {

Expand Down Expand Up @@ -1290,6 +1291,8 @@ class MasterScore : public Score {
int getNextFreeDrumMidiMapping();
void enqueueMidiEvent(MidiInputEvent ev) { _midiInputQueue.enqueue(ev); }
void updateChannel();
void updateExpressive(MasterSynthesizer* m);
void updateExpressive(MasterSynthesizer* m, bool expressive);
void setSoloMute();

void addExcerpt(Excerpt*);
Expand Down
2 changes: 2 additions & 0 deletions mscore/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ MasterScore* MuseScore::getNewFile()
}
score->setCreated(true);
score->fileInfo()->setFile(createDefaultName());
score->updateExpressive(synti);

if (!score->style().chordList()->loaded()) {
if (score->styleB(Sid::chordsXmlFile))
Expand Down Expand Up @@ -2327,6 +2328,7 @@ Score::FileError readScore(MasterScore* score, QString name, bool ignoreVersionE
s->setLayoutAll();
}
score->updateChannel();
score->updateExpressive(synti);
score->setSaved(false);
score->update();

Expand Down
13 changes: 13 additions & 0 deletions mscore/synthcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ void SynthControl::saveButtonClicked()
_score->undo(new ChangeSynthesizerState(_score, synti->state()));
_score->endCmd();

updateExpressivePatches();
loadButton->setEnabled(false);
saveButton->setEnabled(false);
storeButton->setEnabled(true);
Expand Down Expand Up @@ -359,6 +360,7 @@ void SynthControl::storeButtonClicked()
return;
}
synti->storeState();
updateExpressivePatches();
storeButton->setEnabled(false);
recallButton->setEnabled(false);
}
Expand Down Expand Up @@ -397,6 +399,17 @@ void SynthControl::updateGui()
}
}

//---------------------------------------------------------
// updateExpressivePatches
//---------------------------------------------------------

void SynthControl::updateExpressivePatches()
{
_score->masterScore()->updateExpressive(synti);
if (mscore->getMixer())
mscore->getMixer()->updateTracks();
}

//---------------------------------------------------------
// setDirty
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions mscore/synthcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SynthControl : public QWidget, Ui::SynthControl {
virtual void keyPressEvent(QKeyEvent*) override;
void updateGui();
void readSettings();
void updateExpressivePatches();

private slots:
void gainChanged(double, int);
Expand Down
1 change: 1 addition & 0 deletions share/instruments/instruments.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10235,6 +10235,7 @@
<singleNoteDynamics>0</singleNoteDynamics>
<Channel name="pizzicato">
<program value="32"/> <!--Acoustic Bass-->
</Channel>
<Channel>
<program value="32"/>
</Channel>
Expand Down

0 comments on commit 3016ae3

Please sign in to comment.