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
16 Interface fluidsynth avec les adaptations suivantes :
17 - la soundfont FluidR3_GM.sf2 est chargée par défaut
18 - le constructeur démarre le synthé
22 def __init__(self
, gain
=0.2, samplerate
=44100, sfPath
='') :
23 FSynth
.__init
__(self
, gain
=gain
, samplerate
=samplerate
)
26 sfPath
= realpath(__file__
).split(sep
)
28 sfPath
.append('soundfonts')
30 sfPath
.append('FluidR3_GM.sf2')
31 sfPath
= sep
.join(sfPath
)
36 self
.fsid
= self
.sfload(sfPath
)
37 self
._octaveAjusts
= {}
38 console
.info('démarrage du synthétiseur')
39 console
.info('soundfont : %s', sfPath
)
42 console
.info('arrêt du synthétiseur')
45 def adjust_octave(self
, chan
, octave
) :
47 Abaisse ou élève les notes de n octave
49 self
._octaveAjusts
[chan
] = octave
51 def sfunload(self
, update_midi_preset
=0):
52 FSynth
.sfunload(self
, self
.fsid
, update_midi_preset
=update_midi_preset
)
54 def program_select(self
, chan
, bank
, preset
):
55 FSynth
.program_select(self
, chan
, self
.fsid
, bank
, preset
)
57 def sfont_select(self
, chan
):
58 FSynth
.sfont_select(self
, chan
, self
.fsid
)
60 def noteon(self
, chan
, key
, vel
):
61 key
= key
+ self
._octaveAjusts
.get(chan
, 0) * 12
62 FSynth
.noteon(self
, chan
, key
, vel
)
63 evt
= pygame
.event
.Event(events
.NOTEON
, chan
=chan
, key
=key
, vel
=vel
)
64 pygame
.event
.post(evt
)
66 def noteoff(self
, chan
, key
) :
67 key
= key
+ self
._octaveAjusts
.get(chan
, 0) * 12
68 FSynth
.noteoff(self
, chan
, key
)
69 evt
= pygame
.event
.Event(events
.NOTEOFF
, chan
=chan
, key
=key
)
70 pygame
.event
.post(evt
)