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.

PADnoteParameters.h 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. PADnoteParameters.h - 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. #ifndef PAD_NOTE_PARAMETERS_H
  12. #define PAD_NOTE_PARAMETERS_H
  13. #include "../globals.h"
  14. #include "Presets.h"
  15. #include <string>
  16. #include <functional>
  17. /**
  18. * Parameters for PAD synthesis
  19. *
  20. * Note - unlike most other parameter objects significant portions of this
  21. * object are `owned' by the non-realtime context. The realtime context only
  22. * needs the samples generated by the PADsynth algorithm and modulators (ie
  23. * envelopes/filters/LFOs) for amplitude, frequency, and filters.
  24. * The ownership will be unclear for the time being, but it should be made more
  25. * explicit with time.
  26. */
  27. class PADnoteParameters:public Presets
  28. {
  29. public:
  30. PADnoteParameters(const SYNTH_T &synth_, FFTwrapper *fft_,
  31. const AbsTime *time_ = nullptr);
  32. ~PADnoteParameters();
  33. void defaults();
  34. void add2XML(XMLwrapper& xml);
  35. void getfromXML(XMLwrapper& xml);
  36. void paste(PADnoteParameters &p);
  37. void pasteRT(PADnoteParameters &p);
  38. //returns a value between 0.0f-1.0f that represents the estimation perceived bandwidth
  39. float getprofile(float *smp, int size);
  40. //parameters
  41. //the mode: 0 - bandwidth, 1 - discrete (bandwidth=0), 2 - continous
  42. //the harmonic profile is used only on mode 0
  43. unsigned char Pmode;
  44. //Harmonic profile (the frequency distribution of a single harmonic)
  45. struct {
  46. struct { //base function
  47. unsigned char type;
  48. unsigned char par1;
  49. } base;
  50. unsigned char freqmult; //frequency multiplier of the distribution
  51. struct { //the modulator of the distribution
  52. unsigned char par1;
  53. unsigned char freq;
  54. } modulator;
  55. unsigned char width; //the width of the resulting function after the modulation
  56. struct { //the amplitude multiplier of the harmonic profile
  57. unsigned char mode;
  58. unsigned char type;
  59. unsigned char par1;
  60. unsigned char par2;
  61. } amp;
  62. bool autoscale; //if the scale of the harmonic profile is computed automaticaly
  63. unsigned char onehalf; //what part of the base function is used to make the distribution
  64. } Php;
  65. unsigned int Pbandwidth; //the values are from 0 to 1000
  66. unsigned char Pbwscale; //how the bandwidth is increased according to the harmonic's frequency
  67. struct { //where are positioned the harmonics (on integer multimplier or different places)
  68. unsigned char type;
  69. unsigned char par1, par2, par3; //0..255
  70. } Phrpos;
  71. struct { //quality of the samples (how many samples, the length of them,etc.)
  72. unsigned char samplesize;
  73. unsigned char basenote, oct, smpoct;
  74. } Pquality;
  75. //frequency parameters
  76. //If the base frequency is fixed to 440 Hz
  77. unsigned char Pfixedfreq;
  78. /* Equal temperate (this is used only if the Pfixedfreq is enabled)
  79. If this parameter is 0, the frequency is fixed (to 440 Hz);
  80. if this parameter is 64, 1 MIDI halftone -> 1 frequency halftone */
  81. unsigned char PfixedfreqET;
  82. unsigned char PBendAdjust;
  83. unsigned char POffsetHz;
  84. unsigned short int PDetune; //fine detune
  85. unsigned short int PCoarseDetune; //coarse detune+octave
  86. unsigned char PDetuneType; //detune type
  87. EnvelopeParams *FreqEnvelope; //Frequency Envelope
  88. LFOParams *FreqLfo; //Frequency LFO
  89. //Amplitude parameters
  90. unsigned char PStereo;
  91. /* Panning - 0 - random
  92. 1 - left
  93. 64 - center
  94. 127 - right */
  95. unsigned char PPanning;
  96. unsigned char PVolume;
  97. unsigned char PAmpVelocityScaleFunction;
  98. EnvelopeParams *AmpEnvelope;
  99. LFOParams *AmpLfo;
  100. /* Adjustment factor for anti-pop fadein */
  101. unsigned char Fadein_adjustment;
  102. unsigned char PPunchStrength, PPunchTime, PPunchStretch,
  103. PPunchVelocitySensing;
  104. //Filter Parameters
  105. FilterParams *GlobalFilter;
  106. // filter velocity sensing
  107. unsigned char PFilterVelocityScale;
  108. // filter velocity sensing
  109. unsigned char PFilterVelocityScaleFunction;
  110. EnvelopeParams *FilterEnvelope;
  111. LFOParams *FilterLfo;
  112. float setPbandwidth(int Pbandwidth); //returns the BandWidth in cents
  113. float getNhr(int n); //gets the n-th overtone position relatively to N harmonic
  114. void applyparameters(void);
  115. void applyparameters(std::function<bool()> do_abort);
  116. void export2wav(std::string basefilename);
  117. OscilGen *oscilgen;
  118. Resonance *resonance;
  119. //RT sample data
  120. struct Sample {
  121. int size;
  122. float basefreq;
  123. float *smp;
  124. } sample[PAD_MAX_SAMPLES];
  125. typedef std::function<void(int,PADnoteParameters::Sample&)> callback;
  126. void sampleGenerator(PADnoteParameters::callback cb,
  127. std::function<bool()> do_abort);
  128. const AbsTime *time;
  129. int64_t last_update_timestamp;
  130. static const rtosc::MergePorts ports;
  131. static const rtosc::Ports &non_realtime_ports;
  132. static const rtosc::Ports &realtime_ports;
  133. private:
  134. void generatespectrum_bandwidthMode(float *spectrum,
  135. int size,
  136. float basefreq,
  137. float *profile,
  138. int profilesize,
  139. float bwadjust);
  140. void generatespectrum_otherModes(float *spectrum,
  141. int size,
  142. float basefreq);
  143. void deletesamples();
  144. void deletesample(int n);
  145. FFTwrapper *fft;
  146. public:
  147. const SYNTH_T &synth;
  148. };
  149. #endif