Skip to content

Commit a421997

Browse files
bwetherfieldjsbean
authored andcommitted
Add Bool-to-YesNo conversion for encoding (#217)
1 parent af8647b commit a421997

26 files changed

+130
-33
lines changed

.swiftformat

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
--self init-only
1010
--disable andOperator
1111
--disable spaceAroundGenerics
12+
--disable blankLinesBetweenScopes

Sources/MusicXML/Complex Types/Accidental.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,18 @@ extension Accidental: Codable {
121121
self.value = try container.decode(AccidentalValue.self, forKey: .value)
122122
}
123123

124+
// sourcery:inline:Accidental.AutoEncodable
124125
public func encode(to encoder: Encoder) throws {
125126
var container = encoder.container(keyedBy: CodingKeys.self)
126-
try printStyle.encode(to: encoder)
127127
try container.encode(value, forKey: .value)
128-
try container.encodeIfPresent(cautionary, forKey: .cautionary)
129-
try container.encodeIfPresent(editorial, forKey: .editorial)
130-
try container.encodeIfPresent(parentheses, forKey: .parentheses)
131-
try container.encodeIfPresent(bracket, forKey: .bracket)
128+
try container.encodeIfPresent(YesNo(cautionary), forKey: .cautionary)
129+
try container.encodeIfPresent(YesNo(editorial), forKey: .editorial)
130+
try container.encodeIfPresent(YesNo(parentheses), forKey: .parentheses)
131+
try container.encodeIfPresent(YesNo(bracket), forKey: .bracket)
132132
try container.encodeIfPresent(size, forKey: .size)
133+
try printStyle.encode(to: encoder)
133134
}
135+
// sourcery:end
134136
}
135137

136138
import XMLCoder

Sources/MusicXML/Complex Types/BassAlter.swift

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ extension BassAlter: Codable {
3636
self.printStyle = try PrintStyle(from: decoder)
3737
self.location = try container.decodeIfPresent(LeftRight.self, forKey: .location)
3838
}
39+
40+
// sourcery:inline:BassAlter.AutoEncodable
41+
public func encode(to encoder: Encoder) throws {
42+
var container = encoder.container(keyedBy: CodingKeys.self)
43+
try container.encode(value, forKey: .value)
44+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
45+
try printStyle.encode(to: encoder)
46+
try container.encodeIfPresent(location, forKey: .location)
47+
}
48+
// sourcery:end
3949
}
4050

4151
extension BassAlter: ExpressibleByFloatLiteral {

Sources/MusicXML/Complex Types/Bend.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ extension Bend: Codable {
6969
withBar = try container.decodeIfPresent(PlacementText.self, forKey: .withBar)
7070
}
7171

72+
// sourcery:inline:Bend.AutoEncodable
7273
public func encode(to encoder: Encoder) throws {
7374
var container = encoder.container(keyedBy: CodingKeys.self)
7475
try printStyle.encode(to: encoder)
75-
try container.encodeIfPresent(accelerate, forKey: .accelerate)
76-
try container.encodeIfPresent(beats, forKey: .beats)
76+
try container.encodeIfPresent(YesNo(accelerate), forKey: .accelerate)
77+
try container.encodeIfPresent(YesNo(beats), forKey: .beats)
7778
try container.encodeIfPresent(firstBeat, forKey: .firstBeat)
7879
try container.encodeIfPresent(lastBeat, forKey: .lastBeat)
7980
try container.encodeIfPresent(bendAlter, forKey: .bendAlter)
8081
try container.encodeIfPresent(prependOrRelease, forKey: .prependOrRelease)
8182
try container.encodeIfPresent(withBar, forKey: .withBar)
8283
}
84+
// sourcery:end
8385
}

Sources/MusicXML/Complex Types/Clef.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ extension Clef: Codable {
6666
clefOctaveChange = try container.decodeIfPresent(Int.self, forKey: .clefOctaveChange)
6767
}
6868

