dampen/undampen notes on pedal
[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, cdep, width, trim;
25 float fine, random, stretch;
26 float volume, muff, muffvel, sizevel, velsens;
27 uint32_t cpos, size, poly;
28
29 // voice state
30 uint32_t delta; //sample playback
31 uint32_t frac;
32 uint32_t pos;
33 uint32_t end;
34 uint32_t loop;
35
36 float env; //envelope
37 float dec;
38
39 float f0; //first-order LPF
40 float f1;
41 float ff;
42
43 float outl;
44 float outr;
45 uint32_t note; //remember what note triggered this
46 // end of voice state
47
48 protected:
49 unsigned char m_key;
50
51 public:
52 mdaPianoVoice(double, short*, KGRP*);
53 void set_sustain(unsigned short v) { sustain = v; }
54 void set_volume(float v) { volume = v; }
55 void set_muff(float v) { muff = v; }
56
57 float p_helper(unsigned short, Param);
58 void update(Param); // recalculates internal variables
59 void on(unsigned char key, unsigned char velocity);
60 void release(unsigned char velocity);
61 void reset(void);
62 bool is_sustained(void) { return (note == SUSTAIN); }
63 unsigned char get_key(void) const { return m_key; }
64 };
65
66 #endif