From c284151ba2d98ab7ad1110baff7f88fc3a39a323 Mon Sep 17 00:00:00 2001 From: Marco Bavagnoli Date: Tue, 9 Jul 2024 21:55:19 +0200 Subject: [PATCH] some review fixes --- .gitignore | 2 ++ lib/src/bindings/audio_data.dart | 2 +- lib/src/bindings/audio_data_web.dart | 3 +++ lib/src/bindings/bindings_capture.dart | 2 +- lib/src/bindings/bindings_player.dart | 2 +- lib/src/bindings/soloud_controller.dart | 2 +- lib/src/soloud.dart | 7 ++++--- lib/src/utils/loader_base.dart | 3 +++ pubspec.yaml | 4 ++++ wasm.sh | 1 + web.sh | 1 + web/compile_wasm.sh | 1 + web/compile_worker.bat | 3 ++- web/compile_worker.sh | 4 ++-- 14 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index ee15be5..b18daed 100755 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,8 @@ images/ lib/flutter_soloud_FFIGEN.dart web/build +web/worker.dart.js.deps +web/worker.dart.js.map **/android/caches **/android/.tmp diff --git a/lib/src/bindings/audio_data.dart b/lib/src/bindings/audio_data.dart index 2c15b33..c581863 100644 --- a/lib/src/bindings/audio_data.dart +++ b/lib/src/bindings/audio_data.dart @@ -1,6 +1,6 @@ import 'package:flutter_soloud/src/bindings/audio_data_extensions.dart'; import 'package:flutter_soloud/src/bindings/audio_data_ffi.dart' - if (dart.library.html) 'audio_data_web.dart'; + if (dart.library.js_interop) 'audio_data_web.dart'; import 'package:flutter_soloud/src/bindings/soloud_controller.dart'; import 'package:flutter_soloud/src/exceptions/exceptions.dart'; import 'package:meta/meta.dart'; diff --git a/lib/src/bindings/audio_data_web.dart b/lib/src/bindings/audio_data_web.dart index 82a7885..7342f67 100644 --- a/lib/src/bindings/audio_data_web.dart +++ b/lib/src/bindings/audio_data_web.dart @@ -29,6 +29,9 @@ class AudioDataCtrl { SoLoudController().captureFFI.getCaptureAudioTexture; void allocSamples() { + /// This is the max amount of memory [_samplePtr] may need. This number + /// is needed when acquiring data with [getTexture] which is a matrix of + /// 256 rows and 512 columns of floats (4 bytes each). _samplesPtr = wasmMalloc(512 * 256 * 4); } diff --git a/lib/src/bindings/bindings_capture.dart b/lib/src/bindings/bindings_capture.dart index 2291da2..3f2f2b3 100644 --- a/lib/src/bindings/bindings_capture.dart +++ b/lib/src/bindings/bindings_capture.dart @@ -5,7 +5,7 @@ import 'package:flutter_soloud/src/enums.dart'; import 'package:meta/meta.dart'; export 'package:flutter_soloud/src/bindings/bindings_capture_ffi.dart' - if (dart.library.html) 'package:flutter_soloud/src/bindings/bindings_capture_web.dart'; + if (dart.library.js_interop) 'package:flutter_soloud/src/bindings/bindings_capture_web.dart'; /// The experimenta functionality to use the microphone used by "SoLoudCapture". @experimental diff --git a/lib/src/bindings/bindings_player.dart b/lib/src/bindings/bindings_player.dart index 3330da4..79e8b9a 100644 --- a/lib/src/bindings/bindings_player.dart +++ b/lib/src/bindings/bindings_player.dart @@ -9,7 +9,7 @@ import 'package:flutter_soloud/src/sound_hash.dart'; import 'package:meta/meta.dart'; export 'package:flutter_soloud/src/bindings/bindings_player_ffi.dart' - if (dart.library.html) 'package:flutter_soloud/src/bindings/bindings_player_web.dart'; + if (dart.library.js_interop) 'package:flutter_soloud/src/bindings/bindings_player_web.dart'; /// Abstract class defining the interface for the platform-specific /// implementations. diff --git a/lib/src/bindings/soloud_controller.dart b/lib/src/bindings/soloud_controller.dart index 6fd62ac..94d1eea 100644 --- a/lib/src/bindings/soloud_controller.dart +++ b/lib/src/bindings/soloud_controller.dart @@ -1,2 +1,2 @@ export 'package:flutter_soloud/src/bindings/soloud_controller_ffi.dart' - if (dart.library.html) 'package:flutter_soloud/src/bindings/soloud_controller_web.dart'; + if (dart.library.js_interop) 'package:flutter_soloud/src/bindings/soloud_controller_web.dart'; diff --git a/lib/src/soloud.dart b/lib/src/soloud.dart index a171cbb..921ffb5 100644 --- a/lib/src/soloud.dart +++ b/lib/src/soloud.dart @@ -423,8 +423,9 @@ interface class SoLoud { /// Provide a [path] of the file to be used as a reference to distinguis /// this [buffer]. /// - /// The [buffer] represents the bytes of an audio file. It could be also a - /// simple WAV format sequence of manually generated bytes. + /// The [buffer] represents the bytes of a supported audio file (not + /// RAW data). + /// It could be also a simple WAV format sequence of manually generated bytes. /// /// When [mode] is [LoadMode.memory], the whole uncompressed RAW PCM /// audio is loaded into memory. Used to prevent gaps or lags @@ -434,7 +435,7 @@ interface class SoLoud { /// See the [seek] note problem when using [LoadMode.disk]. /// The default is [LoadMode.memory]. /// IMPORTANT: [LoadMode.memory] used the on web platform could cause UI - /// freezy problems. + /// freeze problems. /// /// This is the only choice to load a file when using this plugin on the web /// because browsers cannot read directly files from the loal storage. diff --git a/lib/src/utils/loader_base.dart b/lib/src/utils/loader_base.dart index ee63703..e689ef7 100644 --- a/lib/src/utils/loader_base.dart +++ b/lib/src/utils/loader_base.dart @@ -1,8 +1,11 @@ +// ignore_for_file: public_member_api_docs + import 'package:flutter/services.dart'; import 'package:flutter_soloud/src/audio_source.dart'; import 'package:flutter_soloud/src/enums.dart'; import 'package:http/http.dart' as http; +/// Stub interface for unsupported plarforms. interface class SoLoudLoader { Future initialize() async => throw UnsupportedError('platform not supported'); diff --git a/pubspec.yaml b/pubspec.yaml index b860d00..4dc57d1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -60,6 +60,10 @@ flutter: ffiPlugin: true assets: + # These assets are only needed for the web platform. + # Waiting for https://github.com/flutter/flutter/issues/65065 and + # https://github.com/flutter/flutter/issues/8230 to be addressed + # to make a conditional build. - web/worker.dart.js - web/libflutter_soloud_plugin.js - web/libflutter_soloud_plugin.wasm diff --git a/wasm.sh b/wasm.sh index 2997284..3a2dcaa 100644 --- a/wasm.sh +++ b/wasm.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -euo pipefail cd web sh ./compile_wasm.sh diff --git a/web.sh b/web.sh index b342433..784d1b3 100644 --- a/web.sh +++ b/web.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -euo pipefail cd web sh ./compile_worker.sh diff --git a/web/compile_wasm.sh b/web/compile_wasm.sh index 61b55af..2e19361 100755 --- a/web/compile_wasm.sh +++ b/web/compile_wasm.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -euo pipefail rm -f libflutter_soloud_plugin.* rm -r build diff --git a/web/compile_worker.bat b/web/compile_worker.bat index aef6762..8ed2dea 100755 --- a/web/compile_worker.bat +++ b/web/compile_worker.bat @@ -1,2 +1,3 @@ # -O4 -dart compile js -o worker.dart.js ./worker.dart \ No newline at end of file +dart compile js -o worker.dart.js ./worker.dart + diff --git a/web/compile_worker.sh b/web/compile_worker.sh index de2ccd4..450968f 100755 --- a/web/compile_worker.sh +++ b/web/compile_worker.sh @@ -1,2 +1,2 @@ - # -O4 -dart compile js -O3 -o worker.dart.js ./worker.dart \ No newline at end of file +dart compile js -O3 -o worker.dart.js ./worker.dart +