123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- /*
- * lb302.h - declaration of class lb302 which is a bass synth attempting to
- * emulate the Roland TB303 bass synth
- *
- * Copyright (c) 2006-2008 Paul Giblock <pgib/at/users.sourceforge.net>
- *
- * This file is part of LMMS - https://lmms.io
- *
- * lb302FilterIIR2 is based on the gsyn filter code by Andy Sloane.
- *
- * lb302Filter3Pole is based on the TB303 instrument written by
- * Josep M Comajuncosas for the CSounds library
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program (see COPYING); if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- */
- #ifndef LB302_H_
- #define LB302_H_
- #include "DspEffectLibrary.h"
- #include "Instrument.h"
- #include "InstrumentView.h"
- #include "LedCheckbox.h"
- #include "Knob.h"
- #include "NotePlayHandle.h"
- #include <QMutex>
- static const int NUM_FILTERS = 2;
- class lb302SynthView;
- class NotePlayHandle;
- class lb302FilterKnobState
- {
- public:
- float cutoff;
- float reso;
- float envmod;
- float envdecay;
- float dist;
- };
- class lb302Filter
- {
- public:
- lb302Filter(lb302FilterKnobState* p_fs);
- virtual ~lb302Filter() {};
- virtual void recalc();
- virtual void envRecalc();
- virtual float process(const float& samp)=0;
- virtual void playNote();
- protected:
- lb302FilterKnobState *fs;
- // Filter Decay
- float vcf_c0; // c0=e1 on retrigger; c0*=ed every sample; cutoff=e0+c0
- float vcf_e0, // e0 and e1 for interpolation
- vcf_e1;
- float vcf_rescoeff; // Resonance coefficient [0.30,9.54]
- };
- class lb302FilterIIR2 : public lb302Filter
- {
- public:
- lb302FilterIIR2(lb302FilterKnobState* p_fs);
- virtual ~lb302FilterIIR2();
- virtual void recalc();
- virtual void envRecalc();
- virtual float process(const float& samp);
- protected:
- float vcf_d1, // d1 and d2 are added back into the sample with
- vcf_d2; // vcf_a and b as coefficients. IIR2 resonance
- // loop.
- // IIR2 Coefficients for mixing dry and delay.
- float vcf_a, // Mixing coefficients for the final sound.
- vcf_b, //
- vcf_c;
- DspEffectLibrary::Distortion * m_dist;
- };
- class lb302Filter3Pole : public lb302Filter
- {
- public:
- lb302Filter3Pole(lb302FilterKnobState* p_fs);
- //virtual void recalc();
- virtual void envRecalc();
- virtual void recalc();
- virtual float process(const float& samp);
- protected:
- float kfcn,
- kp,
- kp1,
- kp1h,
- kres;
- float ay1,
- ay2,
- aout,
- lastin,
- value;
- };
- class lb302Note
- {
- public:
- float vco_inc;
- bool dead;
- };
- class lb302Synth : public Instrument
- {
- Q_OBJECT
- public:
- lb302Synth( InstrumentTrack * _instrument_track );
- virtual ~lb302Synth();
- virtual void play( sampleFrame * _working_buffer );
- virtual void playNote( NotePlayHandle * _n,
- sampleFrame * _working_buffer );
- virtual void deleteNotePluginData( NotePlayHandle * _n );
- virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
- virtual void loadSettings( const QDomElement & _this );
- virtual QString nodeName() const;
- virtual Flags flags() const
- {
- return IsSingleStreamed;
- }
- virtual f_cnt_t desiredReleaseFrames() const
- {
- return 0; //4048;
- }
- virtual PluginView * instantiateView( QWidget * _parent );
- private:
- void processNote( NotePlayHandle * n );
- void initNote(lb302Note *Note);
- void initSlide();
- private:
- FloatModel vcf_cut_knob;
- FloatModel vcf_res_knob;
- FloatModel vcf_mod_knob;
- FloatModel vcf_dec_knob;
- FloatModel vco_fine_detune_knob;
- FloatModel dist_knob;
- IntModel wave_shape;
- FloatModel slide_dec_knob;
- BoolModel slideToggle;
- BoolModel accentToggle;
- BoolModel deadToggle;
- BoolModel db24Toggle;
- public slots:
- void filterChanged();
- void db24Toggled();
- private:
- // Oscillator
- float vco_inc, // Sample increment for the frequency. Creates Sawtooth.
- vco_k, // Raw oscillator sample [-0.5,0.5]
- vco_c; // Raw oscillator sample [-0.5,0.5]
- float vco_slide, //* Current value of slide exponential curve. Nonzero=sliding
- vco_slideinc, //* Slide base to use in next node. Nonzero=slide next note
- vco_slidebase; //* The base vco_inc while sliding.
- enum vco_shape_t { SAWTOOTH, SQUARE, TRIANGLE, MOOG, ROUND_SQUARE, SINE, EXPONENTIAL, WHITE_NOISE,
- BL_SAWTOOTH, BL_SQUARE, BL_TRIANGLE, BL_MOOG };
- vco_shape_t vco_shape;
- // Filters (just keep both loaded and switch)
- lb302Filter* vcfs[NUM_FILTERS];
- // User settings
- lb302FilterKnobState fs;
- QAtomicPointer<lb302Filter> vcf;
- int release_frame;
- // More States
- int vcf_envpos; // Update counter. Updates when >= ENVINC
- float vca_attack, // Amp attack
- vca_decay, // Amp decay
- vca_a0, // Initial amplifier coefficient
- vca_a; // Amplifier coefficient.
- // Envelope State
- enum VCA_Mode
- {
- attack = 0,
- decay = 1,
- idle = 2,
- never_played = 3
- };
- VCA_Mode vca_mode;
- // My hacks
- int sample_cnt;
- int last_offset;
- int catch_frame;
- int catch_decay;
- bool new_freq;
- float true_freq;
- void recalcFilter();
- int process(sampleFrame *outbuf, const int size);
- friend class lb302SynthView;
- NotePlayHandle * m_playingNote;
- NotePlayHandleList m_notes;
- QMutex m_notesMutex;
- } ;
- class lb302SynthView : public InstrumentViewFixedSize
- {
- Q_OBJECT
- public:
- lb302SynthView( Instrument * _instrument,
- QWidget * _parent );
- virtual ~lb302SynthView();
- private:
- virtual void modelChanged();
- Knob * m_vcfCutKnob;
- Knob * m_vcfResKnob;
- Knob * m_vcfDecKnob;
- Knob * m_vcfModKnob;
- Knob * m_distKnob;
- Knob * m_slideDecKnob;
- automatableButtonGroup * m_waveBtnGrp;
- LedCheckBox * m_slideToggle;
- /*LedCheckBox * m_accentToggle;*/ // removed pending accent implementation
- LedCheckBox * m_deadToggle;
- LedCheckBox * m_db24Toggle;
- } ;
- #endif
|