From ba750a2d18afe6e368146eceb2d98c08bd2a219d Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 5 Mar 2023 20:18:06 +1100 Subject: [PATCH] vst + ui!!! --- .gitmodules | 3 + Cargo.lock | 607 ++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 3 +- baseview | 1 + gb-vst/Cargo.toml | 3 + gb-vst/src/lib.rs | 84 +++---- gb-vst/src/ui.rs | 125 ++++++++++ nih-plug | 2 +- vst_install.sh | 1 + 9 files changed, 769 insertions(+), 60 deletions(-) create mode 160000 baseview create mode 100644 gb-vst/src/ui.rs create mode 100755 vst_install.sh diff --git a/.gitmodules b/.gitmodules index f75411a..94d8a5c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "nih-plug"] path = nih-plug url = https://github.com/italicsjenga/nih-plug +[submodule "baseview"] + path = baseview + url = https://github.com/italicsjenga/baseview diff --git a/Cargo.lock b/Cargo.lock index 4999b32..4e6de82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "alsa" version = "0.7.0" @@ -39,6 +50,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.69" @@ -51,6 +71,21 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344" +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "ash" +version = "0.37.2+1.3.238" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28bf19c1f0a470be5fbf7522a308a05df06610252c5bcf5143e1b23f629a9a03" +dependencies = [ + "libloading", +] + [[package]] name = "assert_no_alloc" version = "1.1.2" @@ -114,6 +149,24 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "baseview" +version = "0.1.0" +dependencies = [ + "cocoa", + "core-foundation", + "keyboard-types", + "nix 0.22.3", + "objc", + "raw-window-handle 0.5.0", + "rtrb", + "uuid 0.8.2", + "winapi", + "x11", + "xcb", + "xcb-util", +] + [[package]] name = "bindgen" version = "0.61.0" @@ -134,24 +187,63 @@ dependencies = [ "syn", ] +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "bumpalo" version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +[[package]] +name = "bytemuck" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + [[package]] name = "cc" version = "1.0.79" @@ -182,6 +274,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "clang-sys" version = "1.6.0" @@ -245,6 +343,47 @@ dependencies = [ "cc", ] +[[package]] +name = "cocoa" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a" +dependencies = [ + "bitflags", + "block", + "cocoa-foundation", + "core-foundation", + "core-graphics", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "cocoa-foundation" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" +dependencies = [ + "bitflags", + "block", + "core-foundation", + "core-graphics-types", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "combine" version = "4.6.6" @@ -277,6 +416,31 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "core-graphics" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +dependencies = [ + "bitflags", + "core-foundation", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" +dependencies = [ + "bitflags", + "core-foundation", + "foreign-types", + "libc", +] + [[package]] name = "coreaudio-rs" version = "0.11.2" @@ -406,6 +570,17 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" +[[package]] +name = "d3d12" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "827914e1f53b1e0e025ecd3d967a7836b7bcb54520f90e21ef8df7b4d88a2759" +dependencies = [ + "bitflags", + "libloading", + "winapi", +] + [[package]] name = "dasp_sample" version = "0.11.0" @@ -469,6 +644,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "futures" version = "0.3.26" @@ -558,6 +748,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "gb-emu" version = "0.1.0" @@ -603,7 +802,7 @@ dependencies = [ "fnv", "gilrs-core", "log", - "uuid", + "uuid 1.3.0", "vec_map", ] @@ -620,7 +819,7 @@ dependencies = [ "libudev-sys", "log", "nix 0.25.1", - "uuid", + "uuid 1.3.0", "vec_map", "wasm-bindgen", "web-sys", @@ -639,6 +838,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "glow" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8bd5877156a19b8ac83a29b2306fe20537429d318f3ff0a1a2119f8d9c61919" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "goblin" version = "0.6.1" @@ -650,11 +861,53 @@ dependencies = [ "scroll", ] +[[package]] +name = "gpu-alloc" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc59e5f710e310e76e6707f86c561dd646f69a8876da9131703b2f717de818d" +dependencies = [ + "bitflags", + "gpu-alloc-types", +] + +[[package]] +name = "gpu-alloc-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54804d0d6bc9d7f26db4eaec1ad10def69b599315f487d32c334a80d1efe67a5" +dependencies = [ + "bitflags", +] + +[[package]] +name = "gpu-descriptor" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b0c02e1ba0bdb14e965058ca34e09c020f8e507a760df1121728e0aef68d57a" +dependencies = [ + "bitflags", + "gpu-descriptor-types", + "hashbrown", +] + +[[package]] +name = "gpu-descriptor-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126" +dependencies = [ + "bitflags", +] + [[package]] name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] [[package]] name = "heck" @@ -677,6 +930,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +[[package]] +name = "hexf-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" + [[package]] name = "indexmap" version = "1.9.2" @@ -742,9 +1001,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "jni" @@ -798,6 +1057,26 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "keyboard-types" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7668b7cff6a51fe61cdde64cd27c8a220786f399501b57ebe36f7d8112fd68" +dependencies = [ + "bitflags", +] + +[[package]] +name = "khronos-egl" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3" +dependencies = [ + "libc", + "libloading", + "pkg-config", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -912,6 +1191,20 @@ dependencies = [ "autocfg", ] +[[package]] +name = "metal" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de11355d1f6781482d027a3b4d4de7825dcedb197bf573e0596d00008402d060" +dependencies = [ + "bitflags", + "block", + "core-graphics-types", + "foreign-types", + "log", + "objc", +] + [[package]] name = "midi-consts" version = "0.1.0" @@ -959,6 +1252,26 @@ dependencies = [ "adler", ] +[[package]] +name = "naga" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "262d2840e72dbe250e8cf2f522d080988dfca624c4112c096238a4845f591707" +dependencies = [ + "bit-set", + "bitflags", + "codespan-reporting", + "hexf-parse", + "indexmap", + "log", + "num-traits", + "rustc-hash", + "spirv", + "termcolor", + "thiserror", + "unicode-xid", +] + [[package]] name = "ndk" version = "0.7.0" @@ -1025,7 +1338,7 @@ dependencies = [ "nih_plug_derive", "objc", "parking_lot", - "raw-window-handle 0.4.3", + "raw-window-handle 0.5.0", "serde", "serde_json", "vst3-sys", @@ -1053,6 +1366,19 @@ dependencies = [ "toml", ] +[[package]] +name = "nix" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset 0.6.5", +] + [[package]] name = "nix" version = "0.24.3" @@ -1156,6 +1482,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" dependencies = [ "malloc_buf", + "objc_exception", +] + +[[package]] +name = "objc_exception" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" +dependencies = [ + "cc", ] [[package]] @@ -1259,6 +1595,20 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pixels" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5169d2d398c75596005313afae6b4b26cb14a22210f148a0183de95b45795a5" +dependencies = [ + "bytemuck", + "pollster", + "raw-window-handle 0.5.0", + "thiserror", + "ultraviolet", + "wgpu", +] + [[package]] name = "pkg-config" version = "0.3.26" @@ -1271,6 +1621,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +[[package]] +name = "pollster" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da3b0203fd7ee5720aa0b5e790b591aa5d3f41c3ed2c34a3a393382198af2f7" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1320,6 +1676,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "profiling" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74605f360ce573babfe43964cbe520294dcb081afbf8c108fc6e23036b4da2df" + [[package]] name = "quote" version = "1.0.23" @@ -1359,6 +1721,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "range-alloc" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab" + [[package]] name = "raw-window-handle" version = "0.3.4" @@ -1420,6 +1788,12 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "renderdoc-sys" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" + [[package]] name = "ringbuf" version = "0.3.2" @@ -1429,6 +1803,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "rtrb" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99e704dd104faf2326a320140f70f0b736d607c1caa1b1748a6c568a79819109" +dependencies = [ + "cache-padded", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -1443,9 +1826,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.36.8" +version = "0.36.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" dependencies = [ "bitflags", "errno", @@ -1457,9 +1840,18 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "safe_arch" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "794821e4ccb0d9f979512f9c1973480123f9bd62a90d74ab0f9426fcf8f4a529" +dependencies = [ + "bytemuck", +] [[package]] name = "same-file" @@ -1591,12 +1983,31 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slotmap" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +dependencies = [ + "version_check", +] + [[package]] name = "smallvec" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "spirv" +version = "0.2.0+1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830" +dependencies = [ + "bitflags", + "num-traits", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -1726,10 +2137,40 @@ dependencies = [ ] [[package]] -name = "unicode-ident" -version = "1.0.6" +name = "ultraviolet" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "bf2728f3858937f50df6d92b741f53ef8fd5b5ae23b03b73fb9ac891e980df3b" +dependencies = [ + "wide", +] + +[[package]] +name = "unicode-ident" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775c11906edafc97bc378816b94585fbd9a054eabaf86fdd0ced94af449efab7" + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", +] [[package]] name = "uuid" @@ -1759,7 +2200,10 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "vst" version = "0.1.0" dependencies = [ + "baseview", + "gb-emu-lib", "nih_plug", + "pixels", ] [[package]] @@ -1965,6 +2409,110 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wgpu" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81f643110d228fd62a60c5ed2ab56c4d5b3704520bd50561174ec4ec74932937" +dependencies = [ + "arrayvec", + "js-sys", + "log", + "naga", + "parking_lot", + "raw-window-handle 0.5.0", + "smallvec", + "static_assertions", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "wgpu-core", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-core" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6000d1284ef8eec6076fd5544a73125fd7eb9b635f18dceeb829d826f41724ca" +dependencies = [ + "arrayvec", + "bit-vec", + "bitflags", + "cfg_aliases", + "codespan-reporting", + "fxhash", + "log", + "naga", + "parking_lot", + "profiling", + "raw-window-handle 0.5.0", + "smallvec", + "thiserror", + "web-sys", + "wgpu-hal", + "wgpu-types", +] + +[[package]] +name = "wgpu-hal" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cc320a61acb26be4f549c9b1b53405c10a223fbfea363ec39474c32c348d12f" +dependencies = [ + "android_system_properties", + "arrayvec", + "ash", + "bit-set", + "bitflags", + "block", + "core-graphics-types", + "d3d12", + "foreign-types", + "fxhash", + "glow", + "gpu-alloc", + "gpu-descriptor", + "js-sys", + "khronos-egl", + "libloading", + "log", + "metal", + "naga", + "objc", + "parking_lot", + "profiling", + "range-alloc", + "raw-window-handle 0.5.0", + "renderdoc-sys", + "smallvec", + "thiserror", + "wasm-bindgen", + "web-sys", + "wgpu-types", + "winapi", +] + +[[package]] +name = "wgpu-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb6b28ef22cac17b9109b25b3bf8c9a103eeb293d7c5f78653979b09140375f6" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wide" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b689b6c49d6549434bf944e6b0f39238cf63693cb7a147e9d887507fffa3b223" +dependencies = [ + "bytemuck", + "safe_arch", +] + [[package]] name = "widestring" version = "1.0.2" @@ -2109,13 +2657,23 @@ checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "winnow" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faf09497b8f8b5ac5d3bb4d05c0a99be20f26fd3d5f2db7b0716e946d5103658" +checksum = "c95fb4ff192527911dd18eb138ac30908e7165b8944e528b6af93aa4c842d345" dependencies = [ "memchr", ] +[[package]] +name = "x11" +version = "2.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "x11-dl" version = "2.21.0" @@ -2127,6 +2685,27 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "xcb" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62056f63138b39116f82a540c983cc11f1c90cd70b3d492a70c25eaa50bd22a6" +dependencies = [ + "libc", + "log", + "x11", +] + +[[package]] +name = "xcb-util" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43893e47f27bf7d81d489feef3a0e34a457e90bc314b7e74ad9bb3980e4c1c48" +dependencies = [ + "libc", + "xcb", +] + [[package]] name = "xcursor" version = "0.3.4" diff --git a/Cargo.toml b/Cargo.toml index 6f7835e..d661412 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] members = ["lib", "gb-emu", "gb-vst", "gb-vst/xtask"] default-members = ["gb-emu"] -exclude = ["./nih-plug"] \ No newline at end of file +exclude = ["./nih-plug"] +resolver = "2" \ No newline at end of file diff --git a/baseview b/baseview new file mode 160000 index 0000000..a6e07b7 --- /dev/null +++ b/baseview @@ -0,0 +1 @@ +Subproject commit a6e07b7ea78f3febe8c2434998be65cb4ce50094 diff --git a/gb-vst/Cargo.toml b/gb-vst/Cargo.toml index ecec676..4cbe484 100644 --- a/gb-vst/Cargo.toml +++ b/gb-vst/Cargo.toml @@ -11,4 +11,7 @@ crate-type = ["cdylib", "rlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +gb-emu-lib = { path = "../lib" } nih_plug = { path = "../nih-plug", features = ["assert_process_allocs"] } +baseview = { path = "../baseview" } +pixels = "0.11.0" diff --git a/gb-vst/src/lib.rs b/gb-vst/src/lib.rs index e66ac21..29da896 100644 --- a/gb-vst/src/lib.rs +++ b/gb-vst/src/lib.rs @@ -1,6 +1,14 @@ -use std::sync::Arc; - use nih_plug::prelude::*; +use std::sync::Arc; +use ui::Emulator; + +mod ui; + +const WIDTH: u32 = 320; +const HEIGHT: u32 = 240; + +#[derive(Params, Default)] +struct EmuParams {} #[derive(Default)] struct GameboyEmu {} @@ -16,67 +24,55 @@ impl Plugin for GameboyEmu { const VERSION: &'static str = "0.1"; - const AUDIO_IO_LAYOUTS: &'static [AudioIOLayout] = &[ - AudioIOLayout { - main_input_channels: NonZeroU32::new(2), - main_output_channels: NonZeroU32::new(2), + const AUDIO_IO_LAYOUTS: &'static [AudioIOLayout] = &[AudioIOLayout { + main_input_channels: NonZeroU32::new(2), + main_output_channels: NonZeroU32::new(2), - aux_input_ports: &[], - aux_output_ports: &[], + aux_input_ports: &[], + aux_output_ports: &[], - // Individual ports and the layout as a whole can be named here. By default these names - // are generated as needed. This layout will be called 'Stereo', while the other one is - // given the name 'Mono' based no the number of input and output channels. - names: PortNames::const_default(), - }, - AudioIOLayout { - main_input_channels: NonZeroU32::new(1), - main_output_channels: NonZeroU32::new(1), - ..AudioIOLayout::const_default() - }, - ]; + // Individual ports and the layout as a whole can be named here. By default these names + // are generated as needed. This layout will be called 'Stereo', while the other one is + // given the name 'Mono' based no the number of input and output channels. + names: PortNames::const_default(), + }]; type SysExMessage = (); type BackgroundTask = (); fn params(&self) -> Arc { - todo!() + Arc::new(EmuParams::default()) } fn process( &mut self, - buffer: &mut Buffer, - aux: &mut AuxiliaryBuffers, - context: &mut impl ProcessContext, + _buffer: &mut Buffer, + _: &mut AuxiliaryBuffers, + _: &mut impl ProcessContext, ) -> ProcessStatus { - todo!() + ProcessStatus::Normal + } + + fn editor(&self, _: AsyncExecutor) -> Option> { + Some(Box::new(Emulator::new())) + } + + fn initialize( + &mut self, + _audio_io_layout: &AudioIOLayout, + _buffer_config: &BufferConfig, + _context: &mut impl InitContext, + ) -> bool { + true } } impl Vst3Plugin for GameboyEmu { - const VST3_CLASS_ID: [u8; 16] = *b"alexjankagbemul8"; + const VST3_CLASS_ID: [u8; 16] = *b"alexjankagbemula"; const VST3_SUBCATEGORIES: &'static [Vst3SubCategory] = - &[Vst3SubCategory::External, Vst3SubCategory::Instrument]; + &[Vst3SubCategory::Distortion, Vst3SubCategory::Dynamics]; } -impl ClapPlugin for GameboyEmu { - const CLAP_ID: &'static str = "com.alexjanka.GameboyEmu-rs"; - - const CLAP_DESCRIPTION: Option<&'static str> = None; - - const CLAP_MANUAL_URL: Option<&'static str> = None; - - const CLAP_SUPPORT_URL: Option<&'static str> = None; - - const CLAP_FEATURES: &'static [ClapFeature] = &[ - ClapFeature::AudioEffect, - ClapFeature::Stereo, - ClapFeature::Mono, - ClapFeature::Utility, - ]; -} - -// nih_export_clap!(GameboyEmu); nih_export_vst3!(GameboyEmu); diff --git a/gb-vst/src/ui.rs b/gb-vst/src/ui.rs new file mode 100644 index 0000000..d64767a --- /dev/null +++ b/gb-vst/src/ui.rs @@ -0,0 +1,125 @@ +use std::sync::Arc; + +use baseview::{ + Event, EventStatus, MouseButton, MouseEvent, Size, Window, WindowEvent, WindowHandler, + WindowInfo, WindowOpenOptions, +}; +use nih_plug::prelude::*; +use pixels::{Pixels, SurfaceTexture}; + +use crate::{HEIGHT, WIDTH}; + +pub struct Emulator {} + +impl Emulator { + pub fn new() -> Self { + Self {} + } +} + +impl Editor for Emulator { + fn spawn( + &self, + parent: ParentWindowHandle, + _context: Arc, + ) -> Box { + Window::open_parented( + &parent, + WindowOpenOptions { + title: String::from("gb-emu"), + size: Size::new(WIDTH as f64, HEIGHT as f64), + scale: baseview::WindowScalePolicy::SystemScaleFactor, + }, + EmulatorWindow::new, + ); + Box::new(Self::new()) + } + + fn size(&self) -> (u32, u32) { + (WIDTH, HEIGHT) + } + + fn set_scale_factor(&self, _factor: f32) -> bool { + true + } + + fn param_value_changed(&self, _id: &str, _normalized_value: f32) {} + + fn param_modulation_changed(&self, _id: &str, _modulation_offset: f32) {} + + fn param_values_changed(&self) {} +} + +pub struct EmulatorWindow { + pix: Pixels, + current_colour: [u8; 4], +} + +impl EmulatorWindow { + fn new(window: &mut Window) -> Self { + let info = WindowInfo::from_logical_size(Size::new(WIDTH as f64, HEIGHT as f64), 1.); + + let mut pix = init_pixbuf(info, window); + + let current_colour: [u8; 4] = [0xFF, 0x0, 0x0, 0xFF]; + + for pixel in pix.get_frame_mut().chunks_exact_mut(4) { + pixel.copy_from_slice(¤t_colour); + } + + Self { + pix, + current_colour, + } + } + + fn update_pixbuf(&mut self) { + self.current_colour = rotate_colour(&self.current_colour); + self.render_pixbuf(); + println!("colour now {:#?}", self.current_colour); + } + + fn render_pixbuf(&mut self) { + for pixel in self.pix.get_frame_mut().chunks_exact_mut(4) { + pixel.copy_from_slice(&self.current_colour); + } + } +} + +fn init_pixbuf(info: WindowInfo, window: &mut Window) -> Pixels { + let physical_size = info.physical_size(); + pixels::Pixels::new( + physical_size.width, + physical_size.height, + SurfaceTexture::new(physical_size.width, physical_size.height, window), + ) + .unwrap() +} + +fn rotate_colour(current: &[u8; 4]) -> [u8; 4] { + [current[1], current[2], current[0], current[3]] +} + +impl WindowHandler for EmulatorWindow { + fn on_frame(&mut self, _window: &mut Window) { + self.pix.render().unwrap(); + } + + fn on_event(&mut self, window: &mut Window, event: baseview::Event) -> EventStatus { + if let Event::Window(WindowEvent::Resized(info)) = event { + self.pix = init_pixbuf(info, window); + self.update_pixbuf(); + return EventStatus::Captured; + } + if let Event::Mouse(MouseEvent::ButtonPressed { + button: MouseButton::Left, + .. + }) = event + { + println!("click!"); + self.update_pixbuf(); + return EventStatus::Captured; + } + EventStatus::Ignored + } +} diff --git a/nih-plug b/nih-plug index ae3356d..8ada339 160000 --- a/nih-plug +++ b/nih-plug @@ -1 +1 @@ -Subproject commit ae3356dca8cc975a0dd3d390a911f2bf56cc5ff5 +Subproject commit 8ada33953924c7201c977c2e09546bd9c9bdfe56 diff --git a/vst_install.sh b/vst_install.sh new file mode 100755 index 0000000..d89caf9 --- /dev/null +++ b/vst_install.sh @@ -0,0 +1 @@ +cargo xtask bundle-universal vst --release && rm -r $VST3_DEV_INSTALL/gb.vst3 && cp -r target/bundled/vst.vst3 $VST3_DEV_INSTALL/gb.vst3 && echo "Copied to $VST3_DEV_INSTALL/gb.vst3"