1/* FluidSynth - A Software Synthesizer
2 *
3 * Copyright (C) 2003  Peter Hanappe and others.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public License
7 * as published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 * 02111-1307, USA
19 */
20
21
22#ifndef _FLUID_SYNTH_H
23#define _FLUID_SYNTH_H
24
25
26/***************************************************************
27 *
28 *                         INCLUDES
29 */
30
31#if HAVE_CONFIG_H
32#include "config.h"
33#endif
34#include "fluidsynth_priv.h"
35#include "fluid_list.h"
36#include "fluid_rev.h"
37#include "fluid_voice.h"
38#include "fluid_chorus.h"
39#include "fluid_ladspa.h"
40#include "fluid_midi_router.h"
41#include "fluid_sys.h"
42
43/***************************************************************
44 *
45 *                         DEFINES
46 */
47#define FLUID_NUM_PROGRAMS      128
48#define DRUM_INST_BANK		128
49
50#if defined(WITH_FLOAT)
51#define FLUID_SAMPLE_FORMAT     FLUID_SAMPLE_FLOAT
52#else
53#define FLUID_SAMPLE_FORMAT     FLUID_SAMPLE_DOUBLE
54#endif
55
56
57/***************************************************************
58 *
59 *                         ENUM
60 */
61enum fluid_loop {
62  FLUID_UNLOOPED = 0,
63  FLUID_LOOP_DURING_RELEASE = 1,
64  FLUID_NOTUSED = 2,
65  FLUID_LOOP_UNTIL_RELEASE = 3
66};
67
68enum fluid_synth_status
69{
70  FLUID_SYNTH_CLEAN,
71  FLUID_SYNTH_PLAYING,
72  FLUID_SYNTH_QUIET,
73  FLUID_SYNTH_STOPPED
74};
75
76
77typedef struct _fluid_bank_offset_t fluid_bank_offset_t;
78
79struct _fluid_bank_offset_t {
80	int sfont_id;
81	int offset;
82};
83
84
85/*
86 * fluid_synth_t
87 */
88
89struct _fluid_synth_t
90{
91  /* fluid_settings_old_t settings_old;  the old synthesizer settings */
92  fluid_settings_t* settings;         /** the synthesizer settings */
93  int polyphony;                     /** maximum polyphony */
94  char with_reverb;                  /** Should the synth use the built-in reverb unit? */
95  char with_chorus;                  /** Should the synth use the built-in chorus unit? */
96  char verbose;                      /** Turn verbose mode on? */
97  char dump;                         /** Dump events to stdout to hook up a user interface? */
98  double sample_rate;                /** The sample rate */
99  int midi_channels;                 /** the number of MIDI channels (>= 16) */
100  int audio_channels;                /** the number of audio channels (1 channel=left+right) */
101  int audio_groups;                  /** the number of (stereo) 'sub'groups from the synth.
102					 Typically equal to audio_channels. */
103  int effects_channels;              /** the number of effects channels (= 2) */
104  unsigned int state;                /** the synthesizer state */
105  unsigned int ticks;                /** the number of audio samples since the start */
106  unsigned int start;                /** the start in msec, as returned by system clock */
107
108  fluid_list_t *loaders;              /** the soundfont loaders */
109  fluid_list_t* sfont;                /** the loaded soundfont */
110  unsigned int sfont_id;
111  fluid_list_t* bank_offsets;       /** the offsets of the soundfont banks */
112
113#if defined(MACOS9)
114  fluid_list_t* unloading;            /** the soundfonts that need to be unloaded */
115#endif
116
117  double gain;                        /** master gain */
118  fluid_channel_t** channel;          /** the channels */
119  int num_channels;                   /** the number of channels */
120  int nvoice;                         /** the length of the synthesis process array */
121  fluid_voice_t** voice;              /** the synthesis processes */
122  unsigned int noteid;                /** the id is incremented for every new note. it's used for noteoff's  */
123  unsigned int storeid;
124  int nbuf;                           /** How many audio buffers are used? (depends on nr of audio channels / groups)*/
125
126  fluid_real_t** left_buf;
127  fluid_real_t** right_buf;
128  fluid_real_t** fx_left_buf;
129  fluid_real_t** fx_right_buf;
130
131  fluid_revmodel_t* reverb;
132  fluid_chorus_t* chorus;
133  int cur;                           /** the current sample in the audio buffers to be output */
134  int dither_index;		/* current index in random dither value buffer: fluid_synth_(write_s16|dither_s16) */
135
136  char outbuf[256];                  /** buffer for message output */
137  double cpu_load;
138
139  fluid_tuning_t*** tuning;           /** 128 banks of 128 programs for the tunings */
140  fluid_tuning_t* cur_tuning;         /** current tuning in the iteration */
141
142  fluid_midi_router_t* midi_router;     /* The midi router. Could be done nicer. */
143  fluid_mutex_t busy;                   /* Indicates, whether the audio thread is currently running.
144					 * Note: This simple scheme does -not- provide 100 % protection against
145					 * thread problems, for example from MIDI thread and shell thread
146					 */
147#ifdef LADSPA
148  fluid_LADSPA_FxUnit_t* LADSPA_FxUnit; /** Effects unit for LADSPA support */
149#endif
150};
151
152/** returns 1 if the value has been set, 0 otherwise */
153int fluid_synth_setstr(fluid_synth_t* synth, char* name, char* str);
154
155/** returns 1 if the value exists, 0 otherwise */
156int fluid_synth_getstr(fluid_synth_t* synth, char* name, char** str);
157
158/** returns 1 if the value has been set, 0 otherwise */
159int fluid_synth_setnum(fluid_synth_t* synth, char* name, double val);
160
161/** returns 1 if the value exists, 0 otherwise */
162int fluid_synth_getnum(fluid_synth_t* synth, char* name, double* val);
163
164/** returns 1 if the value has been set, 0 otherwise */
165int fluid_synth_setint(fluid_synth_t* synth, char* name, int val);
166
167/** returns 1 if the value exists, 0 otherwise */
168int fluid_synth_getint(fluid_synth_t* synth, char* name, int* val);
169
170
171int fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num);
172
173int fluid_synth_one_block(fluid_synth_t* synth, int do_not_mix_fx_to_out);
174
175fluid_preset_t* fluid_synth_get_preset(fluid_synth_t* synth,
176				     unsigned int sfontnum,
177				     unsigned int banknum,
178				     unsigned int prognum);
179
180fluid_preset_t* fluid_synth_find_preset(fluid_synth_t* synth,
181				      unsigned int banknum,
182				      unsigned int prognum);
183
184int fluid_synth_all_notes_off(fluid_synth_t* synth, int chan);
185int fluid_synth_all_sounds_off(fluid_synth_t* synth, int chan);
186int fluid_synth_modulate_voices(fluid_synth_t* synth, int chan, int is_cc, int ctrl);
187int fluid_synth_modulate_voices_all(fluid_synth_t* synth, int chan);
188int fluid_synth_damp_voices(fluid_synth_t* synth, int chan);
189int fluid_synth_kill_voice(fluid_synth_t* synth, fluid_voice_t * voice);
190void fluid_synth_kill_by_exclusive_class(fluid_synth_t* synth, fluid_voice_t* voice);
191void fluid_synth_release_voice_on_same_note(fluid_synth_t* synth, int chan, int key);
192void fluid_synth_sfunload_macos9(fluid_synth_t* synth);
193
194void fluid_synth_print_voice(fluid_synth_t* synth);
195
196/** This function assures that every MIDI channels has a valid preset
197 *  (NULL is okay). This function is called after a SoundFont is
198 *  unloaded or reloaded. */
199void fluid_synth_update_presets(fluid_synth_t* synth);
200
201
202int fluid_synth_update_gain(fluid_synth_t* synth, char* name, double value);
203int fluid_synth_update_polyphony(fluid_synth_t* synth, char* name, int value);
204
205fluid_bank_offset_t* fluid_synth_get_bank_offset0(fluid_synth_t* synth, int sfont_id);
206void fluid_synth_remove_bank_offset(fluid_synth_t* synth, int sfont_id);
207
208void fluid_synth_dither_s16(int *dither_index, int len, float* lin, float* rin,
209			    void* lout, int loff, int lincr,
210			    void* rout, int roff, int rincr);
211/*
212 * misc
213 */
214
215void fluid_synth_settings(fluid_settings_t* settings);
216
217#endif  /* _FLUID_SYNTH_H */
218