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