I created a Synthesiser subclass and want to change the implementation of some of the methods. With noteOn, everything is fine. But when I copy to my class noteOff method, the error appears:
Error (active) E0265 member "juce::SynthesiserVoice::keyIsDown" (declared at line 273 of "E:\000\MusicProgram\JUCE\modules\juce_audio_basics\synthesisers\juce_Synthesiser.h") is inaccessible NewProject_SharedCode E:\000\MusicProgram\JUCE Projects\NewProject\Source\MySynthesiser.cpp 39
in line:
jassert(!voice->keyIsDown || voice->isSustainPedalDown() == sustainPedalsDown[midiChannel]);
Method code:
void MySynthesiser::noteOff(const int midiChannel, const int midiNoteNumber, const float velocity, const bool allowTailOff)
{
const ScopedLock sl(lock);
for (auto* voice : voices)
{
if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel(midiChannel))
{
if (auto sound = voice->getCurrentlyPlayingSound())
{
if (sound->appliesToNote(midiNoteNumber) && sound->appliesToChannel(midiChannel))
{
jassert(!voice->keyIsDown || voice->isSustainPedalDown() == sustainPedalsDown[midiChannel]);
voice->setKeyDown(false);
if (!(voice->isSustainPedalDown() || voice->isSostenutoPedalDown()))
stopVoice(voice, velocity, allowTailOff);
}
}
}
}
}
What is this jassert? From the description of the macro, I did not understand what it is for and what function it performs.
- If it becomes unexecutable in an assembly with debugging disabled, does that mean that I can simply remove this line from my implementation of MySynthesiser and the functionality of the final plugin will not be affected in any way?
- Why is he needed then?
- Why does he set a condition, but does not have a statement?
- Why does the error appear?
- Is it possible to fix the error without deleting this line?
I would be very grateful for clarifications.
Full code:
#pragma once
#include <JuceHeader.h>
using namespace juce;
class MySynthesiser : public Synthesiser
{
void noteOn(const int midiChannel, const int midiNoteNumber, const float velocity) override;
void noteOff(const int midiChannel, const int midiNoteNumber, const float velocity, const bool allowTailOff) override;
};
#include "MySynthesiser.h"
void MySynthesiser::noteOn(const int midiChannel, const int midiNoteNumber, const float velocity)
{
const ScopedLock sl(lock);
for (auto* sound : sounds)
{
if (sound->appliesToNote(midiNoteNumber) && sound->appliesToChannel(midiChannel))
{
// If hitting a note that's still ringing, stop it first (it could be still playing because of the sustain or sostenuto pedal).
for (auto* voice : voices)
{
DBG("for (auto* voice : voices)");
if ((voice->getCurrentlyPlayingNote() == midiNoteNumber) && voice->isPlayingChannel(midiChannel) && (voice->getCurrentlyPlayingSound() == sound))
{
stopVoice(voice, 1.0f, true);
DBG("stopVoice");
}
}
startVoice(findFreeVoice(sound, midiChannel, midiNoteNumber, isNoteStealingEnabled()), sound, midiChannel, midiNoteNumber, velocity);
}
}
}
void MySynthesiser::noteOff(const int midiChannel, const int midiNoteNumber, const float velocity, const bool allowTailOff)
{
const ScopedLock sl(lock);
for (auto* voice : voices)
{
if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel(midiChannel))
{
if (auto sound = voice->getCurrentlyPlayingSound())
{
if (sound->appliesToNote(midiNoteNumber) && sound->appliesToChannel(midiChannel))
{
jassert(!voice->keyIsDown || voice->isSustainPedalDown() == sustainPedalsDown[midiChannel]);
voice->setKeyDown(false);
if (!(voice->isSustainPedalDown() || voice->isSostenutoPedalDown()))
stopVoice(voice, velocity, allowTailOff);
}
}
}
}
}