BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

module.hpp (2429B)


      1 #pragma once
      2 
      3 #include "rack.hpp"
      4 #include "skins.hpp"
      5 #include <string>
      6 #include <vector>
      7 
      8 using namespace rack;
      9 
     10 namespace bogaudio {
     11 
     12 struct SkinChangeListener {
     13 	virtual void skinChanged(const std::string& skin) = 0;
     14 };
     15 
     16 struct BGModule : Module {
     17 	int _modulationSteps = 100;
     18 	int _steps = -1;
     19 	bool _initialized = false;
     20 
     21 	static constexpr int maxChannels = PORT_MAX_CHANNELS;
     22 	int _channels = 0;
     23 	float _inverseChannels = 0.0f;
     24 
     25 	bool _skinnable = true;
     26 	std::string _skin = "default";
     27 	std::vector<SkinChangeListener*> _skinChangeListeners;
     28 
     29 	BGModule() {}
     30 	virtual ~BGModule() {}
     31 
     32 	void onRemove() override;
     33 	void onReset() override;
     34 	void onSampleRateChange() override;
     35 	json_t* dataToJson() override;
     36 	void dataFromJson(json_t* root) override;
     37 	void process(const ProcessArgs& args) override;
     38 
     39 	virtual void reset() {}
     40 	virtual void sampleRateChange() {}
     41 	virtual json_t* saveToJson(json_t* root) { return root; }
     42 	virtual void loadFromJson(json_t* root) {}
     43 	virtual bool active() { return true; }
     44 	virtual int channels() { return 1; }
     45 	virtual void channelsChanged(int before, int after) {}
     46 	virtual void addChannel(int c) {}
     47 	virtual void removeChannel(int c) {}
     48 	virtual void modulateAlways() {}
     49 	virtual void processAlways(const ProcessArgs& args) {} // called before modulate()!
     50 	virtual void modulate() {}
     51 	virtual void modulateChannel(int c) {}
     52 	virtual void processAll(const ProcessArgs& args) {}
     53 	virtual void processChannel(const ProcessArgs& args, int c) {}
     54 	virtual void postProcess(const ProcessArgs& args) {}
     55 	virtual void postProcessAlways(const ProcessArgs& args) {} // modulate() may not have been called.
     56 
     57 	void setSkin(std::string skin);
     58 	void addSkinChangeListener(SkinChangeListener* listener);
     59 };
     60 
     61 struct BGModuleWidget : ModuleWidget, SkinChangeListener, DefaultSkinChangeListener {
     62 	bool _skinnable = true;
     63 	SvgPanel* _panel = NULL;
     64 	Vec _size;
     65 	std::string _slug;
     66 	std::string _loadedSkin;
     67 
     68 	BGModuleWidget();
     69 	virtual ~BGModuleWidget();
     70 
     71 	void appendContextMenu(Menu* menu) override;
     72 	void addParam(ParamWidget* param);
     73 	void addInput(PortWidget* input);
     74 	void addOutput(PortWidget* output);
     75 
     76 	virtual void contextMenu(Menu* menu) {}
     77 
     78 	void skinChanged(const std::string& skin) override;
     79 	void defaultSkinChanged(const std::string& skin) override;
     80 	void setPanel(Vec size, const std::string slug, bool skinnable = true);
     81 	void updatePanel();
     82 	void createScrews();
     83 };
     84 
     85 } // namespace bogaudio