1 # -*- coding: utf-8 -*-
3 module pour jouer les chansons sur le fluidsynth
9 from musicxmltosong
import musicXml2Song
10 from time
import sleep
12 from optparse
import OptionParser
14 class SongPlayer(object) :
15 """ Lecteur audio d'une chanson """
17 def __init__(self
, part
, soundFont
, quarterNoteDuration
=400, bank
=0, preset
=0) :
19 self
.quarterNoteDuration
= quarterNoteDuration
20 self
.fs
= fs
= fluidsynth
.Synth()
22 self
.fsid
= fsid
= fs
.sfload(soundFont
)
23 fs
.program_select(0, fsid
, bank
, preset
)
30 for note
, verseIndex
in self
.part
.iterNotes(indefinitely
=False) :
31 print note
, note
.lyrics
[verseIndex
]
32 fs
.noteon(0, note
.midi
, 64)
33 duration
= note
.duration
* self
.quarterNoteDuration
/ 1000
35 fs
.noteoff(0, note
.midi
)
42 usage
= "%prog musicXmlFile.xml [options]"
43 op
= OptionParser(usage
)
44 op
.add_option("-i", "--part-index", dest
="partIndex"
46 , help = "Index de la partie qui contient le champ.")
47 op
.add_option("-q", "--quarter-note-duration", dest
="quarterNoteDuration"
48 , type="int", default
=400
49 , help="Durée de la noire [default] (en millisecondes)"
51 op
.add_option("-b", "--bank", dest
="bank"
52 , type="int", default
="0"
53 , help="midi bank [default]")
54 op
.add_option("-p", "--preset", dest
="preset"
55 , type="int", default
="0"
56 , help="midi preset [default]")
58 options
, args
= op
.parse_args()
61 raise SystemExit(op
.format_help())
63 song
= musicXml2Song(args
[0], partIndex
=options
.partIndex
)
65 '/Users/pinbe/dev/minwii/fluid-soundfont-3.1/FluidR3_GM.sf2',
66 quarterNoteDuration
=options
.quarterNoteDuration
,
68 preset
= options
.preset
)
72 if __name__
== '__main__' :