Ben and David,

Short Story

I think what is missing in the previous communication is that both timidity
and fluidsynth can be run as applications from a terminal prompt to play
midi files AND in what’s called “daemon,” i.e., “server” mode - that is,
they are loaded into system memory and stay loaded so that applications
like Frescobaldi can “find” them and use them. They both thus have TWO
modes of use.

The email below explains this for fluidsynth. What follows does not mention
timidity, only fluidsynth and is not really relevant to Windows.

Long Story

Follows is a detailed email I once sent to a friend when he asked about
using midi with Lilypond on his Apple laptop. At the time I, too, used an
Apple Laptop. I now use a Linux installation on a Lenovo laptop, but the
command line usage for fluidsynth, etc. is the same even with newer
systems. When I used a WindowsOS computer, I used Coolsoft’s
VirtualMidiSynth and was quite happy with it.


====

Soundfonts and Fluidsynth

Three methods for using sound fonts:

I. Specify soundfont when running fluidsynth at the commandline

In this method, after installing both fluidsynth and a soundfont, one runs
fluidsynth from a Terminal using commandline syntax to specify fluidsynth
startup paramters, including sound font. In the following “#>“ is the
Terminal command line prompt. Run Terminal and type, followed by
RETURN/ENTER:


#> fluidsynth --help

You will see …

Usage:

  fluidsynth [options] [soundfonts] [midifiles]

Possible options:

[lots of options]

Note that one can run fluidsynth specifying options, the full path to a
soundfount (e.g., ~/Documents/Compositions/SoundFont/FluidR3.SF2) and the
full path to one or more midifiles, and fluidsynth will play (that is,
output as sound) the midi file(s) using the options and soundfont
specified. It is here, then, that one tells fluidsynth what sound font to
use!

One can also specify that fluidsynth start in Server (daemon) mode (option
-s) and the operating system will load it into memory where it will will
remain for use by an application capable of using it, e.g., Frescobaldi. If
running in server mode, one specifies with option -p the port name using
which an application can “find” fluidsynth for use (for example, in
Frescobaldi’s Midi preferences).

Options tell fluidsynth how to interpret midi files and how it outputs midi
to audio sounds. With respect to this guide, the important options are:

Possible options:

-a, --audio-driver=]label]
    The name of the audio driver to use.
    Valid values: coreaudio, file [these values are MacOS specific; if
using on a Linux system, one would use Linux-specific audio options]
-g, --gain
    Set the master gain [0 < gain < 10, default = 0.2]
-i, --no-shell
    Don't read commands from the shell [default = yes]
-m, --midi-driver=[label]
    The name of the midi driver to use.
    Valid values: coremidi [these values are MacOS specific; if using on a
Linux system, one would use Linux-specific midi driver options]

The next two go together, but only if running fluidsynth in server mode.
NOTE - running fluidsynth in server mode precludes adding midi files to the
command.

-p, --portname=[label]
    Set MIDI port name (alsa_seq, coremidi drivers)
-s, --server
    Start FluidSynth as a server process

Using these options and the Usage example above, this is what a fluidsynth
command looks like not running in server mode

#> fluidsynth -a coreaudio --no-shell -m coremidi ./SoundFont/FluidR3.SF2
./Bach-Prelude8EFlatMinor.mid

With a soundfount in that location and a midi file in that location with
that name, fluidsyth will play the midi file through the computer’s sound
system.

To use a different soundfont simply substitute it in the command.

NOTE: if fluidsynth is loaded as a server in this way, it is difficult to
change/add a sound font. See the next section.

II. From within the fluidsynth commandline Interactive Shell

Fluidsynth has an interactive shell. To see it, simply type, followed by
RETURN/ENTER:

#> fluidsynth

at a Terminal prompt and fluidsynth enters interactive mode. You’ll see
something like:

FluidSynth runtime version 1.1.11
Copyright (C) 2000-2018 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.

2019-04-28 20:46:27.735 fluidsynth [1360:53851] 20:46:27.734 WARNING:  140:
This application, or a library it uses, is using the deprecated Carbon
Component Manager for hosting Audio Units. Support for this will be removed
in a future release. Also, this makes the host incompatible with version 3
audio units. Please transition to the API's in AudioComponent.

Type 'help' for help topics.

>

That ‘>‘ character is the prompt. Type ‘help’ and press RETURN/ENTER to see
help topics.

Of note here are these commands:

- quit - Quit the synthesizer
- load file [reset] [bankofs] - Load SoundFont (reset=0|1, def 1;
bankofs=n, def 0)
- unload id [reset] - Unload SoundFont by ID (reset=0|1, default 1)
- reload id - Reload the SoundFont with the specified ID
- fonts - Display the list of loaded SoundFonts
- inst font - Print out the available instruments for the font
channels [-verbose]- Print out preset of all channels
- gain value - Set the master gain (0 < gain < 5)
- settings - Print out all settings
- set name value - Set the value of a controller or settings
- get name - Get the value of a controller or settings
- info name - Get information about a controller or settings

You can run fluidsynth in interactive mode, load and unload soundfounts,
and, most helpfully, get this interactive shell to show you the channels of
the soundfont and the instruments of the soundfont! This is invaluable (see
below). When fluidsynth is run this way, it is loaded in memory and
available for an application like Frescobaldi. The process ID (PID) that
fluidsynth is running as I type these notes is 1360:

Guys-MacBook% ps -ef | grep fluid
  501  >1360<  1226   0  8:46PM ttys003    0:16.76 fluidsynth

>From within Frescobaldi, in its Preferences, I refreshed midi ports, and I
see:

