Fix some crashes in standalone mode, crashes when saving .gpla file

pull/241/head
James Ball 2024-04-26 19:27:28 +01:00 zatwierdzone przez James H Ball
rodzic 13f7c7a2c9
commit d8bb084cac
7 zmienionych plików z 59 dodań i 58 usunięć

Wyświetl plik

@ -94,7 +94,11 @@ void OscirenderLookAndFeel::drawLabel(juce::Graphics& g, juce::Label& label) {
label.setRepaintsOnMouseActivity(true);
auto baseColour = label.findColour(juce::Label::backgroundColourId);
if (label.isEditable()) {
label.setMouseCursor(juce::MouseCursor::IBeamCursor);
juce::MessageManager::callAsync(
[&label]() {
label.setMouseCursor(juce::MouseCursor::IBeamCursor);
}
);
baseColour = LookAndFeelHelpers::createBaseColour(baseColour, false, label.isMouseOver(true), false, label.isEnabled());
}
g.setColour(baseColour);
@ -168,7 +172,11 @@ void OscirenderLookAndFeel::drawTextEditorOutline(juce::Graphics& g, int width,
void OscirenderLookAndFeel::drawComboBox(juce::Graphics& g, int width, int height, bool, int, int, int, int, juce::ComboBox& box) {
juce::Rectangle<int> boxBounds{0, 0, width, height};
box.setMouseCursor(juce::MouseCursor::PointingHandCursor);
juce::MessageManager::callAsync(
[&box]() {
box.setMouseCursor(juce::MouseCursor::PointingHandCursor);
}
);
g.setColour(box.findColour(juce::ComboBox::backgroundColourId));
g.fillRoundedRectangle(boxBounds.toFloat(), RECT_RADIUS);
@ -280,7 +288,11 @@ void OscirenderLookAndFeel::drawLinearSlider(juce::Graphics& g, int x, int y, in
}
void OscirenderLookAndFeel::drawButtonBackground(juce::Graphics& g, juce::Button& button, const juce::Colour& backgroundColour, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) {
button.setMouseCursor(juce::MouseCursor::PointingHandCursor);
juce::MessageManager::callAsync(
[&button]() {
button.setMouseCursor(juce::MouseCursor::PointingHandCursor);
}
);
auto bounds = button.getLocalBounds().toFloat().reduced(0.5f, 0.5f);

Wyświetl plik

@ -558,24 +558,24 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
double bpm = 120;
double playTimeSeconds = 0;
bool isPlaying = false;
int timeSigNum = 4;
int timeSigDen = 4;
juce::AudioPlayHead::TimeSignature timeSig;
// Get MIDI transport info
playHead = this->getPlayHead();
if (playHead != nullptr) {
auto cpi = playHead->getPosition();
if (cpi != juce::nullopt) {
auto currentPositionInfo = *cpi;
bpm = *currentPositionInfo.getBpm();
playTimeSeconds = *currentPositionInfo.getTimeInSeconds();
isPlaying = currentPositionInfo.getIsPlaying();
timeSigNum = (*currentPositionInfo.getTimeSignature()).numerator;
timeSigDen = (*currentPositionInfo.getTimeSignature()).denominator;
auto pos = playHead->getPosition();
if (pos.hasValue()) {
juce::AudioPlayHead::PositionInfo pi = *pos;
bpm = pi.getBpm().orFallback(bpm);
playTimeSeconds = pi.getTimeInSeconds().orFallback(playTimeSeconds);
isPlaying = pi.getIsPlaying();
timeSig = pi.getTimeSignature().orFallback(timeSig);
}
}
// Calculated number of beats
// TODO: To make this more resilient to changing BPMs, we should change how this is calculated
// or use another property of the AudioPlayHead::PositionInfo
double playTimeBeats = bpm * playTimeSeconds / 60;
// Calculated time per sample in seconds and beats

Wyświetl plik

@ -118,71 +118,60 @@ def append_matrix(object_info, obj):
camera_space = bpy.context.scene.camera.matrix_world.inverted() @ obj.matrix_world
object_info["matrix"] = [camera_space[i][j] for i in range(4) for j in range(4)]
return object_info
def get_frame_info():
frame_info = {"objects": []}
for obj in bpy.data.objects:
if obj.visible_get() and obj.type == 'GPENCIL':
object_info = {"name": obj.name}
strokes = obj.data.layers.active.frames.data.active_frame.strokes
object_info["vertices"] = []
for stroke in strokes:
object_info["vertices"].append([{
"x": vert.co[0],
"y": vert.co[1],
"z": vert.co[2],
} for vert in stroke.points])
frame_info["objects"].append(append_matrix(object_info, obj))
frame_info["focalLength"] = -0.05 * bpy.data.cameras[0].lens
return frame_info
@persistent
def save_scene_to_file(scene, FilePath):
returnFrame = scene.frame_current
def save_scene_to_file(scene, file_path):
return_frame = scene.frame_current
scene_info = {"frames": []}
for frame in range(0, scene.frame_end - scene.frame_start):
frame_info = {"objects": []}
scene.frame_set(frame + scene.frame_start)
for obj in bpy.data.objects:
if obj.visible_get() and obj.type == 'GPENCIL':
object_info = {"name": obj.name}
strokes = obj.data.layers.active.frames.data.frames[frame+1].strokes
object_info["vertices"] = []
for stroke in strokes:
object_info["vertices"].append([{
"x": vert.co[0],
"y": vert.co[1],
"z": vert.co[2],
} for vert in stroke.points])
frame_info["objects"].append(append_matrix(object_info, obj))
frame_info["focalLength"] = -0.05 * bpy.data.cameras[0].lens
scene_info["frames"].append(frame_info)
scene_info["frames"].append(get_frame_info())
json_str = json.dumps(scene_info, separators=(',', ':'))
if (FilePath is not None):
f = open(FilePath, "w")
if file_path is not None:
f = open(file_path, "w")
f.write(json_str)
f.close()
else:
return 1
scene.frame_set(returnFrame)
scene.frame_set(return_frame)
return 0
@persistent
def send_scene_to_osci_render(scene):
global sock
engine_info = {"objects": []}
if sock is not None:
for obj in bpy.data.objects:
if obj.visible_get() and obj.type == 'GPENCIL':
object_info = {"name": obj.name}
strokes = obj.data.layers.active.frames.data.active_frame.strokes
object_info["vertices"] = []
for stroke in strokes:
object_info["vertices"].append([{
"x": vert.co[0],
"y": vert.co[1],
"z": vert.co[2],
} for vert in stroke.points])
engine_info["objects"].append(append_matrix(object_info, obj))
frame_info = get_frame_info()
engine_info["focalLength"] = -0.05 * bpy.data.cameras[0].lens
json_str = json.dumps(engine_info, separators=(',', ':')) + '\n'
json_str = json.dumps(frame_info, separators=(',', ':')) + '\n'
try:
print(json_str)
sock.sendall(json_str.encode('utf-8'))
except socket.error as exp:
sock = None

Wyświetl plik

@ -8,10 +8,10 @@
companyEmail="james@ball.sh" defines="NOMINMAX=1" pluginAUMainType="'aumu'">
<MAINGROUP id="j5Ge2T" name="osci-render">
<GROUP id="{5ABCED88-0059-A7AF-9596-DBF91DDB0292}" name="Resources">
<GROUP id="{2A3754EB-A333-139A-56E1-4C1A8856B803}" name="line art">
<FILE id="tKtCYg" name="fallback.gpla" compile="0" resource="1" file="Resources/line art/fallback.gpla"/>
<FILE id="rBdZfZ" name="invalid.gpla" compile="0" resource="1" file="Resources/line art/invalid.gpla"/>
<FILE id="L3YrgX" name="noframes.gpla" compile="0" resource="1" file="Resources/line art/noframes.gpla"/>
<GROUP id="{F3815953-00C0-3876-5552-BDE98F3233D9}" name="gpla">
<FILE id="euGQq0" name="fallback.gpla" compile="0" resource="1" file="Resources/gpla/fallback.gpla"/>
<FILE id="G2dMtI" name="invalid.gpla" compile="0" resource="1" file="Resources/gpla/invalid.gpla"/>
<FILE id="b9HuXW" name="noframes.gpla" compile="0" resource="1" file="Resources/gpla/noframes.gpla"/>
</GROUP>
<GROUP id="{C2609827-4F4A-1ADA-8BA1-A40C1D92649C}" name="lua">
<FILE id="xANsA8" name="demo.lua" compile="0" resource="1" file="Resources/lua/demo.lua"/>