7df00769f299ec4ae55c2d205df67d251503f88d
[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 #include "mdaPiano.peg"
6
7 #pragma GCC system_header
8 #include <lv2synth.hpp>
9
10 enum Param {
11 Default,
12 Current
13 };
14
15 class mdaPianoVoice : public LV2::Voice {
16 private:
17 float Fs, iFs;
18
19 /// global internal variables
20 KGRP *kgrp;
21 short *waves;
22 float default_preset[NPARAMS]; // contains the default preset
23 short sustain;
24 float comb[256];
25 float cdep, width, trim;
26 float fine, random, stretch;
27 float volume, muff, muffvel, sizevel, velsens;
28 uint32_t cpos, size, poly;
29
30 // voice state
31 uint32_t delta; //sample playback
32 uint32_t frac;
33 uint32_t pos;
34 uint32_t end;
35 uint32_t loop;
36
37 float env; //envelope
38 float dec;
39
40 float f0; //first-order LPF
41 float f1;
42 float ff;
43
44 float outl;
45 float outr;
46 uint32_t note; //remember what note triggered this
47 // end of voice state
48
49 protected:
50 unsigned char m_key;
51
52 public:
53 mdaPianoVoice(double, short*, KGRP*);
54 void set_sustain(unsigned short v) { sustain = v; }
55 void set_volume(float v) { volume = v; }
56 void set_muff(float v) { muff = v; }
57
58 float p_helper(unsigned short, Param);
59 void update(Param); // recalculates internal variables
60 void on(unsigned char key, unsigned char velocity);
61 void release(unsigned char velocity);
62 void reset(void);
63 bool is_sustained(void) { return (note == SUSTAIN); }
64 unsigned char get_key(void) const { return m_key; }
65
66 // generates the sound for this voice
67 void render(uint32_t, uint32_t);
68 };
69
70 #endif