~ubuntu-branches/ubuntu/breezy/muse/breezy

« back to all changes in this revision

Viewing changes to synti/stklib/VoicMang.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************/
2
 
/*  Simple Voice Manager (Mangler)        */
3
 
/*  for ToolKit96, 1996 Perry R. Cook     */
4
 
/*  Princeton University                  */
5
 
/*                                        */
6
 
/*  Make one of these by telling it the   */
7
 
/*  maximum number of voices you'll want, */
8
 
/*  and also what flavor instrument       */
9
 
/*  group it will be mangling.  Pipe SKINI*/
10
 
/*  messages into it and it will return   */
11
 
/*  the mixed channel signal each tick.   */
12
 
/*  For multi-channel (multi-timbral),    */
13
 
/*  make one for each channel and mix     */
14
 
/*  their outputs.                        */
15
 
/*                                        */
16
 
/*  Each note on returns a unique tag,    */
17
 
/*  (credits to the NeXT MusicKit here),  */
18
 
/*  so you can send control changes to    */
19
 
/*  unique instances of instruments       */
20
 
/*  within an ensemble.                   */
21
 
/*                                        */
22
 
/*  SKINI (Synthesis toolKit Instrument   */
23
 
/*  Network Interface) is like MIDI, but  */
24
 
/*  allows for floating point control     */
25
 
/*  changes, note numbers, etc. Example:  */
26
 
/*  noteOn 60.01 111.132 plays a sharp    */      
27
 
/*  middle C with a velocity of 111.132   */
28
 
/*  See SKINI09.txt for more information  */
29
 
/*                                        */
30
 
/******************************************/
31
 
 
32
 
#include "VoicMang.h"
33
 
#include "Mandolin.h"
34
 
#include "Plucked.h"
35
 
#include "Clarinet.h"
36
 
#include "Flute.h"
37
 
#include "Brass.h"
38
 
#include "Bowed.h"
39
 
#include "Rhodey.h"
40
 
#include "Wurley.h"
41
 
#include "TubeBell.h"
42
 
#include "HeavyMtl.h"
43
 
#include "PercFlut.h"
44
 
#include "BeeThree.h"
45
 
#include "Moog1.h"
46
 
 
47
 
VoicMang :: VoicMang(int maxVoices, char *instrType)
48
 
