14
15
16
17
18
19
20
21
22
23
24
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
|
# File 'lib/musa-dsl/datasets/score/to-mxml/to-mxml.rb', line 14
def to_mxml(beats_per_bar, ticks_per_beat,
bpm: nil,
title: nil,
creators: nil,
encoding_date: nil,
parts:,
logger: nil,
do_log: nil)
bpm ||= 90
title ||= 'Untitled'
creators ||= { composer: 'Unknown' }
if logger.nil?
logger = Musa::Logger::Logger.new
logger.debug! if do_log
end
do_log ||= nil
mxml = Musa::MusicXML::Builder::ScorePartwise.new do |_|
_.work_title title
_.creators **creators
_.encoding_date encoding_date if encoding_date
parts.each_pair do |id, part_info|
_.part id,
name: part_info&.[](:name),
abbreviation: part_info&.[](:abbreviation) do |_|
_.measure do |_|
_.attributes do |_|
_.divisions ticks_per_beat
i = 0
(part_info&.[](:clefs) || { g: 2 }).each_pair do |clef, line|
i += 1
_.clef i, sign: clef.upcase, line: line
_.time i, beats: beats_per_bar, beat_type: 4
end
end
_.metronome placement: 'above', beat_unit: 'quarter', per_minute: bpm
end
end
end
end
if do_log
logger.debug ""
logger.debug"score.to_mxml log:"
logger.debug"------------------"
end
parts.each_key do |part_id|
fill_part mxml.parts[part_id],
beats_per_bar * ticks_per_beat,
(parts.size > 1 ? part_id : nil),
logger, do_log
end
mxml
end
|