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.

1170 lines
35KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. ADnoteParameters.cpp - Parameters for ADnote (ADsynth)
  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 <stdlib.h>
  18. #include <stdio.h>
  19. #include <math.h>
  20. #include "ADnoteParameters.h"
  21. #include "EnvelopeParams.h"
  22. #include "LFOParams.h"
  23. #include "../Misc/XMLwrapper.h"
  24. #include "../DSP/FFTwrapper.h"
  25. #include "../Synth/OscilGen.h"
  26. #include "../Synth/Resonance.h"
  27. #include "FilterParams.h"
  28. #include <rtosc/ports.h>
  29. #include <rtosc/port-sugar.h>
  30. using rtosc::Ports;
  31. using rtosc::RtData;
  32. #define EXPAND(x) x
  33. #define rObject ADnoteVoiceParam
  34. static const Ports voicePorts = {
  35. rRecurp(OscilSmp, "Primary Oscillator"),
  36. rRecurp(FMSmp, "Modulating Oscillator"),
  37. rRecurp(FreqLfo, "Frequency LFO"),
  38. rRecurp(AmpLfo, "Amplitude LFO"),
  39. rRecurp(FilterLfo, "Filter LFO"),
  40. rRecurp(FreqEnvelope, "Frequency Envelope"),
  41. rRecurp(AmpEnvelope, "Amplitude Envelope"),
  42. rRecurp(FilterEnvelope, "Filter Envelope"),
  43. rRecurp(FMFreqEnvelope, "Modulator Frequency Envelope"),
  44. rRecurp(FMAmpEnvelope, "Modulator Amplitude Envelope"),
  45. rRecurp(VoiceFilter, "Optional Voice Filter"),
  46. rToggle(Enabled, "Voice Enable"),
  47. rParamZyn(Unison_size, "Number of subvoices"),
  48. rParamZyn(Unison_phase_randomness, "Phase Randomness"),
  49. rParamZyn(Unison_frequency_spread, "Subvoice detune"),
  50. rParamZyn(Unison_stereo_spread, "Subvoice L/R Separation"),
  51. rParamZyn(Unison_vibratto, "Subvoice vibratto"),
  52. rParamZyn(Unison_vibratto_speed, "Subvoice vibratto speed"),
  53. rOption(Unison_invert_phase, rOptions(none, random, 50%, 33%, 25%), "Subvoice Phases"),
  54. rOption(Type, rOptions(Sound,Noise), "Type of Sound"),
  55. rParamZyn(PDelay, "Voice Startup Delay"),
  56. rToggle(Presonance, "Resonance Enable"),
  57. rParamZyn(Pextoscil, "External Oscilator Selection"),
  58. rParamZyn(PextFMoscil, "External FM Oscilator Selection"),
  59. rParamZyn(Poscilphase, "Oscillator Phase"),
  60. rParamZyn(PFMoscilphase, "FM Oscillator Phase"),
  61. rToggle(Pfilterbypass, "Filter Bypass"),
  62. //Freq Stuff
  63. rToggle(Pfixedfreq, "If frequency is fixed"),
  64. rParamZyn(PfixedfreqET, "Equal Tempermant Parameter"),
  65. rParamI(PDetune, "Fine Detune"),
  66. rParamI(PCoarseDetune, "Coarse Detune"),
  67. rParamZyn(PDetuneType, "Magnitude of Detune"),
  68. rToggle(PFreqEnvelopeEnabled, "Frequency Envelope Enable"),
  69. rToggle(PFreqLfoEnabled, "Frequency LFO Enable"),
  70. //Amplitude Stuff
  71. rParamZyn(PPanning, "Panning"),
  72. rParamZyn(PVolume, "Volume"),
  73. rToggle(PVolumeminus, "Signal Inverter"), //do we really need this??
  74. rParamZyn(PAmpVelocityScaleFunction, "Velocity Sensing"),
  75. rToggle(PAmpEnvelopeEnabled, "Amplitude Envelope Enable"),
  76. rToggle(PAmpLfoEnabled, "Amplitude LFO Enable"),
  77. //Filter Stuff
  78. rToggle(PFilterEnabled, "Filter Enable"),
  79. rToggle(PFilterEnvelopeEnabled, "Filter Envelope Enable"),
  80. rToggle(PFilterLfoEnabled, "Filter LFO Enable"),
  81. //Modulator Stuff
  82. rParamZyn(PFMEnabled, "Modulator Enable/Type"),
  83. rParamI(PFMVoice, "Modulator Oscillator Selection"),
  84. rParamZyn(PFMVolume, "Modulator Magnitude"),
  85. rParamZyn(PFMVolumeDamp, "Modulator HF dampening"),
  86. rParamZyn(PFMVelocityScaleFunction, "Modulator Velocity Function"),
  87. rParamI(PFMDetune, "Modulator Fine Detune"),
  88. rParamI(PFMCoarseDetune, "Modulator Coarse Detune"),
  89. rParamZyn(PFMDetuneType, "Modulator Detune Magnitude"),
  90. rToggle(PFMFreqEnvelopeEnabled, "Modulator Frequency Envelope"),
  91. rToggle(PFMAmpEnvelopeEnabled, "Modulator Amplitude Envelope"),
  92. //weird stuff for PCoarseDetune
  93. {"detunevalue:", NULL, NULL, [](const char *, RtData &d)
  94. {
  95. rObject *obj = (rObject *)d.obj;
  96. //TODO check if this is accurate or if PCoarseDetune is utilized
  97. //TODO do the same for the other engines
  98. d.reply(d.loc, "f", getdetune(obj->PDetuneType, 0, obj->PDetune));
  99. }},
  100. {"octave::c:i", NULL, NULL, [](const char *msg, RtData &d)
  101. {
  102. rObject *obj = (rObject *)d.obj;
  103. if(!rtosc_narguments(msg)) {
  104. int k=obj->PCoarseDetune/1024;
  105. if (k>=8) k-=16;
  106. d.reply(d.loc, "i", k);
  107. } else {
  108. int k=(int) rtosc_argument(msg, 0).i;
  109. if (k<0) k+=16;
  110. obj->PCoarseDetune = k*1024 + obj->PCoarseDetune%1024;
  111. }
  112. }},
  113. {"coarsedetune::c:i", NULL, NULL, [](const char *msg, RtData &d)
  114. {
  115. rObject *obj = (rObject *)d.obj;
  116. if(!rtosc_narguments(msg)) {
  117. int k=obj->PCoarseDetune%1024;
  118. if (k>=512) k-=1024;
  119. d.reply(d.loc, "i", k);
  120. } else {
  121. int k=(int) rtosc_argument(msg, 0).i;
  122. if (k<0) k+=1024;
  123. obj->PCoarseDetune = k + (obj->PCoarseDetune/1024)*1024;
  124. }
  125. }},
  126. //weird stuff for PCoarseDetune
  127. {"FMdetunevalue:", NULL, NULL, [](const char *, RtData &d)
  128. {
  129. rObject *obj = (rObject *)d.obj;
  130. //TODO check if this is accurate or if PCoarseDetune is utilized
  131. //TODO do the same for the other engines
  132. d.reply(d.loc, "f", getdetune(obj->PFMDetuneType, 0, obj->PFMDetune));
  133. }},
  134. {"FMoctave::c:i", NULL, NULL, [](const char *msg, RtData &d)
  135. {
  136. rObject *obj = (rObject *)d.obj;
  137. if(!rtosc_narguments(msg)) {
  138. int k=obj->PFMCoarseDetune/1024;
  139. if (k>=8) k-=16;
  140. d.reply(d.loc, "i", k);
  141. } else {
  142. int k=(int) rtosc_argument(msg, 0).i;
  143. if (k<0) k+=16;
  144. obj->PFMCoarseDetune = k*1024 + obj->PFMCoarseDetune%1024;
  145. }
  146. }},
  147. {"FMcoarsedetune::c:i", NULL, NULL, [](const char *msg, RtData &d)
  148. {
  149. rObject *obj = (rObject *)d.obj;
  150. if(!rtosc_narguments(msg)) {
  151. int k=obj->PFMCoarseDetune%1024;
  152. if (k>=512) k-=1024;
  153. d.reply(d.loc, "i", k);
  154. } else {
  155. int k=(int) rtosc_argument(msg, 0).i;
  156. if (k<0) k+=1024;
  157. obj->PFMCoarseDetune = k + (obj->PFMCoarseDetune/1024)*1024;
  158. }
  159. }},
  160. //Reader
  161. {"unisonFrequencySpreadCents:", NULL, NULL, [](const char *, RtData &d)
  162. {
  163. rObject *obj = (rObject *)d.obj;
  164. d.reply(d.loc, "f", obj->getUnisonFrequencySpreadCents());
  165. }},
  166. };
  167. #undef rObject
  168. #define rObject ADnoteGlobalParam
  169. static const Ports globalPorts = {
  170. rRecurp(Reson, "Resonance"),
  171. rRecurp(FreqLfo, "Frequency LFO"),
  172. rRecurp(AmpLfo, "Amplitude LFO"),
  173. rRecurp(FilterLfo, "Filter LFO"),
  174. rRecurp(FreqEnvelope, "Frequency Envelope"),
  175. rRecurp(AmpEnvelope, "Frequency Envelope"),
  176. rRecurp(FilterEnvelope, "Frequency Envelope"),
  177. rRecurp(GlobalFilter, "Filter"),
  178. rToggle(PStereo, "Mono/Stereo Enable"),
  179. //Frequency
  180. rParamI(PDetune, "Fine Detune"),
  181. rParamI(PCoarseDetune, "Coarse Detune"),
  182. rParamZyn(PDetuneType, "Detune Scaling Type"),
  183. rParamZyn(PBandwidth, "Relative Fine Detune Gain"),
  184. //Amplitude
  185. rParamZyn(PPanning, "Panning of ADsynth (0 random, 1 left, 127 right)"),
  186. rParamZyn(PVolume, "volume control"),
  187. rParamZyn(PAmpVelocityScaleFunction, "Volume Velocity Control"),
  188. rParamZyn(PPunchStrength, "Punch Strength"),
  189. rParamZyn(PPunchTime, "UNKNOWN"),
  190. rParamZyn(PPunchStretch, "How Punch changes with note frequency"),
  191. rParamZyn(PPunchVelocitySensing, "Punch Velocity control"),
  192. //Filter
  193. rParamZyn(PFilterVelocityScale, "Filter Velocity Magnitude"),
  194. rParamZyn(PFilterVelocityScaleFunction, "Filter Velocity Function Shape"),
  195. //Resonance
  196. rParamZyn(Hrandgrouping, "How randomness is applied to multiple voices using the same oscil"),
  197. //weird stuff for PCoarseDetune
  198. {"detunevalue:", NULL, NULL, [](const char *, RtData &d)
  199. {
  200. rObject *obj = (rObject *)d.obj;
  201. d.reply(d.loc, "f", getdetune(obj->PDetuneType, 0, obj->PDetune));
  202. }},
  203. {"octave::c:i", NULL, NULL, [](const char *msg, RtData &d)
  204. {
  205. rObject *obj = (rObject *)d.obj;
  206. if(!rtosc_narguments(msg)) {
  207. int k=obj->PCoarseDetune/1024;
  208. if (k>=8) k-=16;
  209. d.reply(d.loc, "i", k);
  210. } else {
  211. int k=(int) rtosc_argument(msg, 0).i;
  212. if (k<0) k+=16;
  213. obj->PCoarseDetune = k*1024 + obj->PCoarseDetune%1024;
  214. }
  215. }},
  216. {"coarsedetune::c:i", NULL, NULL, [](const char *msg, RtData &d)
  217. {
  218. rObject *obj = (rObject *)d.obj;
  219. if(!rtosc_narguments(msg)) {
  220. int k=obj->PCoarseDetune%1024;
  221. if (k>=512) k-=1024;
  222. d.reply(d.loc, "i", k);
  223. } else {
  224. int k=(int) rtosc_argument(msg, 0).i;
  225. if (k<0) k+=1024;
  226. obj->PCoarseDetune = k + (obj->PCoarseDetune/1024)*1024;
  227. }
  228. }},
  229. };
  230. #undef rObject
  231. #define rObject ADnoteParameters
  232. static const Ports adPorts = {//XXX 16 should not be hard coded
  233. rSelf(ADnoteParameters),
  234. rPaste,
  235. rArrayPaste,
  236. rRecurs(VoicePar, NUM_VOICES),
  237. rRecur(GlobalPar, "Adnote Parameters"),
  238. };
  239. const Ports &ADnoteParameters::ports = adPorts;
  240. const Ports &ADnoteVoiceParam::ports = voicePorts;
  241. const Ports &ADnoteGlobalParam::ports = globalPorts;
  242. ADnoteParameters::ADnoteParameters(const SYNTH_T &synth, FFTwrapper *fft_)
  243. :PresetsArray()
  244. {
  245. setpresettype("Padsynth");
  246. fft = fft_;
  247. for(int nvoice = 0; nvoice < NUM_VOICES; ++nvoice)
  248. EnableVoice(synth, nvoice);
  249. defaults();
  250. }
  251. ADnoteGlobalParam::ADnoteGlobalParam()
  252. {
  253. FreqEnvelope = new EnvelopeParams(0, 0);
  254. FreqEnvelope->ASRinit(64, 50, 64, 60);
  255. FreqLfo = new LFOParams(70, 0, 64, 0, 0, 0, 0, 0);
  256. AmpEnvelope = new EnvelopeParams(64, 1);
  257. AmpEnvelope->ADSRinit_dB(0, 40, 127, 25);
  258. AmpLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 1);
  259. GlobalFilter = new FilterParams(2, 94, 40);
  260. FilterEnvelope = new EnvelopeParams(0, 1);
  261. FilterEnvelope->ADSRinit_filter(64, 40, 64, 70, 60, 64);
  262. FilterLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 2);
  263. Reson = new Resonance();
  264. }
  265. void ADnoteParameters::defaults()
  266. {
  267. //Default Parameters
  268. GlobalPar.defaults();
  269. for(int nvoice = 0; nvoice < NUM_VOICES; ++nvoice)
  270. defaults(nvoice);
  271. VoicePar[0].Enabled = 1;
  272. }
  273. void ADnoteGlobalParam::defaults()
  274. {
  275. /* Frequency Global Parameters */
  276. PStereo = 1; //stereo
  277. PDetune = 8192; //zero
  278. PCoarseDetune = 0;
  279. PDetuneType = 1;
  280. FreqEnvelope->defaults();
  281. FreqLfo->defaults();
  282. PBandwidth = 64;
  283. /* Amplitude Global Parameters */
  284. PVolume = 90;
  285. PPanning = 64; //center
  286. PAmpVelocityScaleFunction = 64;
  287. AmpEnvelope->defaults();
  288. AmpLfo->defaults();
  289. PPunchStrength = 0;
  290. PPunchTime = 60;
  291. PPunchStretch = 64;
  292. PPunchVelocitySensing = 72;
  293. Hrandgrouping = 0;
  294. /* Filter Global Parameters*/
  295. PFilterVelocityScale = 64;
  296. PFilterVelocityScaleFunction = 64;
  297. GlobalFilter->defaults();
  298. FilterEnvelope->defaults();
  299. FilterLfo->defaults();
  300. Reson->defaults();
  301. }
  302. /*
  303. * Defaults a voice
  304. */
  305. void ADnoteParameters::defaults(int n)
  306. {
  307. VoicePar[n].defaults();
  308. }
  309. void ADnoteVoiceParam::defaults()
  310. {
  311. Enabled = 0;
  312. Unison_size = 1;
  313. Unison_frequency_spread = 60;
  314. Unison_stereo_spread = 64;
  315. Unison_vibratto = 64;
  316. Unison_vibratto_speed = 64;
  317. Unison_invert_phase = 0;
  318. Unison_phase_randomness = 127;
  319. Type = 0;
  320. Pfixedfreq = 0;
  321. PfixedfreqET = 0;
  322. Presonance = 1;
  323. Pfilterbypass = 0;
  324. Pextoscil = -1;
  325. PextFMoscil = -1;
  326. Poscilphase = 64;
  327. PFMoscilphase = 64;
  328. PDelay = 0;
  329. PVolume = 100;
  330. PVolumeminus = 0;
  331. PPanning = 64; //center
  332. PDetune = 8192; //8192=0
  333. PCoarseDetune = 0;
  334. PDetuneType = 0;
  335. PFreqLfoEnabled = 0;
  336. PFreqEnvelopeEnabled = 0;
  337. PAmpEnvelopeEnabled = 0;
  338. PAmpLfoEnabled = 0;
  339. PAmpVelocityScaleFunction = 127;
  340. PFilterEnabled = 0;
  341. PFilterEnvelopeEnabled = 0;
  342. PFilterLfoEnabled = 0;
  343. PFMEnabled = 0;
  344. //I use the internal oscillator (-1)
  345. PFMVoice = -1;
  346. PFMVolume = 90;
  347. PFMVolumeDamp = 64;
  348. PFMDetune = 8192;
  349. PFMCoarseDetune = 0;
  350. PFMDetuneType = 0;
  351. PFMFreqEnvelopeEnabled = 0;
  352. PFMAmpEnvelopeEnabled = 0;
  353. PFMVelocityScaleFunction = 64;
  354. OscilSmp->defaults();
  355. FMSmp->defaults();
  356. AmpEnvelope->defaults();
  357. AmpLfo->defaults();
  358. FreqEnvelope->defaults();
  359. FreqLfo->defaults();
  360. VoiceFilter->defaults();
  361. FilterEnvelope->defaults();
  362. FilterLfo->defaults();
  363. FMFreqEnvelope->defaults();
  364. FMAmpEnvelope->defaults();
  365. }
  366. /*
  367. * Init the voice parameters
  368. */
  369. void ADnoteParameters::EnableVoice(const SYNTH_T &synth, int nvoice)
  370. {
  371. VoicePar[nvoice].enable(synth, fft, GlobalPar.Reson);
  372. }
  373. void ADnoteVoiceParam::enable(const SYNTH_T &synth, FFTwrapper *fft, Resonance *Reson)
  374. {
  375. OscilSmp = new OscilGen(synth, fft, Reson);
  376. FMSmp = new OscilGen(synth, fft, NULL);
  377. AmpEnvelope = new EnvelopeParams(64, 1);
  378. AmpEnvelope->ADSRinit_dB(0, 100, 127, 100);
  379. AmpLfo = new LFOParams(90, 32, 64, 0, 0, 30, 0, 1);
  380. FreqEnvelope = new EnvelopeParams(0, 0);
  381. FreqEnvelope->ASRinit(30, 40, 64, 60);
  382. FreqLfo = new LFOParams(50, 40, 0, 0, 0, 0, 0, 0);
  383. VoiceFilter = new FilterParams(2, 50, 60);
  384. FilterEnvelope = new EnvelopeParams(0, 0);
  385. FilterEnvelope->ADSRinit_filter(90, 70, 40, 70, 10, 40);
  386. FilterLfo = new LFOParams(50, 20, 64, 0, 0, 0, 0, 2);
  387. FMFreqEnvelope = new EnvelopeParams(0, 0);
  388. FMFreqEnvelope->ASRinit(20, 90, 40, 80);
  389. FMAmpEnvelope = new EnvelopeParams(64, 1);
  390. FMAmpEnvelope->ADSRinit(80, 90, 127, 100);
  391. }
  392. /*
  393. * Get the Multiplier of the fine detunes of the voices
  394. */
  395. float ADnoteParameters::getBandwidthDetuneMultiplier() const
  396. {
  397. float bw = (GlobalPar.PBandwidth - 64.0f) / 64.0f;
  398. bw = powf(2.0f, bw * powf(fabs(bw), 0.2f) * 5.0f);
  399. return bw;
  400. }
  401. /*
  402. * Get the unison spread in cents for a voice
  403. */
  404. float ADnoteParameters::getUnisonFrequencySpreadCents(int nvoice) const
  405. {
  406. return VoicePar[nvoice].getUnisonFrequencySpreadCents();
  407. }
  408. float ADnoteVoiceParam::getUnisonFrequencySpreadCents(void) const {
  409. return powf(Unison_frequency_spread / 127.0 * 2.0f, 2.0f) * 50.0f; //cents
  410. }
  411. /*
  412. * Kill the voice
  413. */
  414. void ADnoteParameters::KillVoice(int nvoice)
  415. {
  416. VoicePar[nvoice].kill();
  417. }
  418. void ADnoteVoiceParam::kill()
  419. {
  420. delete OscilSmp;
  421. delete FMSmp;
  422. delete AmpEnvelope;
  423. delete AmpLfo;
  424. delete FreqEnvelope;
  425. delete FreqLfo;
  426. delete VoiceFilter;
  427. delete FilterEnvelope;
  428. delete FilterLfo;
  429. delete FMFreqEnvelope;
  430. delete FMAmpEnvelope;
  431. }
  432. ADnoteGlobalParam::~ADnoteGlobalParam()
  433. {
  434. delete FreqEnvelope;
  435. delete FreqLfo;
  436. delete AmpEnvelope;
  437. delete AmpLfo;
  438. delete GlobalFilter;
  439. delete FilterEnvelope;
  440. delete FilterLfo;
  441. delete Reson;
  442. }
  443. ADnoteParameters::~ADnoteParameters()
  444. {
  445. for(int nvoice = 0; nvoice < NUM_VOICES; ++nvoice)
  446. KillVoice(nvoice);
  447. }
  448. int ADnoteParameters::get_unison_size_index(int nvoice) const
  449. {
  450. int index = 0;
  451. if(nvoice >= NUM_VOICES)
  452. return 0;
  453. int unison = VoicePar[nvoice].Unison_size;
  454. while(1) {
  455. if(ADnote_unison_sizes[index] >= unison)
  456. return index;
  457. if(ADnote_unison_sizes[index] == 0)
  458. return index - 1;
  459. index++;
  460. }
  461. return 0;
  462. }
  463. void ADnoteParameters::set_unison_size_index(int nvoice, int index) {
  464. int unison = 1;
  465. for(int i = 0; i <= index; ++i) {
  466. unison = ADnote_unison_sizes[i];
  467. if(unison == 0) {
  468. unison = ADnote_unison_sizes[i - 1];
  469. break;
  470. }
  471. }
  472. VoicePar[nvoice].Unison_size = unison;
  473. }
  474. void ADnoteParameters::add2XMLsection(XMLwrapper *xml, int n)
  475. {
  476. int nvoice = n;
  477. if(nvoice >= NUM_VOICES)
  478. return;
  479. int oscilused = 0, fmoscilused = 0; //if the oscil or fmoscil are used by another voice
  480. for(int i = 0; i < NUM_VOICES; ++i) {
  481. if(VoicePar[i].Pextoscil == nvoice)
  482. oscilused = 1;
  483. if(VoicePar[i].PextFMoscil == nvoice)
  484. fmoscilused = 1;
  485. }
  486. xml->addparbool("enabled", VoicePar[nvoice].Enabled);
  487. if(((VoicePar[nvoice].Enabled == 0) && (oscilused == 0)
  488. && (fmoscilused == 0)) && (xml->minimal))
  489. return;
  490. VoicePar[nvoice].add2XML(xml, fmoscilused);
  491. }
  492. void ADnoteVoiceParam::add2XML(XMLwrapper *xml, bool fmoscilused)
  493. {
  494. xml->addpar("type", Type);
  495. xml->addpar("unison_size", Unison_size);
  496. xml->addpar("unison_frequency_spread",
  497. Unison_frequency_spread);
  498. xml->addpar("unison_stereo_spread", Unison_stereo_spread);
  499. xml->addpar("unison_vibratto", Unison_vibratto);
  500. xml->addpar("unison_vibratto_speed", Unison_vibratto_speed);
  501. xml->addpar("unison_invert_phase", Unison_invert_phase);
  502. xml->addpar("unison_phase_randomness", Unison_phase_randomness);
  503. xml->addpar("delay", PDelay);
  504. xml->addparbool("resonance", Presonance);
  505. xml->addpar("ext_oscil", Pextoscil);
  506. xml->addpar("ext_fm_oscil", PextFMoscil);
  507. xml->addpar("oscil_phase", Poscilphase);
  508. xml->addpar("oscil_fm_phase", PFMoscilphase);
  509. xml->addparbool("filter_enabled", PFilterEnabled);
  510. xml->addparbool("filter_bypass", Pfilterbypass);
  511. xml->addpar("fm_enabled", PFMEnabled);
  512. xml->beginbranch("OSCIL");
  513. OscilSmp->add2XML(xml);
  514. xml->endbranch();
  515. xml->beginbranch("AMPLITUDE_PARAMETERS");
  516. xml->addpar("panning", PPanning);
  517. xml->addpar("volume", PVolume);
  518. xml->addparbool("volume_minus", PVolumeminus);
  519. xml->addpar("velocity_sensing", PAmpVelocityScaleFunction);
  520. xml->addparbool("amp_envelope_enabled",
  521. PAmpEnvelopeEnabled);
  522. if((PAmpEnvelopeEnabled != 0) || (!xml->minimal)) {
  523. xml->beginbranch("AMPLITUDE_ENVELOPE");
  524. AmpEnvelope->add2XML(xml);
  525. xml->endbranch();
  526. }
  527. xml->addparbool("amp_lfo_enabled", PAmpLfoEnabled);
  528. if((PAmpLfoEnabled != 0) || (!xml->minimal)) {
  529. xml->beginbranch("AMPLITUDE_LFO");
  530. AmpLfo->add2XML(xml);
  531. xml->endbranch();
  532. }
  533. xml->endbranch();
  534. xml->beginbranch("FREQUENCY_PARAMETERS");
  535. xml->addparbool("fixed_freq", Pfixedfreq);
  536. xml->addpar("fixed_freq_et", PfixedfreqET);
  537. xml->addpar("detune", PDetune);
  538. xml->addpar("coarse_detune", PCoarseDetune);
  539. xml->addpar("detune_type", PDetuneType);
  540. xml->addparbool("freq_envelope_enabled",
  541. PFreqEnvelopeEnabled);
  542. if((PFreqEnvelopeEnabled != 0) || (!xml->minimal)) {
  543. xml->beginbranch("FREQUENCY_ENVELOPE");
  544. FreqEnvelope->add2XML(xml);
  545. xml->endbranch();
  546. }
  547. xml->addparbool("freq_lfo_enabled", PFreqLfoEnabled);
  548. if((PFreqLfoEnabled != 0) || (!xml->minimal)) {
  549. xml->beginbranch("FREQUENCY_LFO");
  550. FreqLfo->add2XML(xml);
  551. xml->endbranch();
  552. }
  553. xml->endbranch();
  554. if((PFilterEnabled != 0) || (!xml->minimal)) {
  555. xml->beginbranch("FILTER_PARAMETERS");
  556. xml->beginbranch("FILTER");
  557. VoiceFilter->add2XML(xml);
  558. xml->endbranch();
  559. xml->addparbool("filter_envelope_enabled",
  560. PFilterEnvelopeEnabled);
  561. if((PFilterEnvelopeEnabled != 0) || (!xml->minimal)) {
  562. xml->beginbranch("FILTER_ENVELOPE");
  563. FilterEnvelope->add2XML(xml);
  564. xml->endbranch();
  565. }
  566. xml->addparbool("filter_lfo_enabled",
  567. PFilterLfoEnabled);
  568. if((PFilterLfoEnabled != 0) || (!xml->minimal)) {
  569. xml->beginbranch("FILTER_LFO");
  570. FilterLfo->add2XML(xml);
  571. xml->endbranch();
  572. }
  573. xml->endbranch();
  574. }
  575. if((PFMEnabled != 0) || (fmoscilused != 0)
  576. || (!xml->minimal)) {
  577. xml->beginbranch("FM_PARAMETERS");
  578. xml->addpar("input_voice", PFMVoice);
  579. xml->addpar("volume", PFMVolume);
  580. xml->addpar("volume_damp", PFMVolumeDamp);
  581. xml->addpar("velocity_sensing",
  582. PFMVelocityScaleFunction);
  583. xml->addparbool("amp_envelope_enabled",
  584. PFMAmpEnvelopeEnabled);
  585. if((PFMAmpEnvelopeEnabled != 0) || (!xml->minimal)) {
  586. xml->beginbranch("AMPLITUDE_ENVELOPE");
  587. FMAmpEnvelope->add2XML(xml);
  588. xml->endbranch();
  589. }
  590. xml->beginbranch("MODULATOR");
  591. xml->addpar("detune", PFMDetune);
  592. xml->addpar("coarse_detune", PFMCoarseDetune);
  593. xml->addpar("detune_type", PFMDetuneType);
  594. xml->addparbool("freq_envelope_enabled",
  595. PFMFreqEnvelopeEnabled);
  596. if((PFMFreqEnvelopeEnabled != 0) || (!xml->minimal)) {
  597. xml->beginbranch("FREQUENCY_ENVELOPE");
  598. FMFreqEnvelope->add2XML(xml);
  599. xml->endbranch();
  600. }
  601. xml->beginbranch("OSCIL");
  602. FMSmp->add2XML(xml);
  603. xml->endbranch();
  604. xml->endbranch();
  605. xml->endbranch();
  606. }
  607. }
  608. void ADnoteGlobalParam::add2XML(XMLwrapper *xml)
  609. {
  610. xml->addparbool("stereo", PStereo);
  611. xml->beginbranch("AMPLITUDE_PARAMETERS");
  612. xml->addpar("volume", PVolume);
  613. xml->addpar("panning", PPanning);
  614. xml->addpar("velocity_sensing", PAmpVelocityScaleFunction);
  615. xml->addpar("punch_strength", PPunchStrength);
  616. xml->addpar("punch_time", PPunchTime);
  617. xml->addpar("punch_stretch", PPunchStretch);
  618. xml->addpar("punch_velocity_sensing", PPunchVelocitySensing);
  619. xml->addpar("harmonic_randomness_grouping", Hrandgrouping);
  620. xml->beginbranch("AMPLITUDE_ENVELOPE");
  621. AmpEnvelope->add2XML(xml);
  622. xml->endbranch();
  623. xml->beginbranch("AMPLITUDE_LFO");
  624. AmpLfo->add2XML(xml);
  625. xml->endbranch();
  626. xml->endbranch();
  627. xml->beginbranch("FREQUENCY_PARAMETERS");
  628. xml->addpar("detune", PDetune);
  629. xml->addpar("coarse_detune", PCoarseDetune);
  630. xml->addpar("detune_type", PDetuneType);
  631. xml->addpar("bandwidth", PBandwidth);
  632. xml->beginbranch("FREQUENCY_ENVELOPE");
  633. FreqEnvelope->add2XML(xml);
  634. xml->endbranch();
  635. xml->beginbranch("FREQUENCY_LFO");
  636. FreqLfo->add2XML(xml);
  637. xml->endbranch();
  638. xml->endbranch();
  639. xml->beginbranch("FILTER_PARAMETERS");
  640. xml->addpar("velocity_sensing_amplitude", PFilterVelocityScale);
  641. xml->addpar("velocity_sensing", PFilterVelocityScaleFunction);
  642. xml->beginbranch("FILTER");
  643. GlobalFilter->add2XML(xml);
  644. xml->endbranch();
  645. xml->beginbranch("FILTER_ENVELOPE");
  646. FilterEnvelope->add2XML(xml);
  647. xml->endbranch();
  648. xml->beginbranch("FILTER_LFO");
  649. FilterLfo->add2XML(xml);
  650. xml->endbranch();
  651. xml->endbranch();
  652. xml->beginbranch("RESONANCE");
  653. Reson->add2XML(xml);
  654. xml->endbranch();
  655. }
  656. void ADnoteParameters::add2XML(XMLwrapper *xml)
  657. {
  658. GlobalPar.add2XML(xml);
  659. for(int nvoice = 0; nvoice < NUM_VOICES; ++nvoice) {
  660. xml->beginbranch("VOICE", nvoice);
  661. add2XMLsection(xml, nvoice);
  662. xml->endbranch();
  663. }
  664. }
  665. void ADnoteGlobalParam::getfromXML(XMLwrapper *xml)
  666. {
  667. PStereo = xml->getparbool("stereo", PStereo);
  668. if(xml->enterbranch("AMPLITUDE_PARAMETERS")) {
  669. PVolume = xml->getpar127("volume", PVolume);
  670. PPanning = xml->getpar127("panning", PPanning);
  671. PAmpVelocityScaleFunction = xml->getpar127("velocity_sensing",
  672. PAmpVelocityScaleFunction);
  673. PPunchStrength = xml->getpar127("punch_strength", PPunchStrength);
  674. PPunchTime = xml->getpar127("punch_time", PPunchTime);
  675. PPunchStretch = xml->getpar127("punch_stretch", PPunchStretch);
  676. PPunchVelocitySensing = xml->getpar127("punch_velocity_sensing",
  677. PPunchVelocitySensing);
  678. Hrandgrouping = xml->getpar127("harmonic_randomness_grouping",
  679. Hrandgrouping);
  680. if(xml->enterbranch("AMPLITUDE_ENVELOPE")) {
  681. AmpEnvelope->getfromXML(xml);
  682. xml->exitbranch();
  683. }
  684. if(xml->enterbranch("AMPLITUDE_LFO")) {
  685. AmpLfo->getfromXML(xml);
  686. xml->exitbranch();
  687. }
  688. xml->exitbranch();
  689. }
  690. if(xml->enterbranch("FREQUENCY_PARAMETERS")) {
  691. PDetune = xml->getpar("detune", PDetune, 0, 16383);
  692. PCoarseDetune = xml->getpar("coarse_detune", PCoarseDetune, 0, 16383);
  693. PDetuneType = xml->getpar127("detune_type", PDetuneType);
  694. PBandwidth = xml->getpar127("bandwidth", PBandwidth);
  695. xml->enterbranch("FREQUENCY_ENVELOPE");
  696. FreqEnvelope->getfromXML(xml);
  697. xml->exitbranch();
  698. xml->enterbranch("FREQUENCY_LFO");
  699. FreqLfo->getfromXML(xml);
  700. xml->exitbranch();
  701. xml->exitbranch();
  702. }
  703. if(xml->enterbranch("FILTER_PARAMETERS")) {
  704. PFilterVelocityScale = xml->getpar127("velocity_sensing_amplitude",
  705. PFilterVelocityScale);
  706. PFilterVelocityScaleFunction = xml->getpar127(
  707. "velocity_sensing",
  708. PFilterVelocityScaleFunction);
  709. xml->enterbranch("FILTER");
  710. GlobalFilter->getfromXML(xml);
  711. xml->exitbranch();
  712. xml->enterbranch("FILTER_ENVELOPE");
  713. FilterEnvelope->getfromXML(xml);
  714. xml->exitbranch();
  715. xml->enterbranch("FILTER_LFO");
  716. FilterLfo->getfromXML(xml);
  717. xml->exitbranch();
  718. xml->exitbranch();
  719. }
  720. if(xml->enterbranch("RESONANCE")) {
  721. Reson->getfromXML(xml);
  722. xml->exitbranch();
  723. }
  724. }
  725. void ADnoteParameters::getfromXML(XMLwrapper *xml)
  726. {
  727. GlobalPar.getfromXML(xml);
  728. for(int nvoice = 0; nvoice < NUM_VOICES; ++nvoice) {
  729. VoicePar[nvoice].Enabled = 0;
  730. if(xml->enterbranch("VOICE", nvoice) == 0)
  731. continue;
  732. getfromXMLsection(xml, nvoice);
  733. xml->exitbranch();
  734. }
  735. }
  736. void ADnoteParameters::getfromXMLsection(XMLwrapper *xml, int n)
  737. {
  738. int nvoice = n;
  739. if(nvoice >= NUM_VOICES)
  740. return;
  741. VoicePar[nvoice].getfromXML(xml, nvoice);
  742. }
  743. void ADnoteParameters::paste(ADnoteParameters &a)
  744. {
  745. this->GlobalPar.paste(a.GlobalPar);
  746. for(int i=0; i<NUM_VOICES; ++i)
  747. this->VoicePar[i].paste(a.VoicePar[i]);
  748. }
  749. void ADnoteParameters::pasteArray(ADnoteParameters &a, int nvoice)
  750. {
  751. if(nvoice >= NUM_VOICES)
  752. return;
  753. VoicePar[nvoice].paste(a.VoicePar[nvoice]);
  754. }
  755. #define copy(x) this->x = a.x
  756. #define RCopy(x) this->x->paste(*a.x)
  757. void ADnoteVoiceParam::paste(ADnoteVoiceParam &a)
  758. {
  759. //Come on C++ get some darn reflection, this is horrible
  760. copy(Enabled);
  761. copy(Unison_size);
  762. copy(Unison_frequency_spread);
  763. copy(Unison_stereo_spread);
  764. copy(Unison_vibratto);
  765. copy(Unison_vibratto_speed);
  766. copy(Unison_invert_phase);
  767. copy(Unison_phase_randomness);
  768. copy(Type);
  769. copy(PDelay);
  770. copy(Presonance);
  771. copy(Pextoscil);
  772. copy(PextFMoscil);
  773. copy(Poscilphase);
  774. copy(PFMoscilphase);
  775. copy(PFilterEnabled);
  776. copy(Pfilterbypass);
  777. copy(PFMEnabled);
  778. RCopy(OscilSmp);
  779. copy(PPanning);
  780. copy(PVolume);
  781. copy(PVolumeminus);
  782. copy(PAmpVelocityScaleFunction);
  783. copy(PAmpEnvelopeEnabled);
  784. RCopy(AmpEnvelope);
  785. copy(PAmpLfoEnabled);
  786. RCopy(AmpLfo);
  787. copy(Pfixedfreq);
  788. copy(PfixedfreqET);
  789. copy(PDetune);
  790. copy(PCoarseDetune);
  791. copy(PDetuneType);
  792. copy(PFreqEnvelopeEnabled);
  793. RCopy(FreqEnvelope);
  794. copy(PFreqLfoEnabled);
  795. RCopy(FreqLfo);
  796. RCopy(VoiceFilter);
  797. copy(PFilterEnvelopeEnabled);
  798. RCopy(FilterEnvelope);
  799. copy(PFilterLfoEnabled);
  800. RCopy(FilterLfo);
  801. copy(PFMVoice);
  802. copy(PFMVolume);
  803. copy(PFMVolumeDamp);
  804. copy(PFMVelocityScaleFunction);
  805. copy(PFMAmpEnvelopeEnabled);
  806. RCopy(FMAmpEnvelope);
  807. copy(PFMDetune);
  808. copy(PFMCoarseDetune);
  809. copy(PFMDetuneType);
  810. copy(PFMFreqEnvelopeEnabled);
  811. RCopy(FMFreqEnvelope);
  812. RCopy(FMSmp);
  813. }
  814. void ADnoteGlobalParam::paste(ADnoteGlobalParam &a)
  815. {
  816. copy(PStereo);
  817. copy(PVolume);
  818. copy(PPanning);
  819. copy(PAmpVelocityScaleFunction);
  820. copy(PPunchStrength);
  821. copy(PPunchTime);
  822. copy(PPunchStretch);
  823. copy(PPunchVelocitySensing);
  824. copy(Hrandgrouping);
  825. RCopy(AmpEnvelope);
  826. RCopy(AmpLfo);
  827. copy(PDetune);
  828. copy(PCoarseDetune);
  829. copy(PDetuneType);
  830. copy(PBandwidth);
  831. RCopy(FreqEnvelope);
  832. RCopy(FreqLfo);
  833. copy(PFilterVelocityScale);
  834. copy(PFilterVelocityScaleFunction);
  835. RCopy(GlobalFilter);
  836. RCopy(FilterEnvelope);
  837. RCopy(FilterLfo);
  838. RCopy(Reson);
  839. }
  840. #undef copy
  841. #undef RCopy
  842. void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice)
  843. {
  844. Enabled = xml->getparbool("enabled", 0);
  845. Unison_size = xml->getpar127("unison_size", Unison_size);
  846. Unison_frequency_spread = xml->getpar127("unison_frequency_spread",
  847. Unison_frequency_spread);
  848. Unison_stereo_spread = xml->getpar127("unison_stereo_spread",
  849. Unison_stereo_spread);
  850. Unison_vibratto = xml->getpar127("unison_vibratto", Unison_vibratto);
  851. Unison_vibratto_speed = xml->getpar127("unison_vibratto_speed",
  852. Unison_vibratto_speed);
  853. Unison_invert_phase = xml->getpar127("unison_invert_phase",
  854. Unison_invert_phase);
  855. Unison_phase_randomness = xml->getpar127("unison_phase_randomness",
  856. Unison_phase_randomness);
  857. Type = xml->getpar127("type", Type);
  858. PDelay = xml->getpar127("delay", PDelay);
  859. Presonance = xml->getparbool("resonance", Presonance);
  860. Pextoscil = xml->getpar("ext_oscil", -1, -1, nvoice - 1);
  861. PextFMoscil = xml->getpar("ext_fm_oscil", -1, -1, nvoice - 1);
  862. Poscilphase = xml->getpar127("oscil_phase", Poscilphase);
  863. PFMoscilphase = xml->getpar127("oscil_fm_phase", PFMoscilphase);
  864. PFilterEnabled = xml->getparbool("filter_enabled", PFilterEnabled);
  865. Pfilterbypass = xml->getparbool("filter_bypass", Pfilterbypass);
  866. PFMEnabled = xml->getpar127("fm_enabled", PFMEnabled);
  867. if(xml->enterbranch("OSCIL")) {
  868. OscilSmp->getfromXML(xml);
  869. xml->exitbranch();
  870. }
  871. if(xml->enterbranch("AMPLITUDE_PARAMETERS")) {
  872. PPanning = xml->getpar127("panning", PPanning);
  873. PVolume = xml->getpar127("volume", PVolume);
  874. PVolumeminus = xml->getparbool("volume_minus", PVolumeminus);
  875. PAmpVelocityScaleFunction = xml->getpar127("velocity_sensing",
  876. PAmpVelocityScaleFunction);
  877. PAmpEnvelopeEnabled = xml->getparbool("amp_envelope_enabled",
  878. PAmpEnvelopeEnabled);
  879. if(xml->enterbranch("AMPLITUDE_ENVELOPE")) {
  880. AmpEnvelope->getfromXML(xml);
  881. xml->exitbranch();
  882. }
  883. PAmpLfoEnabled = xml->getparbool("amp_lfo_enabled", PAmpLfoEnabled);
  884. if(xml->enterbranch("AMPLITUDE_LFO")) {
  885. AmpLfo->getfromXML(xml);
  886. xml->exitbranch();
  887. }
  888. xml->exitbranch();
  889. }
  890. if(xml->enterbranch("FREQUENCY_PARAMETERS")) {
  891. Pfixedfreq = xml->getparbool("fixed_freq", Pfixedfreq);
  892. PfixedfreqET = xml->getpar127("fixed_freq_et", PfixedfreqET);
  893. PDetune = xml->getpar("detune", PDetune, 0, 16383);
  894. PCoarseDetune = xml->getpar("coarse_detune", PCoarseDetune, 0, 16383);
  895. PDetuneType = xml->getpar127("detune_type", PDetuneType);
  896. PFreqEnvelopeEnabled = xml->getparbool("freq_envelope_enabled",
  897. PFreqEnvelopeEnabled);
  898. if(xml->enterbranch("FREQUENCY_ENVELOPE")) {
  899. FreqEnvelope->getfromXML(xml);
  900. xml->exitbranch();
  901. }
  902. PFreqLfoEnabled = xml->getparbool("freq_lfo_enabled", PFreqLfoEnabled);
  903. if(xml->enterbranch("FREQUENCY_LFO")) {
  904. FreqLfo->getfromXML(xml);
  905. xml->exitbranch();
  906. }
  907. xml->exitbranch();
  908. }
  909. if(xml->enterbranch("FILTER_PARAMETERS")) {
  910. if(xml->enterbranch("FILTER")) {
  911. VoiceFilter->getfromXML(xml);
  912. xml->exitbranch();
  913. }
  914. PFilterEnvelopeEnabled = xml->getparbool("filter_envelope_enabled",
  915. PFilterEnvelopeEnabled);
  916. if(xml->enterbranch("FILTER_ENVELOPE")) {
  917. FilterEnvelope->getfromXML(xml);
  918. xml->exitbranch();
  919. }
  920. PFilterLfoEnabled = xml->getparbool("filter_lfo_enabled",
  921. PFilterLfoEnabled);
  922. if(xml->enterbranch("FILTER_LFO")) {
  923. FilterLfo->getfromXML(xml);
  924. xml->exitbranch();
  925. }
  926. xml->exitbranch();
  927. }
  928. if(xml->enterbranch("FM_PARAMETERS")) {
  929. PFMVoice = xml->getpar("input_voice", PFMVoice, -1, nvoice - 1);
  930. PFMVolume = xml->getpar127("volume", PFMVolume);
  931. PFMVolumeDamp = xml->getpar127("volume_damp", PFMVolumeDamp);
  932. PFMVelocityScaleFunction = xml->getpar127("velocity_sensing",
  933. PFMVelocityScaleFunction);
  934. PFMAmpEnvelopeEnabled = xml->getparbool("amp_envelope_enabled",
  935. PFMAmpEnvelopeEnabled);
  936. if(xml->enterbranch("AMPLITUDE_ENVELOPE")) {
  937. FMAmpEnvelope->getfromXML(xml);
  938. xml->exitbranch();
  939. }
  940. if(xml->enterbranch("MODULATOR")) {
  941. PFMDetune = xml->getpar("detune", PFMDetune, 0, 16383);
  942. PFMCoarseDetune = xml->getpar("coarse_detune",
  943. PFMCoarseDetune,
  944. 0,
  945. 16383);
  946. PFMDetuneType = xml->getpar127("detune_type", PFMDetuneType);
  947. PFMFreqEnvelopeEnabled = xml->getparbool("freq_envelope_enabled",
  948. PFMFreqEnvelopeEnabled);
  949. if(xml->enterbranch("FREQUENCY_ENVELOPE")) {
  950. FMFreqEnvelope->getfromXML(xml);
  951. xml->exitbranch();
  952. }
  953. if(xml->enterbranch("OSCIL")) {
  954. FMSmp->getfromXML(xml);
  955. xml->exitbranch();
  956. }
  957. xml->exitbranch();
  958. }
  959. xml->exitbranch();
  960. }
  961. }