MCPcopy Create free account
hub / github.com/bspaans/python-mingus / find_fingering

Method find_fingering

mingus/extra/tunings.py:98–147  ·  view source on GitHub ↗

Return a list [(string, fret)] of possible fingerings for 'notes'. The notes parameter should be a list of strings or Notes or a NoteContainer; max_distance denotes the maximum distance between frets; not_strings can be used to disclude certain strings and is

(self, notes, max_distance=4, not_strings=None)

Source from the content-addressed store, hash-verified

96 return result
97
98 def find_fingering(self, notes, max_distance=4, not_strings=None):
99 """Return a list [(string, fret)] of possible fingerings for
100 'notes'.
101
102 The notes parameter should be a list of strings or Notes or a
103 NoteContainer; max_distance denotes the maximum distance between
104 frets; not_strings can be used to disclude certain strings and is
105 used internally to recurse.
106
107 Example:
108 >>> t = StringTuning('test', 'test', ['A-3', 'E-4', 'A-5'])
109 >>> t.find_fingering(['E-4', 'B-4'])
110 [[(0, 7), (1, 7)], [(1, 0), (0, 14)]]
111 """
112 if not_strings is None:
113 not_strings = []
114 if notes is None:
115 return []
116 if len(notes) == 0:
117 return []
118 first = notes[0]
119 notes = notes[1:]
120 frets = self.find_frets(first)
121 result = []
122 for (string, fret) in enumerate(frets):
123 if fret is not None and string not in not_strings:
124 if len(notes) > 0:
125 # recursively find fingerings for
126 # remaining notes
127 r = self.find_fingering(notes, max_distance, not_strings + [string])
128 if r != []:
129 for f in r:
130 result.append([(string, fret)] + f)
131 else:
132 result.append([(string, fret)])
133
134 # filter impossible fingerings and sort
135 res = []
136 for r in result:
137 (min, max) = (1000, -1)
138 frets = 0
139 for (string, fret) in r:
140 if fret > max:
141 max = fret
142 if fret < min and fret != 0:
143 min = fret
144 frets += fret
145 if 0 <= max - min < max_distance or min == 1000 or max == -1:
146 res.append((frets, r))
147 return [r for (_, r) in sorted(res)]
148
149 def find_chord_fingering(
150 self,

Callers 3

from_NoteContainerFunction · 0.80
from_BarFunction · 0.80
test_find_fingeringMethod · 0.80

Calls 1

find_fretsMethod · 0.95

Tested by 1

test_find_fingeringMethod · 0.64