Generate an accompaniement for a given melody
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Utilities.hpp
1 #ifndef UTILITIES_HPP_INCLUDED
2 #define UTILITIES_HPP_INCLUDED
3 
4 #include <string>
5 #include <sstream>
6 #include <vector>
7 
8 #include "Music.hpp"
9 
10 using Number = double;
11 using MachineLearningOutput = std::vector<std::pair<ChordProgression, Number> >;
12 
13 
14 class Time
15 {
16 public :
17  enum Unit {H, MIN, S, MS, US};
18  Time(float v = 0, Unit u = Time::S);
19  Time& operator+=(const Time& o);
20  Time operator+(const Time& o) const;
21  Time& operator/=(float v);
22  Time& operator*=(float v);
23  Time operator/(float v) const;
24  Time operator*(float v) const;
25  float getNumber(Unit u = Time::S) const;
26 private :
27  float number;
28 
29 };
30 
36 std::string getFile(const std::string& str);
37 
38 
39 template<typename T>
40 std::string toString(const T& a)
41 {
42  std::ostringstream o;
43  o<<a;
44  return o.str();
45 }
46 
47 template<typename T>
48 std::vector<std::vector<T> > createAllPossibilities(const std::vector<T>& v, unsigned l)
49 {
50  if(l==0)
51  return std::vector<std::vector<T> >(1, std::vector<T>());
52  auto prec = createAllPossibilities(v, l-1);
53  std::vector<std::vector<T> > res;
54  for(unsigned i=0;i<v.size();i++)
55  {
56  for(unsigned j=0;j<prec.size();j++)
57  {
58  auto tmp(prec[j]);
59  tmp.push_back(v[i]);
60  res.push_back(tmp);
61  }
62  }
63  return res;
64 }
65 
66 
67 
68 
69 MachineLearningOutput getExhaustiveChordProgression(const std::vector<std::string>& c, unsigned size);
70 
71 #endif // UTILITIES_HPP_INCLUDED
This file defines all the data structures related to music objects.
Definition: Utilities.hpp:14