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.

196 lines
6.6KB

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