Fix bugs with old versions of blender and with text parser

pull/279/head
James H Ball 2025-01-26 16:28:35 +00:00
rodzic 57941c6517
commit f7bcba7d34
7 zmienionych plików z 32 dodań i 26 usunięć

Wyświetl plik

@ -316,7 +316,6 @@ void OscirenderAudioProcessor::openFile(int index) {
if (index < 0 || index >= fileBlocks.size()) { if (index < 0 || index >= fileBlocks.size()) {
return; return;
} }
juce::SpinLock::ScopedLockType lock(fontLock);
parsers[index]->parse(juce::String(fileIds[index]), fileNames[index].fromLastOccurrenceOf(".", true, false), std::make_unique<juce::MemoryInputStream>(*fileBlocks[index], false), font); parsers[index]->parse(juce::String(fileIds[index]), fileNames[index].fromLastOccurrenceOf(".", true, false), std::make_unique<juce::MemoryInputStream>(*fileBlocks[index], false), font);
changeCurrentFile(index); changeCurrentFile(index);
} }
@ -744,7 +743,6 @@ void OscirenderAudioProcessor::setStateInformation(const void* data, int sizeInB
auto family = fontXml->getStringAttribute("family"); auto family = fontXml->getStringAttribute("family");
auto bold = fontXml->getBoolAttribute("bold"); auto bold = fontXml->getBoolAttribute("bold");
auto italic = fontXml->getBoolAttribute("italic"); auto italic = fontXml->getBoolAttribute("italic");
juce::SpinLock::ScopedLockType lock(fontLock);
font = juce::Font(family, 1.0, (bold ? juce::Font::bold : 0) | (italic ? juce::Font::italic : 0)); font = juce::Font(family, 1.0, (bold ? juce::Font::bold : 0) | (italic ? juce::Font::italic : 0));
} }

Wyświetl plik

@ -180,7 +180,6 @@ public:
PitchDetector pitchDetector{*this}; PitchDetector pitchDetector{*this};
std::shared_ptr<WobbleEffect> wobbleEffect = std::make_shared<WobbleEffect>(pitchDetector); std::shared_ptr<WobbleEffect> wobbleEffect = std::make_shared<WobbleEffect>(pitchDetector);
juce::SpinLock fontLock;
juce::Font font = juce::Font(juce::Font::getDefaultSansSerifFontName(), 1.0f, juce::Font::plain); juce::Font font = juce::Font(juce::Font::getDefaultSansSerifFontName(), 1.0f, juce::Font::plain);
ShapeSound::Ptr objectServerSound = new ShapeSound(); ShapeSound::Ptr objectServerSound = new ShapeSound();

Wyświetl plik

