Skip to content

Commit

Permalink
Add PluginTreeModel
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jan 13, 2024
1 parent 0c8a48a commit 2b31aef
Show file tree
Hide file tree
Showing 16 changed files with 494 additions and 8 deletions.
15 changes: 14 additions & 1 deletion app/translates/zh-CN/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,17 @@ countries: cn

"Search For Plugin" = "查找插件"
"Find plugins in the list." = "在列表中查找插件。"
"Plugin List" = "插件列表"
"Plugin List" = "插件列表"
"Plugin search in progress, please wait..." = "插件搜索中,请稍候..."

"Description:" = "描述:"
"Format:" = "格式:"
"Category:" = "类别:"
"Manufacturer:" = "制造商:"
"Version:" = "版本:"
"File:" = "文件:"
"Last File Mod Time:" = "最后更新时间:"
"Last Info Update Time:" = "最后刷新时间:"
"Is Instrument:" = "乐器:"
"Input Channels:" = "输入通道:"
"Output Channels:" = "输出通道:"
32 changes: 30 additions & 2 deletions src/audioCore/plugin/AudioPluginSearchThread.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "AudioPluginSearchThread.h"
#include "../uiCallback/UICallbackType.h"
#include "../uiCallback/UICallback.h"
#include "../AudioConfig.h"

