kopia lustrzana https://github.com/jameshball/osci-render
Add lua console clearing, pausing
rodzic
446c065d93
commit
d38fcaced5
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3M19 19H5V5H19V19M13 16V8H15V16H13M9 16V8H11V16H9" /></svg>
|
Po Szerokość: | Wysokość: | Rozmiar: 218 B |
|
@ -21,11 +21,10 @@ OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioPr
|
|||
#endif
|
||||
|
||||
addAndMakeVisible(console);
|
||||
console.setConsoleOpen(false);
|
||||
|
||||
LuaParser::onPrint = [this](const juce::String& message) {
|
||||
juce::MessageManager::callAsync([this, message] {
|
||||
console.print(message);
|
||||
});
|
||||
LuaParser::onPrint = [this](const std::string& message) {
|
||||
console.print(message);
|
||||
};
|
||||
|
||||
if (!usingNativeMenuBar) {
|
||||
|
@ -151,6 +150,10 @@ void OscirenderAudioProcessorEditor::paint(juce::Graphics& g) {
|
|||
if (lua.getBounds().getWidth() > 0 && lua.getBounds().getHeight() > 0) {
|
||||
ds.drawForRectangle(g, lua.getBounds());
|
||||
}
|
||||
|
||||
if (console.getBounds().getWidth() > 0 && console.getBounds().getHeight() > 0) {
|
||||
ds.drawForRectangle(g, console.getBounds());
|
||||
}
|
||||
}
|
||||
|
||||
void OscirenderAudioProcessorEditor::resized() {
|
||||
|
@ -208,8 +211,8 @@ void OscirenderAudioProcessorEditor::resized() {
|
|||
juce::Component* rows[] = { &dummy3, &luaResizerBar, &lua };
|
||||
luaLayout.layOutComponents(rows, 3, dummy2Bounds.getX(), dummy2Bounds.getY(), dummy2Bounds.getWidth(), dummy2Bounds.getHeight(), true, true);
|
||||
auto dummy3Bounds = dummy3.getBounds();
|
||||
console.setBounds(dummy3Bounds.removeFromBottom(200));
|
||||
dummy3Bounds.removeFromBottom(5);
|
||||
console.setBounds(dummy3Bounds.removeFromBottom(console.getConsoleOpen() ? 200 : 30));
|
||||
dummy3Bounds.removeFromBottom(RESIZER_BAR_SIZE);
|
||||
codeEditors[index]->setBounds(dummy3Bounds);
|
||||
} else {
|
||||
codeEditors[index]->setBounds(dummy2Bounds);
|
||||
|
@ -452,6 +455,21 @@ bool OscirenderAudioProcessorEditor::keyPressed(const juce::KeyPress& key) {
|
|||
return consumeKey;
|
||||
}
|
||||
|
||||
void OscirenderAudioProcessorEditor::mouseDown(const juce::MouseEvent& e) {
|
||||
if (console.getBoundsInParent().removeFromTop(30).contains(e.getPosition())) {
|
||||
console.setConsoleOpen(!console.getConsoleOpen());
|
||||
resized();
|
||||
}
|
||||
}
|
||||
|
||||
void OscirenderAudioProcessorEditor::mouseMove(const juce::MouseEvent& event) {
|
||||
if (console.getBoundsInParent().removeFromTop(30).contains(event.getPosition())) {
|
||||
setMouseCursor(juce::MouseCursor::PointingHandCursor);
|
||||
} else {
|
||||
setMouseCursor(juce::MouseCursor::NormalCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void OscirenderAudioProcessorEditor::newProject() {
|
||||
// TODO: open a default project
|
||||
}
|
||||
|
|
|
@ -91,6 +91,8 @@ public:
|
|||
void updateCodeEditor();
|
||||
|
||||
bool keyPressed(const juce::KeyPress& key) override;
|
||||
void mouseDown(const juce::MouseEvent& event) override;
|
||||
void mouseMove(const juce::MouseEvent& event) override;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OscirenderAudioProcessorEditor)
|
||||
};
|
||||
|
|
|
@ -4,41 +4,84 @@
|
|||
LuaConsole::LuaConsole() {
|
||||
setText("Lua Console");
|
||||
|
||||
console.setMultiLine(true);
|
||||
console.setReadOnly(true);
|
||||
console.setCaretVisible(false);
|
||||
|
||||
console.setColour(juce::TextEditor::backgroundColourId, juce::Colours::black);
|
||||
console.setColour(juce::TextEditor::textColourId, juce::Colours::white);
|
||||
console.setColour(juce::TextEditor::outlineColourId, juce::Colours::white);
|
||||
console.setColour(juce::TextEditor::focusedOutlineColourId, juce::Colours::white);
|
||||
console.setColour(juce::TextEditor::highlightColourId, juce::Colours::white);
|
||||
console.setColour(juce::TextEditor::highlightedTextColourId, juce::Colours::black);
|
||||
console.setColour(juce::TextEditor::shadowColourId, juce::Colours::black);
|
||||
console.setLineNumbersShown(false);
|
||||
console.setScrollbarThickness(0);
|
||||
document.getUndoManager().setMaxNumberOfStoredUnits(0, 0);
|
||||
|
||||
startTimerHz(10);
|
||||
|
||||
clearConsoleButton.onClick = [this] {
|
||||
clear();
|
||||
};
|
||||
|
||||
addAndMakeVisible(console);
|
||||
addAndMakeVisible(clearConsoleButton);
|
||||
addAndMakeVisible(pauseConsoleButton);
|
||||
|
||||
pauseConsoleButton.onClick = [this] {
|
||||
console.setScrollbarThickness(pauseConsoleButton.getToggleState() ? 10 : 0);
|
||||
};
|
||||
}
|
||||
|
||||
LuaConsole::~LuaConsole() {}
|
||||
|
||||
void LuaConsole::print(const juce::String& text) {
|
||||
console.moveCaretToEnd();
|
||||
console.insertTextAtCaret(text);
|
||||
void LuaConsole::print(const std::string& text) {
|
||||
juce::SpinLock::ScopedLockType l(lock);
|
||||
|
||||
// clear start of console if it gets too long
|
||||
if (console.getTotalNumChars() > 10000) {
|
||||
console.setHighlightedRegion(juce::Range<int>(0, 1000));
|
||||
console.deleteBackwards(true);
|
||||
console.moveCaretToEnd();
|
||||
if (consoleOpen && !pauseConsoleButton.getToggleState()) {
|
||||
buffer += text + "\n";
|
||||
consoleLines++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LuaConsole::clear() {
|
||||
console.clear();
|
||||
juce::SpinLock::ScopedLockType l(lock);
|
||||
|
||||
document.replaceAllContent("");
|
||||
document.clearUndoHistory();
|
||||
consoleLines = 0;
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
void LuaConsole::timerCallback() {
|
||||
juce::SpinLock::ScopedLockType l(lock);
|
||||
|
||||
if (consoleOpen && !pauseConsoleButton.getToggleState()) {
|
||||
document.insertText(juce::CodeDocument::Position(document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), buffer);
|
||||
buffer.clear();
|
||||
|
||||
// clear console if it gets too long
|
||||
if (consoleLines > 100000) {
|
||||
// soft-clear console
|
||||
int linesToClear = consoleLines * 0.9;
|
||||
document.deleteSection(juce::CodeDocument::Position(document, 0, 0), juce::CodeDocument::Position(document, linesToClear, 0));
|
||||
consoleLines -= linesToClear;
|
||||
}
|
||||
|
||||
console.moveCaretToTop(false);
|
||||
console.moveCaretToEnd(false);
|
||||
console.scrollDown();
|
||||
}
|
||||
}
|
||||
|
||||
void LuaConsole::setConsoleOpen(bool open) {
|
||||
juce::SpinLock::ScopedLockType l(lock);
|
||||
|
||||
consoleOpen = open;
|
||||
console.setVisible(open);
|
||||
if (open) {
|
||||
startTimerHz(10);
|
||||
} else {
|
||||
stopTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void LuaConsole::resized() {
|
||||
auto area = getLocalBounds().withTrimmedTop(20);
|
||||
auto topBar = getLocalBounds().removeFromTop(30);
|
||||
auto area = getLocalBounds().withTrimmedTop(30);
|
||||
console.setBounds(area);
|
||||
|
||||
clearConsoleButton.setBounds(topBar.removeFromRight(30).withSizeKeepingCentre(20, 20));
|
||||
pauseConsoleButton.setBounds(topBar.removeFromRight(30).withSizeKeepingCentre(20, 20));
|
||||
}
|
||||
|
|
|
@ -2,19 +2,32 @@
|
|||
|
||||
#include <JuceHeader.h>
|
||||
#include "../PluginProcessor.h"
|
||||
#include "SvgButton.h"
|
||||
#include "../LookAndFeel.h"
|
||||
|
||||
class LuaConsole : public juce::GroupComponent {
|
||||
class LuaConsole : public juce::GroupComponent, public juce::Timer {
|
||||
public:
|
||||
LuaConsole();
|
||||
~LuaConsole();
|
||||
|
||||
void print(const juce::String& text);
|
||||
void print(const std::string& text);
|
||||
void clear();
|
||||
void timerCallback() override;
|
||||
void setConsoleOpen(bool open);
|
||||
bool getConsoleOpen() { return consoleOpen; }
|
||||
|
||||
void resized() override;
|
||||
private:
|
||||
|
||||
juce::TextEditor console;
|
||||
bool consoleOpen = false;
|
||||
juce::SpinLock lock;
|
||||
std::string buffer;
|
||||
juce::CodeDocument document;
|
||||
juce::CodeEditorComponent console = { document, nullptr };
|
||||
int consoleLines = 0;
|
||||
|
||||
SvgButton clearConsoleButton { "clearConsole", juce::String(BinaryData::delete_svg), juce::Colours::red };
|
||||
SvgButton pauseConsoleButton { "pauseConsole", juce::String(BinaryData::pause_svg), juce::Colours::white, Colours::accentColor };
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LuaConsole)
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "LuaParser.h"
|
||||
#include "luaimport.h"
|
||||
|
||||
std::function<void(const juce::String&)> LuaParser::onPrint;
|
||||
std::function<void(const std::string&)> LuaParser::onPrint;
|
||||
|
||||
static int customPrint(lua_State* L) {
|
||||
int nargs = lua_gettop(L);
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
void resetErrors();
|
||||
void close(lua_State*& L);
|
||||
|
||||
static std::function<void(const juce::String&)> onPrint;
|
||||
static std::function<void(const std::string&)> onPrint;
|
||||
|
||||
private:
|
||||
void reset(lua_State*& L, juce::String script);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<FILE id="n1esUp" name="left_arrow.svg" compile="0" resource="1" file="Resources/svg/left_arrow.svg"/>
|
||||
<FILE id="PxYKbt" name="microphone.svg" compile="0" resource="1" file="Resources/svg/microphone.svg"/>
|
||||
<FILE id="pSc1mq" name="osci.svg" compile="0" resource="1" file="Resources/svg/osci.svg"/>
|
||||
<FILE id="f2D5tv" name="pause.svg" compile="0" resource="1" file="Resources/svg/pause.svg"/>
|
||||
<FILE id="D2AI1b" name="pencil.svg" compile="0" resource="1" file="Resources/svg/pencil.svg"/>
|
||||
<FILE id="PFc2q2" name="random.svg" compile="0" resource="1" file="Resources/svg/random.svg"/>
|
||||
<FILE id="n79IAy" name="record.svg" compile="0" resource="1" file="Resources/svg/record.svg"/>
|
||||
|
|
Ładowanie…
Reference in New Issue