beats 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,203 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
+
3
+ require 'test/includes'
4
+
5
+ class MockTrack < Track
6
+ attr_reader :beats
7
+ end
8
+
9
+ class TrackTest < Test::Unit::TestCase
10
+ SECONDS_IN_MINUTE = 60.0
11
+ SOUND_FILE_PATH = "test/sounds/bass_mono_8.wav"
12
+ W = WaveFile.open(SOUND_FILE_PATH)
13
+
14
+ def generate_test_data
15
+ test_tracks = []
16
+
17
+ test_tracks << MockTrack.new("bass", W.sample_data, "")
18
+ test_tracks << MockTrack.new("bass", W.sample_data, "X")
19
+ test_tracks << MockTrack.new("bass", W.sample_data, "...X")
20
+ test_tracks << MockTrack.new("bass", W.sample_data, "X.X.X.X.")
21
+ test_tracks << MockTrack.new("bass", W.sample_data, "....")
22
+ test_tracks << MockTrack.new("bass", W.sample_data, "..X...X...X...X.X...X...X...X...")
23
+
24
+ return test_tracks
25
+ end
26
+
27
+ def test_initialize
28
+ test_tracks = generate_test_data()
29
+
30
+ assert_equal(test_tracks[0].beats, [0])
31
+ assert_equal(test_tracks[0].name, "bass")
32
+
33
+ assert_equal(test_tracks[1].beats, [0, 1])
34
+ assert_equal(test_tracks[1].name, "bass")
35
+
36
+ assert_equal(test_tracks[2].beats, [3, 1])
37
+ assert_equal(test_tracks[3].beats, [0, 2, 2, 2, 2])
38
+ assert_equal(test_tracks[4].beats, [4])
39
+ assert_equal(test_tracks[5].beats, [2, 4, 4, 4, 2, 4, 4, 4, 4])
40
+ end
41
+
42
+ def test_sample_length
43
+ tick_sample_lengths = [
44
+ W.sample_data.length, # 13860.0
45
+ (W.sample_rate * SECONDS_IN_MINUTE) / 99 / 4, # 6681.81818181818
46
+ (W.sample_rate * SECONDS_IN_MINUTE) / 41 / 4 # 16134.1463414634
47
+ ]
48
+
49
+ tick_sample_lengths.each { |tick_sample_length| helper_test_sample_length(tick_sample_length) }
50
+ end
51
+
52
+ def helper_test_sample_length(tick_sample_length)
53
+ test_tracks = generate_test_data()
54
+
55
+ assert_equal(test_tracks[0].sample_length(tick_sample_length), 0)
56
+ assert_equal(test_tracks[0].sample_length(tick_sample_length), test_tracks[0].sample_data(tick_sample_length)[:primary].length)
57
+
58
+ assert_equal(test_tracks[1].sample_length(tick_sample_length), tick_sample_length.floor)
59
+ assert_equal(test_tracks[1].sample_length(tick_sample_length), test_tracks[1].sample_data(tick_sample_length)[:primary].length)
60
+
61
+ assert_equal(test_tracks[2].sample_length(tick_sample_length), (tick_sample_length * 4).floor)
62
+ assert_equal(test_tracks[2].sample_length(tick_sample_length), test_tracks[2].sample_data(tick_sample_length)[:primary].length)
63
+
64
+ assert_equal(test_tracks[3].sample_length(tick_sample_length), (tick_sample_length * 8).floor)
65
+ assert_equal(test_tracks[3].sample_length(tick_sample_length), test_tracks[3].sample_data(tick_sample_length)[:primary].length)
66
+
67
+ assert_equal(test_tracks[4].sample_length(tick_sample_length), (tick_sample_length * 4).floor)
68
+ assert_equal(test_tracks[4].sample_length(tick_sample_length), test_tracks[4].sample_data(tick_sample_length)[:primary].length)
69
+
70
+ assert_equal(test_tracks[5].sample_length(tick_sample_length), (tick_sample_length * 32).floor)
71
+ assert_equal(test_tracks[5].sample_length(tick_sample_length), test_tracks[5].sample_data(tick_sample_length)[:primary].length)
72
+ end
73
+
74
+ def test_sample_length_with_overflow
75
+ tick_sample_lengths = [
76
+ W.sample_data.length, # 13860.0
77
+ (W.sample_rate * SECONDS_IN_MINUTE) / 99 / 4, # 6681.81818181818
78
+ (W.sample_rate * SECONDS_IN_MINUTE) / 41 / 4 # 16134.1463414634
79
+ ]
80
+
81
+ tick_sample_lengths.each { |tick_sample_length| helper_test_sample_length_with_overflow(tick_sample_length) }
82
+ end
83
+
84
+ def helper_test_sample_length_with_overflow(tick_sample_length)
85
+ wave_sample_length = W.sample_data.length
86
+ test_tracks = generate_test_data()
87
+
88
+ sample_data = test_tracks[0].sample_data(tick_sample_length)
89
+ assert_equal(test_tracks[0].sample_length_with_overflow(tick_sample_length), 0)
90
+ assert_equal(test_tracks[0].sample_length_with_overflow(tick_sample_length), sample_data[:primary].length + sample_data[:overflow].length)
91
+
92
+ sample_data = test_tracks[1].sample_data(tick_sample_length)
93
+ if(wave_sample_length > tick_sample_length * test_tracks[1].beats.last)
94
+ assert_equal(test_tracks[1].sample_length_with_overflow(tick_sample_length), wave_sample_length)
95
+ else
96
+ assert_equal(test_tracks[1].sample_length_with_overflow(tick_sample_length), tick_sample_length.floor)
97
+ assert_equal(test_tracks[1].sample_length_with_overflow(tick_sample_length), sample_data[:primary].length + sample_data[:overflow].length)
98
+ end
99
+
100
+ sample_data = test_tracks[2].sample_data(tick_sample_length)
101
+ if(wave_sample_length > tick_sample_length * test_tracks[2].beats.last)
102
+ assert_equal(test_tracks[2].sample_length_with_overflow(tick_sample_length), (tick_sample_length * 4).floor + (wave_sample_length - tick_sample_length.floor))
103
+ assert_equal(test_tracks[2].sample_length_with_overflow(tick_sample_length), sample_data[:primary].length + sample_data[:overflow].length)
104
+ else
105
+ assert_equal(test_tracks[2].sample_length_with_overflow(tick_sample_length), (tick_sample_length * 4).floor)
106
+ assert_equal(test_tracks[2].sample_length_with_overflow(tick_sample_length), sample_data[:primary].length + sample_data[:overflow].length)
107
+ end
108
+
109
+ sample_data = test_tracks[3].sample_data(tick_sample_length)
110
+ if(wave_sample_length > tick_sample_length * test_tracks[3].beats.last)
111
+ assert_equal(test_tracks[3].sample_length_with_overflow(tick_sample_length), (tick_sample_length * 8).floor + (wave_sample_length - (tick_sample_length * 2).floor))
112
+ assert_equal(test_tracks[3].sample_length_with_overflow(tick_sample_length), sample_data[:primary].length + sample_data[:overflow].length)
113
+ else
114
+ assert_equal(test_tracks[3].sample_length_with_overflow(tick_sample_length), (tick_sample_length * 8).floor)
115
+ assert_equal(test_tracks[3].sample_length_with_overflow(tick_sample_length), sample_data[:primary].length + sample_data[:overflow].length)
116
+ end
117
+
118
+ sample_data = test_tracks[4].sample_data(tick_sample_length)
119
+ assert_equal(test_tracks[4].sample_length_with_overflow(tick_sample_length), (tick_sample_length * 4).floor)
120
+ assert_equal(test_tracks[4].sample_length_with_overflow(tick_sample_length), sample_data[:primary].length + sample_data[:overflow].length)
121
+
122
+ sample_data = test_tracks[5].sample_data(tick_sample_length)
123
+ assert_equal(test_tracks[5].sample_length_with_overflow(tick_sample_length), (tick_sample_length * 32).floor)
124
+ assert_equal(test_tracks[5].sample_length_with_overflow(tick_sample_length), sample_data[:primary].length + sample_data[:overflow].length)
125
+ end
126
+
127
+ def test_sample_data_overflow
128
+ track = generate_test_data()[2]
129
+ tick_sample_length = W.sample_data.length # 6179.0
130
+
131
+ overflow = W.sample_data[(W.sample_data.length / 2)..W.sample_data.length]
132
+ expected_sample_data = zeroes(tick_sample_length * 3) + W.sample_data
133
+ expected_sample_data[0...overflow.length] = overflow
134
+ actual_sample_data = track.sample_data(tick_sample_length, overflow)
135
+ assert_equal(actual_sample_data[:primary], expected_sample_data)
136
+
137
+ # Call sample_data() again with different overflow, to verify that cached
138
+ # sample data only contains the primary sample data.
139
+ overflow = W.sample_data[0..(W.sample_data.length / 2)]
140
+ expected_sample_data = zeroes(tick_sample_length * 3) + W.sample_data
141
+ expected_sample_data[0...overflow.length] = overflow
142
+ actual_sample_data = track.sample_data(tick_sample_length, overflow)
143
+ assert_equal(actual_sample_data[:primary], expected_sample_data)
144
+ end
145
+
146
+ def test_sample_data
147
+ sample_data = W.sample_data
148
+
149
+ tick_sample_length = W.sample_data.length # 6179.0
150
+ test_tracks = generate_test_data()
151
+ assert_equal(test_tracks[0].sample_data(tick_sample_length), {:primary => [], :overflow => []})
152
+ helper_test_sample_data(test_tracks[1], tick_sample_length, sample_data[0...tick_sample_length], [])
153
+ helper_test_sample_data(test_tracks[2], tick_sample_length, zeroes(tick_sample_length * 3) + sample_data, [])
154
+ helper_test_sample_data(test_tracks[3], tick_sample_length, (sample_data + zeroes(tick_sample_length)) * 4, [])
155
+ helper_test_sample_data(test_tracks[4], tick_sample_length, zeroes(tick_sample_length * 4), [])
156
+ # Track 6 is complicated. Will add test later...
157
+
158
+
159
+ tick_sample_length = (W.sample_rate * 60.0) / 220 / 4 # 3006.818181818181818
160
+ test_tracks = generate_test_data()
161
+ assert_equal(test_tracks[0].sample_data(tick_sample_length), {:primary => [], :overflow => []})
162
+ helper_test_sample_data(test_tracks[1], tick_sample_length, sample_data[0...tick_sample_length.floor], sample_data[tick_sample_length.floor...sample_data.length])
163
+ #helper_test_sample_data(test_tracks[2], tick_sample_length, zeroes(tick_sample_length * 3) + sample_data[0..tick_sample_length.floor], sample_data[(tick_sample_length.floor)...sample_data.length])
164
+ #helper_test_sample_data(test_tracks[3], tick_sample_length,
165
+ # sample_data[0...(tick_sample_length * 2)] +
166
+ # sample_data[0..(tick_sample_length * 2)] +
167
+ # sample_data[0...(tick_sample_length * 2)] +
168
+ # sample_data[0..(tick_sample_length * 2)],
169
+ # sample_data[(tick_sample_length * 2)..sample_data.length])
170
+ helper_test_sample_data(test_tracks[4], tick_sample_length, zeroes(tick_sample_length * 4), [])
171
+
172
+
173
+ tick_sample_length = (W.sample_rate * 60.0) / 99 / 4 # 6681.818181818181818
174
+ test_tracks = generate_test_data()
175
+ assert_equal(test_tracks[0].sample_data(tick_sample_length), {:primary => [], :overflow => []})
176
+ helper_test_sample_data(test_tracks[1], tick_sample_length, sample_data + zeroes(tick_sample_length - W.sample_data.length), [])
177
+ helper_test_sample_data(test_tracks[2], tick_sample_length, zeroes(tick_sample_length * 3) + sample_data + zeroes(tick_sample_length - sample_data.length + 1), [])
178
+ helper_test_sample_data(test_tracks[3], tick_sample_length,
179
+ sample_data + zeroes((tick_sample_length * 2) - sample_data.length) +
180
+ sample_data + zeroes((tick_sample_length * 2) - sample_data.length + 1) +
181
+ sample_data + zeroes((tick_sample_length * 2) - sample_data.length) +
182
+ sample_data + zeroes((tick_sample_length * 2) - sample_data.length + 1),
183
+ [])
184
+ helper_test_sample_data(test_tracks[4], tick_sample_length, zeroes(tick_sample_length * 4), [])
185
+ end
186
+
187
+ def helper_test_sample_data(track, tick_sample_length, expected_primary, expected_overflow)
188
+ sample_data = track.sample_data(tick_sample_length)
189
+
190
+ assert_equal(sample_data.class, Hash)
191
+ assert_equal(sample_data.keys.map{|key| key.to_s}.sort, ["overflow", "primary"])
192
+ assert_equal(sample_data[:primary].length, expected_primary.length)
193
+ assert_equal(sample_data[:overflow].length, expected_overflow.length)
194
+ assert_equal(sample_data[:primary], expected_primary)
195
+ assert_equal(sample_data[:overflow], expected_overflow)
196
+ end
197
+
198
+ private
199
+
200
+ def zeroes(length)
201
+ return [].fill(0, 0, length)
202
+ end
203
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beats
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Joel Strait
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-13 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: wavefile
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.0
24
+ version:
25
+ description: A drum machine that uses text files. Feed it a YAML file, and it will produce a Wave file.
26
+ email: ""
27
+ executables:
28
+ - beats
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - LICENSE
35
+ - README.markdown
36
+ - lib/kit.rb
37
+ - lib/pattern.rb
38
+ - lib/song.rb
39
+ - lib/track.rb
40
+ - bin/beats
41
+ - test/includes.rb
42
+ - test/kit_test.rb
43
+ - test/pattern_test.rb
44
+ - test/song_test.rb
45
+ - test/sounds/bass_mono_16.wav
46
+ - test/sounds/bass_mono_8.wav
47
+ - test/sounds/bass_stereo_16.wav
48
+ - test/sounds/hh_closed_mono_8.wav
49
+ - test/sounds/hh_open_mono_8.wav
50
+ - test/sounds/ride_mono_8.wav
51
+ - test/sounds/snare_mono_8.wav
52
+ - test/track_test.rb
53
+ has_rdoc: true
54
+ homepage: http://beatsdrummachine.com/
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: A drum machine that uses text files. Feed it a YAML file, and it will produce a Wave file.
81
+ test_files:
82
+ - test/includes.rb
83
+ - test/kit_test.rb
84
+ - test/pattern_test.rb
85
+ - test/song_test.rb
86
+ - test/sounds/bass_mono_16.wav
87
+ - test/sounds/bass_mono_8.wav
88
+ - test/sounds/bass_stereo_16.wav
89
+ - test/sounds/hh_closed_mono_8.wav
90
+ - test/sounds/hh_open_mono_8.wav
91
+ - test/sounds/ride_mono_8.wav
92
+ - test/sounds/snare_mono_8.wav
93
+ - test/track_test.rb