1 /*
2   ZynAddSubFX - a software synthesizer
3 
4   PADnoteParameters.h - Parameters for PADnote (PADsynth)
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 modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 of the License, or
11   (at your option) any later version.
12 
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License (version 2 or later) for more details.
17 
18   You should have received a copy of the GNU General Public License (version 2)
19   along with this program; if not, write to the Free Software Foundation,
20   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 
22 */
23 
24 #ifndef PAD_NOTE_PARAMETERS_H
25 #define PAD_NOTE_PARAMETERS_H
26 
27 #include "../Misc/XMLwrapper.h"
28 #include "../DSP/FFTwrapper.h"
29 #include "../globals.h"
30 #include "../Synth/OscilGen.h"
31 #include "../Synth/Resonance.h"
32 #include "../Misc/Util.h"
33 
34 #include "EnvelopeParams.h"
35 #include "LFOParams.h"
36 #include "FilterParams.h"
37 #include "Presets.h"
38 #include <string>
39 #include <pthread.h>
40 
41 class PADnoteParameters:public Presets
42 {
43     public:
44         PADnoteParameters(FFTwrapper *fft_, pthread_mutex_t *mutex_);
45         ~PADnoteParameters();
46 
47         void defaults();
48         void add2XML(XMLwrapper *xml);
49         void getfromXML(XMLwrapper *xml);
50 
51         //returns a value between 0.0f-1.0f that represents the estimation perceived bandwidth
52         float getprofile(float *smp, int size);
53 
54         //parameters
55 
56         //the mode: 0 - bandwidth, 1 - discrete (bandwidth=0), 2 - continous
57         //the harmonic profile is used only on mode 0
58         unsigned char Pmode;
59 
60         //Harmonic profile (the frequency distribution of a single harmonic)
61         struct {
62             struct { //base function
63                 unsigned char type;
64                 unsigned char par1;
65             } base;
66             unsigned char freqmult; //frequency multiplier of the distribution
67             struct { //the modulator of the distribution
68                 unsigned char par1;
69                 unsigned char freq;
70             } modulator;
71 
72             unsigned char width; //the width of the resulting function after the modulation
73             struct { //the amplitude multiplier of the harmonic profile
74                 unsigned char mode;
75                 unsigned char type;
76                 unsigned char par1;
77                 unsigned char par2;
78             } amp;
79             bool autoscale; //if the scale of the harmonic profile is computed automaticaly
80             unsigned char onehalf; //what part of the base function is used to make the distribution
81         } Php;
82 
83 
84         unsigned int  Pbandwidth; //the values are from 0 to 1000
85         unsigned char Pbwscale; //how the bandwidth is increased according to the harmonic's frequency
86 
87         struct { //where are positioned the harmonics (on integer multimplier or different places)
88             unsigned char type;
89             unsigned char par1, par2, par3; //0..255
90         } Phrpos;
91 
92         struct { //quality of the samples (how many samples, the length of them,etc.)
93             unsigned char samplesize;
94             unsigned char basenote, oct, smpoct;
95         } Pquality;
96 
97         //frequency parameters
98         //If the base frequency is fixed to 440 Hz
99         unsigned char Pfixedfreq;
100 
101         /* Equal temperate (this is used only if the Pfixedfreq is enabled)
102            If this parameter is 0, the frequency is fixed (to 440 Hz);
103            if this parameter is 64, 1 MIDI halftone -> 1 frequency halftone */
104         unsigned char PfixedfreqET;
105         unsigned short int PDetune; //fine detune
106         unsigned short int PCoarseDetune; //coarse detune+octave
107         unsigned char      PDetuneType; //detune type
108 
109         EnvelopeParams *FreqEnvelope; //Frequency Envelope
110         LFOParams      *FreqLfo; //Frequency LFO
111 
112         //Amplitude parameters
113         unsigned char PStereo;
114         /* Panning -  0 - random
115                   1 - left
116                  64 - center
117                 127 - right */
118         unsigned char PPanning;
119 
120         unsigned char PVolume;
121 
122         unsigned char PAmpVelocityScaleFunction;
123 
124         EnvelopeParams *AmpEnvelope;
125 
126         LFOParams *AmpLfo;
127 
128         unsigned char PPunchStrength, PPunchTime, PPunchStretch,
129                       PPunchVelocitySensing;
130 
131         //Filter Parameters
132         FilterParams *GlobalFilter;
133 
134         // filter velocity sensing
135         unsigned char PFilterVelocityScale;
136 
137         // filter velocity sensing
138         unsigned char PFilterVelocityScaleFunction;
139 
140         EnvelopeParams *FilterEnvelope;
141         LFOParams      *FilterLfo;
142 
143 
144 
145 
146         float setPbandwidth(int Pbandwidth); //returns the BandWidth in cents
147         float getNhr(int n); //gets the n-th overtone position relatively to N harmonic
148 
149         void applyparameters(bool lockmutex);
150         void export2wav(std::string basefilename);
151 
152         OscilGen  *oscilgen;
153         Resonance *resonance;
154 
155         struct {
156             int    size;
157             float  basefreq;
158             float *smp;
159         } sample[PAD_MAX_SAMPLES], newsample;
160 
161     private:
162         void generatespectrum_bandwidthMode(float *spectrum,
163                                             int size,
164                                             float basefreq,
165                                             float *profile,
166                                             int profilesize,
167                                             float bwadjust);
168         void generatespectrum_otherModes(float *spectrum,
169                                          int size,
170                                          float basefreq);
171         void deletesamples();
172         void deletesample(int n);
173 
174         FFTwrapper *fft;
175         pthread_mutex_t *mutex;
176 };
177 
178 
179 
180 #endif
181