198 |
this->name = name; |
this->name = name; |
199 |
this->pSampleManager = pSampleManager ? pSampleManager : this; |
this->pSampleManager = pSampleManager ? pSampleManager : this; |
200 |
pLookupTable = 0; |
pLookupTable = 0; |
201 |
|
|
202 |
|
// The first 6 curves are defined internally (actually 7 with the one at index 0) |
203 |
|
Curve c; |
204 |
|
for (int i = 0; i < 128; i++) c.v[i] = i / 127.0f; |
205 |
|
curves.add(c); curves.add(c); curves.add(c); curves.add(c); |
206 |
|
curves.add(c); curves.add(c); curves.add(c); |
207 |
|
/////// |
208 |
} |
} |
209 |
|
|
210 |
Instrument::~Instrument() |
Instrument::~Instrument() |
946 |
for (int i = 0 ; i < 128 ; i++) { |
for (int i = 0 ; i < 128 ; i++) { |
947 |
_instrument->pLookupTableCC[i] = new LookupTable(_instrument, i); |
_instrument->pLookupTableCC[i] = new LookupTable(_instrument, i); |
948 |
} |
} |
949 |
|
|
950 |
|
for (int k = 0; k < _instrument->regions.size(); k++) { |
951 |
|
Region* r = _instrument->regions[k]; |
952 |
|
|
953 |
|
copyCurves(r->volume_curvecc, r->volume_oncc); |
954 |
|
|
955 |
|
r->volume_curvecc.clear(); |
956 |
|
} |
957 |
} |
} |
958 |
|
|
959 |
File::~File() |
File::~File() |
967 |
{ |
{ |
968 |
return _instrument; |
return _instrument; |
969 |
} |
} |
970 |
|
|
971 |
|
void File::copyCurves(LinuxSampler::ArrayList<CC>& curves, LinuxSampler::ArrayList<CC>& dest) { |
972 |
|
for (int i = 0; i < curves.size(); i++) { |
973 |
|
for (int j = 0; j < dest.size(); j++) { |
974 |
|
if (curves[i].Controller == dest[j].Controller) { |
975 |
|
dest[j].Curve = curves[i].Curve; |
976 |
|
} |
977 |
|
} |
978 |
|
} |
979 |
|
} |
980 |
|
|
981 |
void |
void |
982 |
File::push_header(std::string token) |
File::push_header(std::string token) |
1002 |
octave_offset = 0; |
octave_offset = 0; |
1003 |
note_offset = 0; |
note_offset = 0; |
1004 |
} |
} |
1005 |
|
else if (token == "<curve>") |
1006 |
|
{ |
1007 |
|
_current_section = CURVE; |
1008 |
|
_instrument->curves.add(Curve()); |
1009 |
|
_current_curve = &_instrument->curves[_instrument->curves.size() - 1]; |
1010 |
|
} |
1011 |
else |
else |
1012 |
{ |
{ |
1013 |
_current_section = UNKNOWN; |
_current_section = UNKNOWN; |
1025 |
std::string key = token.substr(0, delimiter_index); |
std::string key = token.substr(0, delimiter_index); |
1026 |
std::string value = token.substr(delimiter_index + 1); |
std::string value = token.substr(delimiter_index + 1); |
1027 |
int x, y, z; |
int x, y, z; |
1028 |
|
|
1029 |
|
if (_current_section == CURVE) { |
1030 |
|
if (sscanf(key.c_str(), "v%d", &x)) { |
1031 |
|
if (x < 0 || x > 127) { |
1032 |
|
std::cerr << "Invalid curve index: " << x << std::endl; |
1033 |
|
} |
1034 |
|
_current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value)); |
1035 |
|
} else { |
1036 |
|
std::cerr << "The opcode '" << key << "' in section <curve> is unsupported by libsfz!" << std::endl; |
1037 |
|
} |
1038 |
|
|
1039 |
|
return; |
1040 |
|
} |
1041 |
|
|
1042 |
// sample definition |
// sample definition |
1043 |
if ("sample" == key) |
if ("sample" == key) |
1376 |
else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value)); |
else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value)); |
1377 |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1378 |
} |
} |
1379 |
|
|
1380 |
// CCs |
// CCs |
1381 |
else if (key.find("cc") != std::string::npos) |
else if (key.find("cc") != std::string::npos) |
1382 |
{ |
{ |
1449 |
else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1450 |
else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1451 |
else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1452 |
|
else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1453 |
|
else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) ); |
1454 |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1455 |
} |
} |
1456 |
|
|
1521 |
cutoff = eg.cutoff; |
cutoff = eg.cutoff; |
1522 |
node = eg.node; |
node = eg.node; |
1523 |
} |
} |
|
|
|
|
EG& File::eg(int x) { |
|
|
while (pCurDef->eg.size() <= x) { |
|
|
pCurDef->eg.add(EG()); |
|
|
} |
|
|
return pCurDef->eg[x]; |
|
|
} |
|
|
|
|
|
EGNode& File::egnode(int x, int y) { |
|
|
EG& e = eg(x); |
|
|
while (e.node.size() <= y) { |
|
|
e.node.add(EGNode()); |
|
|
} |
|
|
return e.node[y]; |
|
|
} |
|
1524 |
|
|
1525 |
LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */ |
LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */ |
1526 |
fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) { |
fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) { |
1544 |
pitch_oncc = lfo.pitch_oncc; |
pitch_oncc = lfo.pitch_oncc; |
1545 |
} |
} |
1546 |
|
|
1547 |
|
EG& File::eg(int x) { |
1548 |
|
while (pCurDef->eg.size() <= x) { |
1549 |
|
pCurDef->eg.add(EG()); |
1550 |
|
} |
1551 |
|
return pCurDef->eg[x]; |
1552 |
|
} |
1553 |
|
|
1554 |
|
EGNode& File::egnode(int x, int y) { |
1555 |
|
EG& e = eg(x); |
1556 |
|
while (e.node.size() <= y) { |
1557 |
|
e.node.add(EGNode()); |
1558 |
|
} |
1559 |
|
return e.node[y]; |
1560 |
|
} |
1561 |
|
|
1562 |
LFO& File::lfo(int x) { |
LFO& File::lfo(int x) { |
1563 |
while (pCurDef->lfos.size() <= x) { |
while (pCurDef->lfos.size() <= x) { |
1564 |
pCurDef->lfos.add(LFO()); |
pCurDef->lfos.add(LFO()); |