peas 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/peas/integer_helper.rb +17 -17
- data/lib/peas/interval.rb +41 -57
- data/lib/peas/pitch.rb +4 -4
- data/lib/peas/pitch_class.rb +23 -23
- data/lib/peas/version.rb +1 -1
- metadata +6 -6
data/lib/peas/integer_helper.rb
CHANGED
@@ -7,88 +7,88 @@ class Integer
|
|
7
7
|
alias unison unisons
|
8
8
|
|
9
9
|
def semitones
|
10
|
-
Peas::Interval::Semitone "S#{self}"
|
10
|
+
Peas::Interval::Semitone "S#{self}" => self
|
11
11
|
end
|
12
12
|
alias semitone semitones
|
13
13
|
|
14
14
|
def minor_seconds
|
15
|
-
Peas::Interval::Diatonic "m2x#{self}"
|
15
|
+
Peas::Interval::Diatonic "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}"
|
20
|
+
Peas::Interval::Wholetone "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}"
|
25
|
+
Peas::Interval::Diatonic "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}"
|
30
|
+
Peas::Interval::Diatonic "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}"
|
35
|
+
Peas::Interval::Diatonic "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}"
|
40
|
+
Peas::Interval::Diatonic "P4x#{self}" => self * 5
|
41
41
|
end
|
42
42
|
alias perfect_fourth perfect_fourths
|
43
43
|
|
44
44
|
def tritones
|
45
|
-
# Peas::Interval::Latin "TTx#{self}"
|
45
|
+
# Peas::Interval::Latin "TTx#{self}" => self * 6
|
46
46
|
self * 6
|
47
47
|
end
|
48
48
|
alias tritone tritones
|
49
49
|
|
50
50
|
def diminished_fifths
|
51
|
-
Peas::Interval::Diatonic "d5x#{self}"
|
51
|
+
Peas::Interval::Diatonic "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}"
|
56
|
+
Peas::Interval::Diatonic "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}"
|
61
|
+
Peas::Interval::Diatonic "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}"
|
66
|
+
Peas::Interval::Diatonic "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}"
|
71
|
+
Peas::Interval::Chromatic "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}"
|
76
|
+
Peas::Interval::Diatonic "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}"
|
81
|
+
Peas::Interval::Diatonic "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}"
|
86
|
+
Peas::Interval::Diatonic "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}"
|
91
|
+
Peas::Interval::Diatonic "P8x#{self}" => self * 12
|
92
92
|
end
|
93
93
|
alias octave octaves
|
94
94
|
end
|
data/lib/peas/interval.rb
CHANGED
@@ -4,7 +4,8 @@ require 'peas/pitch'
|
|
4
4
|
module Peas
|
5
5
|
module Interval
|
6
6
|
# see: http://en.wikipedia.org/wiki/Interval_(music)
|
7
|
-
|
7
|
+
|
8
|
+
NamedValueClass Base:Integer do
|
8
9
|
def -(rhs)
|
9
10
|
if [Pitch,PitchClass].include?(rhs.class)
|
10
11
|
raise Peas::InvalidOperation, '(Interval - Pitch) has no meaning'
|
@@ -13,48 +14,39 @@ module Peas
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
17
|
-
|
18
|
-
include Peas::Interval::Math
|
19
|
-
end
|
17
|
+
|
18
|
+
class Semitone < Base; end
|
20
19
|
128.times do |x|
|
21
|
-
Semitone "S#{x}"
|
20
|
+
Semitone "S#{x}" => x
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
include Peas::Interval::Math
|
26
|
-
end
|
23
|
+
class Wholetone < Base; end
|
27
24
|
64.times do |x|
|
28
|
-
Wholetone "W#{x}"
|
25
|
+
Wholetone "W#{x}" => x * 2
|
29
26
|
end
|
30
27
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
Chromatic :
|
35
|
-
Chromatic :
|
36
|
-
Chromatic :
|
37
|
-
Chromatic :
|
38
|
-
Chromatic :
|
39
|
-
Chromatic :
|
40
|
-
Chromatic :
|
41
|
-
Chromatic :
|
42
|
-
Chromatic :
|
43
|
-
Chromatic :
|
44
|
-
Chromatic :
|
45
|
-
Chromatic :
|
46
|
-
Chromatic :d8, 11
|
47
|
-
Chromatic :A7, 12
|
28
|
+
class Chromatic < Base; end
|
29
|
+
Chromatic d2: 0
|
30
|
+
Chromatic A1: 1
|
31
|
+
Chromatic d3: 2
|
32
|
+
Chromatic A2: 3
|
33
|
+
Chromatic d4: 4
|
34
|
+
Chromatic A3: 5
|
35
|
+
Chromatic d5: 6
|
36
|
+
Chromatic A4: 6
|
37
|
+
Chromatic d6: 7
|
38
|
+
Chromatic A5: 8
|
39
|
+
Chromatic d7: 9
|
40
|
+
Chromatic A6:10
|
41
|
+
Chromatic d8:11
|
42
|
+
Chromatic A7:12
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
Latin
|
53
|
-
Latin 'T', 3
|
54
|
-
Latin 'TT', 6
|
44
|
+
class Latin < Base; end
|
45
|
+
Latin S: 1
|
46
|
+
Latin T: 3
|
47
|
+
Latin TT:6
|
55
48
|
|
56
|
-
|
57
|
-
include Peas::Interval::Math
|
49
|
+
class Diatonic < Base
|
58
50
|
def inverse
|
59
51
|
case @name
|
60
52
|
when 'P1' then Diatonic::P8
|
@@ -82,20 +74,20 @@ module Peas
|
|
82
74
|
end
|
83
75
|
end
|
84
76
|
end
|
85
|
-
Diatonic
|
86
|
-
Diatonic
|
87
|
-
Diatonic
|
88
|
-
Diatonic
|
89
|
-
Diatonic
|
90
|
-
Diatonic
|
91
|
-
Diatonic
|
92
|
-
Diatonic
|
93
|
-
Diatonic
|
94
|
-
Diatonic
|
95
|
-
Diatonic
|
96
|
-
Diatonic
|
97
|
-
Diatonic
|
98
|
-
Diatonic
|
77
|
+
Diatonic P1: 0
|
78
|
+
Diatonic m2: 1
|
79
|
+
Diatonic M2: 2
|
80
|
+
Diatonic m3: 3
|
81
|
+
Diatonic M3: 4
|
82
|
+
Diatonic P4: 5
|
83
|
+
Diatonic A4: 6
|
84
|
+
Diatonic d5: 6
|
85
|
+
Diatonic P5: 7
|
86
|
+
Diatonic m6: 8
|
87
|
+
Diatonic M6: 9
|
88
|
+
Diatonic m7:10
|
89
|
+
Diatonic M7:11
|
90
|
+
Diatonic P8:12
|
99
91
|
end
|
100
92
|
|
101
93
|
module Intervals
|
@@ -114,12 +106,4 @@ module Peas
|
|
114
106
|
include Interval::Diatonic::NamedValues
|
115
107
|
extend Interval::Diatonic::NamedValues
|
116
108
|
end
|
117
|
-
|
118
|
-
def self.is_an_interval?(obj)
|
119
|
-
[Interval::Semitone,
|
120
|
-
Interval::Wholetone,
|
121
|
-
Interval::Chromatic,
|
122
|
-
Interval::Latin,
|
123
|
-
Interval::Diatonic].include? obj.class
|
124
|
-
end
|
125
109
|
end
|
data/lib/peas/pitch.rb
CHANGED
@@ -3,7 +3,7 @@ require 'peas/pitch_class'
|
|
3
3
|
require 'peas/interval'
|
4
4
|
|
5
5
|
module Peas
|
6
|
-
NamedValueClass
|
6
|
+
NamedValueClass Pitch:Fixnum do
|
7
7
|
extend Forwardable
|
8
8
|
def_delegators :pitch_class, :is_sharp?, :is_flat?, :is_natural?
|
9
9
|
|
@@ -18,7 +18,7 @@ module Peas
|
|
18
18
|
end
|
19
19
|
elsif rhs.class == PitchClass
|
20
20
|
self.pitch_class - rhs
|
21
|
-
elsif
|
21
|
+
elsif rhs.is_a? Interval::Base
|
22
22
|
if is_sharp?
|
23
23
|
Pitch.sharps(self._minus(rhs))
|
24
24
|
else
|
@@ -110,10 +110,10 @@ module Peas
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
PitchClass::NamedValues::Collection.each do |pclass|
|
113
|
-
Pitch "#{pclass}_1"
|
113
|
+
Pitch "#{pclass}_1" => pclass, pitch_class:pclass, octave:-1
|
114
114
|
0.upto(9) do |octave|
|
115
115
|
name = pclass.to_s + octave.to_s
|
116
|
-
Pitch name
|
116
|
+
Pitch name => (((octave+1)*12)+pclass), pitch_class:pclass, octave:octave
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
data/lib/peas/pitch_class.rb
CHANGED
@@ -3,7 +3,7 @@ require 'named_value_class'
|
|
3
3
|
module Peas
|
4
4
|
class InvalidOperation < RuntimeError; end
|
5
5
|
|
6
|
-
NamedValueClass
|
6
|
+
NamedValueClass PitchClass:Fixnum do
|
7
7
|
alias _minus :-
|
8
8
|
|
9
9
|
def -(rhs)
|
@@ -19,7 +19,7 @@ module Peas
|
|
19
19
|
end
|
20
20
|
elsif rhs.class == Pitch
|
21
21
|
self - rhs.pitch_class
|
22
|
-
elsif
|
22
|
+
elsif rhs.is_a? Interval::Base
|
23
23
|
result = self._minus(rhs) % 12
|
24
24
|
if is_sharp?
|
25
25
|
PitchClass.sharps(result)
|
@@ -72,25 +72,25 @@ module Peas
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
PitchClass
|
76
|
-
PitchClass
|
77
|
-
PitchClass
|
78
|
-
PitchClass
|
79
|
-
PitchClass
|
80
|
-
PitchClass
|
81
|
-
PitchClass
|
82
|
-
PitchClass
|
83
|
-
PitchClass
|
84
|
-
PitchClass
|
85
|
-
PitchClass
|
86
|
-
PitchClass
|
87
|
-
PitchClass
|
88
|
-
PitchClass
|
89
|
-
PitchClass
|
90
|
-
PitchClass
|
91
|
-
PitchClass
|
92
|
-
PitchClass
|
93
|
-
PitchClass
|
94
|
-
PitchClass
|
95
|
-
PitchClass
|
75
|
+
PitchClass Bs: 0 # B sharp is just Bs
|
76
|
+
PitchClass C: 0
|
77
|
+
PitchClass Cs: 1
|
78
|
+
PitchClass Db: 1
|
79
|
+
PitchClass D: 2
|
80
|
+
PitchClass Ds: 3
|
81
|
+
PitchClass Eb: 3
|
82
|
+
PitchClass E: 4
|
83
|
+
PitchClass Es: 5
|
84
|
+
PitchClass Fb: 4
|
85
|
+
PitchClass F: 5
|
86
|
+
PitchClass Fs: 6
|
87
|
+
PitchClass Gb: 6
|
88
|
+
PitchClass G: 7
|
89
|
+
PitchClass Gs: 8
|
90
|
+
PitchClass Ab: 8
|
91
|
+
PitchClass A: 9
|
92
|
+
PitchClass As: 10
|
93
|
+
PitchClass Bb: 10
|
94
|
+
PitchClass B: 11
|
95
|
+
PitchClass Cb: 11
|
96
96
|
end
|
data/lib/peas/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: named_value_class
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160584520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0.
|
21
|
+
version: '0.5'
|
22
22
|
- - ! '>='
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 0.
|
24
|
+
version: 0.5.0
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *2160584520
|
28
28
|
description: ! 'Peas defines constants from music theory and allows one to perform
|
29
29
|
math with them. Currently supports pitches (as MIDI values), pitch classes, and
|
30
30
|
intervals using semitones, wholetones, chromatic, latin or diatonic
|