Implémentation de l'ajustement « en live » du tempo d'exécution de la chanson sur...
[minwii.git] / src / minwii / widgets / playingscreen.py
index 9296646..b1dbe80 100755 (executable)
@@ -64,7 +64,7 @@ class PlayingScreenBase(pygame.sprite.LayeredDirty, EventHandlerMixin) :
             rect = pygame.Rect(upperLeftCorner, (columnWidth, dispHeight))
             rects.append(rect)
         
             rect = pygame.Rect(upperLeftCorner, (columnWidth, dispHeight))
             rects.append(rect)
         
-        # la dernière colonne a la largeur du reste
+        # la dernière colonne à la largeur du reste
         upperLeftCorner = ((i+1) * columnWidth, 0)
         rect = pygame.Rect(upperLeftCorner, (dispWidth - (self.keyboardLength - 1) * columnWidth , dispHeight))
         rects.append(rect)
         upperLeftCorner = ((i+1) * columnWidth, 0)
         rect = pygame.Rect(upperLeftCorner, (dispWidth - (self.keyboardLength - 1) * columnWidth , dispHeight))
         rects.append(rect)
@@ -191,10 +191,11 @@ class PlayingScreen(PlayingScreenBase) :
 
 class SongPlayingScreen(PlayingScreenBase) :
     
 
 class SongPlayingScreen(PlayingScreenBase) :
     
-    def __init__(self, synth, song, mode=PLAYING_MODES_DICT['NORMAL']) :
+    def __init__(self, synth, song, mode=PLAYING_MODES_DICT['NORMAL'], tempoTrim=0) :
         super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
         self.song = song
         self.quarterNoteDuration = song.quarterNoteDuration
         super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
         self.song = song
         self.quarterNoteDuration = song.quarterNoteDuration
+        self.tempoTrim = tempoTrim
         self.currentColumn = None
         self.noteIterator = self.song.iterNotes()
         self.displayNext()
         self.currentColumn = None
         self.noteIterator = self.song.iterNotes()
         self.displayNext()
@@ -229,10 +230,7 @@ class SongPlayingScreen(PlayingScreenBase) :
         col = event.column
         if col.state and not self.currentNotePlayed :
             self.playnote(col, event.pos)
         col = event.column
         if col.state and not self.currentNotePlayed :
             self.playnote(col, event.pos)
-            SongPlayingScreen.setNoteTimeout(
-                        int(self.currentNote.duration * \
-                            self.quarterNoteDuration)
-                                            )
+            self.setNoteTimeout()
             self.currentNotePlayed = True
 
     def handleEasyColumnOver(self, event) :
             self.currentNotePlayed = True
 
     def handleEasyColumnOver(self, event) :
@@ -241,10 +239,7 @@ class SongPlayingScreen(PlayingScreenBase) :
            self.cursor.pressed and \
            not self.currentNotePlayed :
             self.playnote(col, event.pos)
            self.cursor.pressed and \
            not self.currentNotePlayed :
             self.playnote(col, event.pos)
-            SongPlayingScreen.setNoteTimeout(
-                        int(self.currentNote.duration * \
-                            self.quarterNoteDuration)
-                                            )
+            self.setNoteTimeout()
             self.currentNotePlayed = True
 
     
             self.currentNotePlayed = True
 
     
@@ -267,10 +262,7 @@ class SongPlayingScreen(PlayingScreenBase) :
         if col.state and \
            not self.currentNotePlayed :
             self.playnote(col, event.pos)
         if col.state and \
            not self.currentNotePlayed :
             self.playnote(col, event.pos)
-            SongPlayingScreen.setNoteTimeout(
-                        int(self.currentNote.duration * \
-                            self.quarterNoteDuration)
-                                            )
+            self.setNoteTimeout()
             self.currentNotePlayed = True
 
 
             self.currentNotePlayed = True
 
 
@@ -327,10 +319,17 @@ class SongPlayingScreen(PlayingScreenBase) :
         self.synth.noteoff(0, self.currentNote.midi)
         self.displayNext()
     
         self.synth.noteoff(0, self.currentNote.midi)
         self.displayNext()
     
-    @staticmethod
-    def setNoteTimeout(delay) :
+    def setNoteTimeout(self) :
+        delay = self.currentNote.duration * self.quarterNoteDuration
+        delay = delay + delay * self.tempoTrim
         pygame.time.set_timer(events.NOTEEND, delay)
     
         pygame.time.set_timer(events.NOTEEND, delay)
     
+    def tempoTrimUp(self, step=0.1) :
+        self.tempoTrim = round(self.tempoTrim - step, 1)
+    
+    def tempoTrimDown(self, step=0.1) :
+        self.tempoTrim = round(self.tempoTrim + step, 1)
+    
     def stop(self) :
         pygame.time.set_timer(events.NOTEEND, 0)
         super(SongPlayingScreen, self).stop()
     def stop(self) :
         pygame.time.set_timer(events.NOTEEND, 0)
         super(SongPlayingScreen, self).stop()