Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
7.4KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Controller.h - (Midi) Controllers implementation
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #ifndef CONTROLLER_H
  18. #define CONTROLLER_H
  19. #include <stdint.h>
  20. #include "../globals.h"
  21. /**(Midi) Controllers implementation*/
  22. class Controller
  23. {
  24. public:
  25. Controller(const SYNTH_T &synth, const AbsTime *time = nullptr);
  26. Controller&operator=(const Controller &c);
  27. ~Controller();
  28. void resetall();
  29. void add2XML(XMLwrapper& xml);
  30. void defaults();
  31. void getfromXML(XMLwrapper& xml);
  32. //Controllers functions
  33. void setpitchwheel(int value);
  34. void setexpression(int value);
  35. void setpanning(int value);
  36. void setfiltercutoff(int value);
  37. void setfilterq(int value);
  38. void setbandwidth(int value);
  39. void setmodwheel(int value);
  40. void setfmamp(int value);
  41. void setvolume(int value);
  42. void setsustain(int value);
  43. /**Enable or disable portamento
  44. * @param value 0-127 MIDI value (greater than 64 enables)*/
  45. void setportamento(int value);
  46. void setresonancecenter(int value);
  47. void setresonancebw(int value);
  48. void setparameternumber(unsigned int type, int value); //used for RPN and NRPN's
  49. int getnrpn(int *parhi, int *parlo, int *valhi, int *vallo);
  50. /**
  51. * Initialize a portamento
  52. *
  53. * @param oldfreq Starting frequency of the portamento (Hz)
  54. * @param newfreq Ending frequency of the portamento (Hz)
  55. * @param legatoflag true when legato is in progress, false otherwise
  56. * @returns 1 if properly initialized, 0 otherwise*/
  57. int initportamento(float oldfreq, float newfreq, bool legatoflag);
  58. /**Update portamento's freqrap to next value based upon dx*/
  59. void updateportamento();
  60. // Controllers values
  61. struct { //Pitch Wheel
  62. int data;
  63. bool is_split; //Up and down bends may be different
  64. short int bendrange; //bendrange is in cents
  65. short int bendrange_down;
  66. float relfreq; //the relative frequency (default is 1.0f)
  67. } pitchwheel;
  68. struct { //Expression
  69. int data;
  70. float relvolume;
  71. unsigned char receive;
  72. } expression;
  73. struct { //Panning
  74. int data;
  75. float pan;
  76. unsigned char depth;
  77. } panning;
  78. struct { //Filter cutoff
  79. int data;
  80. float relfreq;
  81. unsigned char depth;
  82. } filtercutoff;
  83. struct { //Filter Q
  84. int data;
  85. float relq;
  86. unsigned char depth;
  87. } filterq;
  88. struct { //Bandwidth
  89. int data;
  90. float relbw;
  91. unsigned char depth;
  92. unsigned char exponential;
  93. } bandwidth;
  94. struct { //Modulation Wheel
  95. int data;
  96. float relmod;
  97. unsigned char depth;
  98. unsigned char exponential;
  99. } modwheel;
  100. struct { //FM amplitude
  101. int data;
  102. float relamp;
  103. unsigned char receive;
  104. } fmamp;
  105. struct { //Volume
  106. int data;
  107. float volume;
  108. unsigned char receive;
  109. } volume;
  110. struct { //Sustain
  111. int data, sustain;
  112. unsigned char receive;
  113. } sustain;
  114. struct { /**<Portamento*/
  115. //parameters
  116. int data;
  117. unsigned char portamento;
  118. /**Whether the portamento midi events are received or not*/
  119. unsigned char receive;
  120. /** The time that it takes for the portamento to complete
  121. *
  122. * Translates in an expontal fashion to 0 Seconds to 1.93f Seconds
  123. * of completion time*/
  124. unsigned char time;
  125. /**If the portamento is proportinal to the distance spanned
  126. *
  127. * 0 - constant time(default)
  128. * 1 - proportional*/
  129. unsigned char proportional;
  130. /**Rate of proportinal portamento*/
  131. unsigned char propRate;
  132. /**Depth of proportinal portamento*/
  133. unsigned char propDepth;
  134. /**pitchthresh is the threshold of enabling protamento*/
  135. unsigned char pitchthresh;
  136. /**enable the portamento only below(0)/above(1) the threshold*/
  137. unsigned char pitchthreshtype;
  138. /**this value represent how the portamento time is reduced
  139. * 0 - for down portamento
  140. * 1-63 - the up portamento's time is smaller than the down portamento
  141. * 64 - the portamento time is always the same
  142. * 64-126 - the down portamento's time is smaller than the up portamento
  143. * 127 - for upper portamento
  144. * 'up portamento' means when the frequency is rising
  145. * (eg: the portamento is from 200Hz to 300 Hz)
  146. * 'down portamento' means when the frequency is lowering
  147. * (eg: the portamento is from 300Hz to 200 Hz)
  148. */
  149. unsigned char updowntimestretch;
  150. /**this value is used to compute the actual portamento
  151. *
  152. * This is a multiplyer to change the frequency of the newer
  153. * frequency to fit the profile of the portamento.
  154. * This will be linear with respect to x.*/
  155. float freqrap;
  156. /**this is used by the Part for knowing which note uses the portamento*/
  157. int noteusing;
  158. /**if a the portamento is used by a note
  159. * \todo see if this can be a bool*/
  160. int used;
  161. //Internal data
  162. /**x is from 0.0f (start portamento) to 1.0f (finished portamento)*/
  163. float x;
  164. /**dx is the increment to x when updateportamento is called*/
  165. float dx;
  166. /** this is used for computing oldfreq value from x*/
  167. float origfreqrap;
  168. } portamento;
  169. struct { //Resonance Center Frequency
  170. int data;
  171. float relcenter;
  172. unsigned char depth;
  173. } resonancecenter;
  174. struct { //Resonance Bandwidth
  175. int data;
  176. float relbw;
  177. unsigned char depth;
  178. } resonancebandwidth;
  179. /** RPN and NPRPN */
  180. struct { //nrpn
  181. int parhi, parlo;
  182. int valhi, vallo;
  183. unsigned char receive; //this is saved to disk by Master
  184. } NRPN;
  185. const AbsTime *time;
  186. int64_t last_update_timestamp;
  187. static const rtosc::Ports ports;
  188. private:
  189. const SYNTH_T &synth;
  190. };
  191. #endif