mm-lilypond 1.0.0 → 1.1.0

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
- SHA1:
3
- metadata.gz: 6ad079b960a30f3524640a6584595d7d755af516
4
- data.tar.gz: b89ab3e471ea7530c80b7c67a8fc206442472dee
2
+ SHA256:
3
+ metadata.gz: cd930b1d2e25368ab27876e5c0a80e7551eec8f599353892322ed8514f5dfdab
4
+ data.tar.gz: 02d6e331e9768b36cbbdd38aed6b72ea94fe73c6b7d5c85f0c9b0bbbcb0ae101
5
5
  SHA512:
6
- metadata.gz: c8801f4f401d22d69ebf0dcb5f0f9ac61f36760a64b1878e339243a16888fabd4bbc94f6ce7e5e63f62f4b1f107115c1cefef46248b28e781f2b81b222f9a439
7
- data.tar.gz: 28f695ef56880379d3a361b0834540c080e81b22351f3ec00a3b36c32115a71dce64bb9f84557e5acf84f80c33f7f55998388eea582cccc3d53642e5f94b1c53
6
+ metadata.gz: 48e39b98a3f8896df5dd14da6d366b4c07e7f4ebf5e8298bf332db59bf152caa8ee59bae2f803750d5ab83891a15093d678a653cca85f19816d1c1817dc2d3be
7
+ data.tar.gz: cab4a1af508f392e4bb1e073198eeaf69bdfd7861badaf070d4fe948297d38d4069253a15115f007d2b6737efa3ee1e48d86557b75cfc57d033cf2c622867f4a
data/.autotest CHANGED
@@ -1,25 +1,25 @@
1
- # -*- ruby -*-
2
-
3
- require "autotest/restart"
4
-
5
- # Autotest.add_hook :initialize do |at|
6
- # at.testlib = "minitest/unit"
7
- #
8
- # at.extra_files << "../some/external/dependency.rb"
9
- #
10
- # at.libs << ":../some/external"
11
- #
12
- # at.add_exception "vendor"
13
- #
14
- # at.add_mapping(/dependency.rb/) do |f, _|
15
- # at.files_matching(/test_.*rb$/)
16
- # end
17
- #
18
- # %w(TestA TestB).each do |klass|
19
- # at.extra_class_map[klass] = "test/test_misc.rb"
20
- # end
21
- # end
22
-
23
- # Autotest.add_hook :run_command do |at|
24
- # system "rake build"
25
- # end
1
+ # -*- ruby -*-
2
+
3
+ require "autotest/restart"
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.testlib = "minitest/unit"
7
+ #
8
+ # at.extra_files << "../some/external/dependency.rb"
9
+ #
10
+ # at.libs << ":../some/external"
11
+ #
12
+ # at.add_exception "vendor"
13
+ #
14
+ # at.add_mapping(/dependency.rb/) do |f, _|
15
+ # at.files_matching(/test_.*rb$/)
16
+ # end
17
+ #
18
+ # %w(TestA TestB).each do |klass|
19
+ # at.extra_class_map[klass] = "test/test_misc.rb"
20
+ # end
21
+ # end
22
+
23
+ # Autotest.add_hook :run_command do |at|
24
+ # system "rake build"
25
+ # end
data/History.txt CHANGED
@@ -1,6 +1,6 @@
1
- === 1.0.0 / 2014-07-22
2
-
3
- * 1 major enhancement
4
-
5
- * Birthday!
6
-
1
+ === 1.0.0 / 2014-07-22
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt CHANGED
@@ -1,8 +1,8 @@
1
- .autotest
2
- History.txt
3
- Manifest.txt
4
- README.txt
5
- Rakefile
6
- lib/mm/lilypond.rb
7
- test/mm/test_lilypond.rb
8
- test/test_template.ly.erb
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/mm/lilypond.rb
7
+ test/mm/test_lilypond.rb
8
+ test/test_template.ly.erb
data/README.txt CHANGED
@@ -1,6 +1,5 @@
1
1
  = mm-lilypond
2
2
 
3
- * http://www.lilypond.org
4
3
  * http://www.andrewchristophersmith.com
5
4
 
6
5
  == DESCRIPTION:
