Return a string made out of ASCII tablature representing a NoteContainer object or list of note strings / Note objects. Throw a FingerError if no playable fingering can be found. 'tuning' should be a StringTuning object or None for the default tuning. To force a certain fingering
(notes, width=80, tuning=None)
| 156 | |
| 157 | |
| 158 | def from_NoteContainer(notes, width=80, tuning=None): |
| 159 | """Return a string made out of ASCII tablature representing a |
| 160 | NoteContainer object or list of note strings / Note objects. |
| 161 | |
| 162 | Throw a FingerError if no playable fingering can be found. |
| 163 | |
| 164 | 'tuning' should be a StringTuning object or None for the default tuning. |
| 165 | |
| 166 | To force a certain fingering you can use a 'string' and 'fret' attribute |
| 167 | on one or more of the Notes. If the fingering is valid, it will get used |
| 168 | instead of the default one. |
| 169 | """ |
| 170 | if tuning is None: |
| 171 | tuning = default_tuning |
| 172 | result = begin_track(tuning) |
| 173 | l = len(result[0]) |
| 174 | w = max(4, (width - l) - 1) |
| 175 | fingerings = tuning.find_fingering(notes) |
| 176 | if fingerings != []: |
| 177 | # Do an attribute check |
| 178 | f = [] |
| 179 | attr = [] |
| 180 | for note in notes: |
| 181 | if hasattr(note, "string") and hasattr(note, "fret"): |
| 182 | n = tuning.get_Note(note.string, note.fret) |
| 183 | if n is not None and int(n) == int(note): |
| 184 | f += (note.string, note.fret) |
| 185 | attr.append(int(note)) |
| 186 | |
| 187 | # See if there are any possible fingerings with the attributes |
| 188 | # that are set. |
| 189 | fres = [] |
| 190 | if f != []: |
| 191 | for x in fingerings: |
| 192 | found = True |
| 193 | for pos in f: |
| 194 | if pos not in x: |
| 195 | found = False |
| 196 | if found: |
| 197 | fres.append(x) |
| 198 | |
| 199 | # Use best fingering. |
| 200 | if fres != []: |
| 201 | f = fres[0] |
| 202 | else: |
| 203 | # Use default fingering if attributes don't make sense |
| 204 | f = fingerings[0] |
| 205 | |
| 206 | # Build {string: fret} result |
| 207 | res = {} |
| 208 | for (string, fret) in f: |
| 209 | res[string] = str(fret) |
| 210 | maxfret = max(res.values()) |
| 211 | |
| 212 | # Produce ASCII |
| 213 | for i in range(len(result)): |
| 214 | if i not in res: |
| 215 | result[i] += "-" * w + "|" |
nothing calls this directly
no test coverage detected