+ super(PlayingScreen, self).__init__(synth, distinctNotes)
+
+ @event_handler(events.NOTEON)
+ def noteon(self, evt) :
+ tone = evt.tone
+ self.synth.noteon(0, tone.midi, 96)
+
+ @event_handler(events.NOTEOFF)
+ def noteoff(self, evt) :
+ tone = evt.tone
+ self.synth.noteoff(0, tone.midi)
+
+
+class SongPlayingScreen(_PlayingScreenBase) :
+
+ def __init__(self, synth, song, mode=PLAYING_MODES_DICT['EASY']) :
+ super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
+ self.song = song
+ self.quarterNoteDuration = song.quarterNoteDuration
+ self.currentColumn = None
+ self.noteIterator = self.song.iterNotes()
+ self.displayNext()
+ if mode == PLAYING_MODES_DICT['NORMAL'] :
+ EventDispatcher.addEventListener(events.COLDOWN, self.handleColumnDown)
+ EventDispatcher.addEventListener(events.COLUP, self.handleColumnUp)
+ elif mode == PLAYING_MODES_DICT['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:
+ pan = self.getPan(col.index)
+ self.synth.cc(0, 10, pan)
+ vel = self.getVelocity(event.pos)
+ self.synth.noteon(0, col.tone.midi, vel)
+ 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 :
+ pan = self.getPan(col.index)
+ self.synth.cc(0, 10, pan)
+ vel = self.getVelocity(event.pos)
+ self.synth.noteon(0, col.tone.midi, vel)
+ SongPlayingScreen.setNoteTimeout(
+ int(self.currentNote.duration * \
+ self.quarterNoteDuration)
+ )
+ self.currentNotePlayed = True
+
+ @event_handler(events.NOTEEND)
+ def clearTimeOutAndDisplayNext(self, evt) :
+ pygame.time.set_timer(evt.type, 0)
+ self.synth.noteoff(0, self.currentNote.midi)
+ self.displayNext()
+
+ @staticmethod
+ def setNoteTimeout(delay) :
+ pygame.time.set_timer(events.NOTEEND, delay)
+
+ def stop(self) :
+ pygame.time.set_timer(events.NOTEEND, 0)
+ super(SongPlayingScreen, self).stop()
+