1 /*
2  *  mdaPianoProcessor.h
3  *  mda-vst3
4  *
5  *  Created by Arne Scheffler on 6/14/08.
6  *
7  *  mda VST Plug-ins
8  *
9  *  Copyright (c) 2008 Paul Kellett
10  *
11  *  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14  *
15  */
16 
17 #pragma once
18 
19 #include "mdaBaseProcessor.h"
20 
21 namespace Steinberg {
22 namespace Vst {
23 namespace mda {
24 
25 //-----------------------------------------------------------------------------
26 class PianoProcessor : public BaseProcessor
27 {
28 public:
29 	PianoProcessor ();
30 	~PianoProcessor ();
31 
32 	tresult PLUGIN_API initialize (FUnknown* context) SMTG_OVERRIDE;
33 	tresult PLUGIN_API terminate () SMTG_OVERRIDE;
34 	tresult PLUGIN_API setActive (TBool state) SMTG_OVERRIDE;
35 
36 	void doProcessing (ProcessData& data) SMTG_OVERRIDE;
37 
38 	bool hasProgram () const SMTG_OVERRIDE { return true; }
39 	Steinberg::uint32 getCurrentProgram () const SMTG_OVERRIDE { return currentProgram; }
40 	void setCurrentProgram (Steinberg::uint32 val) SMTG_OVERRIDE;
41 	void setCurrentProgramNormalized (ParamValue val) SMTG_OVERRIDE;
42 
43 //-----------------------------------------------------------------------------
44 	static FUnknown* createInstance (void*) { return (IAudioProcessor*)new PianoProcessor; }
45 	static FUID uid;
46 //-----------------------------------------------------------------------------
47 
48 	enum {
49 		EVENTBUFFER=120,
50 		EVENTS_DONE=99999999,
51 		NPARAMS=12,
52 		kNumPrograms = 8,
53 		NVOICES=32,
54 		SUSTAIN=128,
Profilellvm::FoldingSetTrait55 		WAVELEN=586348
56 	};
57 
58 	static float programParams[][NPARAMS];
59 
Profilellvm::FoldingSetTrait60 protected:
61 	void setParameter (ParamID index, ParamValue newValue, int32 sampleOffset) SMTG_OVERRIDE;
62 	void processEvents (IEventList* events) SMTG_OVERRIDE;
63 	void noteOn(int32 note, int32 velocity);
64 	void recalculate () SMTG_OVERRIDE;
65 	void allNotesOff ();
66 
67 	struct VOICE  //voice state
68 	{
69 		int32 delta;  //sample playback
70 		int32 frac;
71 		int32 pos;
72 		int32 end;
73 		int32 loop;
74 
75 		float env;  //envelope
76 		float dec;
77 
78 		float f0;   //first-order LPF
79 		float f1;
80 		float ff;
81 
82 		float outl;
83 		float outr;
84 		int32 note; //remember what note triggered this
85 	};
86 
87 
88 	struct KGRP  //keygroup
89 	{
90 		int32  root;  //MIDI root note
91 		int32  high;  //highest note
92 		int32  pos;
93 		int32  end;
94 		int32  loop;
95 	};
96 
97 	float Fs, iFs;
98 
99 	int32 notes[EVENTBUFFER + 8];  //list of delta|note|velocity for current block
100 
101 	///global internal variables
102 	KGRP  kgrp[16];
103 	VOICE voice[NVOICES];
104 	int32 activevoices, poly, cpos;
105 	short *waves;
106 	int32 cmax;
107 	float *comb, cdep, width, trim;
108 	int32 size, sustain;
109 	float tune, fine, random, stretch;
110 	float muff, muffvel, sizevel, velsens, volume;
111 
112 	int32 eventPos;
113 
114 	Steinberg::uint32 currentProgram;
115 };
116 
117 }}} // namespaces
118