MCPcopy Create free account
hub / github.com/bspaans/python-mingus / _track2musicxml

Function _track2musicxml

mingus/extra/musicxml.py:179–220  ·  view source on GitHub ↗
(track)

Source from the content-addressed store, hash-verified

177
178
179def _track2musicxml(track):
180 doc = Document()
181 clef = None
182 track_node = doc.createElement("part")
183 track_node.setAttribute("id", str(id(track)))
184 if track.instrument: # try to guess the clef of the instrument
185 if "treble" in track.instrument.clef.lower():
186 clef = ("G", "2")
187 elif "bass" in track.instrument.clef.lower():
188 clef = ("F", "4")
189 elif "french" in track.instrument.clef.lower():
190 clef = ("G", "1")
191 elif "baritone" in track.instrument.clef.lower():
192 clef = ("F", "3")
193 elif "subbass" in track.instrument.clef.lower():
194 clef = ("F", "5")
195 elif "alto" in track.instrument.clef.lower():
196 clef = ("C", "3")
197 elif "tenor" in track.instrument.clef.lower():
198 clef = ("C", "4")
199 elif "mezzo-soprano" in track.instrument.clef.lower():
200 clef = ("C", "2")
201 elif "soprano" in track.instrument.clef.lower():
202 clef = ("C", "1")
203 counter = 1
204 for b in track.bars:
205 bar = _bar2musicxml(b)
206 bar.setAttribute("number", str(counter))
207 if clef:
208 attrs = bar.getElementsByTagName("attributes")
209 for attr in attrs:
210 clef_node = doc.createElement("clef")
211 sign = doc.createElement("sign")
212 line = doc.createElement("line")
213 sign.appendChild(doc.createTextNode(clef[0]))
214 line.appendChild(doc.createTextNode(clef[1]))
215 clef_node.appendChild(sign)
216 clef_node.appendChild(line)
217 attr.appendChild(clef_node)
218 track_node.appendChild(bar)
219 counter += 1
220 return track_node
221
222
223def _composition2musicxml(comp):

Callers 1

_composition2musicxmlFunction · 0.85

Calls 1

_bar2musicxmlFunction · 0.85

Tested by

no test coverage detected