iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugFaustGen.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
27#ifdef FAUST_COMPILED
28 #include "FaustCode.hpp"
29 #define FAUST_BLOCK(class, member, file, nVoices) Faust_##class member {#class, file, nVoices}
30#else
31 #define FAUST_BLOCK(class, member, file, nVoices) iplug::FaustGen member {#class, file, nVoices}
32#endif
33
34#ifndef FAUST_COMPILED
35
36#include <functional>
37#include <memory>
38#include <string>
39#include <vector>
40
41#include "IPlugFaust.h"
42
43#ifndef FAUST_RECOMPILE_INTERVAL
44 #define FAUST_RECOMPILE_INTERVAL 1000 // ms
45#endif
46
47class interpreter_dsp_factory;
48
49BEGIN_IPLUG_NAMESPACE
50
54class FaustGen : public IPlugFaust
55{
56public:
61 FaustGen(const char* name, const char* inputDSPFile = nullptr, int nVoices = 0, const char* libraryPath = FAUST_SHARE_PATH);
62 ~FaustGen();
63
64 FaustGen(const FaustGen&) = delete;
65 FaustGen& operator=(const FaustGen&) = delete;
66
69 void Init() override;
70
73 bool LoadFile(const char* path);
74
77 bool SetSourceCode(const char* sourceCode);
78
80 void AddLibraryPath(const char* path);
81
86 void SetBundleResourcePath(const char* resourcesPath);
87
89 void AddCompileOption(const char* option);
90
92 void SetAutoRecompile(bool enable);
93
98 void SetOnCompileFunc(std::function<void(bool success)> func) { mOnCompileFunc = func; }
99
101 const char* GetErrorMessage() const { return mErrorMessage.c_str(); }
102
103 const char* GetSourceCode() const { return mSourceCode.c_str(); }
104 const char* GetDSPFile() const { return mDSPFile.c_str(); }
105
106private:
107 bool Compile(const std::string& sourceCode);
108 void CompileDefault();
109 bool ReadFile(std::string& contents);
110 void OnTimer(Timer& timer);
111 void OnCompiled(bool success);
112
113 std::string mDSPFile;
114 std::string mSourceCode;
115 std::string mErrorMessage;
116 std::vector<std::string> mLibraryPaths;
117 std::vector<std::string> mCompileOptions;
118 int64_t mFileModifiedTime = 0;
119
120 interpreter_dsp_factory* mFactory = nullptr;
121 std::unique_ptr<Timer> mFileWatchTimer;
122 std::function<void(bool success)> mOnCompileFunc;
123};
124
125END_IPLUG_NAMESPACE
126
127#endif // #ifndef FAUST_COMPILED
#define FAUST_SHARE_PATH
Default search path for the Faust standard libraries (stdfaust.lib etc.), used by the interpreter bac...
Definition: IPlugFaust.h:54
FaustGen compiles Faust code at runtime using the libfaust interpreter backend, so that the DSP can b...
Definition: IPlugFaustGen.h:55
const char * GetErrorMessage() const
void SetBundleResourcePath(const char *resourcesPath)
Use the .dsp file and Faust libraries that iplug_add_faust(... BUNDLE) copies into the bundle's resou...
void AddLibraryPath(const char *path)
Add a path that is searched for imported .lib/.dsp files.
void Init() override
Compile the DSP.
void SetOnCompileFunc(std::function< void(bool success)> func)
Set a function that is called on the main thread after a (re)compilation.
Definition: IPlugFaustGen.h:98
void SetAutoRecompile(bool enable)
Watch the .dsp file and recompile it when it changes.
bool LoadFile(const char *path)
Load and compile a .dsp file, replacing the current DSP if compilation succeeds.
bool SetSourceCode(const char *sourceCode)
Compile Faust source code, replacing the current DSP if compilation succeeds.
void AddCompileOption(const char *option)
Add a compiler option such as "-vec" (see faust –help)
IPlugFaust is the base class for hosting a Faust DSP inside an iPlug2 plug-in.
Definition: IPlugFaust.h:106
Base class for timer.
Definition: IPlugTimer.h:43