Ajout script d'export des chansons en musicxml vers .smwi (qq trucs en dur).
[minwii.git] / src / songs / xml2smwi.py
1 # -*- coding: utf-8 -*-
2 """
3 conversion d'un fichier musicxml en fichier .smwi
4
5 $Id$
6 $URL$
7 """
8
9 from app.musicxml import musicXml2Song
10 from songs.Song import Song
11 import sys
12 import os.path
13 from optparse import OptionParser
14
15 def main() :
16 usage = "%prog musicXmlFile.xml [options]"
17 op = OptionParser(usage)
18 op.add_option("-i", "--part-index", dest="partIndex"
19 , default = 0
20 , help = "Index de la partie qui contient le champ.")
21
22 op.add_option("-p", '--print', dest='printNotes'
23 , action="store_true"
24 , default = False
25 , help = "Affiche les notes sur la sortie standard (debug)")
26
27 op.add_option("-c", '--no-chorus', dest='autoDetectChorus'
28 , action="store_false"
29 , default = True
30 , help = "désactive la détection du refrain")
31
32
33 options, args = op.parse_args()
34
35 if len(args) != 1 :
36 raise SystemExit(op.format_help())
37
38 part = musicXml2Song(args[0],
39 partIndex=options.partIndex,
40 autoDetectChorus=options.autoDetectChorus,
41 printNotes=options.printNotes)
42
43 midiNoteNumbers = []
44 noteLengths = []
45 lyrics = []
46 for note, verseIndex in part.iterNotes(indefinitely=False) :
47 midiNoteNumbers.append(note.midi)
48 noteLengths.append(note.duration)
49 lyrics.append(note.lyrics[verseIndex].syllabus())
50
51 #scale = [55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72]
52 #scale = [n.midi for n in part.distinctNotes]
53
54 # houlala, c'est codé en dur !!!
55 scale = [65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83]
56 quarterNoteLength = 500
57 #---
58
59 lowerNote = part.distinctNotes[0].midi
60 higherNote = part.distinctNotes[-1].midi
61 requiresExtendedScale = higherNote - lowerNote > 12 # une octave == 12 demi-tons
62 song = Song(scale,
63 requiresExtendedScale=requiresExtendedScale,
64 midiNoteNumbers=midiNoteNumbers,
65 noteLengths=noteLengths,
66 lyrics=lyrics,
67 name=args[0],
68 quarterNoteLength=500)
69 dest = os.path.abspath(__file__).split(os.path.sep)[:-1]
70 dest.append('smwis')
71 dest.append('%s.smwi' % os.path.splitext(os.path.basename(song.name))[0])
72 dest = os.path.sep.join(dest)
73 print dest
74 song.save(dest)
75
76
77 if __name__ == '__main__' :
78 sys.exit(main())