From b440934299bc625d02004c89b0cabcf5d06ac6ca Mon Sep 17 00:00:00 2001 From: luigi-rosso Date: Fri, 5 Apr 2024 21:34:08 +0000 Subject: [PATCH] Fix audio overlap Also fixes some warnings from the flutter runtime. Diffs= 5d10f615b Fix audio overlap (#6979) Co-authored-by: Luigi Rosso --- .rive_head | 2 +- analysis_options.yaml | 3 - lib/src/rive_core/audio_player.dart | 13 +++- lib/src/rive_core/drawable.dart | 3 - .../layout/layout_component_style.dart | 3 - lib/src/rive_core/layout_component.dart | 66 ------------------- lib/src/rive_core/shapes/path_composer.dart | 16 ++--- 7 files changed, 20 insertions(+), 86 deletions(-) diff --git a/.rive_head b/.rive_head index 11aa84d..bc7c686 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -6837ee0f71109d0eee0f35ceb2326cf50325432b +5d10f615b6501e8cff88e0b2aca49c99ae22e5bb diff --git a/analysis_options.yaml b/analysis_options.yaml index 9386fba..63fe01d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -8,7 +8,6 @@ analyzer: linter: rules: - always_put_required_named_parameters_first - - always_require_non_null_named_parameters - annotate_overrides # - avoid_annotating_with_dynamic - avoid_bool_literals_in_conditional_expressions @@ -24,8 +23,6 @@ linter: - avoid_null_checks_in_equality_operators - avoid_relative_lib_imports - avoid_return_types_on_setters - - avoid_returning_null - - avoid_returning_null_for_future - avoid_returning_null_for_void - avoid_returning_this - avoid_setters_without_getters diff --git a/lib/src/rive_core/audio_player.dart b/lib/src/rive_core/audio_player.dart index 0aeb5cd..29590a6 100644 --- a/lib/src/rive_core/audio_player.dart +++ b/lib/src/rive_core/audio_player.dart @@ -52,14 +52,23 @@ class AudioPlayer { isPlaying.value = true; - var sound = engine.play(source, engineTime, 0, + var sound = engine.play( + source, + engineTime, + endTime == null + ? 0 + : (engineTime + + (endTime - startTime).inMicroseconds * + 1e-6 * + engine.sampleRate) + .round(), (startTime.inMicroseconds * 1e-6 * engine.sampleRate).round()); _sounds.add(sound); _soundDuration = source.duration; _soundStartTime = engineTime - (startTime.inMicroseconds * 1e-6 * engine.sampleRate).round(); _soundEndTime = endTime; - _timer = Timer.periodic(const Duration(milliseconds: 0), _frameCallback); + _timer ??= Timer.periodic(const Duration(milliseconds: 0), _frameCallback); } bool playSource(AudioAsset? audio) { diff --git a/lib/src/rive_core/drawable.dart b/lib/src/rive_core/drawable.dart index 523fdff..d42aa3f 100644 --- a/lib/src/rive_core/drawable.dart +++ b/lib/src/rive_core/drawable.dart @@ -40,9 +40,6 @@ abstract class Drawable extends DrawableBase { @override void blendModeValueChanged(int from, int to) {} - @override - void isTargetOpaqueChanged(bool from, bool to) {} - List _clippingShapes = []; bool clip(Canvas canvas) { diff --git a/lib/src/rive_core/layout/layout_component_style.dart b/lib/src/rive_core/layout/layout_component_style.dart index 1b5fdb6..7cdb3ab 100644 --- a/lib/src/rive_core/layout/layout_component_style.dart +++ b/lib/src/rive_core/layout/layout_component_style.dart @@ -326,7 +326,4 @@ class LayoutComponentStyle extends LayoutComponentStyleBase { @override void update(int dirt) {} - - @override - String get defaultName => 'Layout Style'; } diff --git a/lib/src/rive_core/layout_component.dart b/lib/src/rive_core/layout_component.dart index 85a2eb0..ca23656 100644 --- a/lib/src/rive_core/layout_component.dart +++ b/lib/src/rive_core/layout_component.dart @@ -308,70 +308,4 @@ class LayoutComponent extends LayoutComponentBase { super.buildDependencies(); parent?.addDependent(this); } - - @override - String get defaultName => 'Layout Component'; -} - -Mat2D _computeAlignment( - BoxFit fit, Alignment alignment, AABB frame, AABB content) { - double contentWidth = content[2] - content[0]; - double contentHeight = content[3] - content[1]; - - if (contentWidth == 0 || contentHeight == 0) { - return Mat2D(); - } - - double x = - -1 * content[0] - contentWidth / 2.0 - (alignment.x * contentWidth / 2.0); - double y = -1 * content[1] - - contentHeight / 2.0 - - (alignment.y * contentHeight / 2.0); - - double scaleX = 1.0, scaleY = 1.0; - - switch (fit) { - case BoxFit.fill: - scaleX = frame.width / contentWidth; - scaleY = frame.height / contentHeight; - break; - case BoxFit.contain: - double minScale = - min(frame.width / contentWidth, frame.height / contentHeight); - scaleX = scaleY = minScale; - break; - case BoxFit.cover: - double maxScale = - max(frame.width / contentWidth, frame.height / contentHeight); - scaleX = scaleY = maxScale; - break; - case BoxFit.fitHeight: - double minScale = frame.height / contentHeight; - scaleX = scaleY = minScale; - break; - case BoxFit.fitWidth: - double minScale = frame.width / contentWidth; - scaleX = scaleY = minScale; - break; - case BoxFit.none: - scaleX = scaleY = 1.0; - break; - case BoxFit.scaleDown: - double minScale = - min(frame.width / contentWidth, frame.height / contentHeight); - scaleX = scaleY = minScale < 1.0 ? minScale : 1.0; - break; - } - - Mat2D translation = Mat2D(); - - translation[4] = - frame[0] + frame.width / 2.0 + (alignment.x * frame.width / 2.0); - translation[5] = - frame[1] + frame.height / 2.0 + (alignment.y * frame.height / 2.0); - - return Mat2D.multiply( - Mat2D(), - Mat2D.multiply(Mat2D(), translation, Mat2D.fromScale(scaleX, scaleY)), - Mat2D.fromTranslate(x, y)); } diff --git a/lib/src/rive_core/shapes/path_composer.dart b/lib/src/rive_core/shapes/path_composer.dart index 2d4f25b..848e632 100644 --- a/lib/src/rive_core/shapes/path_composer.dart +++ b/lib/src/rive_core/shapes/path_composer.dart @@ -100,14 +100,14 @@ class PathComposer extends Component { artboard?.onComponentDirty(this); } - // Instead of adding dirt and rely on the recursive behavior of the addDirt method, - // we need to explicitly add dirt to the dependents. The reason is that a collapsed - // shape will not clear its dirty path flag in the current frame since it is collapsed. - // So in a future frame if it is uncollapsed, we mark its path flag as dirty again, - // but since it was already dirty, the recursive part will not kick in and the dependents - // won't update. - // This scenario is not common, but it can happen when a solo toggles between an empty - // group and a path for example. + // Instead of adding dirt and rely on the recursive behavior of the addDirt + // method, we need to explicitly add dirt to the dependents. The reason is + // that a collapsed shape will not clear its dirty path flag in the current + // frame since it is collapsed. So in a future frame if it is uncollapsed, we + // mark its path flag as dirty again, but since it was already dirty, the + // recursive part will not kick in and the dependents won't update. This + // scenario is not common, but it can happen when a solo toggles between an + // empty group and a path for example. void pathCollapseChanged() { addDirt(ComponentDirt.path); for (final d in dependents) {