__init__.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:BreezyCreate2 作者: simondlevy 项目源码 文件源码
def play_song(self,song_number,note_string):
        """
        Creates and plays a new song based off a string of notes and durations. 
        note_string - a string of notes,durations
        for example: 'G5,16,G3,16,A#4,30'
        """
        #splits the string of notes and durations into two lists
        split_list= note_string.split(',')
        note_list = split_list[0::2]
        duration_list = split_list[1::2]
        #creates a list for serial codes
        play_list = []
        #convert the durations to integers
        duration_list = map(int, duration_list)
        noError = True

        if noError:
            #Need to map midi to numbers from the dict.
            for i in range (0,len(note_list)):
                #Check that the note is in the list, if it is, add it.
                if note_list[i] in self.config.data['midi table']:
                    play_list.append(self.config.data['midi table'][note_list[i]])
                    play_list.append(duration_list[i])
                else:
                    # Note was not available. Play a rest
                    # Raise an error so the software knows that the input was bad
                    play_list.append(self.config.data['midi table']['rest'])
                    play_list.append(duration_list[i])
                    warnings.formatwarning = custom_format_warning
                    warnings.warn("Warning: Note '" + note_string + "' was not found in midi table")

            #play the song
            self.create_song(song_number,play_list)
            self.play(song_number)
        else:
            raise _ROIFailedToSendError("Invalid data, failed to send")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号