@ -17,15 +17,7 @@ TxtComponent::TxtComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessor
auto updateFont = [this]() { auto updateFont = [this]() {
juce::SpinLock::ScopedLockType lock1(audioProcessor.parsersLock); juce::SpinLock::ScopedLockType lock1(audioProcessor.parsersLock);
juce::SpinLock::ScopedLockType lock2(audioProcessor.effectsLock); juce::SpinLock::ScopedLockType lock2(audioProcessor.effectsLock);
{ audioProcessor.font = juce::Font(installedFonts[font.getSelectedItemIndex()], 1.0, (bold.getToggleState() ? juce::Font::bold : 0) | (italic.getToggleState() ? juce::Font::italic : 0));
juce::SpinLock::ScopedLockType lock3(audioProcessor.fontLock);
audioProcessor.font.setTypefaceName(installedFonts[font.getSelectedItemIndex()]);
audioProcessor.font.setBold(bold.getToggleState());
audioProcessor.font.setItalic(italic.getToggleState());
}
if (audioProcessor.currentFileId > 0 && audioProcessor.parsers[audioProcessor.currentFileId - 1]->getText() != nullptr) {
audioProcessor.openFile(audioProcessor.currentFile);
}
}; };
font.onChange = updateFont; font.onChange = updateFont;
@ -42,7 +34,6 @@ void TxtComponent::resized() {
} }
void TxtComponent::update() { void TxtComponent::update() {
juce::SpinLock::ScopedLockType lock(audioProcessor.fontLock);
juce::String defaultFont = audioProcessor.font.getTypefaceName(); juce::String defaultFont = audioProcessor.font.getTypefaceName();
int index = installedFonts.indexOf(defaultFont); int index = installedFonts.indexOf(defaultFont);
if (index == -1) { if (index == -1) {

Wyświetl plik

@ -26,7 +26,7 @@ void FileParser::parse(juce::String fileId, juce::String extension, std::unique_
} else if (extension == ".svg") { } else if (extension == ".svg") {
svg = std::make_shared<SvgParser>(stream->readEntireStreamAsString()); svg = std::make_shared<SvgParser>(stream->readEntireStreamAsString());
} else if (extension == ".txt") { } else if (extension == ".txt") {
text = std::make_shared<TextParser>(stream->readEntireStreamAsString(), font); text = std::make_shared<TextParser>(audioProcessor, stream->readEntireStreamAsString(), font);
} else if (extension == ".lua") { } else if (extension == ".lua") {
lua = std::make_shared<LuaParser>(fileId, stream->readEntireStreamAsString(), errorCallback, fallbackLuaScript); lua = std::make_shared<LuaParser>(fileId, stream->readEntireStreamAsString(), errorCallback, fallbackLuaScript);
} else if (extension == ".gpla") { } else if (extension == ".gpla") {

Wyświetl plik

@ -1,20 +1,32 @@
#include "TextParser.h" #include "TextParser.h"
#include "../svg/SvgParser.h" #include "../svg/SvgParser.h"
#include "../PluginProcessor.h"
TextParser::TextParser(juce::String text, juce::Font font) { TextParser::TextParser(OscirenderAudioProcessor &p, juce::String text, juce::Font font) : audioProcessor(p), text(text) {
juce::Path textPath; parse(text, font);
juce::GlyphArrangement glyphs;
glyphs.addFittedText(font, text, -2, -2, 4, 4, juce::Justification::centred, 2);
glyphs.createPath(textPath);
SvgParser::pathToShapes(textPath, shapes);
} }
TextParser::~TextParser() { TextParser::~TextParser() {
} }
void TextParser::parse(juce::String text, juce::Font font) {
lastFont = font;
juce::Path textPath;
juce::GlyphArrangement glyphs;
glyphs.addFittedText(font, text, -2, -2, 4, 4, juce::Justification::centred, 2);
glyphs.createPath(textPath);
shapes = std::vector<std::unique_ptr<Shape>>();
SvgParser::pathToShapes(textPath, shapes);
}
std::vector<std::unique_ptr<Shape>> TextParser::draw() { std::vector<std::unique_ptr<Shape>> TextParser::draw() {
// reparse text if font changes
if (audioProcessor.font != lastFont) {
parse(text, audioProcessor.font);
}
// clone with deep copy // clone with deep copy
std::vector<std::unique_ptr<Shape>> tempShapes; std::vector<std::unique_ptr<Shape>> tempShapes;

Wyświetl plik

@ -3,12 +3,18 @@
#include <JuceHeader.h> #include <JuceHeader.h>
#include "../shape/Shape.h" #include "../shape/Shape.h"
class OscirenderAudioProcessor;
class TextParser { class TextParser {
public: public:
TextParser(juce::String text, juce::Font font); TextParser(OscirenderAudioProcessor &p, juce::String text, juce::Font font);
~TextParser(); ~TextParser();
std::vector<std::unique_ptr<Shape>> draw(); std::vector<std::unique_ptr<Shape>> draw();
private: private:
void parse(juce::String text, juce::Font font);
OscirenderAudioProcessor &audioProcessor;
std::vector<std::unique_ptr<Shape>> shapes; std::vector<std::unique_ptr<Shape>> shapes;
juce::Font lastFont;
juce::String text;
}; };

Wyświetl plik

@ -242,23 +242,23 @@ def get_frame_info_binary():
frame_info.extend(("DONE ").encode("utf8")) frame_info.extend(("DONE ").encode("utf8"))
else: else:
for object in bpy.data.objects: for object in bpy.data.objects:
if object.visible_get() and obj.type == 'GPENCIL': if object.visible_get() and object.type == 'GPENCIL':
dg = bpy.context.evaluated_depsgraph_get() dg = bpy.context.evaluated_depsgraph_get()
obj = object.evaluated_get(dg) obj = object.evaluated_get(dg)
frame_info.extend(("OBJECT ").encode("utf8")) frame_info.extend(("OBJECT ").encode("utf8"))
# matrix # matrix
frame_info.extend(("MATRIX ").encode("utf8")) frame_info.extend(("MATRIX ").encode("utf8"))
camera_space = bpy.context.scene.camera.matrix_world.inverted() @ obj.matrix_world camera_space = bpy.context.scene.camera.matrix_world.inverted() @ object.matrix_world
for i in range(4): for i in range(4):
for j in range(4): for j in range(4):
frame_info.extend(camera_space[i][j].to_bytes(8, "little")) frame_info.extend(struct.pack("d", camera_space[i][j]))
# MATRIX # MATRIX
frame_info.extend(("DONE ").encode("utf8")) frame_info.extend(("DONE ").encode("utf8"))
# strokes # strokes
frame_info.extend(("STROKES ").encode("utf8")) frame_info.extend(("STROKES ").encode("utf8"))
layers = obj.data.layers layers = object.data.layers
for layer in layers: for layer in layers:
strokes = layer.frames.data.active_frame.strokes strokes = layer.frames.data.active_frame.strokes
for stroke in strokes: for stroke in strokes: