Inner Metric Analysis code
 All Classes Namespaces Functions Variables Typedefs Pages
InnerMetricAnalysis.hpp
1 #ifndef INNERMETRICANALYSIS_378_1372
2 #define INNERMETRICANALYSIS_378_1372
3 
4 // Author: Geert-Jan Giezeman <geert@cs.uu.nl>
5 // Copyright: Utrecht University, 2014
6 
7 //#include <memory>
8 #include <vector>
9 #include <algorithm>
10 
12 namespace InnerMetricAnalysis
13 {
14 
17  typedef unsigned long Time;
18 
21  typedef unsigned long Weight;
22 
24  struct TimeWeight {
31  };
32 
36  struct Meter {
42  int repeats;
44  Meter() {}
46  Meter(Time s, Time p, int r)
47  :start(s),period(p),repeats(r) {}
48  };
49 
51  class ComputerDetail;
52 
56  unsigned long pos;
57  };
58 
60 
64  class Computer {
65  public:
67  ~Computer();
70  {
71  init();
72  }
74 
79  template <typename TimeIter>
80  Computer(TimeIter begin, TimeIter end)
81  {
82  init();
83  setData(begin,end);
84  }
85 
87 
92  template <typename TimeIter>
93  void setData(TimeIter begin, TimeIter end)
94  {
95  addReserve(std::distance(begin,end));
96  std::for_each (begin, end, [this](Time t){this->addOne(t);});
97  addDone();
98  }
100 
109  Time getMinPeriod() const;
113  std::vector<Time> getGrid() const;
115  std::vector<Time> getOnsets() const;
119  std::vector<Meter> getMeters(int l=-1) const;
123  std::vector<Weight> getMetricWeights1(int p=2, int l=-1) const;
127  std::vector<TimeWeight> getMetricWeights2(int p=2, int l=-1) const;
131  std::vector<Weight> getSpectralWeights1(int p=2, int l=-1) const;
135  std::vector<TimeWeight> getSpectralWeights2(int p=2, int l=-1) const;
137 
145  std::vector<Weight>
146  getDieoutWeights1(double d=1.0, int p=2, int l=-1) const;
148 
151  std::vector<TimeWeight>
152  getDieoutWeights2(double d=1.0, int p=2, int l=-1) const;
154 
157  std::vector<Weight>
158  getSymOutWeights1(double d=1.0, int p=2, int l=-1) const;
160 
163  std::vector<TimeWeight>
164  getSymOutWeights2(double d=1.0, int p=2, int l=-1) const;
165  private:
166  ComputerDetail *detail;
167  void init();
168  void addReserve(size_t n);
169  void addOne(Time t);
170  void addDone();
171  };
172 
173 }
174 
175 // vim:set shiftwidth=4 softtabstop=4 expandtab cindent:
176 #endif // INNERMETRICANALYSIS_378_1372
Time period
Interval between onsets.
Definition: InnerMetricAnalysis.hpp:40
std::vector< Weight > getMetricWeights1(int p=2, int l=-1) const
Get the metric weights for all onsets.
std::vector< TimeWeight > getSymOutWeights2(double d=1.0, int p=2, int l=-1) const
Get the symmetric dieout weights on the grid.
Meter(Time s, Time p, int r)
Initialization with start, period and repeats.
Definition: InnerMetricAnalysis.hpp:46
std::vector< TimeWeight > getSpectralWeights2(int p=2, int l=-1) const
Get the spectral weights on the grid.
std::vector< Weight > getSpectralWeights1(int p=2, int l=-1) const
Get the spectral weights for the grid.
std::vector< Time > getGrid() const
Returns the grid.
std::vector< Meter > getMeters(int l=-1) const
Return the meters associated with these onsets.
unsigned long Weight
Definition: InnerMetricAnalysis.hpp:21
Error class that is thrown if the onsets are not in increasing order.
Definition: InnerMetricAnalysis.hpp:54
void setData(TimeIter begin, TimeIter end)
Set the note onsets.
Definition: InnerMetricAnalysis.hpp:93
Time getMinPeriod() const
Get the grid interval period.
std::vector< Time > getOnsets() const
Returns the onsets as set with setData.
Meter()
Default initialization (undefined meter)
Definition: InnerMetricAnalysis.hpp:44
std::vector< Weight > getDieoutWeights1(double d=1.0, int p=2, int l=-1) const
Get the dieout weights for the grid.
Time start
First onset.
Definition: InnerMetricAnalysis.hpp:38
Computer(TimeIter begin, TimeIter end)
Constructor taking note onsets.
Definition: InnerMetricAnalysis.hpp:80
Time time
The onset time.
Definition: InnerMetricAnalysis.hpp:26
unsigned long Time
Definition: InnerMetricAnalysis.hpp:17
A class for performing Inner Metric Analysis computations.
Definition: InnerMetricAnalysis.hpp:64
std::vector< TimeWeight > getMetricWeights2(int p=2, int l=-1) const
Get the metric weights and onsets.
Struct that contains an onset and a weight.
Definition: InnerMetricAnalysis.hpp:24
A meter is a number of onsets at a regular interval.
Definition: InnerMetricAnalysis.hpp:36
TimeWeight(Time t, Weight w)
Constructor taking onset time and weight.
Definition: InnerMetricAnalysis.hpp:30
std::vector< TimeWeight > getDieoutWeights2(double d=1.0, int p=2, int l=-1) const
Get the dieout weights on the grid.
Computer()
Default constructor.
Definition: InnerMetricAnalysis.hpp:69
int repeats
The number of onsets.
Definition: InnerMetricAnalysis.hpp:42
std::vector< Weight > getSymOutWeights1(double d=1.0, int p=2, int l=-1) const
Get the symmetric dieout weights on the grid.
unsigned long pos
The number of the offending onset (0-based).
Definition: InnerMetricAnalysis.hpp:56
Weight weight
The weight of the onset.
Definition: InnerMetricAnalysis.hpp:28