Skip to content

Commit

Permalink
Modulatino Overview Sliders actually mod values
Browse files Browse the repository at this point in the history
values modify, synth updated, etc...

Still a lot to do but this is a great proof of concept

Addresses surge-synthesizer#2049
  • Loading branch information
baconpaul committed May 2, 2021
1 parent 1b9bddd commit 1e1c225
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/common/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3538,7 +3538,7 @@ void Parameter::set_value_f01(float v, bool force_integer)
bound_value(force_integer);
}

float Parameter::get_modulation_f01(float mod)
float Parameter::get_modulation_f01(float mod) const
{
if (ctrltype == ct_none)
return 0;
Expand All @@ -3551,7 +3551,7 @@ float Parameter::get_modulation_f01(float mod)
return limit_range(v, -1.0f, 1.0f);
}

float Parameter::set_modulation_f01(float v)
float Parameter::set_modulation_f01(float v) const
{
if (ctrltype == ct_none)
return 0;
Expand Down
12 changes: 8 additions & 4 deletions src/common/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,14 @@ class Parameter
void set_value_f01(float v, bool force_integer = false);
bool set_value_from_string(std::string s);
bool set_value_from_string_onto(std::string s, pdata &ontoThis);
float
get_modulation_f01(float mod); // used by the gui to get the position of the modulated handle
float set_modulation_f01(float v); // used by the gui to set the modulation to match the
// position of the modulated handle

/*
* These two functions convert the modulation depth to a -1,1 range appropriate
* for this parameter
*/
float get_modulation_f01(float mod) const;
float set_modulation_f01(float v) const;

float calculate_modulation_value_from_string(const std::string &s, bool &valid);

void bound_value(bool force_integer = false);
Expand Down
37 changes: 32 additions & 5 deletions src/gui/ModulationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ struct ModulationListBoxModel : public juce::ListBoxModel
std::string hLab;
int dest_id = -1, source_id = -1;
std::string dest_name, source_name;
int modNum;

float depth;
bool isBipolar;
int modNum = -1;

float depth = 0;
bool isBipolar = false;
// const Parameter *p;
Parameter *p = nullptr; // When we do proper consting return to this
ModulationDisplayInfoWindowStrings mss;
};
std::vector<Datum> rows;
Expand Down Expand Up @@ -108,12 +109,19 @@ struct ModulationListBoxModel : public juce::ListBoxModel
modSlider->setSliderStyle(juce::Slider::LinearHorizontal);
modSlider->setTextBoxStyle(juce::Slider::NoTextBox, false, 0, 0);
modSlider->setRange(-1, 1);
modSlider->setValue(mod->rows[row].depth, juce::NotificationType::dontSendNotification);
modSlider->setValue(mod->rows[row].p->get_modulation_f01(mod->rows[row].depth),
juce::NotificationType::dontSendNotification);
modSlider->addListener(this);
addAndMakeVisible(*modSlider);
}
void sliderValueChanged(juce::Slider *slider) override
{
auto rd = mod->rows[row];
auto um = rd.p->set_modulation_f01(slider->getValue());
mod->moded->synth->setModulation(rd.dest_id, (modsources)rd.source_id,
slider->getValue());
mod->updateRowByModnum(rd.modNum);
mod->moded->repaint();
// std::cout << "SVC " << slider->getValue() << std::endl;
}
void buttonClicked(juce::Button *button) override
Expand Down Expand Up @@ -175,6 +183,23 @@ struct ModulationListBoxModel : public juce::ListBoxModel

int getNumRows() override { return rows.size(); }

void updateRowByModnum(int modnum)
{
// bit inefficient for now
for (auto &r : rows)
{
if (r.modNum == modnum)
{
char pdisp[TXT_SIZE];
int ptag = r.p->id;
modsources thisms = (modsources)r.source_id;
r.p->get_display_of_modulation_depth(pdisp, moded->synth->getModDepth(ptag, thisms),
moded->synth->isBipolarModulation(thisms),
Parameter::InfoWindow, &(r.mss));
r.depth = moded->synth->getModDepth(ptag, thisms);
}
}
}
void updateRows()
{
rows.clear();
Expand All @@ -188,6 +213,7 @@ struct ModulationListBoxModel : public juce::ListBoxModel
oss << type << "\n";
auto h = Datum(Datum::HEADER);
h.hLab = type;
h.modNum = -1;
rows.push_back(h);

char nm[TXT_SIZE], dst[TXT_SIZE];
Expand All @@ -203,6 +229,7 @@ struct ModulationListBoxModel : public juce::ListBoxModel
rDisp.source_name = sname;
rDisp.dest_name = nm;
rDisp.modNum = modNum++;
rDisp.p = moded->synth->storage.getPatch().param_ptr[rDisp.dest_id];

char pdisp[256];
auto p = moded->synth->storage.getPatch().param_ptr[q.destination_id + idBase];
Expand Down

0 comments on commit 1e1c225

Please sign in to comment.