Skip to content

Commit

Permalink
opcode "default_path" now taken into account during the sfz import
Browse files Browse the repository at this point in the history
Fix #4
  • Loading branch information
davy7125 committed Nov 7, 2018
1 parent df6222f commit 43c2f0d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
16 changes: 15 additions & 1 deletion sources/core/input/sfz/inputsfz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ QString InputSfz::getNomInstrument(QString filePath, int &numBank, int &numPrese

void InputSfz::changeBloc(QString bloc)
{
if (bloc == "group")
if (bloc == "control")
_currentBloc = BLOC_CONTROL;
else if (bloc == "group")
{
_currentBloc = BLOC_GROUP;
_listeEnsembles << SfzParameterGroupAssembly();
Expand All @@ -329,4 +331,16 @@ void InputSfz::addOpcode(QString opcode, QString value)
{
if (_currentBloc == BLOC_GROUP || _currentBloc == BLOC_REGION)
_listeEnsembles.last().addParam(opcode, value);
else if (_currentBloc == BLOC_CONTROL)
{
if (opcode == "default_path")
{
QString defaultPath = value.replace("\\", "/");
if (!defaultPath.isEmpty() && defaultPath[0] == '/')
defaultPath = defaultPath.right(defaultPath.size() - 1);
if (!defaultPath.isEmpty() && defaultPath.endsWith('/'))
defaultPath = defaultPath.left(defaultPath.size() - 1);
SfzParameter::DEFAULT_PATH = defaultPath;
}
}
}
1 change: 1 addition & 0 deletions sources/core/input/sfz/inputsfz.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected slots:
enum Bloc
{
BLOC_UNKNOWN,
BLOC_CONTROL,
BLOC_GROUP,
BLOC_REGION
};
Expand Down
10 changes: 8 additions & 2 deletions sources/core/input/sfz/sfzparameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "contextmanager.h"
#include <QDebug>

QString SfzParameter::DEFAULT_PATH = "";

SfzParameter::SfzParameter(QString opcode, QString valeur) :
_opcode(op_unknown),
_intValue(0),
Expand All @@ -12,7 +14,11 @@ SfzParameter::SfzParameter(QString opcode, QString valeur) :
if (opcode == "sample")
{
_opcode = op_sample;
_strValue = valeur;
_strValue = valeur.replace("\\", "/");
if (!_strValue.isEmpty() && _strValue[0] == '/')
_strValue = _strValue.right(_strValue.size() - 1);
if (!DEFAULT_PATH.isEmpty())
_strValue = DEFAULT_PATH + "/" + _strValue;
}
else if (opcode == "key")
{
Expand Down Expand Up @@ -344,5 +350,5 @@ SfzParameter::SfzParameter(QString opcode, QString valeur) :
// Nothing to do, no warning
}
else
qDebug() << "non pris en charge: " + opcode + " (" + valeur + ")";
qDebug() << "opcode not supported: " + opcode + " (" + valeur + ")";
}
5 changes: 3 additions & 2 deletions sources/core/input/sfz/sfzparameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SfzParameter
op_amp_velcurve_1,
op_amp_velcurve_127,

// Enveloppe volume
// Envelop volume
op_ampeg_delay,
op_ampeg_attack,
op_ampeg_hold,
Expand All @@ -56,7 +56,7 @@ class SfzParameter
op_modLFOfreq,
op_modLFOtoVolume,

// Enveloppe pitch
// Envelop pitch
op_pitcheg_delay,
op_pitcheg_attack,
op_pitcheg_hold,
Expand Down Expand Up @@ -113,6 +113,7 @@ class SfzParameter
void setIntValue(int value) { _intValue = value; }
void setDoubleValue(double value) { _dblValue = value; }

static QString DEFAULT_PATH;
private:
OpCode _opcode;
int _intValue;
Expand Down
8 changes: 4 additions & 4 deletions sources/core/input/sfz/sfzparametergroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ QList<int> SfzParameterGroup::getSampleIndex(SoundfontManager *sf2, EltID idElt,

// Reconstitution adresse du fichier
QString filePath = _listeParam.at(indexOpSample).getStringValue();
QString fileName = pathSfz + "/" + filePath.replace("\\", "/");
QString fileName = pathSfz + "/" + filePath;
if (!QFile(fileName).exists())
{
QStringList list = getFullPath(pathSfz, filePath.split("/", QString::SkipEmptyParts));
Expand Down Expand Up @@ -142,7 +142,7 @@ void SfzParameterGroup::adaptOffsets(int startLoop, int endLoop, int length)

void SfzParameterGroup::adjustStereoVolumeAndCorrection(QString path, int defaultCorrection)
{
QString sample = getStrValue(SfzParameter::op_sample).replace("\\", "/");
QString sample = getStrValue(SfzParameter::op_sample);
if (!sample.isEmpty())
{
Sound son(path + "/" + sample);
Expand All @@ -154,12 +154,12 @@ void SfzParameterGroup::adjustStereoVolumeAndCorrection(QString path, int defaul
}
}

bool SfzParameterGroup::sampleValid(QString path) const
bool SfzParameterGroup::sampleValid(QString path)
{
bool bRet = false;
if (this->isDefined(SfzParameter::op_sample))
{
QString sample = getStrValue(SfzParameter::op_sample).replace("\\", "/");
QString sample = getStrValue(SfzParameter::op_sample);
bRet = QFile(path + "/" + sample).exists();
}
return bRet;
Expand Down
2 changes: 1 addition & 1 deletion sources/core/input/sfz/sfzparametergroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SfzParameterGroup
QList<int> getSampleIndex(SoundfontManager * sf2, EltID idElt, QString pathSfz) const;
void adaptOffsets(int startLoop, int endLoop, int length);
void adjustStereoVolumeAndCorrection(QString path, int defaultCorrection);
bool sampleValid(QString path) const;
bool sampleValid(QString path);
void checkFilter();
void adjustVolume(double offset);
void adjustCorrection(int offset, int defaultCorrection);
Expand Down
2 changes: 1 addition & 1 deletion sources/core/input/sfz/sfzparametergroupassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void SfzParameterGroupAssembly::checkSampleValid(QString path)
{
int size = _listeDivisions.size();
for (int i = size - 1; i >= 0; i--)
if (!_listeDivisions.at(i).sampleValid(path))
if (!_listeDivisions[i].sampleValid(path))
_listeDivisions.removeAt(i);
}

Expand Down

0 comments on commit 43c2f0d

Please sign in to comment.