本文整理汇总了C++中EventBuffer::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ EventBuffer::insert方法的具体用法?C++ EventBuffer::insert怎么用?C++ EventBuffer::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventBuffer
的用法示例。
在下文中一共展示了EventBuffer::insert方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TumbleNoteFunction
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;
}
}
示例2: startAlgorithm
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: createTrill
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;
}
示例4: EchoAlgorithm
static void EchoAlgorithm(FunctionEvent& p, EventBuffer& midiOutput) {
static NoteEvent note; // temporary note before placing in buffer
// check if pausing
if (decaystates[p.getKey()] < 0.0) {
p.setOnTime(p.getOnTime() + p.getDur() + p.shortValue(14));
return;
}
// set the parameters for the output note:
note.setOnDur(t_time, p.getOffTime()); // off time holds dur
note.setVel(p.getVel());
note.setChan(p.getChan());
note.setKey(p.getKey());
// update the parameters for the function:
decaystates[p.getKey()] *= decayrate;
p.setVel((int)decaystates[p.getKey()]);
// if note is too quiet, end the note
if (p.getVel() <= 2) {
p.off(midiOutput);
decaystates[p.getKey()] = 0.0;
}
// next time includes a gap so that key can raise on keyboard
p.setOnTime(p.getOnTime() + p.getDur() + p.shortValue(14));
note.activate();
note.action(midiOutput); // start right now, avoiding any buffer delay
midiOutput.insert(note); // the note off message is being buffered
}
示例5: EnhanceFunction
static void EnhanceFunction(FunctionEvent& p, EventBuffer& midiOutput) {
static NoteEvent note; // temporary note before placing in buffer
// set the parameters for the output note:
note.setOnDur(t_time, p.getOffTime()); // off time holds dur
note.setVel(p.getVel());
note.setChan(p.getChan());
note.setKey(p.getKey());
// if note is too quiet
if (p.getVel() <= 5) {
p.off(midiOutput);
}
// update the parameters for the function:
p.setKey(p.getKey()+p.shortValue(14));
p.setVel(p.getVel()-5);
p.setOnTime(p.getOnTime() + p.getDur()); // OffTime stores duration
note.activate();
note.action(midiOutput); // start right now, avoiding any buffer delay
midiOutput.insert(note); // the note off message is being buffered
// check wether to kill the algorithm or not:
// if note is off the range of the keyboard
if (p.getKey() > C8 || p.getKey() < A0) {
p.off(midiOutput);
}
}
示例6: playgliss
void playgliss(int basenote, int loudness, int channel, int duration,
int distancee) {
static FunctionEvent tn; // a Temporary Note for copying into eventBuffer
// setting the fields of the function note
tn.shortValue(14) = distancee;
tn.setFunction(EnhanceFunction);
tn.setChannel(channel);
tn.setKeyno(basenote + distancee);
tn.setVelocity(loudness - 5);
tn.setStatus(EVENT_STATUS_ACTIVE);
// start time of function and the duration between calling it
tn.setOnDur(t_time, duration);
eventBuffer.insert(tn);
cout << "StartKey = " << basenote
<< "\tLoudness = " << loudness
<< "\tRate = " << duration
<< "\tDirection = " << distancee
<< endl;
}
示例7: playNextPattern
void playNextPattern(EventBuffer& eventbuffer, NoteScore& score,
int pattern, int subpattern, double tempo) {
if (pattern == 0 && subpattern == 3) {
subpattern = 2;
}
if (pattern == 6 && subpattern == 3) {
subpattern = 2;
}
int p = pattern;
int sp = subpattern;
cout << "playing pattern " << pattern << (char)('a' + subpattern) << endl;
NoteEvent note; // temporary note for placing in buffer
int i;
for (i=0; i<score[pattern][subpattern].getSize(); i++) {
if (!activevoice[score[pattern][subpattern][i].voice]) {
continue;
}
note.setOnDur((int)(t_time + score[p][sp][i].start * 1000 * 60 / tempo +
0.5), (int)(score[p][sp][i].dur * 1000 * 60 / tempo + 0.5));
note.setChan(CH_10);
note.setKey(voicetokey[score[p][sp][i].voice]);
note.setVel(score[p][sp][i].vel);
note.activate();
if (score[p][sp][i].start == 0.0) {
note.action(eventbuffer); // play starting notes now, avoiding delay
}
eventbuffer.insert(note);
}
}
示例8: TrillAlgorithm
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
}
示例9: createDecay
void createDecay(int channel, int key, int duration, int velocity) {
static FunctionEvent tn; // temporary function for copying into eventBuffer
tn.shortValue(14) = gap; // gap between successive notes
tn.setFunction(EchoAlgorithm);
tn.setChannel(channel);
tn.setKeyno(key);
decaystates[key] = velocity * decayrate;
tn.setVelocity((int)decaystates[key]);
tn.setStatus(EVENT_STATUS_ACTIVE);
// start time of function and the duration between calling it
tn.setOnDur(t_time, duration);
eventBuffer.insert(tn);
cout << "Key= " << key
<< "\tDuration = " << duration + gap
<< "\tVelocity = " << velocity
<< endl;
}
示例10: playchord
void playchord(MidiEvent aMessage, int chordQuality,
int* rhythm, int* dur) {
int numNotes = 0; // the number of notes to play
NoteEvent tempNote; // temporary Note for copying into eventBuffer
int chordNote[4]; // the notes of the chord to be calculated
int rootNote = aMessage.getP1(); // root of chord to be created
chordNote[0] = rootNote;
switch (chordQuality) {
case DIMINISHED_TRIAD:
chordNote[1] = rootNote + 3; chordNote[2] = rootNote + 6;
numNotes = 3;
break;
case MINOR_TRIAD:
chordNote[1] = rootNote + 3; chordNote[2] = rootNote + 7;
numNotes = 3;
break;
case MAJOR_TRIAD:
chordNote[1] = rootNote + 4; chordNote[2] = rootNote + 7;
numNotes = 3;
break;
case AUGMENTED_TRIAD:
chordNote[1] = rootNote + 4; chordNote[2] = rootNote + 8;
numNotes = 3;
break;
case FULLY_DIM_7TH:
chordNote[1] = rootNote + 3;
chordNote[2] = rootNote + 6;
chordNote[3] = rootNote + 9;
numNotes = 4;
break;
case HALF_DIM_7TH:
chordNote[1] = rootNote + 3;
chordNote[2] = rootNote + 6;
chordNote[3] = rootNote + 10;
numNotes = 4;
break;
case mm_7TH:
chordNote[1] = rootNote + 3;
chordNote[2] = rootNote + 7;
chordNote[3] = rootNote + 10;
numNotes = 4;
break;
case mM_7TH:
chordNote[1] = rootNote + 3;
chordNote[2] = rootNote + 7;
chordNote[3] = rootNote + 11;
numNotes = 4;
break;
case Mm_7TH:
chordNote[1] = rootNote + 3;
chordNote[2] = rootNote + 4;
chordNote[3] = rootNote + 10;
numNotes = 4;
break;
case MM_7TH:
chordNote[1] = rootNote + 4;
chordNote[2] = rootNote + 7;
chordNote[3] = rootNote + 10;
numNotes = 4;
break;
default: // invalid quality
return;
}
cout << "Chord: (";
for (int i=0; i<numNotes; i++) {
tempNote.setKeyno(chordNote[i]);
if (tempNote.getKeyno() < 0 || tempNote.getKeyno() > 127) continue;
if (attack[i] == 0) {
tempNote.setVelocity(aMessage.getP2());
} else {
tempNote.setVelocity(attack[i]);
}
tempNote.setOnDur(t_time+rhythm[i]+offset, dur[i]);
tempNote.setStatus(0); // note hasn't been played yet
eventBuffer.insert(&tempNote);
cout << tempNote.getKeyno();
if (i != numNotes-1) cout << ",";
}
cout << ")" << endl;
}
示例11: processNotes
void processNotes(HumdrumRecord& record) {
NoteEvent note;
int pitch = 0;
double duration = 0.0;
int staccatoQ = 0;
int accentQ = 0;
int sforzandoQ = 0;
int i, j;
int notecount = 0;
char buffer[128] = {0};
for (i=0; i<record.getFieldCount(); i++) {
if ((record.getPrimaryTrack(i) < (int)trackmute.size())
&& trackmute[record.getPrimaryTrack(i)]) {
continue;
}
if (record.getExInterpNum(i) == E_KERN_EXINT) {
notecount = record.getTokenCount(i);
if (strcmp(record[i], ".") == 0) {
continue;
}
for (j=0; j<notecount; j++) {
record.getToken(buffer, i, j);
if (strchr(buffer, '[')) {
// total tied note durations
duration = data.getTiedDuration(linenum, i, j);
} else {
duration = Convert::kernToDuration(buffer);
}
pitch = Convert::kernToMidiNoteNumber(buffer);
// skip rests
if (pitch < 0) {
continue;
}
pitch += transpose;
// don't play note which is transposed too extremely
if (pitch < 0) { continue; }
if (pitch > 127) { continue; }
// skip tied notes
if (strchr(buffer, '_') || strchr(buffer, ']')) {
continue;
}
accentQ = strchr(buffer, '^') == NULL? 0 : 1;
sforzandoQ = strchr(buffer, 'z') == NULL? 0 : 1;
staccatoQ = strchr(buffer, '\'') == NULL? 0 : 1;
note.setChannel(0);
note.setKey(pitch);
note.setOnTime(t_time);
duration = duration * 60000 / tempo / tempoScale;
if (shortenQ) {
duration -= shortenamount;
if (duration < mine) {
duration = mine;
}
}
note.setDur((int)duration);
if (staccatoQ) {
note.setDur((int)(0.5 * note.getDur()));
}
note.setKey(pitch);
if (accentQ) {
velocity *= 1.3;
}
if (sforzandoQ) {
velocity *= 1.5;
}
if (velocity > 127) {
velocity = 127;
}
note.setVelocity(velocity);
note.activate();
note.action(eventBuffer);
eventBuffer.insert(note);
}
}
}
}