-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add console and some midi syscall support
- Loading branch information
1 parent
ca70a28
commit 103679f
Showing
24 changed files
with
387 additions
and
112 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ pub mod decode; | |
pub mod build; | ||
pub mod hex_format; | ||
pub mod regions; | ||
pub mod midi; |
File renamed without changes.
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,2 @@ | ||
pub mod instruments; | ||
pub mod note; |
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 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Serialize, Deserialize)] | ||
pub struct MidiNote { | ||
pub sync: bool, | ||
pub instrument: u64, | ||
pub name: String, | ||
pub note: u64, | ||
pub duration: f64, | ||
pub volume: u64, | ||
} |
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
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
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
use std::sync::Arc; | ||
use saturn_backend::syscall::ConsoleHandler; | ||
use crate::EventHandler; | ||
|
||
pub struct WasmConsole { } | ||
pub struct WasmConsole { | ||
pub events: Arc<EventHandler> | ||
} | ||
|
||
impl ConsoleHandler for WasmConsole { | ||
fn print(&mut self, _text: &str, _error: bool) { | ||
todo!() | ||
fn print(&mut self, text: &str, error: bool) { | ||
self.events.send_console_write(text, error) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,41 @@ | ||
struct Listener { | ||
|
||
use send_wrapper::SendWrapper; | ||
use wasm_bindgen::JsValue; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use saturn_backend::midi::note::MidiNote; | ||
|
||
#[wasm_bindgen] | ||
pub struct EventHandler { | ||
on_console_write: SendWrapper<js_sys::Function>, | ||
on_midi_play: SendWrapper<js_sys::Function>, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl EventHandler { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new( | ||
on_console_write: js_sys::Function, | ||
on_midi_play: js_sys::Function, | ||
) -> EventHandler { | ||
EventHandler { | ||
on_console_write: SendWrapper::new(on_console_write), | ||
on_midi_play: SendWrapper::new(on_midi_play) | ||
} | ||
} | ||
} | ||
|
||
impl EventHandler { | ||
pub fn send_console_write(&self, text: &str, error: bool) { | ||
self.on_console_write.call2( | ||
&JsValue::UNDEFINED, | ||
&JsValue::from_str(text), | ||
&JsValue::from_bool(error) | ||
).ok(); | ||
} | ||
|
||
pub fn send_midi_play(&self, note: MidiNote) { | ||
self.on_midi_play.call1( | ||
&JsValue::UNDEFINED, | ||
&serde_wasm_bindgen::to_value(¬e).unwrap() | ||
).ok(); | ||
} | ||
} |
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.