From 0902c0897d5b497a25d17ce5e4c059b21d904fcc Mon Sep 17 00:00:00 2001 From: rorywalsh Date: Tue, 11 Jun 2019 10:48:22 +0100 Subject: [PATCH] tidying up getChannelDataFromCsound method --- .../Audio/Plugins/CabbagePluginProcessor.cpp | 18 ++++++++++------- .../Audio/Plugins/CsoundPluginProcessor.cpp | 20 ++++++++++++------- Source/Audio/Plugins/CsoundPluginProcessor.h | 1 + Source/Widgets/CabbageWidgetData.cpp | 2 +- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Source/Audio/Plugins/CabbagePluginProcessor.cpp b/Source/Audio/Plugins/CabbagePluginProcessor.cpp index b5a9e6443..feaff97c1 100644 --- a/Source/Audio/Plugins/CabbagePluginProcessor.cpp +++ b/Source/Audio/Plugins/CabbagePluginProcessor.cpp @@ -837,27 +837,26 @@ void CabbagePluginProcessor::getChannelDataFromCsound() for (int i = 0; i < cabbageWidgets.getNumChildren(); i++) { const var chanArray = CabbageWidgetData::getProperty(cabbageWidgets.getChild(i), CabbageIdentifierIds::channel); + const String channelName = (chanArray.size()>0 ? chanArray[0].toString() : chanArray.toString()); const var widgetArray = CabbageWidgetData::getProperty(cabbageWidgets.getChild(i), CabbageIdentifierIds::widgetarray); StringArray channels; if (widgetArray.size() > 0) - channels.add(CabbageWidgetData::getStringProp(cabbageWidgets.getChild(i), CabbageIdentifierIds::channel)); + channels.add(channelName); else if (chanArray.size() == 1) - channels.add(CabbageWidgetData::getStringProp(cabbageWidgets.getChild(i), CabbageIdentifierIds::channel)); + channels.add(channelName); else if (chanArray.size() > 1) { for (int j = 0; j < chanArray.size(); j++) channels.add(var(chanArray[j])); } const var value = CabbageWidgetData::getProperty(cabbageWidgets.getChild(i), CabbageIdentifierIds::value); - const float valuex = CabbageWidgetData::getNumProp(cabbageWidgets.getChild(i), CabbageIdentifierIds::valuex); - const float valuey = CabbageWidgetData::getNumProp(cabbageWidgets.getChild(i), CabbageIdentifierIds::valuey); + const String identChannel = CabbageWidgetData::getStringProp(cabbageWidgets.getChild(i), CabbageIdentifierIds::identchannel); - const String identChannelMessage = CabbageWidgetData::getStringProp(cabbageWidgets.getChild(i), - CabbageIdentifierIds::identchannelmessage); + const String typeOfWidget = CabbageWidgetData::getStringProp(cabbageWidgets.getChild(i), CabbageIdentifierIds::type); @@ -886,7 +885,10 @@ void CabbagePluginProcessor::getChannelDataFromCsound() //currently only dealing with a max of 2 channels... else if (channels.size() == 2 && channels[0].isNotEmpty() && channels[1].isNotEmpty() && - typeOfWidget != CabbageWidgetTypes::eventsequencer) { + typeOfWidget != CabbageWidgetTypes::eventsequencer) + { + const float valuex = CabbageWidgetData::getNumProp(cabbageWidgets.getChild(i), CabbageIdentifierIds::valuex); + const float valuey = CabbageWidgetData::getNumProp(cabbageWidgets.getChild(i), CabbageIdentifierIds::valuey); if (getCsound()->GetChannel(channels[0].toUTF8()) != valuex || getCsound()->GetChannel(channels[1].toUTF8()) != valuey) { if (typeOfWidget == CabbageWidgetTypes::xypad) { @@ -909,6 +911,8 @@ void CabbagePluginProcessor::getChannelDataFromCsound() } if (identChannel.isNotEmpty()) { + const String identChannelMessage = CabbageWidgetData::getStringProp(cabbageWidgets.getChild(i), + CabbageIdentifierIds::identchannelmessage); memset(&tmp_string[0], 0, sizeof(tmp_string)); getCsound()->GetStringChannel(identChannel.toUTF8(), tmp_string); diff --git a/Source/Audio/Plugins/CsoundPluginProcessor.cpp b/Source/Audio/Plugins/CsoundPluginProcessor.cpp index 3203b4b8d..0b733be5a 100755 --- a/Source/Audio/Plugins/CsoundPluginProcessor.cpp +++ b/Source/Audio/Plugins/CsoundPluginProcessor.cpp @@ -365,17 +365,23 @@ void CsoundPluginProcessor::createMatrixEventSequencer(int rows, int cols, Strin } matrixEventSequencers.add(matrix); + numMatrixEventSequencers = matrixEventSequencers.size(); + + } void CsoundPluginProcessor::setMatrixEventSequencerCellData(int col, int row, String channel, String data) { - for (int i = 0 ; i < matrixEventSequencers.size(); i++) - { - if (matrixEventSequencers[i]->channel == channel) - { - matrixEventSequencers[i]->setEventString(col, row, data); - } - } + if (numMatrixEventSequencers > 0) + { + for (int i = 0; i < matrixEventSequencers.size(); i++) + { + if (matrixEventSequencers[i]->channel == channel) + { + matrixEventSequencers[i]->setEventString(col, row, data); + } + } + } } //============================================================================== diff --git a/Source/Audio/Plugins/CsoundPluginProcessor.h b/Source/Audio/Plugins/CsoundPluginProcessor.h index 497f6df2e..ea667de1f 100755 --- a/Source/Audio/Plugins/CsoundPluginProcessor.h +++ b/Source/Audio/Plugins/CsoundPluginProcessor.h @@ -118,6 +118,7 @@ class CsoundPluginProcessor : public AudioProcessor, public AsyncUpdater }; + int numMatrixEventSequencers = 0; void createMatrixEventSequencer(int rows, int cols, String channel); void setMatrixEventSequencerCellData(int row, int col, String channel, String data); //============================================================================= diff --git a/Source/Widgets/CabbageWidgetData.cpp b/Source/Widgets/CabbageWidgetData.cpp index 259a6ba62..7ddcadeeb 100755 --- a/Source/Widgets/CabbageWidgetData.cpp +++ b/Source/Widgets/CabbageWidgetData.cpp @@ -1126,7 +1126,7 @@ float CabbageWidgetData::getNumProp (ValueTree widgetData, Identifier prop) if (props.size() > 0) return props[0]; else - return getProperty (widgetData, prop); + return props; }