forked from musescore/MuseScore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeMap.h
113 lines (90 loc) · 3.17 KB
/
changeMap.h
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
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2009-2019 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#ifndef __CHANGEMAP_H__
#define __CHANGEMAP_H__
#include <QMultiMap>
#include "fraction.h"
/**
\file
Definition of class ChangeMap.
*/
namespace Ms {
enum class ChangeMethod : signed char {
NORMAL,
EXPONENTIAL,
EASE_IN,
EASE_OUT,
EASE_IN_OUT // and shake it all about
};
enum class ChangeDirection : signed char {
INCREASING,
DECREASING
};
//---------------------------------------------------------
/// ChangeEvent
/// item in ChangeMap
//---------------------------------------------------------
enum class ChangeEventType : char {
FIX, RAMP, INVALID
};
class ChangeEvent
{
int value { 0 };
ChangeEventType type { ChangeEventType::INVALID };
Fraction length;
ChangeMethod method { ChangeMethod::NORMAL };
ChangeDirection direction { ChangeDirection::INCREASING };
int cachedStartVal { -1 };
int cachedEndVal { -1 };
public:
ChangeEvent() {}
ChangeEvent(int vel)
: value(vel), type(ChangeEventType::FIX) {}
ChangeEvent(Fraction s, Fraction e, int diff, ChangeMethod m, ChangeDirection d)
: value(diff), type(ChangeEventType::RAMP), length(e - s), method(m), direction(d) {}
bool operator==(const ChangeEvent& event) const;
bool operator!=(const ChangeEvent& event) const { return !(operator==(event)); }
friend class ChangeMap;
};
//---------------------------------------------------------
// ChangeMap
/// List of changes in a value.
//---------------------------------------------------------
typedef std::vector<std::pair<Fraction, Fraction> > EndPointsVector;
class ChangeMap : public QMultiMap<Fraction, ChangeEvent>
{
bool cleanedUp { false };
static const int DEFAULT_VALUE { 80 }; // TODO
struct ChangeMethodItem {
ChangeMethod method;
const char* name;
};
static bool compareRampEvents(ChangeEvent& a, ChangeEvent& b) { return a.length > b.length; }
void cleanupStage0();
void cleanupStage1();
void cleanupStage2(std::vector<bool>& startsInRamp, EndPointsVector& endPoints);
void cleanupStage3();
public:
ChangeMap() {}
int val(Fraction tick);
std::vector<std::pair<Fraction, Fraction> > changesInRange(Fraction stick, Fraction etick);
void addFixed(Fraction tick, int value);
void addRamp(Fraction stick, Fraction etick, int change, ChangeMethod method, ChangeDirection direction);
void cleanup();
void dump();
static int interpolate(Fraction& eventTick, ChangeEvent& event, Fraction& tick);
static QString changeMethodToName(ChangeMethod method);
static ChangeMethod nameToChangeMethod(QString name);
static const std::vector<ChangeMethodItem> changeMethodTable;
};
} // namespace Ms
#endif