1 # -*- coding: utf-8 -*-
3 conversion d'un fichier musicxml en fichier .smwi
9 from app
.musicxml
import musicXml2Song
10 from songs
.Song
import Song
13 from optparse
import OptionParser
16 usage
= "%prog musicXmlFile.xml [options]"
17 op
= OptionParser(usage
)
18 op
.add_option("-i", "--part-index", dest
="partIndex"
20 , help = "Index de la partie qui contient le champ.")
22 op
.add_option("-p", '--print', dest
='printNotes'
25 , help = "Affiche les notes sur la sortie standard (debug)")
27 op
.add_option("-c", '--no-chorus', dest
='autoDetectChorus'
28 , action
="store_false"
30 , help = "désactive la détection du refrain")
33 options
, args
= op
.parse_args()
36 raise SystemExit(op
.format_help())
38 part
= musicXml2Song(args
[0],
39 partIndex
=options
.partIndex
,
40 autoDetectChorus
=options
.autoDetectChorus
,
41 printNotes
=options
.printNotes
)
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())
51 #scale = [55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72]
52 #scale = [n.midi for n in part.distinctNotes]
54 # houlala, c'est codé en dur !!!
55 scale
= [65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83]
56 quarterNoteLength
= 500
59 lowerNote
= part
.distinctNotes
[0].midi
60 higherNote
= part
.distinctNotes
[-1].midi
61 requiresExtendedScale
= higherNote
- lowerNote
> 12 # une octave == 12 demi-tons
63 requiresExtendedScale
=requiresExtendedScale
,
64 midiNoteNumbers
=midiNoteNumbers
,
65 noteLengths
=noteLengths
,
68 quarterNoteLength
=500)
69 dest
= os
.path
.abspath(__file__
).split(os
.path
.sep
)[:-1]
71 dest
.append('%s.smwi' % os
.path
.splitext(os
.path
.basename(song
.name
))[0])
72 dest
= os
.path
.sep
.join(dest
)
77 if __name__
== '__main__' :