- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个基本的合成器插件。我的 slider 有问题。当我将它与 ValueTree 连接时,有时会出现以下错误。有时它可以正常工作。
// for a two-value style slider, you should use the setMinValue() and setMaxValue()
// methods to set the two values.
jassert (style != TwoValueHorizontal && style != TwoValueVertical);
我无法解释为什么我会收到有关二值 slider 的错误,即使我没有使用一个。我错过了什么吗?我是 JUCE 和 C++ 的新手,所以如果我遗漏了一些明显的东西,请原谅。
这就是我在 PluginProcessor.cpp 中添加参数的方式:
tree (*this, nullptr)
tree.createAndAddParameter("osc1_attack", "Osc1_Attack", "Osc1_Attack", envParam, 0, nullptr ,nullptr);
//Initialize Tree
tree.state = ValueTree("SynthTree");
这就是我在 PluginEditor.cpp 中创建 slider 的方式:
osc1AttackSlider.setSliderStyle(Slider::SliderStyle::LinearVertical);
osc1AttackSlider.setRange(0.1f, 500.0f);
osc1AttackSlider.setValue(0.1f);
osc1AttackSlider.addListener(this);
osc1AttackSlider.setTextBoxStyle(Slider::TextBoxBelow, false, 50, 20);
addAndMakeVisible(&osc1AttackSlider);
sliderTree = new AudioProcessorValueTreeState::SliderAttachment(processor.tree, "osc1_attack", osc1AttackSlider);
这就是我在 PluginEditor.h 中声明 sliderTree 变量的方式:
AudioProcessorValueTreeState::SliderAttachment* sliderTree;
我遵循了“theAudioProgrammer”的非常好的 YouTube 教程,他为此使用了 ScopedPointer。对我来说,它只适用于组合框,如果我在这里使用它,我会收到以下错误:
/** Returns a raw pointer to the allocated data.
This may be a null pointer if the data hasn't yet been allocated, or if it has been
freed by calling the free() method.
*/
inline ElementType* get() const noexcept { return data; }
最佳答案
我想我以前遇到过这个问题。该框架已更新,而不是使用 tree.addAndCreate 来设置您需要放置的参数
tree(*this, nullptr, "Parameters", createParameterLayout() )
像这样在你的构造函数中
YourProjectAudioProcessor::YourProjectAudioProcessor(){
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", juce::AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
#endif
),
tree(*this, nullptr, "Parameters", createParameterLayout() );
#endif
}
你可以放
std::make_unique <AudioParameterInt>("oct", "Oct", -3.0f, 3.0f, 0.0f), std::make_unique <AudioParameterInt>("tone", "Tone", -12.0f, 12.0f, 0.0f), std::make_unique <AudioParameterFloat>("tune", "Tune", -1.0f, 1.0f, 0.0f)
(请记住,此参数语句末尾的 float 接管了 slider setRange 函数,我不确定您是否需要保留 setRange 函数,或者这是否会导致错误或崩溃。您可能不得不如果您在 setRange 函数中设置了捕捉值,则捕捉到 int 值而不是浮点值。)
在“参数”位于 tree() 函数中的位置,或者创建如下所示的参数布局,在这种情况下,您只需要按原样保留“参数”。
juce::AudioProcessorValueTreeState::ParameterLayout YourProjectAudioProcessor::createParameterLayout(){
std::vector <std::unique_ptr<RangedAudioParameter>> params;
auto octVal = std::make_unique <AudioParameterInt>("oct", "Oct", -3.0f, 3.0f, 0.0f);
auto toneVal = std::make_unique <AudioParameterInt>("tone", "Tone", -12.0f, 12.0f, 0.0f);
auto tuneVal = std::make_unique <AudioParameterFloat>("tune", "Tune", -1.0f, 1.0f, 0.0f);
params.push_back(std::move(octVal));
params.push_back(std::move(toneVal));
params.push_back(std::move(tuneVal));
return { params.begin(), params.end() };}
此外,值树现在是一个作用域指针,因此在您声明 slider 附件树的地方,它现在需要是一个唯一指针,而不是作用域指针或原始指针。
std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> sliderOctTree;
std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> sliderToneTree;
std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> sliderTuneTree;
例如,您还需要使新的 sliderTree 值独一无二。将 new 更改为 std::make_unique 并将 slider 附件范围 AKA AudioProcessorValueTreeState::SliderAttachment 放在尖括号中。
sliderTree = std::make_unique <AudioProcessorValueTreeState::SliderAttachment>(processor.tree, "osc1_attack", osc1AttackSlider);
关于c++ - JUCE: slider ,ValueTree 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50669459/
我正在尝试制作一个基本的合成器插件。我的 slider 有问题。当我将它与 ValueTree 连接时,有时会出现以下错误。有时它可以正常工作。 // for a two-value style sl
我是一名优秀的程序员,十分优秀!