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.

201 lines
6.7KB

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