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.

220 lines
7.0KB

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