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

« back to all changes in this revision

Viewing changes to synti/stklib/mandplyr.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
 
/*  MandPlyr Player Expert Object to control*/
3
 
/*  commuted dual plucked-string model      */
4
 
/*  by Perry Cook, 1995-96                  */
5
 
/********************************************/  
6
 
 
7
 
#include "Instrmnt.h"
8
 
#include "Mandolin.h"
9
 
#include "mandplyr.h"
10
 
#include "VoicMang.h"
11
 
#include "Noise.h"
12
 
#include "SKINI11.msg"
13
 
 
14
 
MandPlyr :: MandPlyr() : Instrmnt()
15
 
{
16
 
    short i;
17
 
    strings = new VoicMang(NUM_STRINGS,"Mandolin");
18
 
    noise = new Noise;
19
 
    strumming = 0;
20
 
    strumRate = (long) (SRATE * 0.1);            // ( 1/(0.1) = 10Hz)
21
 
    strumCount = 0;
22
 
    skill = (MY_FLOAT) 0.90;
23
 
    for (i=0;i<NUM_STRINGS;i++) {
24
 
        nums[i] = 0;
25
 
        amps[i]  = (MY_FLOAT) 0;
26
 
        tags[i]  = -1;
27
 
    }
28
 
}
29
 
 
30
 
MandPlyr :: ~MandPlyr()
31
 
{
32
 
    delete strings;
33
 
    delete noise;
34
 
}
35
 
 
36
 
void MandPlyr :: noteOnN(short num, MY_FLOAT amp)
37
 
{
38
 
    long temp;
39
 
    short i,notDone;
40
 
    MY_FLOAT isErr,errDir;
41
 
    short error = 0;
42
 
    
43
 
    errDir = noise->tick();
44
 
    if (errDir < 0) 
45
 
        isErr = -errDir;
46
 
    else 
47
 
        isErr = errDir;
48
 
    if (isErr < (0.4 * (1.0 - skill)))  {   /* Should we err here? */
49
 
            error = 1;
50
 
            if (strumming < 1) {
51
 
                strumming = 2;
52
 
                strumCount = strumRate;
53
 
            }
54
 
            if (errDir < 0.0) error = -1;  /* random error +/- 1/2 step */
55
 
    }
56
 
    
57
 
    
58
 
    i = 0;
59
 
    notDone = 1;
60
 
    while (notDone && i<NUM_STRINGS) {
61
 
            if (tags[i] < 0) {
62
 
                nums[i] = num;
63
 
                amps[i] = amp;
64
 
                tags[i] = strings->noteOnN((MY_FLOAT) num + error,amp);
65
 
                notDone = 0;
66
 
                if (tags[i]<0)  {
67
 
                    printf("Must Reallocate a note\n");
68
 
                    notDone = 1;
69
 
                }
70
 
            }
71
 
            i++;
72
 
    }
73
 
    if (notDone)    {
74
 
            temp = strings->oldestVoice();
75
 
            i = 0;
76
 
            while (notDone && i<NUM_STRINGS) {
77
 
                if (tags[i] < 0) {
78
 
                        strings->kill(temp);
79
 
                        nums[i] = num;
80
 
                        amps[i] = amp;
81
 
                        tags[i] = strings->noteOnN((MY_FLOAT) num + error,amp);
82
 
                        notDone = 0;
83
 
                }
84
 
                i++;
85
 
            }
86
 
    }
87
 
    if (notDone) printf("Can't allocate a new note\n");
88
 
}
89
 
 
90
 
void MandPlyr :: noteOffN(short num,MY_FLOAT amp)
91
 
{
92
 
    long temp;
93
 
    short i;
94
 
    temp = strings->noteOffN(num,amp);
95
 
    if (temp>0) {                               // Usual Case
96
 
        for (i=0;i<NUM_STRINGS;i++)      {
97
 
            if (tags[i] == temp)        {
98
 
                tags[i] = -1;
99
 
                nums[i] = 0;
100
 
                amps[i] = (MY_FLOAT) 0.0;
101
 
            }
102
 
        }
103
 
    }
104
 
    else        {                          // In case note already off 
105
 
        for (i=0;i<NUM_STRINGS;i++)      { //    from strumming
106
 
            if (nums[i] == num) {               // Just clear its entry
107
 
                strings->noteOffT(num,amp);
108
 
                tags[i] = -1;
109
 
                nums[i] = 0;
110
 
                amps[i] = (MY_FLOAT) 0.0;
111
 
            }
112
 
        }
113
 
    }
114
 
    if (strumming == 2) strumming = 0;
115
 
}
116
 
 
117
 
MY_FLOAT MandPlyr :: tick()
118
 
