コード例 #1
0
    def restoreKeys(self):  #restores the keys from exported file
        if self.restored:
            self.setText("The keys have ALREADY been restored")
        else:
            for fileName in os.listdir(
                    os.getcwd() +
                    "/userSamples"):  #for every file in the userSamples folder
                if fileName.endswith(".wav") and fileName[
                        1] == ".":  #if the file is a wav and is one letter long
                    self.listOfKeys[fileName[0]] = soundSample(
                        5000, 1024, 44100 * 2, fileName[0]
                    )  #then initialize the object with the letter of the wav file
                    self.listOfLetters.append(fileName[0])

                    textFile = open(
                        os.getcwd() + "/keyConfig/" + fileName[0] + ".txt", 'r'
                    )  #open the text file using the letter of the found file
                    listText = textFile.readlines(
                    )  # read in a text file to a list
                    arrayText = array("h")  #creates an array
                    for i in listText:  #for every item in listText
                        arrayText.append(int(
                            i))  #add the current item in listText to the array

                    self.listOfKeys[fileName[
                        0]].recordedAudio = arrayText  #take the array file and store it to the soundObject
                    self.updateTextKeys()
                    self.setText("The keys have been restored")
                    self.restored = True
 def bindKey (self,letter): #takes a key that has not yet been bound and initializes it to a soundSample object
     if len(letter) > 0: #if there is a key in the textbox for
         if not letter in self.listOfKeys: #if the key has not been bound yet
             self.listOfKeys[letter] = soundSample(5000,1024,44100*2,letter) #create a new object for the key
             self.setText(letter + " key has been bound") #tell the user that the key has been bound
             self.listOfLetters.append(letter)
             self.updateTextKeys()
     else:
         self.setText( "please enter one key for the sound to be bound to")
コード例 #3
0
 def bindKey(
     self, letter
 ):  #takes a key that has not yet been bound and initializes it to a soundSample object
     if len(letter) > 0:  #if there is a key in the textbox for
         if not letter in self.listOfKeys:  #if the key has not been bound yet
             self.listOfKeys[letter] = soundSample(
                 5000, 1024, 44100 * 2,
                 letter)  #create a new object for the key
             self.setText(letter + " key has been bound"
                          )  #tell the user that the key has been bound
             self.listOfLetters.append(letter)
             self.updateTextKeys()
     else:
         self.setText("please enter one key for the sound to be bound to")
    def restoreKeys (self): #restores the keys from exported file
        if self.restored:
            self.setText("The keys have ALREADY been restored")
        else:
            for fileName in os.listdir(os.getcwd()+"/userSamples"): #for every file in the userSamples folder
                if fileName.endswith(".wav") and fileName[1] == ".": #if the file is a wav and is one letter long
                    self.listOfKeys[fileName[0]] = soundSample(5000,1024,44100*2,fileName[0]) #then initialize the object with the letter of the wav file
                    self.listOfLetters.append(fileName[0])

                    textFile = open(os.getcwd()+"/keyConfig/"+fileName[0]+".txt",'r') #open the text file using the letter of the found file
                    listText = textFile.readlines() # read in a text file to a list
                    arrayText = array("h") #creates an array
                    for i in listText: #for every item in listText
                        arrayText.append(int(i)) #add the current item in listText to the array

                    self.listOfKeys[fileName[0]].recordedAudio = arrayText #take the array file and store it to the soundObject
                    self.updateTextKeys()
                    self.setText("The keys have been restored")
                    self.restored = True