-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGridSynth.cpp
92 lines (81 loc) · 3.54 KB
/
GridSynth.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// ======================================================================
// WinGridStrument - a Windows touchscreen musical instrument
// Copyright(C) 2020 Roger Allen
//
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// ======================================================================
#include "GridSynth.h"
#include "GridUtils.h"
// ======================================================================
void checkAlertExit(int rc, std::wstring errStr) {
if (rc == FLUID_FAILED) {
std::wostringstream text;
text << "fluid fail (" << rc << "): " << errStr;
AlertExit(NULL, text.str().c_str());
}
}
// ======================================================================
GridSynth::GridSynth()
{
settings_ = new_fluid_settings();
synth_ = new_fluid_synth(settings_);
int rc = fluid_settings_setstr(settings_, "audio.driver", "dsound");
checkAlertExit(rc, L"fluid_settings_setstr-dsound");
adriver_ = new_fluid_audio_driver(settings_, synth_);
soundfont_id_ = -1;
}
// ======================================================================
GridSynth::~GridSynth()
{
delete_fluid_synth(synth_);
delete_fluid_settings(settings_);
delete_fluid_audio_driver(adriver_);
}
// ======================================================================
// HOWTO FIXME? On windows the path is wchar. We convert it
// to a string before calling this routine, but this might not be right
// for international users.
void GridSynth::loadSoundfont(std::string soundfont_path_)
{
// "/Users/rallen/Documents/Devel/Cpp/WinGridStrument/SoundFonts/VintageDreamsWaves-v2.sf2"
// "/Users/rallen/Documents/Devel/Cpp/WinGridStrument/SoundFonts/fenderjazz.sf2"
// "/Users/rallen/Documents/Devel/Cpp/WinGridStrument/SoundFonts/60s_Rock_Guitar.sf2"
// "/Users/rallen/Documents/Devel/Cpp/WinGridStrument/SoundFonts/Electric_guitar.sf2"
soundfont_id_ = fluid_synth_sfload(synth_, soundfont_path_.c_str(), TRUE);
// FLUID_FAILED is -1, so we will not play if the id is < 0
}
// ======================================================================
void GridSynth::noteOn(int channel, int note, int midi_pressure)
{
if (soundfont_id_ < 0) return;
fluid_synth_noteon(synth_, channel, note, midi_pressure);
}
// ======================================================================
void GridSynth::pitchBend(int channel, int mod_pitch)
{
if (soundfont_id_ < 0) return;
fluid_synth_pitch_bend(synth_, channel, mod_pitch);
}
// ======================================================================
void GridSynth::controlChange(int channel, int controller, int mod_modulation)
{
if (soundfont_id_ < 0) return;
fluid_synth_cc(synth_, channel, controller, mod_modulation);
}
// ======================================================================
void GridSynth::polyKeyPressure(int channel, int key, int pressure)
{
if (soundfont_id_ < 0) return;
fluid_synth_key_pressure(synth_, channel, key, pressure);
}