mallets.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * mallets.h - tuned instruments that one would bang upon
  3. *
  4. * Copyright (c) 2006-2008 Danny McRae <khjklujn/at/users.sourceforge.net>
  5. *
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef _MALLET_H
  26. #define _MALLET_H
  27. #include "Instrmnt.h"
  28. #include "ComboBox.h"
  29. #include "Instrument.h"
  30. #include "InstrumentView.h"
  31. #include "Knob.h"
  32. #include "NotePlayHandle.h"
  33. #include "LedCheckbox.h"
  34. // As of Stk 4.4 all classes and types have been moved to the namespace "stk".
  35. // However in older versions this namespace does not exist, therefore declare it
  36. // so this plugin builds with all versions of Stk.
  37. namespace stk { } ;
  38. using namespace stk;
  39. static const int MALLETS_PRESET_VERSION = 1;
  40. class malletsSynth
  41. {
  42. public:
  43. // ModalBar
  44. malletsSynth( const StkFloat _pitch,
  45. const StkFloat _velocity,
  46. const StkFloat _control1,
  47. const StkFloat _control2,
  48. const StkFloat _control4,
  49. const StkFloat _control8,
  50. const StkFloat _control11,
  51. const int _control16,
  52. const uint8_t _delay,
  53. const sample_rate_t _sample_rate );
  54. // TubeBell
  55. malletsSynth( const StkFloat _pitch,
  56. const StkFloat _velocity,
  57. const int _preset,
  58. const StkFloat _control1,
  59. const StkFloat _control2,
  60. const StkFloat _control4,
  61. const StkFloat _control11,
  62. const StkFloat _control128,
  63. const uint8_t _delay,
  64. const sample_rate_t _sample_rate );
  65. // BandedWG
  66. malletsSynth( const StkFloat _pitch,
  67. const StkFloat _velocity,
  68. const StkFloat _control2,
  69. const StkFloat _control4,
  70. const StkFloat _control11,
  71. const int _control16,
  72. const StkFloat _control64,
  73. const StkFloat _control128,
  74. const uint8_t _delay,
  75. const sample_rate_t _sample_rate );
  76. inline ~malletsSynth()
  77. {
  78. if (m_voice) {m_voice->noteOff(0.0);}
  79. delete[] m_delay;
  80. delete m_voice;
  81. }
  82. inline sample_t nextSampleLeft()
  83. {
  84. if( m_voice == NULL )
  85. {
  86. return( 0.0f );
  87. }
  88. else
  89. {
  90. StkFloat s = m_voice->tick();
  91. m_delay[m_delayWrite] = s;
  92. m_delayWrite++;
  93. return( s );
  94. }
  95. }
  96. inline sample_t nextSampleRight()
  97. {
  98. StkFloat s = m_delay[m_delayRead];
  99. m_delayRead++;
  100. return( s );
  101. }
  102. inline void setFrequency( const StkFloat _pitch )
  103. {
  104. if( m_voice )
  105. {
  106. m_voice->setFrequency( _pitch );
  107. }
  108. }
  109. inline int presetIndex()
  110. {
  111. return m_presetIndex;
  112. }
  113. inline void setPresetIndex(int presetIndex)
  114. {
  115. m_presetIndex = presetIndex;
  116. }
  117. protected:
  118. int m_presetIndex;
  119. Instrmnt * m_voice;
  120. StkFloat * m_delay;
  121. uint8_t m_delayRead;
  122. uint8_t m_delayWrite;
  123. };
  124. class malletsInstrument : public Instrument
  125. {
  126. Q_OBJECT
  127. public:
  128. malletsInstrument( InstrumentTrack * _instrument_track );
  129. virtual ~malletsInstrument();
  130. virtual void playNote( NotePlayHandle * _n,
  131. sampleFrame * _working_buffer );
  132. virtual void deleteNotePluginData( NotePlayHandle * _n );
  133. virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
  134. virtual void loadSettings( const QDomElement & _this );
  135. virtual QString nodeName() const;
  136. virtual PluginView * instantiateView( QWidget * _parent );
  137. private:
  138. FloatModel m_hardnessModel;
  139. FloatModel m_positionModel;
  140. FloatModel m_vibratoGainModel;
  141. FloatModel m_vibratoFreqModel;
  142. FloatModel m_stickModel;
  143. FloatModel m_modulatorModel;
  144. FloatModel m_crossfadeModel;
  145. FloatModel m_lfoSpeedModel;
  146. FloatModel m_lfoDepthModel;
  147. FloatModel m_adsrModel;
  148. FloatModel m_pressureModel;
  149. FloatModel m_motionModel;
  150. FloatModel m_vibratoModel;
  151. FloatModel m_velocityModel;
  152. BoolModel m_strikeModel;
  153. ComboBoxModel m_presetsModel;
  154. FloatModel m_spreadModel;
  155. IntModel m_versionModel;
  156. BoolModel m_isOldVersionModel;
  157. QVector<sample_t> m_scalers;
  158. bool m_filesMissing;
  159. friend class malletsInstrumentView;
  160. } ;
  161. class malletsInstrumentView: public InstrumentView
  162. {
  163. Q_OBJECT
  164. public:
  165. malletsInstrumentView( malletsInstrument * _instrument,
  166. QWidget * _parent );
  167. virtual ~malletsInstrumentView();
  168. public slots:
  169. void changePreset();
  170. private:
  171. virtual void modelChanged();
  172. void setWidgetBackground( QWidget * _widget, const QString & _pic );
  173. QWidget * setupModalBarControls( QWidget * _parent );
  174. QWidget * setupTubeBellControls( QWidget * _parent );
  175. QWidget * setupBandedWGControls( QWidget * _parent );
  176. QWidget * m_modalBarWidget;
  177. Knob * m_hardnessKnob;
  178. Knob * m_positionKnob;
  179. Knob * m_vibratoGainKnob;
  180. Knob * m_vibratoFreqKnob;
  181. Knob * m_stickKnob;
  182. QWidget * m_tubeBellWidget;
  183. Knob * m_modulatorKnob;
  184. Knob * m_crossfadeKnob;
  185. Knob * m_lfoSpeedKnob;
  186. Knob * m_lfoDepthKnob;
  187. Knob * m_adsrKnob;
  188. QWidget * m_bandedWGWidget;
  189. Knob * m_pressureKnob;
  190. // Knob * m_motionKnob;
  191. // Knob * m_vibratoKnob;
  192. Knob * m_velocityKnob;
  193. // LedCheckBox * m_strikeLED;
  194. ComboBox * m_presetsCombo;
  195. Knob * m_spreadKnob;
  196. };
  197. #endif