BogaudioModules

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

lfo_base.hpp (1477B)


      1 
      2 #pragma once
      3 
      4 #include "bogaudio.hpp"
      5 #include "dsp/oscillator.hpp"
      6 #include "dsp/signal.hpp"
      7 
      8 using namespace bogaudio::dsp;
      9 
     10 namespace bogaudio {
     11 
     12 struct PitchModeListener {
     13 	virtual void pitchModeChanged() = 0;
     14 };
     15 
     16 struct LFOBase : BGModule {
     17 	struct OffsetParamQuantity : ParamQuantity {
     18 		float getDisplayValue() override {
     19 			float v = getValue();
     20 			if (!module) {
     21 				return v;
     22 			}
     23 			auto m = dynamic_cast<LFOBase*>(module);
     24 			return v * m->_offsetScale * 5.0f;
     25 		}
     26 
     27 		void setDisplayValue(float dv) override {
     28 			if (!module) {
     29 				return;
     30 			}
     31 			auto m = dynamic_cast<LFOBase*>(module);
     32 			setValue(dv / (m->_offsetScale * 5.0f));
     33 		}
     34 	};
     35 
     36 	struct Smoother {
     37 		float _sampleRate = 0.0f;
     38 		float _frequency = 0.0f;
     39 		float _amount = 0.0f;
     40 		ShapedSlewLimiter _slewLimiter;
     41 
     42 		void setParams(float sampleRate, float frequency, float amount);
     43 		float next(float sample);
     44 	};
     45 
     46 	bool _slowMode = false;
     47 	float _offsetScale = 1.0f;
     48 	PitchModeListener* _pitchModeListener = NULL;
     49 
     50 	struct LFOFrequencyParamQuantity : FrequencyParamQuantity {
     51 		float offset() override;
     52 	};
     53 
     54 	LFOBase(int np, int ni, int no, int nl = 0) {
     55 		config(np, ni, no, nl);
     56 	}
     57 
     58 	float getPitchOffset();
     59 	void setFrequency(Param& frequency, Input& pitch, Phasor& phasor, int c = 0); // FIXME
     60 	json_t* saveToJson(json_t* root) override;
     61 	void loadFromJson(json_t* root) override;
     62 };
     63 
     64 struct LFOBaseModuleWidget : BGModuleWidget {
     65 	void contextMenu(Menu* menu) override;
     66 };
     67 
     68 } // namespace bogaudio