Convert a mingus.containers.Bar object to ASCII tablature. Throw a FingerError if no playable fingering can be found. 'tuning' should be a StringTuning object or None for the default tuning. If 'collapse' is False this will return a list of lines, if it's True all lines will be con
(bar, width=40, tuning=None, collapse=True)
| 225 | |
| 226 | |
| 227 | def from_Bar(bar, width=40, tuning=None, collapse=True): |
| 228 | """Convert a mingus.containers.Bar object to ASCII tablature. |
| 229 | |
| 230 | Throw a FingerError if no playable fingering can be found. |
| 231 | |
| 232 | 'tuning' should be a StringTuning object or None for the default tuning. |
| 233 | If 'collapse' is False this will return a list of lines, if it's True |
| 234 | all lines will be concatenated with a newline symbol. |
| 235 | |
| 236 | Use 'string' and 'fret' attributes on Notes to force certain fingerings. |
| 237 | """ |
| 238 | if tuning is None: |
| 239 | tuning = default_tuning |
| 240 | |
| 241 | # Size of a quarter note |
| 242 | qsize = _get_qsize(tuning, width) |
| 243 | result = begin_track(tuning, max(2, qsize // 2)) |
| 244 | |
| 245 | # Add bar |
| 246 | for entry in bar.bar: |
| 247 | (beat, duration, notes) = entry |
| 248 | fingering = tuning.find_fingering(notes) |
| 249 | if fingering != [] or notes is None: |
| 250 | |
| 251 | # Do an attribute check |
| 252 | f = [] |
| 253 | attr = [] |
| 254 | if notes is not None: |
| 255 | for note in notes: |
| 256 | if hasattr(note, "string") and hasattr(note, "fret"): |
| 257 | n = tuning.get_Note(note.string, note.fret) |
| 258 | if n is not None and int(n) == int(note): |
| 259 | f.append((note.string, note.fret)) |
| 260 | attr.append(int(note)) |
| 261 | |
| 262 | # See if there are any possible fingerings with the attributes that |
| 263 | # are set. |
| 264 | fres = [] |
| 265 | if f != []: |
| 266 | for x in fingering: |
| 267 | found = True |
| 268 | for pos in f: |
| 269 | if pos not in x: |
| 270 | found = False |
| 271 | if found: |
| 272 | fres.append(x) |
| 273 | |
| 274 | # Use best fingering. |
| 275 | maxlen = 0 |
| 276 | if fres != []: |
| 277 | f = fres[0] |
| 278 | else: |
| 279 | # Use default fingering if attributes don't make sense |
| 280 | if notes is None: |
| 281 | f = [] |
| 282 | maxlen = 1 |
| 283 | else: |
| 284 | f = fingering[0] |
no test coverage detected