/usr/include/CLAM/Mapping.hxx is in libclam-dev 1.4.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | /*
* Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
* UNIVERSITAT POMPEU FABRA
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef _Mapping_
#define _Mapping_
#include "CLAM_Math.hxx"
#include <string>
#include <vector>
#include "DataTypes.hxx"
#include "Array.hxx"
namespace CLAM {
class MappingFactory;
class Mapping
{
friend class MappingFactory;
typedef std::vector<MappingFactory*> MappingFactories;
private:
static MappingFactories& FactoryInstance();
public:
virtual TData Map(const TData in) = 0;
static Mapping* Create(const std::string& name);
virtual void Set(DataArray& arguments) { }
virtual ~Mapping();
};
class MappingFactory
{
friend class Mapping;
private:
std::string mName;
public:
MappingFactory(const std::string& name)
:mName(name)
{
}
void AddMe(void);
virtual Mapping* Create(void) = 0;
virtual ~MappingFactory()
{
}
};
class ValueToRatioMapping:public Mapping
{
private:
TData mSemitones ;
public:
ValueToRatioMapping()
{
}
void Set( const TData& inSemitones )
{
mSemitones = inSemitones ;
}
TData Map( const TData inValue )
{
return ( TData(pow( 2. , ( ( mSemitones / 12. ) * ( ( inValue - 8192. ) / 8192. ) ) )) ) ;
}
void Set(DataArray& arguments)
{
CLAM_ASSERT( arguments.Size() == 1,
"Not enough arguments for ValueToRatioMapping" );
Set( arguments[0] ) ;
}
};
class ValueToRatioMappingFactory:public MappingFactory
{
public:
static ValueToRatioMappingFactory sSingleton ;
ValueToRatioMappingFactory():MappingFactory( "ValueToRatio" )
{
AddMe() ;
}
Mapping* Create(void) { return new ValueToRatioMapping; }
};
class NoteToFreqMapping:public Mapping
{
private:
TData mNoteRef ;
TData mFrequencyRef ;
public:
NoteToFreqMapping()
{
}
void Set(
const TData& inNoteRef,
const TData& inFrequencyRef )
{
mNoteRef = inNoteRef ;
mFrequencyRef = inFrequencyRef ;
}
TData Map( const TData inNote )
{
return ( TData( pow( 2.0 , ( inNote - mNoteRef ) / 12.0 ) ) ) * mFrequencyRef ;
}
void Set(DataArray& arguments)
{
if ( arguments.Size() == 0 )
{
// no arguments have been specified, so use the default values:
// reference a 440 Hz at midi note 69
Set(69,440);
}else
{
CLAM_ASSERT(arguments.Size() == 2,
"Not enough arguments for NoteToFreqMapping" );
Set( arguments[0], arguments[1] ) ;
}
}
};
class NoteToFreqMappingFactory:public MappingFactory
{
public:
static NoteToFreqMappingFactory sSingleton ;
NoteToFreqMappingFactory():MappingFactory( "NoteToFreq" )
{
AddMe() ;
}
Mapping* Create(void) { return new NoteToFreqMapping; }
};
class LinearMapping:public Mapping
{
private:
TData mInOffset,mOutOffset,mScale;
public:
LinearMapping()
{
mInOffset = 0;
mOutOffset = 0;
mScale = 1;
}
void Set(
const TData& inA,const TData& inB,
const TData& outA,const TData& outB)
{
mInOffset = inA;
mOutOffset = outA;
mScale = (outB-outA)/(inB-inA);
}
TData Map(const TData in)
{
return mOutOffset+(in-mInOffset)*mScale;
}
void Set(DataArray& arguments)
{
CLAM_ASSERT(arguments.Size()==4,
"Not enough arguments for LinearMapping");
Set(arguments[0],arguments[1],arguments[2],arguments[3]);
}
};
class LinearMappingFactory:public MappingFactory
{
public:
static LinearMappingFactory sSingleton;
LinearMappingFactory():MappingFactory("linear")
{
AddMe();
}
Mapping* Create(void) { return new LinearMapping; }
};
}
#endif
|