import pygame
from colorsys import hls_to_rgb
from gradients import gradients
-import events
-from eventutils import event_handler, EventDispatcher, EventHandlerMixin
from math import floor
from globals import BACKGROUND_LAYER
from globals import FOREGROUND_LAYER
from config import FONT_COLOR
-class Column(pygame.sprite.DirtySprite, EventHandlerMixin) :
+class Column(pygame.sprite.DirtySprite) :
def __init__(self, group, hue, rect, tone) :
pygame.sprite.DirtySprite.__init__(self, group)
self.rect = self.rectOff
self.state = state
self.dirty = 1
-
- #@event_handler(pygame.MOUSEBUTTONDOWN)
- def onMouseDown(self, event) :
- if self.rect.collidepoint(*event.pos) and self.state :
- self.raiseKeyDown()
-
- @event_handler(pygame.MOUSEBUTTONUP)
- def onMouseUp(self, event) :
- self.raiseKeyUp()
-
- def raiseKeyDown(self) :
- evt = pygame.event.Event(events.KEYDOWN, column=self)
- pygame.event.post(evt)
- print 'down', self.tone.nom
-
- 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 hls_to_rgba_8bits(h, l, s, a=1) :
self._initColumns()
self._running = False
self.draw(pygame.display.get_surface())
- self._initCursor()
-
+ self._initCursor()
def _initRects(self) :
""" création des espaces réservés pour
def handleKeyDown(self, event) :
if event.key == pygame.K_q:
self._running = False
-
+
+ @event_handler(pygame.MOUSEBUTTONDOWN)
+ def onMouseDown(self, event) :
+ # TODO à cleaner : on vire le dernier élément
+ # parce qu'il s'agit du curseur
+ for col in reversed(self.sprites()[:-1]) :
+ if col.rect.collidepoint(*event.pos):
+ self.raiseKeyDown(col)
+ break
+
+ @event_handler(pygame.MOUSEBUTTONUP)
+ def onMouseUp(self, event) :
+ for col in reversed(self.sprites()[:-1]) :
+ if col.rect.collidepoint(*event.pos) :
+ self.raiseKeyUp(col)
+ break
+
+ def raiseKeyDown(self, col) :
+ evt = pygame.event.Event(events.COLDOWN, column=col)
+ pygame.event.post(evt)
+
+ def raiseKeyUp(self, col) :
+ evt = pygame.event.Event(events.COLUP, column=col)
+ pygame.event.post(evt)
+
class PlayingScreen(_PlayingScreenBase) :
"fenêtre de jeu pour improvisation"
column = self.columns[note.midi]
column.update(True, syllabus)
self.currentColumn = column
+ self.currentNotePlayed = False
- @event_handler(events.KEYDOWN)
- def handleKeyDown(self, event) :
+ @event_handler(events.COLDOWN)
+ def handleColumnDown(self, event) :
col = event.column
- if col == self.currentColumn:
+ if col.state:
self.synth.noteon(0, col.tone.midi, DEFAULT_MIDI_VELOCITY)
+ self.currentNotePlayed = True
- @event_handler(events.KEYUP)
- def handleKeyUp(self, event) :
- self.synth.noteoff(0, self.currentColumn.tone.midi)
- self.displayNext()
-
\ No newline at end of file
+ @event_handler(events.COLUP)
+ def handleColumnUp(self, event) :
+ if self.currentNotePlayed :
+ self.synth.noteoff(0, self.currentColumn.tone.midi)
+ self.displayNext()