diff --git a/Resources/line art/fallback.gpla b/Resources/gpla/fallback.gpla similarity index 100% rename from Resources/line art/fallback.gpla rename to Resources/gpla/fallback.gpla diff --git a/Resources/line art/invalid.gpla b/Resources/gpla/invalid.gpla similarity index 100% rename from Resources/line art/invalid.gpla rename to Resources/gpla/invalid.gpla diff --git a/Resources/line art/noframes.gpla b/Resources/gpla/noframes.gpla similarity index 100% rename from Resources/line art/noframes.gpla rename to Resources/gpla/noframes.gpla diff --git a/Source/LookAndFeel.cpp b/Source/LookAndFeel.cpp index 321013d..9c8cc71 100644 --- a/Source/LookAndFeel.cpp +++ b/Source/LookAndFeel.cpp @@ -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 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); diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 20ef44b..0cfb2e7 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -558,24 +558,24 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer& 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 diff --git a/blender/osci_render/__init__.py b/blender/osci_render/__init__.py index cfdd20d..dd85a23 100644 --- a/blender/osci_render/__init__.py +++ b/blender/osci_render/__init__.py @@ -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 diff --git a/osci-render.jucer b/osci-render.jucer index 5a2036e..8e49697 100644 --- a/osci-render.jucer +++ b/osci-render.jucer @@ -8,10 +8,10 @@ companyEmail="james@ball.sh" defines="NOMINMAX=1" pluginAUMainType="'aumu'"> - - - - + + + +