コード例 #1
0
bool HelmComputerKeyboard::keyStateChanged(bool isKeyDown, Component *origin) {
  bool consumed = false;
  ScopedLock lock(*critical_section_);
  for (int i = 0; i < layout_.length(); ++i) {
    int note = computer_keyboard_offset_ + i;

    if (KeyPress::isKeyCurrentlyDown(layout_[i]) &&
        !keys_pressed_.count(layout_[i]) && isKeyDown) {
      keys_pressed_.insert(layout_[i]);
      keyboard_state_->noteOn(KEYBOARD_MIDI_CHANNEL, note, 1.0);
    }
    else if (!KeyPress::isKeyCurrentlyDown(layout_[i]) &&
             keys_pressed_.count(layout_[i])) {
      keys_pressed_.erase(layout_[i]);
      keyboard_state_->noteOff(KEYBOARD_MIDI_CHANNEL, note, 1.0);
    }
    consumed = true;
  }

  if (KeyPress::isKeyCurrentlyDown(down_key_)) {
    if (!keys_pressed_.count(down_key_)) {
      keys_pressed_.insert(down_key_);
      changeKeyboardOffset(computer_keyboard_offset_ - mopo::NOTES_PER_OCTAVE);
      consumed = true;
    }
  }
  else
    keys_pressed_.erase(down_key_);

  if (KeyPress::isKeyCurrentlyDown(up_key_)) {
    if (!keys_pressed_.count(up_key_)) {
      keys_pressed_.insert(up_key_);
      changeKeyboardOffset(computer_keyboard_offset_ + mopo::NOTES_PER_OCTAVE);
      consumed = true;
    }
  }
  else
    keys_pressed_.erase(up_key_);

  if (KeyPress::isKeyCurrentlyDown(KeyPress::spaceKey)) {
    if (!keys_pressed_.count(' ')) {
      keys_pressed_.insert(' ');
      synth_->correctToTime(0.0);
      consumed = true;
    }
  }
  else
    keys_pressed_.erase(' ');

  return consumed;
}
コード例 #2
0
bool HelmComputerKeyboard::keyStateChanged(bool isKeyDown, Component *originatingComponent) {
  bool consumed = false;
  ScopedLock lock(*critical_section_);
  for (int i = 0; i < strlen(KEYBOARD); ++i) {
    int note = computer_keyboard_offset_ + i;

    if (KeyPress::isKeyCurrentlyDown(KEYBOARD[i]) && !keys_pressed_.count(KEYBOARD[i])) {
      keys_pressed_.insert(KEYBOARD[i]);
      synth_->noteOn(note);
    }
    else if (!KeyPress::isKeyCurrentlyDown(KEYBOARD[i]) && keys_pressed_.count(KEYBOARD[i])) {
      keys_pressed_.erase(KEYBOARD[i]);
      synth_->noteOff(note);
    }
    consumed = true;
  }

  if (KeyPress::isKeyCurrentlyDown('z')) {
    if (!keys_pressed_.count('z')) {
      keys_pressed_.insert('z');
      changeKeyboardOffset(computer_keyboard_offset_ - mopo::NOTES_PER_OCTAVE);
      consumed = true;
    }
  }
  else
    keys_pressed_.erase('z');

  if (KeyPress::isKeyCurrentlyDown('x')) {
    if (!keys_pressed_.count('x')) {
      keys_pressed_.insert('x');
      changeKeyboardOffset(computer_keyboard_offset_ + mopo::NOTES_PER_OCTAVE);
      consumed = true;
    }
  }
  else
    keys_pressed_.erase('x');

  if (KeyPress::isKeyCurrentlyDown(KeyPress::spaceKey)) {
    if (!keys_pressed_.count(' ')) {
      keys_pressed_.insert(' ');
      synth_->correctToTime(0.0);
      consumed = true;
    }
  }
  else
    keys_pressed_.erase(' ');

  return consumed;
}