示例#1
0
void MidiManager::processMidiMessage(const juce::MidiMessage &midi_message, int sample_position) {
  ScopedLock lock(*critical_section_);
  if (midi_message.isNoteOn()) {
    float velocity = (1.0 * midi_message.getVelocity()) / mopo::MIDI_SIZE;
    synth_->noteOn(midi_message.getNoteNumber(), velocity, sample_position);
  }
  else if (midi_message.isNoteOff())
    synth_->noteOff(midi_message.getNoteNumber(), sample_position);
  else if (midi_message.isSustainPedalOn())
    synth_->sustainOn();
  else if (midi_message.isSustainPedalOff())
    synth_->sustainOff();
  else if (midi_message.isAllNotesOff())
    synth_->allNotesOff();
  else if (midi_message.isAftertouch()) {
    mopo::mopo_float note = midi_message.getNoteNumber();
    mopo::mopo_float value = (1.0 * midi_message.getAfterTouchValue()) / mopo::MIDI_SIZE;
    synth_->setAftertouch(note, value);
  }
  else if (midi_message.isPitchWheel()) {
    double percent = (1.0 * midi_message.getPitchWheelValue()) / PITCH_WHEEL_RESOLUTION;
    double value = 2 * percent - 1.0;
    synth_->setPitchWheel(value);
  }
  else if (midi_message.isController()) {
    if (midi_message.getControllerNumber() == MOD_WHEEL_CONTROL_NUMBER) {
      double percent = (1.0 * midi_message.getControllerValue()) / MOD_WHEEL_RESOLUTION;
      synth_->setModWheel(percent);
    }
    midiInput(midi_message.getControllerNumber(), midi_message.getControllerValue());
  }
}
示例#2
0
void MIDIProcessor::handleIncomingMidiMessage(juce::MidiInput * /*device*/,
  const juce::MidiMessage& message) {
  if (message.isController()) {
    const auto channel =
      static_cast<unsigned short int>(message.getChannel()); // 1-based
    const auto control =
      static_cast<unsigned short int>(message.getControllerNumber());
    const auto value =
      static_cast<unsigned short int>(message.getControllerValue());
    if (nrpn_filter_.ProcessMidi(channel, control, value)) { //true if nrpn piece
      if (nrpn_filter_.IsReady(channel)) { //send when finished
        for (const auto listener : listeners_)
          listener->handleMidiCC(channel, nrpn_filter_.GetControl(channel),
          nrpn_filter_.GetValue(channel));
        nrpn_filter_.Clear(channel);
      }
    }
    else //regular message
      for (const auto listener : listeners_)
        listener->handleMidiCC(channel, control, value);
  }
  else if (message.isNoteOn()) {
    for (const auto listener : listeners_) {
		  listener->handleMidiNote(message.getChannel(), message.getNoteNumber());
	  }
  }
  else if (message.isPitchWheel()) {
    const auto value =
      static_cast<unsigned short int>(message.getPitchWheelValue());
	  for (auto listener : listeners_) {
		  listener->handlePitchWheel(message.getChannel(), value);
	  }
  }
}
示例#3
0
void OwlNestSettings::handleIncomingMidiMessage(juce::MidiInput *source, const juce::MidiMessage &message){
  lastMidiMessageTime = Time::currentTimeMillis();
  bool hasChanged = false;
  if(message.isController()){
    int cc = message.getControllerNumber();
    int value = message.getControllerValue();
    midiArray[cc] = value;
    hasChanged = true;
#ifdef DEBUG
      std::cout << "rx cc " << cc << ": " << value << std::endl;
#endif // DEBUG
  }else if(message.isSysEx() && message.getSysExDataSize() > 2){
    const uint8 *data = message.getSysExData();
    if(data[0] == MIDI_SYSEX_MANUFACTURER && data[1] == MIDI_SYSEX_DEVICE){
      switch(data[2]){
      case SYSEX_PRESET_NAME_COMMAND: {
	handlePresetNameMessage(data[3], (const char*)&data[4], message.getSysExDataSize()-4);
	// hasChanged = true;
	break;
      }
      case SYSEX_PARAMETER_NAME_COMMAND: {
	handleParameterNameMessage(data[3], (const char*)&data[4], message.getSysExDataSize()-4);
	hasChanged = true;
	break;
      }
      case SYSEX_DEVICE_STATS: {
	handleDeviceStatsMessage((const char*)&data[3], message.getSysExDataSize()-3);
	break;
      }
      case SYSEX_FIRMWARE_VERSION: {
	handleFirmwareVersionMessage((const char*)&data[3], message.getSysExDataSize()-3);
	break;
      }
      case SYSEX_DEVICE_ID: {
#if JUCE_MAC || JUCE_LINUX
	int len = message.getSysExDataSize()-3;
	uint8_t deviceId[len];
	len = sysex_to_data((uint8_t*)(data+3), deviceId, len);
	handleDeviceIdMessage(deviceId, len);
#endif
	break;
      }
      case SYSEX_SELFTEST:{
	handleSelfTestMessage(data[3]);
	if(message.getSysExDataSize() > 4)
	  handleErrorMessage(data[4]);
	break;
      }
      }
    }
  }
  if(hasChanged)
    theUpdateGui.setValue(!(bool)theUpdateGui.getValue());
}