/[svn]/linuxsampler/trunk/src/drivers/DeviceParameterFactory.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/drivers/DeviceParameterFactory.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1049 - (hide annotations) (download) (as text)
Wed Feb 28 06:53:42 2007 UTC (17 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5197 byte(s)
* the ALSA audio output driver parameters now reflect the correct
  parameter value ranges for the respective selected sound card
  (patch by Till Wimmer, a bit fixed and extended)
* bumped version to 0.4.0.4cvs

1 senkov 174 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 1049 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 senkov 174 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_DEVICE_PARAMETER_FACTORY_H__
25     #define __LS_DEVICE_PARAMETER_FACTORY_H__
26    
27     #include <map>
28     #include <vector>
29    
30     #include "../common/global.h"
31     #include "../common/optional.h"
32 schoenebeck 880 #include "../common/Exception.h"
33 senkov 174 #include "DeviceParameter.h"
34    
35     namespace LinuxSampler {
36    
37     class DeviceParameterFactory {
38     public:
39 schoenebeck 1049 typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57)
40    
41 senkov 174 class InnerFactory {
42     public:
43 schoenebeck 1049 InnerFactory(DeviceParameterFactory* pParent) { this->pParent = pParent; }
44     virtual DeviceCreationParameter* Create(std::map<String,String> Parameters = StringMap()) = 0;
45 senkov 174 virtual DeviceCreationParameter* Create(String val) = 0;
46 schoenebeck 1049 protected:
47     DeviceParameterFactory* pParent;
48 senkov 174 };
49    
50     template <class Parameter_T>
51     class InnerFactoryTemplate : public InnerFactory {
52     public:
53 schoenebeck 1049 InnerFactoryTemplate(DeviceParameterFactory* pParent) : InnerFactory(pParent) {}
54    
55     /// Create parameter with respective value in map or use its default value.
56     virtual DeviceCreationParameter* Create(std::map<String,String> Parameters = StringMap()) {
57     const String paramName = Parameter_T::Name();
58     if (Parameters.count(paramName)) {
59     // parameter with this name was specified, so use that given value
60     return new Parameter_T(Parameters[paramName]);
61     }
62     // parameter value not given, use its default value ...
63     // ... but first resolve its dependencies to other parameters
64     Parameter_T param;
65     std::map<String,DeviceCreationParameter*> dependencies = param.DependsAsParameters();
66     std::map<String,String> dependencysParams;
67     for (std::map<String,DeviceCreationParameter*>::iterator iter = dependencies.begin(); iter != dependencies.end(); iter++) {
68     if (Parameters.count(iter->first)) {
69     // value for this dependency parameter already given
70     dependencysParams[iter->first] = Parameters[iter->first];
71     } else {
72     // no value provided for this dependency parameter, use its default value
73     // (FIXME: no sanity check for cyclic dependencies here yet)
74     DeviceCreationParameter* pDependencyParam = pParent->Create(iter->first, Parameters);
75     if (pDependencyParam) {
76     dependencysParams[iter->first] = pDependencyParam->Value();
77     delete pDependencyParam;
78     }
79     }
80     }
81     // now that we resolved all dependencies, we can finally determine parameter's default value
82     optional<String> defaultValue = param.Default(dependencysParams);
83     return (defaultValue) ? new Parameter_T(*defaultValue) : new Parameter_T();
84     }
85     /// Create parameter with given value.
86 senkov 174 virtual DeviceCreationParameter* Create(String val) { return new Parameter_T(val); }
87     };
88    
89     template <class Parameter_T>
90     static void Register(DeviceParameterFactory* factory) {
91 schoenebeck 1049 factory->InnerFactories[Parameter_T::Name()] = new InnerFactoryTemplate<Parameter_T>(factory);
92 senkov 174 }
93    
94     std::map<String,DeviceCreationParameter*> CreateAllParams ( std::map<String,String> Parameters );
95     std::map<String,DeviceCreationParameter*> CreateAllParams ();
96    
97 schoenebeck 1049 DeviceCreationParameter* Create(String ParameterName, std::map<String,String> Parameters = StringMap()) throw (Exception);
98 schoenebeck 880 DeviceCreationParameter* Create(String ParameterName, String val) throw (Exception);
99 senkov 174
100     protected:
101     std::map<String, InnerFactory*> InnerFactories;
102     };
103    
104     } // namespace LinuxSampler
105    
106     #endif // __LS_DEVICE_PARAMETER_FACTORY_H__

  ViewVC Help
Powered by ViewVC