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 +5 -5
- data/.autotest +25 -25
- data/History.txt +6 -6
- data/Manifest.txt +8 -8
- data/README.txt +0 -1
- data/Rakefile +2 -1
- data/lib/mm/lilypond.rb +119 -118
- data/test/mm/test_lilypond.rb +70 -68
- data/test/test_template.ly.erb +1 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cd930b1d2e25368ab27876e5c0a80e7551eec8f599353892322ed8514f5dfdab
|
4
|
+
data.tar.gz: 02d6e331e9768b36cbbdd38aed6b72ea94fe73c6b7d5c85f0c9b0bbbcb0ae101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/Rakefile
CHANGED
data/lib/mm/lilypond.rb
CHANGED
@@ -1,118 +1,119 @@
|
|
1
|
-
require 'mm'
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
"
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
basename
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
output.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
+
|
data/test/mm/test_lilypond.rb
CHANGED
@@ -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 "
|
35
|
-
assert_equal "
|
36
|
-
assert_equal "
|
37
|
-
assert_equal "cDs
|
38
|
-
assert_equal "
|
39
|
-
assert_equal "d
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
assert_equal "
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
assert_equal "
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
assert_equal "
|
66
|
-
|
67
|
-
|
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
|
+
|
data/test/test_template.ly.erb
CHANGED
@@ -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.
|
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:
|
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.
|
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.
|
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.
|
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.
|
95
|
+
rubygems_version: 2.7.3
|
82
96
|
signing_key:
|
83
97
|
specification_version: 4
|
84
98
|
summary: FIX (describe your package)
|