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.

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