-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotation_pitch.hpp
More file actions
103 lines (79 loc) · 2.42 KB
/
notation_pitch.hpp
File metadata and controls
103 lines (79 loc) · 2.42 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
#ifndef SGR_NOTATION_PITCH
#define SGR_NOTATION_PITCH
/**
* @file notation_pitch.hpp
*
*
* @author Gašper Ažman, gasper.azman@gmail.com
* @since 2012-01-31
*/
#include <memory>
#include "units.hpp"
namespace sgr {
namespace notation {
namespace pitch {
// forward declarations
struct constant;
struct linear_slide;
// visitor
struct pitch_visitor {
virtual void visit(const linear_slide& p) = 0;
virtual void visit(const constant& p) = 0;
virtual ~pitch_visitor() {}
};
/// Abstract base class for pitch envelopes.
struct pitch {
typedef std::shared_ptr<const pitch> pointer_type;
/// visitor interface
virtual void accept(pitch_visitor& vis) const = 0;
virtual ~pitch() {}
};
// ###############
// PITCH ENVELOPES
// ###############
/**
* Implements a constant pitch envelope.
*/
struct constant : public pitch {
typedef std::shared_ptr<const constant> pointer_type;
/// Pitch, in halftones from a440.
units::tone pitch;
/// create new pitch envelopes through this function.
/// @param pitch the pitch of the note, in halftone offsets from a440.
/// @return a new constant pitch object.
static pointer_type
create(decltype(pitch) pitch) { return pointer_type(new constant(pitch)); }
/// visitor implementation
void accept(pitch_visitor& vis) const { vis.visit(*this); }
/// Virtual destructor.
virtual ~constant() {}
private:
constant(decltype(pitch) pitch) : pitch(pitch) {}
};
/**
* Implements a linear_slide pitch envelope.
*/
struct linear_slide : public pitch {
typedef std::shared_ptr<const linear_slide> pointer_type;
units::tone start_pitch;
units::tone end_pitch;
/// create new pitch envelopes through this function.
/// @param pitch the pitch of the note, in halftone offsets from a440.
/// @return a new linear_slide pitch object.
static pointer_type
create(decltype(start_pitch) start_pitch, decltype(end_pitch) end_pitch) {
return pointer_type(new linear_slide(start_pitch, end_pitch));
}
/// visitor implementation
void accept(pitch_visitor& vis) const { vis.visit(*this); }
/// Virtual destructor.
virtual ~linear_slide() {}
private:
linear_slide(decltype(start_pitch) start_pitch, decltype(end_pitch) end_pitch)
: start_pitch{start_pitch}, end_pitch{end_pitch}
{}
};
} /* end namespace pitch */
} /* end namespace notation */
} /* end namespace sgr */
#endif