All pastes #425965 Raw Edit

pulse00

public text v1 · immutable
·published 2007-04-05 20:42 UTC
rendered paste body
void mycallback( double deltatime, std::vector< unsigned char > *message, void *userData )
{
	
	unsigned int nBytes = message->size();
	for ( unsigned int i=0; i<nBytes; i++ )
    	cout << "Byte " << i << " = " << (int)message->at(i) << ", ";
		if ( nBytes > 0 )
		cout << "stamp = " << deltatime << '\n';
		
		
	vector <stk_note> *note;
	
	note = static_cast <vector <stk_note>*> (userData);
	
	 // -------- Note on ----------------------
		
	if ((int) message->at(0) == 144) {
	
		stk_note::curr_voices++;
		
		note->at(stk_note::curr_voices).exp = (double) message->at(1) / 12.0;
		note->at(stk_note::curr_voices).frequency = 8.1758 * pow(2,note->at(stk_note::curr_voices).exp);
		note->at(stk_note::curr_voices).pitch = (int) message->at(1);
		note->at(stk_note::curr_voices).velocity = (int) message->at(2);
		note->at(stk_note::curr_voices).state = true;
		
				
	}
	// ---------- Note off -----------------------
	if ((int) message->at(0) == 128) {
		
		for (int i = 1; i < (int) note->size(); i++) {
				
			if (note->at(i).pitch == (int) message->at(1)) {
						
				note->at(i).state = false;
				stk_note::curr_voices--;
			}
		}	
	}
	cout << "Current Voices: " << stk_note::curr_voices << " ";
 }