linuxsampler 1.0.0

AudioChannel.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   LinuxSampler - modular, streaming capable sampler                     *
00004  *                                                                         *
00005  *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
00006  *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the Free Software           *
00020  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00021  *   MA  02111-1307  USA                                                   *
00022  ***************************************************************************/
00023 
00024 #ifndef __LS_AUDIOCHANNEL_H__
00025 #define __LS_AUDIOCHANNEL_H__
00026 
00027 #include <map>
00028 #include <vector>
00029 #include <string.h>
00030 #include "../../common/global.h"
00031 #include "../../common/Exception.h"
00032 #include "../DeviceParameter.h"
00033 
00034 namespace LinuxSampler {
00035 
00056     class AudioChannel {
00057         public:
00058             class ParameterName : public DeviceRuntimeParameterString {
00059                 public:
00060                     ParameterName(String s) : DeviceRuntimeParameterString(s) {}
00061                     virtual String              Description()           { return "Arbitrary name";      }
00062                     virtual bool                Fix()                   { return false;                 }
00063                     virtual std::vector<String> PossibilitiesAsString() { return std::vector<String>(); }
00064                     virtual void                OnSetValue(String s)    { /* nothing to do */           }
00065             };
00066 
00067             class ParameterIsMixChannel : public DeviceRuntimeParameterBool {
00068                 public:
00069                     ParameterIsMixChannel(bool b) : DeviceRuntimeParameterBool(b) {}
00070                     virtual String Description()                        { return "Whether real channel or mixed to another channel"; }
00071                     virtual bool   Fix()                                { return true;                                               }
00072                     virtual void   OnSetValue(bool b) throw (Exception) { /* cannot happen, as parameter is fix */                   }
00073             };
00074 
00075             class ParameterMixChannelDestination : public DeviceRuntimeParameterInt {
00076                 public:
00077                     ParameterMixChannelDestination(int i) : DeviceRuntimeParameterInt(i) {}
00078                     virtual String           Description()                       { return "Destination channel of this mix channel";                 }
00079                     virtual bool             Fix()                               { return true;                                                      }
00080                     virtual optional<int>    RangeMinAsInt()                     { return optional<int>::nothing; /*TODO: needs to be implemented */ }
00081                     virtual optional<int>    RangeMaxAsInt()                     { return optional<int>::nothing; /*TODO: needs to be implemented */ }
00082                     virtual std::vector<int> PossibilitiesAsInt()                { return std::vector<int>();     /*TODO: needs to be implemented */ }
00083                     virtual void             OnSetValue(int i) throw (Exception) { /*TODO: needs to be implemented */                                }
00084             };
00085 
00086             // attributes
00087             //String Name;  ///< Arbitrary name of this audio channel
00088 
00089             // methods
00090             inline float*        Buffer()     { return pBuffer;      } 
00091             void SetBuffer(float* pBuffer)    { this->pBuffer = pBuffer; }
00092             inline AudioChannel* MixChannel() { return pMixChannel;  } 
00093             inline void          Clear()      { memset(pBuffer, 0, uiBufferSize * sizeof(float)); } 
00094             inline void          Clear(uint Samples) { memset(pBuffer, 0, Samples * sizeof(float)); } 
00095             void CopyTo(AudioChannel* pDst, const uint Samples);
00096             void CopyTo(AudioChannel* pDst, const uint Samples, const float fLevel);
00097             void MixTo(AudioChannel* pDst, const uint Samples);
00098             void MixTo(AudioChannel* pDst, const uint Samples, const float fLevel);
00099             std::map<String,DeviceRuntimeParameter*> ChannelParameters();
00100 
00101             // constructors / destructor
00102             AudioChannel(uint ChannelNr, uint BufferSize);
00103             AudioChannel(uint ChannelNr, float* pBuffer, uint BufferSize);
00104             AudioChannel(uint ChannelNr, AudioChannel* pMixChannelDestination);
00105             virtual ~AudioChannel();
00106         protected:
00107             uint ChannelNr;
00108             std::map<String,DeviceRuntimeParameter*> Parameters;
00109         private:
00110             float*        pBuffer;
00111             uint          uiBufferSize;
00112             AudioChannel* pMixChannel;
00113             bool          UsesExternalBuffer;
00114     };
00115 }
00116 
00117 #endif // __LS_AUDIOCHANNEL_H__