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.

1240 lines
40KB

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