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/Core/Module.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: Module.h,v $
00026  * Date modified: $Date: 2002/04/15 07:28:45 $
00027  * Version:       $Revision: 1.36 $
00028  * -----------------------------------------------------------------
00029  *
00030  ****************** <SYN heading END do not edit this line> ******************/
00031 
00032 #ifndef SUBSYNTH_SIGNAL_MODULE_H
00033 #define SUBSYNTH_SIGNAL_MODULE_H
00034 
00035 #include <string>
00036 #include <map>
00037 
00038 #include "syn/Util/AudioFormat.h"
00039 #include "syn/Util/MultivariateType.h"
00040 #include "syn/Core/SampleBufferQueuePtr.h"
00041 #include "syn/Core/Terminal.h"
00042 #include "syn/Core/SampleBufferQueue.h"
00043 #include "syn/Core/SampleBuffer.h"
00044 
00045 #include "syn/Core/ModulePtr.h" // my ptr...
00046 
00058 namespace syn
00059 {
00073    class Module
00074    {
00075    public:
00076        Module (): mName( "Unconfigured Module" ), mPutCount( 0 )
00077        {
00078 //           mPreferredLOD = getMinimumLOD();
00079 //           mScheduledLOD = mPreferredLOD;
00080        }
00081 
00082       virtual ~Module() {}
00083 
00084       virtual void update() = 0;
00085    
00089       virtual bool open() = 0;
00090       virtual void close() = 0;
00091 
00092       /* unique instance name */
00093       virtual void setInstanceName( const std::string& name )
00094       {
00095          mName = name;
00096       }
00097 
00098       virtual std::string getInstanceName() const
00099       {
00100           return mName;
00101       }
00102 
00104       virtual Module* clone() const = 0;
00105 
00108       virtual unsigned int pcount() const { return mPutCount; }
00110 
00114        //virtual LOD getMinimumLOD() 
00115        //{
00116        //    return LOD_LOW;
00117        //}
00118 
00123        //void setPreferredLOD( LOD lod ) 
00124        //{
00125        //    assert( ((int)lod >= 0) && ((int)lod < NUM_LODS) );
00126        //    if ((lod != LOD_DEFAULT) && (lod > getMinimumLOD()))
00127        //    {
00128        //        mPreferredLOD = lod;
00129        //    }
00130        //}
00131 
00132        //LOD getPreferredLOD() 
00133        //{
00134        //    return mPreferredLOD;
00135        //}
00136 
00142        //void setScheduledLOD( LOD lod ) 
00143        //{
00144        //    assert( ((int)lod >= 0) && ((int)lod < NUM_LODS) );
00145        //    if (lod == LOD_DEFAULT)
00146        //    {
00147        //        mScheduledLOD = mPreferredLOD;
00148        //    }
00149        //   else
00150        //    {
00151        //       mScheduledLOD = lod;
00152        //    }
00153        //}
00154 
00155        //LOD getScheduledLOD() 
00156        //{
00157        //    return mScheduledLOD;
00158        //}
00159 
00161       bool isTerminator() { return (mOutputTerminals.size() == 0); }
00162 
00164       bool isInitiator() { return (mInputTerminals.size() == 0); }
00165              
00168       
00173       virtual void getParam( const std::string& key, MultivariateType& value ) = 0;
00174 
00179       virtual void setParam( const std::string& key, const MultivariateType& value ) = 0;
00180 
00184       bool getOutput( const std::string& name, TerminalPtr& output )
00185       {
00186          if (mOutputTerminals.count( name ) != 0)
00187          {
00188             output = mOutputTerminals[name];
00189             return true;
00190          }
00191          else
00192          {
00193             // return something safe...
00194             this->createOutput( name );
00195             output = mOutputTerminals[name];
00196             return true;
00197          }
00198       }
00199 
00203       bool getInput( const std::string& name, TerminalPtr& input )
00204       {
00205          if (mInputTerminals.count( name ) != 0)
00206          {
00207             input = mInputTerminals[name];
00208             return true;
00209          }
00210          else
00211          {
00212             // return something safe...
00213             this->createInput( name );
00214             input = mInputTerminals[name];
00215             return true;
00216          }
00217       }
00218        
00219       std::map<std::string, TerminalPtr>& outputs() { return mOutputTerminals; }
00220       std::map<std::string, TerminalPtr>& inputs() { return mInputTerminals; }
00221 
00223       TerminalPtr  createOutput( const std::string& name );
00224 
00226       TerminalPtr  createInput( const std::string& name );
00227      
00229       void removeOutput( const std::string& name );
00230 
00232       void inputsRemove( const std::string& name );
00233 
00235       
00236    protected:
00237       void setPutCount( int p )
00238       {
00239          mPutCount = p;
00240       }
00241    protected:
00242       std::map<std::string, TerminalPtr>  mOutputTerminals;
00243       std::map<std::string, TerminalPtr>  mInputTerminals;
00244       std::map<std::string, MultivariateType>  mParams;
00245       std::string mName;
00246       unsigned int mPutCount;
00247 
00248        //LOD mPreferredLOD;
00249        //LOD mScheduledLOD;
00250 
00252       /*#  InputTerminal lnkInputTerminal; */
00253 
00255       /*#  OutputTerminal lnkOutputTerminal; */
00256    };
00257    
00259    inline TerminalPtr Module::createOutput( const std::string& name )
00260    {
00261       TerminalPtr term = TerminalPtr( new Terminal( *this, name ) );
00262       term->setName( name );
00263       mOutputTerminals[name] = term;
00264       return term;
00265    }      
00266 
00268    inline TerminalPtr Module::createInput( const std::string& name )
00269    {
00270       TerminalPtr term = TerminalPtr( new Terminal( *this, name ) );
00271       term->setName( name );
00272       mInputTerminals[name] = term;
00273       return term;
00274    }
00275 
00276    inline void Module::removeOutput( const std::string& name )
00277    {
00278       mOutputTerminals.erase( name );
00279    }
00280 
00281    inline void Module::inputsRemove( const std::string& name )
00282    {
00283       mInputTerminals.erase( name );
00284    }
00285 }
00286 
00287 #endif //SUBSYNTH_SIGNAL_MODULE_H

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