69+
// sourcery:inline:Clef.AutoEncodable
6970
public func encode(to encoder: Encoder) throws {
7071
var container = encoder.container(keyedBy: CodingKeys.self)
7172
try container.encodeIfPresent(number, forKey: .number)
72-
try container.encodeIfPresent(additional, forKey: .additional)
73+
try container.encodeIfPresent(YesNo(additional), forKey: .additional)
7374
try container.encodeIfPresent(size, forKey: .size)
74-
try container.encodeIfPresent(afterBarline, forKey: .afterBarline)
75+
try container.encodeIfPresent(YesNo(afterBarline), forKey: .afterBarline)
7576
try printStyle.encode(to: encoder)
76-
try container.encodeIfPresent(printObject, forKey: .printObject)
77+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
7778
try container.encode(sign, forKey: .sign)
7879
try container.encodeIfPresent(line, forKey: .line)
7980
try container.encodeIfPresent(clefOctaveChange, forKey: .clefOctaveChange)
8081
}
82+
// sourcery:end
8183
}
8284

8385
extension Clef: DynamicNodeDecoding {

Sources/MusicXML/Complex Types/DegreeAlter.swift

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ extension DegreeAlter: Codable {
4848
self.value = try container.decode(Int.self, forKey: .value)
4949
self.plusMinus = try container.decodeIfPresent(Bool.self, forKey: .plusMinus)
5050
}
51+
52+
// sourcery:inline:DegreeAlter.AutoEncodable
53+
public func encode(to encoder: Encoder) throws {
54+
var container = encoder.container(keyedBy: CodingKeys.self)
55+
try container.encode(value, forKey: .value)
56+
try container.encodeIfPresent(YesNo(plusMinus), forKey: .plusMinus)
57+
try printStyle.encode(to: encoder)
58+
}
59+
// sourcery:end
5160
}
5261

5362
extension DegreeAlter: ExpressibleByIntegerLiteral {

Sources/MusicXML/Complex Types/Ending.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,19 @@ extension Ending: Codable {
8787
self.value = try container.decode(String.self, forKey: .value)
8888
}
8989

90+
// sourcery:inline:Ending.AutoEncodable
9091
public func encode(to encoder: Encoder) throws {
91-
try printStyle.encode(to: encoder)
9292
var container = encoder.container(keyedBy: CodingKeys.self)
9393
try container.encode(value, forKey: .value)
9494
try container.encode(number, forKey: .number)
9595
try container.encode(type, forKey: .type)
96-
try container.encodeIfPresent(printObject, forKey: .printObject)
96+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
9797
try container.encodeIfPresent(endLength, forKey: .endLength)
9898
try container.encodeIfPresent(textX, forKey: .textX)
9999
try container.encodeIfPresent(textY, forKey: .textY)
100+
try printStyle.encode(to: encoder)
100101
}
102+
// sourcery:end
101103
}
102104

103105
import XMLCoder

Sources/MusicXML/Complex Types/FiguredBass.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,16 @@ extension FiguredBass: Codable {
8282
self.figures = try container.decode([Figure].self, forKey: .figures)
8383
}
8484

85+
// sourcery:inline:FiguredBass.AutoEncodable
8586
public func encode(to encoder: Encoder) throws {
8687
var container = encoder.container(keyedBy: CodingKeys.self)
8788
try printStyle.encode(to: encoder)
8889
try printout.encode(to: encoder)
89-
try container.encodeIfPresent(parentheses, forKey: .parentheses)
90+
try container.encodeIfPresent(YesNo(parentheses), forKey: .parentheses)
9091
try container.encode(figures, forKey: .figures)
9192
try container.encodeIfPresent(duration, forKey: .duration)
9293
try container.encodeIfPresent(footnote, forKey: .footnote)
9394
try container.encodeIfPresent(level, forKey: .level)
9495
}
96+
// sourcery:end
9597
}

Sources/MusicXML/Complex Types/Fingering.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ extension Fingering: Codable {
5252
self.value = try container.decode(String.self, forKey: .value)
5353
}
5454

