]> CRI, Mines Paris - PSL - minwii.git/commitdiff
Ajout d'une option pour afficher / masquer les noms de notes en bas du clavier.
authorpin <pin@fe552daf-6dbe-4428-90eb-1537e0879342>
Mon, 27 Jun 2011 17:02:53 +0000 (17:02 +0000)
committerpin <pin@fe552daf-6dbe-4428-90eb-1537e0879342>
Mon, 27 Jun 2011 17:02:53 +0000 (17:02 +0000)
git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@359 fe552daf-6dbe-4428-90eb-1537e0879342

src/minwii/app.py
src/minwii/widgets/column.py
src/minwii/widgets/home.py
src/minwii/widgets/playingscreen.py

index c56700aed7288129f29f00b0670b5d054f381b4f..ab10bdf38b20967b9085a4d1bb9f35caecb2d65a 100755 (executable)
@@ -102,14 +102,14 @@ class MinWii(object):
         pygame.display.set_caption('MINWii')
         WT = self.WT
         
         pygame.display.set_caption('MINWii')
         WT = self.WT
         
-        songFile, playMode, wiimoteIndex = '', 'NORMAL', 0
+        songFile, playMode, displayNotes, wiimoteIndex = '', 'NORMAL', True, 0
 
         while True :
             WT.resume()
             WT.selectWiimote(self.nwiimotes - 1) # la télécommande est la souris
             self.screen = SCREEN_HOME
 
         while True :
             WT.resume()
             WT.selectWiimote(self.nwiimotes - 1) # la télécommande est la souris
             self.screen = SCREEN_HOME
-            exit, songFile, playMode, wiimoteIndex = \
-                self.selectSongAndOptions(songFile, playMode, wiimoteIndex)
+            exit, songFile, playMode, displayNotes, wiimoteIndex = \
+                self.selectSongAndOptions(songFile, playMode, displayNotes, wiimoteIndex)
             if exit : break
             
             
             if exit : break
             
             
@@ -120,20 +120,22 @@ class MinWii(object):
             
             self.screen = SCREEN_PLAY
             WT.selectWiimote(wiimoteIndex)
             
             self.screen = SCREEN_PLAY
             WT.selectWiimote(wiimoteIndex)
-            self.runPlayingScreen(songFile, playMode, instrumentDescription)
+            self.runPlayingScreen(songFile, playMode, displayNotes, instrumentDescription)
             WT.pause()
     
     
             WT.pause()
     
     
-    def selectSongAndOptions(self, songFile, playMode, wiimoteIndex) :
+    def selectSongAndOptions(self, songFile, playMode, displayNotes, wiimoteIndex) :
         """ lance l'écran de paramétrage et retourne un tuple comportant :
             - drapeau de sortie de l'application (booléen)
             - chemin du fichier de la chanson
             - mode (entier)
         """ lance l'écran de paramétrage et retourne un tuple comportant :
             - drapeau de sortie de l'application (booléen)
             - chemin du fichier de la chanson
             - mode (entier)
+            - affichage des notes (booléen)
             - wiimote sélectionnée (entier)
         """
         home = Home(songPath=SONG_FILE_PATH,
                     songFile=songFile,
                     playMode=playMode,
             - wiimote sélectionnée (entier)
         """
         home = Home(songPath=SONG_FILE_PATH,
                     songFile=songFile,
                     playMode=playMode,
+                    displayNotes=displayNotes,
                     wiimoteIndex=wiimoteIndex,
                     nwiimotes=self.nwiimotes)
         app = self.app
                     wiimoteIndex=wiimoteIndex,
                     nwiimotes=self.nwiimotes)
         app = self.app
@@ -163,6 +165,7 @@ class MinWii(object):
         return (home.exitApp,
                 home.songFile,
                 home.selectedPlayMode,
         return (home.exitApp,
                 home.songFile,
                 home.selectedPlayMode,
+                home.displayNotes,
                 home.selectedWiimoteIndex)
     
     def selectInstrument(self) :
                 home.selectedWiimoteIndex)
     
     def selectInstrument(self) :
@@ -182,7 +185,7 @@ class MinWii(object):
             console.info('ajustement octave : %d', instru['octave'])
         return instru
     
             console.info('ajustement octave : %d', instru['octave'])
         return instru
     
-    def runPlayingScreen(self, songFile, playMode, instrumentDescription) :
+    def runPlayingScreen(self, songFile, playMode, displayNotes, instrumentDescription) :
         """ Lance l'écran de jeu principal avec la chanson 'songFile' dans le mode 'playMode'
             avec l'instrument midi 'instrumentDescription'.
         """
         """ Lance l'écran de jeu principal avec la chanson 'songFile' dans le mode 'playMode'
             avec l'instrument midi 'instrumentDescription'.
         """
