-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Foundation + initial plumbing for sampler
* Add VC, AWP, wasm with build scripting, and framework of the UI
- Loading branch information
Showing
32 changed files
with
514 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ members = [ | |
"midi_renderer", | ||
"oscilloscope", | ||
"canvas_utils", | ||
"sampler" | ||
] | ||
|
||
[profile.release] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use uuid::Uuid; | ||
use wasm_bindgen::JsValue; | ||
|
||
use crate::{js, view_context::ViewContext}; | ||
|
||
/// This is just a shim to the JS-based sampler component. | ||
pub struct Sampler { | ||
pub uuid: Uuid, | ||
} | ||
|
||
impl Sampler { | ||
pub fn new(uuid: Uuid) -> Self { Sampler { uuid } } | ||
|
||
pub fn get_state_key(&self) -> String { format!("sampler_{}", self.uuid) } | ||
} | ||
|
||
impl ViewContext for Sampler { | ||
fn init(&mut self) { js::init_sampler(&self.get_state_key()); } | ||
|
||
fn cleanup(&mut self) { js::cleanup_sampler(&self.get_state_key()) } | ||
|
||
fn get_id(&self) -> String { self.uuid.to_string() } | ||
|
||
fn hide(&mut self) { js::hide_sampler(&self.get_state_key()); } | ||
|
||
fn unhide(&mut self) { js::unhide_sampler(&self.get_state_key()); } | ||
|
||
fn dispose(&mut self) { js::delete_localstorage_key(&self.get_state_key()); } | ||
|
||
fn get_audio_connectables(&self) -> JsValue { | ||
js::get_sampler_audio_connectables(&self.get_state_key()) | ||
} | ||
} | ||
|
||
pub fn mk_sampler(uuid: Uuid) -> Box<dyn ViewContext> { Box::new(Sampler { uuid }) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "sampler" | ||
version = "0.1.0" | ||
authors = ["Casey Primozic <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
dsp = { path = "../dsp" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub struct SamplerCtx {} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn init_sampler_ctx() -> *mut SamplerCtx { | ||
let ctx = SamplerCtx {}; | ||
Box::into_raw(Box::new(ctx)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const PARAM_DESCRIPTORS = []; | ||
|
||
class SamplerAWP extends AudioWorkletProcessor { | ||
static get parameterDescriptors() { | ||
return PARAM_DESCRIPTORS; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.isShutdown = false; | ||
this.ctxPtr = 0; | ||
this.wasmInstance = null; | ||
this.wasmMemoryBuffer = null; | ||
this.pendingMessages = []; | ||
|
||
this.port.onmessage = evt => this.handleMessage(evt.data); | ||
} | ||
|
||
async initWasmInstance(wasmBytes) { | ||
const compiledModule = await WebAssembly.compile(wasmBytes); | ||
this.wasmInstance = await WebAssembly.instantiate(compiledModule, { env: {} }); | ||
|
||
this.ctxPtr = this.wasmInstance.exports.init_sampler_ctx(); | ||
this.wasmMemoryBuffer = new Float32Array(this.wasmInstance.exports.memory.buffer); | ||
|
||
this.pendingMessages.forEach(data => this.handleMessage(data)); | ||
this.pendingMessages = []; | ||
} | ||
|
||
handleMessage(data) { | ||
// Store all events other than the initialization event until after Wasm is loaded and they can be handled. | ||
// | ||
// Pending events will be processed once that initialization is finished. | ||
if (!this.ctxPtr && data.type !== 'setWasmBytes') { | ||
this.pendingMessages.push(data); | ||
return; | ||
} | ||
|
||
switch (data.type) { | ||
case 'setWasmBytes': { | ||
this.initWasmInstance(data.wasmBytes); | ||
break; | ||
} | ||
case 'shutdown': { | ||
this.isShutdown = true; | ||
break; | ||
} | ||
default: { | ||
console.error('Unhandled message type in sampler player AWP: ', data.type); | ||
} | ||
} | ||
} | ||
|
||
process(_inputs, _outputs, _params) { | ||
if (this.isShutdown) { | ||
return false; | ||
} else if (!this.ctxPtr) { | ||
return true; | ||
} | ||
|
||
// TODO | ||
|
||
return true; | ||
} | ||
} | ||
|
||
registerProcessor('sampler-awp', SamplerAWP); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.