Skip to content

Commit

Permalink
Add PluginEditorHub
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jan 24, 2024
1 parent 11518a8 commit 1738b5f
Show file tree
Hide file tree
Showing 15 changed files with 351 additions and 92 deletions.
29 changes: 0 additions & 29 deletions src/audioCore/action/ActionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,35 +1103,6 @@ bool ActionSetEffectWindow::doAction() {
return false;
}

ActionSetInstrWindow::ActionSetInstrWindow(
int instr, bool visible)
: instr(instr), visible(visible) {}

bool ActionSetInstrWindow::doAction() {
if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto plugin = graph->getInstrumentProcessor(this->instr)) {
if (auto editor = plugin->createEditorIfNeeded()) {
if (this->visible) {
editor->setName(plugin->getName());
editor->addToDesktop(
juce::ComponentPeer::windowAppearsOnTaskbar |
juce::ComponentPeer::windowHasTitleBar |
juce::ComponentPeer::windowHasDropShadow);
}
editor->setVisible(this->visible);

if (this->visible) {
editor->centreWithSize(editor->getWidth(), editor->getHeight());
}

this->output("Plugin Window: [" + juce::String(this->instr) + "] " + juce::String(this->visible ? "ON" : "OFF") + "\n");
return true;
}
}
}
return false;
}

ActionSetPlayPosition::ActionSetPlayPosition(double pos)
: pos(pos) {}

Expand Down
18 changes: 0 additions & 18 deletions src/audioCore/action/ActionSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,24 +268,6 @@ class ActionSetEffectBypassByPtr final : public ActionUndoableBase {
JUCE_LEAK_DETECTOR(ActionSetEffectBypassByPtr)
};

class ActionSetInstrWindow final : public ActionBase {
public:
ActionSetInstrWindow() = delete;
ActionSetInstrWindow(
int instr, bool visible);

bool doAction() override;
const juce::String getName() override {
return "Set Instr Window";
};

private:
const int instr;
const bool visible;

JUCE_LEAK_DETECTOR(ActionSetInstrWindow)
};

