+ self.wiimotes = instrumentChoice.wiimotes\r
+ self.activeWiimotes = instrumentChoice.activeWiimotes\r
+ self.window = instrumentChoice.window\r
+ self.screen = instrumentChoice.screen\r
+ self.blitOrigin = instrumentChoice.blitOrigin\r
+ self.clock = instrumentChoice.clock\r
+ self.width = instrumentChoice.width\r
+ self.height = instrumentChoice.height\r
+ self.cursorPositions = instrumentChoice.cursorPositions\r
+ self.savedScreen = instrumentChoice.savedScreen\r
+ self.playerScreen = instrumentChoice.playerScreen\r
+ self.extendedScale = extendedScale\r
+ self.cascade = cascade\r
+ self.joys = instrumentChoice.joys\r
+ self.portOffset = instrumentChoice.portOffset\r
+ if eventLog == None :\r
+ self.eventLog = instrumentChoice.eventLog\r
+ else :\r
+ self.eventLog = eventLog\r
+ self.cursorPositions = instrumentChoice.cursorPositions\r
+ self.song = song\r
+ self.songIterator = self.song.iterNotes()\r
+ self.midiNoteNumbers = self.song.scale\r
+ if replay == None :\r
+ self.replay = instrumentChoice.replay\r
+ else :\r
+ self.replay = replay\r
+ self.quarterNoteLength = song.quarterNoteLength\r
+ self.cascadeLockLengthMultiplier = 1\r
+ self.nextCascadeLockLengthMultiplier = 1\r
+ self.cascadeLockLength = self.quarterNoteLength * self.cascadeLockLengthMultiplier\r
+ \r
+ self.defaultInstrumentChannel = defaultInstrumentChannel\r
+ self.defaultNote = defaultNote\r
+ \r
+ self.done = False\r
+ self.backToInstrumentChoice = False\r
+ self.easyMode = easyMode\r
+ \r
+ #Initializes the highlightedNote and highlightedNoteNumber etc...\r
+ self.moveToNextNote()\r
+ self.cascadeLockLengthMultiplier = self.nextCascadeLockLengthMultiplier\r
+ \r
+ self.blinkOn = False\r
+ self.savedBlinkOn = False\r
+ ##Will prevent the song to move on if two consecutive notes are identical and the buttons have not been released in between the two\r
+ ##i.e. it guarantees that there will be an attack between two identical consecutive notes\r
+ self.highlightIsFree = True\r
+ \r
+ self.noteRects = []\r
+ self.boundingRect = None\r
+ self.notes = []\r
+ \r
+ self.buttonDown = []\r
+ self.velocityLock = []\r
+ \r
+ self._blinkOffset = 0\r
+ self._cascadeLockTimer = 0\r
+ self.cascadeIsFree = True\r
+ \r
+ self.font = pygame.font.Font(None,80)\r
+ self.renderedNoteNames = [self.font.render(constants.noteNumberToName(note),False,(0,0,0)) for note in self.midiNoteNumbers]\r
+ \r
+ self.drawBackground()\r
+ self.initializeWiimotes()\r
+ \r
+ self.songStartTime = self.eventLog.getCurrentTime()\r
+ \r
+ #The main loop\r
+ while not self.done :\r
+ \r
+ #Clear the cursors from the screen\r
+ if self.hasChanged():\r
+ self.drawBackground()\r
+ self.playerScreen.blit(self.savedScreen, (0, 0))\r
+ \r
+ # Limit frame speed to 50 FPS\r
+ #\r
+ timePassed = self.clock.tick(10000)\r
+ \r
+ self._blinkOffset += timePassed\r
+ if (self.buttonDown or self.alwaysDown) and not self.cascadeIsFree :\r
+ self._cascadeLockTimer += timePassed\r
+ if self._cascadeLockTimer > self.cascadeLockLengthMultiplier*self.quarterNoteLength :\r
+ self.cascadeIsFree = True\r
+ self.cascadeLockLengthMultiplier = self.nextCascadeLockLengthMultiplier\r
+ \r
+ \r
+ if self._blinkOffset > self.blinkLength:\r
+ self._blinkOffset -= self.blinkLength\r
+ self.blinkOn = not self.blinkOn\r
+ \r
+ if self.replay:\r
+ self.eventLog.update(timePassed)\r
+ pickledEventsToPost = self.eventLog.getPickledEvents() \r
+ for pickledEvent in pickledEventsToPost:\r
+ pygame.event.post(pickledEvent.event)\r
+ \r
+ events = pygame.event.get()\r
+ \r
+ if not self.replay:\r
+ pickledEvents = [PickleableEvent(event.type,event.dict) for event in events]\r
+ if pickledEvents != [] :\r
+ self.eventLog.appendEventGroup(pickledEvents)\r
+ \r
+ for event in events:\r
+ self.input(event)\r
+ \r
+ for i in range(len(self.wiimotes)):\r
+ if self.activeWiimotes[i]:\r
+ self.wiimotes[i].cursor.update(timePassed, self.cursorPositions[i])\r
+ if self.buttonDown[i] or self.alwaysDown:\r
+ self.wiimotes[i].cursor.flash()\r
+ self.wiimotes[i].cursor.blit(self.playerScreen)\r
+ \r
+ self.screen.blit(self.playerScreen, (0,0))\r
+ \r
+ pygame.display.flip()\r
+ \r
+ for i in range(len(self.wiimotes)):\r
+ if self.activeWiimotes[i]:\r
+ self.wiimotes[i].stopNoteByNoteNumber(self.midiNoteNumbers[self.notes[i]])\r
+ if self.replay : \r
+ self.totalDuration = self.eventLog.getCurrentTime()\r