Xpressive.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Xpressive.h - Instrument which uses a mathematical formula parser
  3. *
  4. * Copyright (c) 2016-2017 Orr Dvori
  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 XPRESSIVE_H
  25. #define XPRESSIVE_H
  26. #include <QPlainTextEdit>
  27. #include "Graph.h"
  28. #include "Instrument.h"
  29. #include "InstrumentView.h"
  30. #include "Knob.h"
  31. #include "LedCheckbox.h"
  32. #include "PixmapButton.h"
  33. #include "ExprSynth.h"
  34. class oscillator;
  35. class XpressiveView;
  36. const int W1_EXPR = 0;
  37. const int W2_EXPR = 1;
  38. const int W3_EXPR = 2;
  39. const int O1_EXPR = 3;
  40. const int O2_EXPR = 4;
  41. const int NUM_EXPRS = 5;
  42. class ExprFront;
  43. class SubWindow;
  44. class Xpressive : public Instrument
  45. {
  46. Q_OBJECT
  47. public:
  48. Xpressive(InstrumentTrack* instrument_track );
  49. virtual ~Xpressive();
  50. virtual void playNote(NotePlayHandle* nph,
  51. sampleFrame* working_buffer );
  52. virtual void deleteNotePluginData( NotePlayHandle* nph );
  53. virtual void saveSettings( QDomDocument& _doc,
  54. QDomElement& _this );
  55. virtual void loadSettings( const QDomElement& _this );
  56. virtual QString nodeName() const;
  57. virtual PluginView* instantiateView( QWidget * parent );
  58. graphModel& graphO1() { return m_graphO1; }
  59. graphModel& graphO2() { return m_graphO2; }
  60. graphModel& graphW1() { return m_graphW1; }
  61. graphModel& graphW2() { return m_graphW2; }
  62. graphModel& graphW3() { return m_graphW3; }
  63. graphModel& rawgraphW1() { return m_rawgraphW1; }
  64. graphModel& rawgraphW2() { return m_rawgraphW2; }
  65. graphModel& rawgraphW3() { return m_rawgraphW3; }
  66. IntModel& selectedGraph() { return m_selectedGraph; }
  67. QByteArray& wavesExpression(int i) { return m_wavesExpression[i]; }
  68. QByteArray& outputExpression(int i) { return m_outputExpression[i]; }
  69. FloatModel& parameterA1() { return m_parameterA1; }
  70. FloatModel& parameterA2() { return m_parameterA2; }
  71. FloatModel& parameterA3() { return m_parameterA3; }
  72. FloatModel& smoothW1() { return m_smoothW1; }
  73. FloatModel& smoothW2() { return m_smoothW2; }
  74. FloatModel& smoothW3() { return m_smoothW3; }
  75. BoolModel& interpolateW1() { return m_interpolateW1; }
  76. BoolModel& interpolateW2() { return m_interpolateW2; }
  77. BoolModel& interpolateW3() { return m_interpolateW3; }
  78. FloatModel& panning1() { return m_panning1; }
  79. FloatModel& panning2() { return m_panning2; }
  80. FloatModel& relTransition() { return m_relTransition; }
  81. WaveSample& W1() { return m_W1; }
  82. WaveSample& W2() { return m_W2; }
  83. WaveSample& W3() { return m_W3; }
  84. BoolModel& exprValid() { return m_exprValid; }
  85. static void smooth(float smoothness,const graphModel* in,graphModel* out);
  86. protected:
  87. protected slots:
  88. private:
  89. graphModel m_graphO1;
  90. graphModel m_graphO2;
  91. graphModel m_graphW1;
  92. graphModel m_graphW2;
  93. graphModel m_graphW3;
  94. graphModel m_rawgraphW1;
  95. graphModel m_rawgraphW2;
  96. graphModel m_rawgraphW3;
  97. IntModel m_selectedGraph;
  98. QByteArray m_wavesExpression[3];
  99. QByteArray m_outputExpression[2];
  100. FloatModel m_parameterA1;
  101. FloatModel m_parameterA2;
  102. FloatModel m_parameterA3;
  103. FloatModel m_smoothW1;
  104. FloatModel m_smoothW2;
  105. FloatModel m_smoothW3;
  106. BoolModel m_interpolateW1;
  107. BoolModel m_interpolateW2;
  108. BoolModel m_interpolateW3;
  109. FloatModel m_panning1;
  110. FloatModel m_panning2;
  111. FloatModel m_relTransition;
  112. float m_A1,m_A2,m_A3;
  113. WaveSample m_W1, m_W2, m_W3;
  114. BoolModel m_exprValid;
  115. } ;
  116. class XpressiveView : public InstrumentViewFixedSize
  117. {
  118. Q_OBJECT
  119. public:
  120. XpressiveView( Instrument* _instrument,
  121. QWidget* _parent );
  122. virtual ~XpressiveView();
  123. protected:
  124. protected slots:
  125. void updateLayout();
  126. void sinWaveClicked();
  127. void triangleWaveClicked();
  128. void sqrWaveClicked();
  129. void sawWaveClicked();
  130. void noiseWaveClicked();
  131. void moogSawWaveClicked();
  132. void expWaveClicked();
  133. void usrWaveClicked();
  134. void helpClicked();
  135. void expressionChanged( );
  136. void smoothChanged( );
  137. void graphDrawn( );
  138. private:
  139. virtual void modelChanged();
  140. Knob *m_generalPurposeKnob[3];
  141. Knob *m_panningKnob[2];
  142. Knob *m_relKnob;
  143. Knob *m_smoothKnob;
  144. QPlainTextEdit * m_expressionEditor;
  145. automatableButtonGroup *m_selectedGraphGroup;
  146. PixmapButton *m_w1Btn;
  147. PixmapButton *m_w2Btn;
  148. PixmapButton *m_w3Btn;
  149. PixmapButton *m_o1Btn;
  150. PixmapButton *m_o2Btn;
  151. PixmapButton *m_sinWaveBtn;
  152. PixmapButton *m_triangleWaveBtn;
  153. PixmapButton *m_sqrWaveBtn;
  154. PixmapButton *m_sawWaveBtn;
  155. PixmapButton *m_whiteNoiseWaveBtn;
  156. PixmapButton *m_usrWaveBtn;
  157. PixmapButton *m_moogWaveBtn;
  158. PixmapButton *m_expWaveBtn;
  159. static QPixmap *s_artwork;
  160. Graph *m_graph;
  161. graphModel *m_raw_graph;
  162. LedCheckBox *m_expressionValidToggle;
  163. LedCheckBox *m_waveInterpolate;
  164. bool m_output_expr;
  165. bool m_wave_expr;
  166. } ;
  167. class XpressiveHelpView: public QTextEdit
  168. {
  169. Q_OBJECT
  170. public:
  171. static XpressiveHelpView* getInstance()
  172. {
  173. static XpressiveHelpView instance;
  174. return &instance;
  175. }
  176. static void finalize()
  177. {
  178. }
  179. private:
  180. XpressiveHelpView();
  181. static QString s_helpText;
  182. };
  183. #endif