File: gen.cpp

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-16
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 214,188 kB
  • sloc: cpp: 291,198; xml: 200,238; sh: 3,779; ansic: 1,447; python: 393; makefile: 244; perl: 82; pascal: 79
file content (138 lines) | stat: -rw-r--r-- 7,356 bytes parent folder | download | duplicates (12)
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
/* 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 "gen.h"
#include "fluid.h"

namespace FluidS {

/* See SFSpec21 $8.1.3 */
GenInfo fluid_gen_info[] = {
      /* number/name             init  scale         min        max         def */
      { GEN_STARTADDROFS,           1,     1,       0.0f,     1e10f,       0.0f },
      { GEN_ENDADDROFS,             1,     1,     -1e10f,      0.0f,       0.0f },
      { GEN_STARTLOOPADDROFS,       1,     1,     -1e10f,     1e10f,       0.0f },
      { GEN_ENDLOOPADDROFS,         1,     1,     -1e10f,     1e10f,       0.0f },
      { GEN_STARTADDRCOARSEOFS,     0,     1,       0.0f,     1e10f,       0.0f },
      { GEN_MODLFOTOPITCH,          1,     2,  -12000.0f,  12000.0f,       0.0f },
      { GEN_VIBLFOTOPITCH,          1,     2,  -12000.0f,  12000.0f,       0.0f },
      { GEN_MODENVTOPITCH,          1,     2,  -12000.0f,  12000.0f,       0.0f },
      { GEN_FILTERFC,               1,     2,    1500.0f,  13500.0f,   13500.0f },
      { GEN_FILTERQ,                1,     1,       0.0f,    960.0f,       0.0f },
      { GEN_MODLFOTOFILTERFC,       1,     2,  -12000.0f,  12000.0f,       0.0f },
      { GEN_MODENVTOFILTERFC,       1,     2,  -12000.0f,  12000.0f,       0.0f },
      { GEN_ENDADDRCOARSEOFS,       0,     1,     -1e10f,      0.0f,       0.0f },
      { GEN_MODLFOTOVOL,            1,     1,    -960.0f,    960.0f,       0.0f },
      { GEN_UNUSED1,                0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_CHORUSSEND,             1,     1,       0.0f,   1000.0f,       0.0f },
      { GEN_REVERBSEND,             1,     1,       0.0f,   1000.0f,       0.0f },
      { GEN_PAN,                    1,     1,    -500.0f,    500.0f,       0.0f },
      { GEN_UNUSED2,                0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_UNUSED3,                0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_UNUSED4,                0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_MODLFODELAY,            1,     2,  -12000.0f,   5000.0f,  -12000.0f },
      { GEN_MODLFOFREQ,             1,     4,  -16000.0f,   4500.0f,       0.0f },
      { GEN_VIBLFODELAY,            1,     2,  -12000.0f,   5000.0f,  -12000.0f },
      { GEN_VIBLFOFREQ,             1,     4,  -16000.0f,   4500.0f,       0.0f },
      { GEN_MODENVDELAY,            1,     2,  -12000.0f,   5000.0f,  -12000.0f },
      { GEN_MODENVATTACK,           1,     2,  -12000.0f,   8000.0f,  -12000.0f },
      { GEN_MODENVHOLD,             1,     2,  -12000.0f,   5000.0f,  -12000.0f },
      { GEN_MODENVDECAY,            1,     2,  -12000.0f,   8000.0f,  -12000.0f },
      { GEN_MODENVSUSTAIN,          0,     1,       0.0f,   1000.0f,       0.0f },
      { GEN_MODENVRELEASE,          1,     2,  -12000.0f,   8000.0f,  -12000.0f },
      { GEN_KEYTOMODENVHOLD,        0,     1,   -1200.0f,   1200.0f,       0.0f },
      { GEN_KEYTOMODENVDECAY,       0,     1,   -1200.0f,   1200.0f,       0.0f },
      { GEN_VOLENVDELAY,            1,     2,  -12000.0f,   5000.0f,  -12000.0f },
      { GEN_VOLENVATTACK,           1,     2,  -12000.0f,   8000.0f,  -12000.0f },
      { GEN_VOLENVHOLD,             1,     2,  -12000.0f,   5000.0f,  -12000.0f },
      { GEN_VOLENVDECAY,            1,     2,  -12000.0f,   8000.0f,  -12000.0f },
      { GEN_VOLENVSUSTAIN,          0,     1,       0.0f,   1440.0f,       0.0f },
      { GEN_VOLENVRELEASE,          1,     2,  -12000.0f,   8000.0f,  -12000.0f },
      { GEN_KEYTOVOLENVHOLD,        0,     1,   -1200.0f,   1200.0f,       0.0f },
      { GEN_KEYTOVOLENVDECAY,       0,     1,   -1200.0f,   1200.0f,       0.0f },
      { GEN_INSTRUMENT,             0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_RESERVED1,              0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_KEYRANGE,               0,     0,       0.0f,    127.0f,       0.0f },
      { GEN_VELRANGE,               0,     0,       0.0f,    127.0f,       0.0f },
      { GEN_STARTLOOPADDRCOARSEOFS, 0,     1,     -1e10f,     1e10f,       0.0f },
      { GEN_KEYNUM,                 1,     0,       0.0f,    127.0f,      -1.0f },
      { GEN_VELOCITY,               1,     1,       0.0f,    127.0f,      -1.0f },
      { GEN_ATTENUATION,            1,     1,       0.0f,   1440.0f,       0.0f },
      { GEN_RESERVED2,              0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_ENDLOOPADDRCOARSEOFS,   0,     1,     -1e10f,     1e10f,       0.0f },
      { GEN_COARSETUNE,             0,     1,    -120.0f,    120.0f,       0.0f },
      { GEN_FINETUNE,               0,     1,     -99.0f,     99.0f,       0.0f },
      { GEN_SAMPLEID,               0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_SAMPLEMODE,             0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_RESERVED3,              0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_SCALETUNE,              0,     1,       0.0f,   1200.0f,     100.0f },
      { GEN_EXCLUSIVECLASS,         0,     0,       0.0f,      0.0f,       0.0f },
      { GEN_OVERRIDEROOTKEY,        1,     0,       0.0f,    127.0f,      -1.0f },
      { GEN_PITCH,                  1,     0,       0.0f,    127.0f,       0.0f }
};


