1 /*************************************************************************/
2 /* cp_sample.cpp */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /*************************************************************************/
30 #include "cp_sample.h"
31
get_name() const32 const char *CPSample::get_name() const {
33
34 return name;
35 }
set_name(const char * p_name)36 void CPSample::set_name(const char *p_name) {
37
38 if (p_name == NULL) {
39 name[0] = 0;
40 return;
41 }
42
43 bool done = false;
44 for (int i = 0; i < NAME_MAX_LEN; i++) {
45
46 name[i] = done ? 0 : p_name[i];
47 if (!done && p_name[i] == 0)
48 done = true;
49 }
50
51 name[NAME_MAX_LEN - 1] = 0; /* just in case */
52 }
53
set_default_volume(uint8_t p_vol)54 void CPSample::set_default_volume(uint8_t p_vol) {
55
56 default_volume = p_vol;
57 }
get_default_volume() const58 uint8_t CPSample::get_default_volume() const {
59
60 return default_volume;
61 }
62
set_global_volume(uint8_t p_vol)63 void CPSample::set_global_volume(uint8_t p_vol) {
64
65 global_volume = p_vol;
66 }
get_global_volume() const67 uint8_t CPSample::get_global_volume() const {
68
69 return global_volume;
70 }
71
set_pan_enabled(bool p_vol)72 void CPSample::set_pan_enabled(bool p_vol) {
73
74 pan_enabled = p_vol;
75 }
is_pan_enabled() const76 bool CPSample::is_pan_enabled() const {
77
78 return pan_enabled;
79 }
80
set_pan(uint8_t p_pan)81 void CPSample::set_pan(uint8_t p_pan) {
82
83 pan = p_pan;
84 }
get_pan() const85 uint8_t CPSample::get_pan() const {
86
87 return pan;
88 }
89
set_vibrato_type(VibratoType p_vibrato_type)90 void CPSample::set_vibrato_type(VibratoType p_vibrato_type) {
91
92 vibrato_type = p_vibrato_type;
93 }
get_vibrato_type() const94 CPSample::VibratoType CPSample::get_vibrato_type() const {
95
96 return vibrato_type;
97 }
98
set_vibrato_speed(uint8_t p_vibrato_speed)99 void CPSample::set_vibrato_speed(uint8_t p_vibrato_speed) {
100
101 vibrato_speed = p_vibrato_speed;
102 }
get_vibrato_speed() const103 uint8_t CPSample::get_vibrato_speed() const {
104
105 return vibrato_speed;
106 }
107
set_vibrato_depth(uint8_t p_vibrato_depth)108 void CPSample::set_vibrato_depth(uint8_t p_vibrato_depth) {
109
110 vibrato_depth = p_vibrato_depth;
111 }
get_vibrato_depth() const112 uint8_t CPSample::get_vibrato_depth() const {
113
114 return vibrato_depth;
115 }
116
set_vibrato_rate(uint8_t p_vibrato_rate)117 void CPSample::set_vibrato_rate(uint8_t p_vibrato_rate) {
118
119 vibrato_rate = p_vibrato_rate;
120 }
get_vibrato_rate() const121 uint8_t CPSample::get_vibrato_rate() const {
122
123 return vibrato_rate;
124 }
125
set_sample_data(CPSample_ID p_ID)126 void CPSample::set_sample_data(CPSample_ID p_ID) {
127
128 id = p_ID;
129 }
get_sample_data() const130 CPSample_ID CPSample::get_sample_data() const {
131
132 return id;
133 }
134
operator =(const CPSample & p_sample)135 void CPSample::operator=(const CPSample &p_sample) {
136
137 copy_from(p_sample);
138 }
copy_from(const CPSample & p_sample)139 void CPSample::copy_from(const CPSample &p_sample) {
140
141 reset();
142 set_name(p_sample.get_name());
143
144 default_volume = p_sample.default_volume;
145 global_volume = p_sample.global_volume;
146
147 pan_enabled = p_sample.pan_enabled;
148 pan = p_sample.pan;
149
150 vibrato_type = p_sample.vibrato_type;
151 vibrato_speed = p_sample.vibrato_speed;
152 vibrato_depth = p_sample.vibrato_depth;
153 vibrato_rate = p_sample.vibrato_rate;
154
155 if (CPSampleManager::get_singleton() && !p_sample.id.is_null())
156 CPSampleManager::get_singleton()->copy_to(p_sample.id, id);
157 }
158
reset()159 void CPSample::reset() {
160
161 name[0] = 0;
162
163 default_volume = 64;
164 global_volume = 64;
165
166 pan_enabled = false;
167 pan = 32;
168
169 vibrato_type = VIBRATO_SINE;
170 vibrato_speed = 0;
171 vibrato_depth = 0;
172 vibrato_rate = 0;
173
174 if (!id.is_null() && CPSampleManager::get_singleton())
175 CPSampleManager::get_singleton()->destroy(id);
176
177 id = CPSample_ID();
178 }
179
CPSample(const CPSample & p_from)180 CPSample::CPSample(const CPSample &p_from) {
181
182 reset();
183 copy_from(p_from);
184 }
CPSample()185 CPSample::CPSample() {
186
187 reset();
188 }
189
~CPSample()190 CPSample::~CPSample() {
191
192 reset();
193 }
194