data/Rakefile CHANGED
@@ -6,7 +6,8 @@ require "hoe"
6
6
  # Hoe.plugin :compiler
7
7
  # Hoe.plugin :gem_prelude_sucks
8
8
  # Hoe.plugin :inline
9
- # Hoe.plugin :minitest
9
+ Hoe.plugin :minitest
10
+ Hoe.plugin :gemspec
10
11
  # Hoe.plugin :racc
11
12
  # Hoe.plugin :rcov
12
13
  # Hoe.plugin :rdoc
data/lib/mm/lilypond.rb CHANGED
@@ -1,118 +1,119 @@
1
- require 'mm'
2
- require 'erb'
3
-
4
- class MM::Lilypond
5
- VERSION = "1.0.0"
6
-
7
- attr_accessor :offset, :basenames, :prime_limit, :prime_steps
8
-
9
- def initialize prime_limit: nil
10
- @offset = 2
11
- @basenames = ["c", "g", "d", "a", "e", "b",
12
- "fsharp", "csharp", "gsharp", "dsharp", "asharp", "esharp", "bsharp",
13
- "fdoublesharp", "cdoublesharp", "gdoublesharp", "ddoublesharp", "adoublesharp", "edoublesharp", "bdoublesharp",
14
- "fdoubleflat", "cdoubleflat", "gdoubleflat", "ddoubleflat", "adoubleflat", "edoubleflat", "bdoubleflat",
15
- "fflat", "cflat", "gflat", "dflat", "aflat", "eflat", "bflat", "f"]
16
- @prime_limit = prime_limit
17
- @prime_steps = [1, 4, -2, -1, 3]
18
- end
19
-
20
- def get_pitch ratio
21
- basename = get_basename ratio
22
- alteration = get_alteration ratio
23
- octave = get_octave ratio
24
- basename + alteration + octave
25
- end
26
-
27
- def get_basename ratio
28
- @basenames[@offset + get_steps(ratio)].dup
29
- end
30
-
31
- def get_alteration ratio
32
- ratio.factors.reject {|f| @prime_limit && f[0] > @prime_limit}.map {|f|
33
- case f[0]
34
- when 5
35
- collect_string f[1], "f"
36
- when 7
37
- collect_string f[1], "s"
38
- when 11
39
- collect_string f[1] * -1, "e"
40
- when 13
41
- collect_string f[1], "t"
42
- end
43
- }.join("")
44
- end
45
-
46
- def get_octave ratio
47
- offset = (@offset * 4) % 7
48
- degrees = ratio.factors.inject(0) {|d, f|
49
- d + case f[0]
50
- when 2
51
- f[1] * 7
52
- when 3
53
- f[1] * 11
54
- when 5
55
- f[1] * 17
56
- when 7
57
- f[1] * 20
58
- when 11
59
- f[1] * 24
60
- when 13
61
- f[1] * 26
62
- else
63
- 0
64
- end
65
- } + offset
66
- if degrees > 0
67
- (degrees / 7.0).floor.times.map {"'"}.join("")
68
- else
69
- (degrees / -7.0).ceil.times.map {","}.join("")
70
- end
71
- end
72
-
73
- def get_duration ratio
74
- "1*#{ratio.reciprocal.to_s}"
75
- end
76
-
77
- def full_note ratio
78
- get_pitch(ratio) + get_duration(ratio)
79
- end
80
-
81
- attr_writer :template
82
-
83
- def render ratios
84
- my_music = ratios.map {|r| self.full_note r}.join(" ")
85
- output = ERB.new @template
86
- output.result(binding)
87
- end
88
-
89
- private
90
-
91
- def collect_string times, string
92
- if times > 0
93
- times.times.collect {"D#{string}"}
94
- else
95
- (times * -1).times.collect {"U#{string}"}
96
- end
97
- end
98
-
99
- def get_steps ratio
100
- ratio.factors.inject(0) {|memo, f|
101
- memo + case f[0]
102
- when 3
103
- f[1] * @prime_steps[0]
104
- when 5
105
- f[1] * @prime_steps[1]
106
- when 7
107
- f[1] * @prime_steps[2]
108
- when 11
109
- f[1] * @prime_steps[3]
110
- when 13
111
- f[1] * @prime_steps[4]
112
- else
113
- 0
114
- end
115
- }
116
- end
117
- end
118
-
1
+ require 'mm'
2
+ require 'pry'
3
+ require 'erb'
4
+
5
+ class MM::Lilypond
6
+ VERSION = "1.1.0"
7
+
8
+ attr_accessor :offset, :basenames, :prime_limit, :prime_steps
9
+ attr_writer :template
10
+
11
+ def initialize prime_limit: nil
12
+ # offset is around the circle of fifths
13
+ @offset = 2
14
+ @basenames = ["c", "g", "d", "a", "e", "b",
15
+ "fsharp", "csharp", "gsharp", "dsharp", "asharp", "esharp", "bsharp",
16
+ "fdoublesharp", "cdoublesharp", "gdoublesharp", "ddoublesharp", "adoublesharp", "edoublesharp", "bdoublesharp",
17
+ "fdoubleflat", "cdoubleflat", "gdoubleflat", "ddoubleflat", "adoubleflat", "edoubleflat", "bdoubleflat",
18
+ "fflat", "cflat", "gflat", "dflat", "aflat", "eflat", "bflat", "f"]
19
+ @prime_limit = prime_limit
20
+ @prime_steps = [1, 4, -2, -1, 3]
21
+ end
22
+
23
+ def get_pitch ratio
24
+ basename = get_basename ratio
25
+ alteration = get_alteration ratio
26
+ octave = get_octave ratio
27
+ basename + alteration + octave
28
+ end
29
+
30
+ def get_basename ratio
31
+ @basenames[@offset + get_steps(ratio)].dup
32
+ end
33
+
34
+ def get_alteration ratio
35
+ ratio.factors.reject {|f| @prime_limit && f[0] > @prime_limit}.map {|f|
36
+ case f[0]
37
+ when 5
38
+ collect_string f[1], "f"
39
+ when 7
40
+ collect_string f[1], "s"
41
+ when 11
42
+ collect_string f[1] * -1, "e"
43
+ when 13
44
+ collect_string f[1], "t"
45
+ end
46
+ }.join("")
47
+ end
48
+
49
+ def get_octave ratio
50
+ offset = (@offset * 4) % 7
51
+ degrees = ratio.factors.inject(0) {|d, f|
52
+ d + case f[0]
53
+ when 2
54
+ f[1] * 7
55
+ when 3
56
+ f[1] * 11
57
+ when 5
58
+ f[1] * 16
59
+ when 7
60
+ f[1] * 20
61
+ when 11
62
+ f[1] * 24
63
+ when 13
64
+ f[1] * 26
65
+ else
66
+ 0
67
+ end
68
+ } + offset
69
+ if degrees > 0
70
+ (degrees / 7.0).floor.times.map {"'"}.join("")
71
+ else
72
+ (degrees / -7.0).ceil.times.map {","}.join("")
73
+ end
74
+ end
75
+
76
+ def get_duration ratio
77
+ "1*#{ratio.reciprocal.to_s}"
78
+ end
79
+
80
+ def full_note ratio
81
+ get_pitch(ratio) + get_duration(ratio)
82
+ end
83
+
84
+ def render ratios
85
+ my_music = ratios.map {|r| self.full_note r}.join(" ")
86
+ output = ERB.new @template
87
+ output.result(binding)
88
+ end
89
+
90
+ private
91
+
92
+ def collect_string times, string
93
+ if times > 0
94
+ times.times.collect {"D#{string}"}
95
+ else
96
+ (times * -1).times.collect {"U#{string}"}
97
+ end
98
+ end
99
+
100
+ def get_steps ratio
101
+ ratio.factors.inject(0) {|memo, f|
102
+ memo + case f[0]
103
+ when 3
104
+ f[1] * @prime_steps[0]
105
+ when 5
106
+ f[1] * @prime_steps[1]
107
+ when 7
108
+ f[1] * @prime_steps[2]
109
+ when 11
110
+ f[1] * @prime_steps[3]
111
+ when 13
112
+ f[1] * @prime_steps[4]
113
+ else
114
+ 0
115
+ end
116
+ }
117
+ end
118
+ end
119
+
@@ -1,68 +1,70 @@
1
- require "minitest/autorun"
2
- require "mm/lilypond"
3
-
4
- module TestMM; end
5
-
6
- class TestMM::TestLilypond < Minitest::Test
7
- def setup
8
- @lily_parser = MM::Lilypond.new
9
- end
10
-
11
- def test_get_duration
12
- assert_equal "1*2/3", @lily_parser.get_duration(MM::Ratio.new(3,2))
13
- end
14
-
15
- def test_get_basename
16
- assert_equal "e", @lily_parser.get_basename(MM::Ratio.new(9,8))
17
- assert_equal "fsharp", @lily_parser.get_basename(MM::Ratio.new(5,4))
18
- assert_equal "c", @lily_parser.get_basename(MM::Ratio.new(7,4))
19
- assert_equal "g", @lily_parser.get_basename(MM::Ratio.new(11,8))
20
- end
21
-
22
- def test_get_alteration
23
- assert_equal "Df", @lily_parser.get_alteration(MM::Ratio.new(5,4))
24
- assert_equal "Ds", @lily_parser.get_alteration(MM::Ratio.new(7,4))
25
- end
26
-
27
- def test_get_octave
28
- assert_equal ",,", @lily_parser.get_octave(MM::Ratio.new(1,4))
29
- assert_equal "'", @lily_parser.get_octave(MM::Ratio.new(9,4))
30
- assert_equal "", @lily_parser.get_octave(MM::Ratio.new(7,4))
31
- end
32
-
33
- def test_get_pitch
34
- assert_equal "a", @lily_parser.get_pitch(MM::Ratio.new(3,2))
35
- assert_equal "fsharpDf", @lily_parser.get_pitch(MM::Ratio.new(5,4))
36
- assert_equal "cDs", @lily_parser.get_pitch(MM::Ratio.new(7,4))
37
- assert_equal "cDs,", @lily_parser.get_pitch(MM::Ratio.new(7,8))
38
- assert_equal "d'", @lily_parser.get_pitch(MM::Ratio.new(2,1))
39
- assert_equal "d,", @lily_parser.get_pitch(MM::Ratio.new(1,2))
40
- end
41
-
42
- def test_get_full_note
43
- assert_equal "d'1*1/2", @lily_parser.full_note(MM::Ratio.new(2,1))
44
- assert_equal "aflatUfDs1*5/7", @lily_parser.full_note(MM::Ratio.new(7,5))
45
- end
46
-
47
- def test_render
48
- @lily_parser.template = File.read("test/test_template.ly.erb")
49
- exp = "music = { a1*2/3 cDs1*4/7 }\n"
50
- result = @lily_parser.render([MM::Ratio.new(3,2), MM::Ratio.new(7,4)])
51
- assert_equal exp, result
52
- end
53
-
54
- def test_offset
55
- @lily_parser.offset = 0
56
- assert_equal "c", @lily_parser.get_pitch(MM::Ratio.new(1,1))
57
- assert_equal "eDf", @lily_parser.get_pitch(MM::Ratio.new(5,4))
58
- end
59
-
60
- def test_prime_limit
61
- @lily_parser.prime_limit = 3
62
- @lily_parser.prime_steps[3] = 6
63
- assert_equal "bflat", @lily_parser.get_pitch(MM::Ratio.new(14, 9))
64
- assert_equal "fsharp", @lily_parser.get_pitch(MM::Ratio.new(5, 4))
65
- assert_equal "gsharp", @lily_parser.get_pitch(MM::Ratio.new(11, 8))
66
- end
67
- end
68
-
1
+ require "minitest/autorun"
2
+ require "mm/lilypond"
3
+
4
+ module TestMM; end
5
+
6
+ class TestMM::TestLilypond < Minitest::Test
7
+ def setup
8
+ @lily_parser = MM::Lilypond.new
9
+ end
10
+
11
+ def test_get_duration
12
+ assert_equal "1*2/3", @lily_parser.get_duration(MM::Ratio.new(3,2))
13
+ end
14
+
15
+ def test_get_basename
16
+ assert_equal "e", @lily_parser.get_basename(MM::Ratio.new(9,8))
17
+ assert_equal "fsharp", @lily_parser.get_basename(MM::Ratio.new(5,4))
18
+ assert_equal "c", @lily_parser.get_basename(MM::Ratio.new(7,4))
19
+ assert_equal "g", @lily_parser.get_basename(MM::Ratio.new(11,8))
20
+ end
21
+
22
+ def test_get_alteration
23
+ assert_equal "Df", @lily_parser.get_alteration(MM::Ratio.new(5,4))
24
+ assert_equal "Ds", @lily_parser.get_alteration(MM::Ratio.new(7,4))
25
+ end
26
+
27
+ def test_get_octave
28
+ assert_equal ",,", @lily_parser.get_octave(MM::Ratio.new(1,4))
29
+ assert_equal "'", @lily_parser.get_octave(MM::Ratio.new(9,4))
30
+ assert_equal "'", @lily_parser.get_octave(MM::Ratio.new(7,4))
31
+ end
32
+
33
+ def test_get_pitch
34
+ assert_equal "d", @lily_parser.get_pitch(MM::Ratio.new(1,1))
35
+ assert_equal "a", @lily_parser.get_pitch(MM::Ratio.new(3,2))
36
+ assert_equal "fsharpDf", @lily_parser.get_pitch(MM::Ratio.new(5,4))
37
+ assert_equal "cDs'", @lily_parser.get_pitch(MM::Ratio.new(7,4))
38
+ assert_equal "cDs", @lily_parser.get_pitch(MM::Ratio.new(7,8))
39
+ assert_equal "d'", @lily_parser.get_pitch(MM::Ratio.new(2,1))
40
+ assert_equal "d,", @lily_parser.get_pitch(MM::Ratio.new(1,2))
41
+ end
42
+
43
+ def test_get_full_note
44
+ assert_equal "d'1*1/2", @lily_parser.full_note(MM::Ratio.new(2,1))
45
+ assert_equal "aflatUfDs1*5/7", @lily_parser.full_note(MM::Ratio.new(7,5))
46
+ end
47
+
48
+ def test_render
49
+ @lily_parser.template = File.read("test/test_template.ly.erb")
50
+ exp = "music = { a1*2/3 cDs'1*4/7 }\n"
51
+ result = @lily_parser.render([MM::Ratio.new(3,2), MM::Ratio.new(7,4)])
52
+ assert_equal exp, result
53
+ end
54
+
55
+ def test_offset
56
+ @lily_parser.offset = 0
57
+ assert_equal "c", @lily_parser.get_pitch(MM::Ratio.new(1,1))
58
+ assert_equal "eDf", @lily_parser.get_pitch(MM::Ratio.new(5,4))
59
+ assert_equal "bDf", @lily_parser.get_pitch(MM::Ratio.new(15,8))
60
+ end
61
+
62
+ def test_prime_limit
63
+ @lily_parser.prime_limit = 3
64
+ @lily_parser.prime_steps[3] = 6
65
+ assert_equal "bflat", @lily_parser.get_pitch(MM::Ratio.new(14, 9))
66
+ assert_equal "fsharp", @lily_parser.get_pitch(MM::Ratio.new(5, 4))
67
+ assert_equal "gsharp", @lily_parser.get_pitch(MM::Ratio.new(11, 8))
68
+ end
69
+ end
70
+
@@ -1 +1 @@
1
- music = { <%= my_music %> }
1
+ music = { <%= my_music %> }
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-lilypond
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.10'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rdoc
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,14 +44,14 @@ dependencies:
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '3.14'
47
+ version: '3.16'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '3.14'
54
+ version: '3.16'
41
55
  description: FIX (describe your package)
42
56
  email:
43
57
  - andrewchristophersmith@gmail.com
@@ -56,7 +70,7 @@ files:
56
70
  - lib/mm/lilypond.rb
57
71
  - test/mm/test_lilypond.rb
58
72
  - test/test_template.ly.erb
59
- homepage: http://www.lilypond.org
73
+ homepage: http://www.andrewchristophersmith.com
60
74
  licenses:
61
75
  - MIT
62
76
  metadata: {}
@@ -78,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
92
  version: '0'
79
93
  requirements: []
80
94
  rubyforge_project:
81
- rubygems_version: 2.2.2
95
+ rubygems_version: 2.7.3
82
96
  signing_key:
83
97
  specification_version: 4
84
98
  summary: FIX (describe your package)