/**
 * Set an array of generators to their default values.
 * @param gen Array of generators (should be #GEN_LAST in size).
 * @return Always returns 0
 */
void fluid_gen_set_default_values(Generator* gen)
      {
      for (int i = 0; i < GEN_LAST; i++) {
            gen[i].flags = GEN_UNUSED;
            gen[i].mod = 0.0;
            gen[i].nrpn = 0.0;
            gen[i].val = fluid_gen_info[i].def;
            }
      }


/* fluid_gen_init
 *
 * Set an array of generators to their initial value
 */
void fluid_gen_init(Generator* gen, Channel* channel)
      {
      fluid_gen_set_default_values(gen);

      for (int i = 0; i < GEN_LAST; i++) {
            gen[i].nrpn = channel->getGen(i);

            /* This is an extension to the SoundFont standard. More
             * documentation is available at the fluid_synth_set_gen2()
             * function. */
            if (channel->getGenAbs(i))
                  gen[i].flags = GEN_ABS_NRPN;
            }
      }

float fluid_gen_scale(int gen, float value)
      {
      return (fluid_gen_info[gen].min
              + value * (fluid_gen_info[gen].max - fluid_gen_info[gen].min));
      }

float fluid_gen_scale_nrpn(int gen, int data)
      {
      float value = qBound(-8192.0, (float) data - 8192.0, 8192.0);
      return value * (float) fluid_gen_info[gen].nrpn_scale;
      }
}