123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- /*
- * sfxr.h - declaration of classes of the LMMS sfxr plugin
- * Originally written by Tomas Pettersson. For the original license,
- * please read readme.txt in this directory
- *
- * Copyright (c) 2014 Wong Cho Ching
- *
- * This file is part of LMMS - https://lmms.io
- *
- * 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 SFXR_H
- #define SFXR_H
- #include "Instrument.h"
- #include "InstrumentView.h"
- #include "Knob.h"
- #include "Graph.h"
- #include "PixmapButton.h"
- #include "LedCheckbox.h"
- #include "MemoryManager.h"
- enum SfxrWaves
- {
- SQR_WAVE, SAW_WAVE, SINE_WAVE, NOISE_WAVE, WAVES_NUM
- };
- const int WAVEFORM_BASE_X = 20;
- const int WAVEFORM_BASE_Y = 15;
- const int WAVEFORM_BUTTON_WIDTH = 16;
- const int GENERATOR_BASE_X = 110;
- const int GENERATOR_BASE_Y = 25;
- const int GENERATOR_BUTTON_WIDTH = 16;
- const int RAND_BUTTON_X = 160;
- const int RAND_BUTTON_Y = 4;
- const int MUTA_BUTTON_X = 205;
- const int MUTA_BUTTON_Y = 4;
- const int KNOBS_BASE_X = 20;
- const int KNOBS_BASE_Y = 50;
- const int KNOB_BLOCK_SIZE_X = 40;
- const int KNOB_BLOCK_SIZE_Y = 40;
- class sfxrInstrument;
- class SfxrSynth
- {
- MM_OPERATORS
- public:
- SfxrSynth( const sfxrInstrument * s );
- virtual ~SfxrSynth();
- void resetSample( bool restart );
- void update( sampleFrame * buffer, const int32_t frameNum );
- bool isPlaying() const;
- private:
- const sfxrInstrument * s;
- bool playing_sample;
- int phase;
- double fperiod;
- double fmaxperiod;
- double fslide;
- double fdslide;
- int period;
- float square_duty;
- float square_slide;
- int env_stage;
- int env_time;
- int env_length[3];
- float env_vol;
- float fphase;
- float fdphase;
- int iphase;
- float phaser_buffer[1024];
- int ipp;
- float noise_buffer[32];
- float fltp;
- float fltdp;
- float fltw;
- float fltw_d;
- float fltdmp;
- float fltphp;
- float flthp;
- float flthp_d;
- float vib_phase;
- float vib_speed;
- float vib_amp;
- int rep_time;
- int rep_limit;
- int arp_time;
- int arp_limit;
- double arp_mod;
- } ;
- /**
- * @brief A class that simplify the constructor of FloatModel, with value [0,1]
- */
- class SfxrZeroToOneFloatModel : public FloatModel
- {
- public:
- SfxrZeroToOneFloatModel( float val, Model * parent, const QString& displayName ):
- FloatModel( val, 0.0, 1.0, 0.001, parent, displayName )
- {
- }
- /* purpose: prevent the initial value of the model from being changed */
- virtual void loadSettings( const QDomElement& element, const QString& name = QString( "value" ) )
- {
- float oldInitValue = initValue();
- FloatModel::loadSettings(element, name);
- float oldValue = value();
- setInitValue(oldInitValue);
- setValue(oldValue);
- }
- };
- /**
- * @brief A class that simplify the constructor of FloatModel, with value [-1,1]
- */
- class SfxrNegPosOneFloatModel : public FloatModel
- {
- public:
- SfxrNegPosOneFloatModel(float val, Model * parent, const QString& displayName ):
- FloatModel( val, -1.0, 1.0, 0.001, parent, displayName )
- {
- }
- /* purpose: prevent the initial value of the model from being changed */
- virtual void loadSettings( const QDomElement& element, const QString& name = QString( "value" ) )
- {
- float oldInitValue = initValue();
- FloatModel::loadSettings(element, name);
- float oldValue = value();
- setInitValue(oldInitValue);
- setValue(oldValue);
- }
- };
- class sfxrInstrument : public Instrument
- {
- Q_OBJECT
- public:
- sfxrInstrument(InstrumentTrack * _instrument_track );
- virtual ~sfxrInstrument();
- 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 PluginView * instantiateView( QWidget * _parent );
- void resetModels();
- private:
- SfxrZeroToOneFloatModel m_attModel;
- SfxrZeroToOneFloatModel m_holdModel;
- SfxrZeroToOneFloatModel m_susModel;
- SfxrZeroToOneFloatModel m_decModel;
- SfxrZeroToOneFloatModel m_startFreqModel;
- SfxrZeroToOneFloatModel m_minFreqModel;
- SfxrNegPosOneFloatModel m_slideModel;
- SfxrNegPosOneFloatModel m_dSlideModel;
- SfxrZeroToOneFloatModel m_vibDepthModel;
- SfxrZeroToOneFloatModel m_vibSpeedModel;
- SfxrNegPosOneFloatModel m_changeAmtModel;
- SfxrZeroToOneFloatModel m_changeSpeedModel;
- SfxrZeroToOneFloatModel m_sqrDutyModel;
- SfxrNegPosOneFloatModel m_sqrSweepModel;
- SfxrZeroToOneFloatModel m_repeatSpeedModel;
- SfxrNegPosOneFloatModel m_phaserOffsetModel;
- SfxrNegPosOneFloatModel m_phaserSweepModel;
- SfxrZeroToOneFloatModel m_lpFilCutModel;
- SfxrNegPosOneFloatModel m_lpFilCutSweepModel;
- SfxrZeroToOneFloatModel m_lpFilResoModel;
- SfxrZeroToOneFloatModel m_hpFilCutModel;
- SfxrNegPosOneFloatModel m_hpFilCutSweepModel;
- IntModel m_waveFormModel;
- friend class sfxrInstrumentView;
- friend class SfxrSynth;
- };
- class sfxrInstrumentView : public InstrumentView
- {
- Q_OBJECT
- public:
- sfxrInstrumentView( Instrument * _instrument,
- QWidget * _parent );
- virtual ~sfxrInstrumentView() {};
- protected slots:
- void genPickup();
- void genLaser();
- void genExplosion();
- void genPowerup();
- void genHit();
- void genJump();
- void genBlip();
- void randomize();
- void mutate();
- void previewSound();
- private:
- virtual void modelChanged();
- Knob * m_attKnob; //Attack Time
- Knob * m_holdKnob; //Sustain Time
- Knob * m_susKnob; //Sustain Punch
- Knob * m_decKnob; //Decay Time
- Knob * m_startFreqKnob; //Start Frequency
- Knob * m_minFreqKnob; //Min Frequency
- Knob * m_slideKnob; //Slide
- Knob * m_dSlideKnob; //Delta Slide
- Knob * m_vibDepthKnob; //Vibrato Depth
- Knob * m_vibSpeedKnob; //Vibrato Speed
- Knob * m_changeAmtKnob; //Change Amount
- Knob * m_changeSpeedKnob; //Change Speed
- Knob * m_sqrDutyKnob; //Square Wave Duty
- Knob * m_sqrSweepKnob; //Square Wave Duty Sweep
- Knob * m_repeatSpeedKnob; //Repeat Speed
- Knob * m_phaserOffsetKnob; //Phaser Offset
- Knob * m_phaserSweepKnob; //Phaser Sweep
- Knob * m_lpFilCutKnob; //LP Filter Cutoff
- Knob * m_lpFilCutSweepKnob; //LP Filter Cutoff Sweep
- Knob * m_lpFilResoKnob; //LP Filter Resonance
- Knob * m_hpFilCutKnob; //HP Filter Cutoff
- Knob * m_hpFilCutSweepKnob; //HP Filter Cutoff Sweep
- automatableButtonGroup * m_waveBtnGroup;
- PixmapButton * m_sqrWaveBtn; //NOTE: This button has Square Duty
- //and Square Speed configurable
- PixmapButton * m_sawWaveBtn;
- PixmapButton * m_sinWaveBtn;
- PixmapButton * m_noiseWaveBtn;
- PixmapButton * m_pickupBtn;
- PixmapButton * m_laserBtn;
- PixmapButton * m_explosionBtn;
- PixmapButton * m_powerupBtn;
- PixmapButton * m_hitBtn;
- PixmapButton * m_jumpBtn;
- PixmapButton * m_blipBtn;
- PixmapButton * m_randomizeBtn;
- PixmapButton * m_mutateBtn;
- static QPixmap * s_artwork;
- };
- #endif
|