diff --git a/ports/cabbage/source/Editor/CodeEditor.cpp b/ports/cabbage/source/Editor/CodeEditor.cpp index 7ed1782d..b3b3a13d 100644 --- a/ports/cabbage/source/Editor/CodeEditor.cpp +++ b/ports/cabbage/source/Editor/CodeEditor.cpp @@ -55,7 +55,193 @@ void CsoundCodeEditor::highlightLine(String line){ //setHighlightedRegion(range); } -void CsoundCodeEditor::addPopupMenuItems (PopupMenu &menuToAddTo, const MouseEvent *mouseClickEvent){ +bool CsoundCodeEditor::keyPressed (const KeyPress& key) +{ + //Logger::writeToLog(String(key.getKeyCode())); + if (key.getTextDescription().contains("cursor up") || key.getTextDescription().contains("cursor down") + || key.getTextDescription().contains("cursor left") || key.getTextDescription().contains("cursor right")) + handleEscapeKey(); + + if (! TextEditorKeyMapper::invokeKeyFunction (*this, key)) + { + + if (key == KeyPress::returnKey) + handleReturnKey(); + + else if (key == KeyPress::escapeKey) + handleEscapeKey(); + //else if (key == KeyPress ('[', ModifierKeys::commandModifier, 0)) unindentSelection(); + //else if (key == KeyPress (']', ModifierKeys::commandModifier, 0)) indentSelection(); + else if (key.getTextCharacter() >= ' ') + insertTextAtCaret (String::charToString (key.getTextCharacter())); + //insertMultiTextAtCaret(String::charToString (key.getTextCharacter())); + + else if(key.getKeyCode() == 268435488) + handleTabKey("backwards"); + else if(key == KeyPress::tabKey) + handleTabKey("forwards"); + + + else + return false; + } + //handleUpdateNowIfNeeded(); + return true; +} + +void CsoundCodeEditor::handleReturnKey (){ +if(type=="csound"){ + insertNewLine("\n"); + sendActionMessage("make popup invisible"); +} +} + + +void CsoundCodeEditor::insertText(String text){ + pos1 = getCaretPos(); + getDocument().insertText(pos1, text); +} + + +void CsoundCodeEditor::insertNewLine(String text){ + pos1 = getCaretPos(); + StringArray csdArray; + csdArray.addLines(getAllText()); + String curLine = csdArray[pos1.getLineNumber()]; + int numberOfTabs=0; + String tabs; + while(curLine.substring(numberOfTabs, numberOfTabs+1).equalsIgnoreCase("\t")){ + tabs.append("\t", 8); + numberOfTabs++; + } + Logger::writeToLog("Number of tabs:"+String(numberOfTabs)); + getDocument().insertText(pos1, text+tabs); +} + +void CsoundCodeEditor::insertMultiTextAtCaret (String text) +{ + sendActionMessage("make popup invisible"); + StringArray csdArray; + csdArray.addLines(getAllText()); + String curLine; + CodeDocument::Position newPos, indexPos; + newPos = getCaretPos();//getSelectionStartCaretPos(); + int currentLine = getCaretPos().getLineNumber(); + int index = newPos.getIndexInLine(); + Logger::writeToLog(String(index)); + + StringArray selectedText; + selectedText.addLines(getTextInRange(this->getHighlightedRegion())); + + + for(int i=0;i0) + highlightLine(selectedText.joinIntoString("\n")); + else + moveCaretTo(CodeDocument::Position (getDocument(), getAllText().indexOf(currentLine.substring(1))), false); + + sendActionMessage("make popup invisible"); +} + +void CsoundCodeEditor::toggleComments() +{ + StringArray selectedText; + selectedText.addLines(getSelectedText()); + StringArray csdArray; + csdArray.addLines(this->getAllText()); + String lastLine; + + for(int i=0;isetAllText(csdArray.joinIntoString("\n")); + moveCaretTo(CodeDocument::Position (getDocument(), getAllText().indexOf(lastLine)+lastLine.length()), false); +} + +//=================== addPopupMenuItems ======================= +void CsoundCodeEditor::addPopupMenuItems (PopupMenu &menuToAddTo, const MouseEvent *mouseClickEvent) +{ menuToAddTo.addItem(1, "Cut"); menuToAddTo.addItem(1, "Copy"); menuToAddTo.addItem(1, "Paste"); @@ -64,32 +250,29 @@ void CsoundCodeEditor::addPopupMenuItems (PopupMenu &menuToAddTo, const MouseEve menuToAddTo.addItem(1, "Undo"); menuToAddTo.addItem(1, "Redo"); menuToAddTo.addItem(10, "Add to repo"); - PopupMenu m; - int repoIndex = 100; ScopedPointer xmlElement; xmlElement = appProperties->getUserSettings()->getXmlValue("CopeRepoXmlData"); - + if(xmlElement) forEachXmlChildElement (*xmlElement, e) { m.addItem(repoIndex, e->getTagName()); repoEntries.add(e->getTagName()); repoIndex++; } - xmlElement =nullptr; menuToAddTo.addSubMenu("Insert from repo", m); - }; + Rectangle CsoundCodeEditor::getCaretPoisition() { pos1 = getCaretPos(); -return getCharacterBounds(pos1); - +return getCharacterBounds(pos1); } + void CsoundCodeEditor::performPopupMenuAction (int menuItemID){ if(menuItemID==1000){ pos1 = getDocument().findWordBreakBefore(getCaretPos()); @@ -125,6 +308,23 @@ void CsoundCodeEditor::addRepoToSettings() } +void CsoundCodeEditor::updateCaretPosition() +{ + /* + Logger::writeToLog("Updating caret position"); + int columnEdit = 1; + + if(columnEdit==1){ + StringArray selectedText; + selectedText.addLines(getTextInRange(this->getHighlightedRegion())); + Rectangle newCaretPosition(getCharacterBounds(getSelectionStartCaretPosition())); + newCaretPosition.setHeight(getCharacterBounds (getCaretPos()).getHeight()*selectedText.size()); + caret->setCaretPosition (newCaretPosition); + } + else*/ + setCaretPos(getCharacterBounds (getCaretPos())); +} + void CsoundCodeEditor::addToRepository() { AlertWindow alert("Add to Repository", "Enter a name and hit 'escape'", AlertWindow::NoIcon, this->getTopLevelComponent()); @@ -153,11 +353,6 @@ void CsoundCodeEditor::addToRepository() } } -void CsoundCodeEditor::insertText(String text){ - pos1 = getCaretPos(); - getDocument().insertText(pos1, text); -} - String CsoundCodeEditor::getLineText(){ StringArray csdLines; csdLines.addLines(getDocument().getAllContent()); @@ -236,19 +431,20 @@ textChanged = true; pos1 = getDocument().findWordBreakBefore(getCaretPos()); String lineFromCsd = getDocument().getLine(pos1.getLineNumber()); -int val = CabbageUtils::getPreference(appProperties, "EnablePopupDisplay"); -if(val){ - String parsedString; +if(CabbageUtils::getPreference(appProperties, "EnablePopupDisplay")) + { + String opcodeHelpString; StringArray syntaxTokens, csdLineTokens; csdLineTokens.clear(); - csdLineTokens.addTokens(lineFromCsd, " ", "\n"); + csdLineTokens.addTokens(lineFromCsd, " ,\t", ""); for(int i=0;i3) for(int x=0;x3){ //Logger::writeToLog(syntaxTokens[0]); @@ -268,4 +464,4 @@ if(val){ void CsoundCodeEditor::codeDocumentTextDeleted(int,int){ textChanged = true; sendActionMessage("make popup invisible"); -} \ No newline at end of file +} diff --git a/ports/cabbage/source/Editor/CodeEditor.h b/ports/cabbage/source/Editor/CodeEditor.h index bbbdb1a6..9ea7d56a 100644 --- a/ports/cabbage/source/Editor/CodeEditor.h +++ b/ports/cabbage/source/Editor/CodeEditor.h @@ -41,35 +41,12 @@ class CsoundCodeEditor : public CodeEditorComponent, ~CsoundCodeEditor(); - bool keyPressed (const KeyPress& key){ - //Logger::writeToLog(key.getTextDescription()); - if (key.getTextDescription().contains("cursor up") || key.getTextDescription().contains("cursor down") - || key.getTextDescription().contains("cursor left") || key.getTextDescription().contains("cursor right")) - handleEscapeKey(); + bool keyPressed (const KeyPress& key); + void handleTabKey(String direction); + void toggleComments(); - if (! TextEditorKeyMapper::invokeKeyFunction (*this, key)) - { - - if (key == KeyPress::returnKey) - handleReturnKey(); - - else if (key == KeyPress::escapeKey) - handleEscapeKey(); - //else if (key == KeyPress ('[', ModifierKeys::commandModifier, 0)) unindentSelection(); - //else if (key == KeyPress (']', ModifierKeys::commandModifier, 0)) indentSelection(); - else if (key.getTextCharacter() >= ' ') - insertTextAtCaret (String::charToString (key.getTextCharacter())); - else - return false; - } - //handleUpdateNowIfNeeded(); - return true; - } - - void handleDirectionKey(){ - - } + void handleDirectionKey(){} void handleEscapeKey(){ if(type=="python") @@ -78,13 +55,7 @@ class CsoundCodeEditor : public CodeEditorComponent, sendActionMessage("make popup invisible"); } - void handleReturnKey (){ - if(type=="csound"){ - insertText("\n"); - sendActionMessage("make popup invisible"); - } - } - + void handleReturnKey (); void addPopupMenuItems (PopupMenu &menuToAddTo, const MouseEvent *mouseClickEvent); void performPopupMenuAction (int menuItemID); String getLineText(); @@ -103,11 +74,13 @@ class CsoundCodeEditor : public CodeEditorComponent, void codeDocumentTextDeleted(int,int); void codeDocumentTextInserted(const juce::String &,int); bool textChanged; - + void insertNewLine(String text); void setOpcodeStrings(String opcodes){ - opcodeStrings.addLines(opcodes); + opcodeStrings.addLines(opcodes); } + void updateCaretPosition(); + void insertMultiTextAtCaret(String text); String getOpcodeToken(int index){ return opcodeTokens[index]; } diff --git a/ports/cabbage/source/Editor/CodeWindow.cpp b/ports/cabbage/source/Editor/CodeWindow.cpp index 8d4d3591..10b988ad 100644 --- a/ports/cabbage/source/Editor/CodeWindow.cpp +++ b/ports/cabbage/source/Editor/CodeWindow.cpp @@ -154,8 +154,8 @@ void CodeWindow::getCommandInfo (const CommandID commandID, ApplicationCommandIn result.setInfo (String("Paste"), String("Paste selection"), CommandCategories::edit, 0); result.addDefaultKeypress ('v', ModifierKeys::commandModifier); break; - case CommandIDs::editToggleText: - result.setInfo (String("Toggle output"), String("Toggle output"), CommandCategories::edit, 0); + case CommandIDs::editToggleComments: + result.setInfo (String("Toggle comments"), String("Toggle comments"), CommandCategories::edit, 0); result.addDefaultKeypress ('t', ModifierKeys::commandModifier); break; case CommandIDs::editZoomIn: @@ -274,7 +274,7 @@ else if(topLevelMenuIndex==1) m1.addCommandItem(&commandManager, CommandIDs::editCut); m1.addCommandItem(&commandManager, CommandIDs::editCopy); m1.addCommandItem(&commandManager, CommandIDs::editPaste); - m1.addCommandItem(&commandManager, CommandIDs::editToggleText); + m1.addCommandItem(&commandManager, CommandIDs::editToggleComments); m1.addSeparator(); m2.addCommandItem(&commandManager, CommandIDs::editZoomIn); m2.addCommandItem(&commandManager, CommandIDs::editZoomOut); @@ -386,9 +386,9 @@ bool CodeWindow::perform (const InvocationInfo& info) { textEditor->redo(); } - else if(info.commandID==CommandIDs::editToggleText) + else if(info.commandID==CommandIDs::editToggleComments) { - toggleTextWindows(); + textEditor->toggleComments(); } else if(info.commandID==CommandIDs::editZoomIn) @@ -445,11 +445,15 @@ bool CodeWindow::perform (const InvocationInfo& info) else if(info.commandID==CommandIDs::viewCsoundHelp) { + sendActionMessage("toggleCsoundOutput"); + sendActionMessage("hideOutputWindow"); toggleManuals("Csound"); } else if(info.commandID==CommandIDs::viewCabbageHelp) { + sendActionMessage("toggleCsoundOutput"); + sendActionMessage("hideOutputWindow"); toggleManuals("Cabbage"); } @@ -565,8 +569,10 @@ void CodeWindow::actionListenerCallback(const String &message){ toggleTextWindows(); //else if(message=="pythonFocus") // pythonEditor->textEditor->grabKeyboardFocus(); - else if(message=="make popup invisible") + else if(message=="make popup invisible"){ + popupDisplay->setTopLeftPosition(1000, 1000); popupDisplay->setVisible(false); + } else if(message=="sendPythonEvent"){ /* String text = pythonEditor->textEditor->getSelectedText(); String event = "pyruni {{\n"; @@ -600,7 +606,7 @@ void CodeWindow::actionListenerCallback(const String &message){ // this->getCaretScreenPosition().getY()+18.f, // width, 50); //popupDisplay->setWantsKeyboardFocus(false); - popupDisplay->setText(textEditor->getOpcodeToken(2).removeCharacters("\""), + popupDisplay->setText(textEditor->getOpcodeToken(2).removeCharacters("\""), textEditor->getOpcodeToken(3).removeCharacters("\"")); textEditor->toFront(true); @@ -671,7 +677,7 @@ untitledCSD= "a2 inch 2\n" "\n" "\n" -"outs a1, a2\n" +";outs a1, a2\n" "endin\n" "\n" " \n" diff --git a/ports/cabbage/source/Editor/CodeWindow.h b/ports/cabbage/source/Editor/CodeWindow.h index 67340ee3..67d81c5a 100644 --- a/ports/cabbage/source/Editor/CodeWindow.h +++ b/ports/cabbage/source/Editor/CodeWindow.h @@ -65,7 +65,7 @@ public: CommandIDs::editCut, CommandIDs::editPaste, CommandIDs::editRedo, - CommandIDs::editToggleText, + CommandIDs::editToggleComments, CommandIDs::editZoomIn, CommandIDs::editZoomOut, CommandIDs::whiteBackground, @@ -130,7 +130,7 @@ public: Rectangle getCaretScreenPosition(){ Rectangle rect(textEditor->getCaretPoisition()); - rect.setLeft(rect.getX()+this->getTopLevelComponent()->getX()+10); + rect.setLeft(rect.getX()+this->getTopLevelComponent()->getX()+100); rect.setTop(rect.getY()+this->getTopLevelComponent()->getY()+45); return rect; } @@ -444,7 +444,7 @@ class PopupDisplay : public DialogWindow, g.fillAll(Colour::fromRGB(40,40,40)); g.setColour(Colours::yellow); g.drawRect(0, 0, getWidth()-1, getHeight()-1, 1); - g.setFont(Font(String("Arial"), 16, 1)); + g.setFont(Font(String("Arial"), 16, 0)); g.setColour(Colours::whitesmoke); g.drawFittedText(syntax, 10, 10, getWidth(), getHeight(), Justification::topLeft, 100, 1); g.setFont(Font(String("Arial"), 15, 0)); @@ -454,7 +454,7 @@ class PopupDisplay : public DialogWindow, g.fillAll(Colour::fromRGB(20, 20, 20)); g.setColour(Colours::whitesmoke); g.drawRect(0, 0, getWidth()-1, getHeight()-1, 1); - g.setFont(Font(String("Arial"), 16, 1)); + g.setFont(Font(String("Arial"), 16, 0)); g.setColour(Colours::yellow); g.drawFittedText(syntax, 10, 10, getWidth(), getHeight(), Justification::topLeft, 100, 1); g.setFont(Font(String("Arial"), 15, 0)); diff --git a/ports/cabbage/source/Editor/CommandManager.h b/ports/cabbage/source/Editor/CommandManager.h index ab56218b..15ce74cc 100644 --- a/ports/cabbage/source/Editor/CommandManager.h +++ b/ports/cabbage/source/Editor/CommandManager.h @@ -44,7 +44,7 @@ namespace CommandIDs static const int editZoomOut = 2017; static const int whiteBackground = 2018; static const int blackBackground = 2019; - static const int editToggleText = 2020; + static const int editToggleComments = 2020; static const int insertFromRepo = 2021; static const int addFromRepo = 2022; static const int insertRecentEvent = 2023; diff --git a/ports/cabbage/source/Plugin/CabbagePluginEditor.cpp b/ports/cabbage/source/Plugin/CabbagePluginEditor.cpp index 2153ca8d..bc9a4c0f 100644 --- a/ports/cabbage/source/Plugin/CabbagePluginEditor.cpp +++ b/ports/cabbage/source/Plugin/CabbagePluginEditor.cpp @@ -154,15 +154,16 @@ layoutEditor->updateFrames(); //the data will only be sent to Csund when it's safe for(int index=0;indexgetGUILayoutCtrlsSize();index++) { - if(getFilter()->getGUILayoutCtrls(index).getStringProp("type")=="table") + if(getFilter()->getGUILayoutCtrls(index).getStringProp(CabbageIDs::type)=="table") { for(int y=0;ygetGUILayoutCtrls(index).getStringArrayProp("channels").size();y++) - getFilter()->messageQueue.addOutgoingChannelMessageToQueue(getFilter()->getGUILayoutCtrls(index).getStringArrayPropValue("channel", y).toUTF8(), -1.f, getFilter()->getGUILayoutCtrls(index).getStringProp("type")); + getFilter()->messageQueue.addOutgoingChannelMessageToQueue(getFilter()->getGUILayoutCtrls(index).getStringArrayPropValue(CabbageIDs::channel, y).toUTF8(), -1.f, getFilter()->getGUILayoutCtrls(index).getStringProp(CabbageIDs::type)); } } //start timer. Timer callback updates our GUI control states/positions, etc. with data from Csound -startTimer(20); +//startTimer(20); +getFilter()->addChangeListener(this); resized(); } @@ -174,6 +175,7 @@ CabbagePluginAudioProcessorEditor::~CabbagePluginAudioProcessorEditor() { comps.clear(true); layoutComps.clear(true); +getFilter()->removeChangeListener(this); removeAllChangeListeners(); //getFilter()->editorBeingDeleted(this); if(presetFileText.length()>1) @@ -188,6 +190,12 @@ if(presetFileText.length()>1) //=========================================================================== void CabbagePluginAudioProcessorEditor::changeListenerCallback(ChangeBroadcaster *source) { +//update our GUI controls when the filter says so! This is triggered by the +//CabbagePluginAudioProcessor::updateCabbageControls() +CabbagePluginAudioProcessor* filter = dynamic_cast(source); +if(filter) + updateGUIControls(); + #ifdef Cabbage_Build_Standalone ComponentLayoutEditor* le = dynamic_cast(source); if(le){ @@ -452,7 +460,7 @@ ComponentLayoutEditor* le = layoutEditor; for(int i=0;i newBounds(cAttr.getNumProp("left")-bounds.getX(), cAttr.getNumProp("top")-bounds.getY(), cAttr.getNumProp("width"), cAttr.getNumProp("height")); + Rectangle newBounds(cAttr.getNumProp(CabbageIDs::left)-bounds.getX(), cAttr.getNumProp(CabbageIDs::top)-bounds.getY(), cAttr.getNumProp(CabbageIDs::width), cAttr.getNumProp(CabbageIDs::height)); newPlantText.getReference(i) = replaceIdentifier(newPlantText[i], "bounds", getBoundsString(newBounds)); } @@ -506,10 +514,10 @@ ComponentLayoutEditor* le = layoutEditor; for(int i=0;i bounds(cAttr.getNumProp("left")+plantPos.getX(), - cAttr.getNumProp("top")+plantPos.getY(), - cAttr.getNumProp("width"), - cAttr.getNumProp("height")); + Rectangle bounds(cAttr.getNumProp(CabbageIDs::left)+plantPos.getX(), + cAttr.getNumProp(CabbageIDs::top)+plantPos.getY(), + cAttr.getNumProp(CabbageIDs::width), + cAttr.getNumProp(CabbageIDs::height)); brokenPlant.getReference(i) = replaceIdentifier(brokenPlant[i], "bounds", getBoundsString(bounds)); } //Logger::writeToLog(brokenPlant.joinIntoString("\n")); @@ -568,7 +576,7 @@ ComponentLayoutEditor* le = layoutEditor; //now that the line numbers have been located, remove GUI comps from relevant vectors for(int i=0;igetBounds()) @@ -737,9 +745,9 @@ ComponentLayoutEditor* le = layoutEditor; int numSelected = le->selectedCompsOrigCoordinates.size(); - if(CAttr.getNumProp("width")>0) + if(CAttr.getNumProp(CabbageIDs::width)>0) for(int y=0;yselectedCompsOrigCoordinates[y])); if(le->selectedCompsOrigCoordinates[y]==CAttr.getComponentBounds()) { lineNumbers.add(i); @@ -817,9 +825,10 @@ subm.addItem(8, "image"); subm.addItem(9, "keyboard"); subm.addItem(10, "xypad"); subm.addItem(11, "label"); -//subm.addItem(12, "infobutton"); +subm.addItem(16, "filebutton"); //subm.addItem(13, "soundfiler"); subm.addItem(14, "table"); +subm.addItem(15, "Csound message console"); m.addSubMenu(String("Indigenous"), subm); subm.clear(); @@ -855,10 +864,14 @@ int choice = m.show(); insertComponentsFromCabbageText(StringArray(String("label bounds(")+String(x)+(", ")+String(y)+String(", 50, 15), text(\"Label\"), fontcolour(\"white\")")), false); else if(choice==12) insertComponentsFromCabbageText(StringArray(String("infobutton bounds(")+String(x)+(", ")+String(y)+String(", 60, 25), text(\"Info\"), file(\"info.html\")")), false); + else if(choice==16) + insertComponentsFromCabbageText(StringArray(String("filebutton bounds(")+String(x)+(", ")+String(y)+String(", 60, 25), text(\"File\")")), false); else if(choice==13) insertComponentsFromCabbageText(StringArray(String("soundfiler bounds(")+String(x)+(", ")+String(y)+String(", 360, 160)")), false); else if(choice==14) insertComponentsFromCabbageText(StringArray(String("table bounds(")+String(x)+(", ")+String(y)+String(", 260, 160)")), false); + else if(choice==15) + insertComponentsFromCabbageText(StringArray(String("csoundoutput bounds(")+String(x)+(", ")+String(y)+String(", 360, 200)")), false); else if(choice>=100){ @@ -962,14 +975,14 @@ csdArray.addLines(getFilter()->getCsoundInputFileText()); String plantName = "GUIabst_"+String(getFilter()->getGUILayoutCtrlsSize()+numberPlantsToBeDuplicated); numberPlantsToBeDuplicated++; text.getReference(i) = replaceIdentifier(text[i], "plant", "plant(\""+plantName+"\")"); - Rectangle bounds(cAttr.getNumProp("left")+offset, cAttr.getNumProp("top")+offset, cAttr.getNumProp("width"), cAttr.getNumProp("height")); + Rectangle bounds(cAttr.getNumProp(CabbageIDs::left)+offset, cAttr.getNumProp(CabbageIDs::top)+offset, cAttr.getNumProp(CabbageIDs::width), cAttr.getNumProp(CabbageIDs::height)); text.getReference(i) = replaceIdentifier(text[i], "bounds", getBoundsString(bounds)); boundsForDuplicatedCtrls.add(bounds); } } else{ CabbageGUIClass cAttr(text[i], i-99); - Rectangle bounds(cAttr.getNumProp("left")+offset, cAttr.getNumProp("top")+offset, cAttr.getNumProp("width"), cAttr.getNumProp("height")); + Rectangle bounds(cAttr.getNumProp(CabbageIDs::left)+offset, cAttr.getNumProp(CabbageIDs::top)+offset, cAttr.getNumProp(CabbageIDs::width), cAttr.getNumProp(CabbageIDs::height)); text.getReference(i) = replaceIdentifier(text[i], "bounds", getBoundsString(bounds)); boundsForDuplicatedCtrls.add(bounds); } @@ -1019,7 +1032,7 @@ if(layoutEditor)layoutEditor->setBounds(0, 0, this->getWidth(), this->getHeight( void CabbagePluginAudioProcessorEditor::paint (Graphics& g) { for(int i=0;igetGUILayoutCtrlsSize();i++){ - if(getFilter()->getGUILayoutCtrls(i).getStringProp("type").equalsIgnoreCase("keyboard")){ + if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type).equalsIgnoreCase("keyboard")){ #ifdef Cabbage_Build_Standalone if(keyIsPressed) if(isMouseOver(true)){ @@ -1072,79 +1085,78 @@ void CabbagePluginAudioProcessorEditor::paint (Graphics& g) //============================================================================== void CabbagePluginAudioProcessorEditor::InsertGUIControls(CabbageGUIClass cAttr) { - if(cAttr.getStringProp("type")==String("form")){ + if(cAttr.getStringProp(CabbageIDs::type)==String("form")){ SetupWindow(cAttr); //set main application } - else if(cAttr.getStringProp("type")==String("groupbox")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("groupbox")){ InsertGroupBox(cAttr); } - else if(cAttr.getStringProp("type")==String("image")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("image")){ InsertImage(cAttr); } - else if(cAttr.getStringProp("type")==String("patmatrix")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("patmatrix")){ InsertPatternMatrix(cAttr); } - else if(cAttr.getStringProp("type")==String("keyboard")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("keyboard")){ InsertMIDIKeyboard(cAttr); } - else if(cAttr.getStringProp("type")==String("label")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("label")){ InsertLabel(cAttr); } - else if(cAttr.getStringProp("type")==String("csoundoutput")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("csoundoutput")){ InsertCsoundOutput(cAttr); } - else if(cAttr.getStringProp("type")==String("vumeter")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("vumeter")){ InsertVUMeter(cAttr); } - else if(cAttr.getStringProp("type")==String("snapshot")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("snapshot")){ InsertSnapshot(cAttr); } - else if(cAttr.getStringProp("type")==String("source")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("source")){ InsertSourceButton(cAttr); } - else if(cAttr.getStringProp("type")==String("infobutton")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("infobutton")){ InsertInfoButton(cAttr); } - else if(cAttr.getStringProp("type")==String("filebutton")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("filebutton")){ InsertFileButton(cAttr); } - else if(cAttr.getStringProp("type")==String("transport")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("transport")){ InsertTransport(cAttr); } - else if(cAttr.getStringProp("type")==String("soundfiler")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("soundfiler")){ InsertSoundfiler(cAttr); } - else if(cAttr.getStringProp("type")==String("directorylist")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("directorylist")){ InsertDirectoryList(cAttr); } - else if(cAttr.getStringProp("type")==String("multitab")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("multitab")){ InsertMultiTab(cAttr); } - else if(cAttr.getStringProp("type")==String("line")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String(CabbageIDs::line)){ InsertLineSeparator(cAttr); } - else if(cAttr.getStringProp("type")==String("table")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("table")){ InsertTable(cAttr); } - else if(cAttr.getStringProp("type")==String("pvsview")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("pvsview")){ InsertPVSViewer(cAttr); } - - if(cAttr.getStringProp("type")==String("hslider") - ||cAttr.getStringProp("type")==String("vslider") - ||cAttr.getStringProp("type")==String("rslider")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("hslider") + ||cAttr.getStringProp(CabbageIDs::type)==String("vslider") + ||cAttr.getStringProp(CabbageIDs::type)==String("rslider")){ InsertSlider(cAttr); //insert slider } - else if(cAttr.getStringProp("type")==String("button")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("button")){ InsertButton(cAttr); //insert button } - else if(cAttr.getStringProp("type")==String("checkbox")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("checkbox")){ InsertCheckBox(cAttr); //insert checkbox } - else if(cAttr.getStringProp("type")==String("combobox")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("combobox")){ InsertComboBox(cAttr); //insert combobox } - else if(cAttr.getStringProp("type")==String("xypad")){ + else if(cAttr.getStringProp(CabbageIDs::type)==String("xypad")){ InsertXYPad(cAttr); //insert xypad } //} @@ -1159,18 +1171,18 @@ void CabbagePluginAudioProcessorEditor::InsertGUIControls(CabbageGUIClass cAttr) //+++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertGroupBox(CabbageGUIClass &cAttr) { - layoutComps.add(new CabbageGroupbox(cAttr.getStringProp("name"), - cAttr.getStringProp("caption"), + layoutComps.add(new CabbageGroupbox(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::caption), cAttr.getItems(0), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"), - cAttr.getNumProp("line"))); + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour), + cAttr.getNumProp(CabbageIDs::line))); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; if(layoutComps.size()>0){ for(int y=0;ybutton->addListener(this); //plantButton[plantButton.size()-1]->button->setLookAndFeel(basicLookAndFeel); plantButton[plantButton.size()-1]->button->setColour(TextButton::buttonColourId, Colour::fromString(cAttr.getStringProp("fill"))); - plantButton[plantButton.size()-1]->button->setColour(TextButton::textColourOffId, Colour::fromString(cAttr.getStringProp("fontcolour"))); - plantButton[plantButton.size()-1]->button->setColour(TextButton::textColourOnId, Colour::fromString(cAttr.getStringProp("fontcolour"))); + plantButton[plantButton.size()-1]->button->setColour(TextButton::textColourOffId, Colour::fromString(cAttr.getStringProp(CabbageIDs::fontcolour))); + plantButton[plantButton.size()-1]->button->setColour(TextButton::textColourOnId, Colour::fromString(cAttr.getStringProp(CabbageIDs::fontcolour))); //layoutComps.add(plantButton[plantButton.size()-1]); componentPanel->addAndMakeVisible(plantButton[plantButton.size()-1]); plantButton[plantButton.size()-1]->button->getProperties().set(String("index"), plantButton.size()-1); @@ -1212,9 +1224,9 @@ void CabbagePluginAudioProcessorEditor::InsertGroupBox(CabbageGUIClass &cAttr) } } - cAttr.setStringProp("type", "groupbox"); + cAttr.setStringProp(CabbageIDs::type, "groupbox"); layoutComps[idx]->getProperties().set(String("plant"), var(cAttr.getStringProp("plant"))); - layoutComps[idx]->getProperties().set(String("groupLine"), cAttr.getNumProp("line")); + layoutComps[idx]->getProperties().set(String("groupLine"), cAttr.getNumProp(CabbageIDs::line)); } @@ -1225,42 +1237,33 @@ void CabbagePluginAudioProcessorEditor::InsertImage(CabbageGUIClass &cAttr) { String pic; -#ifdef Cabbage_Build_Standalone - pic = cAttr.getStringProp("file"); - Logger::writeToLog(pic); -#else -#ifdef MACOSX - String osxLocation = - File::getSpecialLocation(File::currentApplicationFile).getFullPathName()+String("/Contents/"); - File thisFile(osxLocation); -#else - File thisFile(File::getSpecialLocation(File::currentApplicationFile)); -#endif - pic = thisFile.getParentDirectory().getFullPathName(); - Logger::writeToLog(pic); - -#endif - if(cAttr.getStringProp("file").length()<2) + if(cAttr.getStringProp(CabbageIDs::file).length()<2) pic=""; - else - #ifdef MACOSX - pic.append(String("/Contents/")+String(cAttr.getStringProp("file")), 1024); - #else - //pic.append(String("/")+String(cAttr.getStringProp("file")), 1024); - #endif - - - Logger::writeToLog(pic); - - layoutComps.add(new CabbageImage(cAttr.getStringProp("name"), - pic, cAttr.getColourProp("outline"), cAttr.getColourProp("colour"), - cAttr.getStringProp("shape"), cAttr.getNumProp("line"))); + else{ + #ifdef MACOSX + #ifndef Cabbage_Build_Standalone + pic.append(String("/Contents/")+String(cAttr.getStringProp(CabbageIDs::file)), 1024); + #else + pic = getFilter()->getCsoundInputFile().getParentDirectory().getFullPathName()+String("//")+String(cAttr.getStringProp(CabbageIDs::file)); + #endif + #endif + #ifdef LINUX + pic = getFilter()->getCsoundInputFile().getParentDirectory().getFullPathName()+String("//")+String(cAttr.getStringProp(CabbageIDs::file));; + #endif + #ifdef WIN32 + pic = getFilter()->getCsoundInputFile().getParentDirectory().getFullPathName()+String("\\")+String(cAttr.getStringProp(CabbageIDs::file));; + #endif + Logger::writeToLog(pic); + } + layoutComps.add(new CabbageImage(cAttr.getStringProp(CabbageIDs::name), + pic, cAttr.getStringProp("outline"), cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp("shape"), cAttr.getNumProp(CabbageIDs::line))); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; if(layoutComps.size()>0){ for(int y=0;ybutton->addListener(this); plantButton[plantButton.size()-1]->button->setLookAndFeel(basicLookAndFeel); plantButton[plantButton.size()-1]->button->setColour(TextButton::buttonColourId, - Colour::fromString(cAttr.getColourProp("fill"))); + Colour::fromString(cAttr.getStringProp("fill"))); plantButton[plantButton.size()-1]->button->setColour(TextButton::textColourOffId, - Colour::fromString(cAttr.getColourProp("fontcolour"))); + Colour::fromString(cAttr.getStringProp(CabbageIDs::fontcolour))); plantButton[plantButton.size()-1]->button->setColour(TextButton::textColourOnId, - Colour::fromString(cAttr.getColourProp("fontcolour"))); + Colour::fromString(cAttr.getStringProp(CabbageIDs::fontcolour))); componentPanel->addAndMakeVisible(plantButton[plantButton.size()-1]); @@ -1322,7 +1325,7 @@ void CabbagePluginAudioProcessorEditor::InsertImage(CabbageGUIClass &cAttr) layoutComps[idx]->getProperties().set(String("scaleX"), cAttr.getNumProp("scaleX")); layoutComps[idx]->getProperties().set(String("plant"), var(cAttr.getStringProp("plant"))); //layoutComps[idx]->toBack(); - cAttr.setStringProp("type", "image"); + cAttr.setStringProp(CabbageIDs::type, "image"); } //+++++++++++++++++++++++++++++++++++++++++++ @@ -1330,13 +1333,13 @@ void CabbagePluginAudioProcessorEditor::InsertImage(CabbageGUIClass &cAttr) //+++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertLineSeparator(CabbageGUIClass &cAttr) { - layoutComps.add(new CabbageLine(true, cAttr.getStringProp("colour"))); + layoutComps.add(new CabbageLine(true, cAttr.getStringProp(CabbageIDs::colour))); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; for(int y=0;y0){ @@ -1379,10 +1382,10 @@ void CabbagePluginAudioProcessorEditor::InsertLineSeparator(CabbageGUIClass &cAt //+++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertTransport(CabbageGUIClass &cAttr) { - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); layoutComps.add(new CabbageTransportControl(width, height)); int idx = layoutComps.size()-1; @@ -1430,13 +1433,13 @@ void CabbagePluginAudioProcessorEditor::InsertTransport(CabbageGUIClass &cAttr) //+++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertLabel(CabbageGUIClass &cAttr) { - layoutComps.add(new CabbageLabel(cAttr.getStringProp("text"), cAttr.getStringProp("fontcolour"))); + layoutComps.add(new CabbageLabel(cAttr.getStringProp("text"), cAttr.getStringProp(CabbageIDs::fontcolour))); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; for(int y=0;y0){ @@ -1471,7 +1474,7 @@ void CabbagePluginAudioProcessorEditor::InsertLabel(CabbageGUIClass &cAttr) } } - cAttr.setStringProp("type", "label"); + cAttr.setStringProp(CabbageIDs::type, "label"); } //+++++++++++++++++++++++++++++++++++++++++++ @@ -1479,22 +1482,22 @@ void CabbagePluginAudioProcessorEditor::InsertLabel(CabbageGUIClass &cAttr) //+++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::SetupWindow(CabbageGUIClass &cAttr) { - setName(cAttr.getStringProp("caption")); - getFilter()->setPluginName(cAttr.getStringProp("caption")); - int left = cAttr.getNumProp("left"); - int top = cAttr.getNumProp("top"); - int width = cAttr.getNumProp("width"); - int height = cAttr.getNumProp("height"); + setName(cAttr.getStringProp(CabbageIDs::caption)); + getFilter()->setPluginName(cAttr.getStringProp(CabbageIDs::caption)); + int left = cAttr.getNumProp(CabbageIDs::left); + int top = cAttr.getNumProp(CabbageIDs::top); + int width = cAttr.getNumProp(CabbageIDs::width); + int height = cAttr.getNumProp(CabbageIDs::height); setSize(width, height); componentPanel->setBounds(left, top, width, height); - if(cAttr.getStringProp("colour").length()>2) - formColour = Colour::fromString(cAttr.getStringProp("colour")); + if(cAttr.getStringProp(CabbageIDs::colour).length()>2) + formColour = Colour::fromString(cAttr.getStringProp(CabbageIDs::colour)); else formColour = CabbageUtils::getBackgroundSkin(); - if(cAttr.getStringProp("fontcolour").length()>2) - fontColour = Colour::fromString(cAttr.getStringProp("fontcolour")); + if(cAttr.getStringProp(CabbageIDs::fontcolour).length()>2) + fontColour = Colour::fromString(cAttr.getStringProp(CabbageIDs::fontcolour)); else fontColour = CabbageUtils::getComponentFontColour(); @@ -1509,12 +1512,12 @@ void CabbagePluginAudioProcessorEditor::SetupWindow(CabbageGUIClass &cAttr) #endif #ifdef LINUX - formPic.append(String("/")+String(cAttr.getStringProp("file")), 1024); + formPic.append(String("/")+String(cAttr.getStringProp(CabbageIDs::file)), 1024); #else - formPic.append(String("\\")+String(cAttr.getStringProp("file")), 1024); + formPic.append(String("\\")+String(cAttr.getStringProp(CabbageIDs::file)), 1024); #endif - if(cAttr.getStringProp("file").length()<2) + if(cAttr.getStringProp(CabbageIDs::file).length()<2) formPic = ""; this->resized(); @@ -1529,15 +1532,15 @@ void CabbagePluginAudioProcessorEditor::SetupWindow(CabbageGUIClass &cAttr) void CabbagePluginAudioProcessorEditor::InsertCsoundOutput(CabbageGUIClass &cAttr) { - layoutComps.add(new CabbageMessageConsole(cAttr.getStringProp("name"), - cAttr.getStringProp("caption"), + layoutComps.add(new CabbageMessageConsole(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::caption), cAttr.getStringProp("text"))); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); //check to see if widgets is anchored //if it is offset its position accordingly. @@ -1574,17 +1577,17 @@ void CabbagePluginAudioProcessorEditor::InsertCsoundOutput(CabbageGUIClass &cAtt //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertSourceButton(CabbageGUIClass &cAttr) { - layoutComps.add(new CabbageButton(cAttr.getStringProp("name"), - cAttr.getStringProp("caption"), - cAttr.getItems(1-(int)cAttr.getNumProp("value")), - cAttr.getStringProp("colour"), + layoutComps.add(new CabbageButton(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::caption), + cAttr.getItems(1-(int)cAttr.getNumProp(CabbageIDs::value)), + cAttr.getStringProp(CabbageIDs::colour), "")); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); //check to see if widgets is anchored //if it is offset its position accordingly. @@ -1613,16 +1616,16 @@ void CabbagePluginAudioProcessorEditor::InsertSourceButton(CabbageGUIClass &cAtt void CabbagePluginAudioProcessorEditor::InsertInfoButton(CabbageGUIClass &cAttr) { layoutComps.add(new CabbageButton("infoButton", - cAttr.getStringProp("caption"), - cAttr.getItems(1-(int)cAttr.getNumProp("value")), - cAttr.getColourProp("colour"), - cAttr.getColourProp("fontcolour"))); + cAttr.getStringProp(CabbageIDs::caption), + cAttr.getItems(1-(int)cAttr.getNumProp(CabbageIDs::value)), + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour))); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); //check to see if widgets is anchored //if it is offset its position accordingly. @@ -1641,7 +1644,7 @@ void CabbagePluginAudioProcessorEditor::InsertInfoButton(CabbageGUIClass &cAttr) } ((CabbageButton*)layoutComps[idx])->button->setName("infobutton"); - ((CabbageButton*)layoutComps[idx])->button->getProperties().set(String("filename"), cAttr.getStringProp("file")); + ((CabbageButton*)layoutComps[idx])->button->getProperties().set(String("filename"), cAttr.getStringProp(CabbageIDs::file)); layoutComps[idx]->getProperties().set(String("plant"), var(cAttr.getStringProp("plant"))); ((CabbageButton*)layoutComps[idx])->button->addListener(this); ((CabbageButton*)layoutComps[idx])->button->setButtonText(cAttr.getItems(0)); @@ -1652,17 +1655,17 @@ void CabbagePluginAudioProcessorEditor::InsertInfoButton(CabbageGUIClass &cAttr) //+++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertFileButton(CabbageGUIClass &cAttr) { - layoutComps.add(new CabbageButton(cAttr.getStringProp("name"), - cAttr.getStringProp("caption"), - cAttr.getItems(1-(int)cAttr.getNumProp("value")), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"))); + layoutComps.add(new CabbageButton(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::caption), + cAttr.getItems(1-(int)cAttr.getNumProp(CabbageIDs::value)), + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour))); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); //check to see if widgets is anchored //if it is offset its position accordingly. @@ -1687,12 +1690,12 @@ void CabbagePluginAudioProcessorEditor::InsertFileButton(CabbageGUIClass &cAttr) ((CabbageButton*)layoutComps[idx])->button->addListener(this); //((CabbageButton*)layoutComps[idx])->button->setName("button"); if(cAttr.getItemsSize()>0) - ((CabbageButton*)layoutComps[idx])->button->setButtonText(cAttr.getItems(cAttr.getNumProp("value"))); + ((CabbageButton*)layoutComps[idx])->button->setButtonText(cAttr.getStringArrayPropValue("text", cAttr.getNumProp(CabbageIDs::value))); #ifdef Cabbage_Build_Standalone ((CabbageButton*)layoutComps[idx])->button->setWantsKeyboardFocus(true); #endif //add initial values to incomingValues array - //incomingValues.add(cAttr.getNumProp("value")); + //incomingValues.add(cAttr.getNumProp(CabbageIDs::value)); //showMessage(layoutComps[idx]->getParentComponent()->getName()); } @@ -1704,15 +1707,15 @@ void CabbagePluginAudioProcessorEditor::InsertSoundfiler(CabbageGUIClass &cAttr) { if(getFilter()->audioSourcesArray[cAttr.getNumProp("soundfilerIndex")]){ - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); - layoutComps.add(new CabbageSoundfiler(cAttr.getStringProp("name"), - cAttr.getStringProp("file"), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"), + layoutComps.add(new CabbageSoundfiler(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::file), + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour), *getFilter()->audioSourcesArray[cAttr.getNumProp("soundfilerIndex")], getFilter()->audioSourcesArray[cAttr.getNumProp("soundfilerIndex")]->sampleRate)); @@ -1745,8 +1748,8 @@ void CabbagePluginAudioProcessorEditor::InsertSoundfiler(CabbageGUIClass &cAttr) //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertDirectoryList(CabbageGUIClass &cAttr) { - layoutComps.add(new CabbageDirectoryList(cAttr.getStringProp("name"), - cAttr.getStringProp("channel"), + layoutComps.add(new CabbageDirectoryList(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::channel), cAttr.getStringProp("workingDir"), cAttr.getStringProp("fileType"))); @@ -1755,10 +1758,10 @@ void CabbagePluginAudioProcessorEditor::InsertDirectoryList(CabbageGUIClass &cAt //check to see if widgets is anchored //if it is offset its position accordingly. int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; if(layoutComps.size()>0){ for(int y=0;ytabComp->addTab(plant, - Colour::fromString(cAttr.getStringProp("colour")), + Colour::fromString(cAttr.getStringProp(CabbageIDs::colour)), layoutComps[i], false); } //check to see if widgets is anchored //if it is offset its position accordingly. - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; if(layoutComps.size()>0){ for(int y=0;ygetCsoundInputFile().withFileExtension(".snaps").getFullPathName(); - SnapShotFile = File(snap); - - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); - int relY=0,relX=0; - for(int y=0;y0){ - if(layoutComps[y]->getProperties().getWithDefault(String("plant"), -99).toString().equalsIgnoreCase(cAttr.getStringProp("reltoplant"))) - { - positionComponentWithinPlant("", idx, left, top, width, height, layoutComps[y], comps[idx]); - } - } - else{ - layoutComps[idx]->setBounds(left+relX, top+relY, width, height); - componentPanel->addAndMakeVisible(layoutComps[idx]); - } - } - - ((CabbageSnapshot*)layoutComps[idx])->addActionListener(this); - ((CabbageSnapshot*)layoutComps[idx])->combobox->addItem("Select preset", -1); - for(int i=1;i<(int)cAttr.getItemsSize()+1;i++){ - String test = cAttr.getItems(i-1); - //showMessage(test); - ((CabbageSnapshot*)layoutComps[idx])->combobox->addItem(cAttr.getItems(i-1), i); - cAttr.setNumProp("maxItems", i); - } - - ((CabbageSnapshot*)layoutComps[idx])->combobox->setSelectedItemIndex(cAttr.getNumProp("value")-1); - - //Load any snapshot files that already exist for this instrument - String snapshotFile = getFilter()->getCsoundInputFile().withFileExtension(".snaps").getFullPathName(); - StringArray data; - String presetText=""; - cAttr.clearPresets(); - String openBlock, endBlock; - //showMessage(cAttr.getStringProp("preset")); - - //I should be using the preset name here and not the instrument name as it gets - // changed whenever the order of the code changes. The presets will always be the same - - openBlock << "------------------------ Instrument ID: " << cAttr.getStringProp("preset"); - endBlock << "------------------------ End of Instrument ID: " << cAttr.getStringProp("preset"); - File dataFile(snapshotFile); - if(dataFile.exists()){ - data.addLines(dataFile.loadFileAsString()); - for(int i=0;isetLowestVisibleKey(cAttr.getNumProp("value")); + ((MidiKeyboardComponent*)layoutComps[idx])->setLowestVisibleKey(cAttr.getNumProp(CabbageIDs::value)); layoutComps[idx]->getProperties().set(String("plant"), var(cAttr.getStringProp("plant"))); #ifdef Cabbage_Build_Standalone @@ -2017,16 +1945,16 @@ void CabbagePluginAudioProcessorEditor::InsertMIDIKeyboard(CabbageGUIClass &cAtt //+++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertSlider(CabbageGUIClass &cAttr) { - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); - comps.add(new CabbageSlider(cAttr.getStringProp("name"), + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); + comps.add(new CabbageSlider(cAttr.getStringProp(CabbageIDs::name), cAttr.getStringProp("text"), - cAttr.getStringProp("caption"), + cAttr.getStringProp(CabbageIDs::caption), cAttr.getStringProp("kind"), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"), + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour), cAttr.getNumProp("textbox"), cAttr.getStringProp("trackercolour"), cAttr.getNumProp("decimalplaces") @@ -2037,11 +1965,11 @@ void CabbagePluginAudioProcessorEditor::InsertSlider(CabbageGUIClass &cAttr) int relY=0,relX=0; if(layoutComps.size()>0){ for(int y=0;y0){ if(layoutComps[y]->getProperties().getWithDefault(String("plant"), -99).toString().equalsIgnoreCase(cAttr.getStringProp("reltoplant"))) { - positionComponentWithinPlant(cAttr.getStringProp("type"), idx, left, top, width, height, layoutComps[y], comps[idx]); + positionComponentWithinPlant(cAttr.getStringProp(CabbageIDs::type), idx, left, top, width, height, layoutComps[y], comps[idx]); } } else{ @@ -2064,10 +1992,10 @@ void CabbagePluginAudioProcessorEditor::InsertSlider(CabbageGUIClass &cAttr) //Logger::writeToLog("Skew:"+String(cAttr.getNumProp("sliderSkew"))); ((CabbageSlider*)comps[idx])->slider->setSkewFactor(cAttr.getNumProp("sliderskew")); ((CabbageSlider*)comps[idx])->slider->setRange(cAttr.getNumProp("min"), cAttr.getNumProp("max"), cAttr.getNumProp("sliderincr")); - ((CabbageSlider*)comps[idx])->slider->setValue(cAttr.getNumProp("value")); + ((CabbageSlider*)comps[idx])->slider->setValue(cAttr.getNumProp(CabbageIDs::value)); //add initial values to incomingValues array - incomingValues.add(cAttr.getNumProp("value")); + incomingValues.add(cAttr.getNumProp(CabbageIDs::value)); ((CabbageSlider*)comps[idx])->slider->addListener(this); @@ -2083,10 +2011,10 @@ void CabbagePluginAudioProcessorEditor::sliderValueChanged (Slider* sliderThatWa #ifndef Cabbage_No_Csound for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++)//find correct control from vector - if(getFilter()->getGUICtrls(i).getStringProp("name")==sliderThatWasMoved->getParentComponent()->getName()) + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::name)==sliderThatWasMoved->getParentComponent()->getName()) { #ifndef Cabbage_Build_Standalone - getFilter()->getGUICtrls(i).setNumProp("value", (float)sliderThatWasMoved->getValue()); + getFilter()->getGUICtrls(i).setNumProp(CabbageIDs::value, (float)sliderThatWasMoved->getValue()); float min = getFilter()->getGUICtrls(i).getNumProp("min"); float range = getFilter()->getGUICtrls(i).getNumProp("range"); //normalise parameters in plugin mode. @@ -2096,7 +2024,7 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++)//find correct control fro //getFilter()->setParameterNotifyingHost(i, (float)sliderThatWasMoved->getValue()); getFilter()->endParameterChangeGesture(i); #else - float value = sliderThatWasMoved->getValue();//getFilter()->getGUICtrls(i).getNumProp("value"); + float value = sliderThatWasMoved->getValue();//getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::value); getFilter()->beginParameterChangeGesture(i); getFilter()->setParameter(i, (float)sliderThatWasMoved->getValue()); getFilter()->setParameterNotifyingHost(i, (float)sliderThatWasMoved->getValue()); @@ -2112,17 +2040,17 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++)//find correct control fro //+++++++++++++++++++++++++++++++++++++++++++ void CabbagePluginAudioProcessorEditor::InsertButton(CabbageGUIClass &cAttr) { - comps.add(new CabbageButton(cAttr.getStringProp("name"), - cAttr.getStringProp("caption"), + comps.add(new CabbageButton(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::caption), cAttr.getStringArrayPropValue("text", 0), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"))); + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour))); int idx = comps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); //check to see if widgets is anchored //if it is offset its position accordingly. @@ -2147,12 +2075,16 @@ void CabbagePluginAudioProcessorEditor::InsertButton(CabbageGUIClass &cAttr) ((CabbageButton*)comps[idx])->button->addListener(this); //((CabbageButton*)comps[idx])->button->setName("button"); //if(cAttr.getItemsSize()>0) - ((CabbageButton*)comps[idx])->button->setButtonText(cAttr.getStringArrayPropValue("text", cAttr.getNumProp("value"))); + //showMessage(cAttr.getStringArrayPropValue("text", cAttr.getNumProp(CabbageIDs::value))); + ((CabbageButton*)comps[idx])->button->setButtonText(cAttr.getStringArrayPropValue("text", cAttr.getNumProp(CabbageIDs::value))); + //getFilter()->setParameter(idx, cAttr.getNumProp(CabbageIDs::value)); + //getFilter()->setParameterNotifyingHost(idx, cAttr.getNumProp(CabbageIDs::value)); + #ifdef Cabbage_Build_Standalone ((CabbageButton*)comps[idx])->button->setWantsKeyboardFocus(true); #endif //add initial values to incomingValues array - //incomingValues.add(cAttr.getNumProp("value")); + //incomingValues.add(cAttr.getNumProp(CabbageIDs::value)); //showMessage(comps[idx]->getParentComponent()->getName()); } @@ -2164,17 +2096,17 @@ void CabbagePluginAudioProcessorEditor::InsertCheckBox(CabbageGUIClass &cAttr) { bool RECT = cAttr.getStringProp("shape").equalsIgnoreCase("square"); - comps.add(new CabbageCheckbox(cAttr.getStringProp("name"), - cAttr.getStringProp("caption"), + comps.add(new CabbageCheckbox(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::caption), cAttr.getItems(0), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"), + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour), RECT)); int idx = comps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; @@ -2202,11 +2134,11 @@ void CabbagePluginAudioProcessorEditor::InsertCheckBox(CabbageGUIClass &cAttr) ((CabbageCheckbox*)comps[idx])->button->setButtonText(cAttr.getItems(0)); //set user-defined colour if given - if(cAttr.getStringProp("colour")!=Colours::lime.toString()) - ((CabbageCheckbox*)comps[idx])->button->getProperties().set("colour", cAttr.getStringProp("colour")); + if(cAttr.getStringProp(CabbageIDs::colour)!=Colours::lime.toString()) + ((CabbageCheckbox*)comps[idx])->button->getProperties().set(CabbageIDs::colour, cAttr.getStringProp(CabbageIDs::colour)); //set initial value if given - if(cAttr.getNumProp("value")==1) + if(cAttr.getNumProp(CabbageIDs::value)==1) ((CabbageCheckbox*)comps[idx])->button->setToggleState(true, sendNotification); else ((CabbageCheckbox*)comps[idx])->button->setToggleState(false, sendNotification); @@ -2216,12 +2148,52 @@ void CabbagePluginAudioProcessorEditor::InsertCheckBox(CabbageGUIClass &cAttr) #endif //add initial values to incomingValues array - incomingValues.add(cAttr.getNumProp("value")); + incomingValues.add(cAttr.getNumProp(CabbageIDs::value)); } /*****************************************************/ /* button/filebutton/checkbox press event */ /*****************************************************/ +//for unlatched buttons... +void CabbagePluginAudioProcessorEditor::buttonStateChanged(Button* button) +{ +if(button->isMouseButtonDown()) + { + for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++) + {//find correct control from vector + //+++++++++++++button+++++++++++++ + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::name)==button->getName()) + { + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String("button")&& + getFilter()->getGUICtrls(i).getNumProp("latched")==0) + { + //toggle button values + if(getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::value)==0){ + getFilter()->setParameterNotifyingHost(i, 1.f); + getFilter()->setParameter(i, 1.f); + getFilter()->getGUICtrls(i).setNumProp(CabbageIDs::value, 1); + } + else{ + getFilter()->setParameterNotifyingHost(i, 0.f); + getFilter()->getGUICtrls(i).setNumProp(CabbageIDs::value, 0); + getFilter()->setParameter(i, 0.f); + } + //toggle text values + for(int o=0;ogetGUICtrls(i).getStringArrayProp("text").size();o++) + Logger::writeToLog(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", o)); + + if(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1).equalsIgnoreCase(button->getButtonText())) + button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 0)); + else + button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1)); + } + + } + } + } +} + + void CabbagePluginAudioProcessorEditor::buttonClicked(Button* button) { #ifndef Cabbage_No_Csound @@ -2230,136 +2202,199 @@ void CabbagePluginAudioProcessorEditor::buttonClicked(Button* button) if(!getFilter()->isGuiEnabled()){ if(button->isEnabled()){ // check button is ok before sending data to on named channel if(dynamic_cast(button)){//check what type of button it is - //deal with non-interactive buttons first.. - if(button->getName()=="source"){ + //deal with non-interactive buttons first.. + if(button->getName()=="source"){ // getFilter()->createAndShowSourceEditor(lookAndFeel); - } - else if(button->getName()=="infobutton"){ - String file = getFilter()->getCsoundInputFile().getParentDirectory().getFullPathName(); - #ifdef LINUX - ChildProcess process; - file.append("/", 5); - file.append(button->getProperties().getWithDefault("filename", ""), 1024); - if(!process.start("xdg-open "+file)) - CabbageUtils::showMessage("Couldn't show file", &getLookAndFeel()); - #else - file.append("\\", 5); - file.append(button->getProperties().getWithDefault("filename", ""), 1024); - if(!infoWindow){ - //showMessage(file); - infoWindow = new InfoWindow(lookAndFeel, file); - infoWindow->centreWithSize(600, 400); - infoWindow->toFront(true); - infoWindow->setVisible(true); - } - else - infoWindow->setVisible(true); - #endif - } + } + else if(button->getName()=="infobutton"){ + String file = getFilter()->getCsoundInputFile().getParentDirectory().getFullPathName(); + #ifdef LINUX + ChildProcess process; + file.append("/", 5); + file.append(button->getProperties().getWithDefault("filename", ""), 1024); + if(!process.start("xdg-open "+file)) + CabbageUtils::showMessage("Couldn't show file", &getLookAndFeel()); + #else + file.append("\\", 5); + file.append(button->getProperties().getWithDefault("filename", ""), 1024); + if(!infoWindow){ + //showMessage(file); + infoWindow = new InfoWindow(lookAndFeel, file); + infoWindow->centreWithSize(600, 400); + infoWindow->setAlwaysOnTop(true); + infoWindow->toFront(true); + infoWindow->setVisible(true); + } + else + infoWindow->setVisible(true); + #endif + } - - //check layoutControls for fileButtons, these are once off buttons.... - for(int i=0;i<(int)getFilter()->getGUILayoutCtrlsSize();i++){//find correct control from vector - //Logger::writeToLog(button->getName()); - if(getFilter()->getGUILayoutCtrls(i).getStringProp("name")==button->getName()) - { - if(getFilter()->getGUILayoutCtrls(i).getStringProp("type")==String("filebutton")) - { - WildcardFileFilter wildcardFilter ("*.*", String::empty, "Foo files"); - //FileChooser dialogBox(const String &dialogBoxTitle); - //FileBrowserComponent browser (FileBrowserComponent::canSelectFiles|FileBrowserComponent::saveMode, File::nonexistent, &wildcardFilter, nullptr); - //FileChooserDialogBox dialogBox ("Open some kind of file", "Please choose...", browser, false, Colours::black); - //dialogBox.getLookAndFeel().setDefaultLookAndFeel(basicLookAndFeel); - //setLookAndFeel(basicLookAndFeel); - //browser.setLookAndFeel(basicLookAndFeel); - //dialogBox.setAlwaysOnTop(true); - //dialogBox.setUsingNativeTitleBar(true); - FileChooser fc ("Select a file to open", - File::getCurrentWorkingDirectory(), - "*.mp3;*.wav;*.ogg;*.Aif;*.flac", true); - //dialogBox.toFront(true); - //dialogBox.setColour(0x1000850, Colours::lime); - if (fc.browseForFileToOpen()) - { - File selectedFile = fc.getResult(); - //Logger::writeToLog(selectedFile.getFullPathName()); - if(getFilter()->getCsound()) - getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp("channel").toUTF8().getAddress(), - selectedFile.getFullPathName().toUTF8().getAddress()); - } + + //check layoutControls for fileButtons, these are once off buttons.... + for(int i=0;i<(int)getFilter()->getGUILayoutCtrlsSize();i++){//find correct control from vector + //Logger::writeToLog(button->getName()); + if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::name)==button->getName()) + { + if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type)==String("filebutton")) + { + WildcardFileFilter wildcardFilter ("*.*", String::empty, "Foo files"); + + + const String filetype = getFilter()->getGUILayoutCtrls(i).getStringProp("filetype"); + const String selectedDir = getFilter()->getGUILayoutCtrls(i).getStringProp("workingdir"); + File directory; + if(selectedDir.isNotEmpty()) + directory = File(selectedDir); + else + directory = File::getCurrentWorkingDirectory(); + + + File selectedFile; + + if(getFilter()->getGUILayoutCtrls(i).getStringProp("mode").equalsIgnoreCase("snapshot") && + getFilter()->getGUILayoutCtrls(i).getStringProp("filetype").contains("snaps")) + { + //here we write the files with generic names for quick saving + Array dirFiles; + File pluginDir; + String currentFileLocation = getFilter()->getCsoundInputFile().getParentDirectory().getFullPathName(); + //Logger::writeToLog(currentFileLocation); + if(selectedDir.length()<1){ + pluginDir = File(currentFileLocation); + } + else + pluginDir = File(selectedDir); + pluginDir.findChildFiles(dirFiles, 2, false, filetype); + + //now check existing files in directory and make sure we use a unique name + for(int i=0;i<100;i++){ + String newName = getFilter()->getCsoundInputFile().getFileNameWithoutExtension()+"_"+String(i); + #ifdef WIN32 + String fullFileName = pluginDir.getFullPathName()+"\\"+newName+".snaps"; + #else + String fullFileName = pluginDir.getFullPathName()+"/"+newName+".snaps"; + #endif + //Logger::writeToLog(fullFileName); + bool allowSave = true; + for(int y=0;ygetGUICtrlsSize();i++){//find correct control from vector - - //+++++++++++++button+++++++++++++ - //Logger::writeToLog(getFilter()->getGUICtrls(i).getStringProp("name")); - //Logger::writeToLog(button->getName()); - if(getFilter()->getGUICtrls(i).getStringProp("name")==button->getName()) - { - if(getFilter()->getGUICtrls(i).getStringProp("type")==String("button")) - { - //toggle button values - if(getFilter()->getGUICtrls(i).getNumProp("value")==0){ - getFilter()->setParameterNotifyingHost(i, 1.f); - getFilter()->setParameter(i, 1.f); - //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp("channel").toUTF8(), 1.f); - getFilter()->getGUICtrls(i).setNumProp("value", 1); - } - else{ - getFilter()->setParameterNotifyingHost(i, 0.f); - //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp("channel").toUTF8(), 0.f); - getFilter()->getGUICtrls(i).setNumProp("value", 0); - getFilter()->setParameter(i, 0.f); - } - //toggle text values - if(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1)==button->getButtonText()) - button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 0)); - else if(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 0)==button->getButtonText()) - button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1)); + if(allowSave){ + savePresetsFromParameters(File(fullFileName), "create"); + refreshDiskReadingGUIControls("combobox"); + return; } - } + + + } + //else let the user specify the filename for the snapshot + else{ + if(!getFilter()->getGUILayoutCtrls(i).getStringProp("filetype").contains("snaps")){ + FileChooser fc("Select a file", directory.getFullPathName(), filetype, true); + if(fc.browseForFileToOpen()){ + selectedFile = fc.getResult(); + getFilter()->messageQueue.addOutgoingChannelMessageToQueue(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel), + selectedFile.getFullPathName().replace("\\", "\\\\"), + "string"); + } + Logger::writeToLog(selectedFile.getFullPathName()); + Logger::writeToLog(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel)); + + } + else{ + FileChooser fc("Select a file to save", directory.getFullPathName(), filetype, true); + if(fc.browseForFileToSave(true)){ + selectedFile = fc.getResult(); + if(filetype.contains("snaps")) + savePresetsFromParameters(selectedFile, "create"); + else + getFilter()->messageQueue.addOutgoingChannelMessageToQueue(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel), + selectedFile.getFullPathName(), + "string"); + refreshDiskReadingGUIControls("combobox"); + } + } + } - //show plants as popup window - else{ - for(int p=0;pgetGUILayoutCtrlsSize();p++){ - if(getFilter()->getGUILayoutCtrls(p).getStringProp("plant") ==button->getName()){ - int index = button->getProperties().getWithDefault(String("index"), 0); - subPatch[index]->setVisible(true); - subPatch[index]->setAlwaysOnTop(true); - subPatch[index]->toFront(true); - i=getFilter()->getGUICtrlsSize(); - break; - } + } + } + } + + + for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++){//find correct control from vector + + //+++++++++++++button+++++++++++++ + //Logger::writeToLog(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::name)); + //Logger::writeToLog(button->getName()); + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::name)==button->getName()) + { + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String("button")) + { + //toggle button values + if(getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::value)==0){ + getFilter()->setParameterNotifyingHost(i, 1.f); + getFilter()->setParameter(i, 1.f); + //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), 1.f); + getFilter()->getGUICtrls(i).setNumProp(CabbageIDs::value, 1); } - } + else{ + getFilter()->setParameterNotifyingHost(i, 0.f); + //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), 0.f); + getFilter()->getGUICtrls(i).setNumProp(CabbageIDs::value, 0); + getFilter()->setParameter(i, 0.f); + } + //toggle text values + for(int o=0;ogetGUICtrls(i).getStringArrayProp("text").size();o++) + Logger::writeToLog(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", o)); + + if(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1).equalsIgnoreCase(button->getButtonText())) + button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 0)); + else + button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1)); + } + + } + + //show plants as popup window + else{ + for(int p=0;pgetGUILayoutCtrlsSize();p++){ + if(getFilter()->getGUILayoutCtrls(p).getStringProp("plant") ==button->getName()){ + int index = button->getProperties().getWithDefault(String("index"), 0); + subPatch[index]->setVisible(true); + subPatch[index]->setAlwaysOnTop(true); + subPatch[index]->toFront(true); + i=getFilter()->getGUICtrlsSize(); + break; + } } + } + } } else if(dynamic_cast(button)){ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++)//find correct control from vector - if(getFilter()->getGUICtrls(i).getStringProp("name")==button->getName()){ + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::name)==button->getName()){ // Logger::writeToLog(String(button->getToggleStateValue().getValue())); if(button->getToggleState()){ button->setToggleState(true, dontSendNotification); getFilter()->setParameter(i, 1.f); getFilter()->setParameterNotifyingHost(i, 1.f); - //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp("channel").toUTF8(), 1.f); - getFilter()->getGUICtrls(i).setNumProp("value", 1); + //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), 1.f); + getFilter()->getGUICtrls(i).setNumProp(CabbageIDs::value, 1); } else{ button->setToggleState(false, dontSendNotification); getFilter()->setParameter(i, 0.f); getFilter()->setParameterNotifyingHost(i, 0.f); - //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp("channel").toUTF8(), 0.f); - getFilter()->getGUICtrls(i).setNumProp("value", 0); + //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), 0.f); + getFilter()->getGUICtrls(i).setNumProp(CabbageIDs::value, 0); //Logger::writeToLog("pressed"); } - //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp("channel").toUTF8(), button->getToggleStateValue().getValue()); + //getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), button->getToggleStateValue().getValue()); //getFilter()->setParameterNotifyingHost(i, button->getToggleStateValue().getValue()); } } @@ -2378,18 +2413,18 @@ if(!getFilter()->isGuiEnabled()){ void CabbagePluginAudioProcessorEditor::InsertComboBox(CabbageGUIClass &cAttr) { Array dirFiles; - comps.add(new CabbageComboBox(cAttr.getStringProp("name"), - cAttr.getStringProp("caption"), + comps.add(new CabbageComboBox(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::caption), cAttr.getItems(0), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"))); + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour))); int idx = comps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; if(layoutComps.size()>0){ @@ -2425,32 +2460,37 @@ void CabbagePluginAudioProcessorEditor::InsertComboBox(CabbageGUIClass &cAttr) //Logger::writeToLog(currentFileLocation); if(cAttr.getStringProp("workingDir").length()<1){ pluginDir = File(currentFileLocation); - } else - pluginDir = File(cAttr.getStringProp("workingdir")); - + if(File(cAttr.getStringProp("workingdir")).exists()) + pluginDir = File(cAttr.getStringProp("workingdir")); + const String filetype = cAttr.getStringProp("filetype"); - //Logger::writeToLog(cAttr.getStringProp("fileType")); + pluginDir.findChildFiles(dirFiles, 2, false, filetype); for (int i = 0; i < dirFiles.size(); ++i){ //m.addItem (i + menuSize, cabbageFiles[i].getFileNameWithoutExtension()); - String test = String(i+1)+": "+dirFiles[i].getFileName(); - ((CabbageComboBox*)comps[idx])->combo->addItem(test, i+1); + //String test = String(i+1)+": "+dirFiles[i].getFileName(); + String filename; + if(filetype.contains("snaps")) + filename = dirFiles[i].getFileNameWithoutExtension(); + else + filename = dirFiles[i].getFileName(); + ((CabbageComboBox*)comps[idx])->combo->addItem(filename, i+1); } } //cAttr.setNumProp("comborange", cAttr.getItemsSize()); - lookAndFeel->setColour(ComboBox::textColourId, Colour::fromString(cAttr.getStringProp("fontcolour"))); - Logger::writeToLog("combo value:"+String(cAttr.getNumProp("value"))); - ((CabbageComboBox*)comps[idx])->combo->setSelectedItemIndex(cAttr.getNumProp("value")-1); + lookAndFeel->setColour(ComboBox::textColourId, Colour::fromString(cAttr.getStringProp(CabbageIDs::fontcolour))); + //Logger::writeToLog("combo value:"+String(cAttr.getNumProp(CabbageIDs::value))); + ((CabbageComboBox*)comps[idx])->combo->setSelectedItemIndex(cAttr.getNumProp(CabbageIDs::value)-1); - ((CabbageComboBox*)comps[idx])->setName(cAttr.getStringProp("name")); + ((CabbageComboBox*)comps[idx])->setName(cAttr.getStringProp(CabbageIDs::name)); ((CabbageComboBox*)comps[idx])->combo->addListener(this); //add initial values to incomingValues array - incomingValues.add(cAttr.getNumProp("value")); + incomingValues.add(cAttr.getNumProp(CabbageIDs::value)); } /******************************************/ @@ -2461,32 +2501,137 @@ void CabbagePluginAudioProcessorEditor::comboBoxChanged (ComboBox* combo) #ifndef Cabbage_No_Csound if(combo->isEnabled()) // before sending data to on named channel { - for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++){//find correct control from vector - String test = combo->getName(); - String test2 = getFilter()->getGUICtrls(i).getStringProp("name"); - if(getFilter()->getGUICtrls(i).getStringProp("name").equalsIgnoreCase(combo->getName())){ - for(int y=0;y<(int)getFilter()->getGUICtrls(i).getStringArrayProp("text").size();y++) - if(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", y).equalsIgnoreCase(combo->getItemText(combo->getSelectedItemIndex()))){ - Logger::writeToLog("here we go"); - getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp("channel").toUTF8(), (float)combo->getSelectedItemIndex()+1); - +for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++)//find correct control from vector + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::name)==combo->getName()) + { + + if(getFilter()->getGUICtrls(i).getStringProp("filetype").contains("snaps")){ + String filename; + String workingDir = getFilter()->getGUICtrls(i).getStringProp("workingdir"); + if(workingDir.isEmpty()) + workingDir = getFilter()->getCsoundInputFile().getParentDirectory().getFullPathName(); + #ifdef WIN32 + filename = workingDir+"\\"+combo->getText()+".snaps"; + #else + filename = workingDir+"/"+combo->getText()+".snaps"; + #endif + //Logger::writeToLog(filename); + if(File(filename).existsAsFile()) + restoreParametersFromPresets(XmlDocument::parse(File(filename))); + //File(combo->getText()) + } + #ifndef Cabbage_Build_Standalone -Logger::writeToLog("ComboRange:"+String(getFilter()->getGUICtrls(i).getNumProp("comborange"))); -Logger::writeToLog(String(combo->getSelectedItemIndex())); - getFilter()->setParameter(i, (float)(combo->getSelectedItemIndex()+1)/(getFilter()->getGUICtrls(i).getNumProp("comborange"))); - getFilter()->setParameterNotifyingHost(i, (float)(combo->getSelectedItemIndex()+1)/(getFilter()->getGUICtrls(i).getNumProp("comborange"))); + getFilter()->setParameter(i, (float)(combo->getSelectedItemIndex()+1)/(getFilter()->getGUICtrls(i).getNumProp("comborange"))); + getFilter()->setParameterNotifyingHost(i, (float)(combo->getSelectedItemIndex()+1)/(getFilter()->getGUICtrls(i).getNumProp("comborange"))); #else - getFilter()->setParameter(i, (float)(combo->getSelectedItemIndex()+1)); - getFilter()->setParameterNotifyingHost(i, (float)(combo->getSelectedItemIndex()+1)); + getFilter()->setParameter(i, (float)(combo->getSelectedItemIndex()+1)); + getFilter()->setParameterNotifyingHost(i, (float)(combo->getSelectedItemIndex()+1)); #endif - } - } } } #endif } +//========================================================================================= +// resfresh GUI controls that read from disk.. +//======================================================================================== +void CabbagePluginAudioProcessorEditor::refreshDiskReadingGUIControls(String typeOfControl) +{ +for(int i=0;igetGUICtrlsSize();i++) + { + //if typeOfControl == combobox, user must have file type set for comboboxes to refresh + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type).equalsIgnoreCase(typeOfControl) && + getFilter()->getGUICtrls(i).getStringProp("filetype").isNotEmpty()) + { + CabbageComboBox* cabCombo = dynamic_cast(comps[i]); + if(cabCombo) + { + File pluginDir; + int currentItemID = cabCombo->combo->getSelectedId(); + String currentFileLocation = getFilter()->getCsoundInputFile().getParentDirectory().getFullPathName(); + + + if(getFilter()->getGUICtrls(i).getStringProp("workingDir").isEmpty()) + pluginDir = File(currentFileLocation); + else + pluginDir = File(getFilter()->getGUICtrls(i).getStringProp("workingdir")); + + const String filetype = getFilter()->getGUICtrls(i).getStringProp("filetype"); + Array dirFiles; + pluginDir.findChildFiles(dirFiles, 2, false, filetype); + cabCombo->combo->clear(dontSendNotification); + for (int i = 0; i < dirFiles.size(); ++i) + if(filetype.contains("snaps")) + cabCombo->combo->addItem(dirFiles[i].getFileNameWithoutExtension(), i+1); + else + cabCombo->combo->addItem(dirFiles[i].getFileName(), i+1); + + cabCombo->combo->setSelectedId(currentItemID, dontSendNotification); + } + } + } +} + + +//========================================================================================= +// save and recall presets +//======================================================================================== +void CabbagePluginAudioProcessorEditor::savePresetsFromParameters(File selectedFile, String mode) +{ + XmlElement xml (getFilter()->getCsoundInputFile().getFileNameWithoutExtension()); + for(int i=0;igetGUICtrlsSize();i++) + xml.setAttribute(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::channel), getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::value)); + + File file(selectedFile.getFullPathName()); + file.replaceWithText(xml.createDocument("")); +} + +void CabbagePluginAudioProcessorEditor::restoreParametersFromPresets(XmlElement* xmlState) +{ + ScopedPointer xml; + xml = xmlState; + +/* + * Might be a better idea to simply change the GUI control positions in the editor + * we don't need to update a combobox if it is a snapshot combobox.. + */ + + //Logger::writeToLog(getFilter()->getCsoundInputFile().getFileNameWithoutExtension()); + // make sure that it's actually our type of XML object.. + if (xml->hasTagName (getFilter()->getCsoundInputFile().getFileNameWithoutExtension())) + { + for(int i=0;igetNumParameters();i++) + { + float newValue = (float)xml->getDoubleAttribute(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::channel)); + + #ifndef Cabbage_Build_Standalone + + float range = getFilter()->getGUICtrls(i).getNumProp("range"); + float comboRange = getFilter()->getGUICtrls(i).getNumProp("comborange"); + //Logger::writeToLog("inValue:"+String(newValue)); + float min = getFilter()->getGUICtrls(i).getNumProp("min"); + + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)=="rslider") + Logger::writeToLog("slider"); + + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)=="xypad") + newValue = (jmax(0.f, newValue)/range)+min; + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)=="combobox")//combo box value need to be rounded... + newValue = (newValue/comboRange); + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)=="checkbox" || + getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)=="button") + range=1; + else + newValue = (newValue/range)+min; + #endif + + if(!getFilter()->getGUICtrls(i).getStringProp("filetype").contains("snaps") ) + getFilter()->setParameter(i, newValue); + } + } +} //+++++++++++++++++++++++++++++++++++++++++++ // xypad //+++++++++++++++++++++++++++++++++++++++++++ @@ -2502,9 +2647,9 @@ don't need to recreate the automation */ int idx; -if(getFilter()->haveXYAutosBeenCreated()){ +if(getFilter()->haveXYAutosBeenCreated()){ comps.add(new CabbageXYController(getFilter()->getXYAutomater(xyPadIndex), - cAttr.getStringProp("name"), + cAttr.getStringProp(CabbageIDs::name), cAttr.getStringProp("text"), "", cAttr.getNumProp("minx"), @@ -2513,8 +2658,8 @@ if(getFilter()->haveXYAutosBeenCreated()){ cAttr.getNumProp("maxy"), xyPadIndex, cAttr.getNumProp("decimalplaces"), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"), + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour), cAttr.getNumProp("valuex"), cAttr.getNumProp("valuey"))); xyPadIndex++; @@ -2529,7 +2674,7 @@ else{ cAttr.setNumProp("xyautoindex", getFilter()->getXYAutomaterSize()-1); comps.add(new CabbageXYController(getFilter()->getXYAutomater(getFilter()->getXYAutomaterSize()-1), - cAttr.getStringProp("name"), + cAttr.getStringProp(CabbageIDs::name), cAttr.getStringProp("text"), "", cAttr.getNumProp("minx"), @@ -2538,8 +2683,8 @@ else{ cAttr.getNumProp("maxy"), getFilter()->getXYAutomaterSize()-1, cAttr.getNumProp("decimalPlaces"), - cAttr.getStringProp("colour"), - cAttr.getStringProp("fontcolour"), + cAttr.getStringProp(CabbageIDs::colour), + cAttr.getStringProp(CabbageIDs::fontcolour), cAttr.getNumProp("valuex"), cAttr.getNumProp("valuey"))); idx = comps.size()-1; @@ -2548,10 +2693,10 @@ else{ } - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); @@ -2569,13 +2714,13 @@ else{ } else{ comps[idx]->setBounds(left+relX, top+relY, width, height); - if(!cAttr.getStringProp("name").containsIgnoreCase("dummy")) + if(!cAttr.getStringProp(CabbageIDs::name).containsIgnoreCase("dummy")) componentPanel->addAndMakeVisible(comps[idx]); } } else{ comps[idx]->setBounds(left+relX, top+relY, width, height); - if(!cAttr.getStringProp("name").containsIgnoreCase("dummy")) + if(!cAttr.getStringProp(CabbageIDs::name).containsIgnoreCase("dummy")) componentPanel->addAndMakeVisible(comps[idx]); } @@ -2594,7 +2739,7 @@ else{ getFilter()->setParameter(idx+1, cAttr.getNumProp("valuey")); //add initial values to incomingValues array - if(!cAttr.getStringProp("name").contains("dummy")){ + if(!cAttr.getStringProp(CabbageIDs::name).contains("dummy")){ incomingValues.add(cAttr.getNumProp("valuex")); incomingValues.add(cAttr.getNumProp("valuey")); } @@ -2606,8 +2751,8 @@ else{ #ifdef Cabbage_Build_Standalone comps[idx]->setWantsKeyboardFocus(false); #endif - //if(!cAttr.getStringProp("name").containsIgnoreCase("dummy")) - // actionListenerCallback(cAttr.getStringProp("name")); + //if(!cAttr.getStringProp(CabbageIDs::name).containsIgnoreCase("dummy")) + // actionListenerCallback(cAttr.getStringProp(CabbageIDs::name)); } //+++++++++++++++++++++++++++++++++++++++++++ @@ -2623,8 +2768,8 @@ void CabbagePluginAudioProcessorEditor::InsertPVSViewer(CabbageGUIClass &cAttr) getFilter()->getPVSDataOut()->overlap = cAttr.getNumProp("fftSize")/4; getFilter()->getPVSDataOut()->frame = (float *) calloc(sizeof(float),(getFilter()->getPVSDataOut()->N+2)); - layoutComps.add(new CabbagePVSView(cAttr.getStringProp("name"), - cAttr.getStringProp("caption"), + layoutComps.add(new CabbagePVSView(cAttr.getStringProp(CabbageIDs::name), + cAttr.getStringProp(CabbageIDs::caption), cAttr.getStringProp("text"), cAttr.getNumProp("winSize"), cAttr.getNumProp("fftSize"), @@ -2633,10 +2778,10 @@ void CabbagePluginAudioProcessorEditor::InsertPVSViewer(CabbageGUIClass &cAttr) int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; if(layoutComps.size()>0){ @@ -2693,14 +2838,14 @@ Array tableSizes; } #endif tableSizes.clear(); - for(int i=0;i tableSizes; this)); int idx = layoutComps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; if(layoutComps.size()>0){ for(int y=0;ygetGUILayoutCtrlsSize();i++)//find correct control from vector //if message came from a directorylist - if(getFilter()->getGUILayoutCtrls(i).getStringProp("type").containsIgnoreCase("directorylist")) + if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type).containsIgnoreCase("directorylist")) { //Logger::writeToLog("update tables now please..."); StringArray events = ((CabbageDirectoryList*)layoutComps[i])->getListContents(); @@ -2776,7 +2921,7 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++)//find correct control fro for(int i=0;igetGUILayoutCtrlsSize();i++) if(getFilter()->getGUILayoutCtrls(i).getStringProp("preset").equalsIgnoreCase(name)) { - //showMessage(getFilter()->getGUILayoutCtrls(i).getStringProp("name")); + //showMessage(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::name)); //showMessage(getFilter()->getGUILayoutCtrls(i).getStringProp("snapshotData")); //showMessage(getFilter()->getGUILayoutCtrls(i).getNumPresets()); for(int x=0;xgetGUILayoutCtrls(i).getItemsSize();x++){ @@ -2790,13 +2935,13 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++)//find correct control fro String comp1 = getFilter()->getGUICtrls(n).getStringProp("preset"); //checks if all widgets are being controlled by this preset, or just some if(masterSnap) - str = str << getFilter()->getGUICtrls(n).getStringProp("channel") << ":\t\t\t" << getFilter()->getGUICtrls(n).getNumProp("value") << "\n"; + str = str << getFilter()->getGUICtrls(n).getStringProp(CabbageIDs::channel) << ":\t\t\t" << getFilter()->getGUICtrls(n).getNumProp(CabbageIDs::value) << "\n"; else if(comp1.trim().equalsIgnoreCase(name.trim())) { //showMessage(getFilter()->getGUILayoutCtrls(i).getStringProp("preset")); - str = str << getFilter()->getGUICtrls(n).getStringProp("channel") << ":\t\t\t" << getFilter()->getGUICtrls(n).getNumProp("value") << "\n"; + str = str << getFilter()->getGUICtrls(n).getStringProp(CabbageIDs::channel) << ":\t\t\t" << getFilter()->getGUICtrls(n).getNumProp(CabbageIDs::value) << "\n"; } } @@ -2842,21 +2987,21 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++)//find correct control fro for(int z=1;zgetGUICtrlsSize();u++) - if(getFilter()->getGUICtrls(u).getStringProp("channel").equalsIgnoreCase(channel)){ + if(getFilter()->getGUICtrls(u).getStringProp(CabbageIDs::channel).equalsIgnoreCase(channel)){ double val = values[z].substring(values[z].indexOf(":")+1, 100).getDoubleValue(); //showMessage(String(val)); - getFilter()->getGUICtrls(u).setNumProp("value", val); - if(getFilter()->getGUICtrls(i).getStringProp("type")==String("hslider")|| - getFilter()->getGUICtrls(u).getStringProp("type")==String("rslider")|| - getFilter()->getGUICtrls(u).getStringProp("type")==String("vslider")){ + getFilter()->getGUICtrls(u).setNumProp(CabbageIDs::value, val); + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String("hslider")|| + getFilter()->getGUICtrls(u).getStringProp(CabbageIDs::type)==String("rslider")|| + getFilter()->getGUICtrls(u).getStringProp(CabbageIDs::type)==String("vslider")){ if(comps[u]) ((CabbageSlider*)comps[u])->slider->setValue(val, dontSendNotification); } - else if(getFilter()->getGUICtrls(u).getStringProp("type")==String("checkbox")){ + else if(getFilter()->getGUICtrls(u).getStringProp(CabbageIDs::type)==String("checkbox")){ if(comps[u]) ((CabbageCheckbox*)comps[u])->button->setToggleState((bool)val, sendNotification); } - else if(getFilter()->getGUICtrls(u).getStringProp("type")==String("combobox")){ + else if(getFilter()->getGUICtrls(u).getStringProp(CabbageIDs::type)==String("combobox")){ //if(comps[u]) //((CabbageComboBox*)comps[u])->combo->setSelectedItemIndex(val); } @@ -2918,18 +3063,18 @@ void CabbagePluginAudioProcessorEditor::InsertPatternMatrix(CabbageGUIClass &cAt int tableSize=0; //getFilter()->patStepMatrix.clear(); //getFilter()->patPfieldMatrix.clear(); - comps.add(new CabbagePatternMatrix(getFilter(), cAttr.getStringProp("name"), - cAttr.getNumProp("width"), - cAttr.getNumProp("height"), - cAttr.getStringProp("caption"), + comps.add(new CabbagePatternMatrix(getFilter(), cAttr.getStringProp(CabbageIDs::name), + cAttr.getNumProp(CabbageIDs::width), + cAttr.getNumProp(CabbageIDs::height), + cAttr.getStringProp(CabbageIDs::caption), cAttr.getItemArray(), cAttr.getNumProp("noSteps"), cAttr.getNumProp("rCtrls"))); int idx = comps.size()-1; - float left = cAttr.getNumProp("left"); - float top = cAttr.getNumProp("top"); - float width = cAttr.getNumProp("width"); - float height = cAttr.getNumProp("height"); + float left = cAttr.getNumProp(CabbageIDs::left); + float top = cAttr.getNumProp(CabbageIDs::top); + float width = cAttr.getNumProp(CabbageIDs::width); + float height = cAttr.getNumProp(CabbageIDs::height); int relY=0,relX=0; @@ -3034,9 +3179,9 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++){ if(getFilter()->getGUICtrls(i).getKeySize()>0) if(getFilter()->getGUICtrls(i).getkey(0).equalsIgnoreCase(key.getTextDescription())) if(key.isCurrentlyDown()){ - if(getFilter()->getGUICtrls(i).getStringProp("type")==String("button")) + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String("button")) this->buttonClicked(((CabbageButton*)comps[i])->button); - else if(getFilter()->getGUICtrls(i).getStringProp("type")==String("checkbox")){ + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String("checkbox")){ if(((CabbageCheckbox*)comps[i])->button->getToggleState()) ((CabbageCheckbox*)comps[i])->button->setToggleState(0, dontSendNotification); else @@ -3049,13 +3194,15 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++){ }//end of GUI enabled check #endif return true; -ComponentDragger d; } //========================================================================================== //Gets called periodically to update GUI controls with values coming from Csound //========================================================================================== void CabbagePluginAudioProcessorEditor::timerCallback(){ + +} +void CabbagePluginAudioProcessorEditor::updateGUIControls(){ // update our GUI so that whenever a VST parameter is changed in the // host the corresponding GUI control gets updated. @@ -3074,45 +3221,52 @@ for(int y=0;ygetXYAutomaterSize();y++){ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++) { //only update controls if their value has changed... + //Logger::writeToLog(String(getFilter()->getParameter(i))); if(incomingValues[i]!=getFilter()->getParameter(i)) { inValue = getFilter()->getParameter(i); - - if(getFilter()->getGUICtrls(i).getStringProp("type")==String("hslider")|| - getFilter()->getGUICtrls(i).getStringProp("type")==String("rslider")|| - getFilter()->getGUICtrls(i).getStringProp("type")==String("vslider")){ + + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==CabbageIDs::hslider|| + getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==CabbageIDs::rslider|| + getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==CabbageIDs::vslider){ CabbageSlider* cabSlider = dynamic_cast(comps[i]); if(cabSlider){ #ifndef Cabbage_Build_Standalone - float val = (getFilter()->getGUICtrls(i).getNumProp("range")*getFilter()->getParameter(i))+ - getFilter()->getGUICtrls(i).getNumProp("min"); + float val = getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::range)*getFilter()->getParameter(i)+ + getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::min); cabSlider->slider->setValue(val, dontSendNotification); incomingValues.set(i, val); #else //Logger::writeToLog(String(inValue)); - cabSlider->slider->setValue(inValue, sendNotification); + cabSlider->slider->setValue(inValue, sendNotification); incomingValues.set(i, inValue); #endif } } - else if(getFilter()->getGUICtrls(i).getStringProp("type")==String("button")){ + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==CabbageIDs::button){ CabbageButton* cabButton = dynamic_cast(comps[i]); if(cabButton){ - cabButton->button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1-(int)inValue)); - incomingValues.set(i, 1-(int)inValue); + //Logger::writeToLog("Button:"+String(inValue)); + cabButton->button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue(CabbageIDs::text, inValue)); + incomingValues.set(i, inValue); + //if(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1).equalsIgnoreCase(cabButton->button->getButtonText())) + // cabButton->button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 0)); + //else + // cabButton->button->setButtonText(getFilter()->getGUICtrls(i).getStringArrayPropValue("text", 1)); + } } - else if(getFilter()->getGUICtrls(i).getStringProp("type")==String("xypad") && - getFilter()->getGUICtrls(i).getStringProp("xychannel").equalsIgnoreCase("x")){ + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==CabbageIDs::xypad && + getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::xychannel).equalsIgnoreCase("x")){ if(comps[i]){ #ifndef Cabbage_Build_Standalone - float xRange = getFilter()->getGUICtrls(i).getNumProp("range"); - float xMin = getFilter()->getGUICtrls(i).getNumProp("minx"); - float yMin = getFilter()->getGUICtrls(i).getNumProp("miny"); - float yRange = getFilter()->getGUICtrls(i+1).getNumProp("range"); + float xRange = getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::range); + float xMin = getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::minx); + float yMin = getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::miny); + float yRange = getFilter()->getGUICtrls(i+1).getNumProp(CabbageIDs::range); ((CabbageXYController*)comps[i])->xypad->setXYValues(getFilter()->getParameter(i)*xRange+xMin, getFilter()->getParameter(i+1)*yRange+yMin); #else ((CabbageXYController*)comps[i])->xypad->setXYValues(getFilter()->getParameter(i), getFilter()->getParameter(i+1)); @@ -3122,22 +3276,36 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++) incomingValues.set(i+1, getFilter()->getParameter(i+1)); } } + - //no automation for comboboxes, still problematic! - else if(getFilter()->getGUICtrls(i).getStringProp("type")==String("combobox")){ + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==CabbageIDs::combobox){ + float val; + NotificationType notify; + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::filetype).contains("snaps")) + notify = sendNotification; + else + notify = dontSendNotification; + #ifdef Cabbage_Build_Standalone - ((CabbageComboBox*)comps[i])->combo->setSelectedItemIndex((int)getFilter()->getParameter(i)-1, dontSendNotification); + val = getFilter()->getParameter(i); + ((CabbageComboBox*)comps[i])->combo->setSelectedItemIndex((int)val-1, notify); + incomingValues.set(i, val); + //Logger::writeToLog(String("timerCallback():")+String(val)); #else - //Logger::writeToLog(String("timerCallback():")+String(getFilter()->getParameter(i))); - float val = getFilter()->getGUICtrls(i).getNumProp("comborange")*getFilter()->getParameter(i); - //((CabbageComboBox*)comps[i])->combo->setSelectedItemIndex(int(val-1), dontSendNotification); - incomingValues.set(i, val); + //needed to move combobox to full when controlled by a host + if(getFilter()->getParameter(i)>=0.98) + val = getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::comborange); + else + val = getFilter()->getGUICtrls(i).getNumProp("comborange")*getFilter()->getParameter(i); + //Logger::writeToLog(String("timerCallback():")+String(val)); + ((CabbageComboBox*)comps[i])->combo->setSelectedItemIndex(int(val)-1, notify); #endif + } - else if(getFilter()->getGUICtrls(i).getStringProp("type")==String("checkbox")){ + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==CabbageIDs::checkbox){ if(comps[i]){ - int val = getFilter()->getGUICtrls(i).getNumProp("value"); + int val = getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::value); ((CabbageCheckbox*)comps[i])->button->setToggleState((bool)val, dontSendNotification); incomingValues.set(i, val); } @@ -3147,25 +3315,25 @@ for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++) #ifndef Cabbage_Build_Standalone for(int i=0;i<(int)getFilter()->getGUILayoutCtrlsSize();i++){ - if(getFilter()->getGUILayoutCtrls(i).getStringProp("type")==String("hostbpm")){ + if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type)==String("hostbpm")){ if (getFilter()->getPlayHead() != 0 && getFilter()->getPlayHead()->getCurrentPosition (hostInfo)) - getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.bpm); + getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), hostInfo.bpm); } - else if(getFilter()->getGUILayoutCtrls(i).getStringProp("type")==String("hosttime")){ + else if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type)==String("hosttime")){ if (getFilter()->getPlayHead() != 0 && getFilter()->getPlayHead()->getCurrentPosition (hostInfo)) - getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.timeInSeconds); + getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), hostInfo.timeInSeconds); } - else if(getFilter()->getGUILayoutCtrls(i).getStringProp("type")==String("hostplaying")){ + else if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type)==String("hostplaying")){ if (getFilter()->getPlayHead() != 0 && getFilter()->getPlayHead()->getCurrentPosition (hostInfo)) - getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.isPlaying); + getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), hostInfo.isPlaying); } - else if(getFilter()->getGUILayoutCtrls(i).getStringProp("type")==String("hostrecording")){ + else if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type)==String("hostrecording")){ if (getFilter()->getPlayHead() != 0 && getFilter()->getPlayHead()->getCurrentPosition (hostInfo)) - getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.isRecording); + getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), hostInfo.isRecording); } - else if(getFilter()->getGUILayoutCtrls(i).getStringProp("type")==String("hostppqpos")){ + else if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type)==String("hostppqpos")){ if (getFilter()->getPlayHead() != 0 && getFilter()->getPlayHead()->getCurrentPosition (hostInfo)) - getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.ppqPosition); + getFilter()->getCsound()->SetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), hostInfo.ppqPosition); debugLabel->setText(String(hostInfo.ppqPosition), dontSendNotification ); } } @@ -3174,23 +3342,23 @@ for(int i=0;i<(int)getFilter()->getGUILayoutCtrlsSize();i++){ //the following code looks after updating any objects that don't get recognised as plugin parameters, //for example, table objects don't get listed by the host as a paramters. Likewise the csoundoutput widget.. for(int i=0;igetGUILayoutCtrlsSize();i++){ - //String test = getFilter()->getGUILayoutCtrls(i).getStringProp("type"); + //String test = getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type); //Logger::writeToLog(test); - if(getFilter()->getGUILayoutCtrls(i).getStringProp("type").containsIgnoreCase("csoundoutput")){ + if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type).containsIgnoreCase("csoundoutput")){ ((CabbageMessageConsole*)layoutComps[i])->editor->setText(getFilter()->getCsoundOutput()); ((CabbageMessageConsole*)layoutComps[i])->editor->setCaretPosition(getFilter()->getCsoundOutput().length()); } - else if(getFilter()->getGUILayoutCtrls(i).getStringProp("type").containsIgnoreCase("vumeter")){ + else if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type).containsIgnoreCase("vumeter")){ //Logger::writeToLog(layoutComps[i]->getName()); for(int y=0;y<((CabbageVUMeter*)layoutComps[i])->getNoMeters();y++) - //String chann = getFilter()->getGUILayoutCtrls(i).getStringProp("channel", y); - //float val = getFilter()->getCsound()->GetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp("channel", y).toUTF8()); + //String chann = getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel, y); + //float val = getFilter()->getCsound()->GetChannel(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::channel, y).toUTF8()); ((CabbageVUMeter*)layoutComps[i])->vuMeter->setVULevel(y, 10); //} } - else if(getFilter()->getGUILayoutCtrls(i).getStringProp("type").containsIgnoreCase("table")){ + else if(getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type)==CabbageIDs::table){ //int tableNumber = getFilter()->getGUILayoutCtrls(i).getNumProp("tableNum"); - int numberOfTables = getFilter()->getGUILayoutCtrls(i).getStringArrayProp("tablenumber").size(); + int numberOfTables = getFilter()->getGUILayoutCtrls(i).getStringArrayProp(CabbageIDs::tablenumber).size(); //for(int y=0;ygetGUILayoutCtrls(i).getNumberOfTableChannels();y++) for(int y=0;ygetGUILayoutCtrlsSize();i++){ if(val<0) { - int tableNumber = getFilter()->getGUILayoutCtrls(i).getIntArrayPropValue("tablenumber", y); + int tableNumber = getFilter()->getGUILayoutCtrls(i).getIntArrayPropValue(CabbageIDs::tablenumber, y); Array tableValues = getFilter()->getTable(tableNumber); ((CabbageTable*)layoutComps[i])->fillTable(y, tableValues); - getFilter()->messageQueue.addOutgoingChannelMessageToQueue(getFilter()->getGUILayoutCtrls(i).getStringArrayPropValue("channel", y).toUTF8(), 0, - getFilter()->getGUILayoutCtrls(i).getStringProp("type")); + getFilter()->messageQueue.addOutgoingChannelMessageToQueue(getFilter()->getGUILayoutCtrls(i).getStringArrayPropValue(CabbageIDs::channel, y).toUTF8(), 0, + getFilter()->getGUILayoutCtrls(i).getStringProp(CabbageIDs::type)); } else { @@ -3226,36 +3394,36 @@ for(int i=0;igetGUILayoutCtrlsSize();i++){ { if(message.isController()) for(int i=0;i<(int)getFilter()->getGUICtrlsSize();i++) - if((message.getChannel()==getFilter()->getGUICtrls(i).getNumProp("midichan"))&& - (message.getControllerNumber()==getFilter()->getGUICtrls(i).getNumProp("midictrl"))) + if((message.getChannel()==getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::midichan))&& + (message.getControllerNumber()==getFilter()->getGUICtrls(i).getNumProp(CabbageIDs::midictrl))) { float value = message.getControllerValue()/127.f* (getFilter()->getGUICtrls(i).getNumProp("max")-getFilter()->getGUICtrls(i).getNumProp("min")+ getFilter()->getGUICtrls(i).getNumProp("min")); - if(getFilter()->getGUICtrls(i).getStringProp("type")==String("hslider")|| - getFilter()->getGUICtrls(i).getStringProp("type")==String("rslider")|| - getFilter()->getGUICtrls(i).getStringProp("type")==String("vslider")){ + if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String(CabbageIDs::hslider)|| + getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String(CabbageIDs::rslider)|| + getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String(CabbageIDs::vslider)){ if(comps[i]) ((CabbageSlider*)comps[i])->slider->setValue(value, dontSendNotification); } - else if(getFilter()->getGUICtrls(i).getStringProp("type")==String("button")){ + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String(CabbageIDs::button)){ if(comps[i]) ((CabbageButton*)comps[i])->button->setButtonText(getFilter()->getGUICtrls(i).getItems(1-(int)value)); } - else if(getFilter()->getGUICtrls(i).getStringProp("type")==String("combobox")){ + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String(CabbageIDs::combobox)){ if(comps[i]){ //((CabbageComboBox*)comps[i])->combo->setSelectedId((int)value+1.5, false); } } - else if(getFilter()->getGUICtrls(i).getStringProp("type")==String("checkbox")){ + else if(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::type)==String(CabbageIDs::checkbox)){ if(comps[i]) if(value==0) ((CabbageCheckbox*)comps[i])->button->setToggleState(0, dontSendNotification); else ((Button*)comps[i])->setToggleState(1, dontSendNotification); } - getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp("channel").toUTF8(), value); + getFilter()->getCsound()->SetChannel(getFilter()->getGUICtrls(i).getStringProp(CabbageIDs::channel).toUTF8(), value); if(message.isController()) if(getFilter()->getMidiDebug()){ String debugInfo = String("MIDI Channel: ")+String(message.getChannel())+String(" \t")+ diff --git a/ports/cabbage/source/Plugin/CabbagePluginEditor.h b/ports/cabbage/source/Plugin/CabbagePluginEditor.h index 1725ddda..f524b25b 100644 --- a/ports/cabbage/source/Plugin/CabbagePluginEditor.h +++ b/ports/cabbage/source/Plugin/CabbagePluginEditor.h @@ -69,7 +69,7 @@ PointData(Point point, int curveType):point(point),curveType(curveType) class CabbagePluginAudioProcessorEditor : public AudioProcessorEditor, public CabbageUtils, public SliderListener, - public ComboBoxListener, + public ComboBoxListener, public ButtonListener, public KeyListener, public ChangeBroadcaster, @@ -132,10 +132,15 @@ private: void InsertSnapshot(CabbageGUIClass &cAttr); void InsertPVSViewer(CabbageGUIClass &cAttr); void InsertTransport(CabbageGUIClass &cAttr); - void buttonClicked (Button*); + void buttonClicked(Button*); + void buttonStateChanged(Button*); void showInsertControlsMenu(int x, int y); void actionListenerCallbackForWidgets(const String message); void insertScoreStatementText(Table *table, bool overwrite); + void restoreParametersFromPresets(XmlElement* xmlData); + void savePresetsFromParameters(File selectedFile, String mode); + void refreshDiskReadingGUIControls(String typeOfControl); + void updateGUIControls(); void timerCallback(); bool LOCKED; diff --git a/ports/cabbage/source/Plugin/CabbagePluginProcessor.cpp b/ports/cabbage/source/Plugin/CabbagePluginProcessor.cpp index 4271d309..65502bb7 100644 --- a/ports/cabbage/source/Plugin/CabbagePluginProcessor.cpp +++ b/ports/cabbage/source/Plugin/CabbagePluginProcessor.cpp @@ -70,8 +70,10 @@ pluginType(_pluginType), automationAmp(0), isAutomator(false), automationParamID(-1), -debugMessage("") +debugMessage(""), +guiRefreshRate(20) { +//suspendProcessing(true); codeEditor = nullptr; #ifdef Cabbage_Logger logFile = File((appProperties->getCommonSettings(true)->getFile().getParentDirectory().getFullPathName()+"/CabbageLog.txt")); @@ -98,7 +100,7 @@ csound->SetHostImplementedMIDIIO(true); csound->Reset(); //Logger::writeToLog(csound->GetEnv("OPCODEDIR64")); #ifdef CSOUND5 -csound->PreCompile(); +csound->PreCompile(); #endif csound->SetHostData(this); csound->SetMessageCallback(CabbagePluginAudioProcessor::messageCallback); @@ -107,7 +109,6 @@ csound->SetExternalMidiReadCallback(ReadMidiData); csound->SetExternalMidiOutOpenCallback(OpenMidiOutputDevice); csound->SetExternalMidiWriteCallback(WriteMidiData); - #ifndef Cabbage_Plugin_Host if(!getPreference(appProperties, "UseCabbageIO")){ csoundPerfThread = new CsoundPerformanceThread(csound); @@ -125,7 +126,7 @@ csndIndex = 32; //set up PVS struct dataout = new PVSDATEXT; -if(!inputfile.isEmpty()){ +if(inputfile.isNotEmpty()){ File(inputfile).setAsCurrentWorkingDirectory(); #ifdef CSOUND6 csoundParams = new CSOUND_PARAMS(); @@ -136,6 +137,7 @@ csCompileResult = csound->Compile(const_cast(inputfile.toUTF8().getAddres if(csCompileResult==0){ +//send root directory path to Csound. setPlayConfigDetails(getNumberCsoundOutChannels(), getNumberCsoundOutChannels(), getCsoundSamplingRate(), @@ -145,8 +147,13 @@ if(csCompileResult==0){ csound->PerformKsmps(); csound->SetScoreOffsetSeconds(0); csound->RewindScore(); + #ifdef WIN32 + csound->SetChannel("CSD_PATH", File(inputfile).getParentDirectory().getFullPathName().replace("\\", "\\\\").toUTF8().getAddress()); + #else + csound->SetChannel("CSD_PATH", File(inputfile).getParentDirectory().getFullPathName().toUTF8().getAddress()); + #endif Logger::writeToLog("Csound compiled your file"); - + //csound->SetYieldCallback(CabbagePluginAudioProcessor::yieldCallback); if(csound->GetSpout()==nullptr); CSspout = csound->GetSpout(); @@ -159,6 +166,9 @@ if(csCompileResult==0){ csoundStatus = true; debugMessageArray.add(CABBAGE_VERSION); debugMessageArray.add(String("\n")); + this->setLatencySamples(csound->GetKsmps()); + updateHostDisplay(); + } else{ Logger::writeToLog("Csound couldn't compile your file"); @@ -263,9 +273,12 @@ csoundParams->nchnls_override =2; csound->SetParams(csoundParams); #endif +csdFile.setAsCurrentWorkingDirectory(); + csCompileResult = csound->Compile(const_cast(csdFile.getFullPathName().toUTF8().getAddress())); csdFile.setAsCurrentWorkingDirectory(); if(csCompileResult==0){ + Logger::writeToLog("compiled Ok"); keyboardState.allNotesOff(0); keyboardState.reset(); @@ -283,10 +296,30 @@ if(csCompileResult==0){ cs_scale = csound->Get0dBFS(); numCsoundChannels = csoundListChannels(csound->GetCsound(), &csoundChanList); csndIndex = csound->GetKsmps(); + this->setLatencySamples(csound->GetKsmps()); + updateHostDisplay(); //soundFilerVector = new MYFLT[csdKsmps]; csoundStatus = true; debugMessageArray.add(VERSION); debugMessageArray.add(String("\n")); + #ifdef WIN32 + csound->SetChannel("CSD_PATH", File(csdFile).getParentDirectory().getFullPathName().replace("\\", "\\\\").toUTF8().getAddress()); + #else + csound->SetChannel("CSD_PATH", File(csdFile).getParentDirectory().getFullPathName().toUTF8().getAddress()); + #endif + + //send host info before performance.. + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::hostbpm.toUTF8(), hostInfo.bpm); + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::timeinseconds.toUTF8(), hostInfo.timeInSeconds); + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::isplaying.toUTF8(), hostInfo.isPlaying); + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::isrecording.toUTF8(), hostInfo.isRecording); + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::hostppqpos.toUTF8(), hostInfo.ppqPosition); + } else{ Logger::writeToLog("Csound couldn't compile your file"); @@ -367,12 +400,12 @@ void CabbagePluginAudioProcessor::YieldCallback(void* data){ void CabbagePluginAudioProcessor::reCompileCsound(File file) { #ifndef Cabbage_No_Csound -this->suspendProcessing(true); +suspendProcessing(true); soundFileIndex = 0; midiOutputBuffer.clear(); getCallbackLock().enter(); csound->DeleteChannelList(csoundChanList); -//csound->SetHostImplementedMIDIIO(true); +csound->SetHostImplementedMIDIIO(true); csound->Reset(); xyAutosCreated = false; @@ -394,6 +427,7 @@ if(csCompileResult==0){ //simple hack to allow tables to be set up correctly. keyboardState.allNotesOff(0); keyboardState.reset(); + csndIndex = 0; CSspout = csound->GetSpout(); CSspin = csound->GetSpin(); csound->PerformKsmps(); @@ -405,17 +439,24 @@ if(csCompileResult==0){ csoundStatus = true; debugMessageArray.add(CABBAGE_VERSION); debugMessageArray.add(String("\n")); - removeAllChangeListeners(); + //removeAllChangeListeners(); getCallbackLock().exit(); //init all channels with their init val for(int i=0;iSetChannel( guiCtrls.getReference(i).getStringProp("channel").toUTF8(), - guiCtrls.getReference(i).getNumProp("value")); + csound->SetChannel( guiCtrls.getReference(i).getStringProp(CabbageIDs::channel).toUTF8(), + guiCtrls.getReference(i).getNumProp(CabbageIDs::value)); } + #ifdef WIN32 + csound->SetChannel("CSD_PATH", file.getParentDirectory().getFullPathName().replace("\\", "\\\\").toUTF8().getAddress()); + #else + csound->SetChannel("CSD_PATH", file.getParentDirectory().getFullPathName().toUTF8().getAddress()); + #endif + this->suspendProcessing(false); + return; } else{ @@ -431,6 +472,7 @@ getCallbackLock().exit(); // GUI OBJECTS ARE CREATED ON THE FLY IN THE CABBAGE PLUGIN // EDITOR FROM INFORMATION HELD IN THE GUICONTROLS VECTOR //=========================================================== +//maybe this should only be done at the end of a k-rate cycle.. void CabbagePluginAudioProcessor::createGUI(String source, bool refresh) { //clear arrays if refresh is set @@ -551,6 +593,8 @@ bool multiLine = false; nativePluginEditor = true; return; } + if(cAttr.getNumProp(CabbageIDs::guirefresh)>1) + guiRefreshRate = cAttr.getNumProp(CabbageIDs::guirefresh); //showMessage(cAttr.getStringProp("type")); csdLine = ""; @@ -564,11 +608,11 @@ bool multiLine = false; //set up stuff for tables if(tokes[0].equalsIgnoreCase(String("table"))){ - if(cAttr.getStringArrayProp("channel").size()==0) + if(cAttr.getStringArrayProp(CabbageIDs::channel).size()==0) for(int i=0;iSetChannel( guiCtrls.getReference(i).getStringProp("channel").toUTF8(), guiCtrls[i].getNumProp("value")); - //float min = guiCtrls.getReference(i).getNumProp("min"); - //float range = guiCtrls.getReference(i).getNumProp("range"); - //setParameter(i, (guiCtrls.getReference(i).getNumProp("value")+min)/range); + if(guiCtrls.getReference(i).getStringProp("channeltype")=="string") + //deal with combobox strings.. + csound->SetChannel(guiCtrls.getReference(i).getStringProp(CabbageIDs::channel).toUTF8(), ""); +// guiCtrls.getReference(i).getStringArrayPropValue("text", guiCtrls[i].getNumProp(CabbageIDs::value)-1).toUTF8().getAddress()); + else + csound->SetChannel( guiCtrls.getReference(i).getStringProp(CabbageIDs::channel).toUTF8(), guiCtrls[i].getNumProp(CabbageIDs::value)); #endif } @@ -771,7 +817,7 @@ void CabbagePluginAudioProcessor::setupNativePluginEditor() Logger::writeToLog(parameterInfo); CabbageGUIClass cAttr(parameterInfo, guiID); cAttr.setNumProp("range", dmax-dmin); - //cAttr.setStringProp("channel", entry.name); + //cAttr.setStringProp(CabbageIDs::channel, entry.name); //cAttr.setNumProp("max", (dmax>0 ? dmax : 1)); //cAttr.setNumProp("init", (ddefaultgetYValue()/xyPad->getYRange())-(fabs(xyPad->getMinimumYValue())/xyPad->getYRange()); - Logger::writeToLog("Param:"+String(xyPad->paramIndex)+" xyPadXVal:"+String(xVal)); - Logger::writeToLog("Param:"+String(xyPad->paramIndex+1)+" xyPadYVal:"+String(yVal)); + //Logger::writeToLog("Param:"+String(xyPad->paramIndex)+" xyPadXVal:"+String(xVal)); + //Logger::writeToLog("Param:"+String(xyPad->paramIndex+1)+" xyPadYVal:"+String(yVal)); setParameterNotifyingHost(xyPad->paramIndex, xVal); setParameterNotifyingHost(xyPad->paramIndex+1, yVal); @@ -905,21 +951,24 @@ const Array CabbagePluginAudioProcessor::getTable(int t //================================================================================= float CabbagePluginAudioProcessor::getParameter (int index) { -float range = getGUICtrls(index).getNumProp("range"); -float min = getGUICtrls(index).getNumProp("min"); -//Logger::writeToLog("parameterGet-"+String(index)+String("-Min:")+String(min)+" Range:"+String(range)+ " Val:"+String(getGUICtrls(index).getNumProp("value"))); -//Logger::writeToLog("parameterGet:"+String(index)+String(":")+String(getGUICtrls(index).getNumProp("value"))); +float range = getGUICtrls(index).getNumProp(CabbageIDs::range); +float min = getGUICtrls(index).getNumProp(CabbageIDs::min); +//Logger::writeToLog("parameterGet-"+String(index)+String("-Min:")+String(min)+" Range:"+String(range)+ " Val:"+String(getGUICtrls(index).getNumProp(CabbageIDs::value))); +//Logger::writeToLog("parameterGet:"+String(index)+String(":")+String(guiCtrls[index].getNumProp(CabbageIDs::value))); /* this gets called at any time by our host or out GUI editor */ if(index<(int)guiCtrls.size()){//make sure index isn't out of range #ifndef Cabbage_Build_Standalone - float val = (getGUICtrls(index).getNumProp("value")/range)-(min/range); - if(getGUICtrls(index).getStringProp("type")=="combobox") - return (getGUICtrls(index).getNumProp("value")/getGUICtrls(index).getNumProp("comborange")); + float val = (getGUICtrls(index).getNumProp(CabbageIDs::value)/range)-(min/range); + if(getGUICtrls(index).getStringProp(CabbageIDs::type)==CabbageIDs::combobox) + return (getGUICtrls(index).getNumProp(CabbageIDs::value)/getGUICtrls(index).getNumProp(CabbageIDs::comborange)); + else if(getGUICtrls(index).getStringProp(CabbageIDs::type)==CabbageIDs::checkbox || + getGUICtrls(index).getStringProp(CabbageIDs::type)==CabbageIDs::button) + return getGUICtrls(index).getNumProp(CabbageIDs::value); else - return (getGUICtrls(index).getNumProp("value")/range)-(min/range); + return (getGUICtrls(index).getNumProp(CabbageIDs::value)/range)-(min/range); #else - return getGUICtrls(index).getNumProp("value"); + return guiCtrls[index].getNumProp(CabbageIDs::value); #endif } else @@ -929,6 +978,7 @@ else void CabbagePluginAudioProcessor::setParameter (int index, float newValue) { +String stringMessage; #ifndef Cabbage_No_Csound /* this will get called by the plugin GUI sliders or by the host, via automation. The timer thread in the plugin's editor @@ -941,30 +991,45 @@ if(index<(int)guiCtrls.size())//make sure index isn't out of range { #ifndef Cabbage_Build_Standalone //scaling in here because incoming values in plugin mode range from 0-1 - range = getGUICtrls(index).getNumProp("range"); - comboRange = getGUICtrls(index).getNumProp("comborange"); + range = getGUICtrls(index).getNumProp(CabbageIDs::range); + comboRange = getGUICtrls(index).getNumProp(CabbageIDs::comborange); //Logger::writeToLog("inValue:"+String(newValue)); - min = getGUICtrls(index).getNumProp("min"); + min = getGUICtrls(index).getNumProp(CabbageIDs::min); - if(getGUICtrls(index).getStringProp("type")=="xypad") + if(getGUICtrls(index).getStringProp(CabbageIDs::type)==CabbageIDs::xypad) newValue = (jmax(0.f, newValue)*range)+min; - else if(getGUICtrls(index).getStringProp("type")=="combobox")//combo box value need to be rounded... + else if(getGUICtrls(index).getStringProp(CabbageIDs::type)==CabbageIDs::combobox)//combo box value need to be rounded... newValue = (newValue*comboRange); - else if(getGUICtrls(index).getStringProp("type")=="checkbox") + else if(getGUICtrls(index).getStringProp(CabbageIDs::type)==CabbageIDs::checkbox || + getGUICtrls(index).getStringProp(CabbageIDs::type)==CabbageIDs::button) range=1; else newValue = (newValue*range)+min; - guiCtrls.getReference(index).setNumProp("value", newValue); - messageQueue.addOutgoingChannelMessageToQueue(guiCtrls.getReference(index).getStringProp("channel").toUTF8(), newValue, - guiCtrls.getReference(index).getStringProp("type")); - Logger::writeToLog(String("parameterSet:"+String(newValue))); - #else - //no need to scale here when in standalone mode - guiCtrls.getReference(index).setNumProp("value", newValue); - messageQueue.addOutgoingChannelMessageToQueue(guiCtrls.getReference(index).getStringProp("channel").toUTF8(), newValue, - guiCtrls.getReference(index).getStringProp("type")); + //guiCtrls.getReference(index).setNumProp(CabbageIDs::value, newValue); + //messageQueue.addOutgoingChannelMessageToQueue(guiCtrls.getReference(index).getStringProp(CabbageIDs::channel).toUTF8(), newValue, + //guiCtrls.getReference(index).getStringProp("type")); + //Logger::writeToLog(String("parameterSet:"+String(newValue))); #endif + //Logger::writeToLog(String("parameterSet:"+String(newValue))); + //no need to scale here when in standalone mode + + if(getGUICtrls(index).getStringProp(CabbageIDs::type)==CabbageIDs::combobox && + getGUICtrls(index).getStringProp(CabbageIDs::channeltype)==CabbageIDs::stringchannel) + { + stringMessage = getGUICtrls(index).getStringArrayPropValue(CabbageIDs::text, newValue-1); + //Logger::writeToLog(stringMessage); + messageQueue.addOutgoingChannelMessageToQueue(guiCtrls.getReference(index).getStringProp(CabbageIDs::channel), + stringMessage, + CabbageIDs::stringchannel); + } + else + messageQueue.addOutgoingChannelMessageToQueue(guiCtrls.getReference(index).getStringProp(CabbageIDs::channel), + newValue, + guiCtrls.getReference(index).getStringProp(CabbageIDs::type)); + + + guiCtrls.getReference(index).setNumProp(CabbageIDs::value, newValue); } #endif } @@ -979,28 +1044,38 @@ void CabbagePluginAudioProcessor::updateCabbageControls() { #ifndef Cabbage_No_Csound String chanName; -MYFLT* val=0; -//update all control widgets -for(int index=0;indexGetChannel(guiCtrls[index].getStringProp("channel").toUTF8()); - guiCtrls[index].setNumProp("value", value); - } - + MYFLT* val=0; + //update all control widgets + for(int index=0;indexGetChannel(guiCtrls[index].getStringProp(CabbageIDs::channel).getCharPointer()); + //Logger::writeToLog("Channel:"+guiCtrls[index].getStringProp(CabbageIDs::channel)); + //Logger::writeToLog("value:"+String(value)); + guiCtrls.getReference(index).setNumProp(CabbageIDs::value, value); + } + } //update all layout control widgets //currently this is only needed for table widgets as other layout controls //don't use channel messages... -for(int index=0;indexGetChannel(guiLayoutCtrls[index].getStringArrayPropValue("channel", y).toUTF8()); - guiLayoutCtrls[index].setTableChannelValues(y, value); + if(guiLayoutCtrls[index].getStringProp(CabbageIDs::type)==CabbageIDs::table) + { + for(int y=0;yGetChannel(guiLayoutCtrls[index].getStringArrayPropValue(CabbageIDs::channel, y).getCharPointer()); + guiLayoutCtrls[index].setTableChannelValues(y, value); + } } } } +sendChangeMessage(); #endif } @@ -1010,8 +1085,27 @@ for(int index=0;indexgetCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::hostbpm.toUTF8(), hostInfo.bpm); + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::timeinseconds.toUTF8(), hostInfo.timeInSeconds); + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::isplaying.toUTF8(), hostInfo.isPlaying); + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::isrecording.toUTF8(), hostInfo.isRecording); + if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) + csound->SetChannel(CabbageIDs::hostppqpos.toUTF8(), hostInfo.ppqPosition); + +#endif + + + for(int i=0;iInputMessage(scoreEvents[y].toUTF8()); @@ -1020,21 +1114,27 @@ for(int i=0;iInputMessage(messageQueue.getOutgoingChannelMessageFromQueue(i).fStatement.toUTF8()); + csound->InputMessage(messageQueue.getOutgoingChannelMessageFromQueue(i).fStatement.getCharPointer()); + } + //catch string messags + else if(messageQueue.getOutgoingChannelMessageFromQueue(i).type==CabbageIDs::stringchannel){ + csound->SetChannel(messageQueue.getOutgoingChannelMessageFromQueue(i).channelName.getCharPointer(), + messageQueue.getOutgoingChannelMessageFromQueue(i).stringVal.toUTF8().getAddress()); } else - csound->SetChannel(messageQueue.getOutgoingChannelMessageFromQueue(i).channelName.toUTF8(), + csound->SetChannel(messageQueue.getOutgoingChannelMessageFromQueue(i).channelName.getCharPointer(), messageQueue.getOutgoingChannelMessageFromQueue(i).value); } messageQueue.flushOutgoingChannelMessages(); -if(isAutomator){ - //sendChangeMessage(); - //sendActionMessage("update automation:"+String(automationParamID)+"|"+String(automationAmp)); - //Logger::writeToLog("update automation:"+String(automationAmp)); + if(isAutomator){ + //sendChangeMessage(); + //sendActionMessage("update automation:"+String(automationParamID)+"|"+String(automationAmp)); + //Logger::writeToLog("update automation:"+String(automationAmp)); + } + } -} #endif } @@ -1110,14 +1210,14 @@ int CabbagePluginAudioProcessor::getNumParameters() const String CabbagePluginAudioProcessor::getParameterName (int index) { if(index<(int)guiCtrls.size())//make sure index isn't out of range - return guiCtrls.getReference(index).getStringProp("channel"); + return guiCtrls.getReference(index).getStringProp(CabbageIDs::channel); else return String::empty; } const String CabbagePluginAudioProcessor::getParameterText (int index) { if(index<(int)guiCtrls.size())//make sure index isn't out of range - return String (guiCtrls.getReference(index).getNumProp("value"), 2); + return String (guiCtrls.getReference(index).getNumProp(CabbageIDs::value), 2); else return String::empty; } @@ -1164,10 +1264,14 @@ bool CabbagePluginAudioProcessor::producesMidi() const } void CabbagePluginAudioProcessor::setGuiEnabled(bool val){ +#ifdef Cabbage_Build_Standalone guiON = val; CabbagePluginAudioProcessorEditor* editor = dynamic_cast< CabbagePluginAudioProcessorEditor*>(this->getActiveEditor()); if(editor){ if(val==false){ + int val = getPreference(appProperties, "ExternalEditor"); + if(val) + csdFile.replaceWithText(codeEditor->getAllText()); //editor->resizer->setVisible(false); //editor->propsWindow->setVisible(false); } @@ -1175,6 +1279,7 @@ void CabbagePluginAudioProcessor::setGuiEnabled(bool val){ //editor->resizer->setVisible(true); } } +#endif } int CabbagePluginAudioProcessor::getNumPrograms() @@ -1222,35 +1327,6 @@ void CabbagePluginAudioProcessor::releaseResources() //host widgets are being used void CabbagePluginAudioProcessor::timerCallback(){ #ifndef Cabbage_No_Csound - -if(!isGuiEnabled()){ - //initiliase any channels send host information to Csound - AudioPlayHead::CurrentPositionInfo hostInfo; - for(int i=0;i<(int)getGUILayoutCtrlsSize();i++){ - if(getGUILayoutCtrls(i).getStringProp("type")==String("hostbpm")){ - if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) - csound->SetChannel(getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.bpm); - } - else if(getGUILayoutCtrls(i).getStringProp("type")==String("hosttime")){ - if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) - csound->SetChannel(getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.timeInSeconds); - } - else if(getGUILayoutCtrls(i).getStringProp("type")==String("hostplaying")){ - if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) - csound->SetChannel(getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.isPlaying); - } - else if(getGUILayoutCtrls(i).getStringProp("type")==String("hostrecording")){ - if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) - csound->SetChannel(getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.isRecording); - } - else if(getGUILayoutCtrls(i).getStringProp("type")==String("hostppqpos")){ - if (getPlayHead() != 0 && getPlayHead()->getCurrentPosition (hostInfo)) - csound->SetChannel(getGUILayoutCtrls(i).getStringProp("channel").toUTF8(), hostInfo.ppqPosition); - } - } - -}// end of GUI enabled check - for(int y=0;yupdate(); @@ -1287,7 +1363,7 @@ if(!isSuspended() && !isGuiEnabled()){ { getCallbackLock().enter(); //slow down calls to these functions, no need for them to be firing at k-rate - yieldCounter = (yieldCounter>10) ? 0 : yieldCounter+1; + yieldCounter = (yieldCounter>guiRefreshRate) ? 0 : yieldCounter+1; if(yieldCounter==0){ sendOutgoingMessagesToCsound(); updateCabbageControls(); @@ -1295,13 +1371,14 @@ if(!isSuspended() && !isGuiEnabled()){ if(audioSourcesArray.size()>0) sendAudioToCsoundFromSoundFilers(csound->GetKsmps()); - CSCompResult = csound->PerformKsmps(); - if(CSCompResult!=0) + csCompileResult = csound->PerformKsmps(); + if(csCompileResult!=0) suspendProcessing(true); + getCallbackLock().exit(); csndIndex = 0; } - if(!CSCompResult) + if(!csCompileResult) { for(int channel = 0; channel < getNumOutputChannels(); channel++ ) { @@ -1449,17 +1526,39 @@ AudioProcessorEditor* CabbagePluginAudioProcessor::createEditor() } //============================================================================== -void CabbagePluginAudioProcessor::getStateInformation (MemoryBlock& /*destData*/) +void CabbagePluginAudioProcessor::getStateInformation (MemoryBlock& destData) { // You should use this method to store your parameters in the memory block. - // You could do that either as raw data, or use the XML or ValueTree classes - // as intermediaries to make it easy to save and load complex data. + // Here's an example of how you can use XML to make it easy and more robust: + + // Create an outer XML element.. + XmlElement xml ("CABBAGE_PLUGIN_SETTINGS"); + + for(int i=0;i xmlState (getXmlFromBinary (data, sizeInBytes)); + + if (xmlState != nullptr) + { + // make sure that it's actually our type of XML object.. + if (xmlState->hasTagName ("CABBAGE_PLUGIN_SETTINGS")) + { + for(int i=0;igetNumParameters();i++) + this->setParameter(i, (float)xmlState->getDoubleAttribute(guiCtrls[i].getStringProp(CabbageIDs::channel))); + + } + } } //============================================================================== diff --git a/ports/cabbage/source/Plugin/CabbagePluginProcessor.h b/ports/cabbage/source/Plugin/CabbagePluginProcessor.h index d5d8f78b..b7e34a14 100644 --- a/ports/cabbage/source/Plugin/CabbagePluginProcessor.h +++ b/ports/cabbage/source/Plugin/CabbagePluginProcessor.h @@ -40,7 +40,7 @@ //#include "../Editor/CabbageEditorWindow.h" //#endif -#define CABBAGE_VERSION "Cabbage v0.5.02 Alpha" +#define CABBAGE_VERSION "Cabbage v0.5.07 Alpha" #define AUDIO_PLUGIN 1 #define EXTERNAL_PLUGIN 2 @@ -81,6 +81,7 @@ protected: bool updateTable; Array tableNumbers; AudioSourceChannelInfo soundfilerChannelData; + AudioPlayHead::CurrentPositionInfo hostInfo; int soundFileIndex; //ScopedPointer fileLogger; @@ -118,7 +119,7 @@ protected: int getNumberCsoundInChannels(){ //return csound->GetInNchnls(); } - + int getCsoundSamplingRate(){ return csound->GetSr(); } @@ -147,6 +148,7 @@ protected: bool editorReOpened; OwnedArray xyAutomation; void updateGUIControlsKsmps(int speed); + int guiRefreshRate; public: //============================================================================== @@ -236,6 +238,7 @@ public: int pluginType; float automationAmp; int automationParamID; + int pluginCalls, csoundCalls; //==============================================================================