(comp)
| 221 | |
| 222 | |
| 223 | def _composition2musicxml(comp): |
| 224 | doc = Document() |
| 225 | score = doc.createElement("score-partwise") |
| 226 | score.setAttribute("version", "2.0") |
| 227 | |
| 228 | # set title information |
| 229 | if comp.title: |
| 230 | title = doc.createElement("movement-title") |
| 231 | title.appendChild(doc.createTextNode(str(comp.title))) |
| 232 | score.appendChild(title) |
| 233 | identification = doc.createElement("identification") |
| 234 | |
| 235 | # set author information |
| 236 | if comp.author: |
| 237 | author = doc.createElement("creator") |
| 238 | author.setAttribute("type", "composer") |
| 239 | author.appendChild(doc.createTextNode(str(comp.author))) |
| 240 | identification.appendChild(author) |
| 241 | |
| 242 | # set additional info |
| 243 | encoding = doc.createElement("encoding") |
| 244 | software = doc.createElement("software") |
| 245 | software.appendChild(doc.createTextNode("mingus")) |
| 246 | encoding.appendChild(software) |
| 247 | enc_date = doc.createElement("encoding-date") |
| 248 | enc_date.appendChild(doc.createTextNode(str(datetime.date.today()))) |
| 249 | encoding.appendChild(enc_date) |
| 250 | identification.appendChild(encoding) |
| 251 | score.appendChild(identification) |
| 252 | |
| 253 | # add tracks |
| 254 | part_list = doc.createElement("part-list") |
| 255 | score.appendChild(part_list) |
| 256 | for t in comp: |
| 257 | track = _track2musicxml(t) |
| 258 | score_part = doc.createElement("score-part") |
| 259 | track.setAttribute("id", str(id(t))) |
| 260 | score_part.setAttribute("id", str(id(t))) |
| 261 | part_name = doc.createElement("part-name") |
| 262 | part_name.appendChild(doc.createTextNode(t.name)) |
| 263 | score_part.appendChild(part_name) |
| 264 | if t.instrument: |
| 265 | |
| 266 | # add instrument info |
| 267 | score_inst = doc.createElement("score-instrument") |
| 268 | score_inst.setAttribute("id", str(id(t.instrument))) |
| 269 | name = doc.createElement("instrument-name") |
| 270 | name.appendChild(doc.createTextNode(str(t.instrument.name))) |
| 271 | score_inst.appendChild(name) |
| 272 | score_part.appendChild(score_inst) |
| 273 | |
| 274 | # add midi instruments |
| 275 | if isinstance(t.instrument, MidiInstrument): |
| 276 | midi = doc.createElement("midi-instrument") |
| 277 | midi.setAttribute("id", str(id(t.instrument))) |
| 278 | channel = doc.createElement("midi-channel") |
| 279 | channel.appendChild(doc.createTextNode(str(1))) # what about |
| 280 | # the MIDI |
no test coverage detected