prise en charge des indications de tempo des fichiers musicxml. Si absent, le tempo...
authorpin <pin@fe552daf-6dbe-4428-90eb-1537e0879342>
Fri, 19 Mar 2010 13:48:05 +0000 (13:48 +0000)
committerpin <pin@fe552daf-6dbe-4428-90eb-1537e0879342>
Fri, 19 Mar 2010 13:48:05 +0000 (13:48 +0000)
git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@97 fe552daf-6dbe-4428-90eb-1537e0879342

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

index b52657d..cb6eef5 100755 (executable)
@@ -22,13 +22,13 @@ class MinWii(object):
         synth = Synth()
         synth.program_select(0, 0, 0)
 
         synth = Synth()
         synth.program_select(0, 0, 0)
 
-        if True :
+        while True :
             home = Home(songPath=SONG_FILE_PATH)
             home.connect(QUIT, app.quit)
             app.run(home)
             app.close(home)
             
             home = Home(songPath=SONG_FILE_PATH)
             home.connect(QUIT, app.quit)
             app.run(home)
             app.close(home)
             
-            song = musicXml2Song('/Users/pinbe/dev/minwii/src/songs/chansons/etoile_neige.xml', printNotes=True)
+            song = musicXml2Song(home.songFile, printNotes=True)
             playingScreen = SongPlayingScreen(synth, song)
             #playingScreen = PlayingScreen(synth)
             playingScreen.run()
             playingScreen = SongPlayingScreen(synth, song)
             #playingScreen = PlayingScreen(synth)
             playingScreen.run()
index ab6dbf9..9302118 100755 (executable)
@@ -53,6 +53,7 @@ class Part(object) :
         self.notes = []
         self.repeats = []
         self.distinctNotes = []
         self.notes = []
         self.repeats = []
         self.distinctNotes = []
+        self.quarterNoteDuration = 500
         self._parseMusic()
         self.verses = [[]]
         self.chorus = []
         self._parseMusic()
         self.verses = [[]]
         self.chorus = []
@@ -104,6 +105,15 @@ class Part(object) :
                 self.repeats.append(barline)
         
         self.distinctNotes.sort(lambda a, b : cmp(a.midi, b.midi))
                 self.repeats.append(barline)
         
         self.distinctNotes.sort(lambda a, b : cmp(a.midi, b.midi))
+        sounds = self.node.getElementsByTagName('sound')
+        tempo = 120
+        for sound in sounds :
+            if sound.hasAttribute('tempo') :
+                tempo = float(sound.getAttribute('tempo'))
+                break
+        
+        self.quarterNoteDuration = int(round(60000/tempo))
+        
         
 
     def _findChorus(self):
         
 
     def _findChorus(self):
@@ -138,7 +148,6 @@ class Part(object) :
     
     def iterNotes(self, indefinitely=True) :
         "exécution de la chanson avec l'alternance couplets / refrains"
     
     def iterNotes(self, indefinitely=True) :
         "exécution de la chanson avec l'alternance couplets / refrains"
-        print 'indefinitely', indefinitely
         if indefinitely == False :
             iterable = self.verses
         else :
         if indefinitely == False :
             iterable = self.verses
         else :
index 391cb29..e1e09f1 100755 (executable)
@@ -13,9 +13,11 @@ from pgu.gui import Switch
 from pgu.gui import Select
 from pgu.gui import CLICK
 from pgu.gui import QUIT
 from pgu.gui import Select
 from pgu.gui import CLICK
 from pgu.gui import QUIT
+from pgu.gui import CHANGE
 import pygame
 from gui.constants import reversedReadabilityDict, modeDict
 from songfilebrowser import FileOpenDialog
 import pygame
 from gui.constants import reversedReadabilityDict, modeDict
 from songfilebrowser import FileOpenDialog
+import os.path
 
 class Home(Table) :
     """
 
 class Home(Table) :
     """
@@ -25,6 +27,7 @@ class Home(Table) :
     def __init__(self,**params):
         Table.__init__(self,**params)
         self.songPath = params.get('songPath', '.')
     def __init__(self,**params):
         Table.__init__(self,**params)
         self.songPath = params.get('songPath', '.')
+        self.songFile = None
         self.spaceSize = (100,100)
         self.font = pygame.font.Font(None,70)
         self._fill()
         self.spaceSize = (100,100)
         self.font = pygame.font.Font(None,70)
         self._fill()
@@ -99,9 +102,12 @@ class Home(Table) :
     
     def open_file_browser(self):
         dlg = FileOpenDialog(self.songPath)
     
     def open_file_browser(self):
         dlg = FileOpenDialog(self.songPath)
-        #d = MINWiiDialog(font = self.font,width = 800, height = 600,path = "../songs/smwis")
-        #d.connect(pguGui.CHANGE, self.handle_file_browser_closed, d)
+        dlg.connect(CHANGE, self.handle_file_browser_closed, dlg)
         dlg.open()
     
         dlg.open()
     
+    def handle_file_browser_closed(self, dlg) :
+        if dlg.value and os.path.isfile(dlg.value):
+            self.songFile = dlg.value
+    
 
     
\ No newline at end of file
 
     
\ No newline at end of file
index ca2e9ff..975f401 100755 (executable)
@@ -169,6 +169,7 @@ class SongPlayingScreen(_PlayingScreenBase) :
     def __init__(self, synth, song, mode=PLAYING_MODES['EASY']) :
         super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
         self.song = song
     def __init__(self, synth, song, mode=PLAYING_MODES['EASY']) :
         super(SongPlayingScreen, self).__init__(synth, song.distinctNotes)
         self.song = song
+        self.quarterNoteDuration = song.quarterNoteDuration
         self.currentColumn = None
         self.noteIterator = self.song.iterNotes()
         self.displayNext()
         self.currentColumn = None
         self.noteIterator = self.song.iterNotes()
         self.displayNext()
@@ -205,7 +206,10 @@ class SongPlayingScreen(_PlayingScreenBase) :
         col = event.column
         if col.state and not self.currentNotePlayed :
             self.synth.noteon(0, col.tone.midi, DEFAULT_MIDI_VELOCITY)
         col = event.column
         if col.state and not self.currentNotePlayed :
             self.synth.noteon(0, col.tone.midi, DEFAULT_MIDI_VELOCITY)
-            SongPlayingScreen.setNoteTimeout(int(self.currentNote.duration * 600))
+            SongPlayingScreen.setNoteTimeout(
+                        int(self.currentNote.duration * \
+                            self.quarterNoteDuration)
+                                            )
             self.currentNotePlayed = True
     
     @event_handler(events.NOTEEND)
             self.currentNotePlayed = True
     
     @event_handler(events.NOTEEND)