|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /*
- * DISTRHO Kars Plugin, based on karplong by Chris Cannam.
- * Copyright (C) 2015 Filipe Coelho <falktx@falktx.com>
- *
- * Permission to use, copy, modify, and/or distribute this software for any purpose with
- * or without fee is hereby granted, provided that the above copyright notice and this
- * permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
- * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
- #ifndef DISTRHO_PLUGIN_KARS_HPP_INCLUDED
- #define DISTRHO_PLUGIN_KARS_HPP_INCLUDED
-
- #include "DistrhoPlugin.hpp"
-
- START_NAMESPACE_DISTRHO
-
- // -----------------------------------------------------------------------
-
- class DistrhoPluginKars : public Plugin
- {
- public:
- static const int kMaxNotes = 128;
- static const uint32_t kNoteNull = (uint32_t)-1;
-
- enum Parameters
- {
- paramSustain = 0,
- paramCount
- };
-
- DistrhoPluginKars();
-
- protected:
- // -------------------------------------------------------------------
- // Information
-
- const char* getLabel() const noexcept override
- {
- return "Kars";
- }
-
- const char* getDescription() const override
- {
- return "Simple karplus-strong plucked string synth.";
- }
-
- const char* getMaker() const noexcept override
- {
- return "falkTX";
- }
-
- const char* getHomePage() const override
- {
- return "https://github.com/DISTRHO/Kars";
- }
-
- const char* getLicense() const noexcept override
- {
- return "ISC";
- }
-
- uint32_t getVersion() const noexcept override
- {
- return d_version(1, 0, 0);
- }
-
- int64_t getUniqueId() const noexcept override
- {
- return d_cconst('D', 'K', 'r', 's');
- }
-
- // -------------------------------------------------------------------
- // Init
-
- void initParameter(uint32_t index, Parameter& parameter) override;
-
- // -------------------------------------------------------------------
- // Internal data
-
- float getParameterValue(uint32_t index) const override;
- void setParameterValue(uint32_t index, float value) override;
-
- // -------------------------------------------------------------------
- // Process
-
- void activate() override;
- void run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) override;
-
- // -------------------------------------------------------------------
-
- private:
- bool fSustain;
- double fSampleRate;
- uint32_t fBlockStart;
-
- struct Note {
- uint32_t on;
- uint32_t off;
- uint8_t velocity;
- float index;
- float size;
- int sizei;
- float* wavetable;
-
- Note() noexcept
- : on(kNoteNull),
- off(kNoteNull),
- velocity(0),
- index(0.0f),
- size(0.0f),
- wavetable(nullptr) {}
-
- ~Note() noexcept
- {
- if (wavetable != nullptr)
- {
- delete[] wavetable;
- wavetable = nullptr;
- }
- }
-
- void setSampleRate(const double sampleRate)
- {
- if (wavetable != nullptr)
- delete[] wavetable;
-
- const float frequency = 440.0f * std::pow(2.0f, (index - 69.0f) / 12.0f);
- size = sampleRate / frequency;
- sizei = int(size)+1;
- wavetable = new float[sizei];
- std::memset(wavetable, 0, sizeof(float)*static_cast<size_t>(sizei));
- }
-
- } fNotes[kMaxNotes];
-
- void addSamples(float* out, int voice, uint32_t offset, uint32_t count);
-
- DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistrhoPluginKars)
- };
-
- // -----------------------------------------------------------------------
-
- END_NAMESPACE_DISTRHO
-
- #endif // DISTRHO_PLUGIN_KARS_HPP_INCLUDED
|