Esempio n. 1
0
void MidiBufferNode::applyEvent(MidiEvent e)
{
	//Event times are relative to the given range, no need to offset.
	
	nodeLock.lockWait();

	//Convert event time from global to local cursor
	e.time -= globalRange.start;
	e.time += cursor.getTimeRange().start;

	switch(e.type)
	{
	case MidiEventType::NOTE_ON:
		//If note with this index is already on, stop it prematurely
		for(auto n_iter = unfinishedNotes.begin(); n_iter != unfinishedNotes.end(); n_iter++)
		{
			MidiNote *n = *n_iter;
			if(n->index == e.midiIndex)
			{
				//Finish note and remove from unfinishedNotes
				n->setFinished(e.time);
				if(n->range.length() <= 0.0)
					data.removeNote(n);
				unfinishedNotes.erase(n_iter);
					
				break;
			}
		}

		//Add new (unfinished) note
		unfinishedNotes.push_back(data.addNote(MidiNote(e.midiIndex, e.velocity, e.time, cursor.getTimeRange().end)));
		break;

	case MidiEventType::NOTE_OFF:
		//If note with this index is on, stop it
		for(auto n_iter = unfinishedNotes.begin(); n_iter != unfinishedNotes.end(); n_iter++)
		{
			MidiNote *n = *n_iter;
			if(n->index == e.midiIndex)
			{
				//Finish note and remove from unfinishedNotes
				n->setFinished(e.time);
				if(n->range.length() <= 0.0)
					data.removeNote(n);
				unfinishedNotes.erase(n_iter);

				break;
			}
		}

		break;
	}

	nodeLock.unlock();
}
Esempio n. 2
0
void MidiIn::noteOnEvent(NoteOnEvent *pEvent)
{
    m_noteNumber = pEvent->noteNumber();
    m_frequency = MidiNote(m_noteNumber).frequency();
    m_velocity = pEvent->normalizedVelocity();
}
Esempio n. 3
0
float NoteOnEvent::frequency() const
{
    return MidiNote(m_number).frequency();
}