Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sym2chord(sym, transpose=0):
ch = None
if is_roman_numeral(sym):
try:
chord_sym = roman.RomanNumeral(sym)
# transpose
chord_sym.transpose(transpose, inPlace=True)
pches = chord_sym.pitches
if chord_sym.secondaryRomanNumeral is not None:
ch = chord.Chord(pches).transpose(-12)
else:
ch = chord.Chord(pches)
except:
print 'WARNING: symbol not found', sym
else:
try:
sym = preprocess_letters_before_sym2chord(sym)
chord_sym = harmony.ChordSymbol(sym)
ch = chord.Chord(chord_sym.pitches).transpose(12)
except:
print 'WARNING: symbol not found', sym
return ch
>>> b = musicxml.Note()
>>> b.setDefaults()
>>> b.set('chord', True)
>>> m = musicxml.Measure()
>>> m.setDefaults()
>>> a.external['measure'] = m # assign measure for divisions ref
>>> a.external['divisions'] = m.external['divisions']
>>> b.external['measure'] = m # assign measure for divisions ref
>>> b.external['divisions'] = m.external['divisions']
>>> c = musicxml.fromMxObjects.mxToChord([a, b])
>>> c.getNotehead(c.pitches[0])
'diamond'
'''
if inputM21 == None:
c = chord.Chord()
else:
c = inputM21
if spannerBundle is None:
#environLocal.printDebug(['mxToNote()', 'creating SpannerBundle'])
spannerBundle = spanner.SpannerBundle()
else: # if we are passed in as spanner bundle, look for any pending
# component assignments
spannerBundle.freePendingSpannedElementAssignment(c)
# assume that first chord is the same duration for all parts
mxToDuration(mxNoteList[0], c.duration)
# assume that first note in list has a grace object (and all do)
mxGrace = mxNoteList[0].get('graceObj')
>>> b.setDefaults()
>>> b.set('chord', True)
>>> m = musicxml.mxObjects.Measure()
>>> m.setDefaults()
>>> a.external['measure'] = m # assign measure for divisions ref
>>> a.external['divisions'] = m.external['divisions']
>>> b.external['measure'] = m # assign measure for divisions ref
>>> b.external['divisions'] = m.external['divisions']
>>> c = musicxml.fromMxObjects.mxToChord([a, b])
>>> c.getNotehead(c.pitches[0])
'diamond'
'''
notes = []
for mxNote in mxNoteList:
notes.append(self.xmlToSimpleNote(mxNote))
c = chord.Chord([notes])
return c
def testHalfDimIII(self):
c = chord.Chord(['F#3', 'A3', 'E4', 'C5'])
k = key.Key('d')
rn = romanNumeralFromChord(c, k)
self.assertEqual(rn.figure, '#iiiø7')
def testChordNoteheadFillA(self):
from music21 import chord
c = chord.Chord(['c4', 'g4'])
c[0].noteheadFill = False
raw = fromMusic21Object(c)
self.assertEqual(raw.count('normal'), 1)
c[1].noteheadFill = False
raw = fromMusic21Object(c)
self.assertEqual(raw.count('normal'), 2)
n = note.Rest()
n.mx = mxNote # assign mxNote to rest obj
_addToStaffReference(mxNote, n, staffReference)
#m.insert(offsetMeasureNote, n)
if useVoices:
m.voices[mxNote.voice]._insertCore(offsetMeasureNote, n)
else:
m._insertCore(offsetMeasureNote, n)
offsetIncrement = n.quarterLength
# if we we have notes in the note list and the next
# note either does not exist or is not a chord, we
# have a complete chord
if len(mxNoteList) > 0 and (mxNoteNext is None
or mxNoteNext.get('chord') is False):
c = chord.Chord()
# TODO: use chord conversion
c.mx = mxNoteList
# add any accumulated lyrics
for mxLyric in mxLyricList:
lyricObj = note.Lyric()
lyricObj.mx = mxLyric
c.lyrics.append(lyricObj)
_addToStaffReference(mxNoteList, c, staffReference)
if useVoices:
m.voices[mxNote.voice]._insertCore(offsetMeasureNote, c)
else:
m._insertCore(offsetMeasureNote, c)
mxNoteList = [] # clear for next chord
mxLyricList = []
def testDurations(self):
Cq = note.Note('C4')
Cq.duration.type = "quarter"
chord35 = Chord([Cq])
self.assertEquals(chord35.duration.type, "quarter")
Dh = note.Note('D4')
Dh.duration.type = "half"
chord36 = Chord([Cq, Dh])
self.assertEquals(chord36.duration.type, "quarter")
chord37 = Chord([Dh, Cq])
self.assertEquals(chord37.duration.type, "half")
chord38 = Chord([Cq, Dh], type="whole")
self.assertEquals(chord38.duration.type, "whole")
def testHashChordsAsChordsNormalOrder(self):
s2 = stream.Stream()
note1 = note.Note('C4')
note1.duration.type = 'half'
cMinor = chord.Chord(['C4', 'G4', 'E-5'])
cMinor.duration.type = 'half'
cMajor = chord.Chord(['C4', 'G4', 'E3'])
cMajor.duration.type = 'whole'
s2.append(note1)
s2.append(cMinor)
s2.append(cMajor)
h = Hasher()
h.hashChordsAsChords = True
h.hashChordsAsNotes = False
h.hashPrimeFormString = False
h.hashNormalOrderString = True
CNoteHash = collections.namedtuple('NoteHash', ['Pitch', 'NormalOrderString',
'Duration', 'Offset'])
hashes_plain_numbers = [(60, '<>', 2.0, 0.0), (1, '<037>', 2.0, 2.0),
(1, '<047>', 4.0, 4.0)]
hashes_in_format = [CNoteHash(Pitch=x, NormalOrderString=y, Duration=z, Offset=a)
display = stream.Stream()
for m in violin2.getElementsByClass('Measure'):
notes = m.findConsecutiveNotes(
skipUnisons=True, skipOctaves=True,
skipRests=True, noNone=True )
pitches = stream.Stream(notes).pitches
for i in range(len(pitches) - 3):
# makes every set of 4 notes into a whole-note chord
testChord = chord.Chord(pitches[i:i + 4])
testChord.duration.type = "whole"
if testChord.isDominantSeventh():
testChord.lyric = "m. " + str(m.number)
m.notesAndRests[0].lyric = chord.Chord(m.pitches).primeFormString
chordMeasure = stream.Measure()
chordMeasure.append(testChord.closedPosition())
display.append(chordMeasure)
display.append(m)
display.show()
def testNormalOrderChords(self):
pList = [pitch.Pitch('C4'), pitch.Pitch('E4'), pitch.Pitch('G#4')]
tc = TranspositionChecker(pList)
allNormalOrderChords = tc.getChordsOfDistinctTranspositions()
self.assertEqual(len(allNormalOrderChords), 4)
# self.assertEqual(lengthDistinctNormalOrders, 4)
self.assertIsInstance(allNormalOrderChords[0], chord.Chord)
self.assertIsInstance(allNormalOrderChords[0].pitches[0], pitch.Pitch)
# self.assertEqual(allDistinctNormalOrders[0], [0,4,8])