Return a string made out of ASCII tablature representing a Note object or note string. Throw a RangeError if a suitable fret can't be found. 'tuning' should be a StringTuning object or None for the default tuning. To force a certain fingering you can use a 'string' and 'fret' attr
(note, width=80, tuning=None)
| 102 | |
| 103 | |
| 104 | def from_Note(note, width=80, tuning=None): |
| 105 | """Return a string made out of ASCII tablature representing a Note object |
| 106 | or note string. |
| 107 | |
| 108 | Throw a RangeError if a suitable fret can't be found. |
| 109 | |
| 110 | 'tuning' should be a StringTuning object or None for the default tuning. |
| 111 | |
| 112 | To force a certain fingering you can use a 'string' and 'fret' attribute |
| 113 | on the Note. If the fingering is valid, it will get used instead of the |
| 114 | default one. |
| 115 | """ |
| 116 | if tuning is None: |
| 117 | tuning = default_tuning |
| 118 | result = begin_track(tuning) |
| 119 | min = 1000 |
| 120 | (s, f) = (-1, -1) |
| 121 | |
| 122 | # Do an attribute check |
| 123 | if hasattr(note, "string") and hasattr(note, "fret"): |
| 124 | n = tuning.get_Note(note.string, note.fret) |
| 125 | if n is not None and int(n) == int(note): |
| 126 | (s, f) = (note.string, note.fret) |
| 127 | min = 0 |
| 128 | |
| 129 | if min == 1000: |
| 130 | for (string, fret) in enumerate(tuning.find_frets(note)): |
| 131 | if fret is not None: |
| 132 | if fret < min: |
| 133 | min = fret |
| 134 | (s, f) = (string, fret) |
| 135 | l = len(result[0]) |
| 136 | w = max(4, (width - l) - 1) |
| 137 | |
| 138 | # Build ASCII |
| 139 | if min != 1000: |
| 140 | fret = str(f) |
| 141 | for i in range(len(result)): |
| 142 | d = len(fret) |
| 143 | if i != s: |
| 144 | result[i] += "-" * w + "|" |
| 145 | else: |
| 146 | d = w - len(fret) |
| 147 | result[i] += "-" * (d // 2) + fret |
| 148 | d = (w - d // 2) - len(fret) |
| 149 | result[i] += "-" * d + "|" |
| 150 | else: |
| 151 | raise RangeError( |
| 152 | "No fret found that could play note '%s'. " "Note out of range." % note |
| 153 | ) |
| 154 | result.reverse() |
| 155 | return os.linesep.join(result) |
| 156 | |
| 157 | |
| 158 | def from_NoteContainer(notes, width=80, tuning=None): |
nothing calls this directly
no test coverage detected