@@ -192,10 +195,10 @@ class MinWii(object):
         self.synth.adjust_octave(0, octave)
         self.synth.program_select(0, bank, preset)
         if playMode == PLAYING_MODES_DICT['IMPRO'] :
         self.synth.adjust_octave(0, octave)
         self.synth.program_select(0, bank, preset)
         if playMode == PLAYING_MODES_DICT['IMPRO'] :
-            playingScreen = PlayingScreen(self.synth)
+            playingScreen = PlayingScreen(self.synth, displayNotes=displayNotes)
         else :
             song = musicXml2Song(songFile)
         else :
             song = musicXml2Song(songFile)
-            self.playingScreen = playingScreen = SongPlayingScreen(self.synth, song, mode=playMode)
+            self.playingScreen = playingScreen = SongPlayingScreen(self.synth, song, mode=playMode, displayNotes=displayNotes)
         playingScreen.run()
         pygame.event.clear()
         EventDispatcher.reset()
         playingScreen.run()
         pygame.event.clear()
         EventDispatcher.reset()
index d82915292ff83163a14faa5f4254f99824945fa3..b1135296b6f19429d6b983a0f6d8a8a433c38e17 100755 (executable)
@@ -27,7 +27,7 @@ class Column(pygame.sprite.DirtySprite) :
     ''' colonne utilisée pour l'affichage d'une touche du clavier de jeu.
     '''
     
     ''' colonne utilisée pour l'affichage d'une touche du clavier de jeu.
     '''
     
-    def __init__(self, group, index, hue, rect, tone) :
+    def __init__(self, group, index, hue, rect, tone, displayNote=True) :
         pygame.sprite.DirtySprite.__init__(self, group)
         self.index = index
         self.state = False
         pygame.sprite.DirtySprite.__init__(self, group)
         self.index = index
         self.state = False
@@ -43,7 +43,8 @@ class Column(pygame.sprite.DirtySprite) :
         w, h = rect.w, rect.h
         tw, th, = toneName.get_size()
         toneRect = pygame.Rect(((w - tw) / 2, h - th), (tw, th))
         w, h = rect.w, rect.h
         tw, th, = toneName.get_size()
         toneRect = pygame.Rect(((w - tw) / 2, h - th), (tw, th))
-        sur.blit(toneName, toneRect)
+        if displayNote :
+            sur.blit(toneName, toneRect)
         self.surOff = sur
         self.rectOff = rect
         
         self.surOff = sur
         self.rectOff = rect
         
@@ -58,7 +59,8 @@ class Column(pygame.sprite.DirtySprite) :
         self.surOn = gradients.vertical(rectOn.size, topRgba, bottomRgba)
         w, h = rectOn.w, rectOn.h
         toneRect = pygame.Rect(((w - tw) / 2, h - th), (tw, th))
         self.surOn = gradients.vertical(rectOn.size, topRgba, bottomRgba)
         w, h = rectOn.w, rectOn.h
         toneRect = pygame.Rect(((w - tw) / 2, h - th), (tw, th))
-        self.surOn.blit(toneName, toneRect)
+        if displayNote :
+            self.surOn.blit(toneName, toneRect)
         self.rectOn = rectOn
         
         self.image = self.surOff
         self.rectOn = rectOn
         
         self.image = self.surOff
index 8a671bcb6d7902f67d349d86c4b1634ff4f9be79..92a0e221b9e46af7b9fb894b878240a4b212df1e 100755 (executable)
@@ -52,6 +52,7 @@ class Home(object, Table) :
         self.font = pygame.font.Font(None,70)
         self._fill()
         self.selectedPlayMode = params.get('playMode', 'NORMAL')
         self.font = pygame.font.Font(None,70)
         self._fill()
         self.selectedPlayMode = params.get('playMode', 'NORMAL')
+        self.displayNotes = params.get('displayNotes', True)
         self.selectedWiimoteIndex = params.get('wiimoteIndex', 0)
         self._initLocalListeners()
 
         self.selectedWiimoteIndex = params.get('wiimoteIndex', 0)
         self._initLocalListeners()
 
@@ -79,6 +80,15 @@ class Home(object, Table) :
         for k, caption in PLAYING_MODES :
             self.modeSelect.add(self.createLabel(caption), k)
         self.td(self.modeSelect,colspan=3, style=STYLE_RIGHT_COL)
         for k, caption in PLAYING_MODES :
             self.modeSelect.add(self.createLabel(caption), k)
         self.td(self.modeSelect,colspan=3, style=STYLE_RIGHT_COL)
