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.

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