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/Module/SplitterModule.cpp

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: SplitterModule.cpp,v $
00026  * Date modified: $Date: 2002/02/16 19:24:16 $
00027  * Version:       $Revision: 1.12 $
00028  * -----------------------------------------------------------------
00029  *
00030  ****************** <SYN heading END do not edit this line> ******************/
00031 #include "syn/Module/SplitterModule.h"
00032 
00033 namespace syn
00034 {
00035    SplitterModule::SplitterModule() : Module(), mPutCount( 0 ), mIsOpen( false )
00036    {
00037       mTerminal = this->createInput( "input" );
00038       this->createOutput( "output1" );
00039       this->createOutput( "output2" );
00040    }
00041 
00042    bool SplitterModule::open()
00043    {
00044       mIsOpen = true;
00045       return mIsOpen;
00046    }
00047    
00048    void SplitterModule::close()
00049    {
00050       mIsOpen = false;
00051    }
00052    
00053    bool SplitterModule::isOutputHigh()
00054    {
00055       std::map<std::string, TerminalPtr>::iterator output_itr;
00056       for (output_itr = this->outputs().begin(); output_itr != this->outputs().end(); ++output_itr)
00057       {
00058          TerminalPtr output_term = (*output_itr).second;
00059          if (output_term->high())
00060             return true;
00061       }
00062       return false;
00063    }   
00064    
00065    void SplitterModule::setDoneState( bool state )
00066    {
00067       std::map<std::string, TerminalPtr>::iterator output_itr;
00068       for (output_itr = this->outputs().begin(); output_itr != this->outputs().end(); ++output_itr)
00069       {
00070          TerminalPtr output_term = (*output_itr).second;
00071          output_term->setDone( state );
00072       }
00073    }   
00074    
00075    void SplitterModule::update()
00076    {
00077       //std::cout<<"SplitterModule::update()\n"<<std::flush;
00078 
00079       // if input queue is empty, or one of the outputs can't 
00080       // recieve any more, then nothing to do, return...
00081       if (mTerminal->empty() || isOutputHigh()) 
00082       {
00083          this->setDoneState( mTerminal->done() );
00084          return;
00085       }
00086       
00087       SampleBuffer1f* read_buf = mTerminal->front();
00088       mPutCount = read_buf->size();
00089       
00090       // for each output term, blit the input data to it
00091       std::map<std::string, TerminalPtr>::iterator output_itr;
00092       for (output_itr = this->outputs().begin(); output_itr != this->outputs().end(); ++output_itr)
00093       {
00094          TerminalPtr output_term = (*output_itr).second;
00095          SampleBuffer1f* write_buf = NULL;
00096          SampleBufferRepos::instance()->take( write_buf );
00097 
00098          // transfer the data to the output terminal
00099          (*write_buf) = (*read_buf);
00100          output_term->push( write_buf );
00101       }
00102       
00103       SampleBufferRepos::instance()->putback( read_buf );
00104       mTerminal->pop();
00105 
00106       // always propogate the done state to the appropriate outputs 
00107       this->setDoneState( mTerminal->done() );
00108    }
00109 
00110 }// end of namespace

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