From a7cd8cbd1a45e24a1847abe2137177c21e50dda2 Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 14 Sep 2024 00:55:51 +0200 Subject: [PATCH] Add instr_hihat --- src/instr_hihat.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++ src/instr_hihat.hh | 32 ++++++++++++++++++++++++ src/main_perkons.cc | 3 ++- 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/instr_hihat.cc create mode 100644 src/instr_hihat.hh diff --git a/src/instr_hihat.cc b/src/instr_hihat.cc new file mode 100644 index 0000000..420b0e1 --- /dev/null +++ b/src/instr_hihat.cc @@ -0,0 +1,60 @@ +#include "instr_hihat.hh" +#include "daisysp.h" +#include "utils.hh" + +namespace Heck { + namespace Instrument { + + HiHat::HiHat() + { + init(); + } + + void HiHat::init() + { + hihat.Init(samplerate); + hihat.SetDecay(1.); + } + + void HiHat::trigger() + { + hihat.Trig(); + } + + void HiHat::ctl(unsigned int ctl_nr, float val) + { + switch (ctl_nr) { + case 0: { + hihat.SetFreq(scalen_min_max(val, 800, 2000)); + } break; + case 1: { + + } break; + case 2: { + hihat.SetTone(scalen_min_max(val, 0, 1)); + } break; + case 3: { + hihat.SetNoisiness(scalen_min_max(val, 0, 1)); + } break; + } + } + + void HiHat::switch_mode1(unsigned int pos) + { + mode1 = pos; + } + + void HiHat::switch_mode2(unsigned int pos) + { + mode2 = pos; + } + + float HiHat::nextsample() + { + float out{}; + out = hihat.Process(); + return out; + } + + } // namespace Instrument +} // namespace Heck \ No newline at end of file diff --git a/src/instr_hihat.hh b/src/instr_hihat.hh new file mode 100644 index 0000000..2468998 --- /dev/null +++ b/src/instr_hihat.hh @@ -0,0 +1,32 @@ +#ifndef HECK_DAISY_INSTR_HIHAT_HH +#define HECK_DAISY_INSTR_HIHAT_HH + +#include "instr_abstract.hh" +#include "daisy_seed.h" +#include "daisysp.h" + +namespace ld = daisy; +namespace dsp = daisysp; + +namespace Heck { + namespace Instrument { + + class HiHat : public AbstractInstrument { + public: + HiHat(); + void init(); + void trigger() override; + void ctl(unsigned int ctl_nr, float val) override; + void switch_mode1(unsigned int pos) override; + void switch_mode2(unsigned int pos) override; + float nextsample() override; + + private: + dsp::HiHat<> hihat{}; + float mode1{}; + float mode2{}; + }; + + } // namespace Instrument +} // namespace Heck +#endif \ No newline at end of file diff --git a/src/main_perkons.cc b/src/main_perkons.cc index d5d0d32..5f85163 100644 --- a/src/main_perkons.cc +++ b/src/main_perkons.cc @@ -12,6 +12,7 @@ #include "instr_noise.hh" #include "instr_fm.hh" #include "instr_grainlet.hh" +#include "instr_hihat.hh" namespace ld = daisy; namespace dsp = daisysp; @@ -30,7 +31,7 @@ namespace Heck { Instrument::Kick instrument0{}; Instrument::Grainlet instrument1{}; Instrument::FM instrument2{}; - Instrument::Grainlet instrument3{}; + Instrument::HiHat instrument3{}; std::array tracks; MidiClock clock{};