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.

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