remove unused, reduce duplication

This commit is contained in:
Alex Birch 2019-07-30 21:12:49 +01:00
parent 79c023d466
commit ba6bec2d9d
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
4 changed files with 13 additions and 146 deletions

View File

@ -44,6 +44,7 @@
allowLocationSimulation = "YES"> allowLocationSimulation = "YES">
<PathRunnable <PathRunnable
runnableDebuggingMode = "0" runnableDebuggingMode = "0"
BundleIdentifier = "com.roli.juce.pluginhost"
FilePath = "/Applications/JUCE/extras/AudioPluginHost/Builds/MacOSX/build/Debug/AudioPluginHost.app"> FilePath = "/Applications/JUCE/extras/AudioPluginHost/Builds/MacOSX/build/Debug/AudioPluginHost.app">
</PathRunnable> </PathRunnable>
<MacroExpansion> <MacroExpansion>

View File

@ -168,29 +168,9 @@ void FluidSynthModel::initialise() {
fluid_synth_add_default_mod(synth.get(), mod.get(), FLUID_SYNTH_ADD); fluid_synth_add_default_mod(synth.get(), mod.get(), FLUID_SYNTH_ADD);
} }
const StringArray FluidSynthModel::programChangeParams{"bank", "preset"};
void FluidSynthModel::parameterChanged(const String& parameterID, float newValue) { void FluidSynthModel::parameterChanged(const String& parameterID, float newValue) {
if (parameterID == "bank") { if (programChangeParams.contains(parameterID)) {
int bank, preset;
{
RangedAudioParameter *param{valueTreeState.getParameter("bank")};
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
AudioParameterInt* castParam{dynamic_cast<AudioParameterInt*>(param)};
bank = castParam->get();
}
{
RangedAudioParameter *param{valueTreeState.getParameter("preset")};
jassert(dynamic_cast<AudioParameterInt*>(param) != nullptr);
AudioParameterInt* castParam{dynamic_cast<AudioParameterInt*>(param)};
preset = castParam->get();
}
int bankOffset{fluid_synth_get_bank_offset(synth.get(), sfont_id)};
fluid_synth_program_select(
synth.get(),
channel,
sfont_id,
static_cast<unsigned int>(bankOffset + bank),
static_cast<unsigned int>(preset));
} else if (parameterID == "preset") {
int bank, preset; int bank, preset;
{ {
RangedAudioParameter *param{valueTreeState.getParameter("bank")}; RangedAudioParameter *param{valueTreeState.getParameter("bank")};

View File

@ -55,7 +55,7 @@ public:
void changeProgramName(int index, const String& newName); void changeProgramName(int index, const String& newName);
private: private:
// static const StringArray controllerParams; static const StringArray programChangeParams;
// there's no bimap in the standard library! // there's no bimap in the standard library!
static const map<fluid_midi_control_change, String> controllerToParam; static const map<fluid_midi_control_change, String> controllerToParam;

View File

@ -14,7 +14,6 @@ Pill::Pill(
bool isFirst, bool isFirst,
bool isLast bool isLast
) )
// : pills{pills}
: valueTreeState{valueTreeState} : valueTreeState{valueTreeState}
, bank{bank} , bank{bank}
, textButton{String(bank)} , textButton{String(bank)}
@ -25,13 +24,9 @@ Pill::Pill(
| (isLast ? 0 : Button::ConnectedOnRight) | (isLast ? 0 : Button::ConnectedOnRight)
); );
textButton.setRadioGroupId(34567); textButton.setRadioGroupId(34567);
// loadToggleState();
textButton.setClickingTogglesState(true); textButton.setClickingTogglesState(true);
addAndMakeVisible(textButton); addAndMakeVisible(textButton);
// valueTreeState.addParameterListener("bank", this);
// valueTreeState.state.addListener(this);
textButton.addListener(this); textButton.addListener(this);
} }
@ -45,8 +40,6 @@ void Pill::resized() {
} }
Pill::~Pill() { Pill::~Pill() {
// valueTreeState.removeParameterListener("bank", this);
// valueTreeState.state.removeListener(this);
textButton.removeListener(this); textButton.removeListener(this);
} }
@ -54,14 +47,6 @@ void Pill::bankChanged(int bank) {
textButton.setToggleState(this->bank == bank, dontSendNotification); textButton.setToggleState(this->bank == bank, dontSendNotification);
} }
// void Pill::loadToggleState() {
// RangedAudioParameter *param {valueTreeState.getParameter("bank")};
// jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
// AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
// int value{castParam->get()};
// textButton.setToggleState(value == bank, dontSendNotification);
// }
void Pill::buttonClicked(Button* button) { void Pill::buttonClicked(Button* button) {
ValueTree banks{valueTreeState.state.getChildWithName("banks")}; ValueTree banks{valueTreeState.state.getChildWithName("banks")};
int banksChildren{banks.getNumChildren()}; int banksChildren{banks.getNumChildren()};
@ -77,8 +62,6 @@ void Pill::buttonClicked(Button* button) {
ValueTree preset{bank.getChild(0)}; ValueTree preset{bank.getChild(0)};
int presetNum{preset.getProperty("num")}; int presetNum{preset.getProperty("num")};
// selected = button;
// onItemSelected(itemToIDMapper(button->getName().toStdString()));
{ {
RangedAudioParameter *param{valueTreeState.getParameter("bank")}; RangedAudioParameter *param{valueTreeState.getParameter("bank")};
jassert(dynamic_cast<AudioParameterInt*>(param) != nullptr); jassert(dynamic_cast<AudioParameterInt*>(param) != nullptr);
@ -93,38 +76,14 @@ void Pill::buttonClicked(Button* button) {
} }
} }
// void Pill::parameterChanged(const String& parameterID, float newValue) {
// if (parameterID == "bank") {
// loadToggleState();
// }
// }
// void Pill::valueTreePropertyChanged(
// ValueTree& treeWhosePropertyHasChanged,
// const Identifier& property) {
// if (treeWhosePropertyHasChanged.getType() == StringRef("presets")) {
// loadModelFrom(treeWhosePropertyHasChanged);
// }
// }
Pills::Pills( Pills::Pills(
AudioProcessorValueTreeState& valueTreeState AudioProcessorValueTreeState& valueTreeState
// string label,
// const vector<string> &items,
// const function<void (int)> &onItemSelected,
// const function<int (const string&)> &itemToIDMapper,
// int initiallySelectedItem
) )
: valueTreeState{valueTreeState} : valueTreeState{valueTreeState}
// , label{label}
// items(items),
// onItemSelected(onItemSelected),
// itemToIDMapper(itemToIDMapper)
{ {
// faster (rounded edges introduce transparency) // faster (rounded edges introduce transparency)
setOpaque (true); setOpaque (true);
// populate(initiallySelectedItem);
ValueTree banks{valueTreeState.state.getChildWithName("banks")}; ValueTree banks{valueTreeState.state.getChildWithName("banks")};
loadModelFrom(banks); loadModelFrom(banks);
@ -169,9 +128,6 @@ void Pills::loadModelFrom(ValueTree& banks) {
for(int i{0}; i < numChildren; i++) { for(int i{0}; i < numChildren; i++) {
ValueTree child{banks.getChild(i)}; ValueTree child{banks.getChild(i)};
int num{child.getProperty("num")}; int num{child.getProperty("num")};
// rows.push_back(unique_ptr<Pill>(new Pill(), [](Pill* pill) {
// pill->remo
// }));
unique_ptr<Pill> pill{make_unique<Pill>( unique_ptr<Pill> pill{make_unique<Pill>(
valueTreeState, valueTreeState,
num, num,
@ -184,99 +140,29 @@ void Pills::loadModelFrom(ValueTree& banks) {
resized(); resized();
} }
// void Pills::populate(int initiallySelectedItem) {
// int index = 0;
// for (string item : items) {
// TextButton* pill = addToList(new TextButton(
// item
// ));
// // pill->setColour (TextButton::buttonOnColourId, Colours::blueviolet.brighter());
// // pill->setBounds(20 + index * 55, 260, 55, 24);
// pill->setConnectedEdges (
// (index == 0 ? 0 : Button::ConnectedOnLeft)
// | (index == (items.size()-1) ? 0 : Button::ConnectedOnRight)
// );
// pill->setRadioGroupId(34567);
// if (index == initiallySelectedItem) {
// pill->setToggleState(true, dontSendNotification);
// selected = pill;
// }
// pill->setClickingTogglesState(true);
// pill->addListener(this);
// index++;
// }
// }
// void Pills::setItems(
// const vector<string> &items,
// int initiallySelectedItem
// ) {
// this->items = items;
// for(TextButton* t : buttons) {
// t->removeListener(this);
// }
// buttons.clear(true);
// populate(initiallySelectedItem);
// resized();
// }
// TextButton* Pills::addToList (TextButton* newButton) {
// buttons.add (newButton);
// addAndMakeVisible (newButton);
// return newButton;
// }
void Pills::cycle(bool right) { void Pills::cycle(bool right) {
RangedAudioParameter *param {valueTreeState.getParameter("bank")}; RangedAudioParameter *param{valueTreeState.getParameter("bank")};
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr); jassert(dynamic_cast<AudioParameterInt*>(param) != nullptr);
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)}; AudioParameterInt* castParam{dynamic_cast<AudioParameterInt*> (param)};
int bank{castParam->get()}; int bank{castParam->get()};
// ValueTree banks{valueTreeState.state.getChildWithName("banks")}; int currentIx{static_cast<const int>(
// int numChildren{banks.getNumChildren()};
// vector<int> bankInts;
// bankInts.resize(banks.getNumChildren());
// transform(banks.begin(), banks.end(), bankInts.begin(), [](ValueTree bank) -> int {
// return bank.getProperty("num");
// });
// int closestBank{bank};
// for(int i{0}; i < numChildren; i++) {
// ValueTree child{banks.getChild(i)};
// int proposedBank{child.getProperty("num")};
// if (right && proposedBank > bank) {
// closestBank = jmin(closestBank, proposedBank);
// } else if (left )
// }
// int currentIx{static_cast<const int>(distance(bankInts.begin(), find(bankInts.begin(), bankInts.end(), currentlySelectedBank)))};
// currentIx += right ? 1 : pills.size()-1;
// // pills[currentIx % pills.size()]->textButton.triggerClick();
// *castParam = bankInts[currentIx % bankInts.size()];
int currentIx = static_cast<const int>(
distance( distance(
pills.begin(), pills.begin(),
find_if( find_if(
pills.begin(), pills.begin(),
pills.end(), pills.end(),
[bank](unique_ptr<Pill>& pill){return pill->bank == bank;}))); [bank](unique_ptr<Pill>& pill){
return pill->bank == bank;})))};
currentIx += right ? 1 : pills.size()-1; currentIx += right ? 1 : pills.size()-1;
pills[currentIx % pills.size()]->textButton.triggerClick(); pills[currentIx % pills.size()]->textButton.triggerClick();
// TODO: base this on valueTree
// int currentIx = static_cast<const int>(distance(pills.begin(), find(pills.begin(), pills.end(), selected)));
// currentIx += right ? 1 : pills.size()-1;
// pills[currentIx % pills.size()]->textButton.triggerClick();
} }
void Pills::resized() { void Pills::resized() {
int index = 0; int index{0};
Rectangle<int> r (getLocalBounds()); Rectangle<int> r{getLocalBounds()};
const int equalWidth = r.proportionOfWidth(pills.size() <= 0 ? 1.0 : 1.0f/pills.size()); const int equalWidth{r.proportionOfWidth(pills.size() <= 0 ? 1.0 : 1.0f/pills.size())};
for(auto& pill : pills) { for(auto& pill : pills) {
Rectangle<int> r2 (getLocalBounds()); Rectangle<int> r2 (getLocalBounds());
r2.removeFromLeft(equalWidth * index); r2.removeFromLeft(equalWidth * index);