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.

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