organic.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * organic.h - additive synthesizer for organ-like sounds
  3. *
  4. * Copyright (c) 2006-2015 Andreas Brandmaier <andy/at/brandmaier/dot/de>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef ORGANIC_H
  25. #define ORGANIC_H
  26. #include <QString>
  27. #include "Instrument.h"
  28. #include "InstrumentView.h"
  29. #include "Oscillator.h"
  30. #include "AutomatableModel.h"
  31. class QPixmap;
  32. class Knob;
  33. class NotePlayHandle;
  34. class PixmapButton;
  35. const int NUM_OSCILLATORS = 8;
  36. const int NUM_HARMONICS = 18;
  37. const QString HARMONIC_NAMES[NUM_HARMONICS] = {
  38. "Octave below",
  39. "Fifth below",
  40. "Fundamental",
  41. "2nd harmonic",
  42. "3rd harmonic",
  43. "4th harmonic",
  44. "5th harmonic",
  45. "6th harmonic",
  46. "7th harmonic",
  47. "8th harmonic",
  48. "9th harmonic",
  49. "10th harmonic",
  50. "11th harmonic",
  51. "12th harmonic",
  52. "13th harmonic",
  53. "14th harmonic",
  54. "15th harmonic",
  55. "16th harmonic"
  56. };
  57. const QString WAVEFORM_NAMES[6] = {
  58. "Sine wave",
  59. "Saw wave",
  60. "Square wave",
  61. "Triangle wave",
  62. "Moog saw wave",
  63. "Exponential wave"
  64. };
  65. const float CENT = 1.0f / 1200.0f;
  66. class OscillatorObject : public Model
  67. {
  68. Q_OBJECT
  69. MM_OPERATORS
  70. private:
  71. int m_numOscillators;
  72. IntModel m_waveShape;
  73. FloatModel m_oscModel;
  74. FloatModel m_harmModel;
  75. FloatModel m_volModel;
  76. FloatModel m_panModel;
  77. FloatModel m_detuneModel;
  78. float m_volumeLeft;
  79. float m_volumeRight;
  80. // normalized detuning -> x/sampleRate
  81. float m_detuningLeft;
  82. float m_detuningRight;
  83. // normalized offset -> x/360
  84. float m_phaseOffsetLeft;
  85. float m_phaseOffsetRight;
  86. OscillatorObject( Model * _parent, int _index );
  87. virtual ~OscillatorObject();
  88. friend class organicInstrument;
  89. friend class organicInstrumentView;
  90. private slots:
  91. void oscButtonChanged();
  92. void updateVolume();
  93. void updateDetuning();
  94. } ;
  95. class organicInstrument : public Instrument
  96. {
  97. Q_OBJECT
  98. public:
  99. organicInstrument( InstrumentTrack * _instrument_track );
  100. virtual ~organicInstrument();
  101. virtual void playNote( NotePlayHandle * _n,
  102. sampleFrame * _working_buffer );
  103. virtual void deleteNotePluginData( NotePlayHandle * _n );
  104. virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
  105. virtual void loadSettings( const QDomElement & _this );
  106. virtual QString nodeName() const;
  107. int intRand( int min, int max );
  108. static float * s_harmonics;
  109. public slots:
  110. void randomiseSettings();
  111. private:
  112. float inline waveshape(float in, float amount);
  113. // fast atan, fast rather than accurate
  114. inline float fastatan( float x )
  115. {
  116. return (x / (1.0 + 0.28 * (x * x)));
  117. }
  118. int m_numOscillators;
  119. OscillatorObject ** m_osc;
  120. struct oscPtr
  121. {
  122. MM_OPERATORS
  123. Oscillator * oscLeft;
  124. Oscillator * oscRight;
  125. float phaseOffsetLeft[NUM_OSCILLATORS];
  126. float phaseOffsetRight[NUM_OSCILLATORS];
  127. } ;
  128. const IntModel m_modulationAlgo;
  129. FloatModel m_fx1Model;
  130. FloatModel m_volModel;
  131. virtual PluginView * instantiateView( QWidget * _parent );
  132. private slots:
  133. void updateAllDetuning();
  134. friend class organicInstrumentView;
  135. } ;
  136. class organicInstrumentView : public InstrumentViewFixedSize
  137. {
  138. Q_OBJECT
  139. public:
  140. organicInstrumentView( Instrument * _instrument, QWidget * _parent );
  141. virtual ~organicInstrumentView();
  142. private:
  143. virtual void modelChanged();
  144. struct OscillatorKnobs
  145. {
  146. MM_OPERATORS
  147. OscillatorKnobs(
  148. Knob * h,
  149. Knob * v,
  150. Knob * o,
  151. Knob * p,
  152. Knob * dt ) :
  153. m_harmKnob( h ),
  154. m_volKnob( v ),
  155. m_oscKnob( o ),
  156. m_panKnob( p ),
  157. m_detuneKnob( dt )
  158. {
  159. }
  160. OscillatorKnobs()
  161. {
  162. }
  163. Knob * m_harmKnob;
  164. Knob * m_volKnob;
  165. Knob * m_oscKnob;
  166. Knob * m_panKnob;
  167. Knob * m_detuneKnob;
  168. } ;
  169. OscillatorKnobs * m_oscKnobs;
  170. Knob * m_fx1Knob;
  171. Knob * m_volKnob;
  172. PixmapButton * m_randBtn;
  173. int m_numOscillators;
  174. static QPixmap * s_artwork;
  175. protected slots:
  176. void updateKnobHint();
  177. };
  178. #endif