peas 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,42 +2,42 @@ require 'peas/interval'
2
2
 
3
3
  class Integer
4
4
  def unisons
5
- Peas::Interval::Diatonic::P1
5
+ Peas::Interval::P1
6
6
  end
7
7
  alias unison unisons
8
8
 
9
9
  def semitones
10
- Peas::Interval::Semitone "S#{self}" => self
10
+ Peas::Interval "S#{self}" => self
11
11
  end
12
12
  alias semitone semitones
13
13
 
14
14
  def minor_seconds
15
- Peas::Interval::Diatonic "m2x#{self}" => self
15
+ Peas::Interval "m2x#{self}" => self
16
16
  end
17
17
  alias minor_second minor_seconds
18
18
 
19
19
  def wholetones
20
- Peas::Interval::Wholetone "W#{self}" => self * 2
20
+ Peas::Interval "W#{self}" => self * 2
21
21
  end
22
22
  alias wholetone wholetones
23
23
 
24
24
  def major_seconds
25
- Peas::Interval::Diatonic "M2x#{self}" => self * 2
25
+ Peas::Interval "M2x#{self}" => self * 2
26
26
  end
27
27
  alias major_second major_seconds
28
28
 
29
29
  def minor_thirds
30
- Peas::Interval::Diatonic "m3x#{self}" => self * 3
30
+ Peas::Interval "m3x#{self}" => self * 3
31
31
  end
32
32
  alias minor_third minor_thirds
33
33
 
34
34
  def major_thirds
35
- Peas::Interval::Diatonic "M3x#{self}" => self * 4
35
+ Peas::Interval "M3x#{self}" => self * 4
36
36
  end
37
37
  alias major_third major_thirds
38
38
 
39
39
  def perfect_fourths
40
- Peas::Interval::Diatonic "P4x#{self}" => self * 5
40
+ Peas::Interval "P4x#{self}" => self * 5
41
41
  end
42
42
  alias perfect_fourth perfect_fourths
43
43
 
@@ -48,47 +48,47 @@ class Integer
48
48
  alias tritone tritones
49
49
 
50
50
  def diminished_fifths
51
- Peas::Interval::Diatonic "d5x#{self}" => self * 6
51
+ Peas::Interval "d5x#{self}" => self * 6
52
52
  end
53
53
  alias diminished_fifth diminished_fifths
54
54
 
55
55
  def augmented_fourths
56
- Peas::Interval::Diatonic "S6x#{self}" => self * 6
56
+ Peas::Interval "S6x#{self}" => self * 6
57
57
  end
58
58
  alias augmented_fourth augmented_fourths
59
59
 
60
60
  def perfect_fifths
61
- Peas::Interval::Diatonic "P5x#{self}" => self * 7
61
+ Peas::Interval "P5x#{self}" => self * 7
62
62
  end
63
63
  alias perfect_fifth perfect_fifths
64
64
 
65
65
  def minor_sixths
66
- Peas::Interval::Diatonic "m6x#{self}" => self * 8
66
+ Peas::Interval "m6x#{self}" => self * 8
67
67
  end
68
68
  alias minor_sixth minor_sixths
69
69
 
70
70
  def augmented_fifths
71
- Peas::Interval::Chromatic "S8x#{self}" => self * 8
71
+ Peas::Interval "S8x#{self}" => self * 8
72
72
  end
73
73
  alias augmented_fifth augmented_fifths
74
74
 
75
75
  def major_sixths
76
- Peas::Interval::Diatonic "M6x#{self}" => self * 9
76
+ Peas::Interval "M6x#{self}" => self * 9
77
77
  end
78
78
  alias major_sixth major_sixths
79
79
 
80
80
  def minor_sevenths
81
- Peas::Interval::Diatonic "m7x#{self}" => self * 10
81
+ Peas::Interval "m7x#{self}" => self * 10
82
82
  end
83
83
  alias minor_seventh minor_sevenths
84
84
 
85
85
  def major_sevenths
86
- Peas::Interval::Diatonic "M7x#{self}" => self * 11
86
+ Peas::Interval "M7x#{self}" => self * 11
87
87
  end
88
88
  alias major_seventh major_sevenths
89
89
 
90
90
  def octaves
