Main Page | Namespaces | Classes | Compounds | Files | Compound Members | Related Modules.h00001 // 00002 // SYNTOPIA. See http://Syntopia.sourceforge.net for details and documentation. 00003 // 00004 // Author of this file: Mikael Hvidtfeldt Christensen (mikaelc@users.sourceforge.net) 00005 // 00006 00007 00008 // Visual C++ compiler warnings: 255 char limit on var names..... 00009 #pragma warning(disable: 4786) 00010 00011 // Modules is a class of standard modules 00012 // That is: delay, filers, oscillators, sample playing and so on. 00013 // mikaelc@ifa.au.dk 2002 00014 00015 #ifndef __Module__ 00016 #define __Module__ 00017 00018 #include "Input.h" 00019 #include "Output.h" 00020 #include "SynthEngine.h" 00021 #include <string> 00022 #include "sndutils.h" 00023 #include "utils.h" 00024 #include <map> 00025 00026 using namespace std; 00027 using namespace Utils; 00028 00029 namespace SynthCore { 00030 00031 class Synth; 00032 class SynthVoice; 00033 00035 00039 class Module { 00040 public: // -------------------------------------------------------------------------------- 00041 00043 int static getUniqueID() {return IDCount++; } 00044 00046 static int IDCount; 00047 00049 void static resetIDCount(int i) {IDCount = i;} 00050 00052 Module() { noInputs = 0; noOutputs = 0; hostVoice = 0; ModID = getUniqueID();} 00053 00056 void virtual update() = 0 ; 00057 00061 virtual int getNoInputs() { return noInputs; } 00062 00064 virtual Input * getInput(int no) { return myInputs[no]; } 00065 00068 virtual void addInput(Input * I) { myInputs[noInputs++]=I;} 00069 00071 virtual int getNoOutputs() { return noOutputs; } 00072 00074 virtual Output * getOutput(int no) { return myOutputs[no]; } 00075 00078 virtual void addOutput(Output * I) { myOutputs[noOutputs++]=I;} 00079 00080 00082 virtual std::string getName() {return "Undefined";} 00083 00086 //virtual std::string * getType() {return new std::string("Undefined");} 00087 00091 virtual void newMidiEvent() {;} 00092 00094 static Module * newInstance() {return 0;}; 00095 00100 SynthVoice * hostVoice; 00101 00105 int ModID; 00106 00111 bool firstVoice; 00112 00115 virtual std::string getXML(int indent = 0) ; 00116 00119 virtual void loadXML(XMLNode * n, bool firstPass); 00120 00121 // When overloading << operator, it must be able to read private fields. 00122 // (In fact this is not true since all access is through getXML() above.) 00123 friend std::ostream & operator<< (std::ostream & ostr, Module & myMod); 00124 friend std::ostream & operator<< (std::ostream & ostr, Module * myMod); 00125 00126 static std::string saveParameter(std::string tag, float f, int indent = 0) ; 00127 static std::string saveParameter(std::string tag, std::string s, int indent = 0); 00128 std::string saveID(int indent = 0) ; 00129 00132 virtual Module * sharedClone() { cout << "No SharedClone Method()" << endl; return 0; } 00133 00134 void loadParameter(string tagName, float par, XMLNode * n) ; 00135 00136 private: // -------------------------------------------------------------------------------------- 00137 00138 int noInputs; 00139 int noOutputs; 00140 00143 Input * myInputs[10]; 00144 00147 Output * myOutputs[10]; 00148 00149 }; 00150 00152 std::ostream & operator<< (std::ostream & ostr, Module & myMod); 00153 00155 std::ostream & operator<< (std::ostream & ostr, Module * myMod); 00156 00157 00158 // --------------------------------------------------------------------------------------------------- 00159 00168 class moduleRegistry { 00169 00170 public: // ---------------------------------------------------------- 00172 typedef Module * (*newPtr)(SynthVoice * S); 00173 00179 void add(string s, newPtr np ) { 00180 00181 constructorMap[s] = np; 00182 } 00183 00185 Module * getNew(string s, SynthVoice * S) { 00186 // find string in map 00187 std::map<string, newPtr>::iterator it = constructorMap.find(s); 00188 if (it == constructorMap.end()) {return 0 ;} 00189 00190 newPtr np = (*it).second; 00191 00192 // call constructor. 00193 return np(S); 00194 } 00195 00196 // Access the moduleRegistry through this method. 00197 static moduleRegistry * getInstance() { 00198 if (instance == 0) {instance = new moduleRegistry();} 00199 return instance; 00200 } 00201 private: // ---------------------------------------------------------- 00202 static moduleRegistry * instance; 00203 00204 std::map<string, newPtr> constructorMap; 00205 00206 // Notice: private constructor - so we can control number of objects. 00207 moduleRegistry() { ; }; 00208 }; 00209 00210 00211 00213 00220 class Multiplier : public Module { 00221 00222 public: // -------------------------------------------------- 00223 00224 virtual std::string getName() {return "Multiplier";} 00225 00227 Output * Output1; 00228 00229 Input * Input1; 00230 00231 Input * Input2; 00232 00234 Multiplier(SynthVoice * S1) ; 00235 00237 ~Multiplier() { 00238 delete Output1; 00239 delete Input1; 00240 delete Input2; 00241 }; 00242 00244 static Module * newInstance(SynthVoice * S1); 00245 00247 void update() ; 00248 00249 private: // ------------------------------------------------- 00250 00251 float freq; 00252 00253 00254 }; 00255 00257 00262 class Dummy : public Module { 00263 // Multiplies two inputs. 00264 private: 00265 00266 float freq; 00267 00268 public: 00269 00270 virtual std::string getName() {return "Dummy";} 00271 00272 // Mono Module 00273 Output * Output1; 00274 Input * Input1; 00275 float * In1; 00276 float * Ou1; 00277 Output * Out; 00278 00279 00280 // Constructor 00281 Dummy(SynthVoice * S1) ; 00282 00283 // Destructor; 00284 ~Dummy() { 00285 delete Output1; 00286 delete Input1; 00287 }; 00288 00289 // Actual Code; 00290 void update() ; 00291 void dupdate() ; 00292 00293 00294 }; 00295 00296 00297 00298 00299 00300 }; // end of namespace: SynthCore 00301 00302 #endif Docs made by Doxygen. Email: Mikael Christensen |