1 /* 2 Part.h - Part implementation 3 4 Original ZynAddSubFX author Nasca Octavian Paul 5 Copyright (C) 2002-2005 Nasca Octavian Paul 6 Copyright 2009-2011 Alan Calvert 7 Copyright 2014-2021, Will Godfrey 8 9 This file is part of yoshimi, which is free software: you can redistribute 10 it and/or modify it under the terms of the GNU Library General Public 11 License as published by the Free Software Foundation; either version 2 of 12 the License, or (at your option) any later version. 13 14 yoshimi is distributed in the hope that it will be useful, but WITHOUT ANY 15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 FOR A PARTICULAR PURPOSE. See the GNU General Public License (version 2 or 17 later) for more details. 18 19 You should have received a copy of the GNU General Public License along with 20 yoshimi; if not, write to the Free Software Foundation, Inc., 51 Franklin 21 Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 23 This file is derivative of original ZynAddSubFX code. 24 25 */ 26 27 #ifndef PART_H 28 #define PART_H 29 30 #include <list> 31 #include <string> 32 #include "globals.h" 33 34 class ADnoteParameters; 35 class SUBnoteParameters; 36 class PADnoteParameters; 37 class ADnote; 38 class SUBnote; 39 class PADnote; 40 class Controller; 41 class XMLwrapper; 42 class Microtonal; 43 class EffectMgr; 44 class FFTwrapper; 45 46 class SynthEngine; 47 48 class Part 49 { 50 public: 51 enum NoteStatus { KEY_OFF, KEY_PLAYING, KEY_RELEASED_AND_SUSTAINED, KEY_RELEASED }; 52 53 Part(Microtonal *microtonal_, FFTwrapper *fft_, SynthEngine *_synth); 54 ~Part(); pannedVolLeft(void)55 inline float pannedVolLeft(void) { return volume * pangainL; } pannedVolRight(void)56 inline float pannedVolRight(void) { return volume * pangainR; } 57 void defaults(void); 58 void setNoteMap(int keyshift); 59 void defaultsinstrument(void); 60 void cleanup(void); 61 62 // Midi commands implemented 63 void setChannelAT(int type, int value); 64 void setKeyAT(int note, int type, int value); 65 void NoteOn(int note, int velocity, bool renote = false); 66 void NoteOff(int note); AllNotesOff(void)67 void AllNotesOff(void) { killallnotes = true; }; // panic, prepare all notes to be turned off 68 void SetController(unsigned int type, int par); 69 void ReleaseSustainedKeys(void); 70 void ReleaseAllKeys(void); 71 void ComputePartSmps(void); 72 73 bool saveXML(std::string filename, bool yoshiFormat); // result true for load ok, otherwise false 74 int loadXMLinstrument(std::string filename); 75 void add2XML(XMLwrapper *xml, bool subset = false); 76 void add2XMLinstrument(XMLwrapper *xml); 77 void getfromXML(XMLwrapper *xml); 78 void getfromXMLinstrument(XMLwrapper *xml); 79 float getLimits(CommandBlock *getData); 80 81 Controller *ctl; 82 83 // part's kit 84 struct Kititem 85 { 86 std::string Pname; 87 unsigned char Penabled; 88 unsigned char Pmuted; 89 unsigned char Pminkey; 90 unsigned char Pmaxkey; 91 unsigned char Padenabled; 92 unsigned char Psubenabled; 93 unsigned char Ppadenabled; 94 unsigned char Psendtoparteffect; 95 ADnoteParameters *adpars; 96 SUBnoteParameters *subpars; 97 PADnoteParameters *padpars; 98 }; 99 Kititem kit[NUM_KIT_ITEMS]; 100 101 // Part parameters 102 void enforcekeylimit(void); 103 void setkititemstatus(int kititem, int Penabled_); 104 void setVolume(float value); 105 void checkVolume(float step); 106 void setDestination(int value); 107 void checkPanning(float step, unsigned char panLaw); 108 getSynthEngine()109 SynthEngine *getSynthEngine() {return synth;} 110 111 bool PyoshiType; 112 int PmapOffset; 113 float PnoteMap[256]; 114 float Pvolume; 115 float TransVolume; 116 float Ppanning; 117 float TransPanning; 118 char Penabled; // this *must* be signed 119 unsigned char Pminkey; 120 unsigned char Pmaxkey; 121 unsigned char Pkeyshift; 122 unsigned char Prcvchn; 123 unsigned char Pvelsns; // velocity sensing (amplitude velocity scale) 124 unsigned char Pveloffs; // velocity offset 125 unsigned char Pkitmode; // if the kitmode is enabled 126 bool Pkitfade; // enables cross fading 127 unsigned char Pdrummode; // if all keys are mapped and the system is 12tET (used for drums) 128 unsigned char Pkeymode; // 0 = poly, 1 = mono, > 1 = legato; 129 unsigned int PchannelATchoice; 130 unsigned int PkeyATchoice; 131 unsigned char Pkeylimit; // how many keys can play simultaneously, 132 // time 0 = off, the older will be released 133 float Pfrand; // Part random frequency content 134 float Pvelrand; // Part random velocity content 135 unsigned char PbreathControl; 136 unsigned char Peffnum; 137 int Paudiodest; // jack output routing 138 std::string Pname; 139 std::string Poriginal; 140 141 struct Info { 142 unsigned char Ptype; 143 std::string Pauthor; 144 std::string Pcomments; 145 }; 146 Info info; 147 148 float *partoutl; 149 float *partoutr; 150 151 float *partfxinputl[NUM_PART_EFX + 1]; // Left and right signal that pass-through part effects 152 float *partfxinputr[NUM_PART_EFX + 1]; // [NUM_PART_EFX] is for "no effect" buffer 153 154 unsigned char Pefxroute[NUM_PART_EFX]; // how the effect's output is 155 // routed (to next effect/to out) 156 bool Pefxbypass[NUM_PART_EFX + 1]; // if the effects are bypassed, 157 // [NUM_PART_EFX] is for "no effect" buffer 158 EffectMgr *partefx[NUM_PART_EFX]; // insertion part effects - part of the instrument 159 160 float volume; // applied by MasterAudio 161 float pangainL; 162 float pangainR; 163 int lastnote; 164 bool busy; 165 166 167 private: 168 void KillNotePos(int pos); 169 void ReleaseNotePos(int pos); 170 void MonoMemRenote(void); // MonoMem stuff. 171 void setPan(float value); 172 173 Microtonal *microtonal; 174 FFTwrapper *fft; 175 176 struct PartNotes { 177 NoteStatus status; 178 int note; // if there is no note playing, "note" = -1 179 int itemsplaying; 180 int keyATtype; 181 int keyATvalue; 182 struct Kititem { 183 ADnote *adnote; 184 SUBnote *subnote; 185 PADnote *padnote; 186 int sendtoparteffect; 187 }; 188 Kititem kititem[NUM_KIT_ITEMS]; 189 int time; 190 }; 191 192 PartNotes partnote[POLIPHONY]; 193 194 int lastpos; // previous pos and posb. 195 int lastposb; // ^^ 196 bool lastlegatomodevalid; // previous legatomodevalid. 197 198 int oldFilterState; // these for channel aftertouch 199 int oldFilterQstate; 200 int oldBendState; 201 float oldVolumeState; 202 float oldVolumeAdjust; 203 int oldModulationState; 204 205 float *tmpoutl; 206 float *tmpoutr; 207 float oldfreq; // for portamento 208 // int partMuted; // **** RHL **** 209 bool killallnotes; 210 211 // MonoMem stuff 212 std::list<unsigned char> monomemnotes; // held notes. 213 struct { 214 unsigned char velocity; 215 } monomem[256]; // 256 is to cover all possible note values. monomem[] 216 // is used in conjunction with the list to store the 217 // velocity value of a given note 218 // (the list only store note values). For example. 219 // 'monomem[note].velocity' would be the velocity 220 // value of the note 'note'. 221 222 SynthEngine *synth; 223 }; 224 225 #endif 226