From 5c0995a5ead306e49c6849b81c041e680b10d87a Mon Sep 17 00:00:00 2001 From: Larpoux Date: Thu, 10 Mar 2022 10:24:32 +0100 Subject: [PATCH] taudio-waa_native --- .bundle/config | 2 - .metadata | 10 - CHANGELOG.md | 5 +- LICENSE | 374 +--- README.md | 16 +- analysis_options.yaml | 4 - android/build.gradle | 33 +- android/src/main/AndroidManifest.xml | 2 +- .../thetatau/taudio_waa/TaudioWaaPlugin.java | 38 + bin/pub.sh | 36 + example/ios/Podfile | 7 + example/ios/Podfile.lock | 9 +- example/lib/main.dart | 77 +- .../flutter/generated_plugin_registrant.cc | 4 + example/linux/flutter/generated_plugins.cmake | 2 +- .../Flutter/GeneratedPluginRegistrant.swift | 2 + example/pubspec.lock | 46 +- .../flutter/generated_plugin_registrant.cc | 3 + .../windows/flutter/generated_plugins.cmake | 2 +- .../winuwp/flutter/generated_plugins.cmake | 1 - ffigen.yaml | 3 + ios/.gitignore | 38 + ios/Assets/.gitkeep | 0 ios/Classes/TaudioWaaPlugin.h | 4 + ios/Classes/TaudioWaaPlugin.mm | 23 + ios/Classes/taudio_waa.c | 3 - .../Classes/taudio_waa.cpp.sav | 1 + ios/taudio_waa.podspec | 14 +- lib/public/web_audio.dart | 1885 ----------------- lib/taudio_waa.dart | 127 +- lib/taudio_waa_bindings_generated.dart | 6 +- linux/CMakeLists.txt | 37 +- linux/include/taudio_waa/taudio_waa_plugin.h | 26 + linux/taudio_waa_plugin.cc | 70 + macos/Classes/TaudioWaaPlugin.swift | 19 + macos/taudio_waa.podspec | 8 +- pubspec.yaml | 38 +- src/taudio_waa.c | 18 +- src/taudio_waa.h | 2 +- test/taudio_waa_test.dart | 23 + windows/CMakeLists.txt | 42 +- .../taudio_waa/taudio_waa_plugin_c_api.h | 23 + windows/taudio_waa_plugin.cpp | 59 + windows/taudio_waa_plugin.h | 32 + windows/taudio_waa_plugin_c_api.cpp | 12 + 45 files changed, 664 insertions(+), 2522 deletions(-) delete mode 100644 .bundle/config delete mode 100644 .metadata delete mode 100644 analysis_options.yaml create mode 100644 android/src/main/java/xyz/thetatau/taudio_waa/TaudioWaaPlugin.java create mode 100755 bin/pub.sh create mode 100644 ios/.gitignore create mode 100644 ios/Assets/.gitkeep create mode 100644 ios/Classes/TaudioWaaPlugin.h create mode 100644 ios/Classes/TaudioWaaPlugin.mm delete mode 100644 ios/Classes/taudio_waa.c rename macos/Classes/taudio_waa.c => ios/Classes/taudio_waa.cpp.sav (96%) delete mode 100644 lib/public/web_audio.dart create mode 100644 linux/include/taudio_waa/taudio_waa_plugin.h create mode 100644 linux/taudio_waa_plugin.cc create mode 100644 macos/Classes/TaudioWaaPlugin.swift create mode 100644 test/taudio_waa_test.dart create mode 100644 windows/include/taudio_waa/taudio_waa_plugin_c_api.h create mode 100644 windows/taudio_waa_plugin.cpp create mode 100644 windows/taudio_waa_plugin.h create mode 100644 windows/taudio_waa_plugin_c_api.cpp diff --git a/.bundle/config b/.bundle/config deleted file mode 100644 index e8bfe8a..0000000 --- a/.bundle/config +++ /dev/null @@ -1,2 +0,0 @@ ---- -BUNDLE_PATH: "~/vendor/bundle" diff --git a/.metadata b/.metadata deleted file mode 100644 index 84e14ee..0000000 --- a/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: 29b949e025bebf841c8c34a0e0fbaeb087b1d2c3 - channel: master - -project_type: plugin_ffi diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b1ed0..41cc7d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,3 @@ -## 0.0.2-beta-1+3 - -- ## The [CHANGELOG file is here](https://tau.canardoux.xyz/doc-v9/changelog.html) +## 0.0.1 +* TODO: Describe initial release. diff --git a/LICENSE b/LICENSE index a612ad9..ba75c69 100644 --- a/LICENSE +++ b/LICENSE @@ -1,373 +1 @@ -Mozilla Public License Version 2.0 -================================== - -1. Definitions --------------- - -1.1. "Contributor" - means each individual or legal entity that creates, contributes to - the creation of, or owns Covered Software. - -1.2. "Contributor Version" - means the combination of the Contributions of others (if any) used - by a Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - means Source Code Form to which the initial Contributor has attached - the notice in Exhibit A, the Executable Form of such Source Code - Form, and Modifications of such Source Code Form, in each case - including portions thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - (a) that the initial Contributor has attached the notice described - in Exhibit B to the Covered Software; or - - (b) that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the - terms of a Secondary License. - -1.6. "Executable Form" - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - means a work that combines Covered Software with other material, in - a separate file or files, that is not Covered Software. - -1.8. "License" - means this document. - -1.9. "Licensable" - means having the right to grant, to the maximum extent possible, - whether at the time of the initial grant or subsequently, any and - all of the rights conveyed by this License. - -1.10. "Modifications" - means any of the following: - - (a) any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered - Software; or - - (b) any new file in Source Code Form that contains any Covered - Software. - -1.11. "Patent Claims" of a Contributor - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the - License, by the making, using, selling, offering for sale, having - made, import, or transfer of either its Contributions or its - Contributor Version. - -1.12. "Secondary License" - means either the GNU General Public License, Version 2.0, the GNU - Lesser General Public License, Version 2.1, the GNU Affero General - Public License, Version 3.0, or any later versions of those - licenses. - -1.13. "Source Code Form" - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that - controls, is controlled by, or is under common control with You. For - purposes of this definition, "control" means (a) the power, direct - or indirect, to cause the direction or management of such entity, - whether by contract or otherwise, or (b) ownership of more than - fifty percent (50%) of the outstanding shares or beneficial - ownership of such entity. - -2. License Grants and Conditions --------------------------------- - -2.1. Grants - -Each Contributor hereby grants You a world-wide, royalty-free, -non-exclusive license: - -(a) under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - -(b) under Patent Claims of such Contributor to make, use, sell, offer - for sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - -The licenses granted in Section 2.1 with respect to any Contribution -become effective for each Contribution on the date the Contributor first -distributes such Contribution. - -2.3. Limitations on Grant Scope - -The licenses granted in this Section 2 are the only rights granted under -this License. No additional rights or licenses will be implied from the -distribution or licensing of Covered Software under this License. -Notwithstanding Section 2.1(b) above, no patent license is granted by a -Contributor: - -(a) for any code that a Contributor has removed from Covered Software; - or - -(b) for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - -(c) under Patent Claims infringed by Covered Software in the absence of - its Contributions. - -This License does not grant any rights in the trademarks, service marks, -or logos of any Contributor (except as may be necessary to comply with -the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - -No Contributor makes additional grants as a result of Your choice to -distribute the Covered Software under a subsequent version of this -License (see Section 10.2) or under the terms of a Secondary License (if -permitted under the terms of Section 3.3). - -2.5. Representation - -Each Contributor represents that the Contributor believes its -Contributions are its original creation(s) or it has sufficient rights -to grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - -This License is not intended to limit any rights You have under -applicable copyright doctrines of fair use, fair dealing, or other -equivalents. - -2.7. Conditions - -Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted -in Section 2.1. - -3. Responsibilities -------------------- - -3.1. Distribution of Source Form - -All distribution of Covered Software in Source Code Form, including any -Modifications that You create or to which You contribute, must be under -the terms of this License. You must inform recipients that the Source -Code Form of the Covered Software is governed by the terms of this -License, and how they can obtain a copy of this License. You may not -attempt to alter or restrict the recipients' rights in the Source Code -Form. - -3.2. Distribution of Executable Form - -If You distribute Covered Software in Executable Form then: - -(a) such Covered Software must also be made available in Source Code - Form, as described in Section 3.1, and You must inform recipients of - the Executable Form how they can obtain a copy of such Source Code - Form by reasonable means in a timely manner, at a charge no more - than the cost of distribution to the recipient; and - -(b) You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter - the recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - -You may create and distribute a Larger Work under terms of Your choice, -provided that You also comply with the requirements of this License for -the Covered Software. If the Larger Work is a combination of Covered -Software with a work governed by one or more Secondary Licenses, and the -Covered Software is not Incompatible With Secondary Licenses, this -License permits You to additionally distribute such Covered Software -under the terms of such Secondary License(s), so that the recipient of -the Larger Work may, at their option, further distribute the Covered -Software under the terms of either this License or such Secondary -License(s). - -3.4. Notices - -You may not remove or alter the substance of any license notices -(including copyright notices, patent notices, disclaimers of warranty, -or limitations of liability) contained within the Source Code Form of -the Covered Software, except that You may alter any license notices to -the extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - -You may choose to offer, and to charge a fee for, warranty, support, -indemnity or liability obligations to one or more recipients of Covered -Software. However, You may do so only on Your own behalf, and not on -behalf of any Contributor. You must make it absolutely clear that any -such warranty, support, indemnity, or liability obligation is offered by -You alone, and You hereby agree to indemnify every Contributor for any -liability incurred by such Contributor as a result of warranty, support, -indemnity or liability terms You offer. You may include additional -disclaimers of warranty and limitations of liability specific to any -jurisdiction. - -4. Inability to Comply Due to Statute or Regulation ---------------------------------------------------- - -If it is impossible for You to comply with any of the terms of this -License with respect to some or all of the Covered Software due to -statute, judicial order, or regulation then You must: (a) comply with -the terms of this License to the maximum extent possible; and (b) -describe the limitations and the code they affect. Such description must -be placed in a text file included with all distributions of the Covered -Software under this License. Except to the extent prohibited by statute -or regulation, such description must be sufficiently detailed for a -recipient of ordinary skill to be able to understand it. - -5. Termination --------------- - -5.1. The rights granted under this License will terminate automatically -if You fail to comply with any of its terms. However, if You become -compliant, then the rights granted under this License from a particular -Contributor are reinstated (a) provisionally, unless and until such -Contributor explicitly and finally terminates Your grants, and (b) on an -ongoing basis, if such Contributor fails to notify You of the -non-compliance by some reasonable means prior to 60 days after You have -come back into compliance. Moreover, Your grants from a particular -Contributor are reinstated on an ongoing basis if such Contributor -notifies You of the non-compliance by some reasonable means, this is the -first time You have received notice of non-compliance with this License -from such Contributor, and You become compliant prior to 30 days after -Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent -infringement claim (excluding declaratory judgment actions, -counter-claims, and cross-claims) alleging that a Contributor Version -directly or indirectly infringes any patent, then the rights granted to -You by any and all Contributors for the Covered Software under Section -2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all -end user license agreements (excluding distributors and resellers) which -have been validly granted by You or Your distributors under this License -prior to termination shall survive termination. - -************************************************************************ -* * -* 6. Disclaimer of Warranty * -* ------------------------- * -* * -* Covered Software is provided under this License on an "as is" * -* basis, without warranty of any kind, either expressed, implied, or * -* statutory, including, without limitation, warranties that the * -* Covered Software is free of defects, merchantable, fit for a * -* particular purpose or non-infringing. The entire risk as to the * -* quality and performance of the Covered Software is with You. * -* Should any Covered Software prove defective in any respect, You * -* (not any Contributor) assume the cost of any necessary servicing, * -* repair, or correction. This disclaimer of warranty constitutes an * -* essential part of this License. No use of any Covered Software is * -* authorized under this License except under this disclaimer. * -* * -************************************************************************ - -************************************************************************ -* * -* 7. Limitation of Liability * -* -------------------------- * -* * -* Under no circumstances and under no legal theory, whether tort * -* (including negligence), contract, or otherwise, shall any * -* Contributor, or anyone who distributes Covered Software as * -* permitted above, be liable to You for any direct, indirect, * -* special, incidental, or consequential damages of any character * -* including, without limitation, damages for lost profits, loss of * -* goodwill, work stoppage, computer failure or malfunction, or any * -* and all other commercial damages or losses, even if such party * -* shall have been informed of the possibility of such damages. This * -* limitation of liability shall not apply to liability for death or * -* personal injury resulting from such party's negligence to the * -* extent applicable law prohibits such limitation. Some * -* jurisdictions do not allow the exclusion or limitation of * -* incidental or consequential damages, so this exclusion and * -* limitation may not apply to You. * -* * -************************************************************************ - -8. Litigation -------------- - -Any litigation relating to this License may be brought only in the -courts of a jurisdiction where the defendant maintains its principal -place of business and such litigation shall be governed by laws of that -jurisdiction, without reference to its conflict-of-law provisions. -Nothing in this Section shall prevent a party's ability to bring -cross-claims or counter-claims. - -9. Miscellaneous ----------------- - -This License represents the complete agreement concerning the subject -matter hereof. If any provision of this License is held to be -unenforceable, such provision shall be reformed only to the extent -necessary to make it enforceable. Any law or regulation which provides -that the language of a contract shall be construed against the drafter -shall not be used to construe this License against a Contributor. - -10. Versions of the License ---------------------------- - -10.1. New Versions - -Mozilla Foundation is the license steward. Except as provided in Section -10.3, no one other than the license steward has the right to modify or -publish new versions of this License. Each version will be given a -distinguishing version number. - -10.2. Effect of New Versions - -You may distribute the Covered Software under the terms of the version -of the License under which You originally received the Covered Software, -or under the terms of any subsequent version published by the license -steward. - -10.3. Modified Versions - -If you create software not governed by this License, and you want to -create a new license for such software, you may create and use a -modified version of this License if you rename the license and remove -any references to the name of the license steward (except to note that -such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary -Licenses - -If You choose to distribute Source Code Form that is Incompatible With -Secondary Licenses under the terms of this version of the License, the -notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice -------------------------------------------- - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular -file, then You may include the notice in a location (such as a LICENSE -file in a relevant directory) where a recipient would be likely to look -for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice ---------------------------------------------------------- - - This Source Code Form is "Incompatible With Secondary Licenses", as - defined by the Mozilla Public License, v. 2.0. +TODO: Add your license here. diff --git a/README.md b/README.md index fd19e4a..5d5e441 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ -# taudio-waa \ No newline at end of file +# taudio_waa + +A new Flutter plugin project. + +## Getting Started + +This project is a starting point for a Flutter +[plug-in package](https://flutter.dev/developing-packages/), +a specialized package that includes platform-specific implementation code for +Android and/or iOS. + +For help getting started with Flutter development, view the +[online documentation](https://flutter.dev/docs), which offers tutorials, +samples, guidance on mobile development, and a full API reference. + diff --git a/analysis_options.yaml b/analysis_options.yaml deleted file mode 100644 index a5744c1..0000000 --- a/analysis_options.yaml +++ /dev/null @@ -1,4 +0,0 @@ -include: package:flutter_lints/flutter.yaml - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options diff --git a/android/build.gradle b/android/build.gradle index 1dc2311..bbf4058 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,6 +1,4 @@ -// The Android Gradle Plugin builds the native code with the Android NDK. - -group 'xyz.canardoux.taudio_waa' +group 'xyz.thetatau.taudio_waa' version '1.0' buildscript { @@ -10,7 +8,6 @@ buildscript { } dependencies { - // The Android Gradle Plugin knows how to build native code with the NDK. classpath 'com.android.tools.build:gradle:4.1.0' } } @@ -25,31 +22,7 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - // Bumping the plugin compileSdkVersion requires all clients of this plugin - // to bump the version in their app. - compileSdkVersion 32 - defaultConfig { - minSdkVersion 24 - } - - // Bumping the plugin ndkVersion requires all clients of this plugin to bump - // the version in their app and to download a newer version of the NDK. - ndkVersion "21.1.6352462" - - // Invoke the shared CMake build with the Android Gradle Plugin. - externalNativeBuild { - cmake { - path "../src/CMakeLists.txt" - - // The default CMake version for the Android Gradle Plugin is 3.10.2. - // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake - // - // The Flutter tooling requires that developers have CMake 3.10 or later - // installed. You should not increase this version, as doing so will cause - // the plugin to fail to compile for some customers of the plugin. - // version "3.10.2" - } - } + compileSdkVersion 31 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -57,6 +30,6 @@ android { } defaultConfig { - minSdkVersion 24 + minSdkVersion 16 } } diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 1b047ee..1fa7c46 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ + package="xyz.thetatau.taudio_waa"> diff --git a/android/src/main/java/xyz/thetatau/taudio_waa/TaudioWaaPlugin.java b/android/src/main/java/xyz/thetatau/taudio_waa/TaudioWaaPlugin.java new file mode 100644 index 0000000..baeae68 --- /dev/null +++ b/android/src/main/java/xyz/thetatau/taudio_waa/TaudioWaaPlugin.java @@ -0,0 +1,38 @@ +package xyz.thetatau.taudio_waa; + +import androidx.annotation.NonNull; + +import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; + +/** TaudioWaaPlugin */ +public class TaudioWaaPlugin implements FlutterPlugin, MethodCallHandler { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private MethodChannel channel; + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "taudio_waa"); + channel.setMethodCallHandler(this); + } + + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { + if (call.method.equals("getPlatformVersion")) { + result.success("Android " + android.os.Build.VERSION.RELEASE); + } else { + result.notImplemented(); + } + } + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + } +} diff --git a/bin/pub.sh b/bin/pub.sh new file mode 100755 index 0000000..0ecf50e --- /dev/null +++ b/bin/pub.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +git add . +VERSION=$1 + +if [ -z "$VERSION" ]; then + echo "Correct syntax is $0 " + exit -1 +fi + + +dart analyze lib +if [ $? -ne 0 ]; then + echo "Error" + exit -1 +fi +dart format lib +if [ $? -ne 0 ]; then + echo "Error" + exit -1 +fi + +dart analyze example/lib +if [ $? -ne 0 ]; then + echo "Error" + exit -1 +fi +dart format example/lib +if [ $? -ne 0 ]; then + echo "Error" + exit -1 +fi + + + +flutter pub publish diff --git a/example/ios/Podfile b/example/ios/Podfile index 1dd1394..34f3d90 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -39,3 +39,10 @@ post_install do |installer| flutter_additional_ios_build_settings(target) end end + + +# ===================================================== +# The following instruction is only for Tau debugging. +# Do not insert such a line in a real App. +pod 'taudio_waa_native', :path => '../../../taudio-waa_native' +# ===================================================== diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 1f76bae..6ddc7c3 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -2,21 +2,26 @@ PODS: - Flutter (1.0.0) - taudio_waa (0.0.1): - Flutter + - taudio_waa_native (9.0.0-beta-1) DEPENDENCIES: - Flutter (from `Flutter`) - taudio_waa (from `.symlinks/plugins/taudio_waa/ios`) + - taudio_waa_native (from `../../../taudio-waa_native`) EXTERNAL SOURCES: Flutter: :path: Flutter taudio_waa: :path: ".symlinks/plugins/taudio_waa/ios" + taudio_waa_native: + :path: "../../../taudio-waa_native" SPEC CHECKSUMS: Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a - taudio_waa: c8c9ed3b96fcb34470b7fe0065c10d1e3f18e4b2 + taudio_waa: 22320709467a9d19a6c787370a5b43bbf34386f4 + taudio_waa_native: df8c464a8efeb437841e4fa53c6fabde47f2a1aa -PODFILE CHECKSUM: b0b272159268c64df66b1b276887e0e0629a3acb +PODFILE CHECKSUM: 5be4f87c29fca89639722ecc6418a8f682d20425 COCOAPODS: 1.11.2 diff --git a/example/lib/main.dart b/example/lib/main.dart index f5ad96d..78b3710 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; -import 'dart:async'; -import 'package:taudio_waa/taudio_waa.dart' as taudio_waa; +import 'package:taudio_waa/taudio_waa.dart' ; void main() { runApp(const MyApp()); @@ -14,17 +13,72 @@ class MyApp extends StatefulWidget { _MyAppState createState() => _MyAppState(); } + class _MyAppState extends State { late int sumResult; - late Future sumAsyncResult; @override void initState() { super.initState(); - sumResult = taudio_waa.sum(1, 2); - sumAsyncResult = taudio_waa.sumAsync(3, 4); + sumResult = TaudioWaa().sum(1, 2); } + + + void onPressed() + { + + String s = TaudioWaa().greeting("John Smith"); + print(s); + /* +// Prepare the parameters + final nameStr = "John Smith"; + final Pointer namePtr = nameStr.toNativeUtf8(); //Utf8.toUtf8(nameStr); + print("- Calling rust_greeting with argument: $namePtr"); + +// Call rust_greeting + final Pointer resultPtr = rustGreeting(namePtr); + print("- Result pointer: $resultPtr"); + +// Handle the result pointer + final String greetingStr = resultPtr.toDartString(); + print("- Response string: $greetingStr"); +*/ +/* + + // Create an empty two second stereo buffer at the + // sample rate of the AudioContext + var frameCount = (audioCtx.sampleRate! * 2). floor(); + var myArrayBuffer = audioCtx.createBuffer(channels, frameCount, audioCtx.sampleRate!); + // Fill the buffer with white noise; + //just random values between -1.0 and 1.0 + + for (int channel = 0; channel < channels; channel++) { + // This gives us the actual array that contains the data + var nowBuffering = myArrayBuffer.getChannelData(channel); + for (int i = 0; i < frameCount; i++) { + // rng.nextInt(2) is in [0; 2] + // audio needs to be in [-1.0; 1.0] + nowBuffering[i] = rng.nextInt(2) - 1; + } + } + + // Get an AudioBufferSourceNode. + // This is the AudioNode to use when we want to play an AudioBuffer + var source = audioCtx.createBufferSource(); + // set the buffer in the AudioBufferSourceNode + source.buffer = myArrayBuffer; + // connect the AudioBufferSourceNode to the + // destination so we can hear the sound + source.connectNode(audioCtx.destination!); + // start the source playing + source.start(); + + + */ + } + + @override Widget build(BuildContext context) { const textStyle = TextStyle(fontSize: 25); @@ -52,18 +106,7 @@ class _MyAppState extends State { textAlign: TextAlign.center, ), spacerSmall, - FutureBuilder( - future: sumAsyncResult, - builder: (BuildContext context, AsyncSnapshot value) { - final displayValue = - (value.hasData) ? value.data : 'loading'; - return Text( - 'await sumAsync(3, 4) = $displayValue', - style: textStyle, - textAlign: TextAlign.center, - ); - }, - ), + RaisedButton(onPressed: onPressed, child: Text('Make white noise')), ], ), ), diff --git a/example/linux/flutter/generated_plugin_registrant.cc b/example/linux/flutter/generated_plugin_registrant.cc index e71a16d..d44b07e 100644 --- a/example/linux/flutter/generated_plugin_registrant.cc +++ b/example/linux/flutter/generated_plugin_registrant.cc @@ -6,6 +6,10 @@ #include "generated_plugin_registrant.h" +#include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) taudio_waa_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "TaudioWaaPlugin"); + taudio_waa_plugin_register_with_registrar(taudio_waa_registrar); } diff --git a/example/linux/flutter/generated_plugins.cmake b/example/linux/flutter/generated_plugins.cmake index ef8accb..a414121 100644 --- a/example/linux/flutter/generated_plugins.cmake +++ b/example/linux/flutter/generated_plugins.cmake @@ -3,10 +3,10 @@ # list(APPEND FLUTTER_PLUGIN_LIST + taudio_waa ) list(APPEND FLUTTER_FFI_PLUGIN_LIST - taudio_waa ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..1bd7d4a 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,8 @@ import FlutterMacOS import Foundation +import taudio_waa func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + TaudioWaaPlugin.register(with: registry.registrar(forPlugin: "TaudioWaaPlugin")) } diff --git a/example/pubspec.lock b/example/pubspec.lock index 899825f..a618d1f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -74,6 +74,18 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" lints: dependency: transitive description: @@ -109,6 +121,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" sky_engine: dependency: transitive description: flutter @@ -148,7 +167,21 @@ packages: path: ".." relative: true source: path - version: "0.0.2-beta-1+2" + version: "0.0.1-beta.1+6" + taudio_waa_platform_interface: + dependency: transitive + description: + path: "../../taudio_waa_platform_interface" + relative: true + source: path + version: "0.0.1-beta.1+6" + taudio_waa_web: + dependency: transitive + description: + path: "../../taudio_waa_web" + relative: true + source: path + version: "0.0.1" term_glyph: dependency: transitive description: @@ -163,13 +196,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.9" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" vector_math: dependency: transitive description: @@ -178,5 +204,5 @@ packages: source: hosted version: "2.1.2" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=2.0.0" + dart: ">=2.16.0-100.0.dev <3.0.0" + flutter: ">=2.5.0" diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc index 8b6d468..0c1b1c2 100644 --- a/example/windows/flutter/generated_plugin_registrant.cc +++ b/example/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + TaudioWaaPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("TaudioWaaPluginCApi")); } diff --git a/example/windows/flutter/generated_plugins.cmake b/example/windows/flutter/generated_plugins.cmake index 498b676..3176ac1 100644 --- a/example/windows/flutter/generated_plugins.cmake +++ b/example/windows/flutter/generated_plugins.cmake @@ -3,10 +3,10 @@ # list(APPEND FLUTTER_PLUGIN_LIST + taudio_waa ) list(APPEND FLUTTER_FFI_PLUGIN_LIST - taudio_waa ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/example/winuwp/flutter/generated_plugins.cmake b/example/winuwp/flutter/generated_plugins.cmake index 498b676..b93c4c3 100644 --- a/example/winuwp/flutter/generated_plugins.cmake +++ b/example/winuwp/flutter/generated_plugins.cmake @@ -6,7 +6,6 @@ list(APPEND FLUTTER_PLUGIN_LIST ) list(APPEND FLUTTER_FFI_PLUGIN_LIST - taudio_waa ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/ffigen.yaml b/ffigen.yaml index 7b2c72a..b590063 100644 --- a/ffigen.yaml +++ b/ffigen.yaml @@ -17,3 +17,6 @@ preamble: | comments: style: any length: full + +llvm-path: + - '/opt/homebrew/Cellar/llvm/13.0.1_1' diff --git a/ios/.gitignore b/ios/.gitignore new file mode 100644 index 0000000..0c88507 --- /dev/null +++ b/ios/.gitignore @@ -0,0 +1,38 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +profile + +DerivedData/ +build/ +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m + +.generated/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/Generated.xcconfig +/Flutter/ephemeral/ +/Flutter/flutter_export_environment.sh \ No newline at end of file diff --git a/ios/Assets/.gitkeep b/ios/Assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/ios/Classes/TaudioWaaPlugin.h b/ios/Classes/TaudioWaaPlugin.h new file mode 100644 index 0000000..bfb9a01 --- /dev/null +++ b/ios/Classes/TaudioWaaPlugin.h @@ -0,0 +1,4 @@ +#import + +@interface TaudioWaaPlugin : NSObject +@end diff --git a/ios/Classes/TaudioWaaPlugin.mm b/ios/Classes/TaudioWaaPlugin.mm new file mode 100644 index 0000000..dec2d20 --- /dev/null +++ b/ios/Classes/TaudioWaaPlugin.mm @@ -0,0 +1,23 @@ +#import "TaudioWaaPlugin.h" + +extern int add_c(int a, int b); + +@implementation TaudioWaaPlugin ++ (void)registerWithRegistrar:(NSObject*)registrar { + FlutterMethodChannel* channel = [FlutterMethodChannel + methodChannelWithName:@"taudio_waa" + binaryMessenger:[registrar messenger]]; + TaudioWaaPlugin* instance = [[TaudioWaaPlugin alloc] init]; + [registrar addMethodCallDelegate:instance channel:channel]; + //int x = add_c(1,2); +} + +- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { + if ([@"getPlatformVersion" isEqualToString:call.method]) { + result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); + } else { + result(FlutterMethodNotImplemented); + } +} + +@end diff --git a/ios/Classes/taudio_waa.c b/ios/Classes/taudio_waa.c deleted file mode 100644 index 4c85991..0000000 --- a/ios/Classes/taudio_waa.c +++ /dev/null @@ -1,3 +0,0 @@ -// Relative import to be able to reuse the C sources. -// See the comment in ../{projectName}}.podspec for more information. -#include "../../src/taudio_waa.c" diff --git a/macos/Classes/taudio_waa.c b/ios/Classes/taudio_waa.cpp.sav similarity index 96% rename from macos/Classes/taudio_waa.c rename to ios/Classes/taudio_waa.cpp.sav index 4c85991..d19f920 100644 --- a/macos/Classes/taudio_waa.c +++ b/ios/Classes/taudio_waa.cpp.sav @@ -1,3 +1,4 @@ // Relative import to be able to reuse the C sources. // See the comment in ../{projectName}}.podspec for more information. #include "../../src/taudio_waa.c" +add_c diff --git a/ios/taudio_waa.podspec b/ios/taudio_waa.podspec index a335a28..3752d7d 100644 --- a/ios/taudio_waa.podspec +++ b/ios/taudio_waa.podspec @@ -5,24 +5,20 @@ Pod::Spec.new do |s| s.name = 'taudio_waa' s.version = '0.0.1' - s.summary = 'A Flutter wrapper around web_audio_api_rs' + s.summary = 'A new Flutter plugin project.' s.description = <<-DESC -A Flutter wrapper around web_audio_api_rs +A new Flutter plugin project. DESC s.homepage = 'http://example.com' s.license = { :file => '../LICENSE' } s.author = { 'Your Company' => 'email@example.com' } - - # This will ensure the source files in Classes/ are included in the native - # builds of apps using this FFI plugin. Podspec does not support relative - # paths, so Classes contains a forwarder C file that relatively imports - # `../src/*` so that the C sources can be shared among all target platforms. s.source = { :path => '.' } s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.platform = :ios, '14.0' + s.platform = :ios, '9.0' # Flutter.framework does not contain a i386 slice. s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } - s.swift_version = '5.0' + #s.dependency '../../t' end diff --git a/lib/public/web_audio.dart b/lib/public/web_audio.dart deleted file mode 100644 index 19c607d..0000000 --- a/lib/public/web_audio.dart +++ /dev/null @@ -1,1885 +0,0 @@ -// web_audio.dart -// -// Created by larpoux on 19/02/2022. -// -/* - * Copyright 2022 Canardoux. - * - * This file is part of the τDio project. - * - * τDio is free software: you can redistribute it and/or modify - * it under the terms of the Mozilla Public License version 2 (MPL2.0), - * as published by the Mozilla organization. - * - * τDio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * MPL General Public License for more details. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -// This source is originated from the Flutter Web Audio Library. -// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -/// --------------------------------------------------------------------------------------------------- -/// A Web Audio API port on Flutter Mobiles and Flutter Desktop. -/// This library is a copy and paste from the Flutter Web Audio Library interface, -/// but runs under Flutter Mobiles and Flutter Desktop instead of Flutter Web. -/// The goal is to be able to execute a Web App under iOS/Android with just an update -/// of the `import` statement. -/// Note : if we have to deviate from the original interface, those divergence will -/// be explicitly list here : -/// - AudioParamMap is a class specific on Flutter and does not have any correspondence in the W3C Recommandation -/// - AudioTrack is a class specific on Flutter and does not have any correspondence in the W3C Recommandation -/// - AudioTrackList is a class specific on Flutter and does not have any correspondence in the W3C Recommandation -/// - ScriptProcessorNode is a class specific on Flutter and does not have any correspondence in the W3C Recommandation -/// - The W3C [AudioContextOptions](https://www.w3.org/TR/webaudio/#AudioContextOptions) class is not implemented -/// - The W3C [AudioNodeOptions](https://www.w3.org/TR/webaudio/#AudioNodeOptions) class is not implemented -/// - The W3C [AudioWorklet](https://www.w3.org/TR/webaudio/#AudioWorklet) class is not implemented -/// - The W3C [MediaStreamTrackAudioSourceNode](https://www.w3.org/TR/webaudio/#MediaStreamTrackAudioSourceNode) class is not implemented -/// ---------------------------------------------------------------------------------------------------- -/// {@category WAA} -library taudio.web_audio; - -//import 'dart:async'; -//import 'dart:collection' hide LinkedList, LinkedListEntry; -//import 'dart:_internal' show FixedLengthListMixin; -//import 'dart:_native_typed_data'; -//import 'dart:typed_data'; -//import 'dart:_foreign_helper' show JS; -//import 'dart:_interceptors' show JavaScriptObject; - - -/// ---------------------------------------------------------------------------------------------------- -/// # AnalyserNode -/// - [see W3C Recommandation](https://www.w3.org/TR/webaudio/#AnalyserNode) -/// - [see Mozilla documentation](https://www.w3.org/TR/webaudio/#AnalyserNode) -/// ---------------------------------------------------------------------------------------------------- -/// The AnalyserNode interface represents a node able to provide real-time frequency and time-domain analysis information. -/// It is an AudioNode that passes the audio stream unchanged from the input to the output, -/// but allows you to take the generated data, process it, and create audio visualizations. -class AnalyserNode extends AudioNode { - // To suppress missing implicit constructor warnings. - factory AnalyserNode._() { - throw new UnsupportedError("Not supported"); - } - - factory AnalyserNode(BaseAudioContext context, [Map? options]) { - if (options != null) { - var options_1 = convertDartToNative_Dictionary(options); - return AnalyserNode._create_1(context, options_1); - } - return AnalyserNode._create_2(context); - } - static AnalyserNode _create_1(context, options) => - super(ctx, LabSound().createAnalyserNodeOptions(ctx.pointer, options)); - static AnalyserNode _create_2(context) => - super(ctx, LabSound().createAnalyserNode(ctx.pointer)); - - setFftSize(int fftSize) => LabSound().AnalyserNode_setFftSize(this.nodeId, this.ctx.pointer, fftSize); - int get fftSize => LabSound().AnalyserNode_fftSize(this.nodeId); - - int get frequencyBinCount => LabSound().AnalyserNode_frequencyBinCount(this.nodeId); - - setMinDecibels(double k) => LabSound().AnalyserNode_setMinDecibels(this.nodeId, k); - int get minDecibels => LabSound().AnalyserNode_minDecibels(this.nodeId); - - setMaxDecibels(double k) => LabSound().AnalyserNode_setMaxDecibels(this.nodeId, k); - int get maxDecibels => LabSound().AnalyserNode_maxDecibels(this.nodeId); - - setSmoothingTimeConstant(double k) => LabSound().AnalyserNode_setSmoothingTimeConstant(this.nodeId, k); - int get smoothingTimeConstant => LabSound().AnalyserNode_smoothingTimeConstant(this.nodeId); - - AnalyserBuffer? floatFrequencyData; - AnalyserBuffer getFloatFrequencyData() { - floatFrequencyData ??= AnalyserBuffer(frequencyBinCount); - if(floatFrequencyData!.ptr == null) throw "floatFrequencyData ptr is null"; - LabSound().AnalyserNode_getFloatFrequencyData(this.nodeId, floatFrequencyData!.ptr! as Pointer); - return floatFrequencyData!; - } - - AnalyserBuffer? byteFrequencyData; - AnalyserBuffer getByteFrequencyData({resample = false}) { - byteFrequencyData ??= AnalyserBuffer(frequencyBinCount); - if(byteFrequencyData!.ptr == null) throw "byteFrequencyData ptr is null"; - LabSound().AnalyserNode_getByteFrequencyData(this.nodeId, byteFrequencyData!.ptr! as Pointer, resample ? 1 : 0); - return byteFrequencyData!; - } - - - AnalyserBuffer? floatTimeDomainData; - AnalyserBuffer getFloatTimeDomainData() { - floatTimeDomainData ??= AnalyserBuffer(frequencyBinCount); - if(floatTimeDomainData!.ptr == null) throw "floatTimeDomainData ptr is null"; - LabSound().AnalyserNode_getFloatTimeDomainData(this.nodeId, floatTimeDomainData!.ptr! as Pointer); - return floatTimeDomainData!; - } - - AnalyserBuffer? byteTimeDomainData; - AnalyserBuffer getByteTimeDomainData() { - byteTimeDomainData ??= AnalyserBuffer(frequencyBinCount); - if(byteTimeDomainData!.ptr == null) throw "byteTimeDomainData ptr is null"; - LabSound().AnalyserNode_getByteTimeDomainData(this.nodeId, byteTimeDomainData!.ptr! as Pointer); - return byteTimeDomainData!; - } - - @override - dispose() { - floatFrequencyData?.free(); - byteFrequencyData?.free(); - floatTimeDomainData?.free(); - byteTimeDomainData?.free(); - super.dispose(); - } - -} - -/// ---------------------------------------------------------------------------------------------------- -/// # AudioBuffer -/// - [see W3C Recommandation](https://www.w3.org/TR/webaudio/#AudioBuffer) -/// - [see Mozilla documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer) -/// ---------------------------------------------------------------------------------------------------- -/// The AudioBuffer interface represents a short audio asset residing in memory, -/// created from an audio file using the AudioContext.decodeAudioData() method, or from raw data using AudioContext.createBuffer(). -/// Once put into an AudioBuffer, the audio can then be played by being passed into an AudioBufferSourceNode. -/// -/// Objects of these types are designed to hold small audio snippets, typically less than 45 s. -/// For longer sounds, objects implementing the MediaElementAudioSourceNode are more suitable. -/// The buffer contains data in the following format: non-interleaved IEEE754 32-bit linear PCM with a nominal range between -1 and +1, -/// that is, a 32-bit floating point buffer, with each sample between -1.0 and 1.0. If the AudioBuffer has multiple channels, -/// they are stored in separate buffers.class AudioBuffer extends JavaScriptObject { -class AudioBuffer extends JavaScriptObject { - /* - // To suppress missing implicit constructor warnings. - factory AudioBuffer._() { - throw new UnsupportedError("Not supported"); - } - - factory AudioBuffer(Map options) { - var options_1 = convertDartToNative_Dictionary(options); - return AudioBuffer._create_1(options_1); - } - static AudioBuffer _create_1(options) => - JS('AudioBuffer', 'new AudioBuffer(#)', options); - - num? get duration native; - - int? get length native; - - int? get numberOfChannels native; - - num? get sampleRate native; - - void copyFromChannel(Float32List destination, int channelNumber, - [int? startInChannel]) native; - - void copyToChannel(Float32List source, int channelNumber, - [int? startInChannel]) native; - - Float32List getChannelData(int channelIndex) native; - - */ -} - -/// ---------------------------------------------------------------------------------------------------- -/// # AudioBufferSourceNode -/// - [see W3C Recommandation](https://www.w3.org/TR/webaudio/#AudioBufferSourceNode) -/// - [see Mozilla documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode) -/// ---------------------------------------------------------------------------------------------------- -/// This interface represents an audio source from an in-memory audio asset in an AudioBuffer. -/// It is useful for playing audio assets which require a high degree of scheduling flexibility and accuracy. -/// If sample-accurate playback of network- or disk-backed assets is required, an implementer should use AudioWorkletNode to implement playback. -/// -/// The start() method is used to schedule when sound playback will happen. -/// The start() method may not be issued multiple times. -/// The playback will stop automatically when the buffer’s audio data has been completely played (if the loop attribute is false), -/// or when the stop() method has been called and the specified time has been reached. Please see more details in the start() and stop() descriptions. -/// -/// - numberOfInputs 0 -/// - numberOfOutputs 1 -/// - channelCount 2 -/// - channelCountMode "max" -/// - channelInterpretation "speakers" -/// - tail-time No -/// -/// The number of channels of the output equals the number of channels of the AudioBuffer assigned to the buffer attribute, -/// or is one channel of silence if buffer is null. -/// -/// In addition, if the buffer has more than one channel, then the AudioBufferSourceNode output must change -/// to a single channel of silence at the beginning of a render quantum after the time at which any one of the following conditions holds: -/// - the end of the buffer has been reached; -/// - the duration has been reached; -/// - the stop time has been reached. -/// -/// A playhead position for an AudioBufferSourceNode is defined as any quantity representing a time offset in seconds, -/// relative to the time coordinate of the first sample frame in the buffer. -/// Such values are to be considered independently from the node’s playbackRate and detune parameters. -/// In general, playhead positions may be subsample-accurate and need not refer to exact sample frame positions. -/// They may assume valid values between 0 and the duration of the buffer. -/// -/// The playbackRate and detune attributes form a compound parameter. They are used together to determine a computedPlaybackRate value: -/// -/// computedPlaybackRate(t) = playbackRate(t) * pow(2, detune(t) / 1200) -/// The nominal range for this compound parameter is (−∞,∞). -/// -/// AudioBufferSourceNodes are created with an internal boolean slot `buffer set`, initially set to false. -class AudioBufferSourceNode extends AudioScheduledSourceNode { - /* - // To suppress missing implicit constructor warnings. - factory AudioBufferSourceNode._() { - throw new UnsupportedError("Not supported"); - } - - factory AudioBufferSourceNode(BaseAudioContext context, [Map? options]) { - if (options != null) { - var options_1 = convertDartToNative_Dictionary(options); - return AudioBufferSourceNode._create_1(context, options_1); - } - return AudioBufferSourceNode._create_2(context); - } - static AudioBufferSourceNode _create_1(context, options) => JS( - 'AudioBufferSourceNode', - 'new AudioBufferSourceNode(#,#)', - context, - options); - static AudioBufferSourceNode _create_2(context) => - JS('AudioBufferSourceNode', 'new AudioBufferSourceNode(#)', context); - - AudioBuffer? get buffer native; - - set buffer(AudioBuffer? value) native; - - AudioParam? get detune native; - - bool? get loop native; - - set loop(bool? value) native; - - num? get loopEnd native; - - set loopEnd(num? value) native; - - num? get loopStart native; - - set loopStart(num? value) native; - - AudioParam? get playbackRate native; - - void start([num? when, num? grainOffset, num? grainDuration]) native; - - */ -} - -/// ---------------------------------------------------------------------------------------------------- -/// # AudioContext -/// - [see W3C Recommandation](https://www.w3.org/TR/webaudio/#AudioContext) -/// - [see Mozilla documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) -/// ---------------------------------------------------------------------------------------------------- -/// The AudioContext interface represents an audio-processing graph built from audio modules linked together, -/// each represented by an AudioNode. -/// -/// An audio context controls both the creation of the nodes it contains and the execution of the audio processing, -/// or decoding. -/// You need to create an AudioContext before you do anything else, as everything happens inside a context. -/// It's recommended to create one AudioContext and reuse it instead of initializing a new one each time, -/// and it's OK to use a single AudioContext for several different audio sources and pipeline concurrently. -class AudioContext extends BaseAudioContext { - /* - // To suppress missing implicit constructor warnings. - factory AudioContext._() { - throw new UnsupportedError("Not supported"); - } - - /// Checks if this type is supported on the current platform. - static bool get supported => - JS('bool', '!!(window.AudioContext || window.webkitAudioContext)'); - - num? get baseLatency native; - - Future close() => promiseToFuture(JS("", "#.close()", this)); - - Map getOutputTimestamp() { - return convertNativeToDart_Dictionary(_getOutputTimestamp_1())!; - } - - @JSName('getOutputTimestamp') - _getOutputTimestamp_1() native; - - Future suspend() => promiseToFuture(JS("", "#.suspend()", this)); - - factory AudioContext() => JS('AudioContext', - 'new (window.AudioContext || window.webkitAudioContext)()'); - - GainNode createGain() { - if (JS('bool', '#.createGain !== undefined', this)) { - return JS('GainNode', '#.createGain()', this); - } else { - return JS('GainNode', '#.createGainNode()', this); - } - } - - ScriptProcessorNode createScriptProcessor( - [int? bufferSize, - int? numberOfInputChannels, - int? numberOfOutputChannels]) { - var function = JS( - '=Object', - '#.createScriptProcessor || ' - '#.createJavaScriptNode', - this, - this); - if (numberOfOutputChannels != null) { - return JS('ScriptProcessorNode', '#.call(#, #, #, #)', function, this, - bufferSize, numberOfInputChannels, numberOfOutputChannels); - } else if (numberOfInputChannels != null) { - return JS('ScriptProcessorNode', '#.call(#, #, #)', function, this, - bufferSize, numberOfInputChannels); - } else if (bufferSize != null) { - return JS( - 'ScriptProcessorNode', '#.call(#, #)', function, this, bufferSize); - } else { - return JS('ScriptProcessorNode', '#.call(#)', function, this); - } - } - - Future decodeAudioData(ByteBuffer audioData, - [DecodeSuccessCallback? successCallback, - DecodeErrorCallback? errorCallback]) { - // Both callbacks need to be provided if they're being used. - assert((successCallback == null) == (errorCallback == null)); - // `decodeAudioData` can exist either in the older callback syntax or the - // newer `Promise`-based syntax that also accepts callbacks. In the former, - // we synthesize a `Future` to be consistent. - // For more details: - // https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/decodeAudioData - // https://www.w3.org/TR/webaudio/#dom-baseaudiocontext-decodeaudiodata - final completer = Completer(); - var errorInCallbackIsNull = false; - - void success(AudioBuffer decodedData) { - completer.complete(decodedData); - successCallback!.call(decodedData); - } - - final nullErrorString = - '[AudioContext.decodeAudioData] completed with a null error.'; - - void error(DomException? error) { - // Safari has a bug where it may return null for the error callback. In - // the case where the Safari version still returns a `Promise` and the - // error is not null after the `Promise` is finished, the error callback - // is called instead in the `Promise`'s `catch` block. Otherwise, and in - // the case where a `Promise` is not returned by the API at all, the - // callback never gets called (for backwards compatibility, it can not - // accept null). Instead, the `Future` completes with a custom string, - // indicating that null was given. - // https://github.com/mdn/webaudio-examples/issues/5 - if (error != null) { - // Note that we `complete` and not `completeError`. This is to make sure - // that errors in the `Completer` are not thrown if the call gets back - // a `Promise`. - completer.complete(error); - errorCallback!.call(error); - } else { - completer.complete(nullErrorString); - errorInCallbackIsNull = true; - } - } - - var decodeResult; - if (successCallback == null) { - decodeResult = - JS("creates:AudioBuffer;", "#.decodeAudioData(#)", this, audioData); - } else { - decodeResult = JS( - "creates:AudioBuffer;", - "#.decodeAudioData(#, #, #)", - this, - audioData, - convertDartClosureToJS(success, 1), - convertDartClosureToJS(error, 1)); - } - - if (decodeResult != null) { - // Promise-based syntax. - return promiseToFuture(decodeResult).catchError((error) { - // If the error was null in the callback, but no longer is now that the - // `Promise` is finished, call the error callback. If it's still null, - // throw the error string. This is to handle the aforementioned bug in - // Safari. - if (errorInCallbackIsNull) { - if (error != null) { - errorCallback?.call(error); - } else { - throw nullErrorString; - } - } - throw error; - }); - } - - // Callback-based syntax. We use the above completer to synthesize a - // `Future` from the callback values. Since we don't use `completeError` - // above, `then` is used to simulate an error. - return completer.future.then((value) { - if (value is AudioBuffer) return value; - throw value; - }); - } - - */ -} - -/// ---------------------------------------------------------------------------------------------------- -/// # AudioDestinationNode -/// - [see W3C Recommandation](https://www.w3.org/TR/webaudio/#AudioDestinationNode) -/// - [see Mozilla documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioDestinationNode) -/// ---------------------------------------------------------------------------------------------------- -/// The AudioDestinationNode interface represents the end destination of an audio graph in a given context — usually the speakers of your device. -/// It can also be the node that will "record" the audio data when used with an OfflineAudioContext. -/// -/// AudioDestinationNode has no output (as it is the output, no more AudioNode can be linked after it in the audio graph) and one input. -/// The number of channels in the input must be between 0 and the maxChannelCount value or an exception is raised. -/// -/// The AudioDestinationNode of a given AudioContext can be retrieved using the AudioContext.destination property. -/// -/// - Number of inputs 1 -/// - Number of outputs 0 -/// - Channel count mode "explicit" -/// - Channel count 2 -/// - Channel interpretation "speakers" -class AudioDestinationNode extends AudioNode { - // To suppress missing implicit constructor warnings. - factory AudioDestinationNode._() { - throw new UnsupportedError("Not supported"); - } - - int? get maxChannelCount native; -} - -/// ---------------------------------------------------------------------------------------------------- -/// # AudioListener -/// - [see W3C Recommandation](https://www.w3.org/TR/webaudio/#AudioListener) -/// - see Mozilla documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioListener) -/// ---------------------------------------------------------------------------------------------------- -/// This interface represents the position and orientation of the person listening to the audio scene. -/// All PannerNode objects spatialize in relation to the BaseAudioContext's listener. -/// See § 6 Spatialization/Panning for more details about spatialization. -/// -/// The positionX, positionY, and positionZ parameters represent the location of the listener in 3D Cartesian coordinate space. -/// PannerNode objects use this position relative to individual audio sources for spatialization. -/// -/// The forwardX, forwardY, and forwardZ parameters represent a direction vector in 3D space. -/// Both a forward vector and an up vector are used to determine the orientation of the listener. -/// In simple human terms, the forward vector represents which direction the person’s nose is pointing. -/// The up vector represents the direction the top of a person’s head is pointing. These two vectors are expected to be linearly independent. -/// For normative requirements of how these values are to be interpreted, see the § 6 Spatialization/Panning section. -class AudioListener extends JavaScriptObject { - // To suppress missing implicit constructor warnings. - factory AudioListener._() { - throw new UnsupportedError("Not supported"); - } - - AudioParam? get forwardX native; - - AudioParam? get forwardY native; - - AudioParam? get forwardZ native; - - AudioParam? get positionX native; - - AudioParam? get positionY native; - - AudioParam? get positionZ native; - - AudioParam? get upX native; - - AudioParam? get upY native; - - AudioParam? get upZ native; - - void setOrientation(num x, num y, num z, num xUp, num yUp, num zUp) native; - - void setPosition(num x, num y, num z) native; -} - -/// ---------------------------------------------------------------------------------------------------- -/// # AudioNode -/// - [see W3C Recommandation](https://www.w3.org/TR/webaudio/#AudioNode) -/// - [see Mozilla documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioNode) -/// ---------------------------------------------------------------------------------------------------- -/// The AudioNode interface is a generic interface for representing an audio processing module. -/// -/// Examples include: -/// - an audio source (e.g. an HTML