-
Notifications
You must be signed in to change notification settings - Fork 0
/
transpose.go
52 lines (40 loc) · 1.33 KB
/
transpose.go
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
package mxml
import (
"encoding/xml"
"strings"
)
// Transpose is the structure for transpose MusicXML element.
type Transpose struct {
XMLName xml.Name `xml:"transpose"`
IdAttr string `xml:"id,attr,omitempty"`
NumberAttr string `xml:"number,attr,omitempty"`
Chromatic []Chromatic `xml:"chromatic,omitempty"`
Diatonic []Diatonic `xml:"diatonic,omitempty"`
Double []Double `xml:"double,omitempty"`
OctaveChange []OctaveChange `xml:"octave-change,omitempty"`
IValue string `xml:",chardata"`
}
// ToMXML creates a MXML.
func (r *Transpose) ToMXML() *MXML {
attributes := make(map[string]string)
children := make(map[string][]*MXML)
attributes["id"] = r.IdAttr
attributes["number"] = r.NumberAttr
children["chromatic"] = make([]*MXML, len(r.Chromatic))
for i, c := range r.Chromatic {
children["chromatic"][i] = c.ToMXML()
}
children["diatonic"] = make([]*MXML, len(r.Diatonic))
for i, c := range r.Diatonic {
children["diatonic"][i] = c.ToMXML()
}
children["double"] = make([]*MXML, len(r.Double))
for i, c := range r.Double {
children["double"][i] = c.ToMXML()
}
children["octave-change"] = make([]*MXML, len(r.OctaveChange))
for i, c := range r.OctaveChange {
children["octave-change"][i] = c.ToMXML()
}
return newMXML("transpose", strings.TrimSpace(r.IValue), attributes, children)
}