33import jsDownload from "downloadjs" ;
44import { WASI } from "@runno/wasi" ;
55
6-
7- const wasm_binary = fetch ( new URL ( "musicxml2pv.wasm" , import . meta. url ) ) ;
8-
96export const copyToClipboard = str => ( ) => navigator . clipboard . writeText ( str ) ;
107
118export function download_ ( data ) {
@@ -139,16 +136,16 @@ export const examplePieceJSONLong = [
139136 ] } ,
140137] ;
141138
142- export const musicxml2pv = ( unfold ) => ( musicxml ) => async ( ) => {
143- var output = null ;
139+ export const musicxml2pv = ( mkLeft ) => ( mkRight ) => ( unfold ) => ( musicxml ) => async ( ) => {
140+ var output = "" ;
144141 var args = [ "musicxml2pv" , "/input.musicxml" ] ;
145142 if ( unfold ) {
146143 args . splice ( 1 , 0 , "-u" ) ;
147144 }
148145 console . log ( args ) ;
149146 const wasi = new WASI ( {
150147 args : args ,
151- stdout : ( out ) => output = out ,
148+ stdout : ( out ) => output + = out ,
152149 stderr : ( err ) => console . error ( "wasm err:" , err ) ,
153150 fs : {
154151 "/input.musicxml" : {
@@ -165,10 +162,17 @@ export const musicxml2pv = (unfold) => (musicxml) => async () => {
165162 } ) ;
166163 // console.log(wasi);
167164
168- const wasm = await WebAssembly . instantiateStreaming ( wasm_binary , wasi . getImportObject ( ) ) ;
165+ const wasm = await WebAssembly . instantiateStreaming ( fetch ( new URL ( "musicxml2pv.wasm" , import . meta . url ) ) , wasi . getImportObject ( ) ) ;
169166 // console.log(wasm);
170167
171- await wasi . start ( wasm , { } ) ;
172- return output ;
168+ result = await wasi . start ( wasm , { } ) ;
169+ console . log ( result ) ;
170+ if ( output == "" ) {
171+ return mkLeft ( "musicxml2pv returned empty string" ) ;
172+ } else if ( result . exitCode != 0 ) {
173+ return mkLeft ( "musicxml2pv returned exit code" + result . exitCode . toString ( ) ) ;
174+ } else {
175+ return mkRight ( output ) ;
176+ }
173177} ;
174178
0 commit comments