From 310114ab3edb1a0641f39d428cbbf5039fe1a0aa Mon Sep 17 00:00:00 2001 From: pin Date: Tue, 16 Mar 2010 10:36:28 +0000 Subject: [PATCH] Ajout script d'export des chansons en musicxml vers .smwi (qq trucs en dur). git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@90 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/songs/xml2smwi.py | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 src/songs/xml2smwi.py diff --git a/src/songs/xml2smwi.py b/src/songs/xml2smwi.py new file mode 100755 index 0000000..add8024 --- /dev/null +++ b/src/songs/xml2smwi.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +""" +conversion d'un fichier musicxml en fichier .smwi + +$Id$ +$URL$ +""" + +from app.musicxml import musicXml2Song +from songs.Song import Song +import sys +import os.path +from optparse import OptionParser + +def main() : + usage = "%prog musicXmlFile.xml [options]" + op = OptionParser(usage) + op.add_option("-i", "--part-index", dest="partIndex" + , default = 0 + , help = "Index de la partie qui contient le champ.") + + op.add_option("-p", '--print', dest='printNotes' + , action="store_true" + , default = False + , help = "Affiche les notes sur la sortie standard (debug)") + + op.add_option("-c", '--no-chorus', dest='autoDetectChorus' + , action="store_false" + , default = True + , help = "désactive la détection du refrain") + + + options, args = op.parse_args() + + if len(args) != 1 : + raise SystemExit(op.format_help()) + + part = musicXml2Song(args[0], + partIndex=options.partIndex, + autoDetectChorus=options.autoDetectChorus, + printNotes=options.printNotes) + + midiNoteNumbers = [] + noteLengths = [] + lyrics = [] + for note, verseIndex in part.iterNotes(indefinitely=False) : + midiNoteNumbers.append(note.midi) + noteLengths.append(note.duration) + lyrics.append(note.lyrics[verseIndex].syllabus()) + + #scale = [55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72] + #scale = [n.midi for n in part.distinctNotes] + + # houlala, c'est codé en dur !!! + scale = [65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83] + quarterNoteLength = 500 + #--- + + lowerNote = part.distinctNotes[0].midi + higherNote = part.distinctNotes[-1].midi + requiresExtendedScale = higherNote - lowerNote > 12 # une octave == 12 demi-tons + song = Song(scale, + requiresExtendedScale=requiresExtendedScale, + midiNoteNumbers=midiNoteNumbers, + noteLengths=noteLengths, + lyrics=lyrics, + name=args[0], + quarterNoteLength=500) + dest = os.path.abspath(__file__).split(os.path.sep)[:-1] + dest.append('smwis') + dest.append('%s.smwi' % os.path.splitext(os.path.basename(song.name))[0]) + dest = os.path.sep.join(dest) + print dest + song.save(dest) + + +if __name__ == '__main__' : + sys.exit(main()) -- 2.20.1