summaryrefslogtreecommitdiff
path: root/src/mdaPiano.h
blob: 04f020f9f82967b76822f5ff2dbb0c4b7317f9f1 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//See associated .cpp file for copyright and other info

#ifndef __mdaPiano__
#define __mdaPiano__

#include <string.h>

#include "audioeffectx.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
{
  VstInt32  delta;  //sample playback
  VstInt32  frac;
  VstInt32  pos;
  VstInt32  end;
  VstInt32  loop;
  
  float env;  //envelope
  float dec;

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

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


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

class mdaPiano : public AudioEffectX
{
public:
  mdaPiano(audioMasterCallback audioMaster);
  ~mdaPiano();

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

  virtual void setProgram(VstInt32 program);
  virtual void setProgramName(char *name);
  virtual void getProgramName(char *name);
  virtual void setParameter(VstInt32 index, float value);
  virtual float getParameter(VstInt32 index);
  virtual void getParameterLabel(VstInt32 index, char *label);
  virtual void getParameterDisplay(VstInt32 index, char *text);
  virtual void getParameterName(VstInt32 index, char *text);
  virtual void setBlockSize(VstInt32 blockSize);
  virtual void resume();

  virtual bool getOutputProperties (VstInt32 index, VstPinProperties* properties);
  virtual bool getProgramNameIndexed (VstInt32 category, VstInt32 index, char* text);
  virtual bool copyProgram (VstInt32 destination);
  virtual bool getEffectName (char* name);
  virtual bool getVendorString (char* text);
  virtual bool getProductString (char* text);
  virtual VstInt32 getVendorVersion () {return 1;}
  virtual VstInt32 canDo (char* text);
  
  virtual VstInt32 getNumMidiInputChannels ()  { return 1; }

  VstInt32 guiUpdate;
  void guiGetDisplay(VstInt32 index, char *label);

private:
  void update();  //my parameter update
  void noteOn(VstInt32 note, VstInt32 velocity);
  void fillpatch(VstInt32 p, char *name, float p0, float p1, float p2, float p3, float p4,
                 float p5, float p6, float p7, float p8, float p9, float p10,float p11);

  float param[NPARAMS];
  mdaPianoProgram* programs;
  float Fs, iFs;

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

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

#endif