Part.h (9141B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 Part.h - Part implementation 5 Copyright (C) 2002-2005 Nasca Octavian Paul 6 Author: Nasca Octavian Paul 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 14 #ifndef PART_H 15 #define PART_H 16 17 #define MAX_INFO_TEXT_SIZE 1000 18 19 #include "../globals.h" 20 #include "../Params/Controller.h" 21 #include "../Containers/NotePool.h" 22 23 #include <functional> 24 25 namespace zyn { 26 27 struct PortamentoParams; 28 /** Part implementation*/ 29 class Part 30 { 31 public: 32 /**Constructor 33 * @param microtonal_ Pointer to the microtonal object 34 * @param fft_ Pointer to the FFTwrapper*/ 35 Part(Allocator &alloc, const SYNTH_T &synth, const AbsTime &time, Sync* sync, 36 const int& gzip_compression, const int& interpolation, 37 Microtonal *microtonal_, FFTwrapper *fft_, WatchManager *wm=0, const char *prefix=0); 38 /**Destructor*/ 39 ~Part(); 40 41 // Copy misc parameters not stored in .xiz format 42 void cloneTraits(Part &part) const REALTIME; 43 44 // Midi commands implemented 45 46 //returns true when successful 47 bool getNoteLog2Freq(int masterkeyshift, float ¬e_log2_freq); 48 49 //returns true when note is successfully applied 50 bool NoteOn(note_t note, uint8_t vel, int shift) REALTIME { 51 float log2_freq = note / 12.0f; 52 return (getNoteLog2Freq(shift, log2_freq) && 53 NoteOnInternal(note, vel, log2_freq)); 54 }; 55 56 //returns true when note is successfully applied 57 bool NoteOn(note_t note, uint8_t vel, int shift, 58 float log2_freq) REALTIME { 59 return (getNoteLog2Freq(shift, log2_freq) && 60 NoteOnInternal(note, vel, log2_freq)); 61 }; 62 63 //returns true when note is successfully applied 64 bool NoteOnInternal(note_t note, 65 unsigned char velocity, 66 float note_log2_freq) REALTIME; 67 void NoteOff(note_t note) REALTIME; 68 void PolyphonicAftertouch(note_t note, 69 unsigned char velocity) REALTIME; 70 void AllNotesOff() REALTIME; //panic 71 void SetController(unsigned int type, int par) REALTIME; 72 void SetController(unsigned int type, note_t, float value, 73 int masterkeyshift) REALTIME; 74 void ReleaseSustainedKeys() REALTIME; //this is called when the sustain pedal is released 75 void ReleaseAllKeys() REALTIME; //this is called on AllNotesOff controller 76 77 /* The synthesizer part output */ 78 void ComputePartSmps() REALTIME; //Part output 79 80 81 //saves the instrument settings to a XML file 82 //returns 0 for ok or <0 if there is an error 83 int saveXML(const char *filename); 84 int loadXMLinstrument(const char *filename); 85 86 void add2XML(XMLwrapper& xml); 87 void add2XMLinstrument(XMLwrapper& xml); 88 89 void defaults(); 90 void defaultsinstrument(); 91 92 void applyparameters(void) NONREALTIME; 93 void applyparameters(std::function<bool()> do_abort) NONREALTIME; 94 95 void initialize_rt(void) REALTIME; 96 void kill_rt(void) REALTIME; 97 98 void getfromXML(XMLwrapper& xml); 99 void getfromXMLinstrument(XMLwrapper& xml); 100 101 void cleanup(bool final = false); 102 103 //the part's kit 104 struct Kit { 105 Kit(void); 106 Part *parent; 107 bool firstkit; 108 bool Penabled, Pmuted; 109 unsigned char Pminkey, Pmaxkey; 110 char *Pname; 111 bool Padenabled, Psubenabled, Ppadenabled; 112 unsigned char Psendtoparteffect; 113 ADnoteParameters *adpars; 114 SUBnoteParameters *subpars; 115 PADnoteParameters *padpars; 116 117 bool active(void) const; 118 uint8_t sendto(void) const; 119 bool validNote(char note) const; 120 121 const static rtosc::Ports &ports; 122 } kit[NUM_KIT_ITEMS]; 123 124 //Part parameters 125 void setkeylimit(unsigned char Pkeylimit); 126 void setvoicelimit(unsigned char Pvoicelimit); 127 void setkititemstatus(unsigned kititem, bool Penabled_); 128 129 unsigned char partno; /**<the part number in Master*/ 130 bool Penabled; /**<if the part is enabled*/ 131 float Volume; /**<part volume*/ 132 unsigned char Pminkey; /**<the minimum key that the part receives noteon messages*/ 133 unsigned char Pmaxkey; //the maximum key that the part receives noteon messages 134 static float volume127TodB(unsigned char volume_); 135 void setVolumeGain(float Volume); 136 void setVolumedB(float Volume); 137 unsigned char Pkeyshift; //Part keyshift 138 unsigned char Prcvchn; //from what midi channel it receives commands 139 unsigned char Ppanning; //part panning 140 void setPpanning(char Ppanning); 141 unsigned char Pvelsns; //velocity sensing (amplitude velocity scale) 142 unsigned char Pveloffs; //velocity offset 143 bool Pnoteon; //if the part receives NoteOn messages 144 int Pkitmode; //if the kitmode is enabled 145 146 //XXX consider deprecating drum mode 147 bool Pdrummode; //if all keys are mapped and the system is 12tET (used for drums) 148 149 bool Ppolymode; //Part mode - 0=monophonic , 1=polyphonic 150 bool Plegatomode; // 0=normal, 1=legato 151 bool Platchmode; // 0=normal, 1=latch 152 unsigned char Pkeylimit; //how many keys are allowed to be played same time (0=off), the older will be released 153 unsigned char Pvoicelimit; //how many voices are allowed to be played same time (0=off), the older will be entombed 154 155 char *Pname; //name of the instrument 156 struct { //instrument additional information 157 unsigned char Ptype; 158 char Pauthor[MAX_INFO_TEXT_SIZE + 1]; 159 char Pcomments[MAX_INFO_TEXT_SIZE + 1]; 160 } info; 161 162 163 float *partoutl; //Left channel output of the part 164 float *partoutr; //Right channel output of the part 165 166 float *partfxinputl[NUM_PART_EFX + 1], //Left and right signal that pass thru part effects; 167 *partfxinputr[NUM_PART_EFX + 1]; //partfxinput l/r [NUM_PART_EFX] is for "no effect" buffer 168 169 170 float gain; 171 float panning; //this is applied by Master, too 172 173 Controller ctl; //Part controllers 174 175 EffectMgr *partefx[NUM_PART_EFX]; //insertion part effects (they are part of the instrument) 176 unsigned char Pefxroute[NUM_PART_EFX]; //how the effect's output is routed(to next effect/to out) 177 bool Pefxbypass[NUM_PART_EFX]; //if the effects are bypassed 178 179 int lastnote; 180 char loaded_file[256]; 181 182 const static rtosc::Ports &ports; 183 184 private: 185 void MonoMemRenote(); // MonoMem stuff. 186 float getVelocity(uint8_t velocity, uint8_t velocity_sense, 187 uint8_t velocity_offset) const; 188 void verifyKeyMode(void); 189 bool isPolyMode(void) const {return Ppolymode;} 190 bool isMonoMode(void) const {return !Ppolymode && !Plegatomode;}; 191 bool isLegatoMode(void) const {return Plegatomode && !Pdrummode;} 192 bool isNonKit(void) const {return Pkitmode == 0;} 193 bool isMultiKit(void) const {return Pkitmode == 1;} 194 bool isSingleKit(void) const {return Pkitmode == 2;} 195 196 bool killallnotes; 197 bool silent; // An output buffer with zeros has been generated 198 199 NotePool notePool; 200 201 void limit_voices(int new_note); 202 203 bool lastlegatomodevalid; // To keep track of previous legatomodevalid. 204 205 // MonoMem stuff 206 void monomemPush(note_t note); 207 void monomemPop(note_t note); 208 note_t monomemBack(void) const; 209 bool monomemEmpty(void) const; 210 void monomemClear(void); 211 212 short monomemnotes[256]; // A list to remember held notes. 213 struct { 214 unsigned char velocity; 215 float note_log2_freq; 216 } monomem[256]; 217 /* 256 is to cover all possible note values. 218 monomem[] is used in conjunction with the list to 219 store the velocity and logarithmic frequency values of a given note. 220 For example 'monomem[note].velocity' would be the velocity value of the note 'note'.*/ 221 222 float oldfreq_log2; // previous note pitch, used for portamento 223 float oldportamentofreq_log2; // previous portamento pitch 224 PortamentoRealtime *oldportamento; // previous portamento 225 PortamentoRealtime *legatoportamento; // last used legato portamento 226 227 Microtonal *microtonal; 228 FFTwrapper *fft; 229 WatchManager *wm; 230 char prefix[64]; 231 Allocator &memory; 232 const SYNTH_T &synth; 233 const AbsTime &time; 234 Sync* sync; 235 const int &gzip_compression, &interpolation; 236 }; 237 238 } 239 240 #endif