我开始测试使用 fluidSyinth 创建 midi 文件。我的第一个脚本非常简单。它在 ipython 中完美运行,但不能作为命令行中的脚本运行,在命令行中它什么也不做,没有错误,也没有声音。我在 ipython 和命令行中都使用了 python2.7。我使用的是 ubuntu。这是代码:
#!/usr/bin/env python2.7
from mingus.midi import fluidsynth as c
import time
for i in range (0,100,1):
c.play_Note(i,0,100)
time.sleep(0.1)
我决定在 ubuntu 终端的命令行中直接测试 fluidsynth,使用
fluidsynth /usr/share/sounds/sf2/FluidR3_GM.sf2 mymusicfile.mid
我得到了这个:
FluidSynth version 1.1.6
Copyright (C) 2000-2012 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.
Cannot connect to server socket err = Connection refused
Cannot connect to server request channel
jackdmp 1.9.10
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2013 Grame.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
no message buffer overruns
no message buffer overruns
no message buffer overruns
JACK server starting in realtime mode with priority 10
audio_reservation_init
Acquire audio card Audio0
creating alsa driver ... hw:0|hw:0|1024|2|44100|0|0|nomon|swmeter|-|32bit
configuring for 44100Hz, period = 1024 frames (23.2 ms), buffer = 2 periods
ALSA: final selected sample format for capture: 32bit integer little-endian
ALSA: use 2 periods for capture
ALSA: final selected sample format for playback: 32bit integer little-endian
ALSA: use 2 periods for playback
Type 'help' for help topics.
>
但是 midi 文件没有被重现,不是吗?
此命令在 ubuntu-terminal 中运行良好:
fluidsynth -a alsa -m alsa_seq -l -i /usr/share/sounds/sf2/FluidR3_GM.sf2 mymusicfile.midi
但问题仍然存在于 python 中。如果我按以下方式运行我在本线程开头复制的脚本,它在 ipython 中可以正常工作:
run script.py
但是,当我从命令行上的 ubuntu-terminal 执行它时它没有运行:
python2.7 script.py
我尝试了以下在 ipython 中也可以运行的脚本:
#!/usr/bin/env python2.7
import time
import fluidsynth
fs = fluidsynth.Synth()
fs.start()
sfid = fs.sfload("example.sf2")
fs.program_select(0, sfid, 0, 0)
fs.noteon(0, 60, 30)
fs.noteon(0, 67, 30)
fs.noteon(0, 76, 30)
time.sleep(1.0)
fs.noteoff(0, 60)
fs.noteoff(0, 67)
fs.noteoff(0, 76)
time.sleep(1.0)
fs.delete()
当我从 ubuntu-terminal 运行它时,我得到以下输出:
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jackdmp 1.9.10
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2013 Grame.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
no message buffer overruns
no message buffer overruns
no message buffer overruns
JACK server starting in realtime mode with priority 10
audio_reservation_init
Acquire audio card Audio0
creating alsa driver ... hw:0|hw:0|1024|2|44100|0|0|nomon|swmeter|-|32bit
configuring for 44100Hz, period = 1024 frames (23.2 ms), buffer = 2 periods
ALSA: final selected sample format for capture: 32bit integer little-endian
ALSA: use 2 periods for capture
ALSA: final selected sample format for playback: 32bit integer little-endian
ALSA: use 2 periods for playback
JackTemporaryException : now quits...
尽管它没有发出任何声音。