1 # -*- coding: utf-8 -*-
3 module pour jouer les chansons sur le fluidsynth
9 from app
.musicxml
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() :
32 print note
, note
.lyrics
[verseIndex
]
35 fs
.noteon(0, note
.midi
, 64)
36 duration
= note
.duration
* self
.quarterNoteDuration
/ 1000
38 fs
.noteoff(0, note
.midi
)
45 usage
= "%prog musicXmlFile.xml [options]"
46 op
= OptionParser(usage
)
47 op
.add_option("-i", "--part-index", dest
="partIndex"
49 , help = "Index de la partie qui contient le champ.")
51 op
.add_option("-c", '--no-chorus', dest
='autoDetectChorus'
52 , action
="store_false"
54 , help = "désactive la détection du refrain")
56 op
.add_option("-q", "--quarter-note-duration", dest
="quarterNoteDuration"
57 , type="int", default
=400
58 , help="Durée de la noire [default] (en millisecondes)"
61 op
.add_option("-b", "--bank", dest
="bank"
62 , type="int", default
="0"
63 , help="midi bank [default]")
65 op
.add_option("-p", "--preset", dest
="preset"
66 , type="int", default
="0"
67 , help="midi preset [default]")
69 options
, args
= op
.parse_args()
72 raise SystemExit(op
.format_help())
74 song
= musicXml2Song(args
[0],
75 partIndex
=options
.partIndex
,
76 autoDetectChorus
=options
.autoDetectChorus
)
78 '/Users/pinbe/dev/minwii/fluid-soundfont-3.1/FluidR3_GM.sf2',
79 quarterNoteDuration
=options
.quarterNoteDuration
,
81 preset
= options
.preset
)
85 if __name__
== '__main__' :