rb-music 0.0.1 → 0.0.3

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: 53f397b83b876fe6811b1244eb54176e4235abdb
4
- data.tar.gz: ae41a88a15cf8aa76fb0fff1c955b29408d7daa4
3
+ metadata.gz: 3fc617a723dd833ba0f1000693c41eb7b268b6ea
4
+ data.tar.gz: 19a307ef2a1fd82f13eb930c205744adbd547f9f
5
5
  SHA512:
6
- metadata.gz: 0aeaace498dede1b9c25c28094d7b94ab0f4dec3f37435844fc3f9f1338e278924d0f0543615e9859344d876323b94c01fc0b8e26066cb22044a60ddb2a3cbda
7
- data.tar.gz: 3831325e305d9df64dca46d01809ae8d9c52c65ec31f52a2ce4912af6b5a572dbed3a3702d50596762500709f98f8db3d8ab293d763e7aabd140a81d015299c3
6
+ metadata.gz: d99d234ff1650ec22574dedacf1afb3624e9e71144405931ff283d64b3abd70cf0944347955f65b053434113ca48bb25fb12db0afb6450a026b66a761faf0dc7
7
+ data.tar.gz: 9f01db156a66dc104f237397dd9e93f421aa51d655a4ac0473f1914852458c1f49a9e925a935e98bdfc93d7f15f1a45fffd79f6f2cc524dd65430d4005655a6d
metadata CHANGED
@@ -1,71 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-music
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Wise
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-18 00:00:00.000000000 Z
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard-rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: '0'
22
+ version: 4.2.8
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 4.2.8
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rake
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.3'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 10.3.1
34
43
  type: :development
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.3'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
- version: '0'
52
+ version: 10.3.1
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: rspec
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.14'
45
60
  - - ">="
46
61
  - !ruby/object:Gem::Version
47
- version: '0'
62
+ version: 2.14.1
48
63
  type: :development
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.14'
52
70
  - - ">="
53
71
  - !ruby/object:Gem::Version
54
- version: '0'
72
+ version: 2.14.1
55
73
  - !ruby/object:Gem::Dependency
56
74
  name: simplecov
57
75
  requirement: !ruby/object:Gem::Requirement
58
76
  requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.8'
59
80
  - - ">="
60
81
  - !ruby/object:Gem::Version
61
- version: '0'
82
+ version: 0.8.2
62
83
  type: :development
63
84
  prerelease: false
64
85
  version_requirements: !ruby/object:Gem::Requirement
65
86
  requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
66
90
  - - ">="
67
91
  - !ruby/object:Gem::Version
68
- version: '0'
92
+ version: 0.8.2
69
93
  description: This gem provides Ruby classes for working with musical notes, scales
70
94
  and intervals.
71
95
  email:
@@ -77,15 +101,7 @@ extra_rdoc_files:
77
101
  files:
78
102
  - LICENSE
79
103
  - README.md
80
- - lib/motion-music.rb
81
- - lib/motion-music/version.rb
82
104
  - lib/rb-music.rb
83
- - lib/rb-music/constants.rb
84
- - lib/rb-music/interval.rb
85
- - lib/rb-music/note.rb
86
- - lib/rb-music/note_set.rb
87
- - lib/rb-music/scale.rb
88
- - lib/rb-music/version.rb
89
105
  - spec/rb-music/constants_spec.rb
90
106
  - spec/rb-music/interval_spec.rb
91
107
  - spec/rb-music/note_set_spec.rb
