diff --git a/Cargo.lock b/Cargo.lock index 4070eb340f..325263d15e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,6 +59,28 @@ dependencies = [ "memchr", ] +[[package]] +name = "alsa" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75c4da790adcb2ce5e758c064b4f3ec17a30349f9961d3e5e6c9688b052a9e18" +dependencies = [ + "alsa-sys", + "bitflags", + "libc", + "nix 0.20.0", +] + +[[package]] +name = "alsa-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "andrew" version = "0.3.1" @@ -192,6 +214,25 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2 1.0.29", + "quote 1.0.9", + "regex", + "rustc-hash", + "shlex", +] + [[package]] name = "bit-set" version = "0.5.2" @@ -314,6 +355,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + [[package]] name = "calloop" version = "0.6.5" @@ -338,6 +385,24 @@ name = "cc" version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom 5.1.2", +] [[package]] name = "cfg-if" @@ -367,6 +432,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "clang-sys" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10612c0ec0e0a1ff0e97980647cb058a6e7aedb913d01d009c406b8b7d0b26ee" +dependencies = [ + "glob", + "libc", + "libloading 0.7.0", +] + [[package]] name = "clap" version = "2.33.3" @@ -407,6 +483,12 @@ dependencies = [ "syn 1.0.76", ] +[[package]] +name = "claxon" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bfbf56724aa9eca8afa4fcfadeb479e722935bb2a0900c2d37e0cc477af0688" + [[package]] name = "cli_utils" version = "0.1.0" @@ -496,6 +578,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "combine" +version = "4.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a909e4d93292cd8e9c42e189f61681eff9d67b6541f96b8a1a737f23737bd001" +dependencies = [ + "bytes 1.1.0", + "memchr", +] + [[package]] name = "confy" version = "0.4.0" @@ -628,6 +720,50 @@ dependencies = [ "objc", ] +[[package]] +name = "coreaudio-rs" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88" +dependencies = [ + "bitflags", + "coreaudio-sys", +] + +[[package]] +name = "coreaudio-sys" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b7e3347be6a09b46aba228d6608386739fb70beff4f61e07422da87b0bb31fa" +dependencies = [ + "bindgen", +] + +[[package]] +name = "cpal" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98f45f0a21f617cd2c788889ef710b63f075c949259593ea09c826f1e47a2418" +dependencies = [ + "alsa", + "core-foundation-sys 0.8.2", + "coreaudio-rs", + "jni", + "js-sys", + "lazy_static", + "libc", + "mach", + "ndk 0.3.0", + "ndk-glue 0.3.0", + "nix 0.20.0", + "oboe", + "parking_lot", + "stdweb", + "thiserror", + "web-sys", + "winapi 0.3.9", +] + [[package]] name = "cpufeatures" version = "0.2.1" @@ -1415,6 +1551,12 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + [[package]] name = "glow" version = "0.11.0" @@ -1548,6 +1690,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hound" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549" + [[package]] name = "humantime" version = "2.1.0" @@ -1776,12 +1924,35 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +[[package]] +name = "jni" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" +dependencies = [ + "cesu8", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", +] + [[package]] name = "jni-sys" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jobserver" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.54" @@ -1835,6 +2006,17 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" +[[package]] +name = "lewton" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777b48df9aaab155475a83a7df3070395ea1ac6902f5cd062b8f2b028075c030" +dependencies = [ + "byteorder", + "ogg", + "tinyvec", +] + [[package]] name = "libc" version = "0.2.101" @@ -2038,6 +2220,26 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c835948974f68e0bd58636fc6c5b1fbff7b297e3046f11b3b3c18bbac012c6d" +[[package]] +name = "minimp3" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985438f75febf74c392071a975a29641b420dd84431135a6e6db721de4b74372" +dependencies = [ + "minimp3-sys", + "slice-deque", + "thiserror", +] + +[[package]] +name = "minimp3-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e21c73734c69dc95696c9ed8926a2b393171d98b3f5f5935686a26a487ab9b90" +dependencies = [ + "cc", +] + [[package]] name = "miniz_oxide" version = "0.4.4" @@ -2132,7 +2334,32 @@ checksum = "5eb167c1febed0a496639034d0c76b3b74263636045db5489eee52143c246e73" dependencies = [ "jni-sys", "ndk-sys", - "num_enum", + "num_enum 0.4.3", + "thiserror", +] + +[[package]] +name = "ndk" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8794322172319b972f528bf90c6b467be0079f1fa82780ffb431088e741a73ab" +dependencies = [ + "jni-sys", + "ndk-sys", + "num_enum 0.5.4", + "thiserror", +] + +[[package]] +name = "ndk" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d64d6af06fde0e527b1ba5c7b79a6cc89cfc46325b0b2887dffe8f70197e0c3c" +dependencies = [ + "bitflags", + "jni-sys", + "ndk-sys", + "num_enum 0.5.4", "thiserror", ] @@ -2145,7 +2372,35 @@ dependencies = [ "lazy_static", "libc", "log", - "ndk", + "ndk 0.2.1", + "ndk-macro", + "ndk-sys", +] + +[[package]] +name = "ndk-glue" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5caf0c24d51ac1c905c27d4eda4fa0635bbe0de596b8f79235e0b17a4d29385" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk 0.3.0", + "ndk-macro", + "ndk-sys", +] + +[[package]] +name = "ndk-glue" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e9e94628f24e7a3cb5b96a2dc5683acd9230bf11991c2a1677b87695138420" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk 0.4.0", "ndk-macro", "ndk-sys", ] @@ -2157,7 +2412,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d" dependencies = [ "darling 0.10.2", - "proc-macro-crate", + "proc-macro-crate 0.1.5", "proc-macro2 1.0.29", "quote 1.0.9", "syn 1.0.76", @@ -2217,6 +2472,16 @@ dependencies = [ "libc", ] +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check", +] + [[package]] name = "nom" version = "7.0.0" @@ -2234,6 +2499,17 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fa586da3e43cc7df44aae0e21ed2e743218b876de3f38035683d30bd8a3828e" +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2 1.0.29", + "quote 1.0.9", + "syn 1.0.76", +] + [[package]] name = "num-traits" version = "0.2.14" @@ -2260,7 +2536,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca565a7df06f3d4b485494f25ba05da1435950f4dc263440eda7a6fa9b8e36e4" dependencies = [ "derivative", - "num_enum_derive", + "num_enum_derive 0.4.3", +] + +[[package]] +name = "num_enum" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9bd055fb730c4f8f4f57d45d35cd6b3f0980535b056dc7ff119cee6a66ed6f" +dependencies = [ + "derivative", + "num_enum_derive 0.5.4", ] [[package]] @@ -2269,7 +2555,19 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffa5a33ddddfee04c0283a7653987d634e880347e96b5b2ed64de07efb59db9d" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 0.1.5", + "proc-macro2 1.0.29", + "quote 1.0.9", + "syn 1.0.76", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9" +dependencies = [ + "proc-macro-crate 1.1.0", "proc-macro2 1.0.29", "quote 1.0.9", "syn 1.0.76", @@ -2348,6 +2646,38 @@ dependencies = [ "memchr", ] +[[package]] +name = "oboe" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e15e22bc67e047fe342a32ecba55f555e3be6166b04dd157cd0f803dfa9f48e1" +dependencies = [ + "jni", + "ndk 0.4.0", + "ndk-glue 0.4.0", + "num-derive", + "num-traits", + "oboe-sys", +] + +[[package]] +name = "oboe-sys" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "338142ae5ab0aaedc8275aa8f67f460e43ae0fca76a695a742d56da0a269eadc" +dependencies = [ + "cc", +] + +[[package]] +name = "ogg" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6951b4e8bf21c8193da321bcce9c9dd2e13c858fe078bf9054a288b419ae5d6e" +dependencies = [ + "byteorder", +] + [[package]] name = "once_cell" version = "1.8.0" @@ -2476,6 +2806,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -2671,6 +3007,16 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-crate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +dependencies = [ + "thiserror", + "toml", +] + [[package]] name = "proc-macro-error" version = "0.4.12" @@ -3476,10 +3822,12 @@ dependencies = [ "roc_solve", "roc_types", "roc_unify", + "rodio", "ropey", "serde", "snafu", "tempfile", + "threadpool", "uuid", "ven_graph", "wgpu", @@ -3824,6 +4172,19 @@ dependencies = [ "snafu", ] +[[package]] +name = "rodio" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d98f5e557b61525057e2bc142c8cd7f0e70d75dc32852309bec440e6e046bf9" +dependencies = [ + "claxon", + "cpal", + "hound", + "lewton", + "minimp3", +] + [[package]] name = "ropey" version = "1.3.1" @@ -4075,6 +4436,12 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + [[package]] name = "siphasher" version = "0.3.7" @@ -4107,6 +4474,17 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" +[[package]] +name = "slice-deque" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31ef6ee280cdefba6d2d0b4b78a84a1c1a3f3a4cec98c2d4231c8bc225de0f25" +dependencies = [ + "libc", + "mach", + "winapi 0.3.9", +] + [[package]] name = "slotmap" version = "1.0.6" @@ -4212,6 +4590,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "stdweb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e" + [[package]] name = "strip-ansi-escapes" version = "0.1.1" @@ -4430,6 +4814,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + [[package]] name = "time" version = "0.1.43" @@ -4450,13 +4843,28 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinyvec" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "tokio" version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" dependencies = [ - "bytes", + "bytes 0.5.6", "fnv", "memchr", "num_cpus", @@ -5269,8 +5677,8 @@ dependencies = [ "log", "mio", "mio-extras", - "ndk", - "ndk-glue", + "ndk 0.2.1", + "ndk-glue 0.2.1", "ndk-sys", "objc", "parking_lot", @@ -5338,7 +5746,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" dependencies = [ - "nom", + "nom 7.0.0", ] [[package]] diff --git a/Earthfile b/Earthfile index fe7629fb8a..815b328641 100644 --- a/Earthfile +++ b/Earthfile @@ -8,6 +8,7 @@ install-other-libs: FROM +prep-debian RUN apt -y install wget git RUN apt -y install libxcb-shape0-dev libxcb-xfixes0-dev # for editor clipboard + RUN apt -y install libasound2-dev # for editor sounds RUN apt -y install libunwind-dev pkg-config libx11-dev zlib1g-dev install-zig-llvm-valgrind-clippy-rustfmt: diff --git a/cli/benches/time_bench.rs b/cli/benches/time_bench.rs index f4c8f6e8be..0a99bfd154 100644 --- a/cli/benches/time_bench.rs +++ b/cli/benches/time_bench.rs @@ -1,7 +1,7 @@ use std::time::Duration; use cli_utils::bench_utils::{ - bench_cfold, bench_deriv, bench_nqueens, bench_quicksort, bench_rbtree_ck, bench_rbtree_delete, + bench_cfold, bench_deriv, bench_nqueens, bench_quicksort, bench_rbtree_ck, }; use criterion::{measurement::WallTime, BenchmarkGroup, Criterion, SamplingMode}; diff --git a/editor/Cargo.toml b/editor/Cargo.toml index d24dadded6..c32c9372f7 100644 --- a/editor/Cargo.toml +++ b/editor/Cargo.toml @@ -55,6 +55,8 @@ nonempty = "0.6.0" tempfile = "3.2.0" uuid = { version = "0.8", features = ["v4"] } fs_extra = "1.2.0" +rodio = "0.14.0" +threadpool = "1.8.1" [dependencies.bytemuck] version = "1.4" diff --git a/editor/src/editor/keyboard_input.rs b/editor/src/editor/keyboard_input.rs index 95538347a3..f1dad9a2af 100644 --- a/editor/src/editor/keyboard_input.rs +++ b/editor/src/editor/keyboard_input.rs @@ -43,11 +43,7 @@ pub fn handle_keydown( } } - A | S | R | Home | End => pass_keydown_to_focused(&modifiers, virtual_keycode, app_model)?, - - F11 => pass_keydown_to_focused(&modifiers, virtual_keycode, app_model)?, - - _ => (), + _ => pass_keydown_to_focused(&modifiers, virtual_keycode, app_model)?, } Ok(()) diff --git a/editor/src/editor/mod.rs b/editor/src/editor/mod.rs index f776acc44c..64903cd2f4 100644 --- a/editor/src/editor/mod.rs +++ b/editor/src/editor/mod.rs @@ -8,6 +8,7 @@ mod mvc; mod render_ast; mod render_debug; mod resources; +mod sound; mod style; mod theme; mod util; diff --git a/editor/src/editor/mvc/app_model.rs b/editor/src/editor/mvc/app_model.rs index b537e7a34f..357ab617de 100644 --- a/editor/src/editor/mvc/app_model.rs +++ b/editor/src/editor/mvc/app_model.rs @@ -8,11 +8,12 @@ use crate::editor::ed_error::{ }; use copypasta::{ClipboardContext, ClipboardProvider}; use std::fmt; +use threadpool::ThreadPool; -#[derive(Debug)] pub struct AppModel<'a> { pub ed_model_opt: Option>, pub clipboard_opt: Option, + pub sound_thread_pool: ThreadPool, // thread is blocked while sound is played, hence the threadpool } impl<'a> AppModel<'a> { @@ -20,6 +21,7 @@ impl<'a> AppModel<'a> { AppModel { ed_model_opt, clipboard_opt: AppModel::init_clipboard_opt(), + sound_thread_pool: ThreadPool::new(7), // can play up to 7 sounds simultaneously } } diff --git a/editor/src/editor/mvc/app_update.rs b/editor/src/editor/mvc/app_update.rs index 1b6ef6bd60..57430f9390 100644 --- a/editor/src/editor/mvc/app_update.rs +++ b/editor/src/editor/mvc/app_update.rs @@ -41,7 +41,11 @@ pub fn pass_keydown_to_focused( ) -> EdResult<()> { if let Some(ref mut ed_model) = app_model.ed_model_opt { if ed_model.has_focus { - ed_model.ed_handle_key_down(modifiers, virtual_keycode)?; + ed_model.ed_handle_key_down( + modifiers, + virtual_keycode, + &mut app_model.sound_thread_pool, + )?; } } diff --git a/editor/src/editor/mvc/ed_update.rs b/editor/src/editor/mvc/ed_update.rs index a0384d0bc0..4459de611b 100644 --- a/editor/src/editor/mvc/ed_update.rs +++ b/editor/src/editor/mvc/ed_update.rs @@ -7,10 +7,6 @@ use crate::editor::code_lines::CodeLines; use crate::editor::ed_error::EdResult; use crate::editor::ed_error::MissingSelection; use crate::editor::grid_node_map::GridNodeMap; -/*use crate::editor::markup::attribute::Attributes; -use crate::editor::markup::nodes; -use crate::editor::markup::nodes::MarkupNode; -use crate::editor::markup::nodes::EQUALS;*/ use crate::editor::mvc::app_update::InputOutcome; use crate::editor::mvc::ed_model::EdModel; use crate::editor::mvc::ed_model::SelectedBlock; @@ -26,18 +22,7 @@ use crate::editor::mvc::string_update::start_new_string; use crate::editor::mvc::string_update::update_small_string; use crate::editor::mvc::string_update::update_string; use crate::editor::mvc::tld_value_update::{start_new_tld_value, update_tld_val_name}; -/*use crate::editor::slow_pool::MarkNodeId; -use crate::editor::slow_pool::SlowPool; -use crate::editor::syntax_highlight::HighlightStyle; -use crate::lang::ast::Def2; -use crate::lang::ast::DefId; -use crate::lang::ast::{Expr2, ExprId}; -use crate::lang::constrain::constrain_expr; -use crate::lang::parse::ASTNodeId; -use crate::lang::pool::Pool; -use crate::lang::pool::PoolStr; -use crate::lang::types::Type2; -use crate::lang::{constrain::Constraint, solve};*/ +use crate::editor::sound::play_sound; use crate::ui::text::caret_w_select::CaretWSelect; use crate::ui::text::lines::MoveCaretFun; use crate::ui::text::selection::validate_raw_sel; @@ -77,6 +62,7 @@ use roc_types::solved_types::Solved; use roc_types::subs::{Subs, Variable}; use roc_types::{pretty_print::content_to_string, subs::VarStore}; use snafu::OptionExt; +use threadpool::ThreadPool; use winit::event::VirtualKeyCode; use VirtualKeyCode::*; @@ -537,6 +523,7 @@ impl<'a> EdModel<'a> { &mut self, modifiers: &Modifiers, virtual_keycode: VirtualKeyCode, + sound_thread_pool: &mut ThreadPool, ) -> EdResult<()> { match virtual_keycode { Left => self.move_caret_left(modifiers)?, @@ -573,6 +560,11 @@ impl<'a> EdModel<'a> { self.show_debug_view = !self.show_debug_view; self.dirty = true; } + F12 => { + sound_thread_pool.execute(move || { + play_sound("./editor/src/editor/resources/sounds/bell_sound.mp3"); + }); + } _ => (), } @@ -1254,6 +1246,7 @@ pub mod test_ed_update { use crate::window::keyboard_input::Modifiers; use bumpalo::Bump; use roc_module::symbol::ModuleIds; + use threadpool::ThreadPool; use winit::event::VirtualKeyCode::*; fn ed_res_to_res(ed_res: EdResult) -> Result { @@ -2663,7 +2656,7 @@ pub mod test_ed_update { } for _ in 0..repeats { - ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up)?; + ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up, &mut ThreadPool::new(1))?; } let mut post_lines = ui_res_to_res(ed_model_to_dsl(&ed_model))?; @@ -3240,7 +3233,7 @@ pub mod test_ed_update { )?; for _ in 0..repeats { - ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up)?; + ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up, &mut ThreadPool::new(1))?; } move_caret_fun(&mut ed_model, &no_mods())?; @@ -3404,7 +3397,7 @@ pub mod test_ed_update { )?; for _ in 0..repeats { - ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up)?; + ed_model.ed_handle_key_down(&ctrl_cmd_shift(), Up, &mut ThreadPool::new(1))?; } handle_new_char(&'\u{8}', &mut ed_model)?; // \u{8} is the char for backspace on linux diff --git a/editor/src/editor/resources/sounds/bell_sound.mp3 b/editor/src/editor/resources/sounds/bell_sound.mp3 new file mode 100644 index 0000000000..c18b130858 Binary files /dev/null and b/editor/src/editor/resources/sounds/bell_sound.mp3 differ diff --git a/editor/src/editor/sound.rs b/editor/src/editor/sound.rs new file mode 100644 index 0000000000..76a9994de6 --- /dev/null +++ b/editor/src/editor/sound.rs @@ -0,0 +1,45 @@ +use rodio::{Decoder, OutputStream, Sink}; +use std::fs::File; +use std::io::BufReader; + +pub(crate) fn play_sound(sound_path_str: &str) { + let out_stream_res = OutputStream::try_default(); + + match out_stream_res { + Ok((_, out_stream_handle)) => match Sink::try_new(&out_stream_handle) { + Ok(sink) => match File::open(sound_path_str) { + Ok(file) => { + let reader = BufReader::new(file); + + match Decoder::new(reader) { + Ok(decoder) => { + sink.append(decoder); + sink.sleep_until_end(); + } + Err(e) => { + println!("Failed to create Decoder from BufReader from sound file at {}. Error message: {:?}", sound_path_str, e); + } + } + } + Err(e) => { + println!( + "Failed to open sound file at {}. Error message: {}", + sound_path_str, e + ); + } + }, + Err(e) => { + println!( + "Failed to create Sink to play sound. Error message: {:?}", + e + ); + } + }, + Err(e) => { + println!( + "Failed to create OutputStream to play sound. Error message: {:?}", + e + ); + } + } +}