]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/speedquantizer.h
d6dc1acd02cb0ebdc8fab126105d3213a6dea49f
[r2c2.git] / source / libr2c2 / speedquantizer.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2011  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBR2C2_SPEEDQUANTIZER_H_
9 #define LIBR2C2_SPEEDQUANTIZER_H_
10
11 #include <list>
12 #include <vector>
13 #include <msp/datafile/objectloader.h>
14
15 namespace R2C2 {
16
17 class SpeedQuantizer
18 {
19 public:
20         class Loader: public Msp::DataFile::ObjectLoader<SpeedQuantizer>
21         {
22         public:
23                 Loader(SpeedQuantizer &);
24         private:
25                 void step(unsigned, float, float);
26         };
27
28 private:
29         struct SpeedStep
30         {
31                 float speed;
32                 float weight;
33
34                 SpeedStep();
35                 void add(float, float);
36         };
37
38         std::vector<SpeedStep> steps;
39
40 public:
41         SpeedQuantizer(unsigned);
42
43         void learn(unsigned, float, float);
44         float get_speed(unsigned) const;
45         float quantize_speed(float) const;
46         unsigned find_speed_step(float) const;
47
48         void save(std::list<Msp::DataFile::Statement> &) const;
49 };
50
51 } // namespace R2C2
52
53 #endif