9fb4a3eb1a1cffa6427ae8d1f05c32d4ab72d812
1 # -*- coding: utf-8 -*-
3 module de wrapping du synthétiseur
8 from os
.path
import realpath
, sep
, exists
9 from fluidsynth
import Synth
as FSynth
10 from log
import console
14 Interface fluidsynth avec les adaptations suivantes :
15 - la soundfont FluidR3_GM.sf2 est chargée par défaut
16 - le constructeur démarre le synthé
20 def __init__(self
, gain
=0.2, samplerate
=44100, sfPath
='') :
21 FSynth
.__init
__(self
, gain
=gain
, samplerate
=samplerate
)
24 sfPath
= realpath(__file__
).split(sep
)
26 sfPath
.append('soundfonts')
28 sfPath
.append('FluidR3_GM.sf2')
29 sfPath
= sep
.join(sfPath
)
34 self
.fsid
= self
.sfload(sfPath
)
35 self
._octaveAjusts
= {}
36 console
.info('démarrage du synthétiseur\nsoundfont : %s', sfPath
)
39 console
.info('arrêt du synthétiseur.')
42 def adjust_octave(self
, chan
, octave
) :
44 Abaisse ou élève les notes de n octave
46 self
._octaveAjusts
[chan
] = octave
48 def sfunload(self
, update_midi_preset
=0):
49 FSynth
.sfunload(self
, self
.fsid
, update_midi_preset
=update_midi_preset
)
51 def program_select(self
, chan
, bank
, preset
):
52 FSynth
.program_select(self
, chan
, self
.fsid
, bank
, preset
)
54 def sfont_select(self
, chan
):
55 FSynth
.sfont_select(self
, chan
, self
.fsid
)
57 def noteon(self
, chan
, key
, vel
):
58 key
= key
+ self
._octaveAjusts
.get(chan
, 0) * 12
59 FSynth
.noteon(self
, chan
, key
, vel
)
61 def noteoff(self
, chan
, key
) :
62 key
= key
+ self
._octaveAjusts
.get(chan
, 0) * 12
63 FSynth
.noteoff(self
, chan
, key
)