#ifndef HECK_PERKONS_TRACK_HH #define HECK_PERKONS_TRACK_HH #include "daisysp.h" #include "instr_abstract.hh" #include "utils.hh" #include "globals.hh" namespace dsp = daisysp; namespace Heck { struct Track { public: void init(Instrument::AbstractInstrument& instr) { // Instr instrument.reset(&instr); // Env decay_.Init(Constants::SAMPLERATE); decay_.SetTime(dsp::ADENV_SEG_ATTACK, .0001); decay_.SetTime(dsp::ADENV_SEG_DECAY, 0.1); decay_.SetMax(1); decay_.SetMin(0); decay_.SetCurve(-50); // Vol ctl_volume_ = 0.; // Filter ladder_.Init(Constants::SAMPLERATE); ladder_.SetFilterMode(daisysp::LadderFilter::FilterMode::LP24); ladder_.SetRes(0.4); ladder_.SetInputDrive(1.3); // Drive od_.Init(); od_.SetDrive(0.425); } float nextsample() { float sig = instrument->nextsample(); float vol_env_sig = decay_.Process(); sig *= vol_env_sig; sig = ladder_.Process(sig); sig = od_.Process(sig); sig = vca_(sig, ctl_volume_); return sig; } void trigger() { decay_.Trigger(); instrument->trigger(); } void decay(float val) { decay_.SetTime(dsp::ADENV_SEG_DECAY, 0.01 + val * 12.); } void volume(float vol) { ctl_volume_ = vol; } void filter(float val) { float ladder_freq = 80 + (val * 9000); ladder_.SetFreq(val * ladder_freq); } void drive(float amt) { od_.SetDrive(scalen_min_max(amt, 0.35, 0.5)); } // range: 0-1 void filtermode(float val) { ctl_filtermode_ = val; // MID if (ctl_filtermode_ < 0.33) { hw.PrintLine("Track: Filter BP"); ladder_.SetFilterMode(daisysp::LadderFilter::FilterMode::BP24); } // HIGH if (ctl_filtermode_ >= 0.33 && ctl_filtermode_ < 0.66) { hw.PrintLine("Track: Filter HP"); ladder_.SetFilterMode(daisysp::LadderFilter::FilterMode::HP24); } // LOW if (ctl_filtermode_ >= 0.66) { hw.PrintLine("Track: Filter LP"); ladder_.SetFilterMode(daisysp::LadderFilter::FilterMode::LP24); } } std::shared_ptr instrument{}; private: dsp::AdEnv decay_{}; dsp::LinearVCA vca_{}; dsp::LadderFilter ladder_{}; dsp::Overdrive od_{}; float ctl_volume_{}; float ctl_filtermode_{}; }; } // namespace Heck #endif