-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotation_volume.hpp
More file actions
116 lines (93 loc) · 2.79 KB
/
notation_volume.hpp
File metadata and controls
116 lines (93 loc) · 2.79 KB
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
114
115
116
#ifndef SGR_NOTATION_VOLUME_HPP
#define SGR_NOTATION_VOLUME_HPP
/**
* @file notation_volume.hpp
* Implements the sgr::notation::volume namespace.
*
* @author Gašper Ažman, gasper.azman@gmail.com
* @since 2012-01-31
*/
#include "scalars.hpp"
#include <memory>
namespace sgr {
namespace notation {
namespace volume {
/* forward declarations */
struct simple;
struct fade;
/* interfaces */
struct volume_visitor {
virtual void visit(const simple& s) = 0;
virtual void visit(const fade& s) = 0;
virtual ~volume_visitor() {}
};
struct volume {
/// volume pointer type
typedef std::shared_ptr<const volume> pointer_type;
virtual void accept(volume_visitor& vis) const = 0;
virtual ~volume() {}
};
/* ################
* volume volumes
* ################ */
/**
* Simple volume volume - does nothing but provides constant volume throughout
* the tone.
*/
class simple : public volume {
public:
scalars::volume volume;
private:
simple(decltype(volume) volume) : volume{volume} {}
public:
/**
* This is how you create these objects - since they must always be stored
* in a shared pointer.
* @param vol_left the left volume. In the range [0,1].
* @param vol_right the right volume. In the range [0,1].
* @return a std::shared_ptr to the created object. The object is immutable.
*/
static std::shared_ptr<const simple>
create(scalars::volume volume_)
{
return std::shared_ptr<const simple>(new simple(volume_));
}
/// visitor interface implementation.
virtual void accept(volume_visitor& v) const { v.visit(*this); }
/// destructor has to be virtual
virtual ~simple() {}
};
/**
* Fade volume volume - varies the tone volume from start volume to end volume
* linearly.
*/
struct fade : public volume {
scalars::volume start_volume;
scalars::volume end_volume;
private:
fade(scalars::volume start_volume, scalars::volume end_volume)
: start_volume(start_volume)
, end_volume(end_volume)
{}
public:
/**
* This is how you create these objects - since they must always be stored
* in a shared pointer.
* @param vol_left the left volume. In the range [0,1].
* @param vol_right the right volume. In the range [0,1].
* @return a std::shared_ptr to the created object. The object is immutable.
*/
static std::shared_ptr<const fade>
create(scalars::volume start_volume, scalars::volume end_volume)
{
return std::shared_ptr<const fade>(new fade(start_volume, end_volume));
}
/// visitor interface implementation.
virtual void accept(volume_visitor& v) const { v.visit(*this); }
/// destructor has to be virtual
virtual ~fade() {}
};
} /* end namespace volume */
} /* end namespace notation */
} /* end namespace sgr */
#endif