From: pin Date: Fri, 19 Mar 2010 13:48:05 +0000 (+0000) Subject: prise en charge des indications de tempo des fichiers musicxml. Si absent, le tempo... X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/63f3b77711f17de3cd3515d1a97f566438c551a7?ds=sidebyside;hp=8107325baba9dacf2d7721192c981714a262dc09 prise en charge des indications de tempo des fichiers musicxml. Si absent, le tempo est 120. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@97 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/app/minwii.py b/src/app/minwii.py index b52657d..cb6eef5 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -22,13 +22,13 @@ class MinWii(object): 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) - 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() diff --git a/src/app/musicxml.py b/src/app/musicxml.py index ab6dbf9..9302118 100755 --- a/src/app/musicxml.py +++ b/src/app/musicxml.py @@ -53,6 +53,7 @@ class Part(object) : self.notes = [] self.repeats = [] self.distinctNotes = [] + self.quarterNoteDuration = 500 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)) + 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): @@ -138,7 +148,6 @@ class Part(object) : 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 : diff --git a/src/app/widgets/home.py b/src/app/widgets/home.py index 391cb29..e1e09f1 100755 --- a/src/app/widgets/home.py +++ b/src/app/widgets/home.py @@ -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 CHANGE import pygame from gui.constants import reversedReadabilityDict, modeDict from songfilebrowser import FileOpenDialog +import os.path class Home(Table) : """ @@ -25,6 +27,7 @@ class Home(Table) : 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() @@ -99,9 +102,12 @@ class Home(Table) : 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() + 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 diff --git a/src/app/widgets/playingscreen.py b/src/app/widgets/playingscreen.py index ca2e9ff..975f401 100755 --- a/src/app/widgets/playingscreen.py +++ b/src/app/widgets/playingscreen.py @@ -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 + self.quarterNoteDuration = song.quarterNoteDuration 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) - SongPlayingScreen.setNoteTimeout(int(self.currentNote.duration * 600)) + SongPlayingScreen.setNoteTimeout( + int(self.currentNote.duration * \ + self.quarterNoteDuration) + ) self.currentNotePlayed = True @event_handler(events.NOTEEND)