motion-music 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/Gemfile +8 -0
  4. data/Guardfile +6 -0
  5. data/LICENSE +23 -0
  6. data/README.md +53 -0
  7. data/doc/Gemfile.html +111 -0
  8. data/doc/Gemfile_lock.html +168 -0
  9. data/doc/Guardfile.html +111 -0
  10. data/doc/LICENSE.html +124 -0
  11. data/doc/Object.html +116 -0
  12. data/doc/RBMusic.html +164 -0
  13. data/doc/RBMusic/Interval.html +440 -0
  14. data/doc/RBMusic/Note.html +620 -0
  15. data/doc/RBMusic/NoteSet.html +277 -0
  16. data/doc/RBMusic/Scale.html +274 -0
  17. data/doc/README_md.html +163 -0
  18. data/doc/created.rid +8 -0
  19. data/doc/fonts.css +167 -0
  20. data/doc/fonts/Lato-Light.ttf +0 -0
  21. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  22. data/doc/fonts/Lato-Regular.ttf +0 -0
  23. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  24. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  25. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  26. data/doc/images/add.png +0 -0
  27. data/doc/images/arrow_up.png +0 -0
  28. data/doc/images/brick.png +0 -0
  29. data/doc/images/brick_link.png +0 -0
  30. data/doc/images/bug.png +0 -0
  31. data/doc/images/bullet_black.png +0 -0
  32. data/doc/images/bullet_toggle_minus.png +0 -0
  33. data/doc/images/bullet_toggle_plus.png +0 -0
  34. data/doc/images/date.png +0 -0
  35. data/doc/images/delete.png +0 -0
  36. data/doc/images/find.png +0 -0
  37. data/doc/images/loadingAnimation.gif +0 -0
  38. data/doc/images/macFFBgHack.png +0 -0
  39. data/doc/images/package.png +0 -0
  40. data/doc/images/page_green.png +0 -0
  41. data/doc/images/page_white_text.png +0 -0
  42. data/doc/images/page_white_width.png +0 -0
  43. data/doc/images/plugin.png +0 -0
  44. data/doc/images/ruby.png +0 -0
  45. data/doc/images/tag_blue.png +0 -0
  46. data/doc/images/tag_green.png +0 -0
  47. data/doc/images/transparent.png +0 -0
  48. data/doc/images/wrench.png +0 -0
  49. data/doc/images/wrench_orange.png +0 -0
  50. data/doc/images/zoom.png +0 -0
  51. data/doc/index.html +93 -0
  52. data/doc/js/darkfish.js +140 -0
  53. data/doc/js/jquery.js +18 -0
  54. data/doc/js/navigation.js +142 -0
  55. data/doc/js/search.js +109 -0
  56. data/doc/js/search_index.js +1 -0
  57. data/doc/js/searcher.js +228 -0
  58. data/doc/projections_json.html +115 -0
  59. data/doc/rb-music_gemspec.html +132 -0
  60. data/doc/rdoc.css +580 -0
  61. data/doc/table_of_contents.html +192 -0
  62. data/lib/motion-music.rb +9 -0
  63. data/lib/motion-music/version.rb +3 -0
  64. data/lib/rb-music.rb +8 -0
  65. data/lib/rb-music/constants.rb +105 -0
  66. data/lib/rb-music/interval.rb +50 -0
  67. data/lib/rb-music/note.rb +107 -0
  68. data/lib/rb-music/note_set.rb +61 -0
  69. data/lib/rb-music/scale.rb +30 -0
  70. data/lib/rb-music/version.rb +3 -0
  71. data/motion-music.gemspec +20 -0
  72. data/projections.json +12 -0
  73. data/rb-music.gemspec +29 -0
  74. data/spec/rb-music/constants_spec.rb +27 -0
  75. data/spec/rb-music/interval_spec.rb +90 -0
  76. data/spec/rb-music/note_set_spec.rb +191 -0
  77. data/spec/rb-music/note_spec.rb +318 -0
  78. data/spec/rb-music/scale_spec.rb +88 -0
  79. data/spec/spec_helper.rb +14 -0
  80. metadata +124 -0