55+
// sourcery:inline:Fingering.AutoEncodable
5556
public func encode(to encoder: Encoder) throws {
5657
var container = encoder.container(keyedBy: CodingKeys.self)
57-
try printStyle.encode(to: encoder)
5858
try container.encode(value, forKey: .value)
59-
try container.encodeIfPresent(substitution, forKey: .substitution)
60-
try container.encodeIfPresent(alternate, forKey: .alternate)
59+
try container.encodeIfPresent(YesNo(substitution), forKey: .substitution)
60+
try container.encodeIfPresent(YesNo(alternate), forKey: .alternate)
6161
try container.encodeIfPresent(placement, forKey: .placement)
62+
try printStyle.encode(to: encoder)
6263
}
64+
// sourcery:end
6365
}
6466

6567
import XMLCoder

Sources/MusicXML/Complex Types/Harmonic.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ extension Harmonic: Codable {
126126
try container.encode(Empty(), forKey: .artificial)
127127
}
128128
}
129-
try container.encodeIfPresent(printObject, forKey: .printObject)
129+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
130130
try container.encodeIfPresent(placement, forKey: .placement)
131131
}
132132
}

Sources/MusicXML/Complex Types/Harmony.swift

+4
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ extension Harmony: Codable {
9191
self.editorial = try Editorial(from: decoder)
9292
self.staff = try container.decodeIfPresent(Int.self, forKey: .staff)
9393
}
94+
95+
public func encode(to encoder: Encoder) throws {
96+
fatalError("TODO")
97+
}
9498
}

Sources/MusicXML/Complex Types/HorizontalTurn.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ extension HorizontalTurn: Codable {
3636
slash = try container.decodeIfPresent(Bool.self, forKey: .slash)
3737
}
3838

39+
// sourcery:inline:HorizontalTurn.AutoEncodable
3940
public func encode(to encoder: Encoder) throws {
4041
var container = encoder.container(keyedBy: CodingKeys.self)
4142
try printStyle.encode(to: encoder)
4243
try container.encodeIfPresent(placement, forKey: .placement)
4344
try trillSound.encode(to: encoder)
44-
try container.encodeIfPresent(slash, forKey: .slash)
45+
try container.encodeIfPresent(YesNo(slash), forKey: .slash)
4546
}
47+
// sourcery:end
4648
}

Sources/MusicXML/Complex Types/Key.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ extension Key: Codable {
231231
try printStyle.encode(to: encoder)
232232
var container = encoder.container(keyedBy: CodingKeys.self)
233233
try container.encodeIfPresent(number, forKey: .number)
234-
try container.encodeIfPresent(printObject, forKey: .printObject)
234+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
235235
try kind.encode(to: encoder)
236236
try container.encode(keyOctaves, forKey: .keyOctaves)
237237
}

Sources/MusicXML/Complex Types/Kind.swift

+15
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ extension Kind: Codable {
116116
self.vAlign = try container.decodeIfPresent(VAlign.self, forKey: .vAlign)
117117
self.value = try container.decode(KindValue.self, forKey: .value)
118118
}
119+
120+
// sourcery:inline:Kind.AutoEncodable
121+
public func encode(to encoder: Encoder) throws {
122+
var container = encoder.container(keyedBy: CodingKeys.self)
123+
try container.encode(value, forKey: .value)
124+
try container.encodeIfPresent(YesNo(useSymbols), forKey: .useSymbols)
125+
try container.encodeIfPresent(text, forKey: .text)
126+
try container.encodeIfPresent(YesNo(stackDegrees), forKey: .stackDegrees)
127+
try container.encodeIfPresent(YesNo(parenthesesDegrees), forKey: .parenthesesDegrees)
128+
try container.encodeIfPresent(YesNo(bracketDegrees), forKey: .bracketDegrees)
129+
try container.encodeIfPresent(hAlign, forKey: .hAlign)
130+
try container.encodeIfPresent(vAlign, forKey: .vAlign)
131+
try printStyle.encode(to: encoder)
132+
}
133+
// sourcery:end
119134
}
120135

121136
import XMLCoder

