- def __init__(self, hue, rect) :
- pygame.sprite.Sprite.__init__(self)
- sur = Surface(rect.size)
- rgba = hls_to_rgb(hue, OFF_LUMINANCE, OFF_SATURATION) + (255,)
- sur.fill(rgba)
- self.stateOff = sur
-
- topRgba = hls_to_rgb(hue, ON_TOP_LUMINANCE, ON_SATURATION) + (255,)
- bottomRgba = hls_to_rgb(hue, ON_BOTTOM_LUMINANCE, ON_SATURATION) + (255,)
- size = rect.inflate(2*rect.width,0).size
- self.stateOn = gradients.vertical(size, topRgba, bottomRgba)
-
\ No newline at end of file
+ def __init__(self, synth, song, mode=PLAYING_MODES['EASY']) :
+ super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
+ self.song = song
+ self.currentColumn = None
+ self.noteIterator = self.song.iterNotes()
+ self.displayNext()
+ if mode == PLAYING_MODES['NORMAL'] :
+ EventDispatcher.addEventListener(events.COLDOWN, self.handleColumnDown)
+ EventDispatcher.addEventListener(events.COLUP, self.handleColumnUp)
+ elif mode == PLAYING_MODES['EASY'] :
+ EventDispatcher.addEventListener(events.COLOVER, self.handleColumnOver)
+
+
+ def displayNext(self, event=None) :
+ if self.currentColumn:
+ self.currentColumn.update(False)
+ note, verseIndex = self.noteIterator.next()
+ syllabus = note.lyrics[verseIndex].syllabus()
+ column = self.columns[note.midi]
+ column.update(True, syllabus)
+ self.currentColumn = column
+ self.currentNote = note
+ self.currentNotePlayed = False
+
+ def handleColumnDown(self, event) :
+ col = event.column
+ if col.state:
+ self.synth.noteon(0, col.tone.midi, DEFAULT_MIDI_VELOCITY)
+ self.currentNotePlayed = True
+
+ def handleColumnUp(self, event) :
+ if self.currentNotePlayed :
+ self.synth.noteoff(0, self.currentColumn.tone.midi)
+ self.displayNext()
+
+ def handleColumnOver(self, event) :
+ col = event.column
+ if col.state and not self.currentNotePlayed :
+ self.synth.noteon(0, col.tone.midi, DEFAULT_MIDI_VELOCITY)
+ SongPlayingScreen.setNoteTimeout(int(self.currentNote.duration * 600))
+ self.currentNotePlayed = True
+
+ @event_handler(events.NOTEEND)
+ def clearTimeOutAndDisplayNext(self, evt) :
+ pygame.time.set_timer(evt.type, 0)
+ self.displayNext()
+
+ @staticmethod
+ def setNoteTimeout(delay) :
+ pygame.time.set_timer(events.NOTEEND, delay)
+