{
49
 
    int i;
50
 
    max_voices = maxVoices;
51
 
    if (max_voices > __VMang_MAX_) {
52
 
        printf("You ask for too many voices, setting to %i\n",__VMang_MAX_);
53
 
        max_voices = __VMang_MAX_;
54
 
    }
55
 
    if (!strcmp(instrType,"Mandolin"))     {
56
 
        for (i=0;i<max_voices;i++)
57
 
            instrument[i] = new Mandolin((MY_FLOAT) 50.0);
58
 
                mute_time = 1000;
59
 
    }
60
 
    else if (!strcmp(instrType,"Plucked"))      {
61
 
        for (i=0;i<max_voices;i++)
62
 
            instrument[i] = new Plucked(50.0);
63
 
        mute_time = 1000;
64
 
    }
65
 
    else if (!strcmp(instrType,"Clarinet"))     {
66
 
        for (i=0;i<max_voices;i++)
67
 
            instrument[i] = new Clarinet(50.0);
68
 
        mute_time = 1000;
69
 
    }
70
 
    else if (!strcmp(instrType,"Flute"))        {
71
 
        for (i=0;i<max_voices;i++)
72
 
            instrument[i] = new Flute(50.0);
73
 
        mute_time = 1000;
74
 
    }
75
 
    else if (!strcmp(instrType,"Brass"))        {
76
 
        for (i=0;i<max_voices;i++)
77
 
            instrument[i] = new Brass(50.0);
78
 
        mute_time = 1000;
79
 
    }
80
 
    else if (!strcmp(instrType,"Bowed"))        {
81
 
        for (i=0;i<max_voices;i++)
82
 
            instrument[i] = new Bowed(50.0);
83
 
        mute_time = 1000;
84
 
    }
85
 
    else if (!strcmp(instrType,"Rhodey"))       {
86
 
        for (i=0;i<max_voices;i++)
87
 
            instrument[i] = new Rhodey;
88
 
        mute_time = 1000;
89
 
    }
90
 
    else if (!strcmp(instrType,"Wurley"))       {
91
 
        for (i=0;i<max_voices;i++)
92
 
            instrument[i] = new Wurley;
93
 
        mute_time = 1000;
94
 
    }
95
 
    else if (!strcmp(instrType,"TubeBell"))     {
96
 
        for (i=0;i<max_voices;i++)
97
 
            instrument[i] = new TubeBell;
98
 
        mute_time = 1000;
99
 
    }
100
 
    else if (!strcmp(instrType,"HeavyMtl"))     {
101
 
        for (i=0;i<max_voices;i++)
102
 
            instrument[i] = new HeavyMtl;
103
 
        mute_time = 1000;
104
 
    }
105
 
    else if (!strcmp(instrType,"PercFlut"))     {
106
 
        for (i=0;i<max_voices;i++)
107
 
            instrument[i] = new PercFlut;
108
 
        mute_time = 1000;
109
 
    }
110
 
    else if (!strcmp(instrType,"BeeThree"))     {
111
 
        for (i=0;i<max_voices;i++)
112
 
            instrument[i] = new BeeThree;
113
 
        mute_time = 1000;
114
 
    }
115
 
    else if (!strcmp(instrType,"Moog1"))        {
116
 
        for (i=0;i<max_voices;i++)
117
 
            instrument[i] = new Moog1;
118
 
        mute_time = 1000;
119
 
    }
120
 
    
121
 
    pitch_bend = (MY_FLOAT) 1.0;
122
 
    newTag = 1;
123
 
    for (i=0;i<max_voices;i++)  {
124
 
        notesOn[i] = -1;
125
 
        voicesOn[i] = 0;
126
 
        freqBases[i] = (MY_FLOAT) 1.0;
127
 
        frequencies[i] = (MY_FLOAT) 0.0;
128
 
    }    
129
 
}
130
 
 
131
 
VoicMang :: ~VoicMang()
132
 
{
133
 
    int i;
134
 
    for (i=0;i<max_voices;i++)
135
 
            delete instrument[i];
136
 
}
137
 
 
138
 
long VoicMang :: noteOn(MY_FLOAT freq, MY_FLOAT amp)
139
 
{
140
 
    MY_FLOAT temp = 0.0;
141
 
    temp = freq / (MY_FLOAT) 220.0;
142
 
    temp = (MY_FLOAT) (log(temp) / log(2.0));
143
 
    temp = (temp * (MY_FLOAT) 12.0) + 57;
144
 
    return this->noteOn(temp,amp);
145
 
}
146
 
 
147
 
#define ONE_OVER_12 0.083333
148
 
 
149
 
long VoicMang :: noteOnN(MY_FLOAT note_num, MY_FLOAT amp)
150
 
{
151
 
    int i,gotOne;
152
 
    MY_FLOAT freq;
153
 
    freq = (MY_FLOAT) 220.0 * pow(2.0,(note_num - 57.0) * ONE_OVER_12);
154
 
    gotOne = 0;
155
 
    for (i=0;i<max_voices;i++) {
156
 
        if (notesOn[i] < 0)    {      /* find a dormant instrument */
157
 
            voicesOn[i] = newTag;
158
 
            newTag += 1;
159
 
            notesOn[i] = (int) (note_num + (MY_FLOAT) 0.5);  /* Nearest Neighbor MIDI Note# */
160
 
            instrument[i]->noteOn(freq,amp*(MY_FLOAT) NORM_7);
161
 
            frequencies[i] = freq;
162
 
            gotOne = 1;
163
 
            i = max_voices;
164
 
        }
165
 
    }
166
 
    if (!gotOne)        {              /* if can't find a free one */
167
 
        return -1;                     /* report back */
168
 
    }
169
 
    return newTag-1;
170
 
}
171
 
 
172
 
long VoicMang :: oldestVoice()
173
 
