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.

1178 lines
36KB

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