wavefile 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -23
- data/README.markdown +27 -43
- data/lib/wavefile.rb +4 -1
- data/lib/wavefile/buffer.rb +7 -5
- data/lib/wavefile/chunk_readers.rb +1 -2
- data/lib/wavefile/chunk_readers/base_chunk_reader.rb +13 -0
- data/lib/wavefile/chunk_readers/data_chunk_reader.rb +12 -3
- data/lib/wavefile/chunk_readers/format_chunk_reader.rb +2 -10
- data/lib/wavefile/chunk_readers/riff_reader.rb +73 -26
- data/lib/wavefile/chunk_readers/sample_chunk_reader.rb +74 -0
- data/lib/wavefile/format.rb +13 -9
- data/lib/wavefile/reader.rb +15 -7
- data/lib/wavefile/sampler_info.rb +162 -0
- data/lib/wavefile/sampler_loop.rb +142 -0
- data/lib/wavefile/smpte_timecode.rb +61 -0
- data/lib/wavefile/writer.rb +7 -1
- data/test/fixtures/wave/invalid/data_chunk_ends_after_chunk_id.wav +0 -0
- data/test/fixtures/wave/invalid/data_chunk_has_incomplete_chunk_size.wav +0 -0
- data/test/fixtures/wave/invalid/data_chunk_truncated.wav +0 -0
- data/test/fixtures/wave/invalid/format_chunk_after_data_chunk.wav +0 -0
- data/test/fixtures/wave/invalid/incomplete_riff_format.wav +0 -0
- data/test/fixtures/wave/invalid/incomplete_riff_header.wav +1 -1
- data/test/fixtures/wave/invalid/no_format_chunk_size.wav +0 -0
- data/test/fixtures/wave/invalid/no_riff_format.wav +0 -0
- data/test/fixtures/wave/invalid/riff_chunk_has_incomplete_chunk_size.wav +1 -0
- data/test/fixtures/wave/invalid/smpl_chunk_empty.wav +0 -0
- data/test/fixtures/wave/invalid/smpl_chunk_fields_out_of_range.wav +0 -0
- data/test/fixtures/wave/invalid/smpl_chunk_loop_count_too_high.wav +0 -0
- data/test/fixtures/wave/invalid/smpl_chunk_truncated_sampler_specific_data.wav +0 -0
- data/test/fixtures/wave/invalid/truncated_smpl_chunk.wav +0 -0
- data/test/fixtures/wave/unsupported/bad_audio_format.wav +0 -0
- data/test/fixtures/wave/unsupported/bad_sample_rate.wav +0 -0
- data/test/fixtures/wave/unsupported/extensible_unsupported_subformat_guid.wav +0 -0
- data/test/fixtures/wave/unsupported/unsupported_audio_format.wav +0 -0
- data/test/fixtures/wave/unsupported/unsupported_bits_per_sample.wav +0 -0
- data/test/fixtures/wave/valid/valid_mono_pcm_16_44100_junk_chunk_final_chunk_missing_padding_byte.wav +0 -0
- data/test/fixtures/wave/valid/valid_mono_pcm_16_44100_junk_chunk_with_padding_byte.wav +0 -0
- data/test/fixtures/wave/valid/valid_mono_pcm_8_44100_with_padding_byte.wav +0 -0
- data/test/fixtures/wave/valid/valid_with_sample_chunk_after_data_chunk.wav +0 -0
- data/test/fixtures/wave/valid/valid_with_sample_chunk_after_data_chunk_and_data_chunk_has_padding_byte.wav +0 -0
- data/test/fixtures/wave/valid/valid_with_sample_chunk_before_data_chunk.wav +0 -0
- data/test/fixtures/wave/valid/valid_with_sample_chunk_no_loops.wav +0 -0
- data/test/fixtures/wave/valid/valid_with_sample_chunk_with_extra_unused_bytes.wav +0 -0
- data/test/fixtures/wave/valid/valid_with_sample_chunk_with_sampler_specific_data.wav +0 -0
- data/test/format_test.rb +4 -4
- data/test/reader_test.rb +266 -8
- data/test/sampler_info_test.rb +314 -0
- data/test/sampler_loop_test.rb +215 -0
- data/test/smpte_timecode_test.rb +103 -0
- data/test/writer_test.rb +1 -1
- metadata +30 -6
- data/lib/wavefile/chunk_readers/generic_chunk_reader.rb +0 -15
- data/lib/wavefile/chunk_readers/riff_chunk_reader.rb +0 -19
@@ -0,0 +1,314 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'wavefile.rb'
|
3
|
+
|
4
|
+
include WaveFile
|
5
|
+
|
6
|
+
class SamplerInfoTest < Minitest::Test
|
7
|
+
VALID_32_BIT_INTEGER_TEST_VALUES = [0, 10, 4_294_967_295]
|
8
|
+
INVALID_32_BIT_INTEGER_TEST_VALUES = ["dsfsfsdf", :foo, -1, 4_294_967_296, 2.5, 2.0, [10], nil]
|
9
|
+
|
10
|
+
def test_missing_keywords
|
11
|
+
assert_raises(ArgumentError) { SamplerInfo.new }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_valid_manufacturer_id
|
15
|
+
VALID_32_BIT_INTEGER_TEST_VALUES.each do |valid_value|
|
16
|
+
sampler_info = SamplerInfo.new(manufacturer_id: valid_value,
|
17
|
+
product_id: 0,
|
18
|
+
sample_nanoseconds: 22675,
|
19
|
+
midi_note: 60,
|
20
|
+
fine_tuning_cents: 0.0,
|
21
|
+
smpte_format: 0,
|
22
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
23
|
+
loops: [],
|
24
|
+
sampler_specific_data: "")
|
25
|
+
|
26
|
+
assert_equal(valid_value, sampler_info.manufacturer_id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_invalid_manufacturer_id
|
31
|
+
INVALID_32_BIT_INTEGER_TEST_VALUES.each do |invalid_value|
|
32
|
+
assert_raises(InvalidSamplerInfoError) do
|
33
|
+
SamplerInfo.new(manufacturer_id: invalid_value,
|
34
|
+
product_id: 0,
|
35
|
+
sample_nanoseconds: 22675,
|
36
|
+
midi_note: 60,
|
37
|
+
fine_tuning_cents: 0.0,
|
38
|
+
smpte_format: 0,
|
39
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
40
|
+
loops: [],
|
41
|
+
sampler_specific_data: "")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_valid_product_id
|
47
|
+
VALID_32_BIT_INTEGER_TEST_VALUES.each do |valid_value|
|
48
|
+
sampler_info = SamplerInfo.new(manufacturer_id: 0,
|
49
|
+
product_id: valid_value,
|
50
|
+
sample_nanoseconds: 22675,
|
51
|
+
midi_note: 60,
|
52
|
+
fine_tuning_cents: 0.0,
|
53
|
+
smpte_format: 0,
|
54
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
55
|
+
loops: [],
|
56
|
+
sampler_specific_data: "")
|
57
|
+
|
58
|
+
assert_equal(valid_value, sampler_info.product_id)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_invalid_product_id
|
63
|
+
INVALID_32_BIT_INTEGER_TEST_VALUES.each do |invalid_value|
|
64
|
+
assert_raises(InvalidSamplerInfoError) do
|
65
|
+
SamplerInfo.new(manufacturer_id: 0,
|
66
|
+
product_id: invalid_value,
|
67
|
+
sample_nanoseconds: 22675,
|
68
|
+
midi_note: 60,
|
69
|
+
fine_tuning_cents: 0.0,
|
70
|
+
smpte_format: 0,
|
71
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
72
|
+
loops: [],
|
73
|
+
sampler_specific_data: "")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_valid_sample_nanoseconds
|
79
|
+
VALID_32_BIT_INTEGER_TEST_VALUES.each do |valid_value|
|
80
|
+
sampler_info = SamplerInfo.new(manufacturer_id: 0,
|
81
|
+
product_id: 0,
|
82
|
+
sample_nanoseconds: valid_value,
|
83
|
+
midi_note: 60,
|
84
|
+
fine_tuning_cents: 0.0,
|
85
|
+
smpte_format: 0,
|
86
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
87
|
+
loops: [],
|
88
|
+
sampler_specific_data: "")
|
89
|
+
|
90
|
+
assert_equal(valid_value, sampler_info.sample_nanoseconds)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_invalid_sample_nanoseconds
|
95
|
+
INVALID_32_BIT_INTEGER_TEST_VALUES.each do |invalid_value|
|
96
|
+
assert_raises(InvalidSamplerInfoError) do
|
97
|
+
SamplerInfo.new(manufacturer_id: 0,
|
98
|
+
product_id: 0,
|
99
|
+
sample_nanoseconds: invalid_value,
|
100
|
+
midi_note: 60,
|
101
|
+
fine_tuning_cents: 0.0,
|
102
|
+
smpte_format: 0,
|
103
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
104
|
+
loops: [],
|
105
|
+
sampler_specific_data: "")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_valid_midi_note
|
111
|
+
VALID_32_BIT_INTEGER_TEST_VALUES.each do |valid_value|
|
112
|
+
sampler_info = SamplerInfo.new(manufacturer_id: 0,
|
113
|
+
product_id: 0,
|
114
|
+
sample_nanoseconds: 22675,
|
115
|
+
midi_note: valid_value,
|
116
|
+
fine_tuning_cents: 0.0,
|
117
|
+
smpte_format: 0,
|
118
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
119
|
+
loops: [],
|
120
|
+
sampler_specific_data: "")
|
121
|
+
|
122
|
+
assert_equal(valid_value, sampler_info.midi_note)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_invalid_midi_note
|
127
|
+
INVALID_32_BIT_INTEGER_TEST_VALUES.each do |invalid_value|
|
128
|
+
assert_raises(InvalidSamplerInfoError) do
|
129
|
+
SamplerInfo.new(manufacturer_id: 0,
|
130
|
+
product_id: 0,
|
131
|
+
sample_nanoseconds: 0,
|
132
|
+
midi_note: invalid_value,
|
133
|
+
fine_tuning_cents: 0.0,
|
134
|
+
smpte_format: 0,
|
135
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
136
|
+
loops: [],
|
137
|
+
sampler_specific_data: "")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_valid_fine_tuning_cents
|
143
|
+
[0, 0.0, 0.5, 50, 50.0, 50.5, 99.99999999999999, 0.0000000000000001].each do |valid_value|
|
144
|
+
sampler_info = SamplerInfo.new(manufacturer_id: 0,
|
145
|
+
product_id: 0,
|
146
|
+
sample_nanoseconds: 0,
|
147
|
+
midi_note: 60,
|
148
|
+
fine_tuning_cents: valid_value,
|
149
|
+
smpte_format: 0,
|
150
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
151
|
+
loops: [],
|
152
|
+
sampler_specific_data: "")
|
153
|
+
|
154
|
+
assert_equal(valid_value, sampler_info.fine_tuning_cents)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_invalid_fine_tuning_cents
|
159
|
+
["dsfsfsdf", :foo, -1, 4_294_967_296, nil, [50], 100, 100.0, 100.00000000001, -0.0000000000001].each do |invalid_value|
|
160
|
+
assert_raises(InvalidSamplerInfoError) do
|
161
|
+
SamplerInfo.new(manufacturer_id: 0,
|
162
|
+
product_id: 0,
|
163
|
+
sample_nanoseconds: 0,
|
164
|
+
midi_note: 60,
|
165
|
+
fine_tuning_cents: invalid_value,
|
166
|
+
smpte_format: 0,
|
167
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
168
|
+
loops: [],
|
169
|
+
sampler_specific_data: "")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_valid_smpte_format
|
175
|
+
VALID_32_BIT_INTEGER_TEST_VALUES.each do |valid_value|
|
176
|
+
sampler_info = SamplerInfo.new(manufacturer_id: 0,
|
177
|
+
product_id: 0,
|
178
|
+
sample_nanoseconds: 22675,
|
179
|
+
midi_note: 60,
|
180
|
+
fine_tuning_cents: 0.0,
|
181
|
+
smpte_format: valid_value,
|
182
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
183
|
+
loops: [],
|
184
|
+
sampler_specific_data: "")
|
185
|
+
|
186
|
+
assert_equal(valid_value, sampler_info.smpte_format)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_invalid_smpte_format
|
191
|
+
INVALID_32_BIT_INTEGER_TEST_VALUES.each do |invalid_value|
|
192
|
+
assert_raises(InvalidSamplerInfoError) do
|
193
|
+
SamplerInfo.new(manufacturer_id: 0,
|
194
|
+
product_id: 0,
|
195
|
+
sample_nanoseconds: 22675,
|
196
|
+
midi_note: 60,
|
197
|
+
fine_tuning_cents: 0.0,
|
198
|
+
smpte_format: invalid_value,
|
199
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
200
|
+
loops: [],
|
201
|
+
sampler_specific_data: "")
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_valid_smpte_offset
|
207
|
+
smpte_timecode = SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0)
|
208
|
+
|
209
|
+
[smpte_timecode].each do |valid_value|
|
210
|
+
sampler_info = SamplerInfo.new(manufacturer_id: 0,
|
211
|
+
product_id: 0,
|
212
|
+
sample_nanoseconds: 22675,
|
213
|
+
midi_note: 60,
|
214
|
+
fine_tuning_cents: 0.0,
|
215
|
+
smpte_format: 0,
|
216
|
+
smpte_offset: smpte_timecode,
|
217
|
+
loops: [],
|
218
|
+
sampler_specific_data: "")
|
219
|
+
|
220
|
+
assert_equal(valid_value, sampler_info.smpte_offset)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_invalid_smpte_offset
|
225
|
+
smpte_timecode = SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0)
|
226
|
+
|
227
|
+
[1, 1.5, false, ["string"], { key: :value}, [smpte_timecode = SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0), "string"]].each do |invalid_value|
|
228
|
+
assert_raises(InvalidSamplerInfoError) do
|
229
|
+
SamplerInfo.new(manufacturer_id: 0,
|
230
|
+
product_id: 0,
|
231
|
+
sample_nanoseconds: 22675,
|
232
|
+
midi_note: 60,
|
233
|
+
fine_tuning_cents: 0.0,
|
234
|
+
smpte_format: 0,
|
235
|
+
smpte_offset: invalid_value,
|
236
|
+
loops: [],
|
237
|
+
sampler_specific_data: "")
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_valid_loops
|
243
|
+
loop1 = SamplerLoop.new(id: 0, type: :forward, start_sample_frame: 0, end_sample_frame: 0, fraction: 0.0, play_count: 1)
|
244
|
+
loop2 = SamplerLoop.new(id: 0, type: :forward, start_sample_frame: 0, end_sample_frame: 0, fraction: 0.0, play_count: 1)
|
245
|
+
|
246
|
+
[[], [loop1], [loop1, loop2]].each do |valid_value|
|
247
|
+
sampler_info = SamplerInfo.new(manufacturer_id: 0,
|
248
|
+
product_id: 0,
|
249
|
+
sample_nanoseconds: 22675,
|
250
|
+
midi_note: 60,
|
251
|
+
fine_tuning_cents: 0.0,
|
252
|
+
smpte_format: 0,
|
253
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
254
|
+
loops: valid_value,
|
255
|
+
sampler_specific_data: "")
|
256
|
+
|
257
|
+
assert_equal(valid_value, sampler_info.loops)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_invalid_loops
|
262
|
+
loop1 = SamplerLoop.new(id: 0, type: :forward, start_sample_frame: 0, end_sample_frame: 0, fraction: 0.0, play_count: 1)
|
263
|
+
|
264
|
+
[1, 1.5, false, ["string"], { key: :value}, [loop1, "string"]].each do |invalid_value|
|
265
|
+
assert_raises(InvalidSamplerInfoError) do
|
266
|
+
SamplerInfo.new(manufacturer_id: 0,
|
267
|
+
product_id: 0,
|
268
|
+
sample_nanoseconds: 22675,
|
269
|
+
midi_note: 60,
|
270
|
+
fine_tuning_cents: 0.0,
|
271
|
+
smpte_format: 0,
|
272
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
273
|
+
loops: invalid_value,
|
274
|
+
sampler_specific_data: "")
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_valid_sampler_specific_data
|
280
|
+
["", "1234"].each do |valid_value|
|
281
|
+
sampler_info = SamplerInfo.new(manufacturer_id: 0,
|
282
|
+
product_id: 0,
|
283
|
+
sample_nanoseconds: 22675,
|
284
|
+
midi_note: 60,
|
285
|
+
fine_tuning_cents: 0.0,
|
286
|
+
smpte_format: 0,
|
287
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
288
|
+
loops: [],
|
289
|
+
sampler_specific_data: valid_value)
|
290
|
+
|
291
|
+
if valid_value.nil?
|
292
|
+
assert_nil(sampler_info.sampler_specific_data)
|
293
|
+
else
|
294
|
+
assert_equal(valid_value, sampler_info.sampler_specific_data)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_invalid_sampler_specific_data
|
300
|
+
[1, 1.5, false, ["string"], { key: :value}].each do |invalid_value|
|
301
|
+
assert_raises(InvalidSamplerInfoError) do
|
302
|
+
SamplerInfo.new(manufacturer_id: 0,
|
303
|
+
product_id: 0,
|
304
|
+
sample_nanoseconds: 22675,
|
305
|
+
midi_note: 60,
|
306
|
+
fine_tuning_cents: 0.0,
|
307
|
+
smpte_format: 0,
|
308
|
+
smpte_offset: SMPTETimecode.new(hours: 0, minutes: 0, seconds: 0, frames: 0),
|
309
|
+
loops: [],
|
310
|
+
sampler_specific_data: invalid_value)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'wavefile.rb'
|
3
|
+
|
4
|
+
include WaveFile
|
5
|
+
|
6
|
+
class SamplerLoopTest < Minitest::Test
|
7
|
+
def test_missing_keywords
|
8
|
+
assert_raises(ArgumentError) { SamplerLoop.new }
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_valid_id
|
12
|
+
[0, 10, 4_294_967_295].each do |valid_value|
|
13
|
+
sampler_loop = SamplerLoop.new(id: valid_value,
|
14
|
+
type: :forward,
|
15
|
+
start_sample_frame: 0,
|
16
|
+
end_sample_frame: 0,
|
17
|
+
fraction: 0.0,
|
18
|
+
play_count: 0)
|
19
|
+
|
20
|
+
assert_equal(valid_value, sampler_loop.id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_invalid_id
|
25
|
+
["dsfsfsdf", :foo, -1, 4_294_967_296, 2.5, 2.0, [10], nil].each do |invalid_value|
|
26
|
+
assert_raises(InvalidSamplerLoopError) do
|
27
|
+
SamplerLoop.new(id: invalid_value,
|
28
|
+
type: :forward,
|
29
|
+
start_sample_frame: 0,
|
30
|
+
end_sample_frame: 0,
|
31
|
+
fraction: 0.0,
|
32
|
+
play_count: 0)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_valid_type
|
38
|
+
[:forward, :alternating, :backward].each do |valid_value|
|
39
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
40
|
+
type: valid_value,
|
41
|
+
start_sample_frame: 0,
|
42
|
+
end_sample_frame: 0,
|
43
|
+
fraction: 0.0,
|
44
|
+
play_count: 0)
|
45
|
+
|
46
|
+
assert_equal(valid_value, sampler_loop.type)
|
47
|
+
end
|
48
|
+
|
49
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
50
|
+
type: 0,
|
51
|
+
start_sample_frame: 0,
|
52
|
+
end_sample_frame: 0,
|
53
|
+
fraction: 0.0,
|
54
|
+
play_count: 0)
|
55
|
+
assert_equal(:forward, sampler_loop.type)
|
56
|
+
|
57
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
58
|
+
type: 1,
|
59
|
+
start_sample_frame: 0,
|
60
|
+
end_sample_frame: 0,
|
61
|
+
fraction: 0.0,
|
62
|
+
play_count: 0)
|
63
|
+
assert_equal(:alternating, sampler_loop.type)
|
64
|
+
|
65
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
66
|
+
type: 2,
|
67
|
+
start_sample_frame: 0,
|
68
|
+
end_sample_frame: 0,
|
69
|
+
fraction: 0.0,
|
70
|
+
play_count: 0)
|
71
|
+
assert_equal(:backward, sampler_loop.type)
|
72
|
+
|
73
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
74
|
+
type: 3,
|
75
|
+
start_sample_frame: 0,
|
76
|
+
end_sample_frame: 0,
|
77
|
+
fraction: 0.0,
|
78
|
+
play_count: 0)
|
79
|
+
assert_equal(3, sampler_loop.type)
|
80
|
+
|
81
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
82
|
+
type: 4_294_967_295,
|
83
|
+
start_sample_frame: 0,
|
84
|
+
end_sample_frame: 0,
|
85
|
+
fraction: 0.0,
|
86
|
+
play_count: 0)
|
87
|
+
assert_equal(4_294_967_295, sampler_loop.type)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_invalid_type
|
91
|
+
["dsfsfsdf", :foo, -1, :alternatin, 4_294_967_296, 2.5, 2.0, [:forward], nil].each do |invalid_value|
|
92
|
+
assert_raises(InvalidSamplerLoopError) do
|
93
|
+
SamplerLoop.new(id: 0,
|
94
|
+
type: invalid_value,
|
95
|
+
start_sample_frame: 0,
|
96
|
+
end_sample_frame: 0,
|
97
|
+
fraction: 0.0,
|
98
|
+
play_count: 0)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_valid_start_sample_frame
|
104
|
+
[0, 10, 4_294_967_295].each do |valid_value|
|
105
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
106
|
+
type: :forward,
|
107
|
+
start_sample_frame: valid_value,
|
108
|
+
end_sample_frame: 0,
|
109
|
+
fraction: 0.0,
|
110
|
+
play_count: 0)
|
111
|
+
|
112
|
+
assert_equal(valid_value, sampler_loop.start_sample_frame)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_invalid_start_sample_frame
|
117
|
+
["dsfsfsdf", :foo, -1, 4_294_967_296, 2.5, 2.0, [10], nil].each do |invalid_value|
|
118
|
+
assert_raises(InvalidSamplerLoopError) do
|
119
|
+
SamplerLoop.new(id: 0,
|
120
|
+
type: :forward,
|
121
|
+
start_sample_frame: invalid_value,
|
122
|
+
end_sample_frame: 0,
|
123
|
+
fraction: 0.0,
|
124
|
+
play_count: 0)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_valid_end_sample_frame
|
130
|
+
[0, 10, 4_294_967_295].each do |valid_value|
|
131
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
132
|
+
type: :forward,
|
133
|
+
start_sample_frame: 0,
|
134
|
+
end_sample_frame: valid_value,
|
135
|
+
fraction: 0.0,
|
136
|
+
play_count: 0)
|
137
|
+
|
138
|
+
assert_equal(valid_value, sampler_loop.end_sample_frame)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_invalid_end_sample_frame
|
143
|
+
["dsfsfsdf", :foo, -1, 4_294_967_296, 2.5, 2.0, [10], nil].each do |invalid_value|
|
144
|
+
assert_raises(InvalidSamplerLoopError) do
|
145
|
+
SamplerLoop.new(id: 0,
|
146
|
+
type: :forward,
|
147
|
+
start_sample_frame: 0,
|
148
|
+
end_sample_frame: invalid_value,
|
149
|
+
fraction: 0.0,
|
150
|
+
play_count: 0)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_valid_fraction
|
156
|
+
[0, 0.0, 0.5, 0.99999999999999, 0.0000000000000001].each do |valid_value|
|
157
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
158
|
+
type: :forward,
|
159
|
+
start_sample_frame: 0,
|
160
|
+
end_sample_frame: 0,
|
161
|
+
fraction: valid_value,
|
162
|
+
play_count: 0)
|
163
|
+
|
164
|
+
assert_equal(valid_value, sampler_loop.fraction)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_invalid_fraction
|
169
|
+
["dsfsfsdf", :foo, -1, 4_294_967_296, 2.5, 2.0, nil, [0.5], 1, 1.0, 1.00000000001, -0.0000000000001].each do |invalid_value|
|
170
|
+
assert_raises(InvalidSamplerLoopError) do
|
171
|
+
SamplerLoop.new(id: 0,
|
172
|
+
type: :forward,
|
173
|
+
start_sample_frame: 0,
|
174
|
+
end_sample_frame: 0,
|
175
|
+
fraction: invalid_value,
|
176
|
+
play_count: 0)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_valid_play_count
|
182
|
+
[10, 4_294_967_295, Float::INFINITY].each do |valid_value|
|
183
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
184
|
+
type: :forward,
|
185
|
+
start_sample_frame: 0,
|
186
|
+
end_sample_frame: 0,
|
187
|
+
fraction: 0.0,
|
188
|
+
play_count: valid_value)
|
189
|
+
|
190
|
+
assert_equal(valid_value, sampler_loop.play_count)
|
191
|
+
end
|
192
|
+
|
193
|
+
sampler_loop = SamplerLoop.new(id: 0,
|
194
|
+
type: :forward,
|
195
|
+
start_sample_frame: 0,
|
196
|
+
end_sample_frame: 0,
|
197
|
+
fraction: 0.0,
|
198
|
+
play_count: 0)
|
199
|
+
|
200
|
+
assert_equal(Float::INFINITY, sampler_loop.play_count)
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_invalid_play_count
|
204
|
+
["dsfsfsdf", :foo, -1, 4_294_967_296, 2.5, 2.0, [10], nil].each do |invalid_value|
|
205
|
+
assert_raises(InvalidSamplerLoopError) do
|
206
|
+
SamplerLoop.new(id: 0,
|
207
|
+
type: :forward,
|
208
|
+
start_sample_frame: 0,
|
209
|
+
end_sample_frame: 0,
|
210
|
+
fraction: 0.0,
|
211
|
+
play_count: invalid_value)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|