Sources/MusicXML/Complex Types/Mordent.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension Mordent: Codable {
3838
public func encode(to encoder: Encoder) throws {
3939
var container = encoder.container(keyedBy: CodingKeys.self)
4040
try value.encode(to: encoder)
41-
try container.encodeIfPresent(long, forKey: .long)
41+
try container.encodeIfPresent(YesNo(long), forKey: .long)
4242
try container.encodeIfPresent(approach, forKey: .approach)
4343
try container.encodeIfPresent(departure, forKey: .departure)
4444
}

Sources/MusicXML/Complex Types/NameDisplay.swift

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ extension NameDisplay: Codable {
8181
let textsContainer = try decoder.singleValueContainer()
8282
self.texts = try textsContainer.decode([Text].self)
8383
}
84+
85+
public func encode(to encoder: Encoder) throws {
86+
fatalError("TODO")
87+
}
8488
}
8589

8690
extension NameDisplay.Text.CodingKeys: XMLChoiceCodingKey {}

Sources/MusicXML/Complex Types/Note.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -461,16 +461,16 @@ extension Note: Codable {
461461
try container.encodeIfPresent(notations, forKey: .notations)
462462
try container.encode(lyrics, forKey: .lyrics)
463463
try container.encodeIfPresent(play, forKey: .play)
464-
try container.encodeIfPresent(printObject, forKey: .printObject)
465-
try container.encodeIfPresent(printDot, forKey: .printDot)
466-
try container.encodeIfPresent(printSpacing, forKey: .printSpacing)
467-
try container.encodeIfPresent(printLyric, forKey: .printLyric)
464+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
465+
try container.encodeIfPresent(YesNo(printDot), forKey: .printDot)
466+
try container.encodeIfPresent(YesNo(printSpacing), forKey: .printSpacing)
467+
try container.encodeIfPresent(YesNo(printLyric), forKey: .printLyric)
468468
try container.encodeIfPresent(dynamics, forKey: .dynamics)
469469
try container.encodeIfPresent(endDynamics, forKey: .endDynamics)
470470
try container.encodeIfPresent(attack, forKey: .attack)
471471
try container.encodeIfPresent(release, forKey: .release)
472472
try container.encodeIfPresent(timeOnly, forKey: .timeOnly)
473-
try container.encodeIfPresent(pizzicato, forKey: .pizzicato)
473+
try container.encodeIfPresent(YesNo(pizzicato), forKey: .pizzicato)
474474

475475
try kind.encode(to: encoder)
476476
}

Sources/MusicXML/Complex Types/Notehead.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ extension Notehead: Codable {
4242
self.color = try container.decodeIfPresent(Color.self, forKey: .color)
4343
}
4444

45+
// sourcery:inline:Notehead.AutoEncodable
4546
public func encode(to encoder: Encoder) throws {
46-
try font.encode(to: encoder)
4747
var container = encoder.container(keyedBy: CodingKeys.self)
4848
try container.encode(value, forKey: .value)
49-
try container.encodeIfPresent(filled, forKey: .filled)
50-
try container.encodeIfPresent(parentheses, forKey: .parentheses)
49+
try container.encodeIfPresent(YesNo(filled), forKey: .filled)
50+
try container.encodeIfPresent(YesNo(parentheses), forKey: .parentheses)
51+
try font.encode(to: encoder)
5152
try container.encodeIfPresent(color, forKey: .color)
5253
}
54+
// sourcery:end
5355
}
5456

5557
import XMLCoder

Sources/MusicXML/Complex Types/OtherDirection.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ extension OtherDirection: Codable {
2727
case value = ""
2828
}
2929

30+
// sourcery:inline:OtherDirection.AutoEncodable
3031
public func encode(to encoder: Encoder) throws {
3132
var container = encoder.container(keyedBy: CodingKeys.self)
3233
try container.encode(value, forKey: .value)
33-
try container.encodeIfPresent(printObject, forKey: .printObject)
34+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
3435
try printStyleAlign.encode(to: encoder)
3536
}
37+
// sourcery:end
3638