class ActionSetInstrBypass final : public ActionUndoableBase {
public:
ActionSetInstrBypass() = delete;
Expand Down
8 changes: 0 additions & 8 deletions src/audioCore/command/CommandSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ AUDIOCORE_FUNC(setEffectBypass) {
return CommandFuncResult{ true, "" };
}

AUDIOCORE_FUNC(setInstrWindow) {
auto action = std::unique_ptr<ActionBase>(new ActionSetInstrWindow{
(int)luaL_checkinteger(L, 1), (bool)lua_toboolean(L, 2) });
ActionDispatcher::getInstance()->dispatch(std::move(action));
return CommandFuncResult{ true, "" };
}

AUDIOCORE_FUNC(setInstrBypass) {
auto action = std::unique_ptr<ActionBase>(new ActionSetInstrBypass{
(int)luaL_checkinteger(L, 1), (bool)lua_toboolean(L, 2) });
Expand Down Expand Up @@ -247,7 +240,6 @@ void regCommandSet(lua_State* L) {
LUA_ADD_AUDIOCORE_FUNC_DEFAULT_NAME(L, setMixerTrackSlider);
LUA_ADD_AUDIOCORE_FUNC_DEFAULT_NAME(L, setEffectWindow);
LUA_ADD_AUDIOCORE_FUNC_DEFAULT_NAME(L, setEffectBypass);
LUA_ADD_AUDIOCORE_FUNC_DEFAULT_NAME(L, setInstrWindow);
LUA_ADD_AUDIOCORE_FUNC_DEFAULT_NAME(L, setInstrBypass);
LUA_ADD_AUDIOCORE_FUNC_DEFAULT_NAME(L, setInstrMIDIChannel);
LUA_ADD_AUDIOCORE_FUNC_DEFAULT_NAME(L, setEffectMIDIChannel);
Expand Down
16 changes: 16 additions & 0 deletions src/audioCore/quickAPI/QuickGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ namespace quickAPI {
return false;
}

EditorPointer getInstrEditor(int index) {
if (auto graph = AudioCore::getInstance()->getGraph()) {
if (auto instr = graph->getInstrumentProcessor(index)) {
return instr->createEditorIfNeeded();
}
}
return nullptr;
}

const juce::String getInstrName(PluginHolder pointer) {
if (pointer) {
return pointer->getName();
Expand All @@ -389,6 +398,13 @@ namespace quickAPI {
return MainGraph::getInstrumentBypass(pointer);
}

EditorPointer getInstrEditor(PluginHolder pointer) {
if (pointer) {
return pointer->createEditorIfNeeded();
}
return nullptr;
}

const juce::String getEffectName(PluginHolder pointer) {
if (pointer) {
return pointer->getName();
Expand Down
3 changes: 3 additions & 0 deletions src/audioCore/quickAPI/QuickGet.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ namespace quickAPI {
const juce::Array<TrackType> getAllTrackTypeWithName();

using PluginHolder = PluginDecorator::SafePointer;
using EditorPointer = juce::Component::SafePointer<juce::AudioProcessorEditor>;

int getInstrNum();
PluginHolder getInstrPointer(int index);
const juce::String getInstrName(int index);
bool getInstrBypass(int index);
EditorPointer getInstrEditor(int index);
const juce::String getInstrName(PluginHolder pointer);
bool getInstrBypass(PluginHolder pointer);
EditorPointer getInstrEditor(PluginHolder pointer);

const juce::String getEffectName(PluginHolder pointer);
bool getEffectBypass(PluginHolder pointer);
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ui/misc/ConfigManager.h"
#include "ui/misc/SysStatus.h"
#include "ui/misc/CoreCallbacks.h"
#include "ui/misc/PluginEditorHub.h"
#include "ui/debug/AudioDebuggerComponent.h"
#include "ui/debug/MidiDebuggerComponent.h"
#include "ui/lookAndFeel/LookAndFeelFactory.h"
Expand Down Expand Up @@ -578,6 +579,7 @@ class MainApplication : public juce::JUCEApplication {
flowUI::FlowWindowHub::shutdown();

/** Release Components */
PluginEditorHub::releaseInstance();
CompManager::releaseInstance();
LookAndFeelFactory::releaseInstance();

Expand Down
27 changes: 23 additions & 4 deletions src/ui/component/InstrComponent.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "InstrComponent.h"
#include "../lookAndFeel/LookAndFeelFactory.h"
#include "../misc/CoreActions.h"
#include "../misc/PluginEditorHub.h"
#include "../Utils.h"
#include "../../audioCore/AC_API.h"
#include <IconManager.h>
Expand Down Expand Up @@ -63,10 +64,12 @@ void InstrComponent::paint(juce::Graphics& g) {

/** Color */
auto& laf = this->getLookAndFeel();
juce::Colour backgroundColor = laf.findColour(
juce::Label::ColourIds::backgroundColourId);
juce::Colour textColor = laf.findColour(
juce::Label::ColourIds::textColourId);
juce::Colour backgroundColor = laf.findColour(this->editorOpened
? juce::Label::ColourIds::backgroundWhenEditingColourId
: juce::Label::ColourIds::backgroundColourId);
juce::Colour textColor = laf.findColour(this->editorOpened
? juce::Label::ColourIds::textWhenEditingColourId
: juce::Label::ColourIds::textColourId);

/** Font */
juce::Font textFont(textHeight);
Expand All @@ -90,6 +93,7 @@ void InstrComponent::update(int index) {
if (index >= 0 && index < quickAPI::getInstrNum()) {
this->index = index;
this->name = quickAPI::getInstrName(index);
this->editorOpened = PluginEditorHub::getInstance()->checkInstr(index);

this->bypassButton->setToggleState(!quickAPI::getInstrBypass(index),
juce::NotificationType::dontSendNotification);
Expand All @@ -100,11 +104,26 @@ void InstrComponent::update(int index) {
}
}

void InstrComponent::mouseUp(const juce::MouseEvent& event) {
if (event.mods.isLeftButtonDown()) {
this->editorShow();
}
}

void InstrComponent::bypass() {
CoreActions::bypassInstr(this->index,
this->bypassButton->getToggleState());
}

void InstrComponent::editorShow() {
if (this->editorOpened) {
PluginEditorHub::getInstance()->closeInstr(this->index);
}
else {
PluginEditorHub::getInstance()->openInstr(this->index);
}
}

juce::String InstrComponent::createToolTip() const {
juce::String result =
"#" + juce::String{ this->index } + "\n"
Expand Down
4 changes: 4 additions & 0 deletions src/ui/component/InstrComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ class InstrComponent final

void update(int index);

void mouseUp(const juce::MouseEvent& event) override;

private:
int index = -1;
juce::String name;
bool editorOpened = false;

std::unique_ptr<juce::Drawable> bypassIcon = nullptr;
std::unique_ptr<juce::Drawable> bypassIconOn = nullptr;
std::unique_ptr<juce::DrawableButton> bypassButton = nullptr;

void bypass();
void editorShow();

juce::String createToolTip() const;

Expand Down
Loading

0 comments on commit 1738b5f

Please sign in to comment.