Class: Clef::Core::Score
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Metadata
#metadata, #metadata=, #set_metadata, #update_metadata
Constructor Details
#initialize(metadata: {}) ⇒ Score
Returns a new instance of Score.
11
12
13
14
|
# File 'lib/clef/core/score.rb', line 11
def initialize(metadata: {})
@staff_groups = []
self.metadata = metadata
end
|
Instance Attribute Details
#composer ⇒ Object
Returns the value of attribute composer.
8
9
10
|
# File 'lib/clef/core/score.rb', line 8
def composer
@composer
end
|
#plugins ⇒ Object
Returns the value of attribute plugins.
8
9
10
|
# File 'lib/clef/core/score.rb', line 8
def plugins
@plugins
end
|
#tempo ⇒ Object
Returns the value of attribute tempo.
8
9
10
|
# File 'lib/clef/core/score.rb', line 8
def tempo
@tempo
end
|
#title ⇒ Object
Returns the value of attribute title.
8
9
10
|
# File 'lib/clef/core/score.rb', line 8
def title
@title
end
|
Instance Method Details
#add_staff(staff) ⇒ Score
29
30
31
32
33
34
35
|
# File 'lib/clef/core/score.rb', line 29
def add_staff(staff)
raise ArgumentError, "staff must be a Clef::Core::Staff" unless staff.is_a?(Staff)
raise ArgumentError, "duplicate staff id: #{staff.id}" if staves.any? { |existing| existing.id == staff.id }
default_group.add_staff(staff)
self
end
|
#add_staff_group(staff_group) ⇒ Score
18
19
20
21
22
23
24
25
|
# File 'lib/clef/core/score.rb', line 18
def add_staff_group(staff_group)
raise ArgumentError, "staff_group must be a Clef::Core::StaffGroup" unless staff_group.is_a?(StaffGroup)
duplicate = staff_group.staves.find { |staff| staves.any? { |existing| existing.id == staff.id } }
raise ArgumentError, "duplicate staff id: #{duplicate.id}" if duplicate
@staff_groups << staff_group
self
end
|
#staff_groups ⇒ Array<StaffGroup>
43
44
45
|
# File 'lib/clef/core/score.rb', line 43
def staff_groups
@staff_groups.dup.freeze
end
|
#staves ⇒ Array<Staff>
38
39
40
|
# File 'lib/clef/core/score.rb', line 38
def staves
@staff_groups.flat_map(&:staves).freeze
end
|
67
68
69
70
71
72
73
74
75
|
# File 'lib/clef/core/score.rb', line 67
def to_format(path, **options)
case File.extname(path.to_s).downcase
when ".pdf" then to_pdf(path, **options)
when ".svg" then to_svg(path, **options)
when ".mid", ".midi" then to_midi(path, **options)
else
raise ArgumentError, "unsupported output format for #{path.inspect}"
end
end
|
#to_midi(path, **options) ⇒ Object
61
62
63
|
# File 'lib/clef/core/score.rb', line 61
def to_midi(path, **options)
::Clef::Midi::Exporter.new(self, **options).export(path)
end
|
#to_pdf(path, **options) ⇒ Object
#to_svg(path, **options) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/clef/core/score.rb', line 79
def validate(strict: false)
result = ValidationResult.new(validation_issues)
raise Clef::Error, result.errors.map(&:message).join(", ") if strict && !result.ok?
result
end
|
87
88
89
|
# File 'lib/clef/core/score.rb', line 87
def validation_warnings
validate.warnings
end
|