-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess-common.go
100 lines (78 loc) · 1.88 KB
/
preprocess-common.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
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
package musicxml
import (
"errors"
"fmt"
"github.com/musica/musicxml/mxml"
)
func (m *MusicXML) preprocess() (*MusicXML, error) {
// there would be a lot of preprocessing functions
// don't need to return or panic in case one of them fails
// figure out a way to handle them. log them??
m.meta = newMusicXMLMeta()
if err := m.ppXMLRoot(); err != nil {
return m, err
}
m.ppWorkTitle()
m.ppCreators()
m.ppRights()
return m, nil
}
// just to figure out an approach about how to preprocess the MusicXML.
func (m *MusicXML) ppXMLRoot() error {
switch mxRoot := m.musicXML.Name(); mxRoot {
case "score-partwise":
m.meta.xmlRoot = mxRoot
return nil
default:
return errorIncorrectRoot
}
}
func (m *MusicXML) ppWorkTitle() error {
var n []*mxml.MXML
var ok bool
n, ok = m.MXML().Children()["work"]
if !ok || len(n) == 0 {
return errors.New("cannot get work title")
}
n, ok = n[0].Children()["work-title"]
if !ok || len(n) == 0 {
return errors.New("cannot get work title")
}
fmt.Println(n[0])
m.meta.workTitle = n[0].IValue()
return nil
}
func (m *MusicXML) ppCreators() error {
var n []*mxml.MXML
var ok bool
n, ok = m.MXML().Children()["identification"]
if !ok || len(n) == 0 {
return errors.New("cannot get creators")
}
n, ok = n[0].Children()["creator"]
if !ok || len(n) == 0 {
return errors.New("cannot get creators")
}
m.meta.creators = make([]string, len(n))
for ix, v := range n {
m.meta.creators[ix] = v.IValue()
}
return nil
}
func (m *MusicXML) ppRights() error {
var n []*mxml.MXML
var ok bool
n, ok = m.MXML().Children()["identification"]
if !ok || len(n) == 0 {
return errors.New("cannot get creators")
}
n, ok = n[0].Children()["rights"]
if !ok || len(n) == 0 {
return errors.New("cannot get creators")
}
m.meta.creators = make([]string, len(n))
for ix, v := range n {
m.meta.creators[ix] = v.IValue()
}
return nil
}