@@ -0,0 +1,318 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe RBMusic::Note do
4
+
5
+ describe "class methods" do
6
+
7
+ describe "#from_latin" do
8
+
9
+ context "when given a single-character valid note name" do
10
+ let(:note_name) { RBMusic::NOTE_NAMES[0] }
11
+ let(:subject) { described_class.from_latin(note_name) }
12
+
13
+ it "returns a #{described_class}" do
14
+ subject.should be_a(described_class)
15
+ end
16
+
17
+ it "assigns the correct latin name" do
18
+ subject.latin.should == note_name
19
+ end
20
+
21
+ it "assigns a default octave of 0" do
22
+ subject.octave.should == 0
23
+ end
24
+ end
25
+
26
+ context "when given a single-character valid note name with octave" do
27
+ let(:note_name) { RBMusic::NOTE_NAMES[0] }
28
+ let(:octave) { 2 }
29
+ let(:subject) { described_class.from_latin("#{note_name}#{octave}") }
30
+
31
+ it "returns a #{described_class}" do
32
+ subject.should be_a(described_class)
33
+ end
34
+
35
+ it "assigns the correct latin name" do
36
+ subject.latin.should == note_name
37
+ end
38
+
39
+ it "assigns the correct octave" do
40
+ subject.octave.should == 2
41
+ end
42
+ end
43
+
44
+ context "when given a two-character valid note name with octave" do
45
+ let(:note_name) { "C#" }
46
+ let(:octave) { 3 }
47
+ let(:subject) { described_class.from_latin("#{note_name}#{octave}") }
48
+
49
+ it "returns a #{described_class}" do
50
+ subject.should be_a(described_class)
51
+ end
52
+
53
+ it "assigns the correct latin name" do
54
+ subject.latin.should == note_name
55
+ end
56
+
57
+ it "assigns the correct octave" do
58
+ subject.octave.should == 3
59
+ end
60
+ end
61
+
62
+ context "when given a single-character invalid note name" do
63
+ let(:note_name) { "Z" }
64
+
65
+ it "raises an exception" do
66
+ lambda {
67
+ described_class.from_latin(note_name)
68
+ }.should raise_error(RBMusic::ArgumentError)
69
+ end
70
+ end
71
+
72
+ context "when given an invalid note name / octave string" do
73
+ it "raises an exception" do
74
+ lambda {
75
+ described_class.from_latin("C0E3")
76
+ }.should raise_error(RBMusic::ArgumentError)
77
+ end
78
+ end
79
+
80
+ context "when given an empty string" do
81
+ it "raises an exception" do
82
+ lambda {
83
+ described_class.from_latin("")
84
+ }.should raise_error(RBMusic::ArgumentError)
85
+ end
86
+ end
87
+
88
+ context "when a non-string" do
89
+ it "raises an exception" do
90
+ lambda {
91
+ described_class.from_latin(1)
92
+ }.should raise_error(RBMusic::ArgumentError)
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+
100
+ describe "instance methods" do
101
+ let(:subject) { Note.from_latin("A4") }
102
+
103
+ describe "#frequency" do
104
+ [
105
+ ["A4", 440],
106
+ ["A#4", 466.16],
107
+ ["C4", 261.63],
108
+ ["B3", 246.94],
109
+ ["Ax3", 246.94]
110
+ ].each do |pair|
111
+
112
+ it "is #{pair[1]} for #{pair[0]}" do
113
+ Note.from_latin(pair[0]).frequency.round(2).should == pair[1]
114
+ end
115
+
116
+ end
117
+
118
+ end
119
+
120
+ it "has a latin name" do
121
+ subject.latin.should == "A"
122
+ end
123
+
124
+ it "has an octave" do
125
+ subject.octave.should == 4
126
+ end
127
+
128
+ describe "#==" do
129
+ context "when the argument is a note with the same latin name and octave" do
130
+ it "is true" do
131
+ subject.should == Note.from_latin("A4")
132
+ end
133
+ end
134
+
135
+ context "when the argument is a note with a different latin name and same octave" do
136
+ it "is false" do
137
+ subject.should_not == Note.from_latin("B4")
138
+ end
139
+ end
140
+
141
+ context "when the argument is a note with the same latin name and a different octave" do
142
+ it "is false" do
143
+ subject.should_not == Note.from_latin("A5")
144
+ end
145
+ end
146
+
147
+ context "when the argument is not a note" do
148
+ it "is false" do
149
+ subject.should_not == "foo"
150
+ end
151
+ end
152
+ end
153
+
154
+ describe "#enharmonic?" do
155
+ context "when the argument is a note with the same latin name and octave" do
156
+ it "is true" do
157
+ subject.should be_enharmonic(Note.from_latin("A4"))
158
+ end
159
+ end
160
+
161
+ context "when the argument is a note with same frequency but a different latin name and/or octave" do
162
+ it "is true" do
163
+ Note.from_latin("E4").should be_enharmonic(Note.from_latin("Fb4"))
164
+ Note.from_latin("Fbb4").should be_enharmonic(Note.from_latin("Eb4"))
165
+ end
166
+ end
167
+
168
+ context "when the argument is a note with a different latin name and same octave" do
169
+ it "is false" do
170
+ subject.should_not be_enharmonic(Note.from_latin("B4"))
171
+ subject.should_not be_enharmonically_equivalent_to(Note.from_latin("B4"))
172
+ end
173
+ end
174
+
175
+ context "when the argument is a note with the same latin name and a different octave" do
176
+ it "is false" do
177
+ subject.should_not be_enharmonic(Note.from_latin("A5"))
178
+ end
179
+ end
180
+
181
+ context "when the argument is not a note" do
182
+ it "raises an exception" do
183
+ lambda {
184
+ subject.enharmonic?("foo")
185
+ }.should raise_exception(RBMusic::ArgumentError)
186
+ end
187
+ end
188
+ end
189
+
190
+ describe "#add" do
191
+ context "when given a string" do
192
+ it "adds an interval from the string" do
193
+ b4 = Note.from_latin("B4")
194
+ result = subject.add("major_second")
195
+
196
+ result.frequency.should == b4.frequency
197
+ result.latin.should == b4.latin
198
+ result.octave.should == b4.octave
199
+ end
200
+ end
201
+
202
+ context "when given a symbol" do
203
+ it "adds an interval from the symbol" do
204
+ c5 = Note.from_latin("C5")
205
+ result = subject.add(:minor_third)
206
+
207
+ result.frequency.should == c5.frequency
208
+ result.latin.should == c5.latin
209
+ result.octave.should == c5.octave
210
+ end
211
+ end
212
+
213
+ context "when given an array" do
214
+ it "returns an NoteSet" do
215
+ b4 = Note.from_latin("B4")
216
+ c5 = Note.from_latin("C5")
217
+ result = subject.add(["major_second", :minor_third])
218
+
219
+ result.should be_a(NoteSet)
220
+
221
+ result[0].frequency.should == b4.frequency
222
+ result[0].latin.should == b4.latin
223
+ result[0].octave.should == b4.octave
224
+
225
+ result[1].frequency.should == c5.frequency
226
+ result[1].latin.should == c5.latin
227
+ result[1].octave.should == c5.octave
228
+ end
229
+ end
230
+ end
231
+
232
+ describe "#subtract" do
233
+
234
+ context "when given a string" do
235
+ it "returns a note with an interval from the string subtracted" do
236
+ g4 = Note.from_latin("G4")
237
+ result = subject.subtract("major_second")
238
+
239
+ result.frequency.should == g4.frequency
240
+ result.latin.should == g4.latin
241
+ result.octave.should == g4.octave
242
+ end
243
+ end
244
+
245
+ context "when given a symbol" do
246
+ it "returns a note with an interval from the symbol subtracted" do
247
+ f4 = Note.from_latin("F4")
248
+ result = subject.subtract(:major_third)
249
+
250
+ result.frequency.should == f4.frequency
251
+ result.latin.should == f4.latin
252
+ result.octave.should == f4.octave
253
+ end
254
+ end
255
+
256
+ context "when given an array" do
257
+ it "returns a NoteSet" do
258
+ f4 = Note.from_latin("F4")
259
+ g4 = Note.from_latin("G4")
260
+ result = subject.subtract(["major_third", :major_second])
261
+
262
+ result.should be_a(NoteSet)
263
+ result[0].frequency.should == f4.frequency
264
+ result[0].latin.should == f4.latin
265
+ result[0].octave.should == f4.octave
266
+
267
+ result[1].frequency.should == g4.frequency
268
+ result[1].latin.should == g4.latin
269
+ result[1].octave.should == g4.octave
270
+ end
271
+ end
272
+
273
+ context "when given a Note" do
274
+ it "returns the difference as an Interval" do
275
+ f4 = Note.from_latin("F4")
276
+ result = subject.subtract(f4)
277
+
278
+ result.coord.should == Interval.from_name("major_third").coord
279
+ end
280
+ end
281
+ end
282
+ end
283
+
284
+ describe "#midi_note_number" do
285
+ [
286
+ ["C3", 48],
287
+ ["B2", 47],
288
+ ["Ax2", 47],
289
+ ["C4", 60],
290
+ ["Cb4", 59],
291
+ ["C#4", 61],
292
+ ["Db4", 61]
293
+ ].each do |pair|
294
+ it "maps #{pair[0]} to #{pair[1]}" do
295
+ Note.from_latin(pair[0]).midi_note_number.should == pair[1]
296
+ end
297
+ end
298
+ end
299
+
300
+ describe "#scale" do
301
+ let(:subject) { Note.from_latin("C4") }
302
+ let(:scale_name) { "major" }
303
+ let(:scale) { Scale.new(subject.latin, scale_name) }
304
+
305
+ it "is a note set with the default octave and range" do
306
+ result = subject.scale(scale_name)
307
+
308
+ result.should == NoteSet.from_scale(scale, subject.octave, 1)
309
+ end
310
+
311
+ it "accepts an octave range" do
312
+ result = subject.scale(scale_name, 2)
313
+
314
+ result.should == NoteSet.from_scale(scale, subject.octave, 2)
315
+ end
316
+ end
317
+
318
+ end
@@ -0,0 +1,88 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe RBMusic::Scale do
4
+
5
+ describe "initializer" do
6
+
7
+ context "when called with no arguments" do
8
+ it "raises an ArgumentError" do
9
+ lambda {
10
+ described_class.new
11
+ }.should raise_error(ArgumentError)
12
+ end
13
+ end
14
+
15
+ context "when called without a valid note name as key" do
16
+ it "raises an ArgumentError" do
17
+ lambda {
18
+ described_class.new("foo", "bar")
19
+ }.should raise_error(RBMusic::ArgumentError)
20
+ end
21
+ end
22
+
23
+ context "when called without a valid key and scale name" do
24
+ it "raises an ArgumentError" do
25
+ lambda {
26
+ described_class.new("C", "bar")
27
+ }.should raise_error(RBMusic::ArgumentError)
28
+ end
29
+ end
30
+
31
+ context "when called with a valid key and scale" do
32
+ let(:key) { "C" }
33
+ let(:name) { "major" }
34
+ let(:subject) { described_class.new(key, name) }
35
+
36
+ it "assigns the key attribute" do
37
+ subject.key.should == key
38
+ end
39
+
40
+ it "assigns the degrees based on the name" do
41
+ subject.degrees.should == [:unison] + SCALES[name.to_sym]
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "instance methods" do
47
+ let(:subject) { described_class.new("C", "major") }
48
+
49
+ describe "#degree_count" do
50
+ it "is the number of scale degrees" do
51
+ subject.degree_count.should == subject.degrees.size
52
+ end
53
+ end
54
+
55
+ describe "#name" do
56
+ it "is the human-readable name" do
57
+ subject.name.should == "C Major"
58
+ Scale.new("D#", "harmonic_minor").name.should == "D# Harmonic Minor"
59
+ end
60
+ end
61
+ end
62
+
63
+ describe "scale types" do
64
+ let(:note) { Note.from_latin("C4") }
65
+
66
+ {
67
+ "major" => ["C", "D", "E", "F", "G", "A", "B"],
68
+ "natural_minor" => ["C", "D", "Eb", "F", "G", "Ab", "Bb"],
69
+ "natural_minor" => ["C", "D", "Eb", "F", "G", "Ab", "Bb"],
70
+ "harmonic_minor" => ["C", "D", "Eb", "F", "G", "Ab", "B"],
71
+ "major_pentatonic" => ["C", "D", "E", "G", "A"],
72
+ "minor_pentatonic" => ["C", "Eb", "F", "G", "Bb"],
73
+ "blues" => ["C", "Eb", "F", "F#", "G", "Bb"],
74
+ "ionian" => ["C", "D", "E", "F", "G", "A", "B"],
75
+ "dorian" => ["C", "D", "Eb", "F", "G", "A", "Bb"],
76
+ "phrygian" => ["C", "Db", "Eb", "F", "G", "A", "Bb"],
77
+ "lydian" => ["C", "D", "E", "F#", "G", "A", "B"],
78
+ "mixolydian" => ["C", "D", "E", "F", "G", "A", "Bb"],
79
+ "aeolian" => ["C", "D", "Eb", "F", "G", "Ab", "Bb"],
80
+ "locrian" => ["C", "Db", "Eb", "F", "Gb", "Ab", "Bb"],
81
+ }.each_pair do |key, value|
82
+ it "calculates a #{key} scale" do
83
+ note.scale(key).map(&:latin).should == value
84
+ end
85
+ end
86
+ end
87
+
88
+ end
@@ -0,0 +1,14 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ if ENV["COVERAGE"]
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+ end
8
+
9
+ RSpec.configure do |c|
10
+ c.filter_run focus: true
11
+ c.run_all_when_everything_filtered = true
12
+ end
13
+
14
+ require 'rb-music'
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-music
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Mark Wise
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem wraps the rb-music gem to provide RubyMotion classes for working
14
+ with musical notes, scales and intervals.
15
+ email:
16
+ - markmediadude@mgail.comm
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.md
21
+ files:
22
+ - ".gitignore"
23
+ - Gemfile
24
+ - Guardfile
25
+ - LICENSE
26
+ - README.md
27
+ - doc/Gemfile.html
28
+ - doc/Gemfile_lock.html
29
+ - doc/Guardfile.html
30
+ - doc/LICENSE.html
31
+ - doc/Object.html
32
+ - doc/RBMusic.html
33
+ - doc/RBMusic/Interval.html
34
+ - doc/RBMusic/Note.html
35
+ - doc/RBMusic/NoteSet.html
36
+ - doc/RBMusic/Scale.html
37
+ - doc/README_md.html
38
+ - doc/created.rid
39
+ - doc/fonts.css
40
+ - doc/fonts/Lato-Light.ttf
41
+ - doc/fonts/Lato-LightItalic.ttf
42
+ - doc/fonts/Lato-Regular.ttf
43
+ - doc/fonts/Lato-RegularItalic.ttf
44
+ - doc/fonts/SourceCodePro-Bold.ttf
45
+ - doc/fonts/SourceCodePro-Regular.ttf
46
+ - doc/images/add.png
47
+ - doc/images/arrow_up.png
48
+ - doc/images/brick.png
49
+ - doc/images/brick_link.png
50
+ - doc/images/bug.png
51
+ - doc/images/bullet_black.png
52
+ - doc/images/bullet_toggle_minus.png
53
+ - doc/images/bullet_toggle_plus.png
54
+ - doc/images/date.png
55
+ - doc/images/delete.png
56
+ - doc/images/find.png
57
+ - doc/images/loadingAnimation.gif
58
+ - doc/images/macFFBgHack.png
59
+ - doc/images/package.png
60
+ - doc/images/page_green.png
61
+ - doc/images/page_white_text.png
62
+ - doc/images/page_white_width.png
63
+ - doc/images/plugin.png
64
+ - doc/images/ruby.png
65
+ - doc/images/tag_blue.png
66
+ - doc/images/tag_green.png
67
+ - doc/images/transparent.png
68
+ - doc/images/wrench.png
69
+ - doc/images/wrench_orange.png
70
+ - doc/images/zoom.png
71
+ - doc/index.html
72
+ - doc/js/darkfish.js
73
+ - doc/js/jquery.js
74
+ - doc/js/navigation.js
75
+ - doc/js/search.js
76
+ - doc/js/search_index.js
77
+ - doc/js/searcher.js
78
+ - doc/projections_json.html
79
+ - doc/rb-music_gemspec.html
80
+ - doc/rdoc.css
81
+ - doc/table_of_contents.html
82
+ - lib/motion-music.rb
83
+ - lib/motion-music/version.rb
84
+ - lib/rb-music.rb
85
+ - lib/rb-music/constants.rb
86
+ - lib/rb-music/interval.rb
87
+ - lib/rb-music/note.rb
88
+ - lib/rb-music/note_set.rb
89
+ - lib/rb-music/scale.rb
90
+ - lib/rb-music/version.rb
91
+ - motion-music.gemspec
92
+ - projections.json
93
+ - rb-music.gemspec
94
+ - spec/rb-music/constants_spec.rb
95
+ - spec/rb-music/interval_spec.rb
96
+ - spec/rb-music/note_set_spec.rb
97
+ - spec/rb-music/note_spec.rb
98
+ - spec/rb-music/scale_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: https://rubygems.org/mwise/motion-music
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Music theory library for RubyMotion
124
+ test_files: []