remove unused, reduce duplication
This commit is contained in:
parent
79c023d466
commit
ba6bec2d9d
|
@ -44,6 +44,7 @@
|
|||
allowLocationSimulation = "YES">
|
||||
<PathRunnable
|
||||
runnableDebuggingMode = "0"
|
||||
BundleIdentifier = "com.roli.juce.pluginhost"
|
||||
FilePath = "/Applications/JUCE/extras/AudioPluginHost/Builds/MacOSX/build/Debug/AudioPluginHost.app">
|
||||
</PathRunnable>
|
||||
<MacroExpansion>
|
||||
|
|
|
@ -168,29 +168,9 @@ void FluidSynthModel::initialise() {
|
|||
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) {
|
||||
if (parameterID == "bank") {
|
||||
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") {
|
||||
if (programChangeParams.contains(parameterID)) {
|
||||
int bank, preset;
|
||||
{
|
||||
RangedAudioParameter *param{valueTreeState.getParameter("bank")};
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
void changeProgramName(int index, const String& newName);
|
||||
|
||||
private:
|
||||
// static const StringArray controllerParams;
|
||||
static const StringArray programChangeParams;
|
||||
|
||||
// there's no bimap in the standard library!
|
||||
static const map<fluid_midi_control_change, String> controllerToParam;
|
||||
|
|
132
Source/Pills.cpp
132
Source/Pills.cpp
|
@ -14,7 +14,6 @@ Pill::Pill(
|
|||
bool isFirst,
|
||||
bool isLast
|
||||
)
|
||||
// : pills{pills}
|
||||
: valueTreeState{valueTreeState}
|
||||
, bank{bank}
|
||||
, textButton{String(bank)}
|
||||
|
@ -25,13 +24,9 @@ Pill::Pill(
|
|||
| (isLast ? 0 : Button::ConnectedOnRight)
|
||||
);
|
||||
textButton.setRadioGroupId(34567);
|
||||
// loadToggleState();
|
||||
textButton.setClickingTogglesState(true);
|
||||
|
||||
addAndMakeVisible(textButton);
|
||||
|
||||
// valueTreeState.addParameterListener("bank", this);
|
||||
// valueTreeState.state.addListener(this);
|
||||
textButton.addListener(this);
|
||||
}
|
||||
|
||||
|
@ -45,8 +40,6 @@ void Pill::resized() {
|
|||
}
|
||||
|
||||
Pill::~Pill() {
|
||||
// valueTreeState.removeParameterListener("bank", this);
|
||||
// valueTreeState.state.removeListener(this);
|
||||
textButton.removeListener(this);
|
||||
}
|
||||
|
||||
|
@ -54,14 +47,6 @@ void Pill::bankChanged(int bank) {
|
|||
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) {
|
||||
ValueTree banks{valueTreeState.state.getChildWithName("banks")};
|
||||
int banksChildren{banks.getNumChildren()};
|
||||
|
@ -77,8 +62,6 @@ void Pill::buttonClicked(Button* button) {
|
|||
ValueTree preset{bank.getChild(0)};
|
||||
int presetNum{preset.getProperty("num")};
|
||||
|
||||
// selected = button;
|
||||
// onItemSelected(itemToIDMapper(button->getName().toStdString()));
|
||||
{
|
||||
RangedAudioParameter *param{valueTreeState.getParameter("bank")};
|
||||
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(
|
||||
AudioProcessorValueTreeState& valueTreeState
|
||||
// string label,
|
||||
// const vector<string> &items,
|
||||
// const function<void (int)> &onItemSelected,
|
||||
// const function<int (const string&)> &itemToIDMapper,
|
||||
// int initiallySelectedItem
|
||||
)
|
||||
: valueTreeState{valueTreeState}
|
||||
// , label{label}
|
||||
// items(items),
|
||||
// onItemSelected(onItemSelected),
|
||||
// itemToIDMapper(itemToIDMapper)
|
||||
{
|
||||
// faster (rounded edges introduce transparency)
|
||||
setOpaque (true);
|
||||
|
||||
// populate(initiallySelectedItem);
|
||||
ValueTree banks{valueTreeState.state.getChildWithName("banks")};
|
||||
loadModelFrom(banks);
|
||||
|
||||
|
@ -169,9 +128,6 @@ void Pills::loadModelFrom(ValueTree& banks) {
|
|||
for(int i{0}; i < numChildren; i++) {
|
||||
ValueTree child{banks.getChild(i)};
|
||||
int num{child.getProperty("num")};
|
||||
// rows.push_back(unique_ptr<Pill>(new Pill(), [](Pill* pill) {
|
||||
// pill->remo
|
||||
// }));
|
||||
unique_ptr<Pill> pill{make_unique<Pill>(
|
||||
valueTreeState,
|
||||
num,
|
||||
|
@ -184,99 +140,29 @@ void Pills::loadModelFrom(ValueTree& banks) {
|
|||
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) {
|
||||
RangedAudioParameter *param {valueTreeState.getParameter("bank")};
|
||||
jassert(dynamic_cast<AudioParameterInt*> (param) != nullptr);
|
||||
AudioParameterInt* castParam {dynamic_cast<AudioParameterInt*> (param)};
|
||||
RangedAudioParameter *param{valueTreeState.getParameter("bank")};
|
||||
jassert(dynamic_cast<AudioParameterInt*>(param) != nullptr);
|
||||
AudioParameterInt* castParam{dynamic_cast<AudioParameterInt*> (param)};
|
||||
int bank{castParam->get()};
|
||||
|
||||
// ValueTree banks{valueTreeState.state.getChildWithName("banks")};
|
||||
// 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>(
|
||||
int currentIx{static_cast<const int>(
|
||||
distance(
|
||||
pills.begin(),
|
||||
find_if(
|
||||
pills.begin(),
|
||||
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;
|
||||
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() {
|
||||
int index = 0;
|
||||
Rectangle<int> r (getLocalBounds());
|
||||
const int equalWidth = r.proportionOfWidth(pills.size() <= 0 ? 1.0 : 1.0f/pills.size());
|
||||
int index{0};
|
||||
Rectangle<int> r{getLocalBounds()};
|
||||
const int equalWidth{r.proportionOfWidth(pills.size() <= 0 ? 1.0 : 1.0f/pills.size())};
|
||||
for(auto& pill : pills) {
|
||||
Rectangle<int> r2 (getLocalBounds());
|
||||
r2.removeFromLeft(equalWidth * index);
|
||||
|
|
Loading…
Reference in New Issue
Block a user