From bf4fd0cf6bb79dffd32e4995f0b312fb1a32502f Mon Sep 17 00:00:00 2001 From: pin Date: Mon, 8 Mar 2010 17:17:52 +0000 Subject: [PATCH] ok pour le mode normal. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@84 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/app/events.py | 4 +-- src/app/minwii.py | 2 +- src/app/widgets/column.py | 33 +--------------------- src/app/widgets/playingscreen.py | 47 ++++++++++++++++++++++++-------- 4 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/app/events.py b/src/app/events.py index dd6ac47..ae99ad5 100755 --- a/src/app/events.py +++ b/src/app/events.py @@ -2,5 +2,5 @@ from pygame.locals import USEREVENT TIMEOUT = USEREVENT + 1 NOTEON = USEREVENT + 2 NOTEOFF = USEREVENT + 3 -KEYDOWN = USEREVENT + 4 -KEYUP = USEREVENT + 5 +COLDOWN = USEREVENT + 4 +COLUP = USEREVENT + 5 diff --git a/src/app/minwii.py b/src/app/minwii.py index be69eb9..08bbcfd 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -27,7 +27,7 @@ class MinWii(object): #app.run(home) #app.close(home) - song = musicXml2Song('/Users/pinbe/dev/minwii/src/songs/chansons/bon_tabac.xml') + song = musicXml2Song('/Users/pinbe/dev/minwii/src/songs/chansons/quinquin.xml') playingScreen = SongPlayingScreen(synth, song) #playingScreen = PlayingScreen(synth) playingScreen.run() diff --git a/src/app/widgets/column.py b/src/app/widgets/column.py index c0d8455..667903c 100755 --- a/src/app/widgets/column.py +++ b/src/app/widgets/column.py @@ -8,8 +8,6 @@ $URL$ 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 @@ -24,7 +22,7 @@ from config import FONT 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) @@ -88,35 +86,6 @@ class Column(pygame.sprite.DirtySprite, EventHandlerMixin) : 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) : diff --git a/src/app/widgets/playingscreen.py b/src/app/widgets/playingscreen.py index 9f84ee5..571a3d9 100755 --- a/src/app/widgets/playingscreen.py +++ b/src/app/widgets/playingscreen.py @@ -41,8 +41,7 @@ class _PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) : 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 @@ -104,7 +103,31 @@ class _PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) : 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" @@ -147,15 +170,17 @@ class SongPlayingScreen(_PlayingScreenBase) : 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() -- 2.20.1