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.

1191 lines
37KB

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