musical_score 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +25 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1156 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/codeclimate-config.patch +1191 -0
- data/lib/musical_score/attribute/attribute.rb +69 -0
- data/lib/musical_score/attribute/clef.rb +44 -0
- data/lib/musical_score/attribute/key.rb +74 -0
- data/lib/musical_score/attribute/time.rb +43 -0
- data/lib/musical_score/const.rb +16 -0
- data/lib/musical_score/element_base.rb +17 -0
- data/lib/musical_score/errors.rb +3 -0
- data/lib/musical_score/io/importer.rb +22 -0
- data/lib/musical_score/location.rb +13 -0
- data/lib/musical_score/measures.rb +42 -0
- data/lib/musical_score/note/lyric.rb +43 -0
- data/lib/musical_score/note/notation/notation.rb +105 -0
- data/lib/musical_score/note/notation/tie.rb +22 -0
- data/lib/musical_score/note/notation/tuplet.rb +22 -0
- data/lib/musical_score/note/note.rb +141 -0
- data/lib/musical_score/note/pitch.rb +140 -0
- data/lib/musical_score/note/time_modification.rb +33 -0
- data/lib/musical_score/note/type.rb +29 -0
- data/lib/musical_score/notes.rb +37 -0
- data/lib/musical_score/part/measure.rb +49 -0
- data/lib/musical_score/part/part.rb +45 -0
- data/lib/musical_score/score/identification/creator.rb +29 -0
- data/lib/musical_score/score/identification/encoding.rb +66 -0
- data/lib/musical_score/score/identification/identification.rb +47 -0
- data/lib/musical_score/score/part/part.rb +37 -0
- data/lib/musical_score/score/score.rb +126 -0
- data/lib/musical_score/version.rb +4 -0
- data/lib/musical_score.rb +12 -0
- data/musical_score.gemspec +42 -0
- metadata +184 -0
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require 'rexml/formatters/pretty'
|
3
|
+
Dir[File.expand_path('../', __FILE__) << '/**/*.rb'].each do |file|
|
4
|
+
# require file except myself
|
5
|
+
if(file != __FILE__)
|
6
|
+
require file
|
7
|
+
end
|
8
|
+
end
|
9
|
+
module MusicalScore
|
10
|
+
module Score
|
11
|
+
class Score < MusicalScore::ElementBase
|
12
|
+
include Contracts
|
13
|
+
|
14
|
+
attr_reader :file_path
|
15
|
+
attr_accessor :credits, :identification, :part_list, :parts
|
16
|
+
Contract KeywordArgs[
|
17
|
+
:credits => Optional[ArrayOf[String]],
|
18
|
+
:identification => Optional[MusicalScore::Score::Identification::Identification],
|
19
|
+
:part_list => ArrayOf[MusicalScore::Score::Part::Part],
|
20
|
+
:parts => ArrayOf[MusicalScore::Part::Part],
|
21
|
+
:file_path => Optional[String],
|
22
|
+
] => Any
|
23
|
+
def initialize(
|
24
|
+
credits: nil,
|
25
|
+
identification: nil,
|
26
|
+
part_list:,
|
27
|
+
parts:,
|
28
|
+
file_path: nil
|
29
|
+
)
|
30
|
+
@credits = credits
|
31
|
+
@identification = identification
|
32
|
+
@part_list = part_list
|
33
|
+
@parts = parts
|
34
|
+
@file_path = file_path
|
35
|
+
|
36
|
+
set_location
|
37
|
+
end
|
38
|
+
|
39
|
+
Contract REXML::Document, String => MusicalScore::Score::Score
|
40
|
+
def self.create_by_xml(xml_doc, file_path)
|
41
|
+
partwise = xml_doc.elements["//score-partwise"]
|
42
|
+
|
43
|
+
args = {}
|
44
|
+
args[:file_path] = file_path
|
45
|
+
identification_doc = partwise.elements["//identification"]
|
46
|
+
if (identification_doc)
|
47
|
+
identification = MusicalScore::Score::Identification::Identification.create_by_xml(identification_doc)
|
48
|
+
args[:identification] = identification
|
49
|
+
end
|
50
|
+
credits = Array.new
|
51
|
+
partwise.elements.each("//credit/credit-words") do |element|
|
52
|
+
credits.push(element.text)
|
53
|
+
end
|
54
|
+
args[:credits] = credits
|
55
|
+
|
56
|
+
part_list = Array.new
|
57
|
+
partwise.elements.each("//part-list/score-part") do |element|
|
58
|
+
part_name = element.elements["part-name"].text
|
59
|
+
part_abbreviation = element.elements["part-abbreviation"].text
|
60
|
+
part = MusicalScore::Score::Part::Part.new(part_name, part_abbreviation)
|
61
|
+
part_list.push(part)
|
62
|
+
end
|
63
|
+
args[:part_list] = part_list
|
64
|
+
|
65
|
+
parts = Array.new
|
66
|
+
partwise.elements.each("//part") do |element|
|
67
|
+
part = MusicalScore::Part::Part.create_by_xml(element)
|
68
|
+
parts.push(part)
|
69
|
+
end
|
70
|
+
args[:parts] = parts
|
71
|
+
|
72
|
+
return MusicalScore::Score::Score.new(args)
|
73
|
+
end
|
74
|
+
|
75
|
+
def export_xml(path)
|
76
|
+
doc = REXML::Document.new
|
77
|
+
doc << REXML::XMLDecl.new('1.0', 'UTF-8')
|
78
|
+
doc << REXML::Document.new(<<-EOS).doctype
|
79
|
+
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
|
80
|
+
EOS
|
81
|
+
|
82
|
+
score_partwise = REXML::Element.new('score-partwise')
|
83
|
+
if (@identification)
|
84
|
+
score_partwise.add_element(@identification.export_xml)
|
85
|
+
end
|
86
|
+
|
87
|
+
if (@credits)
|
88
|
+
@credits.each_with_index do |credit, index|
|
89
|
+
credit_element = REXML::Element.new('credit')
|
90
|
+
credit_element.add_attribute('page', index + 1)
|
91
|
+
|
92
|
+
credit_word = REXML::Element.new('credit-words')
|
93
|
+
credit_word.add_text(credit)
|
94
|
+
|
95
|
+
credit_element.add_element(credit_word)
|
96
|
+
score_partwise.add_element(credit_element)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
part_list = REXML::Element.new('part-list')
|
100
|
+
@part_list.each_with_index do |part, index|
|
101
|
+
part_list.add_element(part.export_xml(index + 1))
|
102
|
+
end
|
103
|
+
score_partwise.add_element(part_list)
|
104
|
+
#
|
105
|
+
@parts.each_with_index do |part, index|
|
106
|
+
score_partwise.add_element(part.export_xml(index + 1))
|
107
|
+
end
|
108
|
+
|
109
|
+
doc.add_element(score_partwise)
|
110
|
+
|
111
|
+
xml = ''
|
112
|
+
formatter = REXML::Formatters::Pretty.new(4)
|
113
|
+
formatter.compact = true
|
114
|
+
formatter.write(doc, xml)
|
115
|
+
|
116
|
+
# puts xml
|
117
|
+
end
|
118
|
+
|
119
|
+
def set_location
|
120
|
+
@parts.each do |part|
|
121
|
+
part.set_location
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'musical_score/version'
|
2
|
+
require 'musical_score/element_base'
|
3
|
+
require 'musical_score/const'
|
4
|
+
require 'musical_score/errors'
|
5
|
+
require 'musical_score/location'
|
6
|
+
Dir[File.expand_path('../musical_score', __FILE__) << '/**/*.rb'].each do |file|
|
7
|
+
require file
|
8
|
+
end
|
9
|
+
|
10
|
+
module MusicalScore
|
11
|
+
# Your code goes here...
|
12
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'musical_score/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "musical_score"
|
8
|
+
spec.version = MusicalScore::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Yuma Ito"]
|
11
|
+
spec.email = ["yumaito0@gmail.com"]
|
12
|
+
|
13
|
+
spec.homepage = "https://github.com/yumaito/musical_score"
|
14
|
+
spec.summary = "Ruby library for analysing a musical score."
|
15
|
+
spec.description = "Ruby library for analysing a musical score. See README.md"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
# if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
# else
|
23
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
24
|
+
# "public gem pushes."
|
25
|
+
# end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
37
|
+
spec.add_development_dependency "fuubar"
|
38
|
+
spec.add_development_dependency "yard"
|
39
|
+
spec.add_development_dependency "yard-contracts"
|
40
|
+
|
41
|
+
spec.add_dependency "contracts"
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: musical_score
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuma Ito
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fuubar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard-contracts
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: contracts
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Ruby library for analysing a musical score. See README.md
|
112
|
+
email:
|
113
|
+
- yumaito0@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".codeclimate.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- codeclimate-config.patch
|
131
|
+
- lib/musical_score.rb
|
132
|
+
- lib/musical_score/attribute/attribute.rb
|
133
|
+
- lib/musical_score/attribute/clef.rb
|
134
|
+
- lib/musical_score/attribute/key.rb
|
135
|
+
- lib/musical_score/attribute/time.rb
|
136
|
+
- lib/musical_score/const.rb
|
137
|
+
- lib/musical_score/element_base.rb
|
138
|
+
- lib/musical_score/errors.rb
|
139
|
+
- lib/musical_score/io/importer.rb
|
140
|
+
- lib/musical_score/location.rb
|
141
|
+
- lib/musical_score/measures.rb
|
142
|
+
- lib/musical_score/note/lyric.rb
|
143
|
+
- lib/musical_score/note/notation/notation.rb
|
144
|
+
- lib/musical_score/note/notation/tie.rb
|
145
|
+
- lib/musical_score/note/notation/tuplet.rb
|
146
|
+
- lib/musical_score/note/note.rb
|
147
|
+
- lib/musical_score/note/pitch.rb
|
148
|
+
- lib/musical_score/note/time_modification.rb
|
149
|
+
- lib/musical_score/note/type.rb
|
150
|
+
- lib/musical_score/notes.rb
|
151
|
+
- lib/musical_score/part/measure.rb
|
152
|
+
- lib/musical_score/part/part.rb
|
153
|
+
- lib/musical_score/score/identification/creator.rb
|
154
|
+
- lib/musical_score/score/identification/encoding.rb
|
155
|
+
- lib/musical_score/score/identification/identification.rb
|
156
|
+
- lib/musical_score/score/part/part.rb
|
157
|
+
- lib/musical_score/score/score.rb
|
158
|
+
- lib/musical_score/version.rb
|
159
|
+
- musical_score.gemspec
|
160
|
+
homepage: https://github.com/yumaito/musical_score
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata: {}
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 2.6.7
|
181
|
+
signing_key:
|
182
|
+
specification_version: 4
|
183
|
+
summary: Ruby library for analysing a musical score.
|
184
|
+
test_files: []
|