FilterParams.h (4538B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 FilterParams.h - Parameters for filter 5 Copyright (C) 2002-2005 Nasca Octavian Paul 6 Author: Nasca Octavian Paul 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 */ 13 14 #ifndef FILTER_PARAMS_H 15 #define FILTER_PARAMS_H 16 17 #include "../globals.h" 18 #include "../Misc/XMLwrapper.h" 19 #include "PresetsArray.h" 20 #include <cstdint> 21 22 namespace zyn { 23 24 class FilterParams:public PresetsArray 25 { 26 public: 27 FilterParams(const AbsTime *time_ = nullptr); 28 FilterParams(unsigned char Ptype_, 29 unsigned char Pfreq, 30 unsigned char Pq_, 31 consumer_location_t loc, 32 const AbsTime *time_ = nullptr); 33 FilterParams(consumer_location_t loc, 34 const AbsTime *time_ = nullptr); 35 ~FilterParams() override; 36 37 void add2XML(XMLwrapper& xml) override; 38 void add2XMLsection(XMLwrapper& xml, int n) override; 39 void defaults(); 40 void getfromXML(XMLwrapper& xml); 41 void getfromXMLsection(XMLwrapper& xml, int n); 42 void paste(FilterParams &); 43 void pasteArray(FilterParams &, int section); 44 45 //! assignment operator-like function 46 //! @warning function has been unused since 2004 47 //! (84ddf9c0132b6be8d685f01c6444edd8bc49bb0f). If you use it, make 48 //! sure it's still up-to-date and make tests 49 void getfromFilterParams(const FilterParams *pars); 50 51 float getfreq() const ; 52 float getq() const ; 53 float getfreqtracking(float notefreq) const ; 54 float getgain() const ; 55 56 unsigned Pcategory:4; //!< Filter category (Analog/Formant/StVar/Moog/Comb) 57 unsigned Ptype:8; //!< Filter type (for analog lpf,hpf,bpf..) 58 unsigned Pstages:8; //!< filter stages+1 59 float basefreq; //!< Base cutoff frequency (Hz) 60 float baseq; //!< Q parameters (resonance or bandwidth) 61 float freqtracking; //!< Tracking of center frequency with note frequency (percentage) 62 float gain; //!< filter's output gain (dB) 63 64 static float baseqFromOldPq(int Pq); 65 static float gainFromOldPgain(int Pgain); 66 static float basefreqFromOldPreq(int Pfreq); 67 68 //Formant filter parameters 69 unsigned char Pnumformants; //how many formants are used 70 unsigned char Pformantslowness; //how slow varies the formants 71 unsigned char Pvowelclearness; //how vowels are kept clean (how much try to avoid "mixed" vowels) 72 unsigned char Pcenterfreq, Poctavesfreq; //the center frequency of the res. func., and the number of octaves 73 74 struct Pvowels_t { 75 struct formants_t { 76 unsigned char loc; //!< only relevant for DynFilter's default values 77 unsigned char freq, amp, q; //frequency,amplitude,Q 78 } formants[FF_MAX_FORMANTS]; 79 } Pvowels[FF_MAX_VOWELS]; 80 81 unsigned char Psequencesize; //how many vowels are in the sequence 82 unsigned char Psequencestretch; //how the sequence is stretched (how the input from filter envelopes/LFOs/etc. is "stretched") 83 unsigned char Psequencereversed; //if the input from filter envelopes/LFOs/etc. is reversed(negated) 84 struct { 85 unsigned char nvowel; //the vowel from the position 86 } Psequence[FF_MAX_SEQUENCE]; 87 88 float getcenterfreq() const ; 89 float getoctavesfreq() const ; 90 float getfreqpos(float freq) const ; 91 float getfreqx(float x) const ; 92 93 float getformantfreq(unsigned char freq) const ; 94 float getformantamp(unsigned char amp) const ; 95 float getformantq(unsigned char q) const ; 96 97 void defaults(int n); //!< set default for formant @p n 98 99 void updateLoc(int newloc); 100 int loc; //!< consumer location 101 bool changed; 102 103 const AbsTime *time; 104 int64_t last_update_timestamp; // timestamp of last update to this structure, 105 // including any change to the vowels/formats 106 107 static const rtosc::Ports ports; 108 private: 109 // common 110 void setup(); 111 void updateLoc(int newloc, int n); 112 113 //stored default parameters 114 unsigned char Dtype; 115 unsigned char Dfreq; 116 unsigned char Dq; 117 }; 118 119 } 120 121 #endif