rb-music 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64717c99b5fbd105422fc99c79fd9d137abd80b0
4
- data.tar.gz: b61cfe61e4b3c562480d2f5b201d4d0636af8e69
3
+ metadata.gz: ede716588e8782f57b070342bc97120fe484cd5f
4
+ data.tar.gz: 7679fb3d8e55ab2789b83197933c9ecb267445f4
5
5
  SHA512:
6
- metadata.gz: cdc92e5119be32c2a4ac88869d8a48903e50992458035265096ef4efaef1a0a6f4a8f79c89237dc2ef6458998a9d689bb4d6c7feb30768d3394c5871709b6cbf
7
- data.tar.gz: ba46377b0db3961a66a2ae7a5c0f82da8e8c3e8fa11e389204de82d87e165888a2370ee6920ffd8d0bafea289471dff5fcdb7f314fc80271d38dc0c83e36b716
6
+ metadata.gz: dcbb0c626c7e84a5ccf0b9f2b315fd730914f977c9a66785addb020bd95c0433ecf7de5c9a92d8e179d8a2f815aaff84a16e5964593519328621803a29f7548f
7
+ data.tar.gz: 5c11ae0a331f398dfaa0f14c053179039fd80913224a0a9b2482627c31eec8977bf22f2b2028af04678f7d1ed3fd4eae788fdab7623c35eaf3414fa2fb3de2ef
data/lib/rb-music/note.rb CHANGED
@@ -58,7 +58,7 @@ module RBMusic
58
58
 
59
59
  def midi_note_number
60
60
  # see http://www.phys.unsw.edu.au/jw/notes.html
61
- 12 * Math.log2(frequency / 440) + 69
61
+ @note_number ||= (12 * Math.log2(frequency / 440) + 69).round
62
62
  end
63
63
 
64
64
  def scale(name, octaves = 1)
@@ -38,6 +38,7 @@ module RBMusic
38
38
  def <<(other)
39
39
  @notes << other
40
40
  end
41
+ alias_method :push, :<<
41
42
 
42
43
  def map(&block)
43
44
  @notes.map(&block)
@@ -48,6 +49,10 @@ module RBMusic
48
49
  end
49
50
  alias_method :eql?, :==
50
51
 
52
+ def size
53
+ @notes.size
54
+ end
55
+
51
56
  def add(that)
52
57
  NoteSet.new(@notes.map { |note| note.add(that) })
53
58
  end
@@ -1,3 +1,3 @@
1
1
  module RBMusic
2
- VERSION = "0.0.4" unless defined? RBMusic::VERSION
2
+ VERSION = "0.0.5" unless defined? RBMusic::VERSION
3
3
  end
@@ -100,6 +100,40 @@ describe RBMusic::NoteSet do
100
100
  end
101
101
  end
102
102
 
103
+ describe "#each" do
104
+ let(:notes) { [double(foo: true), double(foo: true)] }
105
+ let(:subject) { described_class.new(notes) }
106
+
107
+ it "delegates to the notes array" do
108
+ notes[0].should_receive(:foo)
109
+ notes[1].should_receive(:foo)
110
+
111
+ subject.each do |note|
112
+ note.foo
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "#<<" do
118
+ let(:notes) { ["foo", "bar"] }
119
+ let(:note) { "baz" }
120
+ let(:subject) { described_class.new(notes) }
121
+
122
+ it "adds to the notes array" do
123
+ subject << note
124
+
125
+ subject.notes.should == ["foo", "bar", "baz"]
126
+ end
127
+ end
128
+
129
+ describe "#size" do
130
+ let(:notes) { ["foo", "bar"] }
131
+
132
+ it "is the amount of notes in the set" do
133
+ described_class.new(notes).size.should == 2
134
+ end
135
+ end
136
+
103
137
  describe "#add" do
104
138
  let(:f4) { Note.from_latin("F4") }
105
139
  let(:g4) { Note.from_latin("G4") }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-music
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Wise