Convert a mingus.containers.Composition to an ASCII tablature string. Automatically add an header based on the title, subtitle, author, e-mail and description attributes. An extra description of the piece can also be given. Tunings can be set by using the Track.instrument.tuning or
(composition, width=80)
| 347 | |
| 348 | |
| 349 | def from_Composition(composition, width=80): |
| 350 | """Convert a mingus.containers.Composition to an ASCII tablature string. |
| 351 | |
| 352 | Automatically add an header based on the title, subtitle, author, e-mail |
| 353 | and description attributes. An extra description of the piece can also |
| 354 | be given. |
| 355 | |
| 356 | Tunings can be set by using the Track.instrument.tuning or Track.tuning |
| 357 | attribute. |
| 358 | """ |
| 359 | # Collect tunings |
| 360 | instr_tunings = [] |
| 361 | for track in composition: |
| 362 | tun = track.get_tuning() |
| 363 | if tun: |
| 364 | instr_tunings.append(tun) |
| 365 | else: |
| 366 | instr_tunings.append(default_tuning) |
| 367 | result = add_headers( |
| 368 | width, |
| 369 | composition.title, |
| 370 | composition.subtitle, |
| 371 | composition.author, |
| 372 | composition.email, |
| 373 | composition.description, |
| 374 | instr_tunings, |
| 375 | ) |
| 376 | |
| 377 | # Some variables |
| 378 | w = _get_width(width) |
| 379 | barindex = 0 |
| 380 | bars = width / w |
| 381 | lastlen = 0 |
| 382 | maxlen = max([len(x) for x in composition.tracks]) |
| 383 | |
| 384 | while barindex < maxlen: |
| 385 | notfirst = False |
| 386 | for tracks in composition: |
| 387 | tuning = tracks.get_tuning() |
| 388 | ascii = [] |
| 389 | for x in range(bars): |
| 390 | if barindex + x < len(tracks): |
| 391 | bar = tracks[barindex + x] |
| 392 | r = from_Bar(bar, w, tuning, collapse=False) |
| 393 | barstart = r[1].find("||") + 2 |
| 394 | |
| 395 | # Add extra '||' to quarter note marks to connect tracks. |
| 396 | if notfirst: |
| 397 | r[0] = (r[0])[: barstart - 2] + "||" + (r[0])[barstart:] |
| 398 | |
| 399 | # Add bar to ascii |
| 400 | if ascii != []: |
| 401 | for i in range(1, len(r) + 1): |
| 402 | item = r[len(r) - i] |
| 403 | ascii[-i] += item[barstart:] |
| 404 | else: |
| 405 | ascii += r |
| 406 |
no test coverage detected