{
119
 
    short i;
120
 
    MY_FLOAT temp2;
121
 
    if (strumming > 0) {
122
 
        strumCount -= 1;
123
 
        if (strumCount <= 0) {
124
 
            for (i=0;i<NUM_STRINGS;i++)   {
125
 
                if (tags[i] > 0) {
126
 
                    strings->kill(tags[i]);
127
 
                    temp2 = (MY_FLOAT) fabs(noise->tick());
128
 
                    if (temp2 > 0.2 * (1.0 - skill))
129
 
                        tags[i] = strings->noteOnN(nums[i],amps[i]);
130
 
                }
131
 
            }
132
 
            strumCount = strumRate;
133
 
            strumCount = strumCount +
134
 
                (long) (strumCount * (noise->tick() * (1.0 - skill)));
135
 
            if (strumming == 2) strumming = 0;
136
 
        }
137
 
    }
138
 
    for (i=0;i<NUM_STRINGS;i++) {
139
 
        if (tags[i] < -1) {
140
 
            tags[i] += 1;
141
 
            if (tags[i] == -1)  {
142
 
                tags[i] = strings->noteOnN(nums[i],amps[i]);
143
 
            }
144
 
        }
145
 
    }
146
 
    lastOutput = strings->tick();
147
 
    return lastOutput;
148
 
}
149
 
 
150
 
 
151
 
/*    Some very basic Mandolin Chords   */
152
 
/* Base Strings:        G  D  A  E                      */
153
 
/* G Chord:                     G  D  B  G                      */
154
 
/* C Chord:                     G  E  C  G                      */
155
 
/* D Chord:                     A  D  A  F#                     */
156
 
/* E Chord:                     G# E  B  G#                     */
157
 
/* A Chord:                     A  E  C# A                      */
158
 
/* B Chord:                     B  D# B  F#                     */
159
 
 
160
 
#define NUM_CHORDS 6
161
 
 
162
 
void MandPlyr :: playChord(MY_FLOAT amp, char *chordString)
163
 
{
164
 
    short i;
165
 
        char chordStr[NUM_CHORDS+1] = {"GCDEAB"};
166
 
        short chords[NUM_CHORDS][4] = {
167
 
                {55,62,71,79},
168
 
                {55,64,72,79},
169
 
                {57,62,69,78},
170
 
                {56,64,71,80},
171
 
                {57,64,73,81},
172
 
                {59,63,71,78}                           };
173
 
    short whichChord = -1;
174
 
 
175
 
    for (i=0;i<4;i++)
176
 
                if (tags[i] >= 0) strings->noteOffT(tags[i],amp);
177
 
 
178
 
    for (i=0;i<NUM_CHORDS;i++)  {
179
 
                if (chordString[0]==chordStr[i])
180
 
                        whichChord = i;
181
 
    }
182
 
 
183
 
    if (chordString[0] == 0)    {
184
 
    }
185
 
    else        {
186
 
        if (whichChord == -1) {
187
 
            printf("I don't know this chord: %s\n",chordString);
188
 
        }
189
 
        else {
190
 
            for (i=0;i<4;i++)   {
191
 
                nums[i] = chords[whichChord][i];
192
 
                tags[i] = -2 - (i * 10 * (200 - (int) amp));
193
 
                amps[i] = amp;
194
 
            }
195
 
        }
196
 
    }
197
 
}
198
 
 
199
 
void MandPlyr :: controlChange(int number, MY_FLOAT value)
200
 
{
201
 
#if defined(_debug_)        
202
 
    printf("MandPlyr : ControlChange: Number=%i Value=%f\n",number,value);
203
 
#endif    
204
 
    
205
 
    if (number == __SK_BodySize_)
206
 
            strings->controlChange(number,value);
207
 
    else if (number == __SK_PickPosition_)
208
 
            strings->controlChange(number,value);
209
 
    else if (number == __SK_StringDamping_)
210
 
            strings->controlChange(number,value);
211
 
    else if (number == __SK_StringDetune_)
212
 
            strings->controlChange(number,value);
213
 
    
214
 
    else if (number == __SK_Strumming_)   {
215
 
            if (value < 0.5) 
216
 
                strumming = 0;
217
 
            else
218
 
                strumming = 1;
219
 
    }
220
 
    else if (number == __SK_NotStrumming_)
221
 
            strumming = 0;
222
 
    else if (number == __SK_PlayerSkill_)
223
 
            skill = value * (MY_FLOAT) NORM_7;
224
 
    else if (number == __SK_StrumSpeed_)
225
 
        strumRate = (long) (SRATE * value * NORM_7); // (0 - 1Hz.)
226
 
    else    {        
227
 
            printf("MandPlyr : Undefined Control Number!!\n");
228
 
    }   
229
 
}