mm-lilypond 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ad079b960a30f3524640a6584595d7d755af516
4
+ data.tar.gz: b89ab3e471ea7530c80b7c67a8fc206442472dee
5
+ SHA512:
6
+ metadata.gz: c8801f4f401d22d69ebf0dcb5f0f9ac61f36760a64b1878e339243a16888fabd4bbc94f6ce7e5e63f62f4b1f107115c1cefef46248b28e781f2b81b222f9a439
7
+ data.tar.gz: 28f695ef56880379d3a361b0834540c080e81b22351f3ec00a3b36c32115a71dce64bb9f84557e5acf84f80c33f7f55998388eea582cccc3d53642e5f94b1c53
data/.autotest ADDED
@@ -0,0 +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
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2014-07-22
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +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
data/README.txt ADDED
@@ -0,0 +1,58 @@
1
+ = mm-lilypond
2
+
3
+ * http://www.lilypond.org
4
+ * http://www.andrewchristophersmith.com
5
+
6
+ == DESCRIPTION:
7
+
8
+ FIX (describe your package)
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * FIX (list of features or problems)
13
+
14
+ == SYNOPSIS:
15
+
16
+ FIX (code sample of usage)
17
+
18
+ == REQUIREMENTS:
19
+
20
+ * FIX (list of requirements)
21
+
22
+ == INSTALL:
23
+
24
+ * FIX (sudo gem install, anything else)
25
+
26
+ == DEVELOPERS:
27
+
28
+ After checking out the source, run:
29
+
30
+ $ rake newb
31
+
32
+ This task will install any missing dependencies, run the tests/specs,
33
+ and generate the RDoc.
34
+
35
+ == LICENSE:
36
+
37
+ (The MIT License)
38
+
39
+ Copyright (c) 2014 FIX
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+
6
+ # Hoe.plugin :compiler
7
+ # Hoe.plugin :gem_prelude_sucks
8
+ # Hoe.plugin :inline
9
+ # Hoe.plugin :minitest
10
+ # Hoe.plugin :racc
11
+ # Hoe.plugin :rcov
12
+ # Hoe.plugin :rdoc
13
+ # Hoe.plugin :travis
14
+
15
+ Hoe.spec "mm-lilypond" do
16
+ developer("Andrew Smith", "andrewchristophersmith@gmail.com")
17
+
18
+ # self.group_name = "mm-lilypond" # if part of an organization/group
19
+
20
+ # license "MIT" # this should match the license in the README
21
+ end
22
+
23
+ # vim: syntax=ruby
@@ -0,0 +1,118 @@
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
+
@@ -0,0 +1,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 "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
+
@@ -0,0 +1 @@
1
+ music = { <%= my_music %> }
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mm-lilypond
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.14'
41
+ description: FIX (describe your package)
42
+ email:
43
+ - andrewchristophersmith@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - README.txt
50
+ files:
51
+ - ".autotest"
52
+ - History.txt
53
+ - Manifest.txt
54
+ - README.txt
55
+ - Rakefile
56
+ - lib/mm/lilypond.rb
57
+ - test/mm/test_lilypond.rb
58
+ - test/test_template.ly.erb
59
+ homepage: http://www.lilypond.org
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options:
65
+ - "--main"
66
+ - README.txt
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: FIX (describe your package)
85
+ test_files: []