Fluidsynth virtual port (1360)

To load a soundfont in the interactive shell:

> load ~/Documents/Compositions/SoundFont/FluidR3.SF2
fluidsynth: warning: Found samples with invalid loops, audible glitches
possible.
loaded SoundFont has ID 1

You can load more than one (I think). To see loaded soundfonts:

> fonts
ID  Name
 1  /Users/gstalnaker/Documents/Compositions/SoundFont/FluidR3.SF2

You can see the instruments for a font by typing “inst 1“:

> inst 1

A LOT OF output here. A General Music (GM) soundfont may have 128
instruments, so the screen will scroll for a bit. But, many soundfonts do
NOT have all 128 instruments and thus there will be gaps. Were you to
select a midi instrument in LP and the soundfont didn’t map that instrument
to an instrument number in the loaded soundfont there will be no output for
that stave/voice.

When you play midi from within an application like Frescobaldi (which you
may have configured to use fluidsynth as I showed above), it will play the
score with the sound font loaded. Unload one font, and load another in the
fluidsynth interactive shell, and the next time you play a midi file in
Frescobaldi, fluidsynth will use the new sound font.

NOTE: Frescobaldi and LP do not care what soundfont is loaded. LP does not
specify soundfonts only instruments. Frescobaldi only cares that the
application/port you’re running (fluidsynth) will accept its midi stream.
It’s only if the application is loaded correctly and is property configured
for a soundfont that you’ll hear anything.

This is important - LP was written with a General Music soundfont in mind,
and internally it maps a standardized GM instrument name to a midi channel
number (0, 1, 2 … 127). When you select a midiInstrument in your score, LP
creates a midi file with not that midiInstrument name, but a midi
instrument channel number (I may be glossing the details here, but that’s
the gist of it). Frescobaldi knows this, and it provides helpful methods to
use these LP instrument names.

III. From within a UI that controls fluidsynth, e.g., QSynth <- MUCH
preferred

Using QSynth is much preferred as the UI helps to guide you on the process.
I have used QSynth on MacOS and Linux. QSynth will start fluidsynth in
daemon mode. You can use the QSynth Settings to select the soundfont and
the computer’s sound system (e.g., on an Apple system, that’s likely to be
‘coreaudio’ whereas on a Linux system1.  it would be something like ‘alsa’
or ‘pulseaudio’).

Steps to add soundfonts:

1. Run QSynth.
1. Click on Setup button at bottom left
1. Select the correct sound system (QSynth may default to Jack)
1. Click on the Soundfonts tab to see what fonts are loaded.
1. Click on the Open button on the right to add a font is one is not
already set
1. Can you USE more than one soundfont at a time? They are loaded with an
ID. In QSynth at the list of soundfonts on the Soundfonts tab, the far left
column is SFID and there are numbers.

I don’t think Frescobaldi can, nor Lilypond. They are not true midi
applications designed to make full use of an applicatio like fluidsynth. A
true midi synthesizer/controller (e.g., Rosegarden) probably can as one may
can specify the soundfont ID for some particular track or section of a
track. I’ve googled “lilypond soundfont” but found nothing useful.

IV. All of that said, I’ll circle back to midiInstrument naming - there is
a problem in using a non-GM soundfont — the instrument names!! And there
are a LOT of non-GM soundfonts you can download or buy.

Follows is taken from a post to the LP list:

The instruments or programs in FluidR3_GM.sf2 follow the General MIDI
specification, see

https://en.wikipedia.org/wiki/General_MIDI

[NOTE: the instrument names in Lilypond ALSO follow the General MIDI
instrument name specification!!]

In lilypond, \set Staff.midiInstrument only accepts instrument names, not
numbers. However, knowing the mapping [program number <-> instrument name]
in your non-GM soundfont and comparing it with the GM mapping you could try
“translating” directly in the lilypond score file from one instrument to
another.

I use FLuidR3_GM.sf2 almost exclusively because it’s remarkably good. But I
sometimes want some good organ sounds. The organ sounds in FluidR3_GM are
not so good. So, if I load an organ soundfont in QSynth how do I know
what’s what? The organ soundfont certainly won’t have Acoustic Grand Piano
for the instrument in its first channel.

Basically, as that post says, I create a mapping that shows the General
Instrument name (that Lilypond is hardcoded to use) and its program number,
then find that program number in the organ soundfont to discover what
sound(s) the organ soundfont plays when that program number is select in LP
(when InstrumentName=”” is used).

This means that the soundfont instrument names in Lilypond (
http://lilypond.org/doc/v2.19/Documentation/notation/midi-instruments)
cannot be altered, yet the program numbers they represent are true and they
can be used to specify instruments in other sound fonts. The biggest issue
I’ve found is getting that list of instruments in other soundfonts. That’s
where the fluidsynth interactive shell and it’s “inst \“ command comes in
handy. Run it, load the sound font you want to use, and use that command.
Save the output to a file and you can do the mapping.

I found that using a spreadsheet program (Google Sheets, for example) is
good for this. Numbers in column A to 128. Column B with the LP General
Midi instrument names (from that Lilypond link just above). The list of
instruments from the fluidsynth inst command. Then add them to Column C.
Now you can see what instrument in Column B in LP to use for the midi
instrument of the soundfont in Column C. It’s cumbersome, but it does work.

====

I know that is long, but sometimes it helps to have the details to
understand how things are supposed to work, especially if they seem to not
be working.

Regards.

--

“There is only love, and then oblivion. Love is all we have to set against
hatred.” (paraphrased) Ian McEwan

Reply via email to