首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JUCE:滑块,ValueTree错误

JUCE:滑块,ValueTree错误
EN

Stack Overflow用户
提问于 2018-06-04 02:06:02
回答 1查看 490关注 0票数 3

我正在尝试做一个基本的合成器插件。我的滑块出了点问题。当我将它与ValueTree连接时,我有时会得到以下错误。有时它可以正常工作而不会出错。

代码语言:javascript
复制
// for a two-value style slider, you should use the setMinValue() and setMaxValue()
// methods to set the two values.
 jassert (style != TwoValueHorizontal && style != TwoValueVertical);

我不能解释为什么我得到一个关于两值滑块的错误,即使我没有使用一个滑块。我是不是遗漏了什么?我是JUCE和C++的新手,所以如果我错过了一些明显的东西,请原谅。

下面是我在PluginProcessor.cpp中添加参数的方法:

代码语言:javascript
复制
tree (*this, nullptr)

tree.createAndAddParameter("osc1_attack", "Osc1_Attack", "Osc1_Attack", envParam, 0, nullptr ,nullptr);

//Initialize Tree 
tree.state = ValueTree("SynthTree");

这就是我在PluginEditor.cpp中创建滑块的方式:

代码语言:javascript
复制
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变量的方式:

代码语言:javascript
复制
AudioProcessorValueTreeState::SliderAttachment* sliderTree;

我遵循了“theAudioProgrammer”的非常好的YouTube教程,他为此使用了一个ScopedPointer。对于我来说,这只适用于ComboBoxes,如果我在这里使用它,我会得到以下错误:

代码语言:javascript
复制
/** 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; }
EN

回答 1

Stack Overflow用户

发布于 2020-08-14 23:38:37

我想我以前遇到过这个问题。框架已经更新,您不需要使用tree.addAndCreate来设置参数,而需要将以下内容

代码语言:javascript
复制
 tree(*this, nullptr, "Parameters", createParameterLayout() )

在您的构造函数中,如下所示

代码语言:javascript
复制
 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
 }

或者你可以把

代码语言:javascript
复制
 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)

(请记住,此参数语句末尾的浮点数接管了滑块setRange函数,我不确定您是否需要保留setRange函数,或者这是否会导致错误或崩溃。如果已在setRange函数中设定捕捉值,则必须捕捉到整数值,而不是浮点值。)

在其中“参数”在tree()函数中,或者创建如下所示的参数布局,在这种情况下,您只需保留“参数”不变。

代码语言:javascript
复制
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() };}

另外,值树现在是一个作用域指针,所以在声明滑块附件树的地方,它现在需要是一个唯一的指针,而不是作用域指针或原始指针。

代码语言:javascript
复制
std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> sliderOctTree;
std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> sliderToneTree;
std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> sliderTuneTree;

例如,您还需要使您的新sliderTree值具有唯一性。更改为新的std::make_unique,并将您的滑块附件范围AKA AudioProcessorValueTreeState::SliderAttachment中的尖括号。

代码语言:javascript
复制
 sliderTree = std::make_unique <AudioProcessorValueTreeState::SliderAttachment>(processor.tree, "osc1_attack", osc1AttackSlider);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50669459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档