From: pin Date: Mon, 22 Mar 2010 09:15:23 +0000 (+0000) Subject: implémentation du sélecteur d'instrument (début). X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/afeb92b07428059fd3a1022aefa64a1aeba68152?ds=inline;hp=cc386bf1182f3c1b5744c73ad63bd635b3c2af53 implémentation du sélecteur d'instrument (début). git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@101 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/app/globals.py b/src/app/globals.py index 8261eda..ef51d78 100755 --- a/src/app/globals.py +++ b/src/app/globals.py @@ -5,6 +5,8 @@ constantes globales partagées par plusieurs modules. $Id$ $URL$ """ +from colorsys import hls_to_rgb +from math import floor BACKGROUND_LAYER = 0 FOREGROUND_LAYER = 1 @@ -13,3 +15,9 @@ PLAYING_MODES = {'EASY':0 ,'NORMAL':1 ,'ADVANCED':2 ,'EXPERT':3} + +def hls_to_rgba_8bits(h, l, s, a=1) : + #convert to rgb ranging from 0 to 255 + rgba = [floor(255 * i) for i in hls_to_rgb(h, l, s) + (a,)] + return tuple(rgba) + diff --git a/src/app/minwii.py b/src/app/minwii.py index 350f32d..6f277a7 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -11,6 +11,7 @@ from pgu.gui import Desktop from pgu.gui import QUIT from widgets.home import Home from widgets.playingscreen import SongPlayingScreen, PlayingScreen +from widgets.instrumentselector import InstrumentSelector from synth import Synth from eventutils import EventDispatcher from musicxml import musicXml2Song @@ -28,8 +29,14 @@ class MinWii(object): app.run(home) app.close(home) + selector = InstrumentSelector() + selector.run() + selector.stop() + pygame.event.clear() + EventDispatcher.reset() + song = musicXml2Song(home.songFile, printNotes=True) - synth.program_select(0, 0, 45) + synth.program_select(0, 0, 0) playingScreen = SongPlayingScreen(synth, song) playingScreen.run() pygame.event.clear() diff --git a/src/app/widgets/column.py b/src/app/widgets/column.py index 771b1e4..92f53ba 100755 --- a/src/app/widgets/column.py +++ b/src/app/widgets/column.py @@ -6,11 +6,11 @@ $Id$ $URL$ """ import pygame -from colorsys import hls_to_rgb from gradients import gradients from math import floor from globals import BACKGROUND_LAYER from globals import FOREGROUND_LAYER +from globals import hls_to_rgba_8bits from config import OFF_LUMINANCE from config import OFF_SATURATION from config import ON_TOP_LUMINANCE @@ -85,8 +85,3 @@ class Column(pygame.sprite.DirtySprite) : self.state = state self.dirty = 1 - -def hls_to_rgba_8bits(h, l, s, a=1) : - #convert to rgb ranging from 0 to 255 - rgba = [floor(255 * i) for i in hls_to_rgb(h, l, s) + (a,)] - return tuple(rgba) diff --git a/src/app/widgets/instrumentselector.py b/src/app/widgets/instrumentselector.py new file mode 100755 index 0000000..330d6cb --- /dev/null +++ b/src/app/widgets/instrumentselector.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +""" +Écran de sélection de l'instrument + +$Id$ +$URL$ +""" +import pygame +from eventutils import event_handler, EventDispatcher, EventHandlerMixin +from cursors import WarpingCursor +from config import FRAMERATE +from globals import BACKGROUND_LAYER +from globals import CURSOR_LAYER +from globals import hls_to_rgba_8bits + + +class InstrumentSelector(pygame.sprite.LayeredDirty, EventHandlerMixin) : + + rows = 3 + cols = 3 + + def __init__(self) : + super(InstrumentSelector, self).__init__() + self._initCursor() + self._initRects() + self._initTiles() + + def _initRects(self) : + screen = pygame.display.get_surface() + tileWidth = int(round(float(screen.get_width()) / self.cols)) + tileHeight = int(round(float(screen.get_height()) / self.rows)) + + rects = [] + for y in range(self.cols) : + for x in range(self.rows) : + upperLeftCorner = (y * tileWidth, x * tileHeight) + rect = pygame.Rect(upperLeftCorner, (tileWidth, tileHeight)) + rects.append(rect) + self.rects = rects + + def _initTiles(self) : + for rect in self.rects : + tile = InstrumentTile(self, rect) + self.add(tile, layer=BACKGROUND_LAYER) + + + + def _initCursor(self) : + self.cursor = WarpingCursor(blinkMode=True) + self.add(self.cursor, layer=CURSOR_LAYER) + + + def run(self): + self._running = True + clock = pygame.time.Clock() + pygame.display.flip() + pygame.mouse.set_visible(False) + while self._running : + EventDispatcher.dispatchEvents() + dirty = self.draw(pygame.display.get_surface()) + pygame.display.update(dirty) + clock.tick(FRAMERATE) + + def stop(self) : + self._running = False + pygame.mouse.set_visible(True) + self.cursor._stopBlink() + + @event_handler(pygame.KEYDOWN) + def handleKeyDown(self, event) : + if event.key == pygame.K_q: + self.stop() + + +class InstrumentTile(pygame.sprite.DirtySprite) : + + def __init__(self, group, rect) : + pygame.sprite.DirtySprite.__init__(self, group) + self.rect = rect + self.image = pygame.Surface(rect.size) + self.image.fill((0,255,255,64))