SynthNote.h (4440B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 Note.h - Abstract Base Class for synthesizers 5 Copyright (C) 2010-2010 Mark McCurry 6 Author: Mark McCurry 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 */ 13 #ifndef SYNTH_NOTE_H 14 #define SYNTH_NOTE_H 15 #include "../globals.h" 16 #include "../Misc/Util.h" 17 #include "../Containers/NotePool.h" 18 19 namespace zyn { 20 21 class Allocator; 22 class Controller; 23 class Portamento; 24 struct SynthParams 25 { 26 Allocator &memory; //Memory Allocator for the Note to use 27 const Controller &ctl; 28 const SYNTH_T &synth; 29 const AbsTime &time; 30 float velocity; //Velocity of the Note 31 Portamento *portamento; //Realtime portamento info 32 float note_log2_freq; //Floating point value of the note 33 bool quiet; //Initial output condition for legato notes 34 prng_t seed; //Random seed 35 }; 36 37 struct LegatoParams 38 { 39 float velocity; 40 Portamento *portamento; 41 float note_log2_freq; //Floating point value of the note 42 bool externcall; 43 prng_t seed; 44 }; 45 46 class SynthNote 47 { 48 public: 49 SynthNote(const SynthParams &pars); 50 virtual ~SynthNote() {} 51 52 /**Compute Output Samples 53 * @return 0 if note is finished*/ 54 virtual int noteout(float *outl, float *outr) = 0; 55 56 //TODO fix this spelling error [noisey commit] 57 /**Release the key for the note and start release portion of envelopes.*/ 58 virtual void releasekey() = 0; 59 60 /**Return if note is finished. 61 * @return finished=1 unfinished=0*/ 62 virtual bool finished() const = 0; 63 64 /**Make a note die off next buffer compute*/ 65 virtual void entomb(void) = 0; 66 67 virtual void legatonote(const LegatoParams &pars) = 0; 68 69 virtual SynthNote *cloneLegato(void) = 0; 70 71 /* For polyphonic aftertouch needed */ 72 void setVelocity(float velocity_); 73 74 /* For per-note pitch */ 75 void setPitch(float log2_freq_); 76 77 /* For per-note filter cutoff */ 78 void setFilterCutoff(float); 79 float getFilterCutoffRelFreq(void); 80 81 /* Random numbers with own seed */ 82 float getRandomFloat(); 83 prng_t getRandomUint(); 84 85 //Realtime Safe Memory Allocator For notes 86 class Allocator &memory; 87 protected: 88 // Legato transitions 89 class Legato 90 { 91 public: 92 Legato(const SYNTH_T &synth_, float vel, 93 Portamento *portamento, 94 float note_log2_freq, bool quiet, prng_t seed); 95 96 void apply(SynthNote ¬e, float *outl, float *outr); 97 int update(const LegatoParams &pars); 98 99 private: 100 bool silent; 101 float lastfreq_log2; 102 LegatoMsg msg; 103 int decounter; 104 struct { // Fade In/Out vars 105 int length; 106 float m, step; 107 } fade; 108 public: 109 //TODO: portamento and note freq are used not just for legato, 110 //so should they really be here in the Legato class? 111 struct { // Note parameters 112 float freq, vel; 113 Portamento *portamento; 114 float note_log2_freq; 115 prng_t seed; 116 } param; 117 const SYNTH_T &synth; 118 119 public: /* Some get routines for legatonote calls (aftertouch feature)*/ 120 float getFreq() {return param.freq; } 121 float getVelocity() {return param.vel; } 122 Portamento *getPortamento() {return param.portamento; } 123 float getNoteLog2Freq() {return param.note_log2_freq; } 124 prng_t getSeed() {return param.seed;} 125 void setSilent(bool silent_) {silent = silent_; } 126 void setDecounter(int decounter_) {decounter = decounter_; } 127 } legato; 128 129 prng_t initial_seed; 130 prng_t current_prng_state; 131 const Controller &ctl; 132 const SYNTH_T &synth; 133 const AbsTime &time; 134 WatchManager *wm; 135 smooth_float filtercutoff_relfreq; 136 }; 137 138 } 139 140 #endif