91
- Peas::Interval::Diatonic "P8x#{self}" => self * 12
91
+ Peas::Interval "P8x#{self}" => self * 12
92
92
  end
93
93
  alias octave octaves
94
94
  end
data/lib/peas/interval.rb CHANGED
@@ -2,104 +2,78 @@ require 'named_value_class'
2
2
  require 'peas/pitch'
3
3
 
4
4
  module Peas
5
-
6
5
  # see: http://en.wikipedia.org/wiki/Interval_(music)
7
6
  #
8
- module Interval
9
- NamedValueClass Base:Integer, constrain:0..24 do
10
- minus_a Pitch, raises:SyntaxError
11
- minus_a PitchClass, raises:SyntaxError
12
- end
13
-
14
- class Semitone < Base; end
15
- 25.times do |x|
16
- Semitone "S#{x}" => x
17
- end
7
+ NamedValueClass Interval:Fixnum do
8
+ multiplied_by_a 'Interval', raises:SyntaxError
18
9
 
19
- class Wholetone < Base; end
20
- 13.times do |x|
21
- Wholetone "W#{x}" => x * 2
10
+ def inverse
11
+ case @name
12
+ when 'P1' then Interval::P8
13
+ when 'm2' then Interval::M7
14
+ when 'M2' then Interval::m7
15
+ when 'm3' then Interval::M6
16
+ when 'M3' then Interval::m6
17
+ when 'P4' then Interval::P5
18
+ when 'A4' then Interval::d5
19
+ when 'd5' then Interval::A4
20
+ when 'P5' then Interval::P4
21
+ when 'm6' then Interval::M3
22
+ when 'M6' then Interval::m3
23
+ when 'm7' then Interval::M2
24
+ when 'M7' then Interval::m2
25
+ when 'P8' then Interval::P1
26
+ end
22
27
  end
23
28
 
24
- class Chromatic < Base; end
25
- Chromatic d2: 0
26
- Chromatic A1: 1
27
- Chromatic d3: 2
28
- Chromatic A2: 3
29
- Chromatic d4: 4
30
- Chromatic A3: 5
31
- Chromatic d5: 6
32
- Chromatic A4: 6
33
- Chromatic d6: 7
34
- Chromatic A5: 8
35
- Chromatic d7: 9
36
- Chromatic A6:10
37
- Chromatic d8:11
38
- Chromatic A7:12
39
-
40
- class Latin < Base; end
41
- Latin S: 1
42
- Latin T: 3
43
- Latin TT:6
44
-
45
- class Diatonic < Base
46
- def inverse
47
- case @name
48
- when 'P1' then Diatonic::P8
49
- when 'm2' then Diatonic::M7
50
- when 'M2' then Diatonic::m7
51
- when 'm3' then Diatonic::M6
52
- when 'M3' then Diatonic::m6
53
- when 'P4' then Diatonic::P5
54
- when 'A4' then Diatonic::d5
55
- when 'd5' then Diatonic::A4
56
- when 'P5' then Diatonic::P4
57
- when 'm6' then Diatonic::M3
58
- when 'M6' then Diatonic::m3
59
- when 'm7' then Diatonic::M2
60
- when 'M7' then Diatonic::m2
61
- when 'P8' then Diatonic::P1
62
- end
63
- end
64
-
65
- def interval_class
66
- if (mod_12 = self % 12) > 6
67
- 12 - mod_12
68
- else
69
- mod_12
70
- end
29
+ def interval_class
30
+ if (mod_12 = self % 12) > 6
31
+ 12 - mod_12
32
+ else
33
+ mod_12
71
34
  end
72
35
  end
73
- Diatonic P1: 0
74
- Diatonic m2: 1
75
- Diatonic M2: 2
76
- Diatonic m3: 3
77
- Diatonic M3: 4
78
- Diatonic P4: 5
79
- Diatonic A4: 6
80
- Diatonic d5: 6
81
- Diatonic P5: 7
82
- Diatonic m6: 8
83
- Diatonic M6: 9
84
- Diatonic m7:10
85
- Diatonic M7:11
86
- Diatonic P8:12
36
+ end
37
+
38
+ 25.times do |x|
39
+ Interval "S#{x}" => x
87
40
  end
88
41
 
