示例#1
0
static void TrillAlgorithm(FunctionEvent& p, EventBuffer& midiOutput) {
   static NoteEvent note;           // temporary note before placing in buffer

   int key1 = p.getKey();           // lower key of trill
   int key2 = p.charValue(14);      // upper key of trill
   int state = p.charValue(15);     // which note to play next
   int starttime = p.intValue(10);  // when trill was started
   int i;
  
   // turn off the trill if there is a note played inside the trill
   int range1 = key1;
   int range2 = key2;
   if (range2 - range1 == 1) {
      range1--;
      range2++;
   }
   for (i=range1; i<=range2; i++) {
      if (noteontimes[i] > starttime) {
         p.off(midiOutput);
         return;
      }
   }

   // set the next note to play
   int key = state ? key2 : key1;
   state = !state;
   p.charValue(15) = state;

   // set the parameters for the output note:
   note.setOnDur(t_time, p.getDur()); 
   note.setVel(p.getVel());
   note.setChan(p.getChan());
   note.setKey(key);

   // update the parameters for the gliss function:
   p.setOnTime(p.getOnTime() + p.getDur());  
   
   int value = p.getVel() + velcorrection;
   if (value < 100 && value > 3) {
      p.setVel(value);
   }
   if (p.getDur() + trillcorrection > MINTRIGTIME) {
      p.setDur(p.getDur() + trillcorrection);
   }

   note.activate();
   note.action(midiOutput);       // start right now, avoiding any buffer delay
   midiOutput.insert(note);       // the note off message is being buffered
}
示例#2
0
int startAlgorithm(TumbleParameters& p) {
   static FunctionEvent tn;   // a Temporary Note for copying into eventBuffer

   int ploc = storeParameters(tparam, p);
   if (ploc < 0) {
      cout << "Warning: Parameter space is full.  Not adding new algorithm"
           << endl;
      return -1;
   }

   // setting the fields of the function note
   tn.setFunction(TumbleNoteFunction);
   tn.setChannel(channel);
   tn.setKeyno(0);
   tn.setVelocity(0);
   tn.charValue(0) = (char)ploc;         // store location of the parameters
   tn.setStatus(EVENT_STATUS_ACTIVE);
   tn.setOnTime(t_time + p.i[0] - anticipation);

   // display the basic algorithm info
   cout << "Tumble: Time: " << t_time << "\tStart = " << (int)p.current
        << "\tPattern = . ";
   for (int i=1; i<p.n.getSize(); i++) {
      cout << (int)p.n[i] << " ";
   }
   cout << "(" << (int)p.n[0] << ")";
   cout << " ioi: " << p.i[0];
   cout << endl;

   return eventBuffer.insert(tn);
}
示例#3
0
static void TumbleNoteFunction(FunctionEvent& p, EventBuffer& midiOutput) {
   static NoteEvent note;           // temporary note for placing in buffer

   TumbleParameters& param = tparam[p.charValue(0)];
   int newnote = limit(param.current + param.dir * param.n[param.pos], 0, 127);

   // turn off algorithm if someone turned the algorithm off externally
   // or if the current note is too large or too small.
   if (param.active == 0 || newnote < A0 || newnote > C7) {
      param.active = 0;
      p.off(midiOutput);
      return;
   }

   // set the parameters of the output note:
   note.setOnDur(t_time, param.d[param.pos]);   // off time holds dur
   note.setVel(param.v[param.pos]);
   note.setChan(p.getChan());
   note.setKey(newnote);
   note.activate();
   note.action(midiOutput);     // start right now, avoiding any buffer delay
   midiOutput.insert(note);     // store the note for turning off later

   // update the parameters for the tumble algorithm
   p.setOnTime(p.getOnTime() + param.i[param.pos]);
   param.current = newnote;
   param.pos++;
   if (param.pos > param.n.getSize()) {
      param.pos = 0;
   }
}
示例#4
0
void createTrill(int key1, int key2, int velocity, int channel, int duration) {
   static FunctionEvent tn;   // a Temporary Note for copying into eventBuffer

   // key1 should always be smaller than key2
   int temp;
   if (key1 > key2) {
      temp = key1;
      key1 = key2;
      key2 = temp;
   }

   // setting the fields of the function note
   tn.setFunction(TrillAlgorithm);
   tn.setChannel(channel);
   tn.setKeyno(key1);
   tn.setVelocity(velocity);

   // set extra parameters
   tn.charValue(15) = 0;        // 0 = play key1 next, 1 = play key2 next
   tn.charValue(14) = key2;     // secondary pitch
   tn.intValue(10) = t_time;    // initialization time

   tn.setStatus(EVENT_STATUS_ACTIVE);

   // start time of function and the duration between calling it
   tn.setOnDur(t_time + duration, duration);

   eventBuffer.insert(tn);

   cout << "Trill = " << key1 << " to " << key2 
        << "\tRate = " << duration
        << endl;
}