From 3bc96b347ae12e530f0dd56495c87caccc9043ec Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Mon, 22 Aug 2011 19:34:36 +0100 Subject: [PATCH] VST fix. Minor clean-ups. --- .../format_types/juce_VSTPluginFormat.cpp | 17 ++++--- .../juce_gui_basics/menus/juce_PopupMenu.cpp | 51 +++++-------------- .../juce_gui_basics/menus/juce_PopupMenu.h | 2 - 3 files changed, 23 insertions(+), 47 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp index 42fae03b00..b7706e136a 100644 --- a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp @@ -1779,8 +1779,12 @@ private: void removeView (HIViewRef) { - owner->dispatch (effEditClose, 0, 0, 0, 0); - owner->dispatch (effEditSleep, 0, 0, 0, 0); + if (owner->isOpen) + { + owner->isOpen = false; + owner->dispatch (effEditClose, 0, 0, 0, 0); + owner->dispatch (effEditSleep, 0, 0, 0, 0); + } } bool getEmbeddedViewSize (int& w, int& h) @@ -1992,11 +1996,11 @@ bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSiz if (usesChunks()) { + MemoryBlock chunk; + getChunkData (chunk, ! isFXB, maxSizeMB); + if (isFXB) { - MemoryBlock chunk; - getChunkData (chunk, false, maxSizeMB); - const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8; dest.setSize (totalLen, true); @@ -2014,9 +2018,6 @@ bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSiz } else { - MemoryBlock chunk; - getChunkData (chunk, true, maxSizeMB); - const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8; dest.setSize (totalLen, true); diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index 054503003e..6a1d20cd06 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -270,7 +270,12 @@ public: setOpaque (getLookAndFeel().findColour (PopupMenu::backgroundColourId).isOpaque() || ! Desktop::canUseSemiTransparentWindows()); for (int i = 0; i < menu.items.size(); ++i) - items.add (new PopupMenu::ItemComponent (*menu.items.getUnchecked(i), standardItemHeight, this)); + { + PopupMenu::Item* const item = menu.items.getUnchecked(i); + + if (i < menu.items.size() - 1 || ! item->isSeparator) + items.add (new PopupMenu::ItemComponent (*item, standardItemHeight, this)); + } calculateWindowPos (target, alignToRectangle); setTopLeftPosition (windowPos.getPosition()); @@ -667,7 +672,7 @@ private: bool isOver, hasBeenOver, isDown, needsToScroll; bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus; int numColumns, contentHeight, childYOffset; - Array columnWidths; + Array columnWidths; uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp; double scrollAcceleration; @@ -1162,14 +1167,12 @@ private: //============================================================================== PopupMenu::PopupMenu() - : lookAndFeel (nullptr), - separatorPending (false) + : lookAndFeel (nullptr) { } PopupMenu::PopupMenu (const PopupMenu& other) - : lookAndFeel (other.lookAndFeel), - separatorPending (other.separatorPending) + : lookAndFeel (other.lookAndFeel) { items.addCopiesOf (other.items); } @@ -1189,8 +1192,7 @@ PopupMenu& PopupMenu::operator= (const PopupMenu& other) #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS PopupMenu::PopupMenu (PopupMenu&& other) noexcept - : lookAndFeel (other.lookAndFeel), - separatorPending (other.separatorPending) + : lookAndFeel (other.lookAndFeel) { items.swapWithArray (other.items); } @@ -1201,34 +1203,19 @@ PopupMenu& PopupMenu::operator= (PopupMenu&& other) noexcept { items.swapWithArray (other.items); lookAndFeel = other.lookAndFeel; - separatorPending = other.separatorPending; } return *this; } #endif - PopupMenu::~PopupMenu() { - clear(); } void PopupMenu::clear() { items.clear(); - separatorPending = false; -} - -void PopupMenu::addSeparatorIfPending() -{ - if (separatorPending) - { - separatorPending = false; - - if (items.size() > 0) - items.add (new Item()); - } } void PopupMenu::addItem (const int itemResultId, const String& itemText, @@ -1238,8 +1225,6 @@ void PopupMenu::addItem (const int itemResultId, const String& itemText, // didn't pick anything, so you shouldn't use it as the id // for an item.. - addSeparatorIfPending(); - items.add (new Item (itemResultId, itemText, isActive, isTicked, iconToUse, Colours::black, false, 0, 0, 0)); } @@ -1257,8 +1242,6 @@ void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager, ApplicationCommandInfo info (*registeredInfo); ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info); - addSeparatorIfPending(); - items.add (new Item (commandID, displayName.isNotEmpty() ? displayName : info.shortName, @@ -1283,8 +1266,6 @@ void PopupMenu::addColouredItem (const int itemResultId, // didn't pick anything, so you shouldn't use it as the id // for an item.. - addSeparatorIfPending(); - items.add (new Item (itemResultId, itemText, isActive, isTicked, iconToUse, itemTextColour, true, 0, 0, 0)); } @@ -1296,8 +1277,6 @@ void PopupMenu::addCustomItem (const int itemResultId, CustomComponent* const cu // didn't pick anything, so you shouldn't use it as the id // for an item.. - addSeparatorIfPending(); - items.add (new Item (itemResultId, String::empty, true, false, Image::null, Colours::black, false, customComponent, 0, 0)); } @@ -1348,18 +1327,16 @@ void PopupMenu::addSubMenu (const String& subMenuName, const Image& iconToUse, const bool isTicked) { - addSeparatorIfPending(); - items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked, iconToUse, Colours::black, false, 0, &subMenu, 0)); } void PopupMenu::addSeparator() { - separatorPending = true; + if (items.size() > 0 && ! items.getLast()->isSeparator) + items.add (new Item()); } - //============================================================================== class HeaderItemComponent : public PopupMenu::CustomComponent { @@ -1627,10 +1604,10 @@ bool PopupMenu::containsCommandItem (const int commandID) const { for (int i = items.size(); --i >= 0;) { - const Item* mi = items.getUnchecked (i); + const Item* const mi = items.getUnchecked (i); if ((mi->itemId == commandID && mi->commandManager != nullptr) - || (mi->subMenu != nullptr && mi->subMenu->containsCommandItem (commandID))) + || (mi->subMenu != nullptr && mi->subMenu->containsCommandItem (commandID))) { return true; } diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.h b/modules/juce_gui_basics/menus/juce_PopupMenu.h index 7c1e953c75..ae09843ade 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.h +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.h @@ -487,9 +487,7 @@ private: OwnedArray items; LookAndFeel* lookAndFeel; - bool separatorPending; - void addSeparatorIfPending(); Component* createWindow (const Options&, ApplicationCommandManager**) const; int showWithOptionalCallback (const Options&, ModalComponentManager::Callback*, bool);