From 5c310a16061f4777e6a8f7496355391a1d2aeffb Mon Sep 17 00:00:00 2001 From: Alex Birch Date: Sun, 21 Jul 2019 16:25:22 +0100 Subject: [PATCH] keyboard left/right triggers pill button click (as it used to). pills now send you to first valid preset in bank (as they used to). --- Source/Pills.cpp | 66 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/Source/Pills.cpp b/Source/Pills.cpp index 82601ff..fe8a3d6 100644 --- a/Source/Pills.cpp +++ b/Source/Pills.cpp @@ -62,13 +62,35 @@ void Pill::bankChanged(int bank) { // textButton.setToggleState(value == bank, dontSendNotification); // } -void Pill::buttonClicked (Button* button) { +void Pill::buttonClicked(Button* button) { + ValueTree banks{valueTreeState.state.getChildWithName("banks")}; + int banksChildren{banks.getNumChildren()}; + ValueTree bank; + for(int bankIx{0}; bankIxbank) { + bank = currentBank; + break; + } + } + 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 (param) != nullptr); - AudioParameterInt* castParam {dynamic_cast (param)}; - *castParam = bank; + { + RangedAudioParameter *param{valueTreeState.getParameter("bank")}; + jassert(dynamic_cast(param) != nullptr); + AudioParameterInt* castParam{dynamic_cast(param)}; + *castParam = this->bank; + } + { + RangedAudioParameter *param{valueTreeState.getParameter("preset")}; + jassert(dynamic_cast(param) != nullptr); + AudioParameterInt* castParam{dynamic_cast(param)}; + *castParam = presetNum; + } } // void Pill::parameterChanged(const String& parameterID, float newValue) { @@ -208,31 +230,41 @@ void Pills::cycle(bool right) { RangedAudioParameter *param {valueTreeState.getParameter("bank")}; jassert(dynamic_cast (param) != nullptr); AudioParameterInt* castParam {dynamic_cast (param)}; - int currentlySelectedBank{castParam->get()}; + int bank{castParam->get()}; - ValueTree banks{valueTreeState.state.getChildWithName("banks")}; + // ValueTree banks{valueTreeState.state.getChildWithName("banks")}; // int numChildren{banks.getNumChildren()}; - vector bankInts; - bankInts.resize(banks.getNumChildren()); + // vector bankInts; + // bankInts.resize(banks.getNumChildren()); - transform(banks.begin(), banks.end(), bankInts.begin(), [](ValueTree bank) -> int { - return bank.getProperty("num"); - }); + // transform(banks.begin(), banks.end(), bankInts.begin(), [](ValueTree bank) -> int { + // return bank.getProperty("num"); + // }); -// int closestBank{currentlySelectedBank}; +// int closestBank{bank}; // for(int i{0}; i < numChildren; i++) { // ValueTree child{banks.getChild(i)}; // int proposedBank{child.getProperty("num")}; -// if (right && proposedBank > currentlySelectedBank) { +// if (right && proposedBank > bank) { // closestBank = jmin(closestBank, proposedBank); // } else if (left ) // } - int currentIx{static_cast(distance(bankInts.begin(), find(bankInts.begin(), bankInts.end(), currentlySelectedBank)))}; + // int currentIx{static_cast(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( + distance( + pills.begin(), + find_if( + pills.begin(), + pills.end(), + [bank](unique_ptr& pill){return pill->bank == bank;}))); currentIx += right ? 1 : pills.size()-1; - // pills[currentIx % pills.size()]->textButton.triggerClick(); - *castParam = bankInts[currentIx % bankInts.size()]; + pills[currentIx % pills.size()]->textButton.triggerClick(); // TODO: base this on valueTree