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 #include "fluid_config.h"
32 #include "fluidsynth_priv.h"
33 #include "fluid_list.h"
34 #include "fluid_rev.h"
35 #include "fluid_voice.h"
36 #include "fluid_chorus.h"
37 #include "fluid_sys.h"
38 
39 /***************************************************************
40  *
41  *                         DEFINES
42  */
43 #define FLUID_NUM_PROGRAMS      128
44 #define DRUM_INST_BANK		128
45 
46 #if defined(WITH_FLOAT)
47 #define FLUID_SAMPLE_FORMAT     FLUID_SAMPLE_FLOAT
48 #else
49 #define FLUID_SAMPLE_FORMAT     FLUID_SAMPLE_DOUBLE
50 #endif
51 
52 
53 /***************************************************************
54  *
55  *                         ENUM
56  */
57 enum fluid_loop {
58   FLUID_UNLOOPED = 0,
59   FLUID_LOOP_DURING_RELEASE = 1,
60   FLUID_NOTUSED = 2,
61   FLUID_LOOP_UNTIL_RELEASE = 3
62 };
63 
64 enum fluid_synth_status
65 {
66   FLUID_SYNTH_CLEAN,
67   FLUID_SYNTH_PLAYING,
68   FLUID_SYNTH_QUIET,
69   FLUID_SYNTH_STOPPED
70 };
71 
72 
73 typedef struct _fluid_bank_offset_t fluid_bank_offset_t;
74 
75 struct _fluid_bank_offset_t {
76 	int sfont_id;
77 	int offset;
78 };
79 
80 
81 /*
82  * fluid_synth_t
83  */
84 
85 struct _fluid_synth_t
86 {
87   /* fluid_settings_old_t settings_old;  the old synthesizer settings */
88   fluid_settings_t* settings;         /** the synthesizer settings */
89   int polyphony;                     /** maximum polyphony */
90   char with_reverb;                  /** Should the synth use the built-in reverb unit? */
91   char with_chorus;                  /** Should the synth use the built-in chorus unit? */
92   char verbose;                      /** Turn verbose mode on? */
93   char dump;                         /** Dump events to stdout to hook up a user interface? */
94   double sample_rate;                /** The sample rate */
95   int midi_channels;                 /** the number of MIDI channels (>= 16) */
96   int audio_channels;                /** the number of audio channels (1 channel=left+right) */
97   int audio_groups;                  /** the number of (stereo) 'sub'groups from the synth.
98 					 Typically equal to audio_channels. */
99   int effects_channels;              /** the number of effects channels (= 2) */
100   unsigned int state;                /** the synthesizer state */
101   unsigned int ticks;                /** the number of audio samples since the start */
102 
103   fluid_list_t *loaders;              /** the soundfont loaders */
104   fluid_list_t* sfont;                /** the loaded soundfont */
105   unsigned int sfont_id;
106   fluid_list_t* bank_offsets;       /** the offsets of the soundfont banks */
107 
108 #if defined(MACOS9)
109   fluid_list_t* unloading;            /** the soundfonts that need to be unloaded */
110 #endif
111 
112   double gain;                        /** master gain */
113   fluid_channel_t** channel;          /** the channels */
114   int num_channels;                   /** the number of channels */
115   int nvoice;                         /** the length of the synthesis process array */
116   fluid_voice_t** voice;              /** the synthesis processes */
117   unsigned int noteid;                /** the id is incremented for every new note. it's used for noteoff's  */
118   unsigned int storeid;
119   int nbuf;                           /** How many audio buffers are used? (depends on nr of audio channels / groups)*/
120 
121   fluid_real_t** left_buf;
122   fluid_real_t** right_buf;
123   fluid_real_t** fx_left_buf;
124   fluid_real_t** fx_right_buf;
125 
126   fluid_revmodel_t* reverb;
127   fluid_chorus_t* chorus;
128   int cur;                           /** the current sample in the audio buffers to be output */
129   int dither_index;		/* current index in random dither value buffer: fluid_synth_(write_s16|dither_s16) */
130 
131   char outbuf[256];                  /** buffer for message output */
132 
133   fluid_tuning_t*** tuning;           /** 128 banks of 128 programs for the tunings */
134   fluid_tuning_t* cur_tuning;         /** current tuning in the iteration */
135 
136   //midi router and mutex disabled
137 };
138 
139 /** returns 1 if the value has been set, 0 otherwise */
140 int fluid_synth_setstr(fluid_synth_t* synth, char* name, char* str);
141 
142 /** returns 1 if the value exists, 0 otherwise */
143 int fluid_synth_getstr(fluid_synth_t* synth, char* name, char** str);
144 
145 /** returns 1 if the value has been set, 0 otherwise */
146 int fluid_synth_setnum(fluid_synth_t* synth, char* name, double val);
147 
148 /** returns 1 if the value exists, 0 otherwise */
149 int fluid_synth_getnum(fluid_synth_t* synth, char* name, double* val);
150 
151 /** returns 1 if the value has been set, 0 otherwise */
152 int fluid_synth_setint(fluid_synth_t* synth, char* name, int val);
153 
154 /** returns 1 if the value exists, 0 otherwise */
155 int fluid_synth_getint(fluid_synth_t* synth, char* name, int* val);
156 
157 
158 int fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num);
159 
160 int fluid_synth_one_block(fluid_synth_t* synth, int do_not_mix_fx_to_out);
161 
162 fluid_preset_t* fluid_synth_get_preset(fluid_synth_t* synth,
163 				     unsigned int sfontnum,
164 				     unsigned int banknum,
165 				     unsigned int prognum);
166 
167 fluid_preset_t* fluid_synth_find_preset(fluid_synth_t* synth,
168 				      unsigned int banknum,
169 				      unsigned int prognum);
170 
171 int fluid_synth_all_notes_off(fluid_synth_t* synth, int chan);
172 int fluid_synth_all_sounds_off(fluid_synth_t* synth, int chan);
173 int fluid_synth_modulate_voices(fluid_synth_t* synth, int chan, int is_cc, int ctrl);
174 int fluid_synth_modulate_voices_all(fluid_synth_t* synth, int chan);
175 int fluid_synth_damp_voices(fluid_synth_t* synth, int chan);
176 int fluid_synth_kill_voice(fluid_synth_t* synth, fluid_voice_t * voice);
177 void fluid_synth_kill_by_exclusive_class(fluid_synth_t* synth, fluid_voice_t* voice);
178 void fluid_synth_release_voice_on_same_note(fluid_synth_t* synth, int chan, int key);
179 void fluid_synth_sfunload_macos9(fluid_synth_t* synth);
180 
181 void fluid_synth_print_voice(fluid_synth_t* synth);
182 
183 /** This function assures that every MIDI channels has a valid preset
184  *  (NULL is okay). This function is called after a SoundFont is
185  *  unloaded or reloaded. */
186 void fluid_synth_update_presets(fluid_synth_t* synth);
187 
188 
189 int fluid_synth_update_gain(fluid_synth_t* synth, char* name, double value);
190 int fluid_synth_update_polyphony(fluid_synth_t* synth, char* name, int value);
191 
192 fluid_bank_offset_t* fluid_synth_get_bank_offset0(fluid_synth_t* synth, int sfont_id);
193 void fluid_synth_remove_bank_offset(fluid_synth_t* synth, int sfont_id);
194 
195 void fluid_synth_dither_s16(int *dither_index, int len, float* lin, float* rin,
196 			    void* lout, int loff, int lincr,
197 			    void* rout, int roff, int rincr);
198 /*
199  * misc
200  */
201 
202 void fluid_synth_settings(fluid_settings_t* settings);
203 
204 #endif  /* _FLUID_SYNTH_H */
205