@moodbar/native 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +193 -0
- package/LICENSE-MIT +21 -0
- package/README.md +30 -0
- package/android/build.gradle +35 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/include/moodbar_native_ffi.h +66 -0
- package/android/src/main/java/expo/modules/moodbarnative/MoodbarNativeModule.kt +96 -0
- package/android/src/main/java/expo/modules/moodbarnative/NativeBridge.kt +13 -0
- package/android/src/main/jniLibs/.gitkeep +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libmoodbar_native_ffi.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libmoodbar_native_ffi.so +0 -0
- package/android/src/main/jniLibs/x86/libmoodbar_native_ffi.so +0 -0
- package/android/src/main/jniLibs/x86_64/libmoodbar_native_ffi.so +0 -0
- package/expo-module.config.json +9 -0
- package/index.d.ts +62 -0
- package/index.js +177 -0
- package/ios/MoodbarNativeFFI.xcframework/Info.plist +48 -0
- package/ios/MoodbarNativeFFI.xcframework/ios-arm64/Headers/MoodbarNativeFFI.h +1 -0
- package/ios/MoodbarNativeFFI.xcframework/ios-arm64/Headers/moodbar_native_ffi.h +66 -0
- package/ios/MoodbarNativeFFI.xcframework/ios-arm64/libmoodbar_native_ffi.a +0 -0
- package/ios/MoodbarNativeFFI.xcframework/ios-arm64_x86_64-simulator/Headers/MoodbarNativeFFI.h +1 -0
- package/ios/MoodbarNativeFFI.xcframework/ios-arm64_x86_64-simulator/Headers/moodbar_native_ffi.h +66 -0
- package/ios/MoodbarNativeFFI.xcframework/ios-arm64_x86_64-simulator/libmoodbar_native_ffi_simulator.a +0 -0
- package/ios/MoodbarNativeModule.swift +129 -0
- package/ios/include/MoodbarNativeFFI.h +1 -0
- package/ios/include/moodbar_native_ffi.h +66 -0
- package/moodbar-native.podspec +30 -0
- package/package.json +42 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and its Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a
|
|
80
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
81
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
82
|
+
or contributory patent infringement, then any patent licenses
|
|
83
|
+
granted to You under this License for that Work shall terminate
|
|
84
|
+
as of the date such litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or
|
|
92
|
+
Derivative Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or as an addendum to
|
|
115
|
+
the NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the
|
|
117
|
+
License.
|
|
118
|
+
|
|
119
|
+
You may add Your own license statement for Your modifications and
|
|
120
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
121
|
+
publish, distribute, sublicense, and/or sell copies of the Work,
|
|
122
|
+
and to permit persons to whom the Work is furnished to do so,
|
|
123
|
+
subject to the following conditions:
|
|
124
|
+
|
|
125
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
126
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
127
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
128
|
+
this License, without any additional terms or conditions.
|
|
129
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
130
|
+
the terms of any separate license agreement you may have executed
|
|
131
|
+
with Licensor regarding such Contributions.
|
|
132
|
+
|
|
133
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
134
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
135
|
+
except as required for reasonable and customary use in describing the
|
|
136
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
137
|
+
|
|
138
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
139
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
140
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
141
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
142
|
+
implied, including, without limitation, any warranties or conditions
|
|
143
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
144
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
145
|
+
appropriateness of using or reproducing the Work and assume any
|
|
146
|
+
risks associated with Your exercise of permissions under this License.
|
|
147
|
+
|
|
148
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
149
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
150
|
+
unless required by applicable law (such as deliberate and grossly
|
|
151
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
152
|
+
liable to You for damages, including any direct, indirect, special,
|
|
153
|
+
incidental, or exemplary damages of any character arising as a
|
|
154
|
+
result of this License or out of the use or inability to use the
|
|
155
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
156
|
+
work stoppage, computer failure or malfunction, or all other
|
|
157
|
+
commercial damages or losses), even if such Contributor has been
|
|
158
|
+
advised of the possibility of such damages.
|
|
159
|
+
|
|
160
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
161
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
162
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
163
|
+
or other liability obligations and/or rights consistent with this
|
|
164
|
+
License. However, in accepting such obligations, You may act only
|
|
165
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
166
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
167
|
+
defend, and hold each Contributor harmless for any liability
|
|
168
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
169
|
+
of your accepting any such warranty or additional liability.
|
|
170
|
+
|
|
171
|
+
END OF TERMS AND CONDITIONS
|
|
172
|
+
|
|
173
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
174
|
+
|
|
175
|
+
To apply the Apache License to your work, attach the following
|
|
176
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
177
|
+
replaced with your own identifying information. (Don't include
|
|
178
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
179
|
+
comment syntax for the format in question.
|
|
180
|
+
|
|
181
|
+
Copyright 2026 Gil Desmarais
|
|
182
|
+
|
|
183
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
184
|
+
you may not use this file except in compliance with the License.
|
|
185
|
+
You may obtain a copy of the License at
|
|
186
|
+
|
|
187
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
188
|
+
|
|
189
|
+
Unless required by applicable law or agreed to in writing, software
|
|
190
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
191
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
192
|
+
See the License for the specific language governing permissions and
|
|
193
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gil Desmarais
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @moodbar/native
|
|
2
|
+
|
|
3
|
+
React Native bindings for Moodbar analysis and rendering (PNG/SVG) on iOS and Android.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @moodbar/native
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { analyze, render, generate } from "@moodbar/native";
|
|
15
|
+
|
|
16
|
+
const analysis = await analyze({ uri: "file:///path/to/input.mp3" });
|
|
17
|
+
const pngBytes = await render(analysis, "png", { width: 1200, height: 96 });
|
|
18
|
+
const svg = await render(analysis, "svg", { width: 1200, height: 96, shape: "Waveform" });
|
|
19
|
+
|
|
20
|
+
await analysis.dispose();
|
|
21
|
+
|
|
22
|
+
const fromMemory = await generate(
|
|
23
|
+
{ bytes: new Uint8Array([/* encoded audio bytes */]) },
|
|
24
|
+
"png"
|
|
25
|
+
);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`analyze({ uri })` accepts:
|
|
29
|
+
- iOS: file paths and `file://` URIs
|
|
30
|
+
- Android: file paths, `file://` URIs, and `content://` URIs
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
3
|
+
|
|
4
|
+
group = 'expo.modules.moodbarnative'
|
|
5
|
+
version = '0.0.0'
|
|
6
|
+
|
|
7
|
+
def safeExtGet(prop, fallback) {
|
|
8
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
apply from: new File(project(':expo-modules-core').projectDir, 'ExpoModulesCorePlugin.gradle')
|
|
12
|
+
|
|
13
|
+
android {
|
|
14
|
+
namespace "expo.modules.moodbarnative"
|
|
15
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 35)
|
|
16
|
+
|
|
17
|
+
defaultConfig {
|
|
18
|
+
minSdkVersion safeExtGet('minSdkVersion', 24)
|
|
19
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 35)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
sourceSets {
|
|
23
|
+
main {
|
|
24
|
+
jniLibs.srcDirs = ['src/main/jniLibs']
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
lintOptions {
|
|
29
|
+
abortOnError false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dependencies {
|
|
34
|
+
implementation project(':expo-modules-core')
|
|
35
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#ifndef MOODBAR_NATIVE_FFI_H
|
|
2
|
+
#define MOODBAR_NATIVE_FFI_H
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
/* This file is generated by cbindgen. */
|
|
7
|
+
|
|
8
|
+
#include <stdarg.h>
|
|
9
|
+
#include <stdbool.h>
|
|
10
|
+
#include <stddef.h>
|
|
11
|
+
#include <stdint.h>
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
|
|
14
|
+
enum MoodbarNativeStatus {
|
|
15
|
+
Ok = 0,
|
|
16
|
+
InvalidArgument = 1,
|
|
17
|
+
NotFound = 2,
|
|
18
|
+
Internal = 3,
|
|
19
|
+
};
|
|
20
|
+
typedef int32_t MoodbarNativeStatus;
|
|
21
|
+
|
|
22
|
+
typedef struct MoodbarNativeAnalysisSummary {
|
|
23
|
+
uint64_t handle;
|
|
24
|
+
uint32_t frame_count;
|
|
25
|
+
uint32_t channel_count;
|
|
26
|
+
} MoodbarNativeAnalysisSummary;
|
|
27
|
+
|
|
28
|
+
typedef struct MoodbarNativeBuffer {
|
|
29
|
+
uint8_t *ptr;
|
|
30
|
+
size_t len;
|
|
31
|
+
size_t cap;
|
|
32
|
+
} MoodbarNativeBuffer;
|
|
33
|
+
|
|
34
|
+
MoodbarNativeStatus moodbar_native_analysis_from_path(const char *path,
|
|
35
|
+
const char *options_json,
|
|
36
|
+
struct MoodbarNativeAnalysisSummary *out_summary);
|
|
37
|
+
|
|
38
|
+
MoodbarNativeStatus moodbar_native_analysis_from_bytes(const uint8_t *bytes,
|
|
39
|
+
size_t bytes_len,
|
|
40
|
+
const char *extension,
|
|
41
|
+
const char *options_json,
|
|
42
|
+
struct MoodbarNativeAnalysisSummary *out_summary);
|
|
43
|
+
|
|
44
|
+
MoodbarNativeStatus moodbar_native_analysis_dispose(uint64_t handle);
|
|
45
|
+
|
|
46
|
+
MoodbarNativeStatus moodbar_native_render_svg(uint64_t handle,
|
|
47
|
+
const char *options_json,
|
|
48
|
+
struct MoodbarNativeBuffer *out_svg_utf8);
|
|
49
|
+
|
|
50
|
+
MoodbarNativeStatus moodbar_native_render_png(uint64_t handle,
|
|
51
|
+
const char *options_json,
|
|
52
|
+
struct MoodbarNativeBuffer *out_png);
|
|
53
|
+
|
|
54
|
+
MoodbarNativeStatus moodbar_native_last_error(struct MoodbarNativeBuffer *out_message_utf8);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Frees a heap buffer previously returned by this library.
|
|
58
|
+
*
|
|
59
|
+
* # Safety
|
|
60
|
+
*
|
|
61
|
+
* `buffer` must be a valid, writable pointer obtained from this library, and must not be
|
|
62
|
+
* freed more than once.
|
|
63
|
+
*/
|
|
64
|
+
void moodbar_native_buffer_free(struct MoodbarNativeBuffer *buffer);
|
|
65
|
+
|
|
66
|
+
#endif /* MOODBAR_NATIVE_FFI_H */
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
package expo.modules.moodbarnative
|
|
2
|
+
|
|
3
|
+
import android.net.Uri
|
|
4
|
+
import android.util.Base64
|
|
5
|
+
import expo.modules.kotlin.exception.CodedException
|
|
6
|
+
import expo.modules.kotlin.modules.Module
|
|
7
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
8
|
+
import org.json.JSONObject
|
|
9
|
+
|
|
10
|
+
class MoodbarNativeModule : Module() {
|
|
11
|
+
override fun definition() = ModuleDefinition {
|
|
12
|
+
Name("MoodbarNative")
|
|
13
|
+
|
|
14
|
+
AsyncFunction("analyzeFromUri") { uri: String, optionsJson: String ->
|
|
15
|
+
val payload = parseResponse(analyzeUri(uri, optionsJson))
|
|
16
|
+
mapOf(
|
|
17
|
+
"handle" to payload.getLong("handle"),
|
|
18
|
+
"frameCount" to payload.getInt("frameCount"),
|
|
19
|
+
"channelCount" to payload.getInt("channelCount"),
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
AsyncFunction("analyzeFromBase64") { base64: String, extension: String?, optionsJson: String ->
|
|
24
|
+
val bytes = try {
|
|
25
|
+
Base64.decode(base64, Base64.DEFAULT)
|
|
26
|
+
} catch (error: IllegalArgumentException) {
|
|
27
|
+
throw CodedException("ERR_INVALID_BASE64", "input bytes were not valid base64", error)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
val payload = parseResponse(NativeBridge.nativeAnalyzeFromBytes(bytes, extension, optionsJson))
|
|
31
|
+
mapOf(
|
|
32
|
+
"handle" to payload.getLong("handle"),
|
|
33
|
+
"frameCount" to payload.getInt("frameCount"),
|
|
34
|
+
"channelCount" to payload.getInt("channelCount"),
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
AsyncFunction("renderSvg") { handle: Long, optionsJson: String ->
|
|
39
|
+
val payload = parseResponse(NativeBridge.nativeRenderSvg(handle, optionsJson))
|
|
40
|
+
payload.getString("svg")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
AsyncFunction("renderPng") { handle: Long, optionsJson: String ->
|
|
44
|
+
val payload = parseResponse(NativeBridge.nativeRenderPng(handle, optionsJson))
|
|
45
|
+
payload.getString("pngBase64")
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
AsyncFunction("disposeAnalysis") { handle: Long ->
|
|
49
|
+
parseResponse(NativeBridge.nativeDisposeAnalysis(handle))
|
|
50
|
+
null
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private fun analyzeUri(uri: String, optionsJson: String): String {
|
|
55
|
+
val parsed = Uri.parse(uri)
|
|
56
|
+
return when (parsed.scheme?.lowercase()) {
|
|
57
|
+
"content" -> {
|
|
58
|
+
val context = appContext.reactContext
|
|
59
|
+
?: throw CodedException("ERR_CONTEXT_UNAVAILABLE", "React context is unavailable for content URI decode")
|
|
60
|
+
val bytes = context.contentResolver.openInputStream(parsed)?.use { it.readBytes() }
|
|
61
|
+
?: throw CodedException("ERR_URI_READ_FAILED", "could not read content URI: $uri")
|
|
62
|
+
val extension = inferExtension(parsed)
|
|
63
|
+
NativeBridge.nativeAnalyzeFromBytes(bytes, extension, optionsJson)
|
|
64
|
+
}
|
|
65
|
+
null, "", "file" -> {
|
|
66
|
+
val path = parsed.path
|
|
67
|
+
?: throw CodedException("ERR_INVALID_URI", "file URI is missing a path: $uri")
|
|
68
|
+
NativeBridge.nativeAnalyzeFromUri(path, optionsJson)
|
|
69
|
+
}
|
|
70
|
+
else -> throw CodedException(
|
|
71
|
+
"ERR_UNSUPPORTED_URI_SCHEME",
|
|
72
|
+
"unsupported URI scheme '${parsed.scheme}': only file:// and content:// are supported on Android"
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private fun inferExtension(uri: Uri): String? {
|
|
78
|
+
val segment = uri.lastPathSegment ?: return null
|
|
79
|
+
val idx = segment.lastIndexOf('.')
|
|
80
|
+
if (idx < 0 || idx == segment.length - 1) {
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
return segment.substring(idx + 1).lowercase()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private fun parseResponse(raw: String): JSONObject {
|
|
87
|
+
val payload = JSONObject(raw)
|
|
88
|
+
if (!payload.optBoolean("ok", false)) {
|
|
89
|
+
throw CodedException(
|
|
90
|
+
"ERR_MOODBAR_NATIVE",
|
|
91
|
+
payload.optString("error", "native moodbar call failed")
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
return payload
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package expo.modules.moodbarnative
|
|
2
|
+
|
|
3
|
+
object NativeBridge {
|
|
4
|
+
init {
|
|
5
|
+
System.loadLibrary("moodbar_native_ffi")
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
external fun nativeAnalyzeFromUri(uri: String, optionsJson: String): String
|
|
9
|
+
external fun nativeAnalyzeFromBytes(bytes: ByteArray, extension: String?, optionsJson: String): String
|
|
10
|
+
external fun nativeRenderSvg(handle: Long, optionsJson: String): String
|
|
11
|
+
external fun nativeRenderPng(handle: Long, optionsJson: String): String
|
|
12
|
+
external fun nativeDisposeAnalysis(handle: Long): String
|
|
13
|
+
}
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type NormalizeMode = "PerChannelPeak" | "GlobalPeak";
|
|
2
|
+
export type DetectionMode = "SpectralEnergy" | "SpectralFlux";
|
|
3
|
+
export type SvgShape = "Strip" | "Waveform";
|
|
4
|
+
|
|
5
|
+
export interface AnalyzeOptions {
|
|
6
|
+
fft_size?: number;
|
|
7
|
+
low_cut_hz?: number;
|
|
8
|
+
mid_cut_hz?: number;
|
|
9
|
+
normalize_mode?: NormalizeMode;
|
|
10
|
+
deterministic_floor?: number;
|
|
11
|
+
detection_mode?: DetectionMode;
|
|
12
|
+
frames_per_color?: number;
|
|
13
|
+
band_edges_hz?: number[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RenderOptions {
|
|
17
|
+
width?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
shape?: SvgShape;
|
|
20
|
+
background?: "transparent" | "black" | "white" | "none";
|
|
21
|
+
max_gradient_stops?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type MoodbarInput =
|
|
25
|
+
| { uri: string }
|
|
26
|
+
| { bytes: Uint8Array; name?: string; mimeType?: string };
|
|
27
|
+
|
|
28
|
+
export interface MoodbarAnalysis {
|
|
29
|
+
readonly frameCount: number;
|
|
30
|
+
readonly channelCount: number;
|
|
31
|
+
readonly disposed: boolean;
|
|
32
|
+
dispose(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function analyze(
|
|
36
|
+
input: MoodbarInput,
|
|
37
|
+
options?: AnalyzeOptions
|
|
38
|
+
): Promise<MoodbarAnalysis>;
|
|
39
|
+
|
|
40
|
+
export function render(
|
|
41
|
+
analysis: MoodbarAnalysis,
|
|
42
|
+
format: "png",
|
|
43
|
+
options?: RenderOptions
|
|
44
|
+
): Promise<Uint8Array>;
|
|
45
|
+
export function render(
|
|
46
|
+
analysis: MoodbarAnalysis,
|
|
47
|
+
format: "svg",
|
|
48
|
+
options?: RenderOptions
|
|
49
|
+
): Promise<string>;
|
|
50
|
+
|
|
51
|
+
export function generate(
|
|
52
|
+
input: MoodbarInput,
|
|
53
|
+
format: "png",
|
|
54
|
+
options?: AnalyzeOptions & RenderOptions
|
|
55
|
+
): Promise<Uint8Array>;
|
|
56
|
+
export function generate(
|
|
57
|
+
input: MoodbarInput,
|
|
58
|
+
format: "svg",
|
|
59
|
+
options?: AnalyzeOptions & RenderOptions
|
|
60
|
+
): Promise<string>;
|
|
61
|
+
|
|
62
|
+
export function disposeAnalysis(analysis: MoodbarAnalysis): Promise<void>;
|
package/index.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
const { requireNativeModule } = require("expo-modules-core");
|
|
2
|
+
|
|
3
|
+
const Native = requireNativeModule("MoodbarNative");
|
|
4
|
+
const finalizer =
|
|
5
|
+
typeof FinalizationRegistry === "function"
|
|
6
|
+
? new FinalizationRegistry((handle) => {
|
|
7
|
+
Native.disposeAnalysis(handle).catch(() => {});
|
|
8
|
+
})
|
|
9
|
+
: null;
|
|
10
|
+
|
|
11
|
+
class NativeAnalysis {
|
|
12
|
+
constructor(handle, frameCount, channelCount) {
|
|
13
|
+
this.__nativeHandle = handle;
|
|
14
|
+
this.frameCount = frameCount;
|
|
15
|
+
this.channelCount = channelCount;
|
|
16
|
+
this.disposed = false;
|
|
17
|
+
|
|
18
|
+
if (finalizer) {
|
|
19
|
+
finalizer.register(this, handle, this);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async dispose() {
|
|
24
|
+
if (this.disposed) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.disposed = true;
|
|
28
|
+
if (finalizer) {
|
|
29
|
+
finalizer.unregister(this);
|
|
30
|
+
}
|
|
31
|
+
await Native.disposeAnalysis(this.__nativeHandle);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function assertAnalysis(analysis) {
|
|
36
|
+
if (!(analysis instanceof NativeAnalysis)) {
|
|
37
|
+
throw new TypeError("analysis must be returned by analyze() from @moodbar/native");
|
|
38
|
+
}
|
|
39
|
+
if (analysis.disposed) {
|
|
40
|
+
throw new Error("analysis handle has already been disposed");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function stringifyOptions(options) {
|
|
45
|
+
if (!options) {
|
|
46
|
+
return "{}";
|
|
47
|
+
}
|
|
48
|
+
return JSON.stringify(options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function inferExtension(name, mimeType) {
|
|
52
|
+
if (typeof name === "string") {
|
|
53
|
+
const match = name.match(/\.([A-Za-z0-9]+)$/);
|
|
54
|
+
if (match) {
|
|
55
|
+
return match[1].toLowerCase();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (typeof mimeType === "string") {
|
|
60
|
+
const slash = mimeType.indexOf("/");
|
|
61
|
+
if (slash >= 0 && slash < mimeType.length - 1) {
|
|
62
|
+
return mimeType.slice(slash + 1).toLowerCase();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const BASE64_ALPHABET =
|
|
70
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
71
|
+
const BASE64_REVERSE = (() => {
|
|
72
|
+
const out = new Uint8Array(256);
|
|
73
|
+
out.fill(255);
|
|
74
|
+
for (let i = 0; i < BASE64_ALPHABET.length; i += 1) {
|
|
75
|
+
out[BASE64_ALPHABET.charCodeAt(i)] = i;
|
|
76
|
+
}
|
|
77
|
+
out["=".charCodeAt(0)] = 0;
|
|
78
|
+
return out;
|
|
79
|
+
})();
|
|
80
|
+
|
|
81
|
+
function bytesToBase64(bytes) {
|
|
82
|
+
let out = "";
|
|
83
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
84
|
+
const a = bytes[i];
|
|
85
|
+
const b = i + 1 < bytes.length ? bytes[i + 1] : 0;
|
|
86
|
+
const c = i + 2 < bytes.length ? bytes[i + 2] : 0;
|
|
87
|
+
const triple = (a << 16) | (b << 8) | c;
|
|
88
|
+
|
|
89
|
+
out += BASE64_ALPHABET[(triple >> 18) & 63];
|
|
90
|
+
out += BASE64_ALPHABET[(triple >> 12) & 63];
|
|
91
|
+
out += i + 1 < bytes.length ? BASE64_ALPHABET[(triple >> 6) & 63] : "=";
|
|
92
|
+
out += i + 2 < bytes.length ? BASE64_ALPHABET[triple & 63] : "=";
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function base64ToBytes(base64) {
|
|
98
|
+
const clean = base64.replace(/\s+/g, "");
|
|
99
|
+
if (clean.length % 4 !== 0) {
|
|
100
|
+
throw new Error("invalid base64 payload from native renderPng");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const padding = clean.endsWith("==") ? 2 : clean.endsWith("=") ? 1 : 0;
|
|
104
|
+
const outLen = (clean.length / 4) * 3 - padding;
|
|
105
|
+
const out = new Uint8Array(outLen);
|
|
106
|
+
let outIdx = 0;
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < clean.length; i += 4) {
|
|
109
|
+
const c0 = BASE64_REVERSE[clean.charCodeAt(i)];
|
|
110
|
+
const c1 = BASE64_REVERSE[clean.charCodeAt(i + 1)];
|
|
111
|
+
const c2 = BASE64_REVERSE[clean.charCodeAt(i + 2)];
|
|
112
|
+
const c3 = BASE64_REVERSE[clean.charCodeAt(i + 3)];
|
|
113
|
+
if (c0 === 255 || c1 === 255 || c2 === 255 || c3 === 255) {
|
|
114
|
+
throw new Error("invalid base64 payload from native renderPng");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const triple = (c0 << 18) | (c1 << 12) | (c2 << 6) | c3;
|
|
118
|
+
if (outIdx < outLen) out[outIdx++] = (triple >> 16) & 255;
|
|
119
|
+
if (outIdx < outLen) out[outIdx++] = (triple >> 8) & 255;
|
|
120
|
+
if (outIdx < outLen) out[outIdx++] = triple & 255;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function analyze(input, options) {
|
|
127
|
+
const optionsJson = stringifyOptions(options);
|
|
128
|
+
|
|
129
|
+
if (input && typeof input.uri === "string") {
|
|
130
|
+
const result = await Native.analyzeFromUri(input.uri, optionsJson);
|
|
131
|
+
return new NativeAnalysis(result.handle, result.frameCount, result.channelCount);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (input && input.bytes instanceof Uint8Array) {
|
|
135
|
+
const extension = inferExtension(input.name, input.mimeType);
|
|
136
|
+
const base64 = bytesToBase64(input.bytes);
|
|
137
|
+
const result = await Native.analyzeFromBase64(base64, extension, optionsJson);
|
|
138
|
+
return new NativeAnalysis(result.handle, result.frameCount, result.channelCount);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
throw new TypeError("input must be { uri: string } or { bytes: Uint8Array }");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function render(analysis, format, options) {
|
|
145
|
+
assertAnalysis(analysis);
|
|
146
|
+
|
|
147
|
+
const optionsJson = stringifyOptions(options);
|
|
148
|
+
if (format === "png") {
|
|
149
|
+
const pngBase64 = await Native.renderPng(analysis.__nativeHandle, optionsJson);
|
|
150
|
+
return base64ToBytes(pngBase64);
|
|
151
|
+
}
|
|
152
|
+
if (format === "svg") {
|
|
153
|
+
return Native.renderSvg(analysis.__nativeHandle, optionsJson);
|
|
154
|
+
}
|
|
155
|
+
throw new TypeError('format must be "png" or "svg"');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function generate(input, format, options) {
|
|
159
|
+
const analysis = await analyze(input, options);
|
|
160
|
+
try {
|
|
161
|
+
return await render(analysis, format, options);
|
|
162
|
+
} finally {
|
|
163
|
+
await analysis.dispose();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function disposeAnalysis(analysis) {
|
|
168
|
+
assertAnalysis(analysis);
|
|
169
|
+
await analysis.dispose();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = {
|
|
173
|
+
analyze,
|
|
174
|
+
render,
|
|
175
|
+
generate,
|
|
176
|
+
disposeAnalysis,
|
|
177
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>AvailableLibraries</key>
|
|
6
|
+
<array>
|
|
7
|
+
<dict>
|
|
8
|
+
<key>BinaryPath</key>
|
|
9
|
+
<string>libmoodbar_native_ffi.a</string>
|
|
10
|
+
<key>HeadersPath</key>
|
|
11
|
+
<string>Headers</string>
|
|
12
|
+
<key>LibraryIdentifier</key>
|
|
13
|
+
<string>ios-arm64</string>
|
|
14
|
+
<key>LibraryPath</key>
|
|
15
|
+
<string>libmoodbar_native_ffi.a</string>
|
|
16
|
+
<key>SupportedArchitectures</key>
|
|
17
|
+
<array>
|
|
18
|
+
<string>arm64</string>
|
|
19
|
+
</array>
|
|
20
|
+
<key>SupportedPlatform</key>
|
|
21
|
+
<string>ios</string>
|
|
22
|
+
</dict>
|
|
23
|
+
<dict>
|
|
24
|
+
<key>BinaryPath</key>
|
|
25
|
+
<string>libmoodbar_native_ffi_simulator.a</string>
|
|
26
|
+
<key>HeadersPath</key>
|
|
27
|
+
<string>Headers</string>
|
|
28
|
+
<key>LibraryIdentifier</key>
|
|
29
|
+
<string>ios-arm64_x86_64-simulator</string>
|
|
30
|
+
<key>LibraryPath</key>
|
|
31
|
+
<string>libmoodbar_native_ffi_simulator.a</string>
|
|
32
|
+
<key>SupportedArchitectures</key>
|
|
33
|
+
<array>
|
|
34
|
+
<string>arm64</string>
|
|
35
|
+
<string>x86_64</string>
|
|
36
|
+
</array>
|
|
37
|
+
<key>SupportedPlatform</key>
|
|
38
|
+
<string>ios</string>
|
|
39
|
+
<key>SupportedPlatformVariant</key>
|
|
40
|
+
<string>simulator</string>
|
|
41
|
+
</dict>
|
|
42
|
+
</array>
|
|
43
|
+
<key>CFBundlePackageType</key>
|
|
44
|
+
<string>XFWK</string>
|
|
45
|
+
<key>XCFrameworkFormatVersion</key>
|
|
46
|
+
<string>1.0</string>
|
|
47
|
+
</dict>
|
|
48
|
+
</plist>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#include "moodbar_native_ffi.h"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#ifndef MOODBAR_NATIVE_FFI_H
|
|
2
|
+
#define MOODBAR_NATIVE_FFI_H
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
/* This file is generated by cbindgen. */
|
|
7
|
+
|
|
8
|
+
#include <stdarg.h>
|
|
9
|
+
#include <stdbool.h>
|
|
10
|
+
#include <stddef.h>
|
|
11
|
+
#include <stdint.h>
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
|
|
14
|
+
enum MoodbarNativeStatus {
|
|
15
|
+
Ok = 0,
|
|
16
|
+
InvalidArgument = 1,
|
|
17
|
+
NotFound = 2,
|
|
18
|
+
Internal = 3,
|
|
19
|
+
};
|
|
20
|
+
typedef int32_t MoodbarNativeStatus;
|
|
21
|
+
|
|
22
|
+
typedef struct MoodbarNativeAnalysisSummary {
|
|
23
|
+
uint64_t handle;
|
|
24
|
+
uint32_t frame_count;
|
|
25
|
+
uint32_t channel_count;
|
|
26
|
+
} MoodbarNativeAnalysisSummary;
|
|
27
|
+
|
|
28
|
+
typedef struct MoodbarNativeBuffer {
|
|
29
|
+
uint8_t *ptr;
|
|
30
|
+
size_t len;
|
|
31
|
+
size_t cap;
|
|
32
|
+
} MoodbarNativeBuffer;
|
|
33
|
+
|
|
34
|
+
MoodbarNativeStatus moodbar_native_analysis_from_path(const char *path,
|
|
35
|
+
const char *options_json,
|
|
36
|
+
struct MoodbarNativeAnalysisSummary *out_summary);
|
|
37
|
+
|
|
38
|
+
MoodbarNativeStatus moodbar_native_analysis_from_bytes(const uint8_t *bytes,
|
|
39
|
+
size_t bytes_len,
|
|
40
|
+
const char *extension,
|
|
41
|
+
const char *options_json,
|
|
42
|
+
struct MoodbarNativeAnalysisSummary *out_summary);
|
|
43
|
+
|
|
44
|
+
MoodbarNativeStatus moodbar_native_analysis_dispose(uint64_t handle);
|
|
45
|
+
|
|
46
|
+
MoodbarNativeStatus moodbar_native_render_svg(uint64_t handle,
|
|
47
|
+
const char *options_json,
|
|
48
|
+
struct MoodbarNativeBuffer *out_svg_utf8);
|
|
49
|
+
|
|
50
|
+
MoodbarNativeStatus moodbar_native_render_png(uint64_t handle,
|
|
51
|
+
const char *options_json,
|
|
52
|
+
struct MoodbarNativeBuffer *out_png);
|
|
53
|
+
|
|
54
|
+
MoodbarNativeStatus moodbar_native_last_error(struct MoodbarNativeBuffer *out_message_utf8);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Frees a heap buffer previously returned by this library.
|
|
58
|
+
*
|
|
59
|
+
* # Safety
|
|
60
|
+
*
|
|
61
|
+
* `buffer` must be a valid, writable pointer obtained from this library, and must not be
|
|
62
|
+
* freed more than once.
|
|
63
|
+
*/
|
|
64
|
+
void moodbar_native_buffer_free(struct MoodbarNativeBuffer *buffer);
|
|
65
|
+
|
|
66
|
+
#endif /* MOODBAR_NATIVE_FFI_H */
|
package/ios/MoodbarNativeFFI.xcframework/ios-arm64_x86_64-simulator/Headers/MoodbarNativeFFI.h
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#include "moodbar_native_ffi.h"
|
package/ios/MoodbarNativeFFI.xcframework/ios-arm64_x86_64-simulator/Headers/moodbar_native_ffi.h
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#ifndef MOODBAR_NATIVE_FFI_H
|
|
2
|
+
#define MOODBAR_NATIVE_FFI_H
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
/* This file is generated by cbindgen. */
|
|
7
|
+
|
|
8
|
+
#include <stdarg.h>
|
|
9
|
+
#include <stdbool.h>
|
|
10
|
+
#include <stddef.h>
|
|
11
|
+
#include <stdint.h>
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
|
|
14
|
+
enum MoodbarNativeStatus {
|
|
15
|
+
Ok = 0,
|
|
16
|
+
InvalidArgument = 1,
|
|
17
|
+
NotFound = 2,
|
|
18
|
+
Internal = 3,
|
|
19
|
+
};
|
|
20
|
+
typedef int32_t MoodbarNativeStatus;
|
|
21
|
+
|
|
22
|
+
typedef struct MoodbarNativeAnalysisSummary {
|
|
23
|
+
uint64_t handle;
|
|
24
|
+
uint32_t frame_count;
|
|
25
|
+
uint32_t channel_count;
|
|
26
|
+
} MoodbarNativeAnalysisSummary;
|
|
27
|
+
|
|
28
|
+
typedef struct MoodbarNativeBuffer {
|
|
29
|
+
uint8_t *ptr;
|
|
30
|
+
size_t len;
|
|
31
|
+
size_t cap;
|
|
32
|
+
} MoodbarNativeBuffer;
|
|
33
|
+
|
|
34
|
+
MoodbarNativeStatus moodbar_native_analysis_from_path(const char *path,
|
|
35
|
+
const char *options_json,
|
|
36
|
+
struct MoodbarNativeAnalysisSummary *out_summary);
|
|
37
|
+
|
|
38
|
+
MoodbarNativeStatus moodbar_native_analysis_from_bytes(const uint8_t *bytes,
|
|
39
|
+
size_t bytes_len,
|
|
40
|
+
const char *extension,
|
|
41
|
+
const char *options_json,
|
|
42
|
+
struct MoodbarNativeAnalysisSummary *out_summary);
|
|
43
|
+
|
|
44
|
+
MoodbarNativeStatus moodbar_native_analysis_dispose(uint64_t handle);
|
|
45
|
+
|
|
46
|
+
MoodbarNativeStatus moodbar_native_render_svg(uint64_t handle,
|
|
47
|
+
const char *options_json,
|
|
48
|
+
struct MoodbarNativeBuffer *out_svg_utf8);
|
|
49
|
+
|
|
50
|
+
MoodbarNativeStatus moodbar_native_render_png(uint64_t handle,
|
|
51
|
+
const char *options_json,
|
|
52
|
+
struct MoodbarNativeBuffer *out_png);
|
|
53
|
+
|
|
54
|
+
MoodbarNativeStatus moodbar_native_last_error(struct MoodbarNativeBuffer *out_message_utf8);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Frees a heap buffer previously returned by this library.
|
|
58
|
+
*
|
|
59
|
+
* # Safety
|
|
60
|
+
*
|
|
61
|
+
* `buffer` must be a valid, writable pointer obtained from this library, and must not be
|
|
62
|
+
* freed more than once.
|
|
63
|
+
*/
|
|
64
|
+
void moodbar_native_buffer_free(struct MoodbarNativeBuffer *buffer);
|
|
65
|
+
|
|
66
|
+
#endif /* MOODBAR_NATIVE_FFI_H */
|
|
Binary file
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
public class MoodbarNativeModule: Module {
|
|
5
|
+
public func definition() -> ModuleDefinition {
|
|
6
|
+
Name("MoodbarNative")
|
|
7
|
+
|
|
8
|
+
AsyncFunction("analyzeFromUri") { (uri: String, optionsJson: String?) throws -> [String: Any] in
|
|
9
|
+
let resolvedPath = try self.resolvePath(from: uri)
|
|
10
|
+
var summary = MoodbarNativeAnalysisSummary(handle: 0, frame_count: 0, channel_count: 0)
|
|
11
|
+
let status = resolvedPath.withCString { pathPtr in
|
|
12
|
+
withOptionalCString(optionsJson) { optionsPtr in
|
|
13
|
+
moodbar_native_analysis_from_path(pathPtr, optionsPtr, &summary)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
try throwIfNeeded(status)
|
|
17
|
+
return [
|
|
18
|
+
"handle": summary.handle,
|
|
19
|
+
"frameCount": Int(summary.frame_count),
|
|
20
|
+
"channelCount": Int(summary.channel_count),
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
AsyncFunction("analyzeFromBase64") { (base64: String, fileExtension: String?, optionsJson: String?) throws -> [String: Any] in
|
|
25
|
+
guard let data = Data(base64Encoded: base64) else {
|
|
26
|
+
throw NSError(domain: "MoodbarNative", code: 1, userInfo: [NSLocalizedDescriptionKey: "input bytes were not valid base64"])
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var summary = MoodbarNativeAnalysisSummary(handle: 0, frame_count: 0, channel_count: 0)
|
|
30
|
+
let status = data.withUnsafeBytes { rawBuffer in
|
|
31
|
+
let bytes = rawBuffer.bindMemory(to: UInt8.self).baseAddress
|
|
32
|
+
return withOptionalCString(fileExtension) { extensionPtr in
|
|
33
|
+
withOptionalCString(optionsJson) { optionsPtr in
|
|
34
|
+
moodbar_native_analysis_from_bytes(bytes, data.count, extensionPtr, optionsPtr, &summary)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try throwIfNeeded(status)
|
|
40
|
+
return [
|
|
41
|
+
"handle": summary.handle,
|
|
42
|
+
"frameCount": Int(summary.frame_count),
|
|
43
|
+
"channelCount": Int(summary.channel_count),
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
AsyncFunction("renderSvg") { (handle: UInt64, optionsJson: String?) throws -> String in
|
|
48
|
+
var out = MoodbarNativeBuffer(ptr: nil, len: 0, cap: 0)
|
|
49
|
+
defer { moodbar_native_buffer_free(&out) }
|
|
50
|
+
let status = withOptionalCString(optionsJson) { optionsPtr in
|
|
51
|
+
moodbar_native_render_svg(handle, optionsPtr, &out)
|
|
52
|
+
}
|
|
53
|
+
try throwIfNeeded(status)
|
|
54
|
+
|
|
55
|
+
let data = consumeBuffer(out)
|
|
56
|
+
guard let svg = String(data: data, encoding: .utf8) else {
|
|
57
|
+
throw NSError(domain: "MoodbarNative", code: 3, userInfo: [NSLocalizedDescriptionKey: "native SVG payload was not UTF-8"])
|
|
58
|
+
}
|
|
59
|
+
return svg
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
AsyncFunction("renderPng") { (handle: UInt64, optionsJson: String?) throws -> String in
|
|
63
|
+
var out = MoodbarNativeBuffer(ptr: nil, len: 0, cap: 0)
|
|
64
|
+
defer { moodbar_native_buffer_free(&out) }
|
|
65
|
+
let status = withOptionalCString(optionsJson) { optionsPtr in
|
|
66
|
+
moodbar_native_render_png(handle, optionsPtr, &out)
|
|
67
|
+
}
|
|
68
|
+
try throwIfNeeded(status)
|
|
69
|
+
|
|
70
|
+
let data = consumeBuffer(out)
|
|
71
|
+
return data.base64EncodedString()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
AsyncFunction("disposeAnalysis") { (handle: UInt64) throws -> Void in
|
|
75
|
+
let status = moodbar_native_analysis_dispose(handle)
|
|
76
|
+
try throwIfNeeded(status)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private func withOptionalCString<T>(_ value: String?, _ body: (UnsafePointer<CChar>?) -> T) -> T {
|
|
81
|
+
guard let value else {
|
|
82
|
+
return body(nil)
|
|
83
|
+
}
|
|
84
|
+
return value.withCString { cString in
|
|
85
|
+
body(cString)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private func throwIfNeeded(_ status: MoodbarNativeStatus) throws {
|
|
90
|
+
if status == 0 {
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var out = MoodbarNativeBuffer(ptr: nil, len: 0, cap: 0)
|
|
95
|
+
_ = moodbar_native_last_error(&out)
|
|
96
|
+
defer { moodbar_native_buffer_free(&out) }
|
|
97
|
+
|
|
98
|
+
let data = consumeBuffer(out)
|
|
99
|
+
let message = String(data: data, encoding: .utf8) ?? "native moodbar call failed"
|
|
100
|
+
throw NSError(
|
|
101
|
+
domain: "MoodbarNative",
|
|
102
|
+
code: Int(status),
|
|
103
|
+
userInfo: [NSLocalizedDescriptionKey: message]
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private func consumeBuffer(_ buffer: MoodbarNativeBuffer) -> Data {
|
|
108
|
+
guard let ptr = buffer.ptr else {
|
|
109
|
+
return Data()
|
|
110
|
+
}
|
|
111
|
+
return Data(bytes: ptr, count: buffer.len)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private func resolvePath(from uri: String) throws -> String {
|
|
115
|
+
guard let url = URL(string: uri), url.scheme != nil else {
|
|
116
|
+
return uri
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if url.isFileURL {
|
|
120
|
+
return url.path
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
throw NSError(
|
|
124
|
+
domain: "MoodbarNative",
|
|
125
|
+
code: 4,
|
|
126
|
+
userInfo: [NSLocalizedDescriptionKey: "unsupported URI scheme for iOS: \(uri)"]
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#include "moodbar_native_ffi.h"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#ifndef MOODBAR_NATIVE_FFI_H
|
|
2
|
+
#define MOODBAR_NATIVE_FFI_H
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
/* This file is generated by cbindgen. */
|
|
7
|
+
|
|
8
|
+
#include <stdarg.h>
|
|
9
|
+
#include <stdbool.h>
|
|
10
|
+
#include <stddef.h>
|
|
11
|
+
#include <stdint.h>
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
|
|
14
|
+
enum MoodbarNativeStatus {
|
|
15
|
+
Ok = 0,
|
|
16
|
+
InvalidArgument = 1,
|
|
17
|
+
NotFound = 2,
|
|
18
|
+
Internal = 3,
|
|
19
|
+
};
|
|
20
|
+
typedef int32_t MoodbarNativeStatus;
|
|
21
|
+
|
|
22
|
+
typedef struct MoodbarNativeAnalysisSummary {
|
|
23
|
+
uint64_t handle;
|
|
24
|
+
uint32_t frame_count;
|
|
25
|
+
uint32_t channel_count;
|
|
26
|
+
} MoodbarNativeAnalysisSummary;
|
|
27
|
+
|
|
28
|
+
typedef struct MoodbarNativeBuffer {
|
|
29
|
+
uint8_t *ptr;
|
|
30
|
+
size_t len;
|
|
31
|
+
size_t cap;
|
|
32
|
+
} MoodbarNativeBuffer;
|
|
33
|
+
|
|
34
|
+
MoodbarNativeStatus moodbar_native_analysis_from_path(const char *path,
|
|
35
|
+
const char *options_json,
|
|
36
|
+
struct MoodbarNativeAnalysisSummary *out_summary);
|
|
37
|
+
|
|
38
|
+
MoodbarNativeStatus moodbar_native_analysis_from_bytes(const uint8_t *bytes,
|
|
39
|
+
size_t bytes_len,
|
|
40
|
+
const char *extension,
|
|
41
|
+
const char *options_json,
|
|
42
|
+
struct MoodbarNativeAnalysisSummary *out_summary);
|
|
43
|
+
|
|
44
|
+
MoodbarNativeStatus moodbar_native_analysis_dispose(uint64_t handle);
|
|
45
|
+
|
|
46
|
+
MoodbarNativeStatus moodbar_native_render_svg(uint64_t handle,
|
|
47
|
+
const char *options_json,
|
|
48
|
+
struct MoodbarNativeBuffer *out_svg_utf8);
|
|
49
|
+
|
|
50
|
+
MoodbarNativeStatus moodbar_native_render_png(uint64_t handle,
|
|
51
|
+
const char *options_json,
|
|
52
|
+
struct MoodbarNativeBuffer *out_png);
|
|
53
|
+
|
|
54
|
+
MoodbarNativeStatus moodbar_native_last_error(struct MoodbarNativeBuffer *out_message_utf8);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Frees a heap buffer previously returned by this library.
|
|
58
|
+
*
|
|
59
|
+
* # Safety
|
|
60
|
+
*
|
|
61
|
+
* `buffer` must be a valid, writable pointer obtained from this library, and must not be
|
|
62
|
+
* freed more than once.
|
|
63
|
+
*/
|
|
64
|
+
void moodbar_native_buffer_free(struct MoodbarNativeBuffer *buffer);
|
|
65
|
+
|
|
66
|
+
#endif /* MOODBAR_NATIVE_FFI_H */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "MoodbarNative"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.description = package["description"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.author = "Moodbar"
|
|
12
|
+
s.homepage = package["homepage"]
|
|
13
|
+
s.platforms = {
|
|
14
|
+
:ios => "14.0"
|
|
15
|
+
}
|
|
16
|
+
s.source = {
|
|
17
|
+
:git => "https://github.com/gildesmarais/moodbar.rs.git"
|
|
18
|
+
}
|
|
19
|
+
s.static_framework = true
|
|
20
|
+
|
|
21
|
+
s.dependency "ExpoModulesCore"
|
|
22
|
+
|
|
23
|
+
s.source_files = "ios/**/*.{swift,h,m,mm}"
|
|
24
|
+
s.public_header_files = "ios/include/*.h"
|
|
25
|
+
s.vendored_frameworks = "ios/MoodbarNativeFFI.xcframework"
|
|
26
|
+
s.pod_target_xcconfig = {
|
|
27
|
+
"DEFINES_MODULE" => "YES",
|
|
28
|
+
"SWIFT_COMPILATION_MODE" => "wholemodule"
|
|
29
|
+
}
|
|
30
|
+
end
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moodbar/native",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "React Native bindings for moodbar audio visualization",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/gildesmarais/moodbar.rs.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/gildesmarais/moodbar.rs#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/gildesmarais/moodbar.rs/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"moodbar",
|
|
16
|
+
"react-native",
|
|
17
|
+
"expo",
|
|
18
|
+
"audio",
|
|
19
|
+
"visualization"
|
|
20
|
+
],
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"types": "index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"index.js",
|
|
25
|
+
"index.d.ts",
|
|
26
|
+
"expo-module.config.json",
|
|
27
|
+
"moodbar-native.podspec",
|
|
28
|
+
"android",
|
|
29
|
+
"ios",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE-MIT",
|
|
32
|
+
"LICENSE-APACHE"
|
|
33
|
+
],
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"expo": "*",
|
|
36
|
+
"react-native": "*"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"expo-modules-core": "^2.6.0"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false
|
|
42
|
+
}
|