Example #1
0
  void VoiceHandler::noteOn(mopo_float note, mopo_float velocity, int sample, int channel) {
    MOPO_ASSERT(sample >= 0 && sample < buffer_size_);
    MOPO_ASSERT(channel >= 0 && channel < NUM_MIDI_CHANNELS);

    Voice* voice = grabVoice();
    pressed_notes_.push_front(note);

    if (last_played_note_ < 0)
      last_played_note_ = note;
    voice->activate(note, velocity, last_played_note_, pressed_notes_.size(), sample, channel);
    active_voices_.push_back(voice);
    last_played_note_ = note;
  }
Example #2
0
  void VoiceHandler::noteOn(mopo_float note, mopo_float velocity) {
    Voice* voice = 0;
    pressed_notes_.push_back(note);
    if (free_voices_.size() && active_voices_.size() < polyphony_) {
      voice = free_voices_.front();
      free_voices_.pop_front();
    }
    else {
      voice = active_voices_.front();
      active_voices_.pop_front();
    }

    voice->activate(note, velocity);
    active_voices_.push_back(voice);
  }
Example #3
0
  void VoiceHandler::noteOff(mopo_float note) {
    std::list<mopo_float>::iterator note_iter = pressed_notes_.begin();
    while (note_iter != pressed_notes_.end()) {
      if (*note_iter == note)
        note_iter = pressed_notes_.erase(note_iter);
      else
        note_iter++;
    }

    std::list<Voice*>::iterator iter = active_voices_.begin();
    for (; iter != active_voices_.end(); ++iter) {
      Voice* voice = *iter;
      if (voice->state()->note == note) {
        if (sustain_)
          sustained_voices_.push_back(voice);
        else {
          if (polyphony_ == 1 && pressed_notes_.size())
            voice->activate(pressed_notes_.back(), voice->state()->velocity);
          else
            voice->deactivate();
        }
      }
    }
  }