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\nsoundfont : %s', sfPath
)
41 console
.info('arrêt du synthétiseur.')
44 def adjust_octave(self
, chan
, octave
) :
46 Abaisse ou élève les notes de n octave
48 self
._octaveAjusts
[chan
] = octave
50 def sfunload(self
, update_midi_preset
=0):
51 FSynth
.sfunload(self
, self
.fsid
, update_midi_preset
=update_midi_preset
)
53 def program_select(self
, chan
, bank
, preset
):
54 FSynth
.program_select(self
, chan
, self
.fsid
, bank
, preset
)
56 def sfont_select(self
, chan
):
57 FSynth
.sfont_select(self
, chan
, self
.fsid
)
59 def noteon(self
, chan
, key
, vel
):
60 key
= key
+ self
._octaveAjusts
.get(chan
, 0) * 12
61 FSynth
.noteon(self
, chan
, key
, vel
)
62 evt
= pygame
.event
.Event(events
.NOTEON
, chan
=chan
, key
=key
, vel
=vel
)
63 pygame
.event
.post(evt
)
65 def noteoff(self
, chan
, key
) :
66 key
= key
+ self
._octaveAjusts
.get(chan
, 0) * 12
67 FSynth
.noteoff(self
, chan
, key
)
68 evt
= pygame
.event
.Event(events
.NOTEOFF
, chan
=chan
, key
=key
)
69 pygame
.event
.post(evt
)