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 print [n
.midi
for n
in part
.distinctNotes
]
53 for n
in part
.distinctNotes
:
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
64 lowerNote
= part
.distinctNotes
[0].midi
65 higherNote
= part
.distinctNotes
[-1].midi
66 requiresExtendedScale
= higherNote
- lowerNote
> 12 # une octave == 12 demi-tons
68 requiresExtendedScale
=requiresExtendedScale
,
69 midiNoteNumbers
=midiNoteNumbers
,
70 noteLengths
=noteLengths
,
73 quarterNoteLength
=quarterNoteLength
)
74 dest
= os
.path
.abspath(__file__
).split(os
.path
.sep
)[:-1]
76 dest
.append('%s.smwi' % os
.path
.splitext(os
.path
.basename(song
.name
))[0])
77 dest
= os
.path
.sep
.join(dest
)
82 if __name__
== '__main__' :