本文整理汇总了Python中note.Note.setAccidental方法的典型用法代码示例。如果您正苦于以下问题:Python Note.setAccidental方法的具体用法?Python Note.setAccidental怎么用?Python Note.setAccidental使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类note.Note
的用法示例。
在下文中一共展示了Note.setAccidental方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getBar
# 需要导入模块: from note import Note [as 别名]
# 或者: from note.Note import setAccidental [as 别名]
def getBar(self):
"""
Generate next bar of the song
:return: list of notes within a bar
"""
self.currentBar += 1
points = []
values = []
# choosing places for notes
for i in range(self.metrum * 4):
if self.valueProb[i] >= random.uniform(0, 1):
points.append(i)
# calculating values
if points[0] != 0:
values.append(points[0])
self.extendPrevious = True
self.extendedPrevious = True
for i in range(len(points) - 1):
values.append(points[i + 1] - points[i])
values.append(self.metrum * 4 - points[len(points) - 1])
# generate heights for each note
notes = []
for value in values:
# see if a note should be a rest
if self.restProb > random.uniform(0, 1):
pause = Note(0, value, True)
notes.append(pause)
else:
note = None
# generating first note
if self.prevNote is None:
if self.first == -1:
note = Note(random.randint(self.lowest, self.highest), value)
else:
note = Note(self.first, value)
# stretching the note from previous bar
elif self.extendPrevious:
note = Note(self.prevNote.semitones, value)
self.extendPrevious = False
# generating consecutive note so it fits chosen ambitus
else:
while True:
# generate based on intervals
if self.intervalToSemitoneRatio > random.uniform(0, 1):
interval = random.choices(range(13), self.intervalWeight)[0]
toneDiff = getTones(interval)
if 0.5 > random.uniform(0, 1):
toneDiff *= -1
interval *= -1
pitch = self.prevNote.pitch + toneDiff
note = Note(getSemitones(pitch), value)
note.setAccidental(interval - self.prevNote.getInterval(note))
# generate based on semitones
else:
octave = self.prevNote.octave
semitones = random.choices(range(12), self.semitoneWeight)[0]
note = Note(octave * 12 + semitones, value)
# check if note is in ambitus
if note.semitones >= self.lowest and note.semitones <= self.highest:
break
notes.append(note)
self.prevNote = note
# setting the last note
if self.last != -1 and self.currentBar == self.bars:
lastVal = notes[-1].value
notes[-1] = Note(self.last, lastVal)
return notes