Mozzi  version 2016-12-11-17:03
sound synthesis library for Arduino
AutoMap.h
1 /*
2  * AutoMap.h
3  *
4  * Copyright 2012 Tim Barrass.
5  *
6  * This file is part of Mozzi.
7  *
8  * Mozzi is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
9  *
10  */
11 
12 #ifndef AUTOMAP_H_
13 #define AUTOMAP_H_
14 
15 // for map - maybe rewrite my own templated map for better efficiency
16 #if ARDUINO >= 100
17  #include "Arduino.h" // for map
18 #else
19  #include "WProgram.h"
20 #endif
21 
22 #include "AutoRange.h"
23 
28 class AutoMap : public AutoRange<int>
29 {
30 public:
35  AutoMap(int min_expected, int max_expected, int map_to_min, int map_to_max)
36  : inherited(min_expected,max_expected),map_min(map_to_min), map_max(map_to_max)
37  {
38  }
39 
40 
46  inline
47  int next(int n){
48  inherited::next(n);
49  return map(n,inherited::getMin(),inherited::getMax(),map_min,map_max);
50  }
51 
57  inline
58  int operator()(int n) {
59  return next(n);
60  }
61 
62 private:
63  typedef AutoRange <int> inherited;
64  int map_min, map_max;
65 };
66 
67 
73 #endif // #ifndef AUTOMAP_H_
74 
int next(int n)
Process the next value and return it mapped to the range which was set in the constructor.
Definition: AutoMap.h:47
int operator()(int n)
Process the next value and return it mapped to the range which was set in the constructor.
Definition: AutoMap.h:58
Automatically map an input value to an output range without knowing the precise range of inputs befor...
Definition: AutoMap.h:28
int getMax()
Returns the current maximum.
Definition: AutoRange.h:57
int getMin()
Returns the current minimum.
Definition: AutoRange.h:49
Keeps a running calculation of the range of the input values it receives.
Definition: AutoRange.h:18
AutoMap(int min_expected, int max_expected, int map_to_min, int map_to_max)
Constructor.
Definition: AutoMap.h:35
void next(int n)
Updates the current range.
Definition: AutoRange.h:34