From 9845b232ab53ef98733306299e1a52afbabb4e70 Mon Sep 17 00:00:00 2001 From: "benoit.pin" Date: Wed, 1 Dec 2010 12:45:55 +0000 Subject: [PATCH 1/1] Ajout du mode improvisation. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@322 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/minwii/app.py | 7 +++++-- src/minwii/globals.py | 3 ++- src/minwii/widgets/column.py | 2 +- src/minwii/widgets/home.py | 18 +++++++++++++++--- src/minwii/widgets/playingscreen.py | 22 +++++++++++++--------- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/minwii/app.py b/src/minwii/app.py index dfe24ca..f36094c 100755 --- a/src/minwii/app.py +++ b/src/minwii/app.py @@ -148,12 +148,15 @@ class MinWii(object): avec l'instrument midi 'instrumentDescription'. """ playMode = PLAYING_MODES_DICT[playMode] - song = musicXml2Song(songFile) bank, preset = instrumentDescription['bank'], instrumentDescription['preset'] octave = instrumentDescription['octave'] self.synth.adjust_octave(0, octave) self.synth.program_select(0, bank, preset) - playingScreen = SongPlayingScreen(self.synth, song, mode=playMode) + if playMode == PLAYING_MODES_DICT['IMPRO'] : + playingScreen = PlayingScreen(self.synth) + else : + song = musicXml2Song(songFile) + playingScreen = SongPlayingScreen(self.synth, song, mode=playMode) playingScreen.run() pygame.event.clear() EventDispatcher.reset() diff --git a/src/minwii/globals.py b/src/minwii/globals.py index 2ce25eb..ac94d4e 100755 --- a/src/minwii/globals.py +++ b/src/minwii/globals.py @@ -15,7 +15,8 @@ PLAYING_MODES = (('BEGINNER' , u'Débutant'), ('EASY' , u'Facile'), ('NORMAL' , u'Normal'), ('ADVANCED' , u'Avancé'), - ('EXPERT' , u'Expert')) + ('EXPERT' , u'Expert'), + ('IMPRO' , u'Impro.'),) diff --git a/src/minwii/widgets/column.py b/src/minwii/widgets/column.py index fc7dde2..d829152 100755 --- a/src/minwii/widgets/column.py +++ b/src/minwii/widgets/column.py @@ -72,9 +72,9 @@ class Column(pygame.sprite.DirtySprite) : if state : group.change_layer(self, FOREGROUND_LAYER) sur = self.surOn + rect = self.rectOn if syllabus : sur = sur.copy() - rect = self.rectOn renderedSyl = LYRICS_FONT.render(syllabus, True, FONT_COLOR) sw, sh, = renderedSyl.get_size() w, h = self.rectOn.w, self.rectOn.h diff --git a/src/minwii/widgets/home.py b/src/minwii/widgets/home.py index 429342b..5b34403 100755 --- a/src/minwii/widgets/home.py +++ b/src/minwii/widgets/home.py @@ -72,9 +72,9 @@ class Home(object, Table) : del st['padding_top'] self.td(self.songTitle, style = st) - # choix du niveau + # choix du mode de jeu self.tr() - self.td(self.createLabel("Niveau :"), style=STYLE_LEFT_COL) + self.td(self.createLabel("Mode :"), style=STYLE_LEFT_COL) self.modeSelect = Select('NORMAL') for k, caption in PLAYING_MODES : self.modeSelect.add(self.createLabel(caption), k) @@ -96,7 +96,7 @@ class Home(object, Table) : self.tr() self.quitButton = Button(self.createLabel("Quitter")) self.td(self.quitButton, style={'padding_top' : 50}) - self.playButton = Button(self.createLabel("Jouer"), disabled=not self.songFile) + self.playButton = Button(self.createLabel("Jouer")) self.td(self.playButton, style={'padding_top' : 50}) @property @@ -106,6 +106,11 @@ class Home(object, Table) : @selectedPlayMode.setter def selectedPlayMode(self, value) : self.modeSelect.value = value + if self.selectedPlayMode != 'IMPRO' and \ + not self.songFile : + self.playButton.disabled = True + else : + self.playButton.disabled = False @property def selectedWiimoteIndex(self) : @@ -119,6 +124,13 @@ class Home(object, Table) : self.browseButton.connect(CLICK, self.open_file_browser) self.quitButton.connect(CLICK, self._exitApp) self.playButton.connect(CLICK, self._exitHome) + self.modeSelect.connect(CHANGE, self._changeModeCB) + + def _changeModeCB(self) : + if self.selectedPlayMode == 'IMPRO' : + self.playButton.disabled = False + elif not self.songFile : + self.playButton.disabled = True def _exitApp(self, data=None) : self.exitApp = True diff --git a/src/minwii/widgets/playingscreen.py b/src/minwii/widgets/playingscreen.py index ca6a1e3..9c1ebfb 100755 --- a/src/minwii/widgets/playingscreen.py +++ b/src/minwii/widgets/playingscreen.py @@ -163,22 +163,26 @@ class PlayingScreen(PlayingScreenBase) : 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) : -- 2.20.1