Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/root/src/subsynth/syn/Builder/ModuleFactory.h

Go to the documentation of this file.
00001 
00002 /****************** <SYN heading BEGIN do not edit this line> *****************
00003  *
00004  * subsynth - modular audio synthesizer
00005  * subsynth is (C) Copyright 2001-2002 by Kevin Meinert
00006  *
00007  * Original Author: Kevin Meinert
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this library; if not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00022  * Boston, MA 02111-1307, USA.
00023  *
00024  * -----------------------------------------------------------------
00025  * File:          $RCSfile: ModuleFactory.h,v $
00026  * Date modified: $Date: 2002/04/15 01:55:54 $
00027  * Version:       $Revision: 1.3 $
00028  * -----------------------------------------------------------------
00029  *
00030  ****************** <SYN heading END do not edit this line> ******************/
00031 
00032 #ifndef SYNTHMODULE_FACTORY
00033 #define SYNTHMODULE_FACTORY
00034 
00035 #include <string>
00036 #include <map>
00037 #include <syn/Core/Module.h>
00038 #include <syn/Util/Singleton.h>
00039 #include <syn/Module/DummyOutputModule.h>
00040 #include <syn/Module/FilterModule.h>
00041 #include <syn/Module/IStreamModule.h>
00042 #include <syn/Module/MixerModule.h>
00043 #include <syn/Module/OpenALOutputModule.h>
00044 #include <syn/Module/OperatorModule.h>
00045 #include <syn/Module/OscModule.h>
00046 #include <syn/Module/SplitterModule.h>
00047 #include <syn/Module/WaveTableOscModule.h>
00048 #include <syn/Module/InstrumentModule.h>
00049 
00050 #include <syn/xmlpp/xmlpp.h>
00051 
00055 namespace syn
00056 {
00060    class ModuleFactory : syn::Singleton<ModuleFactory>
00061    {
00062    public:
00063       ModuleFactory()
00064       {
00065          // just some defaults, in the future these may be dynamically loaded.
00066          // if you're extending subsynth with your own modules, 
00067          // you have the option to edit this (bad), or to call reg 
00068          // externally from your own application (good).
00069 
00070          // modules
00071          this->reg( "Sink", DummyOutputModule() );
00072          this->reg( "Filter", FilterModule() );
00073          this->reg( "IStream", IStreamModule() );
00074          this->reg( "Mixer", MixerModule() );
00075          this->reg( "OpenALSink", OpenALOutputModule() );
00076          this->reg( "Splitter", SplitterModule() );
00077          this->reg( "WaveTableOsc", WaveTableOscModule() );
00078 
00079          // operators
00080          this->reg( "Add", AddModule() );
00081          this->reg( "Mult", MultModule() );
00082          this->reg( "Copy", CopyModule() );
00083 
00084          // osc
00085          this->reg( "TriangleOsc", TriangleOscModule() );
00086          this->reg( "WhiteNoiseOsc", WhiteNoiseOscModule() );
00087          this->reg( "PinkNoiseOsc", PinkNoiseOscModule() );
00088          this->reg( "SineOsc", SineOscModule() );
00089          this->reg( "SquareOsc", SquareOscModule() );
00090          this->reg( "AdsrOsc", AdsrOscModule() );
00091       }
00092 
00096       void reg( std::string typeName, const Module& proto )
00097       {
00098          mPrototypes[typeName] = proto.clone();
00099       }
00100 
00102       void unreg( std::string typeName )
00103       {
00104          mPrototypes.erase( typeName );
00105       }
00106 
00112       bool create( std::string typeName, Module* &newModule )
00113       {
00114          if (mPrototypes.count( typeName ) > 0)
00115          {
00116             newModule = mPrototypes[typeName]->clone();
00117             return true;
00118          }
00119          return false;
00120       }
00121 
00122    private:
00123       // each module prototype knows how to clone itself
00124       std::map<std::string, Module*> mPrototypes;
00125    };
00126 
00127 } // end namespace
00128 
00129 #endif

Generated at Mon Apr 15 09:26:06 2002 for subsynth by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001