+        
+        # affichage / masquage des noms de notes
+        self.tr()
+        self.td(self.createLabel("Notes :"), style=STYLE_LEFT_COL)
+        self.displayNotesSelect = Select(True)
+        for k, caption in ((True, 'Oui'), (False, 'Non')) :
+            self.displayNotesSelect.add(self.createLabel(caption), k)
+        self.td(self.displayNotesSelect, style=STYLE_RIGHT_COL)
+        
 
         # choix des wiimotes
         self.tr()
 
         # choix des wiimotes
         self.tr()
@@ -112,6 +122,14 @@ class Home(object, Table) :
         else :
             self.playButton.disabled = False
     
         else :
             self.playButton.disabled = False
     
+    @property
+    def displayNotes(self) :
+        return self.displayNotesSelect.value
+    
+    @displayNotes.setter
+    def displayNotes(self, value) :
+        self.displayNotesSelect.value = value
+    
     @property
     def selectedWiimoteIndex(self) :
         return self.selectedWiimote.value
     @property
     def selectedWiimoteIndex(self) :
         return self.selectedWiimote.value
index b1dbe800565b3cd1cfacf61cfbbb303dd91fde44..95190530c6d44b2bb0bf321cca7943fff1756574 100755 (executable)
@@ -27,7 +27,7 @@ from column import Column
 
 class PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) :
 
 
 class PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) :
 
-    def __init__(self, synth, distinctNotes=[]) :
+    def __init__(self, synth, distinctNotes=[], displayNotes=True) :
         """
         distinctNotes : notes disctinctes présentes dans la chanson
         triées du plus grave au plus aigu.
         """
         distinctNotes : notes disctinctes présentes dans la chanson
         triées du plus grave au plus aigu.
@@ -35,6 +35,7 @@ class PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) :
         super(PlayingScreenBase, self).__init__()
         self.synth = synth
         self.distinctNotes = distinctNotes
         super(PlayingScreenBase, self).__init__()
         self.synth = synth
         self.distinctNotes = distinctNotes
+        self.displayNotes = displayNotes
         self.keyboardLength = 0
         self.keyboardRects = []
         self.cursor = None
         self.keyboardLength = 0
         self.keyboardRects = []
         self.cursor = None
@@ -77,7 +78,7 @@ class PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) :
         for i, rect in enumerate(self.keyboardRects) :
             hue = FIRST_HUE - hueStep * i
             tone = self.distinctNotes[i]
         for i, rect in enumerate(self.keyboardRects) :
             hue = FIRST_HUE - hueStep * i
             tone = self.distinctNotes[i]
-            c = Column(self, i, hue, rect, tone)
+            c = Column(self, i, hue, rect, tone, displayNote=self.displayNotes)
             self.add(c, layer=BACKGROUND_LAYER)
             self.columns[tone.midi] = c
         
             self.add(c, layer=BACKGROUND_LAYER)
             self.columns[tone.midi] = c
         
@@ -166,14 +167,14 @@ class PlayingScreen(PlayingScreenBase) :
     
     scale = [55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72]
 
     
     scale = [55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72]
 
-    def __init__(self, synth) :
+    def __init__(self, synth, displayNotes=True) :
         distinctNotes = []
         self.currentColumn = None
         for midi in self.scale :
             tone = Tone(midi)
             distinctNotes.append(tone)
         
         distinctNotes = []
         self.currentColumn = None
         for midi in self.scale :
             tone = Tone(midi)
             distinctNotes.append(tone)
         
-        super(PlayingScreen, self).__init__(synth, distinctNotes)
+        super(PlayingScreen, self).__init__(synth, distinctNotes, displayNotes=displayNotes)
             
     @event_handler(events.COLDOWN)
     def noteon(self, event) :
             
     @event_handler(events.COLDOWN)
     def noteon(self, event) :
@@ -191,8 +192,8 @@ class PlayingScreen(PlayingScreenBase) :
 
 class SongPlayingScreen(PlayingScreenBase) :
     
 
 class SongPlayingScreen(PlayingScreenBase) :
     
-    def __init__(self, synth, song, mode=PLAYING_MODES_DICT['NORMAL'], tempoTrim=0) :
-        super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
+    def __init__(self, synth, song, mode=PLAYING_MODES_DICT['NORMAL'], displayNotes=True, tempoTrim=0) :
+        super(SongPlayingScreen, self).__init__(synth, song.distinctNotes, displayNotes=displayNotes)
         self.song = song
         self.quarterNoteDuration = song.quarterNoteDuration
         self.tempoTrim = tempoTrim
         self.song = song
         self.quarterNoteDuration = song.quarterNoteDuration
         self.tempoTrim = tempoTrim