ajout de la méthode adjust_octave au synthé pour corriger la hauteur des notes.
[minwii.git] / src / app / synth.py
1 # -*- coding: utf-8 -*-
2 """
3 module de wrapping du synthétiseur
4
5 $Id$
6 $URL$
7 """
8 from os.path import realpath, sep, exists
9 from fluidsynth import Synth as FSynth
10
11 class Synth(FSynth) :
12
13 def __init__(self, gain=0.2, samplerate=44100) :
14 FSynth.__init__(self, gain=gain, samplerate=samplerate)
15
16 sfPath = realpath(__file__).split(sep)
17 sfPath = sfPath[:-1]
18 sfPath.append('soundfonts')
19
20 sfPath.append('FluidR3_GM.sf2')
21 sfPath = sep.join(sfPath)
22 assert exists(sfPath)
23
24 self.start()
25 self.fsid = self.sfload(sfPath)
26 self._octaveAjusts = {}
27
28 def adjust_octave(self, chan, octave) :
29 '''
30 Abaisse ou élève les notes de n octave
31 '''
32 self._octaveAjusts[chan] = octave
33
34 def sfunload(self, update_midi_preset=0):
35 FSynth.sfunload(self, self.fsid, update_midi_preset=update_midi_preset)
36
37 def program_select(self, chan, bank, preset):
38 FSynth.program_select(self, chan, self.fsid, bank, preset)
39
40 def sfont_select(self, chan):
41 FSynth.sfont_select(self, chan, self.fsid)
42
43 def noteon(self, chan, key, vel):
44 key = key + self._octaveAjusts.get(chan, 0) * 12
45 FSynth.noteon(self, chan, key, vel)
46
47 def noteoff(self, chan, key) :
48 key = key + self._octaveAjusts.get(chan, 0) * 12
49 FSynth.noteoff(self, chan, key)
50
51
52 if __name__ == '__main__' :
53 initsynth()