opl2instrument.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * OPL2 FM synth
  3. *
  4. * Copyright (c) 2013 Raine M. Ekman <raine/at/iki/fi>
  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 _OPL2_H
  25. #define _OPL2_H
  26. #include "Instrument.h"
  27. #include "InstrumentView.h"
  28. #include "opl.h"
  29. #include "LcdSpinBox.h"
  30. #include "Knob.h"
  31. #include "PixmapButton.h"
  32. // This one is a flag, MIDI notes take 7 low bits
  33. #define OPL2_VOICE_FREE 128
  34. #define OPL2_NO_VOICE 255
  35. #define OPL2_VOICES 9
  36. // The "normal" range for LMMS pitchbends
  37. #define DEFAULT_BEND_CENTS 100
  38. class opl2instrument : public Instrument
  39. {
  40. Q_OBJECT
  41. public:
  42. opl2instrument( InstrumentTrack * _instrument_track );
  43. virtual ~opl2instrument();
  44. virtual QString nodeName() const;
  45. virtual PluginView * instantiateView( QWidget * _parent );
  46. virtual Flags flags() const
  47. {
  48. return IsSingleStreamed | IsMidiBased;
  49. }
  50. virtual bool handleMidiEvent( const MidiEvent& event, const MidiTime& time, f_cnt_t offset = 0 );
  51. virtual void play( sampleFrame * _working_buffer );
  52. void saveSettings( QDomDocument & _doc, QDomElement & _this );
  53. void loadSettings( const QDomElement & _this );
  54. void loadPatch(const unsigned char inst[14]);
  55. void tuneEqual(int center, float Hz);
  56. virtual void loadFile( const QString& file );
  57. IntModel m_patchModel;
  58. FloatModel op1_a_mdl;
  59. FloatModel op1_d_mdl;
  60. FloatModel op1_s_mdl;
  61. FloatModel op1_r_mdl;
  62. FloatModel op1_lvl_mdl;
  63. FloatModel op1_scale_mdl;
  64. FloatModel op1_mul_mdl;
  65. FloatModel feedback_mdl;
  66. BoolModel op1_ksr_mdl;
  67. BoolModel op1_perc_mdl;
  68. BoolModel op1_trem_mdl;
  69. BoolModel op1_vib_mdl;
  70. BoolModel op1_w0_mdl;
  71. BoolModel op1_w1_mdl;
  72. BoolModel op1_w2_mdl;
  73. BoolModel op1_w3_mdl;
  74. IntModel op1_waveform_mdl;
  75. FloatModel op2_a_mdl;
  76. FloatModel op2_d_mdl;
  77. FloatModel op2_s_mdl;
  78. FloatModel op2_r_mdl;
  79. FloatModel op2_lvl_mdl;
  80. FloatModel op2_scale_mdl;
  81. FloatModel op2_mul_mdl;
  82. BoolModel op2_ksr_mdl;
  83. BoolModel op2_perc_mdl;
  84. BoolModel op2_trem_mdl;
  85. BoolModel op2_vib_mdl;
  86. BoolModel op2_w0_mdl;
  87. BoolModel op2_w1_mdl;
  88. BoolModel op2_w2_mdl;
  89. BoolModel op2_w3_mdl;
  90. IntModel op2_waveform_mdl;
  91. BoolModel fm_mdl;
  92. BoolModel vib_depth_mdl;
  93. BoolModel trem_depth_mdl;
  94. private slots:
  95. void updatePatch();
  96. void reloadEmulator();
  97. void loadGMPatch();
  98. private:
  99. Copl *theEmulator;
  100. QString storedname;
  101. fpp_t frameCount;
  102. short *renderbuffer;
  103. int voiceNote[OPL2_VOICES];
  104. // Least recently used voices
  105. int voiceLRU[OPL2_VOICES];
  106. // 0 - no note, >0 - note on velocity
  107. int velocities[128];
  108. // These include both octave and Fnumber
  109. int fnums[128];
  110. // in cents, range defaults to +/-100 cents (should this be changeable?)
  111. int pitchbend;
  112. int pitchBendRange;
  113. int popVoice();
  114. int pushVoice(int v);
  115. int Hz2fnum(float Hz);
  116. static QMutex emulatorMutex;
  117. void setVoiceVelocity(int voice, int vel);
  118. // Pitch bend range comes through RPNs.
  119. int RPNcoarse, RPNfine;
  120. };
  121. class opl2instrumentView : public InstrumentView
  122. {
  123. Q_OBJECT
  124. public:
  125. opl2instrumentView( Instrument * _instrument, QWidget * _parent );
  126. virtual ~opl2instrumentView();
  127. LcdSpinBox *m_patch;
  128. void modelChanged();
  129. Knob *op1_a_kn;
  130. Knob *op1_d_kn;
  131. Knob *op1_s_kn;
  132. Knob *op1_r_kn;
  133. Knob *op1_lvl_kn;
  134. Knob *op1_scale_kn;
  135. Knob *op1_mul_kn;
  136. Knob *feedback_kn;
  137. PixmapButton *op1_ksr_btn;
  138. PixmapButton *op1_perc_btn;
  139. PixmapButton *op1_trem_btn;
  140. PixmapButton *op1_vib_btn;
  141. PixmapButton *op1_w0_btn;
  142. PixmapButton *op1_w1_btn;
  143. PixmapButton *op1_w2_btn;
  144. PixmapButton *op1_w3_btn;
  145. automatableButtonGroup *op1_waveform;
  146. Knob *op2_a_kn;
  147. Knob *op2_d_kn;
  148. Knob *op2_s_kn;
  149. Knob *op2_r_kn;
  150. Knob *op2_lvl_kn;
  151. Knob *op2_scale_kn;
  152. Knob *op2_mul_kn;
  153. PixmapButton *op2_ksr_btn;
  154. PixmapButton *op2_perc_btn;
  155. PixmapButton *op2_trem_btn;
  156. PixmapButton *op2_vib_btn;
  157. PixmapButton *op2_w0_btn;
  158. PixmapButton *op2_w1_btn;
  159. PixmapButton *op2_w2_btn;
  160. PixmapButton *op2_w3_btn;
  161. automatableButtonGroup *op2_waveform;
  162. PixmapButton *fm_btn;
  163. PixmapButton *vib_depth_btn;
  164. PixmapButton *trem_depth_btn;
  165. private slots:
  166. void updateKnobHints();
  167. private:
  168. QString knobHintHelper(float n);
  169. };
  170. #endif