gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

tagtreeitem.cpp (4023B)


      1 #include "tagtreeitem.h"
      2 
      3 #include "patchmanager.h"
      4 #include "tree.h"
      5 
      6 #if JUCE_MAJOR_VERSION < 8	// they forgot this include but fixed it in version 8+
      7 #include "juce_gui_extra/misc/juce_ColourSelector.h"
      8 #endif
      9 
     10 namespace jucePluginEditorLib::patchManager
     11 {
     12 	TagTreeItem::TagTreeItem(PatchManager& _pm, const GroupType _type, const std::string& _tag) : TreeItem(_pm, _tag), m_group(_type), m_tag(_tag)
     13 	{
     14 		const auto tagType = toTagType(getGroupType());
     15 
     16 		if(tagType == pluginLib::patchDB::TagType::Favourites)
     17 		{
     18 			pluginLib::patchDB::SearchRequest sr;
     19 			sr.tags.add(tagType, getTag());
     20 
     21 			search(std::move(sr));
     22 		}
     23 
     24 		setDeselectonSecondClick(true);
     25 	}
     26 
     27 	bool TagTreeItem::isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails)
     28 	{
     29 		return TreeItem::isInterestedInDragSource(dragSourceDetails) && hasSearch();
     30 	}
     31 
     32 	bool TagTreeItem::isInterestedInPatchList(const ListModel*, const std::vector<pluginLib::patchDB::PatchPtr>&)
     33 	{
     34 		return hasSearch() && toTagType(getGroupType()) != pluginLib::patchDB::TagType::Invalid;
     35 	}
     36 
     37 	void TagTreeItem::patchesDropped(const std::vector<pluginLib::patchDB::PatchPtr>& _patches, const SavePatchDesc*/* _savePatchDesc = nullptr*/)
     38 	{
     39 		const auto tagType = toTagType(getGroupType());
     40 
     41 		if (tagType == pluginLib::patchDB::TagType::Invalid)
     42 			return;
     43 
     44 		modifyTags(getPatchManager(), tagType, getTag(), _patches);
     45 	}
     46 
     47 	void TagTreeItem::onParentSearchChanged(const pluginLib::patchDB::SearchRequest& _parentSearchRequest)
     48 	{
     49 		const auto tagType = toTagType(getGroupType());
     50 
     51 		if(tagType == pluginLib::patchDB::TagType::Invalid)
     52 			return;
     53 
     54 		pluginLib::patchDB::SearchRequest sr = _parentSearchRequest;
     55 		sr.tags.add(tagType, getTag());
     56 
     57 		search(std::move(sr));
     58 	}
     59 
     60 	void TagTreeItem::modifyTags(PatchManager& _pm, pluginLib::patchDB::TagType _type, const std::string& _tag, const std::vector<pluginLib::patchDB::PatchPtr>& _patches)
     61 	{
     62 		pluginLib::patchDB::TypedTags tags;
     63 		if (juce::ModifierKeys::currentModifiers.isShiftDown())
     64 			tags.addRemoved(_type, _tag);
     65 		else
     66 			tags.add(_type, _tag);
     67 
     68 		_pm.modifyTags(_patches, tags);
     69 		_pm.repaint();
     70 	}
     71 
     72 	void TagTreeItem::itemClicked(const juce::MouseEvent& _mouseEvent)
     73 	{
     74 		if(!_mouseEvent.mods.isPopupMenu())
     75 		{
     76 			TreeItem::itemClicked(_mouseEvent);
     77 			return;
     78 		}
     79 
     80 		const auto tagType = toTagType(getGroupType());
     81 
     82 		if(tagType != pluginLib::patchDB::TagType::Invalid && getOwnerView()->getNumSelectedItems() == 1)
     83 		{
     84 			juce::PopupMenu menu;
     85 			const auto& s = getPatchManager().getSearch(getSearchHandle());
     86 			if(s && !s->getResultSize())
     87 			{
     88 				menu.addItem("Remove", [this, tagType]
     89 				{
     90 					getPatchManager().removeTag(tagType, m_tag);
     91 				});
     92 			}
     93 			menu.addItem("Set Color...", [this, tagType]
     94 			{
     95 				juce::ColourSelector* cs = new juce::ColourSelector(juce::ColourSelector::showColourAtTop | juce::ColourSelector::showSliders | juce::ColourSelector::showColourspace);
     96 
     97 				cs->getProperties().set("tagType", static_cast<int>(tagType));
     98 				cs->getProperties().set("tag", juce::String(getTag()));
     99 
    100 				cs->setSize(400,300);
    101 				cs->setCurrentColour(juce::Colour(getColor()));
    102 				cs->addChangeListener(&getPatchManager());
    103 
    104 				const auto treeRect = getTree()->getScreenBounds();
    105 				const auto itemRect = getItemPosition(true);
    106 				auto rect = itemRect;
    107 				rect.translate(treeRect.getX(), treeRect.getY());
    108 
    109 				juce::CallOutBox::launchAsynchronously(std::unique_ptr<juce::Component>(cs), rect, nullptr);
    110 			});
    111 			if(getColor() != pluginLib::patchDB::g_invalidColor)
    112 			{
    113 				menu.addItem("Clear Color", [this, tagType]
    114 				{
    115 					getPatchManager().setTagColor(tagType, getTag(), pluginLib::patchDB::g_invalidColor);
    116 					getPatchManager().repaint();
    117 				});
    118 			}
    119 
    120 			menu.showMenuAsync({});
    121 		}
    122 	}
    123 
    124 	pluginLib::patchDB::Color TagTreeItem::getColor() const
    125 	{
    126 		const auto tagType = toTagType(getGroupType());
    127 		if(tagType != pluginLib::patchDB::TagType::Invalid)
    128 			return getPatchManager().getTagColor(tagType, getTag());
    129 		return TreeItem::getColor();
    130 	}
    131 }