3739
public init(from decoder: Decoder) throws {
3840
let container = try decoder.container(keyedBy: CodingKeys.self)

Sources/MusicXML/Complex Types/OtherNotation.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ extension OtherNotation: Codable {
3737
case value = ""
3838
}
3939

40+
// sourcery:inline:OtherNotation.AutoEncodable
4041
public func encode(to encoder: Encoder) throws {
4142
var container = encoder.container(keyedBy: CodingKeys.self)
4243
try container.encode(value, forKey: .value)
4344
try container.encode(type, forKey: .type)
4445
try container.encodeIfPresent(number, forKey: .number)
45-
try container.encodeIfPresent(printObject, forKey: .printObject)
46+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
4647
try printStyle.encode(to: encoder)
4748
try container.encodeIfPresent(placement, forKey: .placement)
4849
}
50+
// sourcery:end
4951

5052
public init(from decoder: Decoder) throws {
5153
let container = try decoder.container(keyedBy: CodingKeys.self)

Sources/MusicXML/Complex Types/PartName.swift

+10
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ extension PartName: Codable {
5454
self.printObject = try container.decodeIfPresent(Bool.self, forKey: .printObject)
5555
self.justify = try container.decodeIfPresent(Justify.self, forKey: .justify)
5656
}
57+
58+
// sourcery:inline:PartName.AutoEncodable
59+
public func encode(to encoder: Encoder) throws {
60+
var container = encoder.container(keyedBy: CodingKeys.self)
61+
try container.encode(value, forKey: .value)
62+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
63+
try container.encodeIfPresent(justify, forKey: .justify)
64+
try printStyle.encode(to: encoder)
65+
}
66+
// sourcery:end
5767
}
5868

5969
extension PartName: ExpressibleByStringLiteral {

Sources/MusicXML/Complex Types/PrintStyleAlignObject.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ extension PrintStyleAlignObject: Codable {
2323
case printObject = "print-object"
2424
}
2525

26+
// sourcery:inline:PrintStyleAlignObject.AutoEncodable
2627
public func encode(to encoder: Encoder) throws {
2728
var container = encoder.container(keyedBy: CodingKeys.self)
29+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
2830
try printStyleAlign.encode(to: encoder)
29-
try container.encodeIfPresent(printObject, forKey: .printObject)
3031
}
32+
// sourcery:end
3133

3234
public init(from decoder: Decoder) throws {
3335
let container = try decoder.container(keyedBy: CodingKeys.self)

Sources/MusicXML/Complex Types/RootAlter.swift

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ extension RootAlter: Codable {
5555
self.printStyle = try PrintStyle(from: decoder)
5656
self.location = try container.decodeIfPresent(LeftRight.self, forKey: .location)
5757
}
58+
59+
// sourcery:inline:RootAlter.AutoEncodable
60+
public func encode(to encoder: Encoder) throws {
61+
var container = encoder.container(keyedBy: CodingKeys.self)
62+
try container.encode(value, forKey: .value)
63+
try container.encodeIfPresent(YesNo(printObject), forKey: .printObject)
64+
try container.encodeIfPresent(location, forKey: .location)
65+
try printStyle.encode(to: encoder)
66+
}
67+
// sourcery:end
5868
}
5969

6070
extension RootAlter: ExpressibleByFloatLiteral {

Sources/MusicXML/Complex Types/Wedge.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ extension Wedge: Codable {
4848
case color
4949
}
5050

51+
// sourcery:inline:Wedge.AutoEncodable
5152
public func encode(to encoder: Encoder) throws {
5253
var container = encoder.container(keyedBy: CodingKeys.self)
5354
try container.encode(type, forKey: .type)
5455
try container.encodeIfPresent(number, forKey: .number)
5556
try container.encodeIfPresent(spread, forKey: .spread)
56-
try container.encodeIfPresent(niente, forKey: .niente)
57+
try container.encodeIfPresent(YesNo(niente), forKey: .niente)
5758
try container.encodeIfPresent(lineType, forKey: .lineType)
5859
try dashedFormatting.encode(to: encoder)
5960
try position.encode(to: encoder)
6061
try container.encodeIfPresent(color, forKey: .color)
6162
}
63+
// sourcery:end
6264

6365
public init(from decoder: Decoder) throws {
6466
let container = try decoder.container(keyedBy: CodingKeys.self)

0 commit comments

Comments
 (0)