summaryrefslogtreecommitdiff
path: root/src/mdaPiano.h
blob: c8a02a31f9b617678ee138ad37a6567ab6baf33d (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//See associated .cpp file for copyright and other info

#ifndef __mdaPiano__
#define __mdaPiano__

#pragma GCC system_header
#include <lv2synth.hpp>
#include <string.h>

#define NPARAMS 12       //number of parameters
#define NPROGS   8       //number of programs
#define NOUTS    2       //number of outputs
#define NVOICES 32       //max polyphony
#define SUSTAIN 128
#define SILENCE 0.0001f  //voice choking
#define WAVELEN 586348   //wave data bytes

class mdaPianoProgram
{
  friend class mdaPiano;
public:
  mdaPianoProgram();
  ~mdaPianoProgram() {}

private:
  float param[NPARAMS];
  char  name[24];
};


struct VOICE  //voice state
{
  uint32_t  delta;  //sample playback
  uint32_t  frac;
  uint32_t  pos;
  uint32_t  end;
  uint32_t  loop;
  
  float env;  //envelope
  float dec;

  float f0;   //first-order LPF
  float f1;
  float ff;

  float outl;
  float outr;
  uint32_t  note; //remember what note triggered this
};


struct KGRP  //keygroup
{
  uint32_t  root;  //MIDI root note
  uint32_t  high;  //highest note
  uint32_t  pos;
  uint32_t  end;
  uint32_t  loop;
};

class mdaPiano : public LV2::Synth<mdaPianoVoice, mdaPiano> {
public:
  mdaPiano(double rate);
  ~mdaPiano();

  virtual void process(float **inputs, float **outputs, uint32_t sampleframes);
  virtual void processReplacing(float **inputs, float **outputs, uint32_t sampleframes);
  virtual uint32_t processEvents(VstEvents* events);

  virtual void setParameter(uint32_t index, float value);
  virtual void resume();


private:
  void update();  //my parameter update
  void noteOn(uint32_t note, uint32_t velocity);

  float param[NPARAMS];
  float Fs, iFs;

  #define EVENTBUFFER 120
  #define EVENTS_DONE 99999999
  uint32_t notes[EVENTBUFFER + 8];  //list of delta|note|velocity for current block

  ///global internal variables
  KGRP  kgrp[16];
  VOICE voice[NVOICES];
  uint32_t activevoices, poly, cpos;
  short *waves;
  uint32_t cmax;
  float *comb, cdep, width, trim;
  uint32_t size, sustain;
  float tune, fine, random, stretch;
  float muff, muffvel, sizevel, velsens, volume;
};

#endif