import types
import minwii.events as events
+from minwii.log import eventLogger
from minwii.eventutils import event_handler, EventDispatcher, EventHandlerMixin
from minwii.musicxml import Tone
from minwii.config import FRAMERATE
columnWidth = int(round(float(dispWidth) / self.keyboardLength))
rects = []
- for i in range(self.keyboardLength) :
+ for i in range(self.keyboardLength - 1) :
upperLeftCorner = (i*columnWidth, 0)
rect = pygame.Rect(upperLeftCorner, (columnWidth, dispHeight))
rects.append(rect)
+ # la dernière colonne a la largeur du reste
+ upperLeftCorner = ((i+1) * columnWidth, 0)
+ rect = pygame.Rect(upperLeftCorner, (dispWidth - (self.keyboardLength - 1) * columnWidth , dispHeight))
+ rects.append(rect)
+
self.keyboardRects = rects
def _initColumns(self) :
@event_handler(pygame.KEYDOWN)
def handleKeyDown(self, event) :
- if event.key == pygame.K_q or event.unicode == u'q':
+ if event.key == pygame.K_q or \
+ event.unicode == u'q' or \
+ pygame.K_ESCAPE:
self.stop()
@event_handler(pygame.MOUSEBUTTONDOWN)
def __init__(self, synth) :
distinctNotes = []
+ self.currentColumn = None
for midi in self.scale :
tone = Tone(midi)
distinctNotes.append(tone)
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)
+ @event_handler(events.COLDOWN)
+ def noteon(self, event) :
+ col = event.column
+ col.update(True)
+ self.currentColumn = col
+ self.playnote(col, event.pos)
+ @event_handler(events.COLUP)
+ def noteoff(self, event) :
+ if self.currentColumn :
+ self.currentColumn.update(False)
+ self.synth.noteoff(0, self.currentColumn.tone.midi)
+
class SongPlayingScreen(PlayingScreenBase) :
def handleEasyColumnOver(self, event) :
col = event.column
if col.state and \
- any(event.mouseEvent.buttons) and \
+ self.cursor.pressed and \
not self.currentNotePlayed :
self.playnote(col, event.pos)
SongPlayingScreen.setNoteTimeout(
def handleNormalColumnOver(self, event) :
col = event.column
if col.state and \
- any(event.mouseEvent.buttons) and \
+ self.cursor.pressed and \
not self.currentNotePlayed :
self.playnote(col, event.pos)
self.currentNotePlayed = True
def displayNext(self, event=None) :
if self.currentColumn:
self.currentColumn.update(False)
- note, verseIndex = self.noteIterator.next()
+ try :
+ note, verseIndex = self.noteIterator.next()
+ except StopIteration :
+ self.noteIterator = self.song.iterNotes()
+ note, verseIndex = self.noteIterator.next()
+ eventLogger.info(pygame.event.Event(events.SONGEND))
try :
syllabus = note.lyrics[verseIndex].syllabus()
except IndexError :
syllabus = u'…'
+
column = self.columns[note.midi]
column.update(True, syllabus)
self.currentColumn = column