当前位置: 首页>>代码示例>>Python>>正文


Python Note.setAccidental方法代码示例

本文整理汇总了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
开发者ID:Revzik,项目名称:Music_Generator,代码行数:85,代码来源:melody.py


注:本文中的note.Note.setAccidental方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。