示例#1
0
文件: snap.py 项目: glm35/abcde
    def setup_synth(self):
        """Setup the player so that it can produce sound.

           Raises:
               SingleNoteAbcPlayerException: an error occured during the synth setup.
                   Most common errors: fluidsynth library not found, soundfont not found.
        """
        try:
            self._handle = fluidhandle.FluidHandle()
            self._settings = fluidsettings.FluidSettings(self._handle)
            self._settings['synth.gain'] = 0.2
            self._synth = fluidsynth.FluidSynth(self._handle, self._settings)
            self._load_soundfont()
            self._settings['audio.driver'] = 'alsa'
            self._driver = fluidaudiodriver.FluidAudioDriver(
                self._handle, self._synth, self._settings)
        except (AttributeError, FluidError) as e:
            # rem: under Linux, AttributeError is raised when pyfluidsynth3 is
            # available but libfluidsynth1 is not.
            message = 'Failed to setup fluidsynth: ' + str(
                e) + '. Audio output will be disabled.'
            log.warning(message)
            log.debug(traceback.format_exc())
            raise SingleNoteAbcPlayerException(message)

        self._no_sound = False  # If we can reach that point without exception, we should have sound
        self.select_instrument(self._instrument)
示例#2
0
def create_synth():
    global HANDLE
    global SYNTH
    global ADRIVER
    global SEQUENCER
    global SYNTH_SEQ_ID
    global MY_SEQ_ID
    global SEQ_DURATION

    HANDLE = fluidhandle.FluidHandle()

    settings = fluidsettings.FluidSettings(HANDLE)
    settings['synth.gain'] = 0.2
    settings['synth.reverb.active'] = 'yes'
    settings['synth.chorus.active'] = 'no'
    SYNTH = fluidsynth.FluidSynth(HANDLE, settings)
    settings['audio.driver'] = 'alsa'
    ADRIVER = fluidaudiodriver.FluidAudioDriver(HANDLE, SYNTH, settings)

    SEQUENCER = fluidsequencer.FluidSequencer(HANDLE)
    # rem: the demo C code calls 'new_fluid_sequencer2(0)' while
    # the pyfluidsynth3 code calls new_fluid_sequencer()
    SEQUENCER.ticks_per_beat = TPB
    SEQUENCER.beats_per_minute = DEFAULT_BPM

    # register synth as first destination
    (SYNTH_SEQ_ID, name) = SEQUENCER.add_synth(SYNTH)

    # register myself as second destination
    MY_SEQ_ID = HANDLE.fluid_sequencer_register_client(
        SEQUENCER.seq, utility.fluidstring('me'), seq_callback, None)
示例#3
0
import time
import traceback

''' Based on the examples from pyfluidsynth by MostAwesomeDude. '''
''' Based on sequencer.py from tea2code'''

soundfonts = [  # We will use the first sound font that can be found in that list:
    '/usr/share/sounds/sf2/FluidR3_GM.sf2',
    '/usr/share/sounds/sf2/default.sf2'  # Fedora: symlink to '/usr/share/soundfonts/FluidR3_GM.sf2'
]

try:
    HANDLE = fluidhandle.FluidHandle()
    settings = fluidsettings.FluidSettings(HANDLE)
    settings['synth.gain'] = 0.2
    SYNTH = fluidsynth.FluidSynth(HANDLE, settings)
    #load_soundfont()
    settings['audio.driver'] = 'alsa'
    driver = fluidaudiodriver.FluidAudioDriver(HANDLE, SYNTH, settings)
except FluidError as e:
    message = 'Failed to setup fluidsynth: ' + str(
        e) + '. Audio output will be disabled.'
    print(message)
    print(traceback.format_exc())
    sys.exit(1)

#if len( sys.argv ) < 3:
#    print( "Usage: {0} library soundfont.sf2".format(sys.argv[0]) )
#    sys.exit()

示例#4
0
from pyfluidsynth3 import fluidaudiodriver, fluidhandle, fluidplayer, fluidsettings, fluidsynth

import sys
''' Based on the examples from pyfluidsynth by MostAwesomeDude. '''

if len(sys.argv) < 4:
    print("Usage: {0} library soundfont.sf2 song.mid".format(sys.argv[0]))
    sys.exit()

handle = fluidhandle.FluidHandle(sys.argv[1])
settings = fluidsettings.FluidSettings(handle)
synth = fluidsynth.FluidSynth(handle, settings)
driver = fluidaudiodriver.FluidAudioDriver(handle, synth, settings)
player = fluidplayer.FluidPlayer(handle, synth)

synth.load_soundfont(sys.argv[2])

player.play(sys.argv[3])
player.join()