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.

Controller.h 7.0KB

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