mallets.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. protected:
  110. Instrmnt * m_voice;
  111. StkFloat * m_delay;
  112. uint8_t m_delayRead;
  113. uint8_t m_delayWrite;
  114. };
  115. class malletsInstrument : public Instrument
  116. {
  117. Q_OBJECT
  118. public:
  119. malletsInstrument( InstrumentTrack * _instrument_track );
  120. virtual ~malletsInstrument();
  121. virtual void playNote( NotePlayHandle * _n,
  122. sampleFrame * _working_buffer );
  123. virtual void deleteNotePluginData( NotePlayHandle * _n );
  124. virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
  125. virtual void loadSettings( const QDomElement & _this );
  126. virtual QString nodeName() const;
  127. virtual PluginView * instantiateView( QWidget * _parent );
  128. private:
  129. FloatModel m_hardnessModel;
  130. FloatModel m_positionModel;
  131. FloatModel m_vibratoGainModel;
  132. FloatModel m_vibratoFreqModel;
  133. FloatModel m_stickModel;
  134. FloatModel m_modulatorModel;
  135. FloatModel m_crossfadeModel;
  136. FloatModel m_lfoSpeedModel;
  137. FloatModel m_lfoDepthModel;
  138. FloatModel m_adsrModel;
  139. FloatModel m_pressureModel;
  140. FloatModel m_motionModel;
  141. FloatModel m_vibratoModel;
  142. FloatModel m_velocityModel;
  143. BoolModel m_strikeModel;
  144. ComboBoxModel m_presetsModel;
  145. FloatModel m_spreadModel;
  146. IntModel m_versionModel;
  147. BoolModel m_isOldVersionModel;
  148. QVector<sample_t> m_scalers;
  149. bool m_filesMissing;
  150. friend class malletsInstrumentView;
  151. } ;
  152. class malletsInstrumentView: public InstrumentViewFixedSize
  153. {
  154. Q_OBJECT
  155. public:
  156. malletsInstrumentView( malletsInstrument * _instrument,
  157. QWidget * _parent );
  158. virtual ~malletsInstrumentView();
  159. public slots:
  160. void changePreset();
  161. private:
  162. virtual void modelChanged();
  163. void setWidgetBackground( QWidget * _widget, const QString & _pic );
  164. QWidget * setupModalBarControls( QWidget * _parent );
  165. QWidget * setupTubeBellControls( QWidget * _parent );
  166. QWidget * setupBandedWGControls( QWidget * _parent );
  167. QWidget * m_modalBarWidget;
  168. Knob * m_hardnessKnob;
  169. Knob * m_positionKnob;
  170. Knob * m_vibratoGainKnob;
  171. Knob * m_vibratoFreqKnob;
  172. Knob * m_stickKnob;
  173. QWidget * m_tubeBellWidget;
  174. Knob * m_modulatorKnob;
  175. Knob * m_crossfadeKnob;
  176. Knob * m_lfoSpeedKnob;
  177. Knob * m_lfoDepthKnob;
  178. Knob * m_adsrKnob;
  179. QWidget * m_bandedWGWidget;
  180. Knob * m_pressureKnob;
  181. // Knob * m_motionKnob;
  182. // Knob * m_vibratoKnob;
  183. Knob * m_velocityKnob;
  184. // LedCheckBox * m_strikeLED;
  185. ComboBox * m_presetsCombo;
  186. Knob * m_spreadKnob;
  187. };
  188. #endif