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

commit 9531f9d2066ac527ddca975cbcd3dd424f044656
parent b7ae1e32d5e652a0f57a9d2c5365c500de864810
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sat, 13 Jul 2024 19:16:14 +0200

separated list model and list component

Diffstat:
Msource/jucePluginEditorLib/patchmanager/list.cpp | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msource/jucePluginEditorLib/patchmanager/list.h | 25+++++++++++++++++++++++++
Msource/jucePluginEditorLib/patchmanager/listitem.cpp | 2+-
Msource/jucePluginEditorLib/patchmanager/listmodel.cpp | 57++++++++++++++++-----------------------------------------
Msource/jucePluginEditorLib/patchmanager/listmodel.h | 16++++++++++++++--
Msource/jucePluginEditorLib/patchmanager/patchmanager.cpp | 3++-
Msource/jucePluginEditorLib/patchmanager/patchmanager.h | 3++-
7 files changed, 149 insertions(+), 46 deletions(-)

diff --git a/source/jucePluginEditorLib/patchmanager/list.cpp b/source/jucePluginEditorLib/patchmanager/list.cpp @@ -0,0 +1,89 @@ +#include "list.h" + +#include "defaultskin.h" +#include "patchmanager.h" + +#include "../../juceUiLib/uiObject.h" + +#include "../pluginEditor.h" + +namespace jucePluginEditorLib::patchManager +{ + List::List(PatchManager& _pm) : ListModel(_pm) + { + setColour(backgroundColourId, juce::Colour(defaultSkin::colors::background)); + setColour(textColourId, juce::Colour(defaultSkin::colors::itemText)); + + getViewport()->setScrollBarsShown(true, false); + setModel(this); + setMultipleSelectionEnabled(true); + + if (const auto& t = _pm.getTemplate("pm_listbox")) + t->apply(_pm.getEditor(), *this); + + if(const auto t = _pm.getTemplate("pm_scrollbar")) + { + t->apply(_pm.getEditor(), getVerticalScrollBar()); + t->apply(_pm.getEditor(), getHorizontalScrollBar()); + } + else + { + getVerticalScrollBar().setColour(juce::ScrollBar::thumbColourId, juce::Colour(defaultSkin::colors::scrollbar)); + getVerticalScrollBar().setColour(juce::ScrollBar::trackColourId, juce::Colour(defaultSkin::colors::scrollbar)); + getHorizontalScrollBar().setColour(juce::ScrollBar::thumbColourId, juce::Colour(defaultSkin::colors::scrollbar)); + getHorizontalScrollBar().setColour(juce::ScrollBar::trackColourId, juce::Colour(defaultSkin::colors::scrollbar)); + } + + setRowSelectedOnMouseDown(false); + } + + juce::Colour List::findColor(const int _colorId) + { + return findColour(_colorId); + } + + const juce::LookAndFeel& List::getStyle() const + { + return getLookAndFeel(); + } + + void List::onModelChanged() + { + updateContent(); + } + + void List::redraw() + { + repaint(); + } + + void List::ensureVisible(const int _row) + { + scrollToEnsureRowIsOnscreen(_row); + } + + int List::getSelectedEntry() const + { + return getSelectedRow(); + } + + juce::SparseSet<int> List::getSelectedEntries() const + { + return getSelectedRows(); + } + + void List::deselectAll() + { + deselectAllRows(); + } + + void List::setSelectedEntries(const juce::SparseSet<int>& _rows) + { + setSelectedRows(_rows); + } + + juce::Rectangle<int> List::getEntryPosition(int _row, const bool _relativeToComponentTopLeft) + { + return getRowPosition(_row, _relativeToComponentTopLeft); + } +} diff --git a/source/jucePluginEditorLib/patchmanager/list.h b/source/jucePluginEditorLib/patchmanager/list.h @@ -0,0 +1,25 @@ +#pragma once + +#include "listmodel.h" + +namespace jucePluginEditorLib::patchManager +{ + class List : public ListModel, public juce::ListBox + { + public: + explicit List(PatchManager& _pm); + + private: + // ListModel + juce::Colour findColor(int _colorId) override; + const juce::LookAndFeel& getStyle() const override; + void onModelChanged() override; + void redraw() override; + void ensureVisible(int _row) override; + int getSelectedEntry() const override; + juce::SparseSet<int> getSelectedEntries() const override; + void deselectAll() override; + void setSelectedEntries(const juce::SparseSet<int>&) override; + juce::Rectangle<int> getEntryPosition(int _row, bool _relativeToComponentTopLeft) override; + }; +} diff --git a/source/jucePluginEditorLib/patchmanager/listitem.cpp b/source/jucePluginEditorLib/patchmanager/listitem.cpp @@ -142,7 +142,7 @@ namespace jucePluginEditorLib::patchManager void ListItem::mouseDown(const juce::MouseEvent& event) { - m_list.mouseDown(event); +// m_list.mouseDown(event); } bool ListItem::hitTest(int x, int y) diff --git a/source/jucePluginEditorLib/patchmanager/listmodel.cpp b/source/jucePluginEditorLib/patchmanager/listmodel.cpp @@ -8,37 +8,12 @@ #include "../pluginEditor.h" -#include "../../juceUiLib/uiObject.h" #include "../../juceUiLib/uiObjectStyle.h" namespace jucePluginEditorLib::patchManager { ListModel::ListModel(PatchManager& _pm): m_patchManager(_pm) { - setColour(backgroundColourId, juce::Colour(defaultSkin::colors::background)); - setColour(textColourId, juce::Colour(defaultSkin::colors::itemText)); - - getViewport()->setScrollBarsShown(true, false); - setModel(this); - setMultipleSelectionEnabled(true); - - if (const auto& t = _pm.getTemplate("pm_listbox")) - t->apply(_pm.getEditor(), *this); - - if(const auto t = _pm.getTemplate("pm_scrollbar")) - { - t->apply(_pm.getEditor(), getVerticalScrollBar()); - t->apply(_pm.getEditor(), getHorizontalScrollBar()); - } - else - { - getVerticalScrollBar().setColour(juce::ScrollBar::thumbColourId, juce::Colour(defaultSkin::colors::scrollbar)); - getVerticalScrollBar().setColour(juce::ScrollBar::trackColourId, juce::Colour(defaultSkin::colors::scrollbar)); - getHorizontalScrollBar().setColour(juce::ScrollBar::thumbColourId, juce::Colour(defaultSkin::colors::scrollbar)); - getHorizontalScrollBar().setColour(juce::ScrollBar::trackColourId, juce::Colour(defaultSkin::colors::scrollbar)); - } - - setRowSelectedOnMouseDown(false); } void ListModel::setContent(const pluginLib::patchDB::SearchHandle& _handle) @@ -66,7 +41,7 @@ namespace jucePluginEditorLib::patchManager m_search.reset(); m_patches.clear(); m_filteredPatches.clear(); - updateContent(); + onModelChanged(); getPatchManager().setListStatus(0, 0); } @@ -90,11 +65,11 @@ namespace jucePluginEditorLib::patchManager sortPatches(); filterPatches(); - updateContent(); + onModelChanged(); setSelectedPatches(selectedPatches); - repaint(); + redraw(); getPatchManager().setListStatus(static_cast<uint32_t>(selectedPatches.size()), static_cast<uint32_t>(getPatches().size())); } @@ -155,12 +130,12 @@ namespace jucePluginEditorLib::patchManager if(selectedPatches.size() == 1) { const auto& patch = *selectedPatches.begin(); - const auto row = getSelectedRow(); - const auto pos = getRowPosition(row, true); + const auto row = getSelectedEntry(); + const auto pos = getEntryPosition(row, true); menu.addItem("Rename...", [this, patch, pos] { - beginEdit(this, pos, patch->getName(), [this, patch](bool _cond, const std::string& _name) + beginEdit(dynamic_cast<juce::Component*>(this), pos, patch->getName(), [this, patch](bool _cond, const std::string& _name) { if(_name != patch->getName()) getPatchManager().renamePatch(patch, _name); @@ -319,7 +294,7 @@ namespace jucePluginEditorLib::patchManager void ListModel::paintListBoxItem(const int _rowNumber, juce::Graphics& _g, const int _width, const int _height, const bool _rowIsSelected) { - const auto* style = dynamic_cast<genericUI::UiObjectStyle*>(&getLookAndFeel()); + const auto* style = dynamic_cast<const genericUI::UiObjectStyle*>(&getStyle()); if (_rowNumber >= getNumRows()) return; // Juce what are you up to? @@ -361,7 +336,7 @@ namespace jucePluginEditorLib::patchManager // if(c != pluginLib::patchDB::g_invalidColor) // _g.setColour(juce::Colour(c)); // else - _g.setColour(findColour(textColourId)); + _g.setColour(findColor(juce::ListBox::textColourId)); _g.drawText(text, offsetX, 0, _width - 4, _height, style ? style->getAlign() : juce::Justification::centredLeft, true); } @@ -387,7 +362,7 @@ namespace jucePluginEditorLib::patchManager return new SavePatchDesc(m_patchManager, std::move(patches)); } - juce::Component* ListModel::refreshComponentForRow(int rowNumber, bool isRowSelected, Component* existingComponentToUpdate) + juce::Component* ListModel::refreshComponentForRow(int rowNumber, bool isRowSelected, juce::Component* existingComponentToUpdate) { auto* existing = dynamic_cast<ListItem*>(existingComponentToUpdate); @@ -417,7 +392,7 @@ namespace jucePluginEditorLib::patchManager { std::set<Patch> result; - const auto selectedRows = getSelectedRows(); + const auto selectedRows = getSelectedEntries(); const auto& ranges = selectedRows.getRanges(); for (const auto& range : ranges) @@ -450,7 +425,7 @@ namespace jucePluginEditorLib::patchManager { if (_patches.empty()) { - deselectAllRows(); + deselectAll(); return false; } @@ -474,14 +449,14 @@ namespace jucePluginEditorLib::patchManager if(selection.isEmpty()) { - deselectAllRows(); + deselectAll(); return false; } m_ignoreSelectedRowsChanged = true; - setSelectedRows(selection); + setSelectedEntries(selection); m_ignoreSelectedRowsChanged = false; - scrollToEnsureRowIsOnscreen((minRow + maxRow) >> 1); + ensureVisible((minRow + maxRow) >> 1); return true; } @@ -530,11 +505,11 @@ namespace jucePluginEditorLib::patchManager m_hideDuplicatesByName = _hideDuplicatesByName; filterPatches(); - updateContent(); + onModelChanged(); setSelectedPatches(selected); - repaint(); + redraw(); getPatchManager().setListStatus(static_cast<uint32_t>(selected.size()), static_cast<uint32_t>(getPatches().size())); } diff --git a/source/jucePluginEditorLib/patchmanager/listmodel.h b/source/jucePluginEditorLib/patchmanager/listmodel.h @@ -19,7 +19,7 @@ namespace jucePluginEditorLib::patchManager { class PatchManager; - class ListModel : public juce::ListBox, juce::ListBoxModel, Editable + class ListModel : public juce::ListBoxModel, Editable { public: using Patch = pluginLib::patchDB::PatchPtr; @@ -37,7 +37,7 @@ namespace jucePluginEditorLib::patchManager int getNumRows() override; void paintListBoxItem(int _rowNumber, juce::Graphics& _g, int _width, int _height, bool _rowIsSelected) override; juce::var getDragSourceDescription(const juce::SparseSet<int>& rowsToDescribe) override; - Component* refreshComponentForRow(int rowNumber, bool isRowSelected, Component* existingComponentToUpdate) override; + juce::Component* refreshComponentForRow(int rowNumber, bool isRowSelected, juce::Component* existingComponentToUpdate) override; void selectedRowsChanged(int lastRowSelected) override; @@ -90,6 +90,18 @@ namespace jucePluginEditorLib::patchManager pluginLib::patchDB::SearchHandle getSearchHandle() const; + // to be implemented in derived class + virtual juce::Colour findColor(int _colorId) = 0; + virtual const juce::LookAndFeel& getStyle() const = 0; + virtual void onModelChanged() = 0; + virtual void redraw() = 0; + virtual void ensureVisible(int _row) = 0; + virtual int getSelectedEntry() const = 0; + virtual juce::SparseSet<int> getSelectedEntries() const = 0; + virtual void deselectAll() = 0; + virtual void setSelectedEntries(const juce::SparseSet<int>&) = 0; + virtual juce::Rectangle<int> getEntryPosition(int _row, bool _relativeToComponentTopLeft) = 0; + private: void sortPatches(); void sortPatches(Patches& _patches) const; diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.cpp b/source/jucePluginEditorLib/patchmanager/patchmanager.cpp @@ -3,6 +3,7 @@ #include "datasourcetree.h" #include "datasourcetreeitem.h" #include "info.h" +#include "list.h" #include "listmodel.h" #include "searchlist.h" #include "searchtree.h" @@ -75,7 +76,7 @@ namespace jucePluginEditorLib::patchManager // 3rd column w = weight(15); - m_list = new ListModel(*this); + m_list = new List(*this); m_list->setTopLeftPosition(m_treeTags->getRight() + g_padding, 0); m_list->setSize(w - g_padding, rootH - g_searchBarHeight - g_padding); diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.h b/source/jucePluginEditorLib/patchmanager/patchmanager.h @@ -21,6 +21,7 @@ namespace genericUI namespace jucePluginEditorLib::patchManager { + class List; class Status; class TreeItem; class SearchTree; @@ -132,7 +133,7 @@ namespace jucePluginEditorLib::patchManager Tree* m_treeDS = nullptr; Tree* m_treeTags = nullptr; - ListModel* m_list = nullptr; + List* m_list = nullptr; Info* m_info = nullptr; SearchTree* m_searchTreeDS = nullptr;