Skip to content

Commit

Permalink
Add 'declare soundfiles' in faust-dynamic-engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Jun 11, 2024
1 parent 59bc7bb commit 0c484de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
23 changes: 22 additions & 1 deletion architecture/faust/dsp/faust-dynamic-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,29 @@ struct dsp_aux {
fDriver->init(fNameApp, fDSP);
fDSP->buildUserInterface(&fParams);
#if SOUNDFILE

// Analyse 'soundfiles' metadata to extract the list of URLs.
struct SoundfilesMeta : Meta
{
vector<string> fURLs;

void declare(const char* key, const char* value)
{
if (string(key) == "soundfiles") {
stringstream ss(value);
string item;
// Use getline with ';' as the delimiter to split the string
while (getline(ss, item, ';')) { fURLs.push_back(item); }
}
}

};

// Use bundle path
fSoundInterface = new SoundUI(SoundUI::getBinaryPath());
SoundfilesMeta sf;
fDSP->metadata(&sf);
sf.fURLs.push_back(SoundUI::getBinaryPath());
fSoundInterface = new SoundUI(sf.fURLs);
fDSP->buildUserInterface(fSoundInterface);
#endif
return true;
Expand Down
3 changes: 1 addition & 2 deletions compiler/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,7 @@ void global::reset()

gInputString = "";
gInputFiles.clear();
gMetaDataSet.clear();


// Backend configuration : default values
gAllowForeignFunction = true;
gAllowForeignConstant = true;
Expand Down
11 changes: 6 additions & 5 deletions tests/llvm-tests/faust-dynamic-engine-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace std;
void test1()
{
// Create an osc DSP using a code string
const char* code = "import(\"stdfaust.lib\"); process = os.osc(500);";
const char* code = "import(\"stdfaust.lib\"); declare soundfiles \"https://url1;https://url2;https://url3\"; process = os.osc(500);";
dsp* DSP = createDsp("Test1", code, 0, NULL, "", -1);
if (!DSP) {
printf("ERROR in createDsp : %s", getLastError());
Expand Down Expand Up @@ -64,9 +64,9 @@ void test2()
char error_msg[4096];

// Create an osc DSP using a code string
Box osc = CDSPToBoxes("FaustDSP", "import(\"stdfaust.lib\"); process = os.osc(500);", 0, nullptr, &inputs, &outputs, error_msg);
Box osc = CDSPToBoxes("FaustDSP", "import(\"stdfaust.lib\"); declare soundfiles \"https://url1;https://url2;https://url3\"; process = os.osc(500);", 0, nullptr, &inputs, &outputs, error_msg);
if (!osc) {
printf("ERROR in CDSPToBoxes : %s\n", error_msg);
printf("ERROR in CDSPToBoxes : %s", error_msg);
destroyLibContext();
return;
}
Expand Down Expand Up @@ -104,9 +104,10 @@ void test3()
char error_msg[4096];

// Create an osc DSP using a code string
Box osc = CDSPToBoxes("FaustDSP", "import(\"stdfaust.lib\"); process = os.osc(500);", 0, nullptr, &inputs, &outputs, error_msg);
Box osc = CDSPToBoxes("FaustDSP", "import(\"stdfaust.lib\"); declare soundfiles \"https://url1;https://url2;https://url3\"; process = os.osc(500);", 0, nullptr, &inputs, &outputs, error_msg);

if (!osc) {
printf("ERROR in CDSPToBoxes : %s\n", error_msg);
printf("ERROR in CDSPToBoxes : %s", error_msg);
destroyLibContext();
return;
}
Expand Down

0 comments on commit 0c484de

Please sign in to comment.