예제 #1
0
  void Arpeggiator::process() {
    mopo_float frequency = input(kFrequency)->at(0);
    float min_gate = (MIN_VOICE_TIME + VOICE_KILL_TIME) * frequency;
    mopo_float gate = INTERPOLATE(min_gate, 1.0, input(kGate)->at(0));

    mopo_float delta_phase = frequency / sample_rate_;
    mopo_float new_phase = phase_ + buffer_size_ * delta_phase;

    // If we're past the gate phase and we're playing a note, turn it off.
    if (new_phase >= gate && last_played_note_ >= 0) {
      int offset = CLAMP((gate - phase_) / delta_phase, 0, buffer_size_ - 1);
      note_handler_->noteOff(last_played_note_, offset);
      last_played_note_ = -1;
    }

    // Check if it's time to play the next note.
    if (getNumNotes() && new_phase >= 1) {
      int offset = CLAMP((1 - phase_) / delta_phase, 0, buffer_size_ - 1);
      std::pair<mopo_float, mopo_float> note = getNextNote();
      note_handler_->noteOn(note.first, note.second, offset);
      last_played_note_ = note.first;
      phase_ = new_phase - 1.0;
    }
    else
      phase_ = new_phase;
  }
예제 #2
0
bool NoteCollection::getGeneralNotes( unsigned int& first,
		unsigned int& last ) const
{
	if( !m_vecNotes.empty() )
	{
		first = m_vecNotes.size();
		last = getNumNotes() - 1;
		return true;
	}
	return false;
}