replace VstInt32 with uint32_t
[software/lv2-mdametapiano.git] / src / mdaPiano.h
1 //See associated .cpp file for copyright and other info
2
3 #ifndef __mdaPiano__
4 #define __mdaPiano__
5
6 #pragma GCC system_header
7 #include <lv2synth.hpp>
8 #include <string.h>
9
10 #define NPARAMS 12 //number of parameters
11 #define NPROGS 8 //number of programs
12 #define NOUTS 2 //number of outputs
13 #define NVOICES 32 //max polyphony
14 #define SUSTAIN 128
15 #define SILENCE 0.0001f //voice choking
16 #define WAVELEN 586348 //wave data bytes
17
18 class mdaPianoProgram
19 {
20 friend class mdaPiano;
21 public:
22 mdaPianoProgram();
23 ~mdaPianoProgram() {}
24
25 private:
26 float param[NPARAMS];
27 char name[24];
28 };
29
30
31 struct VOICE //voice state
32 {
33 uint32_t delta; //sample playback
34 uint32_t frac;
35 uint32_t pos;
36 uint32_t end;
37 uint32_t loop;
38
39 float env; //envelope
40 float dec;
41
42 float f0; //first-order LPF
43 float f1;
44 float ff;
45
46 float outl;
47 float outr;
48 uint32_t note; //remember what note triggered this
49 };
50
51
52 struct KGRP //keygroup
53 {
54 uint32_t root; //MIDI root note
55 uint32_t high; //highest note
56 uint32_t pos;
57 uint32_t end;
58 uint32_t loop;
59 };
60
61 class mdaPiano : public LV2::Synth<mdaPianoVoice, mdaPiano> {
62 public:
63 mdaPiano(double rate);
64 ~mdaPiano();
65
66 virtual void process(float **inputs, float **outputs, uint32_t sampleframes);
67 virtual void processReplacing(float **inputs, float **outputs, uint32_t sampleframes);
68 virtual uint32_t processEvents(VstEvents* events);
69
70 virtual void setParameter(uint32_t index, float value);
71 virtual void resume();
72
73
74 private:
75 void update(); //my parameter update
76 void noteOn(uint32_t note, uint32_t velocity);
77
78 float param[NPARAMS];
79 float Fs, iFs;
80
81 #define EVENTBUFFER 120
82 #define EVENTS_DONE 99999999
83 uint32_t notes[EVENTBUFFER + 8]; //list of delta|note|velocity for current block
84
85 ///global internal variables
86 KGRP kgrp[16];
87 VOICE voice[NVOICES];
88 uint32_t activevoices, poly, cpos;
89 short *waves;
90 uint32_t cmax;
91 float *comb, cdep, width, trim;
92 uint32_t size, sustain;
93 float tune, fine, random, stretch;
94 float muff, muffvel, sizevel, velsens, volume;
95 };
96
97 #endif