-
Notifications
You must be signed in to change notification settings - Fork 46
/
Rakefile
108 lines (96 loc) · 2.92 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
desc "Generate Chord.swift and ChordQualities.swift"
task :codegen do
Rake::Task['gen_chordqualities'].execute
Rake::Task['gen_chord'].execute
end
task :docgen do
Rake::Task['gen_frameworkoverview'].execute
end
task :gen_chordqualities do
infile = "MusicKit/ChordQuality.swift"
outfile = "MusicKit/ChordQualities.swift"
lines = File.readlines(infile)
newlines = [
"import Foundation", "\n",
"public extension ChordQuality {",
]
starts = "//:"
continues = "//>"
ends = "//."
all_qualities = []
quality_names = []
for line in lines
if line.include? starts
group = line.sub(starts, "").strip
newlines.push "public static let #{group} = ["
end
if line.include? continues
group = line.sub(continues, "").strip
newlines.push "]"
newlines.push "public static let #{group} = ["
end
if line.include? ends
newlines.push "]"
newlines.push "public static let Tetrads = ChordQuality.UnalteredTetrads + ChordQuality.AlteredTetrads"
newlines.push "public static let Pentads = ChordQuality.UnalteredPentads + ChordQuality.AlteredPentads"
newlines.push "public static let Hexads = ChordQuality.UnalteredHexads + ChordQuality.AlteredHexads"
newlines.push "public static let Heptads = ChordQuality.UnalteredHeptads + ChordQuality.AlteredHeptads"
newlines.push "public static let All = ["
newlines.concat all_qualities
newlines.push "]"
newlines.push "public var name : String {"
newlines.push "switch self {"
newlines.concat quality_names
newlines.push "}"
newlines.push "}"
newlines.push "}"
break
end
if line.include? "case"
quality = line.rpartition('=')[0].sub("case", "").strip
qline = "ChordQuality.#{quality},"
all_qualities.push qline
quality_names.push "case #{quality}: return \"#{quality}\""
newlines.push qline
end
end
File.open(outfile, "w").puts newlines
print("Generated ChordQualities.swift with #{all_qualities.length} chord qualities\n")
end
task :gen_chord do
infile = "MusicKit/ChordQuality.swift"
outfile = "MusicKit/Chord.swift"
lines = File.readlines(infile)
newlines = [
"import Foundation", "\n",
"public enum Chord {",
]
starts = "//:"
continues = "//>"
ends = "//."
for line in lines
if line.include? starts
newlines.push line.strip
end
if line.include? continues
newlines.push line.strip
end
if line.include? ends
newlines.push "}"
break
end
if line.include? "case"
quality = line.rpartition('=')[0].sub("case", "").strip
newlines.push "public static let #{quality} = Harmony.create(ChordQuality.#{quality}.intervals)"
end
end
File.open(outfile, "w").puts newlines
print("Generated Chord.swift\n")
end
task :gen_frameworkoverview do
infile = "Playgrounds/FrameworkOverview.playground/section-1.swift"
outfile = "Documentation/FrameworkOverview.md"
lines = File.readlines(infile).drop(3).join("").gsub("///", "")
File.open(outfile, "w").puts lines
print("Generated FrameworkOverview.md\n")
end