data/lib/motion-music.rb DELETED
@@ -1,9 +0,0 @@
1
- unless defined?(Motion::Project::Config)
2
- raise "This file must be required within a RubyMotion project Rakefile."
3
- end
4
-
5
- Motion::Project::App.setup do |app|
6
- Dir.glob(File.join(File.dirname(__FILE__), 'rb-music/*.rb')).each do |file|
7
- app.files.unshift(file)
8
- end
9
- end
@@ -1,3 +0,0 @@
1
- module MotionMusic
2
- VERSION = "0.0.0" unless defined? MotionMusic::VERSION
3
- end
@@ -1,105 +0,0 @@
1
- module RBMusic
2
- Error = Class.new(StandardError)
3
- ArgumentError = Class.new(ArgumentError)
4
-
5
- NOTE_NAMES = ["F", "C", "G", "D", "A", "E", "B"]
6
- ACCIDENTALS = ["bb", "b", "", "#", "x"]
7
-
8
- # notes - two dimensional [octave, fifth] - relative to the 'main' note
9
- NOTES = {
10
- "Fbb" => [10, -17],
11
- "Cbb" => [10, -16],
12
- "Gbb" => [9, -15],
13
- "Dbb" => [8, -14],
14
- "Abb" => [8, -13],
15
- "Ebb" => [7, -12],
16
- "Bbb" => [7, -11],
17
-
18
- "Fb" => [6, -10],
19
- "Cb" => [5, -9],
20
- "Gb" => [5, -8],
21
- "Db" => [4, -7],
22
- "Ab" => [4, -6],
23
- "Eb" => [3, -5],
24
- "Bb" => [3, -4],
25
-
26
- "F" => [2, -3],
27
- "C" => [1, -2],
28
- "G" => [1, -1],
29
- "D" => [0, 0],
30
- "A" => [0, 1],
31
- "E" => [-1, 2],
32
- "B" => [-1, 3],
33
-
34
- "F#" => [-2, 4],
35
- "C#" => [-3, 5],
36
- "G#" => [-3, 6],
37
- "D#" => [-4, 7],
38
- "A#" => [-4, 8],
39
- "E#" => [-5, 9],
40
- "B#" => [-5, 10],
41
-
42
- "Fx" => [-6, 11],
43
- "Cx" => [-7, 12],
44
- "Gx" => [-7, 13],
45
- "Dx" => [-8, 14],
46
- "Ax" => [-8, 15],
47
- "Ex" => [-9, 16],
48
- "Bx" => [-10, 17]
49
- }
50
-
51
- BASE_FREQ = 440 # A4 'main' note
52
- BASE_OFFSET = [4, 1] # offset of base note from D0
53
-
54
- # intervals - two dimensional [octave, fifth] - relative to the 'main' note
55
- INTERVALS = {
56
- unison: [0, 0],
57
- minor_second: [3, -5],
58
- major_second: [-1, 2],
59
- minor_third: [2, -3],
60
- major_third: [-2, 4],
61
- fourth: [1, -1],
62
- augmented_fourth: [-3, 6],
63
- tritone: [-3, 6],
64
- diminished_fifth: [4, -6],
65
- fifth: [0, 1],
66
- minor_sixth: [3, -4],
67
- major_sixth: [-1, 3],
68
- minor_seventh: [2, -2],
69
- major_seventh: [-2, 5],
70
- octave: [1, 0]
71
- }
72
-
73
- INTERVALS_SEMITONES = {
74
- 0 => [0, 0],
75
- 1 => [3, -5],
76
- 2 => [-1, 2],
77
- 3 => [2, -3],
78
- 4 => [-2, 4],
79
- 5 => [1, -1],
80
- 6 => [-3, 6],
81
- 7 => [0, 1],
82
- 8 => [3, -4],
83
- 9 => [-1, 3],
84
- 10 => [2, -2],
85
- 11 => [-2, 5],
86
- 12 => [1, 0]
87
- }
88
-
89
- SCALES = {
90
- major: [:major_second, :major_third, :fourth, :fifth, :major_sixth, :major_seventh],
91
- natural_minor: [:major_second, :minor_third, :fourth, :fifth, :minor_sixth, :minor_seventh],
92
- harmonic_minor: [:major_second, :minor_third, :fourth, :fifth, :minor_sixth, :major_seventh],
93
- major_pentatonic: [:major_second, :major_third, :fifth, :major_sixth],
94
- minor_pentatonic: [:minor_third, :fourth, :fifth, :minor_seventh],
95
- blues: [:minor_third, :fourth, :augmented_fourth, :fifth, :minor_seventh],
96
- dorian: [:major_second, :minor_third, :fourth, :fifth, :major_sixth, :minor_seventh],
97
- phrygian: [:minor_second, :minor_third, :fourth, :fifth, :major_sixth, :minor_seventh],
98
- lydian: [:major_second, :major_third, :augmented_fourth, :fifth, :major_sixth, :major_seventh],
99
- mixolydian: [:major_second, :major_third, :fourth, :fifth, :major_sixth, :minor_seventh],
100
- locrian: [:minor_second, :minor_third, :fourth, :diminished_fifth, :minor_sixth, :minor_seventh],
101
- }
102
- SCALES[:ionian] = SCALES[:major]
103
- SCALES[:aeolian] = SCALES[:natural_minor]
104
-
105
- end
@@ -1,50 +0,0 @@
1
- module RBMusic
2
-
3
- class Interval
4
- attr_accessor :coord
5
-
6
- def initialize(coord)
7
- self.coord = coord
8
- end
9
-
10
- def self.from_name(name)
11
- Interval.new(INTERVALS[name.to_sym])
12
- end
13
-
14
- def self.from_semitones(num)
15
- Interval.new(INTERVALS_SEMITONES[num])
16
- end
17
-
18
- def self.from_tones_semitones(tone_semitone)
19
- # multiply [tones, semitones] vector with [-1 2;3 -5] to get coordinate from tones and semitones
20
- Interval.new([tone_semitone[0] * -1 + tone_semitone[1] * 3, tone_semitone[0] * 2 + tone_semitone[1] * -5])
21
- end
22
-
23
- def tone_semitone
24
- # multiply coord vector with [5 2;3 1] to get coordinate in tones and semitones
25
- # [5 2;3 1] is the inverse of [-1 2;3 -5], which is the coordinates of [tone; semitone]
26
- @tone_semitone ||= [coord[0] * 5 + coord[1] * 3, coord[0] * 2 + coord[1] * 1]
27
- end
28
-
29
- def semitone
30
- # number of semitones of interval = tones * 2 + semitones
31
- tone_semitone[0] * 2 + tone_semitone[1]
32
- end
33
-
34
- def add(interval)
35
- if interval.is_a?(String)
36
- interval = Interval.from_name(interval)
37
- end
38
- Interval.new([coord[0] + interval.coord[0], coord[1] + interval.coord[1]])
39
- end
40
-
41
- def subtract(interval)
42
- if interval.is_a?(String)
43
- interval = Interval.from_name(interval)
44
- end
45
- Interval.new([coord[0] - interval.coord[0], coord[1] - interval.coord[1]])
46
- end
47
-
48
- end
49
-
50
- end
data/lib/rb-music/note.rb DELETED
@@ -1,107 +0,0 @@
1
- module RBMusic
2
-
3
- class Note
4
- attr_accessor :coord
5
-
6
- def initialize(coord)
7
- self.coord = coord
8
- end
9
-
10
- def self.from_latin(name)
11
- raise ArgumentError unless name.is_a?(String)
12
-
13
- note_parts = name.split(/(\d+)/)
14
- note_name = note_parts.first
15
- octave = note_parts.last.to_i
16
-
17
- unless NOTES.has_key?(note_name) && note_parts.size < 3
18
- raise ArgumentError
19
- end
20
-
21
- coordinate = [NOTES[note_name][0] + octave, NOTES[note_name][1]]
22
-
23
- coordinate[0] -= BASE_OFFSET[0]
24
- coordinate[1] -= BASE_OFFSET[1]
25
-
26
- Note.new(coordinate)
27
- end
28
-
29
- def frequency
30
- BASE_FREQ * (2.0 ** ((coord[0] * 1200 + coord[1] * 700.0) / 1200.0))
31
- end
32
-
33
- def accidental
34
- @accidental ||= ((coord[1] + BASE_OFFSET[1]) / 7.0).round
35
- end
36
-
37
- def octave
38
- # calculate octave of base note without accidentals
39
- @octave ||= coord[0] + BASE_OFFSET[0] + 4 * accidental + ((coord[1] + BASE_OFFSET[1] - 7 * accidental) / 2).floor
40
- end
41
-
42
- def latin
43
- return @latin if @latin
44
- accidentalName = ACCIDENTALS[accidental + 2]
45
- @latin ||= base_note_name + accidentalName
46
- end
47
-
48
- def ==(other)
49
- other.is_a?(Note) && other.latin == latin && other.octave == octave
50
- end
51
-
52
- def enharmonic?(other)
53
- raise ArgumentError unless other.is_a?(Note)
54
-
55
- other.frequency == frequency
56
- end
57
- alias_method :enharmonically_equivalent_to?, :enharmonic?
58
-
59
- def midi_note_number
60
- # see http://www.phys.unsw.edu.au/jw/notes.html
61
- 12 * Math.log2(frequency / 440) + 69
62
- end
63
-
64
- def scale(name, octaves = 1)
65
- NoteSet.from_scale(Scale.new(latin, name), octave, octaves)
66
- end
67
-
68
- def add(that)
69
- # if input is an array return an array
70
- if that.is_a?(Array)
71
- notes = that.map { |thing| add(thing) }
72
- return NoteSet.new(notes)
73
- end
74
-
75
- # if input is string/symbol try to parse it as interval
76
- if that.is_a?(String) || that.is_a?(Symbol)
77
- that = Interval.from_name(that)
78
- end
79
-
80
- Note.new([coord[0] + that.coord[0], coord[1] + that.coord[1]])
81
- end
82
-
83
- def subtract(that)
84
- if that.is_a?(Array)
85
- notes = that.map { |thing| subtract(thing) }
86
- return NoteSet.new(notes)
87
- end
88
-
89
- # if input is string try to parse it as interval
90
- if that.is_a?(String) || that.is_a?(Symbol)
91
- that = Interval.from_name(that)
92
- end
93
-
94
- coordinate = [coord[0] - that.coord[0], coord[1] - that.coord[1]]
95
-
96
- # if input is another note return the difference as an Interval
97
- that.is_a?(Note) ? Interval.new(coordinate) : Note.new(coordinate)
98
- end
99
-
100
- private
101
-
102
- def base_note_name
103
- @base_note_name ||= NOTE_NAMES[coord[1] + BASE_OFFSET[1] - accidental * 7 + 3]
104
- end
105
- end
106
-
107
- end
@@ -1,61 +0,0 @@
1
- module RBMusic
2
-
3
- class NoteSet
4
- include Enumerable
5
-
6
- attr_accessor :notes
7
-
8
- def initialize(notes = [])
9
- @notes = notes
10
- end
11
-
12
- def self.from_scale(scale, octave=0, octaves=1)
13
- raise ArgumentError unless scale.is_a?(Scale) && octaves > 0
14
-
15
- root_note = Note.from_latin("#{scale.key}#{octave}")
16
- notes = []
17
- octaves.times do |i|
18
- notes += scale.degrees.map do |interval_name|
19
- note = root_note.add(interval_name)
20
- i.times do |octave_offset|
21
- note = note.add(:octave)
22
- end
23
- note
24
- end
25
- end
26
-
27
- self.new(notes)
28
- end
29
-
30
- def each(&block)
31
- @notes.each(&block)
32
- end
33
-
34
- def [](index)
35
- @notes[index]
36
- end
37
-
38
- def <<(other)
39
- @notes << other
40
- end
41
-
42
- def map(&block)
43
- @notes.map(&block)
44
- end
45
-
46
- def ==(other)
47
- @notes == other.notes
48
- end
49
- alias_method :eql?, :==
50
-
51
- def add(that)
52
- NoteSet.new(@notes.map { |note| note.add(that) })
53
- end
54
-
55
- def subtract(that)
56
- NoteSet.new(@notes.map { |note| note.subtract(that) })
57
- end
58
-
59
- end
60
-
61
- end
@@ -1,30 +0,0 @@
1
- module RBMusic
2
-
3
- class Scale
4
- attr_reader :key
5
- attr_reader :degrees
6
-
7
- def initialize(key, name)
8
- @scale_name = name.to_sym
9
- raise ArgumentError unless NOTES.has_key?(key)
10
- raise ArgumentError unless SCALES.has_key?(@scale_name)
11
- @key = key
12
- @degrees = [:unison] + SCALES[@scale_name]
13
- end
14
-
15
- def degree_count
16
- @degree_count ||= @degrees.size
17
- end
18
- alias_method :size, :degree_count
19
-
20
- def name
21
- @name ||= "#{key} #{human_scale_name}"
22
- end
23
-
24
- private
25
- def human_scale_name
26
- @scale_name.to_s.split("_").map { |word| word.capitalize }.join(" ")
27
- end
28
- end
29
-
30
- end
@@ -1,3 +0,0 @@
1
- module RBMusic
2
- VERSION = "0.0.1" unless defined? RBMusic::VERSION
3
- end