| 1 |
export const dlinit = (hostInstance, pluginInstance, table, csoundInstance) => { |
| 2 |
if (pluginInstance.exports.csoundModuleInit) { |
| 3 |
const csoundModuleCreate = new WebAssembly.Global({ value: "i32", mutable: true }, 0); |
| 4 |
const csoundModuleInit = new WebAssembly.Global({ value: "i32", mutable: true }, 0); |
| 5 |
const csoundModuleDestroy = new WebAssembly.Global({ value: "i32", mutable: true }, 0); |
| 6 |
const csoundModuleErrorCodeToString = new WebAssembly.Global( |
| 7 |
{ value: "i32", mutable: true }, |
| 8 |
0, |
| 9 |
); |
| 10 |
|
| 11 |
let tableEnd = table.length; |
| 12 |
|
| 13 |
if (typeof pluginInstance.exports.csoundModuleCreate === "function") { |
| 14 |
table.grow(1); |
| 15 |
csoundModuleCreate.value = tableEnd; |
| 16 |
table.set(tableEnd, pluginInstance.exports.csoundModuleCreate); |
| 17 |
tableEnd += 1; |
| 18 |
} |
| 19 |
|
| 20 |
if (typeof pluginInstance.exports.csoundModuleInit === "function") { |
| 21 |
table.grow(1); |
| 22 |
csoundModuleInit.value = tableEnd; |
| 23 |
table.set(tableEnd, pluginInstance.exports.csoundModuleInit); |
| 24 |
tableEnd += 1; |
| 25 |
} |
| 26 |
|
| 27 |
if (typeof pluginInstance.exports.csoundModuleDestroy === "function") { |
| 28 |
table.grow(1); |
| 29 |
csoundModuleDestroy.value = tableEnd; |
| 30 |
table.set(tableEnd, pluginInstance.exports.csoundModuleDestroy); |
| 31 |
tableEnd += 1; |
| 32 |
} |
| 33 |
|
| 34 |
if (typeof pluginInstance.exports.csoundModuleErrorCodeToString === "function") { |
| 35 |
table.grow(1); |
| 36 |
csoundModuleErrorCodeToString.value = tableEnd; |
| 37 |
table.set(tableEnd, pluginInstance.exports.csoundModuleErrorCodeToString); |
| 38 |
tableEnd += 1; |
| 39 |
} |
| 40 |
|
| 41 |
hostInstance.exports.csoundWasiLoadPlugin( |
| 42 |
csoundInstance, |
| 43 |
csoundModuleCreate, |
| 44 |
csoundModuleInit, |
| 45 |
csoundModuleDestroy, |
| 46 |
csoundModuleErrorCodeToString, |
| 47 |
); |
| 48 |
} else if (pluginInstance.exports.csound_opcode_init || pluginInstance.exports.csound_fgen_init) { |
| 49 |
const csoundOpcodeInit = new WebAssembly.Global({ value: "i32", mutable: true }, 0); |
| 50 |
const csoundFgenInit = new WebAssembly.Global({ value: "i32", mutable: true }, 0); |
| 51 |
|
| 52 |
let tableEnd = table.length; |
| 53 |
|
| 54 |
if (typeof pluginInstance.exports.csound_opcode_init === "function") { |
| 55 |
csoundOpcodeInit.value = tableEnd; |
| 56 |
table.grow(1); |
| 57 |
table.set(tableEnd, pluginInstance.exports.csound_opcode_init); |
| 58 |
tableEnd += 1; |
| 59 |
} |
| 60 |
|
| 61 |
if (typeof pluginInstance.exports.csound_fgen_init === "function") { |
| 62 |
csoundFgenInit.value = tableEnd; |
| 63 |
table.grow(1); |
| 64 |
table.set(tableEnd, pluginInstance.exports.csound_fgen_init); |
| 65 |
tableEnd += 1; |
| 66 |
} |
| 67 |
|
| 68 |
hostInstance.exports.csoundWasiLoadOpcodeLibrary( |
| 69 |
csoundInstance, |
| 70 |
csoundFgenInit, |
| 71 |
csoundOpcodeInit, |
| 72 |
); |
| 73 |
} else { |
| 74 |
console.error("Plugin doesn't export nececcary functions to quality as csound plugin."); |
| 75 |
} |
| 76 |
}; |