89
- module Intervals
90
- include Interval::Semitone::NamedValues
91
- extend Interval::Semitone::NamedValues
92
-
93
- include Interval::Wholetone::NamedValues
94
- extend Interval::Wholetone::NamedValues
95
-
96
- include Interval::Chromatic::NamedValues
97
- extend Interval::Chromatic::NamedValues
98
-
99
- include Interval::Latin::NamedValues
100
- extend Interval::Latin::NamedValues
101
-
102
- include Interval::Diatonic::NamedValues
103
- extend Interval::Diatonic::NamedValues
42
+ 13.times do |x|
43
+ Interval "W#{x}" => x * 2
104
44
  end
45
+
46
+ Interval d2: 0
47
+ Interval A1: 1
48
+ Interval d3: 2
49
+ Interval A2: 3
50
+ Interval d4: 4
51
+ Interval A3: 5
52
+ Interval d5: 6
53
+ Interval A4: 6
54
+ Interval d6: 7
55
+ Interval A5: 8
56
+ Interval d7: 9
57
+ Interval A6:10
58
+ Interval d8:11
59
+ Interval A7:12
60
+
61
+ Interval S: 1
62
+ Interval T: 3
63
+ Interval TT:6
64
+
65
+ Interval P1: 0
66
+ Interval m2: 1
67
+ Interval M2: 2
68
+ Interval m3: 3
69
+ Interval M3: 4
70
+ Interval P4: 5
71
+ Interval A4: 6
72
+ Interval d5: 6
73
+ Interval P5: 7
74
+ Interval m6: 8
75
+ Interval M6: 9
76
+ Interval m7:10
77
+ Interval M7:11
78
+ Interval P8:12
105
79
  end
@@ -2,7 +2,7 @@ require 'named_value_class'
2
2
 
3
3
  module Peas
4
4
  NamedValueClass PitchClass:Fixnum, constrain:0..11 do
5
- minus_a 'Interval::Base' do |lhs,minus,rhs|
5
+ minus_a :Interval do |lhs,minus,rhs|
6
6
  result = minus.call(rhs) % 12
7
7
  is_sharp? ? PitchClass.sharps[result] : PitchClass.flats[result]
8
8
  end
@@ -10,6 +10,8 @@ module Peas
10
10
  all_operators_with_a :PitchClass, raise:SyntaxError
11
11
  all_operators_with_a :Pitch, raise:SyntaxError
12
12
 
13
+ divided_by_a :Interval, raises:SyntaxError
14
+
13
15
  def as_flat
14
16
  self.class.naturals[self] || self.class.flats[self]
15
17
  end
data/lib/peas/scale.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'named_value_class'
2
+
3
+ module Peas
4
+ NamedValueClass Scale:Array do
5
+ end
6
+ end
data/lib/peas/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Peas
2
2
  NAME = 'peas'
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  SUMMARY = 'Do math with music pitches, intervals, scales, chords and progressions in Ruby.'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-20 00:00:00.000000000Z
12
+ date: 2012-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: named_value_class
16
- requirement: &2151835560 !ruby/object:Gem::Requirement
16
+ requirement: &2153195200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -24,7 +24,7 @@ dependencies:
24
24
  version: 0.7.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *2151835560
27
+ version_requirements: *2153195200
28
28
  description: Peas defines constants from music theory and allows one to perform math
29
29
  with them. Currently supports pitches (as MIDI values), pitch classes, and intervals
30
30
  using semitones, wholetones, chromatic, latin or diatonic abbreviations.
@@ -33,10 +33,11 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
- - lib/peas/interger_helper.rb
36
+ - lib/peas/integer_helper.rb
37
37
  - lib/peas/interval.rb
38
38
  - lib/peas/pitch.rb
39
39
  - lib/peas/pitch_class.rb
40
+ - lib/peas/scale.rb
40
41
  - lib/peas/version.rb
41
42
  - lib/peas.rb
42
43
  homepage: http://github.com/mgarriss/peas
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  version: '0'
60
61
  requirements: []
61
62
  rubyforge_project:
62
- rubygems_version: 1.8.11
63
+ rubygems_version: 1.8.12
63
64
  signing_key:
64
65
  specification_version: 3
65
66
  summary: Peas defines constants from music theory and allows one to perform math with