sfxr.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * sfxr.h - declaration of classes of the LMMS sfxr plugin
  3. * Originally written by Tomas Pettersson. For the original license,
  4. * please read readme.txt in this directory
  5. *
  6. * Copyright (c) 2014 Wong Cho Ching
  7. *
  8. * This file is part of LMMS - https://lmms.io
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program (see COPYING); if not, write to the
  22. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301 USA.
  24. *
  25. */
  26. #ifndef SFXR_H
  27. #define SFXR_H
  28. #include "Instrument.h"
  29. #include "InstrumentView.h"
  30. #include "Knob.h"
  31. #include "Graph.h"
  32. #include "PixmapButton.h"
  33. #include "LedCheckbox.h"
  34. #include "MemoryManager.h"
  35. enum SfxrWaves
  36. {
  37. SQR_WAVE, SAW_WAVE, SINE_WAVE, NOISE_WAVE, WAVES_NUM
  38. };
  39. const int WAVEFORM_BASE_X = 20;
  40. const int WAVEFORM_BASE_Y = 15;
  41. const int WAVEFORM_BUTTON_WIDTH = 16;
  42. const int GENERATOR_BASE_X = 110;
  43. const int GENERATOR_BASE_Y = 25;
  44. const int GENERATOR_BUTTON_WIDTH = 16;
  45. const int RAND_BUTTON_X = 160;
  46. const int RAND_BUTTON_Y = 4;
  47. const int MUTA_BUTTON_X = 205;
  48. const int MUTA_BUTTON_Y = 4;
  49. const int KNOBS_BASE_X = 20;
  50. const int KNOBS_BASE_Y = 50;
  51. const int KNOB_BLOCK_SIZE_X = 40;
  52. const int KNOB_BLOCK_SIZE_Y = 40;
  53. class sfxrInstrument;
  54. class SfxrSynth
  55. {
  56. MM_OPERATORS
  57. public:
  58. SfxrSynth( const sfxrInstrument * s );
  59. virtual ~SfxrSynth();
  60. void resetSample( bool restart );
  61. void update( sampleFrame * buffer, const int32_t frameNum );
  62. bool isPlaying() const;
  63. private:
  64. const sfxrInstrument * s;
  65. bool playing_sample;
  66. int phase;
  67. double fperiod;
  68. double fmaxperiod;
  69. double fslide;
  70. double fdslide;
  71. int period;
  72. float square_duty;
  73. float square_slide;
  74. int env_stage;
  75. int env_time;
  76. int env_length[3];
  77. float env_vol;
  78. float fphase;
  79. float fdphase;
  80. int iphase;
  81. float phaser_buffer[1024];
  82. int ipp;
  83. float noise_buffer[32];
  84. float fltp;
  85. float fltdp;
  86. float fltw;
  87. float fltw_d;
  88. float fltdmp;
  89. float fltphp;
  90. float flthp;
  91. float flthp_d;
  92. float vib_phase;
  93. float vib_speed;
  94. float vib_amp;
  95. int rep_time;
  96. int rep_limit;
  97. int arp_time;
  98. int arp_limit;
  99. double arp_mod;
  100. } ;
  101. /**
  102. * @brief A class that simplify the constructor of FloatModel, with value [0,1]
  103. */
  104. class SfxrZeroToOneFloatModel : public FloatModel
  105. {
  106. public:
  107. SfxrZeroToOneFloatModel( float val, Model * parent, const QString& displayName ):
  108. FloatModel( val, 0.0, 1.0, 0.001, parent, displayName )
  109. {
  110. }
  111. /* purpose: prevent the initial value of the model from being changed */
  112. virtual void loadSettings( const QDomElement& element, const QString& name = QString( "value" ) )
  113. {
  114. float oldInitValue = initValue();
  115. FloatModel::loadSettings(element, name);
  116. float oldValue = value();
  117. setInitValue(oldInitValue);
  118. setValue(oldValue);
  119. }
  120. };
  121. /**
  122. * @brief A class that simplify the constructor of FloatModel, with value [-1,1]
  123. */
  124. class SfxrNegPosOneFloatModel : public FloatModel
  125. {
  126. public:
  127. SfxrNegPosOneFloatModel(float val, Model * parent, const QString& displayName ):
  128. FloatModel( val, -1.0, 1.0, 0.001, parent, displayName )
  129. {
  130. }
  131. /* purpose: prevent the initial value of the model from being changed */
  132. virtual void loadSettings( const QDomElement& element, const QString& name = QString( "value" ) )
  133. {
  134. float oldInitValue = initValue();
  135. FloatModel::loadSettings(element, name);
  136. float oldValue = value();
  137. setInitValue(oldInitValue);
  138. setValue(oldValue);
  139. }
  140. };
  141. class sfxrInstrument : public Instrument
  142. {
  143. Q_OBJECT
  144. public:
  145. sfxrInstrument(InstrumentTrack * _instrument_track );
  146. virtual ~sfxrInstrument();
  147. virtual void playNote( NotePlayHandle * _n, sampleFrame * _working_buffer );
  148. virtual void deleteNotePluginData( NotePlayHandle * _n );
  149. virtual void saveSettings( QDomDocument & _doc,
  150. QDomElement & _parent );
  151. virtual void loadSettings( const QDomElement & _this );
  152. virtual QString nodeName() const;
  153. virtual PluginView * instantiateView( QWidget * _parent );
  154. void resetModels();
  155. private:
  156. SfxrZeroToOneFloatModel m_attModel;
  157. SfxrZeroToOneFloatModel m_holdModel;
  158. SfxrZeroToOneFloatModel m_susModel;
  159. SfxrZeroToOneFloatModel m_decModel;
  160. SfxrZeroToOneFloatModel m_startFreqModel;
  161. SfxrZeroToOneFloatModel m_minFreqModel;
  162. SfxrNegPosOneFloatModel m_slideModel;
  163. SfxrNegPosOneFloatModel m_dSlideModel;
  164. SfxrZeroToOneFloatModel m_vibDepthModel;
  165. SfxrZeroToOneFloatModel m_vibSpeedModel;
  166. SfxrNegPosOneFloatModel m_changeAmtModel;
  167. SfxrZeroToOneFloatModel m_changeSpeedModel;
  168. SfxrZeroToOneFloatModel m_sqrDutyModel;
  169. SfxrNegPosOneFloatModel m_sqrSweepModel;
  170. SfxrZeroToOneFloatModel m_repeatSpeedModel;
  171. SfxrNegPosOneFloatModel m_phaserOffsetModel;
  172. SfxrNegPosOneFloatModel m_phaserSweepModel;
  173. SfxrZeroToOneFloatModel m_lpFilCutModel;
  174. SfxrNegPosOneFloatModel m_lpFilCutSweepModel;
  175. SfxrZeroToOneFloatModel m_lpFilResoModel;
  176. SfxrZeroToOneFloatModel m_hpFilCutModel;
  177. SfxrNegPosOneFloatModel m_hpFilCutSweepModel;
  178. IntModel m_waveFormModel;
  179. friend class sfxrInstrumentView;
  180. friend class SfxrSynth;
  181. };
  182. class sfxrInstrumentView : public InstrumentViewFixedSize
  183. {
  184. Q_OBJECT
  185. public:
  186. sfxrInstrumentView( Instrument * _instrument,
  187. QWidget * _parent );
  188. virtual ~sfxrInstrumentView() {};
  189. protected slots:
  190. void genPickup();
  191. void genLaser();
  192. void genExplosion();
  193. void genPowerup();
  194. void genHit();
  195. void genJump();
  196. void genBlip();
  197. void randomize();
  198. void mutate();
  199. void previewSound();
  200. private:
  201. virtual void modelChanged();
  202. Knob * m_attKnob; //Attack Time
  203. Knob * m_holdKnob; //Sustain Time
  204. Knob * m_susKnob; //Sustain Punch
  205. Knob * m_decKnob; //Decay Time
  206. Knob * m_startFreqKnob; //Start Frequency
  207. Knob * m_minFreqKnob; //Min Frequency
  208. Knob * m_slideKnob; //Slide
  209. Knob * m_dSlideKnob; //Delta Slide
  210. Knob * m_vibDepthKnob; //Vibrato Depth
  211. Knob * m_vibSpeedKnob; //Vibrato Speed
  212. Knob * m_changeAmtKnob; //Change Amount
  213. Knob * m_changeSpeedKnob; //Change Speed
  214. Knob * m_sqrDutyKnob; //Square Wave Duty
  215. Knob * m_sqrSweepKnob; //Square Wave Duty Sweep
  216. Knob * m_repeatSpeedKnob; //Repeat Speed
  217. Knob * m_phaserOffsetKnob; //Phaser Offset
  218. Knob * m_phaserSweepKnob; //Phaser Sweep
  219. Knob * m_lpFilCutKnob; //LP Filter Cutoff
  220. Knob * m_lpFilCutSweepKnob; //LP Filter Cutoff Sweep
  221. Knob * m_lpFilResoKnob; //LP Filter Resonance
  222. Knob * m_hpFilCutKnob; //HP Filter Cutoff
  223. Knob * m_hpFilCutSweepKnob; //HP Filter Cutoff Sweep
  224. automatableButtonGroup * m_waveBtnGroup;
  225. PixmapButton * m_sqrWaveBtn; //NOTE: This button has Square Duty
  226. //and Square Speed configurable
  227. PixmapButton * m_sawWaveBtn;
  228. PixmapButton * m_sinWaveBtn;
  229. PixmapButton * m_noiseWaveBtn;
  230. PixmapButton * m_pickupBtn;
  231. PixmapButton * m_laserBtn;
  232. PixmapButton * m_explosionBtn;
  233. PixmapButton * m_powerupBtn;
  234. PixmapButton * m_hitBtn;
  235. PixmapButton * m_jumpBtn;
  236. PixmapButton * m_blipBtn;
  237. PixmapButton * m_randomizeBtn;
  238. PixmapButton * m_mutateBtn;
  239. static QPixmap * s_artwork;
  240. };
  241. #endif