Incrémentation de la version : 2.0.0 -> 2.0.1.
[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() :
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 print [n.midi for n in part.distinctNotes]
53 for n in part.distinctNotes :
54 print n.midi, n.nom
55
56
57 # houlala, c'est codé en dur !!!
58 # scale = [65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83] (étoile des neiges)
59 # quarterNoteLength = 500
60 scale = [60, 62, 67, 69, 70, 72, 74, 75, 77, 79, 81] # (mon amant de saint-jean)
61 quarterNoteLength = 300
62 #---
63
64 lowerNote = part.distinctNotes[0].midi
65 higherNote = part.distinctNotes[-1].midi
66 requiresExtendedScale = higherNote - lowerNote > 12 # une octave == 12 demi-tons
67 song = Song(scale,
68 requiresExtendedScale=requiresExtendedScale,
69 midiNoteNumbers=midiNoteNumbers,
70 noteLengths=noteLengths,
71 lyrics=lyrics,
72 name=args[0],
73 quarterNoteLength=quarterNoteLength)
74 dest = os.path.abspath(__file__).split(os.path.sep)[:-1]
75 dest.append('smwis')
76 dest.append('%s.smwi' % os.path.splitext(os.path.basename(song.name))[0])
77 dest = os.path.sep.join(dest)
78 print dest
79 song.save(dest)
80
81
82 if __name__ == '__main__' :
83 sys.exit(main())