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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/* FluidSynth - A Software Synthesizer
*
* Copyright (C) 2003 Peter Hanappe and others.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307, USA
*/
#include "fluid.h"
#include "sfont.h"
#include "gen.h"
namespace FluidS {
//---------------------------------------------------------
// Channel
//---------------------------------------------------------
Channel::Channel(Fluid* s, int num)
{
synth = s;
channum = num;
_preset = 0;
banknum = 0;
prognum = 0;
reset();
}
//---------------------------------------------------------
// reset
//---------------------------------------------------------
void Channel::reset()
{
init();
initCtrl();
}
//---------------------------------------------------------
// init
//---------------------------------------------------------
void Channel::init()
{
sfontnum = 0;
setPreset(synth->find_preset(banknum, prognum));
interp_method = FLUID_INTERP_DEFAULT;
nrpn_select = 0;
}
//---------------------------------------------------------
// initCtrl
//---------------------------------------------------------
void Channel::initCtrl()
{
key_pressure = 0;
channel_pressure = 0;
pitch_bend = 0x2000; // Range is 0x4000, pitch bend wheel starts in centered position
pitch_wheel_sensitivity = 12; /* twelve semi-tones */
bank_msb = 0;
for (int i = 0; i < GEN_LAST; i++) {
gen[i] = 0.0f;
gen_abs[i] = 0;
}
for (int i = 0; i < 128; i++)
setCC(i, 0);
/* Volume / initial attenuation (MSB & LSB) */
setCC(VOLUME_MSB, 127);
setCC(VOLUME_LSB, 0);
/* Pan (MSB & LSB) */
setCC(PAN_MSB, 64);
setCC(PAN_LSB, 64);
/* Expression (MSB & LSB) */
setCC(EXPRESSION_MSB, 127);
setCC(EXPRESSION_LSB, 127);
}
//---------------------------------------------------------
// setcc
//---------------------------------------------------------
void Channel::setcc(int num, int value)
{
cc[num] = value;
// printf("setcc %d %d\n", num, value);
switch (num) {
case SUSTAIN_SWITCH:
if (value < 64)
synth->damp_voices(channum);
break;
case BANK_SELECT_MSB:
{
bank_msb = value & 0x7f;
setBanknum(bank_msb << 7);
}
break;
case BANK_SELECT_LSB:
/* FIXME: according to the Downloadable Sounds II specification,
bit 31 should be set when we receive the message on channel
10 (drum channel) */
setBanknum((value & 0x7f) + (bank_msb << 7));
break;
case ALL_NOTES_OFF:
synth->allNotesOff(channum);
break;
case ALL_SOUND_OFF:
synth->allSoundsOff(channum);
break;
case ALL_CTRL_OFF:
initCtrl();
synth->modulate_voices_all(channum);
break;
case DATA_ENTRY_MSB:
{
int data = (value << 7) + cc[DATA_ENTRY_LSB];
/* SontFont 2.01 NRPN Message (Sect. 9.6, p. 74) */
if ((cc[NRPN_MSB] == 120) && (cc[NRPN_LSB] < 100)) {
float val = fluid_gen_scale_nrpn(nrpn_select, data);
qDebug("%s: %d: Data = %d, value = %f", __FILE__, __LINE__, data, val);
synth->set_gen(channum, nrpn_select, val);
}
break;
}
case NRPN_MSB:
cc[NRPN_LSB] = 0;
nrpn_select = 0;
break;
case NRPN_LSB:
/* SontFont 2.01 NRPN Message (Sect. 9.6, p. 74) */
if (cc[NRPN_MSB] == 120) {
if (value == 100)
nrpn_select += 100;
else if (value == 101)
nrpn_select += 1000;
else if (value == 102)
nrpn_select += 10000;
else if (value < 100) {
nrpn_select += value;
qDebug("%s: %d: NRPN Select = %d", __FILE__, __LINE__, nrpn_select);
}
}
break;
case RPN_MSB:
break;
case RPN_LSB:
/* erase any previously received NRPN message */
cc[NRPN_MSB] = 0;
cc[NRPN_LSB] = 0;
nrpn_select = 0;
break;
default:
synth->modulate_voices(channum, true, num);
}
}
//---------------------------------------------------------
// getCC
//---------------------------------------------------------
int Channel::getCC(int num)
{
return ((num >= 0) && (num < 128))? cc[num] : 0;
}
//---------------------------------------------------------
// pitchBend
//---------------------------------------------------------
void Channel::pitchBend(int val)
{
pitch_bend = val;
synth->modulate_voices(channum, false, FLUID_MOD_PITCHWHEEL);
}
//---------------------------------------------------------
// pitchWheelSens
//---------------------------------------------------------
void Channel::pitchWheelSens(int val)
{
pitch_wheel_sensitivity = val;
synth->modulate_voices(channum, false, FLUID_MOD_PITCHWHEELSENS);
}
//---------------------------------------------------------
// setPreset
//---------------------------------------------------------
void Channel::setPreset(Preset* p)
{
if (_preset != p) {
if (p)
p->loadSamples();
_preset = p;
}
}
}
|