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); label.setRepaintsOnMouseActivity(true);
auto baseColour = label.findColour(juce::Label::backgroundColourId); auto baseColour = label.findColour(juce::Label::backgroundColourId);
if (label.isEditable()) { 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()); baseColour = LookAndFeelHelpers::createBaseColour(baseColour, false, label.isMouseOver(true), false, label.isEnabled());
} }
g.setColour(baseColour); 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) { 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}; 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.setColour(box.findColour(juce::ComboBox::backgroundColourId));
g.fillRoundedRectangle(boxBounds.toFloat(), RECT_RADIUS); 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) { 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); 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 bpm = 120;
double playTimeSeconds = 0; double playTimeSeconds = 0;
bool isPlaying = false; bool isPlaying = false;
int timeSigNum = 4; juce::AudioPlayHead::TimeSignature timeSig;
int timeSigDen = 4;
// Get MIDI transport info // Get MIDI transport info
playHead = this->getPlayHead(); playHead = this->getPlayHead();
if (playHead != nullptr) { if (playHead != nullptr) {
auto cpi = playHead->getPosition(); auto pos = playHead->getPosition();
if (cpi != juce::nullopt) { if (pos.hasValue()) {
auto currentPositionInfo = *cpi; juce::AudioPlayHead::PositionInfo pi = *pos;
bpm = *currentPositionInfo.getBpm(); bpm = pi.getBpm().orFallback(bpm);
playTimeSeconds = *currentPositionInfo.getTimeInSeconds(); playTimeSeconds = pi.getTimeInSeconds().orFallback(playTimeSeconds);
isPlaying = currentPositionInfo.getIsPlaying(); isPlaying = pi.getIsPlaying();
timeSigNum = (*currentPositionInfo.getTimeSignature()).numerator; timeSig = pi.getTimeSignature().orFallback(timeSig);
timeSigDen = (*currentPositionInfo.getTimeSignature()).denominator;
} }
} }
// Calculated number of beats // 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; double playTimeBeats = bpm * playTimeSeconds / 60;
// Calculated time per sample in seconds and beats // 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 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)] object_info["matrix"] = [camera_space[i][j] for i in range(4) for j in range(4)]
return object_info 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 @persistent
def save_scene_to_file(scene, FilePath): def save_scene_to_file(scene, file_path):
returnFrame = scene.frame_current return_frame = scene.frame_current
scene_info = {"frames": []} scene_info = {"frames": []}
for frame in range(0, scene.frame_end - scene.frame_start): for frame in range(0, scene.frame_end - scene.frame_start):
frame_info = {"objects": []}
scene.frame_set(frame + scene.frame_start) scene.frame_set(frame + scene.frame_start)
for obj in bpy.data.objects: scene_info["frames"].append(get_frame_info())
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)
json_str = json.dumps(scene_info, separators=(',', ':')) json_str = json.dumps(scene_info, separators=(',', ':'))
if (FilePath is not None): if file_path is not None:
f = open(FilePath, "w") f = open(file_path, "w")
f.write(json_str) f.write(json_str)
f.close() f.close()
else: else:
return 1 return 1
scene.frame_set(returnFrame) scene.frame_set(return_frame)
return 0 return 0
@persistent @persistent
def send_scene_to_osci_render(scene): def send_scene_to_osci_render(scene):
global sock global sock
engine_info = {"objects": []}
if sock is not None: if sock is not None:
for obj in bpy.data.objects: frame_info = get_frame_info()
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))
json_str = json.dumps(frame_info, separators=(',', ':')) + '\n'
engine_info["focalLength"] = -0.05 * bpy.data.cameras[0].lens
json_str = json.dumps(engine_info, separators=(',', ':')) + '\n'
try: try:
print(json_str)
sock.sendall(json_str.encode('utf-8')) sock.sendall(json_str.encode('utf-8'))
except socket.error as exp: except socket.error as exp:
sock = None sock = None

Wyświetl plik

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