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.

205 lines
6.8KB

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