/* * Architecture wrapper for the headless effects platform */ <> <> #include #include #include #include #ifndef FAUSTFLOAT #define FAUSTFLOAT float #endif #define MAXKNOBS 10 #define MAXSWITCHES 5 #ifndef Uint typedef unsigned int Uint; #endif class dsp {}; // // Our implementation of the Faust Meta interface // struct Meta { public: void declare(const char* key, const char* value) {} }; // // Our implementation of the Faust UI interface // // Effectively we ignore everything except sliders at the moment // class UI { private: float*** sliders; Uint num_sliders; public: UI(float** knobs[]) { sliders = knobs; } ~UI(); virtual void openTabBox(const char* label) {}; virtual void openHorizontalBox(const char* label) {}; virtual void openVerticalBox(const char* label) {}; virtual void closeBox() {}; virtual void addButton(const char* label, FAUSTFLOAT* zone) {}; virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) {}; virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) {}; virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) {}; virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) {}; virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) {}; virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) {}; virtual void addSoundfile(const char* label, const char* filename, void** sf_zone) {}; virtual void declare(FAUSTFLOAT* slider, const char* key, const char* val) { if (num_sliders < MAXKNOBS) { *sliders[num_sliders++]=slider; } } }; // // The interface to the headless framework - very similar to Faust, but not exactly the // the same, so the default implementation is a "protocol converter" between // the two, allowing the Faust code to be used as-is. // // HOWEVER - the Faust code itself may need tweaking to properly implement the // algorithm that it represents - THIS code is simply how to use Faust code // 'directly' in the headles fralework. // struct headless { enum SWITCH_STATE { UP = 0, DOWN = 1, MIDDLE = 2 }; private: float* knobs[MAXKNOBS]; SWITCH_STATE switches[MAXSWITCHES]; SWITCH_STATE stompSwitch; std::string name; UI* faust_ui; mydsp* faust; protected: std::string version; public: int fSampleRate = 44100; stratus() { faust_ui = new UI((float***)&knobs); faust = new mydsp(); faust->init(fSampleRate); faust->buildUserInterface(faust_ui); name = "null"; for (int i = 0; i < MAXSWITCHES; ++i) switches[i] = SWITCH_STATE::DOWN; stompSwitch = DOWN; } ~stratus() {} // Use for switch debugging // static const int SWITCH_STATES = 3; // const char* swStates[SWITCH_STATES] = {"UP", "MIDDLE", "DOWN"}; void getTextForEnum(SWITCH_STATE enumVal, std::string *out) { if (enumVal == 0) // SWITCH_STATE::UP) *out = "UP"; else if (enumVal == 1) // SWITCH_STATE::MIDDLE) *out = "MIDDLE"; else if (enumVal == 2) // SWITCH_STATE::DOWN) *out = "DOWN"; else *out = "BAD"; return; } void setName(std::string name) { this->name = name; } std::string getName() { return name; } std::string getVersion() { return version; } void setKnob(int num, float knobVal) { *(this->knobs[num]) = knobVal; } float getKnob(int in) { return *knobs[in]; } void setSwitch(int num, SWITCH_STATE switchVal) { switches[num] = switchVal; } SWITCH_STATE getSwitch(int in) { return switches[in]; } void setStompSwitch(SWITCH_STATE switchVal) { stompSwitch = switchVal; } bool getStompSwitch() { return stompSwitch; } void stompSwitchPressed(int count, FAUSTFLOAT *inputs, FAUSTFLOAT *outputs) { if (stompSwitch) { faust->compute(count, &inputs, &outputs); } return; } void compute(int count, FAUSTFLOAT *inputs, FAUSTFLOAT *outputs) { faust->compute(count,&inputs,&outputs); } }; extern "C" { headless * create() { return new headless; } } using dsp_creator_t = headless *(*)();