Hi there, in the editor I have a nested component (several levels):
A Sequence containg bars
Some Bars containing Steps
Some Steps containing info on note value velocity and such
This is for the ui. So I Instantiate my Sequnce and then the sequnce instatiates some bars and each bar instatiates some steps. All fine and dandy and it doesnt look great by now but it all works.
Now I change a value in one of the steps (or the amount of steps in a bar or the amount of bars in a seqeunce). The dynamic creation of the objects and stuff and repainting is no problem.
Ho would you go to get thisinformaton up to the Editor so it can communicate it to the processor (maybe Valuetreestate or such but that is not the question)
I could run a timer in my top level component and cycle through all subcomponents and collect data, which I belive is not the right way
I could on the change of a subcomponent call a function on the parent and let it know about the change and the parent will call its parent all the way up. This is I believe a better way.
I could attach all values to a ValueTreestate right away in the subcomponents but as I am having for example a lot of steps in a bar how would I go about the naming ? Give an ID to the step or bar and include it in the name?
I believe its definitely not method one, which would of course perfectly work, my preferred is option two and then create all the ValueTree members in the top level component at once.
I have no code to show yet as I did not start implementing any of this but I have for example the step component (see below)
Any advise ?
thanks in advanced
.h
class SqStep : public juce::Component,
juce::Slider::Listener
{
public:
SqStep();
~SqStep() override;
void paint(juce::Graphics&) override;
void resized() override;
void sliderValueChanged(juce::Slider* slider) override;
struct StepData
{
int stPitch = 36;
int stOctave = 1;
juce::uint8 stVelocity =100;
float stDuration = 0.75f;
};
private:
juce::Slider pitchSlider;
juce::Slider octaveSlider;
juce::Slider velocitySlider;
juce::Slider durationSlider;
StepData stepData;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SqStep)
};```
cpp
SqStep::SqStep()
{
pitchSlider.setRange(juce::Range<double>(1, 12),1.0);
pitchSlider.setValue(12);
pitchSlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
pitchSlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 0, 0);
pitchSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::green);
addAndMakeVisible(pitchSlider);
pitchSlider.addListener(this);
octaveSlider.setRange(juce::Range<double>(0, 6), 1.0);
octaveSlider.setValue(3);
octaveSlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
octaveSlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox,false,0,0);
octaveSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::darkgreen);
addAndMakeVisible(octaveSlider);
octaveSlider.addListener(this);
durationSlider.setRange(juce::Range<double>(0, 1), 0.05f);
durationSlider.setValue(0.75f);
durationSlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
durationSlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 0, 0);
durationSlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::darkorange);
addAndMakeVisible(durationSlider);
durationSlider.addListener(this);
velocitySlider.setRange(juce::Range<double>(0, 127), 1.0);
velocitySlider.setValue(100);
velocitySlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
velocitySlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 0, 0);
velocitySlider.setColour(juce::Slider::ColourIds::trackColourId, juce::Colours::blueviolet);
addAndMakeVisible(velocitySlider);
velocitySlider.addListener(this);
}
SqStep::~SqStep()
{
}
void SqStep::paint(juce::Graphics & g)
{
g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId)); // clear the background
g.setColour(juce::Colours::white);
g.drawRect(getLocalBounds(), 1); // draw an outline around the component
}
void SqStep::resized()
{
auto myBounds = getLocalBounds();
myBounds.reduce(3, 3);
auto totalHeight = myBounds.getHeight();
auto sliderHeight = totalHeight * 0.3f;
auto rotaryHeight = totalHeight * 0.15f;
auto verticalSliderHeight = totalHeight * 0.1f;
auto dividerHeight = totalHeight * 0.05f;
octaveSlider.setBounds(myBounds.removeFromTop(rotaryHeight));
myBounds.removeFromTop(dividerHeight);
pitchSlider.setBounds(myBounds.removeFromTop(sliderHeight));
myBounds.removeFromTop(dividerHeight);
velocitySlider.setBounds(myBounds.removeFromTop(sliderHeight));
myBounds.removeFromTop(dividerHeight);
durationSlider.setBounds(myBounds.removeFromTop(verticalSliderHeight));
}
void SqStep::sliderValueChanged(juce::Slider * slider)
{
if (slider == &pitchSlider)
{
auto pitch = slider->getValue();
stepData.stPitch = (int) (stepData.stOctave * pitch);
}
if (slider == &octaveSlider)
{
auto octave = slider->getValue();
stepData.stOctave = octave;
}
if (slider == &velocitySlider)
{
auto velocity = slider->getValue();
stepData.stVelocity = velocity;
}
if (slider == &durationSlider)
{
auto duration = slider->getValue();
stepData.stDuration = duration;
}
}