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.

1307 lines
43KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. PADnoteParameters.cpp - Parameters for PADnote (PADsynth)
  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
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #include <limits>
  12. #include <cmath>
  13. #include "PADnoteParameters.h"
  14. #include "FilterParams.h"
  15. #include "EnvelopeParams.h"
  16. #include "LFOParams.h"
  17. #include "../Synth/Resonance.h"
  18. #include "../Synth/OscilGen.h"
  19. #include "../Misc/WavFile.h"
  20. #include "../Misc/Time.h"
  21. #include <cstdio>
  22. #include <thread>
  23. #include <rtosc/ports.h>
  24. #include <rtosc/port-sugar.h>
  25. using namespace rtosc;
  26. namespace zyncarla {
  27. #define rObject PADnoteParameters
  28. #undef rChangeCb
  29. #define rChangeCb if (obj->time) { obj->last_update_timestamp = obj->time->time(); }
  30. static const rtosc::Ports realtime_ports =
  31. {
  32. rRecurp(FreqLfo, "Frequency LFO"),
  33. rRecurp(AmpLfo, "Amplitude LFO"),
  34. rRecurp(FilterLfo, "Filter LFO"),
  35. rRecurp(FreqEnvelope, "Frequency Envelope"),
  36. rRecurp(AmpEnvelope, "Amplitude Envelope"),
  37. rRecurp(FilterEnvelope, "Filter Envelope"),
  38. rRecurp(GlobalFilter, "Post Filter"),
  39. //Volume
  40. rToggle(PStereo, rShort("stereo"), rDefault(true), "Stereo/Mono Mode"),
  41. rParamZyn(PPanning, rShort("panning"), rDefault(64), "Left Right Panning"),
  42. rParamZyn(PVolume, rShort("vol"), rDefault(90), "Synth Volume"),
  43. rParamZyn(PAmpVelocityScaleFunction, rShort("sense"), rDefault(64),
  44. "Amplitude Velocity Sensing function"),
  45. rParamZyn(Fadein_adjustment, rShort("a.pop."),
  46. rDefault(FADEIN_ADJUSTMENT_SCALE), "Adjustment for anti-pop strategy."),
  47. //Punch
  48. rParamZyn(PPunchStrength, rShort("strength"), rDefault(0),
  49. "Punch Strength"),
  50. rParamZyn(PPunchTime, rShort("time"), rDefault(60),
  51. "Length of punch"),
  52. rParamZyn(PPunchStretch, rShort("stretch"), rDefault(64),
  53. "How Punch changes with note frequency"),
  54. rParamZyn(PPunchVelocitySensing, rShort("sense"), rDefault(72),
  55. "Punch Velocity control"),
  56. //Filter
  57. rParamZyn(PFilterVelocityScale, rShort("scale"), rDefault(64),
  58. "Filter Velocity Magnitude"),
  59. rParamZyn(PFilterVelocityScaleFunction, rShort("sense"), rDefault(64),
  60. "Filter Velocity Function Shape"),
  61. //Freq
  62. rToggle(Pfixedfreq, rShort("fixed"), rDefault(false),
  63. "Base frequency fixed frequency enable"),
  64. rParamZyn(PfixedfreqET, rShort("f.ET"), rDefault(0),
  65. "Equal temeperate control for fixed frequency operation"),
  66. rParamZyn(PBendAdjust, rDefault(88),
  67. "Pitch bend adjustment"),
  68. rParamZyn(POffsetHz, rShort("offset"), rDefault(64),
  69. "Voice constant offset"),
  70. rParamI(PDetune, rShort("fine"), rLinear(0, 16383), rDefault(8192),
  71. "Fine Detune"),
  72. rParamI(PCoarseDetune, rShort("coarse"), rDefault(0), "Coarse Detune"),
  73. rParamZyn(PDetuneType, rShort("type"),
  74. rOptions(L35cents, L10cents, E100cents, E1200cents),
  75. rDefault(L10cents), "Magnitude of Detune"),
  76. {"sample#64:ifb", rProp(internal) rDoc("Nothing to see here"), 0,
  77. [](const char *m, rtosc::RtData &d)
  78. {
  79. PADnoteParameters *p = (PADnoteParameters*)d.obj;
  80. const char *mm = m;
  81. while(!isdigit(*mm))++mm;
  82. unsigned n = atoi(mm);
  83. p->sample[n].size = rtosc_argument(m,0).i;
  84. p->sample[n].basefreq = rtosc_argument(m,1).f;
  85. p->sample[n].smp = *(float**)rtosc_argument(m,2).b.data;
  86. //XXX TODO memory managment (deallocation of smp buffer)
  87. }},
  88. //weird stuff for PCoarseDetune
  89. {"detunevalue:", rMap(unit,cents) rDoc("Get detune value"), NULL,
  90. [](const char *, RtData &d)
  91. {
  92. PADnoteParameters *obj = (PADnoteParameters *)d.obj;
  93. d.reply(d.loc, "f", getdetune(obj->PDetuneType, 0, obj->PDetune));
  94. }},
  95. {"octave::c:i", rProp(parameter) rShort("octave") rLinear(-8,7)
  96. rDoc("Octave note offset"), NULL,
  97. [](const char *msg, RtData &d)
  98. {
  99. PADnoteParameters *obj = (PADnoteParameters *)d.obj;
  100. if(!rtosc_narguments(msg)) {
  101. int k=obj->PCoarseDetune/1024;
  102. if (k>=8) k-=16;
  103. d.reply(d.loc, "i", k);
  104. } else {
  105. int k=(int) rtosc_argument(msg, 0).i;
  106. if (k<0) k+=16;
  107. obj->PCoarseDetune = k*1024 + obj->PCoarseDetune%1024;
  108. }
  109. }},
  110. {"coarsedetune::c:i", rProp(parameter) rShort("coarse") rLinear(-64, 63)
  111. rDoc("Coarse note detune"), NULL,
  112. [](const char *msg, RtData &d)
  113. {
  114. PADnoteParameters *obj = (PADnoteParameters *)d.obj;
  115. if(!rtosc_narguments(msg)) {
  116. int k=obj->PCoarseDetune%1024;
  117. if (k>=512) k-=1024;
  118. d.reply(d.loc, "i", k);
  119. } else {
  120. int k=(int) rtosc_argument(msg, 0).i;
  121. if (k<0) k+=1024;
  122. obj->PCoarseDetune = k + (obj->PCoarseDetune/1024)*1024;
  123. }
  124. }},
  125. {"paste:b", rProp(internal) rDoc("paste port"), 0,
  126. [](const char *m, rtosc::RtData &d){
  127. rObject &paste = **(rObject **)rtosc_argument(m,0).b.data;
  128. rObject &o = *(rObject*)d.obj;
  129. o.pasteRT(paste);}}
  130. };
  131. static const rtosc::Ports non_realtime_ports =
  132. {
  133. rSelf(PADnoteParameters),
  134. rPresetType,
  135. {"paste:b", rProp(internal) rDoc("paste port"), 0,
  136. [](const char *m, rtosc::RtData &d){
  137. rObject &paste = **(rObject **)rtosc_argument(m,0).b.data;
  138. rObject &o = *(rObject*)d.obj;
  139. o.paste(paste);
  140. //avoid the match to forward the request along
  141. d.matches--;}},
  142. //Harmonic Source Distribution
  143. rRecurp(oscilgen, "Oscillator"),
  144. rRecurp(resonance, "Resonance"),
  145. //Harmonic Shape
  146. rOption(Pmode, rMap(min, 0), rMap(max, 2), rShort("distribution"),
  147. rOptions(bandwidth,discrete,continious),
  148. rDefault(bandwidth),
  149. "Harmonic Distribution Model"),
  150. rOption(Php.base.type, rOptions(Gaussian, Rectanglar, Double Exponential),
  151. rShort("shape"), rDefault(Gaussian),
  152. "Harmonic profile shape"),
  153. rParamZyn(Php.base.par1, rShort("warp"), rDefault(80),
  154. "Harmonic shape distribution parameter"),
  155. rParamZyn(Php.freqmult, rShort("clone"), rDefault(0),
  156. "Frequency multiplier on distribution"),
  157. rParamZyn(Php.modulator.par1, rShort("p1"), rDefault(0),
  158. "Distribution modulator parameter"),
  159. rParamZyn(Php.modulator.freq, rShort("freq"), rDefault(30),
  160. "Frequency of modulator parameter"),
  161. rParamZyn(Php.width, rShort("bandwidth"), rDefault(127),
  162. "Width of base harmonic"),
  163. rOption(Php.amp.mode, rShort("mode"),
  164. rOptions(Sum, Mult, Div1, Div2), rDefault(Sum),
  165. "Amplitude harmonic multiplier type"),
  166. //Harmonic Modulation
  167. rOption(Php.amp.type, rShort("mult"), rOptions(Off, Gauss, Sine, Flat),
  168. rDefault(Off), "Type of amplitude multipler"),
  169. rParamZyn(Php.amp.par1, rShort("p1"), rDefault(80),
  170. "Amplitude multiplier parameter"),
  171. rParamZyn(Php.amp.par2, rShort("p2"), rDefault(60),
  172. "Amplitude multiplier parameter"),
  173. rToggle(Php.autoscale, rShort("auto"), rDefault(true),
  174. "Autoscaling Harmonics"),
  175. rOption(Php.onehalf, rShort("side"),
  176. rOptions(Full, Upper Half, Lower Half), rDefault(Full)
  177. "Harmonic cutoff model"),
  178. //Harmonic Bandwidth
  179. rOption(Pbwscale, rShort("bw scale"),
  180. rOptions(Normal,
  181. EqualHz, Quarter,
  182. Half, 75%, 150%,
  183. Double, Inv. Half),
  184. rDefault(Normal),
  185. "Bandwidth scaling"),
  186. //Harmonic Position Modulation
  187. rOption(Phrpos.type,
  188. rOptions(Harmonic, ShiftU, ShiftL, PowerU, PowerL, Sine,
  189. Power, Shift),
  190. rDefault(Harmonic)
  191. "Harmonic Overtone shifting mode"),
  192. rParamI(Phrpos.par1, rShort("p1"), rLinear(0,255), rDefault(0),
  193. "Harmonic position parameter"),
  194. rParamI(Phrpos.par2, rShort("p2"), rLinear(0,255), rDefault(0),
  195. "Harmonic position parameter"),
  196. rParamI(Phrpos.par3, rShort("force h."), rLinear(0,255), rDefault(0),
  197. "Harmonic position parameter"),
  198. //Quality
  199. rOption(Pquality.samplesize, rShort("quality"),
  200. rOptions(16k (Tiny), 32k, 64k (Small), 128k,
  201. 256k (Normal), 512k, 1M (Big)),
  202. rDefaultId(128k),
  203. "Size of each wavetable element"),
  204. rOption(Pquality.basenote, rShort("basenote"),
  205. rOptions(C-2, G-2, C-3, G-3, C-4,
  206. G-4, C-5, G-5, G-6,),
  207. rDefaultId(C-4),
  208. "Base note for wavetable"),
  209. rOption(Pquality.smpoct, rShort("smp/oct"),
  210. rOptions(0.5, 1, 2, 3, 4, 6, 12),
  211. rDefault(2),
  212. "Samples per octave"),
  213. rParamI(Pquality.oct, rShort("octaves"), rLinear(0,7), rDefault(3),
  214. "Number of octaves to sample (above the first sample"),
  215. {"Pbandwidth::i", rShort("bandwidth") rProp(parameter) rLinear(0,1000) rDoc("Bandwith Of Harmonics"), NULL,
  216. [](const char *msg, rtosc::RtData &d) {
  217. PADnoteParameters *p = ((PADnoteParameters*)d.obj);
  218. if(rtosc_narguments(msg)) {
  219. p->setPbandwidth(rtosc_argument(msg, 0).i);
  220. } else {
  221. d.reply(d.loc, "i", p->Pbandwidth);
  222. }}},
  223. {"bandwidthvalue:", rMap(unit, cents) rDoc("Get Bandwidth"), NULL,
  224. [](const char *, rtosc::RtData &d) {
  225. PADnoteParameters *p = ((PADnoteParameters*)d.obj);
  226. d.reply(d.loc, "f", p->setPbandwidth(p->Pbandwidth));
  227. }},
  228. {"nhr:", rProp(non-realtime) rDoc("Returns the harmonic shifts"),
  229. NULL, [](const char *, rtosc::RtData &d) {
  230. PADnoteParameters *p = ((PADnoteParameters*)d.obj);
  231. const unsigned n = p->synth.oscilsize / 2;
  232. float *tmp = new float[n];
  233. *tmp = 0;
  234. for(unsigned i=1; i<n; ++i)
  235. tmp[i] = p->getNhr(i);
  236. d.reply(d.loc, "b", n*sizeof(float), tmp);
  237. delete[] tmp;}},
  238. {"profile:i", rProp(non-realtime) rDoc("UI display of the harmonic profile"),
  239. NULL, [](const char *m, rtosc::RtData &d) {
  240. PADnoteParameters *p = ((PADnoteParameters*)d.obj);
  241. const int n = rtosc_argument(m, 0).i;
  242. if(n<=0)
  243. return;
  244. float *tmp = new float[n];
  245. float realbw = p->getprofile(tmp, n);
  246. d.reply(d.loc, "b", n*sizeof(float), tmp);
  247. d.reply(d.loc, "i", (int)realbw);
  248. delete[] tmp;}},
  249. {"harmonic_profile:", rProp(non-realtime) rDoc("UI display of the harmonic profile"),
  250. NULL, [](const char *m, rtosc::RtData &d) {
  251. PADnoteParameters *p = ((PADnoteParameters*)d.obj);
  252. #define RES 512
  253. char types[RES+2] = {0};
  254. rtosc_arg_t args[RES+1];
  255. float tmp[RES];
  256. types[0] = 'f';
  257. args[0].f = p->getprofile(tmp, RES);
  258. for(int i=0; i<RES; ++i) {
  259. types[i+1] = 'f';
  260. args[i+1].f = tmp[i];
  261. }
  262. d.replyArray(d.loc, types, args);
  263. #undef RES
  264. }},
  265. {"needPrepare:", rDoc("Unimplemented Stub"),
  266. NULL, [](const char *, rtosc::RtData&) {}},
  267. };
  268. #undef rChangeCb
  269. const rtosc::Ports &PADnoteParameters::non_realtime_ports = zyncarla::non_realtime_ports;
  270. const rtosc::Ports &PADnoteParameters::realtime_ports = zyncarla::realtime_ports;
  271. const rtosc::MergePorts PADnoteParameters::ports =
  272. {
  273. &realtime_ports,
  274. &non_realtime_ports
  275. };
  276. PADnoteParameters::PADnoteParameters(const SYNTH_T &synth_, FFTwrapper *fft_,
  277. const AbsTime *time_)
  278. : Presets(), time(time_), last_update_timestamp(0), synth(synth_)
  279. {
  280. setpresettype("Ppadsynth");
  281. resonance = new Resonance();
  282. oscilgen = new OscilGen(synth, fft_, resonance);
  283. oscilgen->ADvsPAD = true;
  284. FreqEnvelope = new EnvelopeParams(0, 0, time_);
  285. FreqEnvelope->init(EnvelopeParams::ad_global_freq_env);
  286. FreqLfo = new LFOParams(70, 0, 64, 0, 0, 0, 0, 0, time_);
  287. AmpEnvelope = new EnvelopeParams(64, 1, time_);
  288. AmpEnvelope->init(EnvelopeParams::ad_global_amp_env);
  289. AmpLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 1, time_);
  290. GlobalFilter = new FilterParams(2, 94, 40, time_);
  291. FilterEnvelope = new EnvelopeParams(0, 1, time_);
  292. FilterEnvelope->init(EnvelopeParams::ad_global_filter_env);
  293. FilterLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 2, time_);
  294. for(int i = 0; i < PAD_MAX_SAMPLES; ++i)
  295. sample[i].smp = NULL;
  296. defaults();
  297. }
  298. PADnoteParameters::~PADnoteParameters()
  299. {
  300. deletesamples();
  301. delete (oscilgen);
  302. delete (resonance);
  303. delete (FreqEnvelope);
  304. delete (FreqLfo);
  305. delete (AmpEnvelope);
  306. delete (AmpLfo);
  307. delete (GlobalFilter);
  308. delete (FilterEnvelope);
  309. delete (FilterLfo);
  310. }
  311. void PADnoteParameters::defaults()
  312. {
  313. Pmode = 0;
  314. Php.base.type = 0;
  315. Php.base.par1 = 80;
  316. Php.freqmult = 0;
  317. Php.modulator.par1 = 0;
  318. Php.modulator.freq = 30;
  319. Php.width = 127;
  320. Php.amp.type = 0;
  321. Php.amp.mode = 0;
  322. Php.amp.par1 = 80;
  323. Php.amp.par2 = 64;
  324. Php.autoscale = true;
  325. Php.onehalf = 0;
  326. setPbandwidth(500);
  327. Pbwscale = 0;
  328. resonance->defaults();
  329. oscilgen->defaults();
  330. Phrpos.type = 0;
  331. Phrpos.par1 = 0;
  332. Phrpos.par2 = 0;
  333. Phrpos.par3 = 0;
  334. Pquality.samplesize = 3;
  335. Pquality.basenote = 4;
  336. Pquality.oct = 3;
  337. Pquality.smpoct = 2;
  338. PStereo = 1; //stereo
  339. /* Frequency Global Parameters */
  340. Pfixedfreq = 0;
  341. PfixedfreqET = 0;
  342. PBendAdjust = 88; // 64 + 24
  343. POffsetHz = 64;
  344. PDetune = 8192; //zero
  345. PCoarseDetune = 0;
  346. PDetuneType = 1;
  347. FreqEnvelope->defaults();
  348. FreqLfo->defaults();
  349. /* Amplitude Global Parameters */
  350. PVolume = 90;
  351. PPanning = 64; //center
  352. PAmpVelocityScaleFunction = 64;
  353. AmpEnvelope->defaults();
  354. AmpLfo->defaults();
  355. Fadein_adjustment = FADEIN_ADJUSTMENT_SCALE;
  356. PPunchStrength = 0;
  357. PPunchTime = 60;
  358. PPunchStretch = 64;
  359. PPunchVelocitySensing = 72;
  360. /* Filter Global Parameters*/
  361. PFilterVelocityScale = 64;
  362. PFilterVelocityScaleFunction = 64;
  363. GlobalFilter->defaults();
  364. FilterEnvelope->defaults();
  365. FilterLfo->defaults();
  366. deletesamples();
  367. }
  368. void PADnoteParameters::deletesample(int n)
  369. {
  370. if((n < 0) || (n >= PAD_MAX_SAMPLES))
  371. return;
  372. delete[] sample[n].smp;
  373. sample[n].smp = NULL;
  374. sample[n].size = 0;
  375. sample[n].basefreq = 440.0f;
  376. }
  377. void PADnoteParameters::deletesamples()
  378. {
  379. for(int i = 0; i < PAD_MAX_SAMPLES; ++i)
  380. deletesample(i);
  381. }
  382. /*
  383. * Get the harmonic profile (i.e. the frequency distributio of a single harmonic)
  384. */
  385. float PADnoteParameters::getprofile(float *smp, int size)
  386. {
  387. for(int i = 0; i < size; ++i)
  388. smp[i] = 0.0f;
  389. const int supersample = 16;
  390. float basepar = powf(2.0f, (1.0f - Php.base.par1 / 127.0f) * 12.0f);
  391. float freqmult = floor(powf(2.0f,
  392. Php.freqmult / 127.0f
  393. * 5.0f) + 0.000001f);
  394. float modfreq = floor(powf(2.0f,
  395. Php.modulator.freq / 127.0f
  396. * 5.0f) + 0.000001f);
  397. float modpar1 = powf(Php.modulator.par1 / 127.0f, 4.0f) * 5.0f / sqrt(
  398. modfreq);
  399. float amppar1 =
  400. powf(2.0f, powf(Php.amp.par1 / 127.0f, 2.0f) * 10.0f) - 0.999f;
  401. float amppar2 = (1.0f - Php.amp.par2 / 127.0f) * 0.998f + 0.001f;
  402. float width = powf(150.0f / (Php.width + 22.0f), 2.0f);
  403. for(int i = 0; i < size * supersample; ++i) {
  404. bool makezero = false;
  405. float x = i * 1.0f / (size * (float) supersample);
  406. float origx = x;
  407. //do the sizing (width)
  408. x = (x - 0.5f) * width + 0.5f;
  409. if(x < 0.0f) {
  410. x = 0.0f;
  411. makezero = true;
  412. }
  413. else
  414. if(x > 1.0f) {
  415. x = 1.0f;
  416. makezero = true;
  417. }
  418. //compute the full profile or one half
  419. switch(Php.onehalf) {
  420. case 1:
  421. x = x * 0.5f + 0.5f;
  422. break;
  423. case 2:
  424. x = x * 0.5f;
  425. break;
  426. }
  427. float x_before_freq_mult = x;
  428. //do the frequency multiplier
  429. x *= freqmult;
  430. //do the modulation of the profile
  431. x += sinf(x_before_freq_mult * 3.1415926f * modfreq) * modpar1;
  432. x = fmod(x + 1000.0f, 1.0f) * 2.0f - 1.0f;
  433. //this is the base function of the profile
  434. float f;
  435. switch(Php.base.type) {
  436. case 1:
  437. f = expf(-(x * x) * basepar);
  438. if(f < 0.4f)
  439. f = 0.0f;
  440. else
  441. f = 1.0f;
  442. break;
  443. case 2:
  444. f = expf(-(fabs(x)) * sqrt(basepar));
  445. break;
  446. default:
  447. f = expf(-(x * x) * basepar);
  448. break;
  449. }
  450. if(makezero)
  451. f = 0.0f;
  452. float amp = 1.0f;
  453. origx = origx * 2.0f - 1.0f;
  454. //compute the amplitude multiplier
  455. switch(Php.amp.type) {
  456. case 1:
  457. amp = expf(-(origx * origx) * 10.0f * amppar1);
  458. break;
  459. case 2:
  460. amp = 0.5f
  461. * (1.0f
  462. + cosf(3.1415926f * origx * sqrt(amppar1 * 4.0f + 1.0f)));
  463. break;
  464. case 3:
  465. amp = 1.0f
  466. / (powf(origx * (amppar1 * 2.0f + 0.8f), 14.0f) + 1.0f);
  467. break;
  468. }
  469. //apply the amplitude multiplier
  470. float finalsmp = f;
  471. if(Php.amp.type != 0)
  472. switch(Php.amp.mode) {
  473. case 0:
  474. finalsmp = amp * (1.0f - amppar2) + finalsmp * amppar2;
  475. break;
  476. case 1:
  477. finalsmp *= amp * (1.0f - amppar2) + amppar2;
  478. break;
  479. case 2:
  480. finalsmp = finalsmp
  481. / (amp + powf(amppar2, 4.0f) * 20.0f + 0.0001f);
  482. break;
  483. case 3:
  484. finalsmp = amp
  485. / (finalsmp
  486. + powf(amppar2, 4.0f) * 20.0f + 0.0001f);
  487. break;
  488. }
  489. ;
  490. smp[i / supersample] += finalsmp / supersample;
  491. }
  492. //normalize the profile (make the max. to be equal to 1.0f)
  493. float max = 0.0f;
  494. for(int i = 0; i < size; ++i) {
  495. if(smp[i] < 0.0f)
  496. smp[i] = 0.0f;
  497. if(smp[i] > max)
  498. max = smp[i];
  499. }
  500. if(max < 0.00001f)
  501. max = 1.0f;
  502. for(int i = 0; i < size; ++i)
  503. smp[i] /= max;
  504. if(!Php.autoscale)
  505. return 0.5f;
  506. //compute the estimated perceived bandwidth
  507. float sum = 0.0f;
  508. int i;
  509. for(i = 0; i < size / 2 - 2; ++i) {
  510. sum += smp[i] * smp[i] + smp[size - i - 1] * smp[size - i - 1];
  511. if(sum >= 4.0f)
  512. break;
  513. }
  514. float result = 1.0f - 2.0f * i / (float) size;
  515. return result;
  516. }
  517. /*
  518. * Compute the real bandwidth in cents and returns it
  519. * Also, sets the bandwidth parameter
  520. */
  521. float PADnoteParameters::setPbandwidth(int Pbandwidth)
  522. {
  523. this->Pbandwidth = Pbandwidth;
  524. float result = powf(Pbandwidth / 1000.0f, 1.1f);
  525. result = powf(10.0f, result * 4.0f) * 0.25f;
  526. return result;
  527. }
  528. /*
  529. * Get the harmonic(overtone) position
  530. */
  531. float PADnoteParameters::getNhr(int n) const
  532. {
  533. float result = 1.0f;
  534. const float par1 = powf(10.0f, -(1.0f - Phrpos.par1 / 255.0f) * 3.0f);
  535. const float par2 = Phrpos.par2 / 255.0f;
  536. const float n0 = n - 1.0f;
  537. float tmp = 0.0f;
  538. int thresh = 0;
  539. switch(Phrpos.type) {
  540. case 1:
  541. thresh = (int)(par2 * par2 * 100.0f) + 1;
  542. if(n < thresh)
  543. result = n;
  544. else
  545. result = 1.0f + n0 + (n0 - thresh + 1.0f) * par1 * 8.0f;
  546. break;
  547. case 2:
  548. thresh = (int)(par2 * par2 * 100.0f) + 1;
  549. if(n < thresh)
  550. result = n;
  551. else
  552. result = 1.0f + n0 - (n0 - thresh + 1.0f) * par1 * 0.90f;
  553. break;
  554. case 3:
  555. tmp = par1 * 100.0f + 1.0f;
  556. result = powf(n0 / tmp, 1.0f - par2 * 0.8f) * tmp + 1.0f;
  557. break;
  558. case 4:
  559. result = n0
  560. * (1.0f
  561. - par1)
  562. + powf(n0 * 0.1f, par2 * 3.0f
  563. + 1.0f) * par1 * 10.0f + 1.0f;
  564. break;
  565. case 5:
  566. result = n0
  567. + sinf(n0 * par2 * par2 * PI
  568. * 0.999f) * sqrt(par1) * 2.0f + 1.0f;
  569. break;
  570. case 6:
  571. tmp = powf(par2 * 2.0f, 2.0f) + 0.1f;
  572. result = n0 * powf(1.0f + par1 * powf(n0 * 0.8f, tmp), tmp) + 1.0f;
  573. break;
  574. case 7:
  575. result = (n + Phrpos.par1 / 255.0f) / (Phrpos.par1 / 255.0f + 1);
  576. break;
  577. default:
  578. result = n;
  579. break;
  580. }
  581. const float par3 = Phrpos.par3 / 255.0f;
  582. const float iresult = floor(result + 0.5f);
  583. const float dresult = result - iresult;
  584. return iresult + (1.0f - par3) * dresult;
  585. }
  586. //Transform non zero positive signals into ones with a max of one
  587. static void normalize_max(float *f, size_t len)
  588. {
  589. float max = 0.0f;
  590. for(unsigned i = 0; i < len; ++i)
  591. if(f[i] > i)
  592. max = f[i];
  593. if(max > 0.000001f)
  594. for(unsigned i = 0; i < len; ++i)
  595. f[i] /= max;
  596. }
  597. //Translate Bandwidth scale integer into floating point value
  598. static float Pbwscale_translate(char Pbwscale)
  599. {
  600. switch(Pbwscale) {
  601. case 0: return 1.0f;
  602. case 1: return 0.0f;
  603. case 2: return 0.25f;
  604. case 3: return 0.5f;
  605. case 4: return 0.75f;
  606. case 5: return 1.5f;
  607. case 6: return 2.0f;
  608. case 7: return -0.5f;
  609. default: return 1.0;
  610. }
  611. }
  612. /*
  613. * Generates the long spectrum for Bandwidth mode (only amplitudes are generated; phases will be random)
  614. */
  615. //Requires
  616. // - bandwidth scaling power
  617. // - bandwidth
  618. // - oscilator harmonics at various frequences (oodles of data)
  619. // - sampled resonance
  620. void PADnoteParameters::generatespectrum_bandwidthMode(float *spectrum,
  621. int size,
  622. float basefreq,
  623. const float *profile,
  624. int profilesize,
  625. float bwadjust) const
  626. {
  627. float harmonics[synth.oscilsize];
  628. memset(spectrum, 0, sizeof(float) * size);
  629. memset(harmonics, 0, sizeof(float) * synth.oscilsize);
  630. //get the harmonic structure from the oscillator (I am using the frequency amplitudes, only)
  631. oscilgen->get(harmonics, basefreq, false);
  632. //normalize
  633. normalize_max(harmonics, synth.oscilsize / 2);
  634. //Constants across harmonics
  635. const float power = Pbwscale_translate(Pbwscale);
  636. const float bandwidthcents = const_cast<PADnoteParameters*>(this)->setPbandwidth(Pbandwidth);
  637. for(int nh = 1; nh < synth.oscilsize / 2; ++nh) { //for each harmonic
  638. const float realfreq = getNhr(nh) * basefreq;
  639. if(realfreq > synth.samplerate_f * 0.49999f)
  640. break;
  641. if(realfreq < 20.0f)
  642. break;
  643. if(harmonics[nh - 1] < 1e-4)
  644. continue;
  645. //compute the bandwidth of each harmonic
  646. const float bw =
  647. ((powf(2.0f, bandwidthcents / 1200.0f) - 1.0f) * basefreq / bwadjust)
  648. * powf(realfreq / basefreq, power);
  649. const int ibw = (int)((bw / (synth.samplerate_f * 0.5f) * size)) + 1;
  650. float amp = harmonics[nh - 1];
  651. if(resonance->Penabled)
  652. amp *= resonance->getfreqresponse(realfreq);
  653. if(ibw > profilesize) { //if the bandwidth is larger than the profilesize
  654. const float rap = sqrt((float)profilesize / (float)ibw);
  655. const int cfreq =
  656. (int) (realfreq
  657. / (synth.samplerate_f * 0.5f) * size) - ibw / 2;
  658. for(int i = 0; i < ibw; ++i) {
  659. const int src = i * rap * rap;
  660. const int spfreq = i + cfreq;
  661. if(spfreq < 0)
  662. continue;
  663. if(spfreq >= size)
  664. break;
  665. spectrum[spfreq] += amp * profile[src] * rap;
  666. }
  667. }
  668. else { //if the bandwidth is smaller than the profilesize
  669. const float rap = sqrt((float)ibw / (float)profilesize);
  670. const float ibasefreq = realfreq / (synth.samplerate_f * 0.5f) * size;
  671. for(int i = 0; i < profilesize; ++i) {
  672. const float idfreq = (i / (float)profilesize - 0.5f) * ibw;
  673. const float freqsum = idfreq + ibasefreq;
  674. const int spfreq = (int)freqsum;
  675. const float fspfreq = freqsum - spfreq;
  676. if(spfreq <= 0)
  677. continue;
  678. if(spfreq >= size - 1)
  679. break;
  680. spectrum[spfreq] += amp * profile[i] * rap
  681. * (1.0f - fspfreq);
  682. spectrum[spfreq + 1] += amp * profile[i] * rap * fspfreq;
  683. }
  684. }
  685. }
  686. }
  687. /*
  688. * Generates the long spectrum for non-Bandwidth modes (only amplitudes are generated; phases will be random)
  689. */
  690. void PADnoteParameters::generatespectrum_otherModes(float *spectrum,
  691. int size,
  692. float basefreq) const
  693. {
  694. float harmonics[synth.oscilsize];
  695. memset(spectrum, 0, sizeof(float) * size);
  696. memset(harmonics, 0, sizeof(float) * synth.oscilsize);
  697. //get the harmonic structure from the oscillator (I am using the frequency amplitudes, only)
  698. oscilgen->get(harmonics, basefreq, false);
  699. //normalize
  700. normalize_max(harmonics, synth.oscilsize / 2);
  701. for(int nh = 1; nh < synth.oscilsize / 2; ++nh) { //for each harmonic
  702. const float realfreq = getNhr(nh) * basefreq;
  703. //take care of interpolation if frequency decreases
  704. if(realfreq > synth.samplerate_f * 0.49999f)
  705. break;
  706. if(realfreq < 20.0f)
  707. break;
  708. float amp = harmonics[nh - 1];
  709. if(resonance->Penabled)
  710. amp *= resonance->getfreqresponse(realfreq);
  711. const int cfreq = realfreq / (synth.samplerate_f * 0.5f) * size;
  712. spectrum[cfreq] = amp + 1e-9;
  713. }
  714. //In continous mode the spectrum gets additional interpolation between the
  715. //spectral peaks
  716. if(Pmode != 1) { //continous mode
  717. int old = 0;
  718. for(int k = 1; k < size; ++k)
  719. if((spectrum[k] > 1e-10) || (k == (size - 1))) {
  720. const int delta = k - old;
  721. const float val1 = spectrum[old];
  722. const float val2 = spectrum[k];
  723. const float idelta = 1.0f / delta;
  724. for(int i = 0; i < delta; ++i) {
  725. const float x = idelta * i;
  726. spectrum[old + i] = val1 * (1.0f - x) + val2 * x;
  727. }
  728. old = k;
  729. }
  730. }
  731. }
  732. /*
  733. * Applies the parameters (i.e. computes all the samples, based on parameters);
  734. */
  735. void PADnoteParameters::applyparameters()
  736. {
  737. applyparameters([]{return false;});
  738. }
  739. void PADnoteParameters::applyparameters(std::function<bool()> do_abort,
  740. unsigned max_threads)
  741. {
  742. if(do_abort())
  743. return;
  744. unsigned num = sampleGenerator([this]
  745. (unsigned N, PADnoteParameters::Sample &smp) {
  746. delete[] sample[N].smp;
  747. sample[N] = smp;
  748. },
  749. do_abort, max_threads);
  750. //Delete remaining unused samples
  751. for(unsigned i = num; i < PAD_MAX_SAMPLES; ++i)
  752. deletesample(i);
  753. }
  754. //Requires
  755. // - Pquality.samplesize
  756. // - Pquality.basenote
  757. // - Pquality.oct
  758. // - Pquality.smpoct
  759. // - spectrum at various frequencies (oodles of data)
  760. int PADnoteParameters::sampleGenerator(PADnoteParameters::callback cb,
  761. std::function<bool()> do_abort,
  762. unsigned max_threads)
  763. {
  764. if(!max_threads)
  765. max_threads = std::numeric_limits<unsigned>::max();
  766. const int samplesize = (((int) 1) << (Pquality.samplesize + 14));
  767. const int spectrumsize = samplesize / 2;
  768. const int profilesize = 512;
  769. float profile[profilesize];
  770. const float bwadjust = getprofile(profile, profilesize);
  771. float basefreq = 65.406f * powf(2.0f, Pquality.basenote / 2);
  772. if(Pquality.basenote % 2 == 1)
  773. basefreq *= 1.5f;
  774. int samplemax = Pquality.oct + 1;
  775. int smpoct = Pquality.smpoct;
  776. if(Pquality.smpoct == 5)
  777. smpoct = 6;
  778. if(Pquality.smpoct == 6)
  779. smpoct = 12;
  780. if(smpoct != 0)
  781. samplemax *= smpoct;
  782. else
  783. samplemax = samplemax / 2 + 1;
  784. if(samplemax == 0)
  785. samplemax = 1;
  786. if(samplemax > PAD_MAX_SAMPLES)
  787. samplemax = PAD_MAX_SAMPLES;
  788. //this is used to compute frequency relation to the base frequency
  789. float adj[samplemax];
  790. for(int nsample = 0; nsample < samplemax; ++nsample)
  791. adj[nsample] = (Pquality.oct + 1.0f) * (float)nsample / samplemax;
  792. const PADnoteParameters* this_c = this;
  793. auto thread_cb = [basefreq, bwadjust, &cb, do_abort,
  794. samplesize, samplemax, spectrumsize,
  795. &adj, &profile, this_c](
  796. unsigned nthreads, unsigned threadno)
  797. {
  798. //prepare a BIG IFFT
  799. FFTwrapper *fft = new FFTwrapper(samplesize);
  800. fft_t *fftfreqs = new fft_t[samplesize / 2];
  801. float *spectrum = new float[spectrumsize];
  802. for(int nsample = 0; nsample < samplemax; ++nsample)
  803. if(nsample % nthreads == threadno)
  804. {
  805. if(do_abort())
  806. break;
  807. const float basefreqadjust =
  808. powf(2.0f, adj[nsample] - adj[samplemax - 1] * 0.5f);
  809. if(this_c->Pmode == 0)
  810. this_c->generatespectrum_bandwidthMode(spectrum,
  811. spectrumsize,
  812. basefreq*basefreqadjust,
  813. profile,
  814. profilesize,
  815. bwadjust);
  816. else
  817. this_c->generatespectrum_otherModes(spectrum, spectrumsize,
  818. basefreq * basefreqadjust);
  819. //the last samples contains the first samples
  820. //(used for linear/cubic interpolation)
  821. const int extra_samples = 5;
  822. PADnoteParameters::Sample newsample;
  823. newsample.smp = new float[samplesize + extra_samples];
  824. newsample.smp[0] = 0.0f;
  825. for(int i = 1; i < spectrumsize; ++i) //randomize the phases
  826. fftfreqs[i] = FFTpolar(spectrum[i], (float)RND * 2 * PI);
  827. //that's all; here is the only ifft for the whole sample;
  828. //no windows are used ;-)
  829. fft->freqs2smps(fftfreqs, newsample.smp);
  830. //normalize(rms)
  831. float rms = 0.0f;
  832. for(int i = 0; i < samplesize; ++i)
  833. rms += newsample.smp[i] * newsample.smp[i];
  834. rms = sqrt(rms);
  835. if(rms < 0.000001f)
  836. rms = 1.0f;
  837. rms *= sqrt(262144.0f / samplesize);//262144=2^18
  838. for(int i = 0; i < samplesize; ++i)
  839. newsample.smp[i] *= 1.0f / rms * 50.0f;
  840. //prepare extra samples used by the linear or cubic interpolation
  841. for(int i = 0; i < extra_samples; ++i)
  842. newsample.smp[i + samplesize] = newsample.smp[i];
  843. //yield new sample
  844. newsample.size = samplesize;
  845. newsample.basefreq = basefreq * basefreqadjust;
  846. cb(nsample, newsample);
  847. }
  848. //Cleanup
  849. delete (fft);
  850. delete[] fftfreqs;
  851. delete[] spectrum;
  852. };
  853. unsigned nthreads = std::min(max_threads,
  854. std::thread::hardware_concurrency());
  855. std::vector<std::thread> threads(nthreads);
  856. for(unsigned i = 0; i < nthreads; ++i)
  857. threads[i] = std::thread(thread_cb, nthreads, i);
  858. for(unsigned i = 0; i < nthreads; ++i)
  859. threads[i].join();
  860. return samplemax;
  861. }
  862. void PADnoteParameters::export2wav(std::string basefilename)
  863. {
  864. applyparameters();
  865. basefilename += "_PADsynth_";
  866. for(int k = 0; k < PAD_MAX_SAMPLES; ++k) {
  867. if(sample[k].smp == NULL)
  868. continue;
  869. char tmpstr[20];
  870. snprintf(tmpstr, 20, "_%02d", k + 1);
  871. std::string filename = basefilename + std::string(tmpstr) + ".wav";
  872. WavFile wav(filename, synth.samplerate, 1);
  873. if(wav.good()) {
  874. int nsmps = sample[k].size;
  875. short int *smps = new short int[nsmps];
  876. for(int i = 0; i < nsmps; ++i)
  877. smps[i] = (short int)(sample[k].smp[i] * 32767.0f);
  878. wav.writeMonoSamples(nsmps, smps);
  879. }
  880. }
  881. }
  882. void PADnoteParameters::add2XML(XMLwrapper& xml)
  883. {
  884. xml.setPadSynth(true);
  885. xml.addparbool("stereo", PStereo);
  886. xml.addpar("mode", Pmode);
  887. xml.addpar("bandwidth", Pbandwidth);
  888. xml.addpar("bandwidth_scale", Pbwscale);
  889. xml.beginbranch("HARMONIC_PROFILE");
  890. xml.addpar("base_type", Php.base.type);
  891. xml.addpar("base_par1", Php.base.par1);
  892. xml.addpar("frequency_multiplier", Php.freqmult);
  893. xml.addpar("modulator_par1", Php.modulator.par1);
  894. xml.addpar("modulator_frequency", Php.modulator.freq);
  895. xml.addpar("width", Php.width);
  896. xml.addpar("amplitude_multiplier_type", Php.amp.type);
  897. xml.addpar("amplitude_multiplier_mode", Php.amp.mode);
  898. xml.addpar("amplitude_multiplier_par1", Php.amp.par1);
  899. xml.addpar("amplitude_multiplier_par2", Php.amp.par2);
  900. xml.addparbool("autoscale", Php.autoscale);
  901. xml.addpar("one_half", Php.onehalf);
  902. xml.endbranch();
  903. xml.beginbranch("OSCIL");
  904. oscilgen->add2XML(xml);
  905. xml.endbranch();
  906. xml.beginbranch("RESONANCE");
  907. resonance->add2XML(xml);
  908. xml.endbranch();
  909. xml.beginbranch("HARMONIC_POSITION");
  910. xml.addpar("type", Phrpos.type);
  911. xml.addpar("parameter1", Phrpos.par1);
  912. xml.addpar("parameter2", Phrpos.par2);
  913. xml.addpar("parameter3", Phrpos.par3);
  914. xml.endbranch();
  915. xml.beginbranch("SAMPLE_QUALITY");
  916. xml.addpar("samplesize", Pquality.samplesize);
  917. xml.addpar("basenote", Pquality.basenote);
  918. xml.addpar("octaves", Pquality.oct);
  919. xml.addpar("samples_per_octave", Pquality.smpoct);
  920. xml.endbranch();
  921. xml.beginbranch("AMPLITUDE_PARAMETERS");
  922. xml.addpar("volume", PVolume);
  923. xml.addpar("panning", PPanning);
  924. xml.addpar("velocity_sensing", PAmpVelocityScaleFunction);
  925. xml.addpar("fadein_adjustment", Fadein_adjustment);
  926. xml.addpar("punch_strength", PPunchStrength);
  927. xml.addpar("punch_time", PPunchTime);
  928. xml.addpar("punch_stretch", PPunchStretch);
  929. xml.addpar("punch_velocity_sensing", PPunchVelocitySensing);
  930. xml.beginbranch("AMPLITUDE_ENVELOPE");
  931. AmpEnvelope->add2XML(xml);
  932. xml.endbranch();
  933. xml.beginbranch("AMPLITUDE_LFO");
  934. AmpLfo->add2XML(xml);
  935. xml.endbranch();
  936. xml.endbranch();
  937. xml.beginbranch("FREQUENCY_PARAMETERS");
  938. xml.addpar("fixed_freq", Pfixedfreq);
  939. xml.addpar("fixed_freq_et", PfixedfreqET);
  940. xml.addpar("bend_adjust", PBendAdjust);
  941. xml.addpar("offset_hz", POffsetHz);
  942. xml.addpar("detune", PDetune);
  943. xml.addpar("coarse_detune", PCoarseDetune);
  944. xml.addpar("detune_type", PDetuneType);
  945. xml.beginbranch("FREQUENCY_ENVELOPE");
  946. FreqEnvelope->add2XML(xml);
  947. xml.endbranch();
  948. xml.beginbranch("FREQUENCY_LFO");
  949. FreqLfo->add2XML(xml);
  950. xml.endbranch();
  951. xml.endbranch();
  952. xml.beginbranch("FILTER_PARAMETERS");
  953. xml.addpar("velocity_sensing_amplitude", PFilterVelocityScale);
  954. xml.addpar("velocity_sensing", PFilterVelocityScaleFunction);
  955. xml.beginbranch("FILTER");
  956. GlobalFilter->add2XML(xml);
  957. xml.endbranch();
  958. xml.beginbranch("FILTER_ENVELOPE");
  959. FilterEnvelope->add2XML(xml);
  960. xml.endbranch();
  961. xml.beginbranch("FILTER_LFO");
  962. FilterLfo->add2XML(xml);
  963. xml.endbranch();
  964. xml.endbranch();
  965. }
  966. void PADnoteParameters::getfromXML(XMLwrapper& xml)
  967. {
  968. PStereo = xml.getparbool("stereo", PStereo);
  969. Pmode = xml.getpar127("mode", 0);
  970. Pbandwidth = xml.getpar("bandwidth", Pbandwidth, 0, 1000);
  971. Pbwscale = xml.getpar127("bandwidth_scale", Pbwscale);
  972. if(xml.enterbranch("HARMONIC_PROFILE")) {
  973. Php.base.type = xml.getpar127("base_type", Php.base.type);
  974. Php.base.par1 = xml.getpar127("base_par1", Php.base.par1);
  975. Php.freqmult = xml.getpar127("frequency_multiplier",
  976. Php.freqmult);
  977. Php.modulator.par1 = xml.getpar127("modulator_par1",
  978. Php.modulator.par1);
  979. Php.modulator.freq = xml.getpar127("modulator_frequency",
  980. Php.modulator.freq);
  981. Php.width = xml.getpar127("width", Php.width);
  982. Php.amp.type = xml.getpar127("amplitude_multiplier_type",
  983. Php.amp.type);
  984. Php.amp.mode = xml.getpar127("amplitude_multiplier_mode",
  985. Php.amp.mode);
  986. Php.amp.par1 = xml.getpar127("amplitude_multiplier_par1",
  987. Php.amp.par1);
  988. Php.amp.par2 = xml.getpar127("amplitude_multiplier_par2",
  989. Php.amp.par2);
  990. Php.autoscale = xml.getparbool("autoscale", Php.autoscale);
  991. Php.onehalf = xml.getpar127("one_half", Php.onehalf);
  992. xml.exitbranch();
  993. }
  994. if(xml.enterbranch("OSCIL")) {
  995. oscilgen->getfromXML(xml);
  996. xml.exitbranch();
  997. }
  998. if(xml.enterbranch("RESONANCE")) {
  999. resonance->getfromXML(xml);
  1000. xml.exitbranch();
  1001. }
  1002. if(xml.enterbranch("HARMONIC_POSITION")) {
  1003. Phrpos.type = xml.getpar127("type", Phrpos.type);
  1004. Phrpos.par1 = xml.getpar("parameter1", Phrpos.par1, 0, 255);
  1005. Phrpos.par2 = xml.getpar("parameter2", Phrpos.par2, 0, 255);
  1006. Phrpos.par3 = xml.getpar("parameter3", Phrpos.par3, 0, 255);
  1007. xml.exitbranch();
  1008. }
  1009. if(xml.enterbranch("SAMPLE_QUALITY")) {
  1010. Pquality.samplesize = xml.getpar127("samplesize", Pquality.samplesize);
  1011. Pquality.basenote = xml.getpar127("basenote", Pquality.basenote);
  1012. Pquality.oct = xml.getpar127("octaves", Pquality.oct);
  1013. Pquality.smpoct = xml.getpar127("samples_per_octave",
  1014. Pquality.smpoct);
  1015. xml.exitbranch();
  1016. }
  1017. if(xml.enterbranch("AMPLITUDE_PARAMETERS")) {
  1018. PVolume = xml.getpar127("volume", PVolume);
  1019. PPanning = xml.getpar127("panning", PPanning);
  1020. PAmpVelocityScaleFunction = xml.getpar127("velocity_sensing",
  1021. PAmpVelocityScaleFunction);
  1022. Fadein_adjustment = xml.getpar127("fadein_adjustment", Fadein_adjustment);
  1023. PPunchStrength = xml.getpar127("punch_strength", PPunchStrength);
  1024. PPunchTime = xml.getpar127("punch_time", PPunchTime);
  1025. PPunchStretch = xml.getpar127("punch_stretch", PPunchStretch);
  1026. PPunchVelocitySensing = xml.getpar127("punch_velocity_sensing",
  1027. PPunchVelocitySensing);
  1028. xml.enterbranch("AMPLITUDE_ENVELOPE");
  1029. AmpEnvelope->getfromXML(xml);
  1030. xml.exitbranch();
  1031. xml.enterbranch("AMPLITUDE_LFO");
  1032. AmpLfo->getfromXML(xml);
  1033. xml.exitbranch();
  1034. xml.exitbranch();
  1035. }
  1036. if(xml.enterbranch("FREQUENCY_PARAMETERS")) {
  1037. Pfixedfreq = xml.getpar127("fixed_freq", Pfixedfreq);
  1038. PfixedfreqET = xml.getpar127("fixed_freq_et", PfixedfreqET);
  1039. PBendAdjust = xml.getpar127("bend_adjust", PBendAdjust);
  1040. POffsetHz = xml.getpar127("offset_hz", POffsetHz);
  1041. PDetune = xml.getpar("detune", PDetune, 0, 16383);
  1042. PCoarseDetune = xml.getpar("coarse_detune", PCoarseDetune, 0, 16383);
  1043. PDetuneType = xml.getpar127("detune_type", PDetuneType);
  1044. xml.enterbranch("FREQUENCY_ENVELOPE");
  1045. FreqEnvelope->getfromXML(xml);
  1046. xml.exitbranch();
  1047. xml.enterbranch("FREQUENCY_LFO");
  1048. FreqLfo->getfromXML(xml);
  1049. xml.exitbranch();
  1050. xml.exitbranch();
  1051. }
  1052. if(xml.enterbranch("FILTER_PARAMETERS")) {
  1053. PFilterVelocityScale = xml.getpar127("velocity_sensing_amplitude",
  1054. PFilterVelocityScale);
  1055. PFilterVelocityScaleFunction = xml.getpar127(
  1056. "velocity_sensing",
  1057. PFilterVelocityScaleFunction);
  1058. xml.enterbranch("FILTER");
  1059. GlobalFilter->getfromXML(xml);
  1060. xml.exitbranch();
  1061. xml.enterbranch("FILTER_ENVELOPE");
  1062. FilterEnvelope->getfromXML(xml);
  1063. xml.exitbranch();
  1064. xml.enterbranch("FILTER_LFO");
  1065. FilterLfo->getfromXML(xml);
  1066. xml.exitbranch();
  1067. xml.exitbranch();
  1068. }
  1069. }
  1070. #define COPY(y) this->y = x.y
  1071. void PADnoteParameters::paste(PADnoteParameters &x)
  1072. {
  1073. COPY(Pmode);
  1074. COPY(Php.base.type);
  1075. COPY(Php.base.par1);
  1076. COPY(Php.freqmult);
  1077. COPY(Php.modulator.par1);
  1078. COPY(Php.modulator.freq);
  1079. COPY(Php.width);
  1080. COPY(Php.amp.mode);
  1081. COPY(Php.amp.type);
  1082. COPY(Php.amp.par1);
  1083. COPY(Php.amp.par2);
  1084. COPY(Php.autoscale);
  1085. COPY(Php.onehalf);
  1086. COPY(Pbandwidth);
  1087. COPY(Pbwscale);
  1088. COPY(Phrpos.type);
  1089. COPY(Phrpos.par1);
  1090. COPY(Phrpos.par2);
  1091. COPY(Phrpos.par3);
  1092. COPY(Pquality.samplesize);
  1093. COPY(Pquality.basenote);
  1094. COPY(Pquality.oct);
  1095. COPY(Pquality.smpoct);
  1096. oscilgen->paste(*x.oscilgen);
  1097. resonance->paste(*x.resonance);
  1098. if ( time ) {
  1099. last_update_timestamp = time->time();
  1100. }
  1101. }
  1102. void PADnoteParameters::pasteRT(PADnoteParameters &x)
  1103. {
  1104. //Realtime stuff
  1105. COPY(Pfixedfreq);
  1106. COPY(PfixedfreqET);
  1107. COPY(PBendAdjust);
  1108. COPY(POffsetHz);
  1109. COPY(PDetune);
  1110. COPY(PCoarseDetune);
  1111. COPY(PDetuneType);
  1112. FreqEnvelope->paste(*x.FreqEnvelope);
  1113. FreqLfo->paste(*x.FreqLfo);
  1114. COPY(PStereo);
  1115. COPY(PPanning);
  1116. COPY(PVolume);
  1117. COPY(PAmpVelocityScaleFunction);
  1118. AmpEnvelope->paste(*x.AmpEnvelope);
  1119. AmpLfo->paste(*x.AmpLfo);
  1120. COPY(Fadein_adjustment);
  1121. COPY(PPunchStrength);
  1122. COPY(PPunchTime);
  1123. COPY(PPunchStretch);
  1124. COPY(PPunchVelocitySensing);
  1125. GlobalFilter->paste(*x.GlobalFilter);
  1126. COPY(PFilterVelocityScale);
  1127. COPY(PFilterVelocityScaleFunction);
  1128. FilterEnvelope->paste(*x.FilterEnvelope);
  1129. FilterLfo->paste(*x.FilterLfo);
  1130. if ( time ) {
  1131. last_update_timestamp = time->time();
  1132. }
  1133. }
  1134. #undef COPY
  1135. }