| 38 | } |
| 39 | |
| 40 | void Player::processBlock(AudioBuffer<float>& inAudioBuffer, MidiBuffer& outMidiBuffer) |
| 41 | { |
| 42 | auto old_audio_gain = mGainSourceAudio; |
| 43 | auto old_synth_gain = mGainSynth; |
| 44 | |
| 45 | int playhead_index = static_cast<int>(std::round(mPlayheadTime * mSampleRate)); |
| 46 | |
| 47 | float audio_gain_db = mProcessor->getParameterValue(ParameterHelpers::AudioPlayerGainId); |
| 48 | float synth_gain_db = mProcessor->getParameterValue(ParameterHelpers::MidiPlayerGainId); |
| 49 | |
| 50 | _setGains(audio_gain_db, synth_gain_db); |
| 51 | |
| 52 | bool is_playing = mIsPlaying.load(); |
| 53 | mInternalBuffer.clear(); |
| 54 | |
| 55 | int num_out_channels = mProcessor->getTotalNumOutputChannels(); |
| 56 | jassert(num_out_channels > 0 && num_out_channels <= 2); |
| 57 | |
| 58 | if (is_playing) { |
| 59 | auto& midi_buffer = mSynthController->generateNextMidiBuffer(inAudioBuffer.getNumSamples()); |
| 60 | |
| 61 | if (mShouldOutputMidi) { |
| 62 | outMidiBuffer.addEvents(midi_buffer, 0, inAudioBuffer.getNumSamples(), 0); |
| 63 | |
| 64 | // Iterate over midi events and update active notes for midi out |
| 65 | for (const auto& metadata: midi_buffer) { |
| 66 | auto midi_message = metadata.getMessage(); |
| 67 | if (midi_message.isNoteOn() || midi_message.isNoteOff()) { |
| 68 | int note_number = midi_message.getNoteNumber(); |
| 69 | int increment = midi_message.isNoteOn() ? 1 : -1; |
| 70 | |
| 71 | if (note_number >= 0 && note_number < 128) { |
| 72 | auto idx = static_cast<size_t>(note_number); |
| 73 | mActiveNotesMidiOut[idx] = std::max(mActiveNotesMidiOut[idx] + increment, 0); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | mWasOutputtingMidi = true; |
| 79 | |
| 80 | } else if (mWasOutputtingMidi) { |
| 81 | _clearActiveNotesMidiOut(outMidiBuffer); |
| 82 | mWasOutputtingMidi = false; |
| 83 | } |
| 84 | |
| 85 | mSynth->renderNextBlock(mInternalBuffer, midi_buffer, 0, inAudioBuffer.getNumSamples()); |
| 86 | mWasPlaying = true; |
| 87 | |
| 88 | } else { |
| 89 | if (mWasPlaying && mShouldOutputMidi) { |
| 90 | _clearActiveNotesMidiOut(outMidiBuffer); |
| 91 | } |
| 92 | |
| 93 | mWasPlaying = false; |
| 94 | |
| 95 | mSynth->renderNextBlock(mInternalBuffer, {}, 0, inAudioBuffer.getNumSamples()); |
| 96 | } |
| 97 |
nothing calls this directly
no test coverage detected