Gestion explicite de KeyboardInterrupt pour être sûr de quitter le jeu sur un ^C.
[minwii.git] / src / minwii / synth.py
index f8e8798..f89dcc9 100755 (executable)
@@ -7,6 +7,7 @@ $URL$
 """
 from os.path import realpath, sep, exists
 from  fluidsynth import Synth as FSynth
+from fluidsynth import fluid_settings_setnum
 from log import console, envLogger, eventLogger
 import pygame
 import events
@@ -20,14 +21,16 @@ class Synth(FSynth) :
     - octaviation
     """
     
-    def __init__(self, gain=0.2, samplerate=44100, sfPath='') :
+    def __init__(self, gain=0.2, samplerate=44100, sfPath='', driver=None) :
         FSynth.__init__(self, gain=gain, samplerate=samplerate)
         
         if not sfPath :
             sfPath = SOUND_FONT
         assert exists(sfPath)
+        
+        self._gain = gain
 
-        self.start()
+        self.start(driver=driver)
         self.fsid = self.sfload(sfPath)
         self._octaveAjusts = {}
         console.debug('démarrage du synthétiseur')
@@ -37,6 +40,22 @@ class Synth(FSynth) :
         console.debug('arrêt du synthétiseur')
         self.delete()
     
+    def gain(self, gain) :
+        self._gain = gain
+        fluid_settings_setnum(self.settings, 'synth.gain', self._gain)
+    
+    def inc_gain(self, step = 0.1) :
+        self._gain = self._gain + step
+        if self._gain > 5 :
+            self._gain = 5
+        self.gain(self._gain)
+    
+    def dec_gain(self, step = 0.1) :
+        self._gain = self._gain - step
+        if self._gain < 0 :
+            self._gain = 0
+        self.gain(self._gain)
+
     def adjust_octave(self, chan, octave) :
         '''
         Abaisse ou élève les notes de n octave