{
174
 
    int i;
175
 
    long temp2,gotOne;
176
 
    temp2 = newTag;
177
 
    gotOne = -1;
178
 
    for (i=0;i<max_voices;i++)  {
179
 
        temp2 = voicesOn[i];
180
 
        if (temp2 > 0 && temp2 < newTag)  {
181
 
            gotOne = temp2;
182
 
        }
183
 
    }
184
 
    return gotOne;
185
 
}
186
 
 
187
 
long VoicMang :: noteOffN(int note_num, MY_FLOAT amp)
188
 
{
189
 
    int i,gotOne;
190
 
    gotOne = -1;
191
 
    for (i=0;i<max_voices;i++)  {
192
 
            if (notesOn[i]==note_num)       {
193
 
                instrument[i]->noteOff(amp * (MY_FLOAT) NORM_7); 
194
 
                gotOne = voicesOn[i];
195
 
                voicesOn[i] = -mute_time - 2;
196
 
            }
197
 
    }
198
 
    return gotOne;
199
 
}
200
 
 
201
 
void VoicMang :: noteOffT(long tag, MY_FLOAT amp)
202
 
{
203
 
    int i;
204
 
    for (i=0;i<max_voices;i++)  {
205
 
        if (voicesOn[i]==tag)       {
206
 
            instrument[i]->noteOff(amp * (MY_FLOAT) NORM_7); 
207
 
            voicesOn[i] = -mute_time - 2;
208
 
        }
209
 
    }
210
 
}
211
 
 
212
 
void VoicMang :: kill(long tag)
213
 
{
214
 
    int i;
215
 
    for (i=0;i<max_voices;i++)  {
216
 
        if (voicesOn[i]==tag)       {
217
 
            instrument[i]->noteOff((MY_FLOAT) 1.0); 
218
 
            voicesOn[i] = 0;
219
 
            notesOn[i] = -1;
220
 
        }
221
 
    }
222
 
}
223
 
 
224
 
void VoicMang :: pitchBend(MY_FLOAT value)
225
 
{
226
 
    int i;
227
 
    pitch_bend = value;
228
 
    for (i=0;i<max_voices;i++)  {
229
 
        freqBases[i] = pitch_bend;
230
 
        instrument[i]->setFreq(freqBases[i]*frequencies[i]);
231
 
    }
232
 
}
233
 
 
234
 
void VoicMang :: pitchBendT(long tag, MY_FLOAT value)
235
 
{
236
 
    int i;
237
 
    for (i=0;i<max_voices;i++)  { 
238
 
        if (voicesOn[i] == tag)    {
239
 
            freqBases[i] = value;
240
 
            instrument[i]->setFreq(freqBases[i]*frequencies[i]);
241
 
            i = max_voices;
242
 
        }
243
 
    }
244
 
}
245
 
 
246
 
MY_FLOAT VoicMang :: tick()
247
 
{
248
 
    int i;
249
 
    MY_FLOAT temp;
250
 
    temp = (MY_FLOAT) 0.0;
251
 
    for (i=0;i<max_voices;i++)  {
252
 
        if (voicesOn[i] != 0)   {
253
 
            temp += instrument[i]->tick();
254
 
        }
255
 
        if (voicesOn[i] < 0) {
256
 
            voicesOn[i] += 1;
257
 
            if (voicesOn[i] == 0)       {
258
 
                notesOn[i] = -1;
259
 
                frequencies[i] = (MY_FLOAT) 0.0;
260
 
                freqBases[i] = (MY_FLOAT) 1.0;
261
 
            }
262
 
        }        
263
 
    }
264
 
    return temp;
265
 
}
266
 
 
267
 
void VoicMang :: controlChange(int number, MY_FLOAT value)
268
 
{
269
 
    int i;
270
 
    for (i=0;i<max_voices;i++)  {
271
 
        instrument[i]->controlChange(number,value);
272
 
    }
273
 
}
274
 
 
275
 
void VoicMang :: controlChangeT(long tag, int number, MY_FLOAT value)
276
 
{
277
 
    int i;
278
 
    for (i=0;i<max_voices;i++)  { 
279
 
        if (voicesOn[i] == tag)    {
280
 
            instrument[i]->controlChange(number,value);
281
 
            i = max_voices;
282
 
        }
283
 
    }
284
 
}
285
 
 
286