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.

251 lines
7.7KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. SUBnoteParameters.cpp - Parameters for SUBnote (SUBsynth)
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include "../globals.h"
  18. #include "SUBnoteParameters.h"
  19. #include <stdio.h>
  20. SUBnoteParameters::SUBnoteParameters():Presets()
  21. {
  22. setpresettype("Psubsynth");
  23. AmpEnvelope = new EnvelopeParams(64, 1);
  24. AmpEnvelope->ADSRinit_dB(0, 40, 127, 25);
  25. FreqEnvelope = new EnvelopeParams(64, 0);
  26. FreqEnvelope->ASRinit(30, 50, 64, 60);
  27. BandWidthEnvelope = new EnvelopeParams(64, 0);
  28. BandWidthEnvelope->ASRinit_bw(100, 70, 64, 60);
  29. GlobalFilter = new FilterParams(2, 80, 40);
  30. GlobalFilterEnvelope = new EnvelopeParams(0, 1);
  31. GlobalFilterEnvelope->ADSRinit_filter(64, 40, 64, 70, 60, 64);
  32. defaults();
  33. }
  34. void SUBnoteParameters::defaults()
  35. {
  36. PVolume = 96;
  37. PPanning = 64;
  38. PAmpVelocityScaleFunction = 90;
  39. Pfixedfreq = 0;
  40. PfixedfreqET = 0;
  41. Pnumstages = 2;
  42. Pbandwidth = 40;
  43. Phmagtype = 0;
  44. Pbwscale = 64;
  45. Pstereo = 1;
  46. Pstart = 1;
  47. PDetune = 8192;
  48. PCoarseDetune = 0;
  49. PDetuneType = 1;
  50. PFreqEnvelopeEnabled = 0;
  51. PBandWidthEnvelopeEnabled = 0;
  52. for(int n = 0; n < MAX_SUB_HARMONICS; ++n) {
  53. Phmag[n] = 0;
  54. Phrelbw[n] = 64;
  55. }
  56. Phmag[0] = 127;
  57. PGlobalFilterEnabled = 0;
  58. PGlobalFilterVelocityScale = 64;
  59. PGlobalFilterVelocityScaleFunction = 64;
  60. AmpEnvelope->defaults();
  61. FreqEnvelope->defaults();
  62. BandWidthEnvelope->defaults();
  63. GlobalFilter->defaults();
  64. GlobalFilterEnvelope->defaults();
  65. }
  66. SUBnoteParameters::~SUBnoteParameters()
  67. {
  68. delete (AmpEnvelope);
  69. delete (FreqEnvelope);
  70. delete (BandWidthEnvelope);
  71. delete (GlobalFilter);
  72. delete (GlobalFilterEnvelope);
  73. }
  74. void SUBnoteParameters::add2XML(XMLwrapper *xml)
  75. {
  76. xml->addpar("num_stages", Pnumstages);
  77. xml->addpar("harmonic_mag_type", Phmagtype);
  78. xml->addpar("start", Pstart);
  79. xml->beginbranch("HARMONICS");
  80. for(int i = 0; i < MAX_SUB_HARMONICS; ++i) {
  81. if((Phmag[i] == 0) && (xml->minimal))
  82. continue;
  83. xml->beginbranch("HARMONIC", i);
  84. xml->addpar("mag", Phmag[i]);
  85. xml->addpar("relbw", Phrelbw[i]);
  86. xml->endbranch();
  87. }
  88. xml->endbranch();
  89. xml->beginbranch("AMPLITUDE_PARAMETERS");
  90. xml->addparbool("stereo", Pstereo);
  91. xml->addpar("volume", PVolume);
  92. xml->addpar("panning", PPanning);
  93. xml->addpar("velocity_sensing", PAmpVelocityScaleFunction);
  94. xml->beginbranch("AMPLITUDE_ENVELOPE");
  95. AmpEnvelope->add2XML(xml);
  96. xml->endbranch();
  97. xml->endbranch();
  98. xml->beginbranch("FREQUENCY_PARAMETERS");
  99. xml->addparbool("fixed_freq", Pfixedfreq);
  100. xml->addpar("fixed_freq_et", PfixedfreqET);
  101. xml->addpar("detune", PDetune);
  102. xml->addpar("coarse_detune", PCoarseDetune);
  103. xml->addpar("detune_type", PDetuneType);
  104. xml->addpar("bandwidth", Pbandwidth);
  105. xml->addpar("bandwidth_scale", Pbwscale);
  106. xml->addparbool("freq_envelope_enabled", PFreqEnvelopeEnabled);
  107. if((PFreqEnvelopeEnabled != 0) || (!xml->minimal)) {
  108. xml->beginbranch("FREQUENCY_ENVELOPE");
  109. FreqEnvelope->add2XML(xml);
  110. xml->endbranch();
  111. }
  112. xml->addparbool("band_width_envelope_enabled", PBandWidthEnvelopeEnabled);
  113. if((PBandWidthEnvelopeEnabled != 0) || (!xml->minimal)) {
  114. xml->beginbranch("BANDWIDTH_ENVELOPE");
  115. BandWidthEnvelope->add2XML(xml);
  116. xml->endbranch();
  117. }
  118. xml->endbranch();
  119. xml->beginbranch("FILTER_PARAMETERS");
  120. xml->addparbool("enabled", PGlobalFilterEnabled);
  121. if((PGlobalFilterEnabled != 0) || (!xml->minimal)) {
  122. xml->beginbranch("FILTER");
  123. GlobalFilter->add2XML(xml);
  124. xml->endbranch();
  125. xml->addpar("filter_velocity_sensing",
  126. PGlobalFilterVelocityScaleFunction);
  127. xml->addpar("filter_velocity_sensing_amplitude",
  128. PGlobalFilterVelocityScale);
  129. xml->beginbranch("FILTER_ENVELOPE");
  130. GlobalFilterEnvelope->add2XML(xml);
  131. xml->endbranch();
  132. }
  133. xml->endbranch();
  134. }
  135. void SUBnoteParameters::getfromXML(XMLwrapper *xml)
  136. {
  137. Pnumstages = xml->getpar127("num_stages", Pnumstages);
  138. Phmagtype = xml->getpar127("harmonic_mag_type", Phmagtype);
  139. Pstart = xml->getpar127("start", Pstart);
  140. if(xml->enterbranch("HARMONICS")) {
  141. Phmag[0] = 0;
  142. for(int i = 0; i < MAX_SUB_HARMONICS; ++i) {
  143. if(xml->enterbranch("HARMONIC", i) == 0)
  144. continue;
  145. Phmag[i] = xml->getpar127("mag", Phmag[i]);
  146. Phrelbw[i] = xml->getpar127("relbw", Phrelbw[i]);
  147. xml->exitbranch();
  148. }
  149. xml->exitbranch();
  150. }
  151. if(xml->enterbranch("AMPLITUDE_PARAMETERS")) {
  152. Pstereo = xml->getparbool("stereo", Pstereo);
  153. PVolume = xml->getpar127("volume", PVolume);
  154. PPanning = xml->getpar127("panning", PPanning);
  155. PAmpVelocityScaleFunction = xml->getpar127("velocity_sensing",
  156. PAmpVelocityScaleFunction);
  157. if(xml->enterbranch("AMPLITUDE_ENVELOPE")) {
  158. AmpEnvelope->getfromXML(xml);
  159. xml->exitbranch();
  160. }
  161. xml->exitbranch();
  162. }
  163. if(xml->enterbranch("FREQUENCY_PARAMETERS")) {
  164. Pfixedfreq = xml->getparbool("fixed_freq", Pfixedfreq);
  165. PfixedfreqET = xml->getpar127("fixed_freq_et", PfixedfreqET);
  166. PDetune = xml->getpar("detune", PDetune, 0, 16383);
  167. PCoarseDetune = xml->getpar("coarse_detune", PCoarseDetune, 0, 16383);
  168. PDetuneType = xml->getpar127("detune_type", PDetuneType);
  169. Pbandwidth = xml->getpar127("bandwidth", Pbandwidth);
  170. Pbwscale = xml->getpar127("bandwidth_scale", Pbwscale);
  171. PFreqEnvelopeEnabled = xml->getparbool("freq_envelope_enabled",
  172. PFreqEnvelopeEnabled);
  173. if(xml->enterbranch("FREQUENCY_ENVELOPE")) {
  174. FreqEnvelope->getfromXML(xml);
  175. xml->exitbranch();
  176. }
  177. PBandWidthEnvelopeEnabled = xml->getparbool(
  178. "band_width_envelope_enabled",
  179. PBandWidthEnvelopeEnabled);
  180. if(xml->enterbranch("BANDWIDTH_ENVELOPE")) {
  181. BandWidthEnvelope->getfromXML(xml);
  182. xml->exitbranch();
  183. }
  184. xml->exitbranch();
  185. }
  186. if(xml->enterbranch("FILTER_PARAMETERS")) {
  187. PGlobalFilterEnabled = xml->getparbool("enabled", PGlobalFilterEnabled);
  188. if(xml->enterbranch("FILTER")) {
  189. GlobalFilter->getfromXML(xml);
  190. xml->exitbranch();
  191. }
  192. PGlobalFilterVelocityScaleFunction = xml->getpar127(
  193. "filter_velocity_sensing",
  194. PGlobalFilterVelocityScaleFunction);
  195. PGlobalFilterVelocityScale = xml->getpar127(
  196. "filter_velocity_sensing_amplitude",
  197. PGlobalFilterVelocityScale);
  198. if(xml->enterbranch("FILTER_ENVELOPE")) {
  199. GlobalFilterEnvelope->getfromXML(xml);
  200. xml->exitbranch();
  201. }
  202. xml->exitbranch();
  203. }
  204. }