/** Plugin Searcher Path */
Expand Down Expand Up @@ -30,7 +32,7 @@ const juce::Array<juce::AudioPluginFormat*> AudioPluginSearchThread::getFormats(

std::tuple<bool, juce::KnownPluginList&> AudioPluginSearchThread::getPluginList() {
if (this->isThreadRunning()) {
return std::tuple<bool, juce::KnownPluginList&>(false, this->pluginList);
return std::tuple<bool, juce::KnownPluginList&>(this->pluginListValidFlag, this->pluginList);
}

if (!this->pluginListValidFlag) {
Expand Down Expand Up @@ -61,19 +63,29 @@ void AudioPluginSearchThread::clearList() {
if (this->isThreadRunning()) {
this->stopThread(-1);
}

UICallbackAPI<bool>::invoke(UICallbackType::PluginSearchStateChanged, true);

this->pluginList.clear();
this->pluginList.clearBlacklistedFiles();
this->pluginListValidFlag = false;

UICallbackAPI<bool>::invoke(UICallbackType::PluginSearchStateChanged, false);
}

void AudioPluginSearchThread::clearTemporary() {
if (this->isThreadRunning()) {
this->stopThread(-1);
}

UICallbackAPI<bool>::invoke(UICallbackType::PluginSearchStateChanged, true);

this->pluginList.clear();
this->pluginList.clearBlacklistedFiles();
this->clearTemporaryInternal();
this->pluginListValidFlag = false;

UICallbackAPI<bool>::invoke(UICallbackType::PluginSearchStateChanged, false);
}

const juce::StringArray AudioPluginSearchThread::getBlackList() const {
Expand Down Expand Up @@ -137,6 +149,10 @@ void AudioPluginSearchThread::removeFromSearchPath(const juce::String& path) con
}

void AudioPluginSearchThread::run() {
/** Search Start */
juce::MessageManager::callAsync(
[] { UICallbackAPI<bool>::invoke(UICallbackType::PluginSearchStateChanged, true); });

/** Get Temporary File */
juce::String temporaryFilePath = AudioConfig::getPluginListTemporaryFilePath();
juce::File temporaryFile =
Expand Down Expand Up @@ -171,6 +187,10 @@ void AudioPluginSearchThread::run() {
/** Check If Thread Terminate */
if (this->threadShouldExit()) {
process.kill();

/** Search End */
juce::MessageManager::callAsync(
[] { UICallbackAPI<bool>::invoke(UICallbackType::PluginSearchStateChanged, false); });
return;
}

Expand All @@ -186,15 +206,23 @@ void AudioPluginSearchThread::run() {
/** Create Plugin List From Xml Data */
this->pluginList.recreateFromXml(*xmlElement);

/** Set List Valid Flag And Return */
/** Set List Valid Flag */
this->pluginListValidFlag = true;

/** Search End */
juce::MessageManager::callAsync(
[] { UICallbackAPI<bool>::invoke(UICallbackType::PluginSearchStateChanged, false); });
return;
}
else {
/** The Xml File Is Invalid, Remove It */
temporaryFile.deleteFile();
}
}

/** Search End */
juce::MessageManager::callAsync(
[] { UICallbackAPI<bool>::invoke(UICallbackType::PluginSearchStateChanged, false); });
}

void AudioPluginSearchThread::clearTemporaryInternal() const {
Expand Down
5 changes: 5 additions & 0 deletions src/audioCore/quickAPI/QuickGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,9 @@ namespace quickAPI {
const juce::StringArray getAllSIMDInsName() {
return vMath::getAllInsTypeName();
}

const std::tuple<bool, juce::Array<juce::PluginDescription>> getPluginList() {
auto [result, list] = Plugin::getInstance()->getPluginList();
return { result, list.getTypes() };
}
}
2 changes: 2 additions & 0 deletions src/audioCore/quickAPI/QuickGet.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ namespace quickAPI {
int getSIMDLevel();
const juce::String getSIMDInsName();
const juce::StringArray getAllSIMDInsName();

const std::tuple<bool, juce::Array<juce::PluginDescription>> getPluginList();
}
1 change: 1 addition & 0 deletions src/audioCore/uiCallback/UICallbackType.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum class UICallbackType : int {
PlayStateChanged,
RecordStateChanged,
ErrorMessage,
PluginSearchStateChanged,

TypeMaxNum
};
16 changes: 16 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ class MainApplication : public juce::JUCEApplication {
);
};

void loadAudioPlugins() {
InitTaskList::getInstance()->add(
[splash = Splash::SafePointer<Splash>(this->splash.get())] {
if (splash) { splash->showMessage("Load Audio Plugins..."); }
}
);
InitTaskList::getInstance()->add(
[] {
[[maybe_unused]] auto result = quickAPI::getPluginList();
}
);
};

void loadTheme() {
InitTaskList::getInstance()->add(
[splash = Splash::SafePointer<Splash>(this->splash.get())] {
Expand Down Expand Up @@ -483,6 +496,9 @@ class MainApplication : public juce::JUCEApplication {

/** Set Audio Config */
this->setAudioConfig();

/** Load Plugin List */
this->loadAudioPlugins();

/** Load Theme Colors */
this->loadTheme();
Expand Down
106 changes: 105 additions & 1 deletion src/ui/component/PluginView.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "PluginView.h"
#include "../lookAndFeel/LookAndFeelFactory.h"
#include "../misc/CoreCallbacks.h"
#include "../Utils.h"
#include "../../audioCore/AC_API.h"
#include <IconManager.h>

PluginView::PluginView()
Expand Down Expand Up @@ -30,9 +32,29 @@ PluginView::PluginView()

/** Plugin Tree */
this->pluginTree = std::make_unique<juce::TreeView>(TRANS("Plugin List"));
this->pluginTree->setDefaultOpenness(true);
this->pluginTree->setOpenCloseButtonsVisible(true);
this->pluginTree->setRootItemVisible(false);
this->addAndMakeVisible(this->pluginTree.get());

/** Searching Message */
this->searchingMes = TRANS("Plugin search in progress, please wait...");

/** Add Callback */
CoreCallbacks::getInstance()->addSearchPlugin(
[comp = PluginView::SafePointer(this)](bool status) {
if (comp) {
if (status) { comp->searchStart(); }
else { comp->searchEnd(); }
}
}
);

/** Update Plugin List */
this->update();
}

PluginView::~PluginView() {
this->pluginTree->setRootItem(nullptr);
}

void PluginView::resized() {
Expand All @@ -56,11 +78,20 @@ void PluginView::paint(juce::Graphics& g) {
int searchHeight = screenSize.getHeight() * 0.03;
float searchIconHeight = searchHeight * 0.6f;

int paddingWidth = screenSize.getWidth() * 0.01;
int paddingHeight = screenSize.getHeight() * 0.02;
float textHeight = screenSize.getHeight() * 0.02f;

/** Color */
juce::Colour backgroundColor = laf.findColour(
juce::ResizableWindow::ColourIds::backgroundColourId);
juce::Colour searchBackgroundColor = laf.findColour(
juce::TextEditor::ColourIds::backgroundColourId);
juce::Colour textColor = laf.findColour(
juce::Label::ColourIds::textColourId);

/** Font */
juce::Font textFont(textHeight);

/** BackGround */
g.setColour(backgroundColor);
Expand All @@ -79,4 +110,77 @@ void PluginView::paint(juce::Graphics& g) {
searchIconHeight, searchIconHeight);
this->searchIcon->drawWithin(g, searchIconRect,
juce::RectanglePlacement::centred | juce::RectanglePlacement::fillDestination, 1.f);

/** Searching Text */
if (!this->pluginTree->isVisible()) {
juce::Rectangle<int> textRect(
paddingWidth, searchRect.getBottom() + paddingHeight,
this->getWidth() - paddingWidth * 2, textHeight);
g.setFont(textFont);
g.setColour(textColor);
g.drawFittedText(this->searchingMes, textRect,
juce::Justification::centred, 1, 1.f);
}
}

void PluginView::update() {
/** Clear Plugin Tree */
this->pluginTree->setRootItem(nullptr);
this->pluginModel = nullptr;

/** Get Plugin List */
auto [valid, list] = quickAPI::getPluginList();
if (valid) {
/** Plugin Groups */
std::map<juce::String, juce::Array<juce::PluginDescription>> groupMap;

/** Group Plugin */
for (auto& i : list) {
/** Group Index */
juce::String index;
switch (this->groupType) {
case GroupType::Format:
index = i.pluginFormatName;
break;
case GroupType::Manufacturer:
index = i.manufacturerName;
break;
case GroupType::Category:
index = i.category;
break;
}

/** Insert To Group List */
auto& groupList = groupMap[index];
groupList.add(i);
}

/** Plugin Group List */
juce::Array<PluginTreeModel::PluginClass> groupList;
for (auto& i : groupMap) {
groupList.add({ i.first, i.second });
}

/** Create Plugin Tree Model */
this->pluginModel = std::make_unique<PluginTreeModel>(groupList);
this->pluginTree->setRootItem(this->pluginModel.get());
this->pluginTree->setDefaultOpenness(false);
}
}

void PluginView::searchStart() {
/** Hide Plugin Tree */
this->pluginTree->setVisible(false);

/** Clear Plugin Tree */
this->pluginTree->setRootItem(nullptr);
this->pluginModel = nullptr;
}

void PluginView::searchEnd() {
/** Update Plugin Tree */
this->update();

/** Show Plugin Tree */
this->pluginTree->setVisible(true);
}
15 changes: 15 additions & 0 deletions src/ui/component/PluginView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@

#include <JuceHeader.h>
#include <FlowUI.h>
#include "../dataModel/PluginTreeModel.h"

class PluginView final
: public flowUI::FlowComponent,
public juce::DragAndDropContainer {
public:
PluginView();
~PluginView();

void resized() override;
void paint(juce::Graphics& g) override;

void update();

private:
std::unique_ptr<juce::Drawable> searchIcon = nullptr;
std::unique_ptr<juce::TextEditor> searchBox = nullptr;
std::unique_ptr<juce::TreeView> pluginTree = nullptr;
std::unique_ptr<PluginTreeModel> pluginModel = nullptr;

juce::String searchingMes;

enum class GroupType {
Format, Manufacturer, Category
};
GroupType groupType = GroupType::Manufacturer;

void searchStart();
void searchEnd();

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginView)
};
Loading

0 comments on commit 2b31aef

Please sign in to comment.