Пример #1
0
     def __init__(self, nKeys, volume):

         #Set the ouput device to speakers implemented elsewhere
         self.outputDevice = Speakers()         
         self.volume = volume
         
         super(ComputerKeyboard, self).__init__(nKeys)
Пример #2
0
class MusicalKeyboard(Keyboard):
	
     def __init__(self, nKeys, volume):

         #Set the ouput device to speakers implemented elsewhere
         self.outputDevice = Speakers()         
         self.volume = volume
         
         super(ComputerKeyboard, self).__init__(nKeys)

                  
     def setupKeys(self):
         lowest = 27.5 #Hz
         step = 1.06 #Relative increase in Hz (neighbouring keys)
         
         self.keys = [lowest + i*step for i in range(self.nKeys)]


     def pressKey(self, key):

         #Returns a harmonic wave with frequency and amplitude
         #extracted from the pressed key and the volume level.
         outout = ...
         self.outputDevice.play(key, output)