TIMEOUT = USEREVENT + 1
NOTEON = USEREVENT + 2
NOTEOFF = USEREVENT + 3
TIMEOUT = USEREVENT + 1
NOTEON = USEREVENT + 2
NOTEOFF = USEREVENT + 3
+KEYDOWN = USEREVENT + 4
+KEYUP = USEREVENT + 5
self.state = state
self.dirty = 1
self.state = state
self.dirty = 1
- @event_handler(pygame.MOUSEBUTTONDOWN)
+ #@event_handler(pygame.MOUSEBUTTONDOWN)
def onMouseDown(self, event) :
def onMouseDown(self, event) :
- if self.rect.collidepoint(*event.pos) :
- self.update(True)
- self.raiseNoteOn()
+ if self.rect.collidepoint(*event.pos) and self.state :
+ self.raiseKeyDown()
@event_handler(pygame.MOUSEBUTTONUP)
def onMouseUp(self, event) :
@event_handler(pygame.MOUSEBUTTONUP)
def onMouseUp(self, event) :
- self.update(False)
- self.raiseNoteOff()
- def raiseNoteOn(self) :
- evt = pygame.event.Event(events.NOTEON, tone=self.tone)
+ def raiseKeyDown(self) :
+ evt = pygame.event.Event(events.KEYDOWN, column=self)
+ print 'down', self.tone.nom
- def raiseNoteOff(self) :
- evt = pygame.event.Event(events.NOTEOFF, tone=self.tone)
- pygame.event.post(evt)
+ def raiseKeyUp(self) :
+ if self.state :
+ evt = pygame.event.Event(events.KEYUP, column=self)
+ pygame.event.post(evt)
+ print 'up', self.tone.nom
+
+# def raiseNoteOn(self) :
+# evt = pygame.event.Event(events.NOTEON, tone=self.tone)
+# pygame.event.post(evt)
+#
+# def raiseNoteOff(self) :
+# evt = pygame.event.Event(events.NOTEOFF, tone=self.tone)
+# pygame.event.post(evt)
def __init__(self, synth, song, mode=PLAYING_MODES['NORMAL']) :
super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
self.song = song
def __init__(self, synth, song, mode=PLAYING_MODES['NORMAL']) :
super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
self.song = song
+ self.currentColumn = None
self.noteIterator = self.song.iterNotes()
self.noteIterator = self.song.iterNotes()
+ def displayNext(self) :
+ if self.currentColumn:
+ self.currentColumn.update(False)
note, verseIndex = self.noteIterator.next()
note, verseIndex = self.noteIterator.next()
- syllabus = note.lyrics[verseIndex].syllabus()
+ syllabus = note.lyrics[verseIndex].syllabus(encoding="iso-8859-1")
column = self.columns[note.midi]
column.update(True, syllabus)
column = self.columns[note.midi]
column.update(True, syllabus)
+ self.currentColumn = column
+ @event_handler(events.KEYDOWN)
+ def handleKeyDown(self, event) :
+ col = event.column
+ if col == self.currentColumn:
+ self.synth.noteon(0, col.tone.midi, DEFAULT_MIDI_VELOCITY)
- @event_handler(events.NOTEON)
- def noteon(self, evt) :
- tone = evt.tone
- self.synth.noteon(0, tone.midi, DEFAULT_MIDI_VELOCITY)
-
- @event_handler(events.NOTEOFF)
- def noteoff(self, evt) :
- tone = evt.tone
- self.synth.noteoff(0, tone.midi)
+ @event_handler(events.KEYUP)
+ def handleKeyUp(self, event) :
+ self.synth.noteoff(0, self.currentColumn.tone.midi)
+ self.displayNext()
+
\ No newline at end of file