Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lbigo committed Nov 18, 2021
1 parent 7d0e45b commit 780a425
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6062,6 +6062,16 @@ def staffLayoutToXmlStaffDetails(self, staffLayout):
mxStaffLines.text = str(staffLayout.staffLines)

# TODO: staff-tuning
if hasattr(staffLayout, 'fretboard'):
tuning_pitches = staffLayout.fretboard.tuning
for i in range(len(tuning_pitches)):
mxStaffTuning = SubElement(mxStaffDetails, 'staff-tuning')
mxStaffTuning.set('line', str(i + 1))
mxTuningStep = SubElement(mxStaffTuning, 'tuning-step')
mxTuningStep.text = tuning_pitches[i].name
mxTuningOctave = SubElement(mxStaffTuning, 'tuning-octave')
mxTuningOctave.text = str(tuning_pitches[i].octave)

# TODO: capo
# TODO: staff-size
return mxStaffDetails
Expand Down
13 changes: 13 additions & 0 deletions music21/musicxml/xmlToM21.py
Original file line number Diff line number Diff line change
Expand Up @@ -5691,7 +5691,20 @@ def xmlStaffLayoutFromStaffDetails(
stl.staffType = stream.enums.StaffType(xmlText)
except ValueError:
environLocal.warn(f'Got an incorrect staff-type in details: {mxStaffType}')

# TODO: staff-tuning*
mxStaffTuning = mxDetails.findall('staff-tuning')
if mxStaffTuning is not None:
tuning_pitches = []
for i in range(len(mxStaffTuning)):
staff_tuning = mxStaffTuning[i]
line = int(staff_tuning.get('line'))
tuning_step = staff_tuning.find('tuning-step').text
tuning_octave = int(staff_tuning.find('tuning-octave').text)
tuning_pitches.append(pitch.Pitch(tuning_step + str(tuning_octave)))
fretboard = tablature.FretBoard.getFretBoardFromTuning(tuning_pitches)
setattr(stl, 'fretboard', fretboard)

# TODO: capo
# TODO: show-frets
# TODO: print-spacing
Expand Down
18 changes: 18 additions & 0 deletions music21/tablature.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ def getPitches(self):

return pitchList

@staticmethod
def getFretBoardFromTuning(pitches):
standard_fret_boards = [GuitarFretBoard, UkeleleFretBoard, BassGuitarFretBoard, MandolinFretBoard]
for standard_fret_board in standard_fret_boards:
if pitches == standard_fret_board().tuning:
return standard_fret_board()
return CustomFretBoard(pitches)

class FirstFret:
'''
Expand Down Expand Up @@ -344,6 +351,17 @@ def __init__(self, fretNotes=None, displayFrets=4):
super().__init__(numStrings, fretNotes, displayFrets)

self.tuning = [pitch.Pitch('G3'), pitch.Pitch('D4'), pitch.Pitch('A4'), pitch.Pitch('E5')]

class CustomFretBoard(FretBoard):
'''
A custom fretboard tuned with any list of pitches
'''

def __init__(self, pitches, fretNotes=None, displayFrets=4):
numStrings = len(pitches)
super().__init__(numStrings, fretNotes, displayFrets)

self.tuning = pitches.copy()
# ------------------------------------------------------------------------------


Expand Down

0 comments on commit 780a425

Please sign in to comment.