diff options
author | Damien Zammit <damien@zamaudio.com> | 2015-02-13 20:13:41 +1100 |
---|---|---|
committer | Damien Zammit <damien@zamaudio.com> | 2015-02-13 20:13:41 +1100 |
commit | d00365cc523b4d699e4b2b06394a552c45f5c1cc (patch) | |
tree | 7f7445f2e784b43fe88505e941f02023714a0b5d /plugins/ZamSFZ | |
parent | 17e7dbd81a847777a48265778e3f255bd111117d (diff) |
Update ZamSFZ
Signed-off-by: Damien Zammit <damien@zamaudio.com>
Diffstat (limited to 'plugins/ZamSFZ')
-rw-r--r-- | plugins/ZamSFZ/Sfz.cpp | 42 | ||||
-rw-r--r-- | plugins/ZamSFZ/Sfz.hpp | 14 | ||||
-rw-r--r-- | plugins/ZamSFZ/ZamSFZPlugin.cpp | 18 | ||||
-rw-r--r-- | plugins/ZamSFZ/ZamSFZUI.cpp | 1 | ||||
-rw-r--r-- | plugins/ZamSFZ/libsfz/sfz.cpp | 10 |
5 files changed, 63 insertions, 22 deletions
diff --git a/plugins/ZamSFZ/Sfz.cpp b/plugins/ZamSFZ/Sfz.cpp index 32754b4..0bc2383 100644 --- a/plugins/ZamSFZ/Sfz.cpp +++ b/plugins/ZamSFZ/Sfz.cpp @@ -36,11 +36,20 @@ void Sfz::clearsamples() } } } + for (i = 0; i < 128; i++) { + layers[i].max = 0; + for (j = 0; j < MAX_LAYERS; j++) { + layers[i].l[j].lovel = 0; + layers[i].l[j].hivel = 0; + layers[i].l[j].lokey = 0; + layers[i].l[j].hikey = 0; + } + } } void Sfz::loadsamples(std::string path, std::string filename) { - int note, layer, i; + int note, layer, i, key; ::sfz::File* sfzfile = NULL; ::sfz::Instrument* sfzinstrument = NULL; sfzfile = new ::sfz::File(filename, path); @@ -56,22 +65,28 @@ void Sfz::loadsamples(std::string path, std::string filename) } else { for (i = 0; i < maxregions; i++) { for (note = 0; note < 128; note++) { - if (note >= sfzinstrument->regions[i]->lokey && - note <= sfzinstrument->regions[i]->hikey) { - + key = 0; + if (sfzinstrument->regions[i]->lokey == sfzinstrument->regions[i]->hikey) { + key = sfzinstrument->regions[i]->lokey; + } else { + key = sfzinstrument->regions[i]->pitch_keycenter; + } + if (note == key) { infile = NULL; if ((infile = sf_open(sfzinstrument->regions[i]->sample.c_str(), SFM_READ, &sfinfo)) == NULL) { printf("Missing samples\n"); puts (sf_strerror (NULL)); + printf("File: %s\n",sfzinstrument->regions[i]->sample.c_str()); } - readsamples (infile, sfinfo.channels, note, layer); + readsamples (infile, sfinfo.channels, note, layers[note].max); + int k = layers[note].max; + layers[note].l[k].lovel = sfzinstrument->regions[i]->lovel; + layers[note].l[k].hivel = sfzinstrument->regions[i]->hivel; + layers[note].l[k].lokey = sfzinstrument->regions[i]->lokey; + layers[note].l[k].hikey = sfzinstrument->regions[i]->hikey; sf_close (infile); - //printf("N-%d V-%d %s\n", note, layer, sfzinstrument->regions[i]->sample.c_str()); - layer++; - if (sfzinstrument->regions[i]->hivel >= 127) { - maxlayers[note] = layer; - layer = 0; - } + printf("N-%d V-%d %s\n", note, k, sfzinstrument->regions[i]->sample.c_str()); + layers[note].max++; break; } } @@ -79,4 +94,9 @@ void Sfz::loadsamples(std::string path, std::string filename) printf("All samples loaded, Woot!\n"); } delete sfzfile; + for (i = 0; i < 128; i++) { + if (layers[i].max) { + layers[i].max--; + } + } } diff --git a/plugins/ZamSFZ/Sfz.hpp b/plugins/ZamSFZ/Sfz.hpp index b577812..ce7891e 100644 --- a/plugins/ZamSFZ/Sfz.hpp +++ b/plugins/ZamSFZ/Sfz.hpp @@ -12,7 +12,19 @@ class Sfz { public: Sfz(); float sample[128][MAX_LAYERS][2][MAX_SAMPLES]; - int maxlayers[128]; + typedef struct { + uint8_t lovel; + uint8_t hivel; + uint8_t lokey; + uint8_t hikey; + } hilo_t; + + typedef struct { + int max; + hilo_t l[MAX_LAYERS]; + } layer_t; + + layer_t layers[128]; void clearsamples(); void loadsamples(std::string path, std::string filename); void readsamples (SNDFILE *infile, int channels, int note, int layer); diff --git a/plugins/ZamSFZ/ZamSFZPlugin.cpp b/plugins/ZamSFZ/ZamSFZPlugin.cpp index 54b2cc2..9c436e5 100644 --- a/plugins/ZamSFZ/ZamSFZPlugin.cpp +++ b/plugins/ZamSFZ/ZamSFZPlugin.cpp @@ -279,14 +279,20 @@ void ZamSFZPlugin::d_run(const float**, float** outputs, uint32_t frames, voice[k].vi = 0.f; } else { int n = voice[k].notenum; - int vel = (int) (sfz.maxlayers[voice[k].notenum] - * voice[k].vi); + int v = voice[k].vi * 127.; + int l = 0; + for (int k = 0; k < sfz.layers[n].max; k++) { + if (sfz.layers[n].l[k].lovel <= v && v <= sfz.layers[n].l[k].hivel) { + l = k; + break; + } + } int pos = voice[k].rampstate; - wavel = sfz.sample[n][vel][0][pos]; - waver = sfz.sample[n][vel][1][pos]; + wavel = sfz.sample[n][l][0][pos]; + waver = sfz.sample[n][l][1][pos]; } - outl += wavel*voice[k].curamp/5.; - outr += waver*voice[k].curamp/5.; + outl += wavel*voice[k].curamp/2.; + outr += waver*voice[k].curamp/2.; } if (signal) { //outl; diff --git a/plugins/ZamSFZ/ZamSFZUI.cpp b/plugins/ZamSFZ/ZamSFZUI.cpp index 11a440b..d0a477f 100644 --- a/plugins/ZamSFZ/ZamSFZUI.cpp +++ b/plugins/ZamSFZ/ZamSFZUI.cpp @@ -131,6 +131,7 @@ void ZamSFZUI::imageButtonClicked(ImageButton*, int) gtk_widget_destroy(dialog); */ d_setState("filepath", "/home/damien/Music/rhodes-nord/rhodes-nord.sfz"); + //d_setState("filepath", "/home/damien/Music/sfz/sfz LatelyBass/TX_LatelyBass.sfz"); } void ZamSFZUI::onDisplay() diff --git a/plugins/ZamSFZ/libsfz/sfz.cpp b/plugins/ZamSFZ/libsfz/sfz.cpp index 56fca2f..23ecf28 100644 --- a/plugins/ZamSFZ/libsfz/sfz.cpp +++ b/plugins/ZamSFZ/libsfz/sfz.cpp @@ -189,7 +189,7 @@ namespace sfz Instrument::~Instrument() { - for (int i = 0; i < regions.size(); i++) { + for (uint32_t i = 0; i < regions.size(); i++) { delete regions[i]; } } @@ -589,7 +589,7 @@ namespace sfz while (std::getline(fs, line)) { currentLine++; - //printf("line %d: %s\n", currentLine, line.c_str()); + printf("line %d: %s\n", currentLine, line.c_str()); // COMMENT std::string::size_type slash_index = line.find("//"); if (slash_index != std::string::npos) @@ -739,12 +739,14 @@ namespace sfz // sample definition if ("sample" == key) { + std::string path = default_path + value; + for (uint32_t i = 0; i < path.length(); i++) if (path[i] == '\\') path[i] = '/'; switch (_current_section) { case REGION: - _current_region->sample = default_path + value; + _current_region->sample = path; case GROUP: - _current_group->sample = default_path + value; + _current_group->sample = path; } return; } |