2b9af71a91b0da13f26c7c1916388b43807b8b34
[ardour.git] / libs / ardour / ardour / fluid_synth.h
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 #ifndef _ardour_fluidsynth_h_
19 #define _ardour_fluidsynth_h_
20
21 #include <stdint.h>
22 #include <string.h>
23 #include <glib.h>
24
25 #include "ardour/libardour_visibility.h"
26 #include "ardour/types.h"
27
28 #include "fluidsynth.h"
29
30 namespace ARDOUR {
31
32         class LIBARDOUR_API FluidSynth {
33                 public:
34                         /** instantiate a Synth
35                          *
36                          * @param samplerate samplerate
37                          */
38                         FluidSynth (float samplerate, int polyphony = 32);
39                         ~FluidSynth ();
40
41                         bool load_sf2 (const std::string& fn);
42
43                         bool synth (float* left, float* right, uint32_t n_samples);
44                         bool midi_event (uint8_t const* const data, size_t len);
45                         void panic ();
46
47                         /* load a preset 
48                          * @pgm BankProgram index
49                          * @chan midi channel (0..15)
50                          * @return true on succcess
51                          */
52                         bool select_program (uint32_t pgm, uint8_t chan);
53
54                         uint32_t program_count () const { return _presets.size(); }
55
56                         std::string program_name (uint32_t pgm) const {
57                                 if (pgm >= _presets.size()) { return ""; }
58                                 return _presets[pgm].name;
59                         }
60
61                 private:
62                         fluid_settings_t*   _settings;
63                         fluid_synth_t*      _synth;
64                         int                 _synth_id;
65                         fluid_midi_event_t* _f_midi_event;
66
67                         struct BankProgram {
68                                 BankProgram (const std::string& n, int b, int p)
69                                         : name (n)
70                                         , bank (b)
71                                         , program (p)
72                                 {}
73
74                                 BankProgram (const BankProgram& other)
75                                         : name (other.name)
76                                         , bank (other.bank)
77                                         , program (other.program)
78                                 {}
79
80                                 std::string name;
81                                 int bank;
82                                 int program;
83                         };
84
85                         std::vector<BankProgram> _presets;
86         };
87
88 } /* namespace */
89 #endif