name peg file after TYPE
[software/lv2-mdametapiano.git] / src / mdaPianoVoice.h
1 #ifndef MDA_PIANO_VOICE_H
2 #define MDA_PIANO_VOICE_H
3
4 #include "mdaPianoCommon.h"
5 #ifdef PIANO
6 #include "mdaPiano.peg"
7 #elif defined EPIANO
8 #include "mdaEPiano.peg"
9 #endif
10
11 #pragma GCC system_header
12 #include <lvtk/synth.hpp>
13
14 enum Param {
15 Default,
16 Current
17 };
18
19 class mdaPianoVoice : public lvtk::Voice {
20 private:
21 float Fs, iFs;
22
23 /// global internal variables
24 KGRP *kgrp;
25 Sample *samples;
26 uint32_t sample_index;
27 short sustain;
28 float width;
29 float fine, random;
30 float sizevel, velsens, volume;
31 long size;
32
33 #ifdef PIANO
34 float comb[256];
35 float cdep, trim;
36 float stretch;
37 float muff, muffvel;
38 uint32_t cpos;
39 #endif
40 #ifdef EPIANO
41 float overdrive;
42 float lfo0, lfo1, dlfo, lmod, rmod;
43 float treb, tfrq, tl, tr;
44 #endif
45
46 // TODO: uint32_t or long?
47 #ifdef PIANO
48 // voice state
49 uint32_t delta; // sample playback
50 uint32_t frac;
51 uint32_t pos;
52 uint32_t end;
53 uint32_t loop;
54 #elif defined EPIANO
55 long delta; // sample playback
56 long frac;
57 long pos;
58 long end;
59 long loop;
60 #endif
61
62 float env; // envelope
63 float dec;
64
65 #ifdef PIANO
66 float f0; // first-order LPF
67 float f1;
68 float ff;
69 #endif
70
71 float outl;
72 float outr;
73 // end of voice state
74
75 float default_preset[NPARAMS]; // contains the default preset
76
77 protected:
78 unsigned char m_key;
79
80 public:
81 mdaPianoVoice(double, Sample*, KGRP*);
82 void set_sustain(unsigned short v) { sustain = v; }
83 void set_volume(float v) { volume = v; }
84 #ifdef PIANO
85 void set_muff(float v) { muff = v; }
86 #endif
87
88 float p_helper(unsigned short, Param);
89 void update(Param); // recalculates internal variables
90 void on(unsigned char key, unsigned char velocity);
91 void release(unsigned char velocity);
92 void reset(void);
93 bool is_sustained(void) { return (m_key == SUSTAIN); }
94 unsigned char get_key(void) const { return m_key; }
95
96 // generates the sound for this voice
97 void render(uint32_t, uint32_t);
98 };
99
100 #endif