diff --git a/Cargo.lock b/Cargo.lock index 2758f9b..681071e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,38 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" +[[package]] +name = "alsa" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3f93573e7ddb15145d27c58c0fa0a452faad9f5452ac17ed4554ea035ea9b71" +dependencies = [ + "alsa-sys", + "bitflags", + "cfg-if", + "libc", +] + +[[package]] +name = "alsa-sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0320138053ef93099f168102c37b46ac0b9c53affc56ef7696633ad5477e2be" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "android-build" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fc9904ad2ad097c3c1cfe2eacaaf0fc24710936fa9ed941cb310b7c6ed2ab7" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "autocfg" version = "1.5.1" @@ -47,6 +79,27 @@ dependencies = [ "serde_core", ] +[[package]] +name = "block2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" +dependencies = [ + "objc2", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + [[package]] name = "cassowary" version = "0.3.0" @@ -62,12 +115,38 @@ dependencies = [ "rustversion", ] +[[package]] +name = "cc" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6651c9ed80effdc7db0ff72512157f901af5e3549e341e24b1dd4887d836d838" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" +[[package]] +name = "combine" +version = "4.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfc320937d09e6de266b31b9afb480f197d7a861be86be7cb2ea7e5d1bfffc5e" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "compact_str" version = "0.8.2" @@ -83,6 +162,43 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "coremidi" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a57ede822fdaf19280cf1320a5a5d3a522c75c910d01750af1e8122b6ad2595b" +dependencies = [ + "block2", + "core-foundation", + "core-foundation-sys", + "coremidi-sys", +] + +[[package]] +name = "coremidi-sys" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a2b8c2cefa9a8f712213c5a1383ffe428efc8f1a1fd1e2f757be94daf7e256a" +dependencies = [ + "core-foundation-sys", +] + [[package]] name = "crossterm" version = "0.28.1" @@ -148,6 +264,16 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +[[package]] +name = "dlopen2" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60768c353d76ba6dd1b6332a5dbbdd3bc2dddadc2935f4cc6a9d0f17ca8ecb6a" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "either" version = "1.18.0" @@ -178,7 +304,7 @@ dependencies = [ "rustix 1.1.5", "serde", "tempfile", - "thiserror", + "thiserror 2.0.21", "toml", "toml_edit", ] @@ -189,7 +315,7 @@ version = "0.1.0" dependencies = [ "proptest", "regex", - "thiserror", + "thiserror 2.0.21", ] [[package]] @@ -209,6 +335,12 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" +[[package]] +name = "find-msvc-tools" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484" + [[package]] name = "fnv" version = "1.0.7" @@ -221,6 +353,30 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -244,6 +400,12 @@ dependencies = [ "r-efi 6.0.0", ] +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + [[package]] name = "hashbrown" version = "0.15.5" @@ -320,12 +482,103 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "java-locator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c46c1fe465c59b1474e665e85e1256c3893dd00927b8d55f63b09044c1e64f" +dependencies = [ + "glob", +] + +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "java-locator", + "jni-sys 0.3.1", + "libloading", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-min-helper" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "913370a00ba1851b0f3369b49d0f3e745da2d20d3f15ecc296a64234ccda45f7" +dependencies = [ + "android-build", + "dlopen2", + "jni", + "libc", + "log", + "ndk-context", + "process_path", +] + +[[package]] +name = "jni-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258" +dependencies = [ + "jni-sys 0.4.1", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.119", +] + +[[package]] +name = "js-sys" +version = "0.3.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + [[package]] name = "libc" version = "0.2.190" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78" +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + [[package]] name = "libpulse-binding" version = "2.30.1" @@ -400,6 +653,29 @@ name = "midi" version = "0.1.0" dependencies = [ "fader-core", + "midir", + "thiserror 2.0.21", +] + +[[package]] +name = "midir" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea58b9250a667b032ff61fb1bf77aed74873152563f5cd613016dce4c821832" +dependencies = [ + "alsa", + "cc", + "coremidi", + "jni", + "jni-min-helper", + "js-sys", + "libc", + "log", + "ndk-context", + "parking_lot", + "wasm-bindgen", + "web-sys", + "windows", ] [[package]] @@ -414,6 +690,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + [[package]] name = "num-conv" version = "0.2.2" @@ -449,6 +731,21 @@ dependencies = [ "libc", ] +[[package]] +name = "objc2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08849bbd4767dfae9457696856ae1c84fe4e0281bbe4a7abff2d0e06fb7981f8" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + [[package]] name = "once_cell" version = "1.21.4" @@ -484,6 +781,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + [[package]] name = "pkg-config" version = "0.3.34" @@ -514,6 +817,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "process_path" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f676f11eb0b3e2ea0fbaee218fa6b806689e2297b8c8adc5bf73df465c4f6171" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "proptest" version = "1.11.0" @@ -709,6 +1022,15 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -754,6 +1076,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + [[package]] name = "signal-hook" version = "0.3.18" @@ -785,6 +1113,12 @@ dependencies = [ "libc", ] +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "smallvec" version = "1.16.2" @@ -860,13 +1194,33 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + [[package]] name = "thiserror" version = "2.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.21", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", ] [[package]] @@ -997,7 +1351,7 @@ version = "0.1.0" dependencies = [ "fader-core", "libpulse-binding", - "thiserror", + "thiserror 2.0.21", ] [[package]] @@ -1009,6 +1363,16 @@ dependencies = [ "libc", ] +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -1024,6 +1388,61 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasm-bindgen" +version = "0.2.129" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.129" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.129" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.6", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.129" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88261b9deccee56594c11a3460c462c41f58d148598fe70ad77070126a68aba4" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1040,25 +1459,138 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" +dependencies = [ + "windows-core", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-numerics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" +dependencies = [ + "windows-core", + "windows-link", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1070,34 +1602,76 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1110,24 +1684,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index 584b08e..9fd8e35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ fader-config = { path = "config" } fader-core = { path = "core" } midi = { path = "midi" } libpulse-binding = "2.30.1" +midir = "0.11.1" proptest = "1.11.0" ratatui = { version = "0.29.0", features = ["all-widgets", "serde"] } regex = "1.13.1" diff --git a/architecture.md b/architecture.md index 2aee7a6..77fb277 100644 --- a/architecture.md +++ b/architecture.md @@ -289,7 +289,7 @@ These are fit-for-purpose recommendations based on primary documentation, not be | Concern | Recommendation and tradeoff | Primary source | | --- | --- | --- | -| USB MIDI | `midir`; owns input/output connections, Linux transport support. Prefer this to hand-written ALSA MIDI FFI; supplement persistent identity separately. | [midir](https://docs.rs/midir/latest/midir/) | +| USB MIDI | `midir` 0.11.1 (MIT); owns input/output connections and uses ALSA on Linux. Prefer this to hand-written ALSA MIDI FFI; supplement persistent identity separately. It declares no MSRV, so the locked release is compiled in the Rust 1.88 gate. | [midir](https://docs.rs/midir/0.11.1/midir/) | | Pulse protocol | `libpulse-binding`; exposes asynchronous introspection/control. Keep callbacks on an owned loop. Prefer this to parsing `pactl` output; simple playback APIs do not provide the control plane. | [libpulse-binding](https://docs.rs/libpulse-binding/latest/libpulse_binding/) | | Native PipeWire | Official `pipewire` Rust bindings; full native object access, with more SPA/graph complexity. Keep behind a feature and capability spike. | [pipewire-rs](https://pipewire.pages.freedesktop.org/pipewire-rs/pipewire/index.html) | | Hardware mixer | `alsa` for mixer controls and optional MIDI identity enrichment; feature-gated. No promise of application volume control. | [alsa::mixer](https://docs.rs/alsa/latest/alsa/mixer/index.html) | diff --git a/checklist.md b/checklist.md index 6631447..8d245ce 100644 --- a/checklist.md +++ b/checklist.md @@ -138,3 +138,47 @@ The main TUI is still explicitly backed by demo state at this milestone. Passing this checklist validates the real Pulse control boundary that will feed the server and live multi-application/group TUI; it does not yet validate MIDI or the final TUI-to-server path. + +# MIDI decode and input milestone checklist (Arch Linux) + +This section validates M5.1 against a real controller. It only reads MIDI input; +it does not change application audio, send MIDI output, or save an assignment. +Persistent device matching, hotplug recovery, and MIDI feedback are later +milestones. + +## MIDI preparation and discovery + +- [ ] Confirm the Arch ALSA userspace library is installed: + `sudo pacman -S --needed alsa-lib`. +- [ ] Connect the controller and run + `cargo run --locked -p midi --example midi_monitor -- list`. +- [ ] Confirm the controller appears with an `index`, backend `id`, and readable + `name`. Ignore `Midi Through` unless that is intentionally the input under + test. +- [ ] Record the controller model/firmware and its reported `id` and `name` for + the M5.2 identity spike. + +## Decode a real controller + +Replace `INDEX` with the controller index from the list command. + +- [ ] Run + `cargo run --locked -p midi --example midi_monitor -- watch INDEX 30`. +- [ ] Move an absolute fader or knob. Confirm `ControlChange` lines show the + expected 1-based channel and values spanning some or all of `0..127`. +- [ ] Press and release a note button. Confirm a nonzero note-on reports + `Press`, while note-off or note-on velocity zero reports `Release`. +- [ ] If the controller has a CC button, press and release it and confirm its + values move between nonzero and zero. CC button edge interpretation is tested + in the router even though the raw monitor intentionally displays CC values. +- [ ] If the controller sends MIDI clock or active sensing, confirm those + packets produce no lines and do not prevent supported controls from appearing. +- [ ] Confirm the command exits normally without `Malformed`, callback + disconnection, or `queue overflowed` errors. + +## Hardware-free verification + +- [ ] Run `cargo test --locked -p midi --all-targets --all-features`. +- [ ] Run `cargo test --locked -p midi --all-targets --no-default-features`. +- [ ] Confirm both pass. The second command proves decoding and binding remain + testable without an ALSA device or daemon. diff --git a/docs/build.md b/docs/build.md index de5e1e9..b1ab4ce 100644 --- a/docs/build.md +++ b/docs/build.md @@ -9,7 +9,7 @@ The default build includes the PulseAudio protocol adapter and links to libpulse. On a Debian-family Linux system, install: ```sh -sudo apt-get install build-essential pkg-config libpulse-dev +sudo apt-get install build-essential pkg-config libasound2-dev libpulse-dev rustup toolchain install 1.88.0 \ --profile minimal \ --component rustfmt \ @@ -21,7 +21,7 @@ On Arch Linux with PipeWire, install the client library, build tools, and the PulseAudio-compatible PipeWire service: ```sh -sudo pacman -S --needed base-devel pkgconf libpulse pipewire-audio pipewire-pulse wireplumber +sudo pacman -S --needed base-devel pkgconf alsa-lib libpulse pipewire-audio pipewire-pulse wireplumber pactl info ``` @@ -31,15 +31,21 @@ separate development package. The application communicates with PipeWire through `pipewire-pulse`; it does not require the standalone PulseAudio server. The Pulse adapter works with PulseAudio and PipeWire's pipewire-pulse -compatibility service. A build that deliberately excludes native audio -dependencies remains available: +compatibility service. MIDI input uses ALSA's sequencer API through `midir`; +PipeWire does not replace the `alsa-lib` build dependency. A build that +deliberately excludes native audio and MIDI dependencies remains available: ```sh cargo build --workspace --no-default-features --locked ``` -Future native PipeWire, ALSA, MIDI, and udev adapters will add their own -feature-gated development packages. +Future native PipeWire, ALSA mixer, and udev adapters will add their own +feature-gated development packages. The MIDI crate can also be checked without +its native transport while retaining byte decoding and routing: + +```sh +cargo check -p midi --no-default-features --locked +``` From a fresh checkout, use the tracked lockfile for reproducible resolution: diff --git a/midi/Cargo.toml b/midi/Cargo.toml index acea353..9cc9e49 100644 --- a/midi/Cargo.toml +++ b/midi/Cargo.toml @@ -7,5 +7,15 @@ license-file.workspace = true repository.workspace = true publish.workspace = true +[features] +default = ["midir"] +midir = ["dep:midir"] + [dependencies] fader-core.workspace = true +midir = { workspace = true, optional = true } +thiserror.workspace = true + +[[example]] +name = "midi_monitor" +required-features = ["midir"] diff --git a/midi/examples/midi_monitor.rs b/midi/examples/midi_monitor.rs new file mode 100644 index 0000000..f6360e3 --- /dev/null +++ b/midi/examples/midi_monitor.rs @@ -0,0 +1,64 @@ +use std::{ + error::Error, + io, + sync::mpsc::{self, RecvTimeoutError}, + time::{Duration, Instant}, +}; + +use fader_core::SurfaceId; +use midi::MidiInputCatalog; + +fn main() -> Result<(), Box> { + let mut arguments = std::env::args().skip(1); + let command = arguments.next().unwrap_or_else(|| "list".to_owned()); + let catalog = MidiInputCatalog::new("fader_master monitor")?; + let ports = catalog.ports()?; + if command == "list" { + for (index, port) in ports.iter().enumerate() { + println!("index={index} id={:?} name={:?}", port.id(), port.name()); + } + return Ok(()); + } + if command != "watch" { + return Err(invalid_input( + "usage: midi_monitor [list|watch INDEX [SECONDS]]", + )); + } + let index = arguments + .next() + .ok_or_else(|| invalid_input("missing port index"))? + .parse::()?; + let seconds = arguments.next().as_deref().unwrap_or("30").parse::()?; + let port = ports + .get(index) + .ok_or_else(|| invalid_input("port index is out of range"))?; + println!("watching id={:?} name={:?}", port.id(), port.name()); + + let (sender, receiver) = mpsc::sync_channel(128); + let connection = catalog.connect( + port, + "fader_master monitor input", + SurfaceId::new("monitor")?, + sender, + )?; + let deadline = Instant::now() + Duration::from_secs(seconds); + while let Some(remaining) = deadline.checked_duration_since(Instant::now()) { + match receiver.recv_timeout(remaining.min(Duration::from_millis(250))) { + Ok(event) => println!("{event:?}"), + Err(RecvTimeoutError::Timeout) => {} + Err(RecvTimeoutError::Disconnected) => { + return Err(invalid_input("MIDI input callback disconnected")); + } + } + } + if connection.overflowed() { + return Err(invalid_input( + "MIDI input queue overflowed; events require resync", + )); + } + Ok(()) +} + +fn invalid_input(message: &str) -> Box { + Box::new(io::Error::new(io::ErrorKind::InvalidInput, message)) +} diff --git a/midi/src/decode.rs b/midi/src/decode.rs new file mode 100644 index 0000000..42d2539 --- /dev/null +++ b/midi/src/decode.rs @@ -0,0 +1,107 @@ +use fader_core::{MidiChannel, MidiData}; +use thiserror::Error; + +/// Press/release semantics normalized across note and CC buttons. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum ButtonEdge { + Press, + Release, +} + +/// Supported MIDI 1.0 channel messages. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum MidiMessage { + ControlChange { + channel: MidiChannel, + number: MidiData, + value: MidiData, + }, + Note { + channel: MidiChannel, + number: MidiData, + velocity: MidiData, + edge: ButtonEdge, + }, +} + +/// Malformed bytes for a message type that fader_master otherwise supports. +#[derive(Clone, Copy, Debug, Error, Eq, PartialEq)] +pub enum DecodeError { + #[error("empty MIDI message")] + Empty, + #[error("MIDI message starts with data byte 0x{0:02x}; running status is unsupported")] + MissingStatus(u8), + #[error("MIDI status 0x{status:02x} requires {expected} bytes, received {actual}")] + Length { + status: u8, + expected: usize, + actual: usize, + }, + #[error("MIDI byte {position} contains a status bit: 0x{value:02x}")] + InvalidData { position: usize, value: u8 }, + #[error("unsupported MIDI status reached the channel decoder: 0x{0:02x}")] + UnsupportedStatus(u8), +} + +/// Decodes supported channel messages and ignores unrelated MIDI traffic. +/// +/// Clock, active-sensing, SysEx, program-change, pressure, and pitch messages +/// are deliberately outside the first controller profile and return `None`. +pub fn decode_message(bytes: &[u8]) -> Result, DecodeError> { + let Some(&status) = bytes.first() else { + return Err(DecodeError::Empty); + }; + if status & 0x80 == 0 { + return Err(DecodeError::MissingStatus(status)); + } + + match status & 0xf0 { + 0x80 | 0x90 | 0xb0 => decode_three_byte(status, bytes).map(Some), + _ => Ok(None), + } +} + +fn decode_three_byte(status: u8, bytes: &[u8]) -> Result { + if bytes.len() != 3 { + return Err(DecodeError::Length { + status, + expected: 3, + actual: bytes.len(), + }); + } + let first = data_byte(bytes[1], 1)?; + let second = data_byte(bytes[2], 2)?; + let channel = MidiChannel::new(u16::from(status & 0x0f) + 1) + .map_err(|_| DecodeError::MissingStatus(status))?; + match status & 0xf0 { + 0x80 => Ok(MidiMessage::Note { + channel, + number: first, + velocity: second, + edge: ButtonEdge::Release, + }), + 0x90 => Ok(MidiMessage::Note { + channel, + number: first, + velocity: second, + edge: if second.get() == 0 { + ButtonEdge::Release + } else { + ButtonEdge::Press + }, + }), + 0xb0 => Ok(MidiMessage::ControlChange { + channel, + number: first, + value: second, + }), + _ => Err(DecodeError::UnsupportedStatus(status)), + } +} + +fn data_byte(value: u8, position: usize) -> Result { + if value & 0x80 != 0 { + return Err(DecodeError::InvalidData { position, value }); + } + MidiData::new(u16::from(value)).map_err(|_| DecodeError::InvalidData { position, value }) +} diff --git a/midi/src/lib.rs b/midi/src/lib.rs index 2d21a0c..240bbd1 100644 --- a/midi/src/lib.rs +++ b/midi/src/lib.rs @@ -1,3 +1,15 @@ //! MIDI transport, device identity, bindings, and feedback adapters. #![forbid(unsafe_code)] + +mod decode; +mod router; +#[cfg(feature = "midir")] +mod transport; + +pub use decode::{ButtonEdge, DecodeError, MidiMessage, decode_message}; +pub use router::{MidiIntent, MidiRouter}; +#[cfg(feature = "midir")] +pub use transport::{ + InputPort, MidiInputCatalog, MidiInputConnection, MidiInputEvent, MidiTransportError, +}; diff --git a/midi/src/router.rs b/midi/src/router.rs new file mode 100644 index 0000000..d986a3c --- /dev/null +++ b/midi/src/router.rs @@ -0,0 +1,97 @@ +use std::collections::BTreeSet; + +use fader_core::{BindingAction, BindingKey, Bindings, FaderId, Gain, MessageKind, SurfaceId}; + +use crate::{ButtonEdge, MidiMessage}; + +/// Logical action emitted from one configured physical MIDI control. +#[derive(Clone, Debug, PartialEq)] +pub enum MidiIntent { + AbsoluteVolume { + surface: SurfaceId, + fader: FaderId, + gain: Gain, + }, + ToggleMute { + surface: SurfaceId, + fader: FaderId, + }, +} + +/// Surface-scoped binding lookup with duplicate-press suppression. +#[derive(Clone, Debug)] +pub struct MidiRouter { + bindings: Bindings, + pressed: BTreeSet, +} + +impl MidiRouter { + #[must_use] + pub fn new(bindings: Bindings) -> Self { + Self { + bindings, + pressed: BTreeSet::new(), + } + } + + /// Routes a decoded message. Unknown controls, releases, and repeated + /// button presses intentionally emit no logical action. + pub fn route(&mut self, surface: &SurfaceId, message: MidiMessage) -> Option { + let (channel, kind, number) = match message { + MidiMessage::ControlChange { + channel, number, .. + } => (channel, MessageKind::ControlChange, number), + MidiMessage::Note { + channel, number, .. + } => (channel, MessageKind::Note, number), + }; + let key = BindingKey { + surface: surface.clone(), + channel, + kind, + number, + }; + let binding = self.bindings.get(&key)?.clone(); + match (binding.action, message) { + (BindingAction::Volume, MidiMessage::ControlChange { value, .. }) => { + let gain = Gain::new(f64::from(value.get()) / 127.0).ok()?; + Some(MidiIntent::AbsoluteVolume { + surface: surface.clone(), + fader: binding.fader, + gain, + }) + } + (BindingAction::ToggleMute, MidiMessage::Note { edge, .. }) => { + self.route_button(surface, binding.fader, key, edge) + } + (BindingAction::ToggleMute, MidiMessage::ControlChange { value, .. }) => { + let edge = if value.get() == 0 { + ButtonEdge::Release + } else { + ButtonEdge::Press + }; + self.route_button(surface, binding.fader, key, edge) + } + (BindingAction::Volume, MidiMessage::Note { .. }) => None, + } + } + + fn route_button( + &mut self, + surface: &SurfaceId, + fader: FaderId, + key: BindingKey, + edge: ButtonEdge, + ) -> Option { + match edge { + ButtonEdge::Press => self.pressed.insert(key).then(|| MidiIntent::ToggleMute { + surface: surface.clone(), + fader, + }), + ButtonEdge::Release => { + self.pressed.remove(&key); + None + } + } + } +} diff --git a/midi/src/transport.rs b/midi/src/transport.rs new file mode 100644 index 0000000..a48a31c --- /dev/null +++ b/midi/src/transport.rs @@ -0,0 +1,210 @@ +use std::sync::{ + Arc, + atomic::{AtomicBool, Ordering}, + mpsc::{SyncSender, TrySendError}, +}; + +use fader_core::SurfaceId; +use midir::{Ignore, MidiInput, MidiInputConnection as NativeConnection, MidiInputPort}; +use thiserror::Error; + +use crate::{DecodeError, MidiMessage, decode_message}; + +/// One port reported by midir, retaining its opaque backend handle. +pub struct InputPort { + id: String, + name: String, + native: MidiInputPort, +} + +impl InputPort { + #[must_use] + pub fn id(&self) -> &str { + &self.id + } + + #[must_use] + pub fn name(&self) -> &str { + &self.name + } +} + +impl std::fmt::Debug for InputPort { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("InputPort") + .field("id", &self.id) + .field("name", &self.name) + .finish_non_exhaustive() + } +} + +/// Copied result of one midir callback invocation. +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum MidiInputEvent { + Message { + surface: SurfaceId, + timestamp_micros: u64, + message: MidiMessage, + }, + Malformed { + surface: SurfaceId, + timestamp_micros: u64, + error: DecodeError, + }, +} + +/// Initialization, discovery, or connection failure at the midir boundary. +#[derive(Clone, Debug, Error, Eq, PartialEq)] +pub enum MidiTransportError { + #[error("could not initialize MIDI input: {0}")] + Initialize(String), + #[error("could not read MIDI port information: {0}")] + PortInfo(String), + #[error("could not connect MIDI input: {0}")] + Connect(String), +} + +/// One-use midir catalog; connecting consumes it because midir transfers input ownership. +pub struct MidiInputCatalog { + input: MidiInput, +} + +impl MidiInputCatalog { + pub fn new(client_name: &str) -> Result { + let mut input = MidiInput::new(client_name) + .map_err(|error| MidiTransportError::Initialize(error.to_string()))?; + input.ignore(Ignore::None); + Ok(Self { input }) + } + + pub fn ports(&self) -> Result, MidiTransportError> { + self.input + .ports() + .into_iter() + .map(|native| { + let id = native.id(); + let name = self + .input + .port_name(&native) + .map_err(|error| MidiTransportError::PortInfo(error.to_string()))?; + Ok(InputPort { id, name, native }) + }) + .collect() + } + + /// Opens one device callback that only parses and nonblockingly enqueues. + pub fn connect( + self, + port: &InputPort, + connection_name: &str, + surface: SurfaceId, + sender: SyncSender, + ) -> Result { + let overflowed = Arc::new(AtomicBool::new(false)); + let callback_overflowed = Arc::clone(&overflowed); + let connection = self + .input + .connect( + &port.native, + connection_name, + move |timestamp_micros, bytes, _| { + enqueue_bytes( + &sender, + &callback_overflowed, + &surface, + timestamp_micros, + bytes, + ); + }, + (), + ) + .map_err(|error| MidiTransportError::Connect(error.to_string()))?; + Ok(MidiInputConnection { + _connection: connection, + overflowed, + }) + } +} + +fn enqueue_bytes( + sender: &SyncSender, + overflowed: &AtomicBool, + surface: &SurfaceId, + timestamp_micros: u64, + bytes: &[u8], +) { + let event = match decode_message(bytes) { + Ok(Some(message)) => MidiInputEvent::Message { + surface: surface.clone(), + timestamp_micros, + message, + }, + Ok(None) => return, + Err(error) => MidiInputEvent::Malformed { + surface: surface.clone(), + timestamp_micros, + error, + }, + }; + if matches!(sender.try_send(event), Err(TrySendError::Full(_))) { + overflowed.store(true, Ordering::Release); + } +} + +/// Keeps a midir input open and exposes callback overflow as an explicit fault. +pub struct MidiInputConnection { + _connection: NativeConnection<()>, + overflowed: Arc, +} + +impl MidiInputConnection { + #[must_use] + pub fn overflowed(&self) -> bool { + self.overflowed.load(Ordering::Acquire) + } +} + +#[cfg(test)] +mod tests { + use std::sync::mpsc; + + use super::*; + + #[test] + fn callback_path_never_blocks_and_marks_bounded_overflow() { + let (sender, receiver) = mpsc::sync_channel(1); + let overflowed = AtomicBool::new(false); + let surface = SurfaceId::new("fixture").unwrap(); + + enqueue_bytes(&sender, &overflowed, &surface, 10, &[0xb0, 7, 64]); + enqueue_bytes(&sender, &overflowed, &surface, 11, &[0x90, 32, 127]); + assert!(overflowed.load(Ordering::Acquire)); + assert!(matches!( + receiver.try_recv(), + Ok(MidiInputEvent::Message { + timestamp_micros: 10, + .. + }) + )); + } + + #[test] + fn callback_reports_malformed_and_discards_clock_traffic() { + let (sender, receiver) = mpsc::sync_channel(2); + let overflowed = AtomicBool::new(false); + let surface = SurfaceId::new("fixture").unwrap(); + + enqueue_bytes(&sender, &overflowed, &surface, 20, &[0xb0, 7]); + enqueue_bytes(&sender, &overflowed, &surface, 21, &[0xf8]); + assert!(matches!( + receiver.try_recv(), + Ok(MidiInputEvent::Malformed { + timestamp_micros: 20, + .. + }) + )); + assert!(receiver.try_recv().is_err()); + assert!(!overflowed.load(Ordering::Acquire)); + } +} diff --git a/midi/tests/decode_route.rs b/midi/tests/decode_route.rs new file mode 100644 index 0000000..1005dc6 --- /dev/null +++ b/midi/tests/decode_route.rs @@ -0,0 +1,242 @@ +use fader_core::{ + Binding, BindingAction, BindingKey, Bindings, FaderId, Gain, MessageKind, MidiChannel, + MidiData, SurfaceId, +}; +use midi::{ButtonEdge, DecodeError, MidiIntent, MidiMessage, MidiRouter, decode_message}; + +fn channel(value: u16) -> MidiChannel { + MidiChannel::new(value).unwrap() +} + +fn data(value: u16) -> MidiData { + MidiData::new(value).unwrap() +} + +fn key(surface: &str, kind: MessageKind, number: u16) -> BindingKey { + BindingKey { + surface: SurfaceId::new(surface).unwrap(), + channel: channel(1), + kind, + number: data(number), + } +} + +fn binding(fader: &str, action: BindingAction) -> Binding { + Binding { + fader: FaderId::new(fader).unwrap(), + action, + } +} + +#[test] +fn decodes_absolute_cc_across_all_channels_and_endpoints() { + for wire_channel in 0_u8..16 { + let message = decode_message(&[0xb0 | wire_channel, 7, 127]).unwrap(); + assert_eq!( + message, + Some(MidiMessage::ControlChange { + channel: channel(u16::from(wire_channel) + 1), + number: data(7), + value: data(127), + }) + ); + } + assert!(matches!( + decode_message(&[0xb0, 0, 0]).unwrap(), + Some(MidiMessage::ControlChange { number, value, .. }) + if number == data(0) && value == data(0) + )); +} + +#[test] +fn note_on_zero_and_note_off_are_release_edges() { + assert!(matches!( + decode_message(&[0x90, 32, 100]).unwrap(), + Some(MidiMessage::Note { + edge: ButtonEdge::Press, + .. + }) + )); + for bytes in [[0x90, 32, 0], [0x80, 32, 64]] { + assert!(matches!( + decode_message(&bytes).unwrap(), + Some(MidiMessage::Note { + edge: ButtonEdge::Release, + .. + }) + )); + } +} + +#[test] +fn malformed_supported_messages_are_rejected_precisely() { + assert_eq!(decode_message(&[]), Err(DecodeError::Empty)); + assert_eq!( + decode_message(&[7, 1, 2]), + Err(DecodeError::MissingStatus(7)) + ); + assert_eq!( + decode_message(&[0xb0, 7]), + Err(DecodeError::Length { + status: 0xb0, + expected: 3, + actual: 2, + }) + ); + assert_eq!( + decode_message(&[0x90, 0x80, 1]), + Err(DecodeError::InvalidData { + position: 1, + value: 0x80, + }) + ); + assert_eq!( + decode_message(&[0xb0, 1, 0xff]), + Err(DecodeError::InvalidData { + position: 2, + value: 0xff, + }) + ); +} + +#[test] +fn unrelated_and_clock_traffic_is_ignored() { + for bytes in [ + &[0xf8][..], + &[0xfe][..], + &[0xf0, 1, 2, 0xf7][..], + &[0xc0, 3][..], + &[0xd0, 4][..], + &[0xe0, 0, 64][..], + ] { + assert_eq!(decode_message(bytes).unwrap(), None); + } +} + +#[test] +fn volume_routes_to_the_bound_surface_and_normalizes_seven_bits() { + let bindings = Bindings::new([ + ( + key("left", MessageKind::ControlChange, 7), + binding("left-volume", BindingAction::Volume), + ), + ( + key("right", MessageKind::ControlChange, 7), + binding("right-volume", BindingAction::Volume), + ), + ]) + .unwrap(); + let mut router = MidiRouter::new(bindings); + let message = MidiMessage::ControlChange { + channel: channel(1), + number: data(7), + value: data(127), + }; + + assert_eq!( + router.route(&SurfaceId::new("left").unwrap(), message), + Some(MidiIntent::AbsoluteVolume { + surface: SurfaceId::new("left").unwrap(), + fader: FaderId::new("left-volume").unwrap(), + gain: Gain::UNITY, + }) + ); + assert_eq!( + router.route( + &SurfaceId::new("right").unwrap(), + MidiMessage::ControlChange { + channel: channel(1), + number: data(7), + value: data(0), + } + ), + Some(MidiIntent::AbsoluteVolume { + surface: SurfaceId::new("right").unwrap(), + fader: FaderId::new("right-volume").unwrap(), + gain: Gain::SILENCE, + }) + ); +} + +#[test] +fn note_and_cc_buttons_emit_once_per_press_until_release() { + let bindings = Bindings::new([ + ( + key("desk", MessageKind::Note, 32), + binding("note-mute", BindingAction::ToggleMute), + ), + ( + key("desk", MessageKind::ControlChange, 33), + binding("cc-mute", BindingAction::ToggleMute), + ), + ]) + .unwrap(); + let mut router = MidiRouter::new(bindings); + let surface = SurfaceId::new("desk").unwrap(); + let note = |edge| MidiMessage::Note { + channel: channel(1), + number: data(32), + velocity: data(if edge == ButtonEdge::Press { 127 } else { 0 }), + edge, + }; + assert!(matches!( + router.route(&surface, note(ButtonEdge::Press)), + Some(MidiIntent::ToggleMute { .. }) + )); + assert_eq!(router.route(&surface, note(ButtonEdge::Press)), None); + assert_eq!(router.route(&surface, note(ButtonEdge::Release)), None); + assert!(matches!( + router.route(&surface, note(ButtonEdge::Press)), + Some(MidiIntent::ToggleMute { .. }) + )); + + let cc = |value| MidiMessage::ControlChange { + channel: channel(1), + number: data(33), + value: data(value), + }; + assert!(matches!( + router.route(&surface, cc(127)), + Some(MidiIntent::ToggleMute { .. }) + )); + assert_eq!(router.route(&surface, cc(64)), None); + assert_eq!(router.route(&surface, cc(0)), None); + assert!(matches!( + router.route(&surface, cc(1)), + Some(MidiIntent::ToggleMute { .. }) + )); +} + +#[test] +fn unknown_controls_and_incompatible_bindings_emit_nothing() { + let bindings = Bindings::new([( + key("desk", MessageKind::Note, 1), + binding("invalid-note-volume", BindingAction::Volume), + )]) + .unwrap(); + let mut router = MidiRouter::new(bindings); + let surface = SurfaceId::new("desk").unwrap(); + assert_eq!( + router.route( + &surface, + MidiMessage::ControlChange { + channel: channel(1), + number: data(99), + value: data(100), + } + ), + None + ); + assert_eq!( + router.route( + &surface, + MidiMessage::Note { + channel: channel(1), + number: data(1), + velocity: data(100), + edge: ButtonEdge::Press, + } + ), + None + ); +} diff --git a/task.md b/task.md index 46a1a29..6dab4af 100644 --- a/task.md +++ b/task.md @@ -149,12 +149,27 @@ an explicit native PipeWire request failed visibly without fallback. Dependencies: M3; M4 for full end-to-end acceptance. -- [ ] **M5.1 Decode/bind:** midir connections; absolute 7-bit CC, note/CC press/release; validate channels/data. Tests: malformed/truncated messages, note-on zero, ignored clock traffic, unknown controls, duplicate press policy and surface-specific routing. +- [x] **M5.1 Decode/bind:** midir connections; absolute 7-bit CC, note/CC press/release; validate channels/data. Tests: malformed/truncated messages, note-on zero, ignored clock traffic, unknown controls, duplicate press policy and surface-specific routing. + The feature-gated `midir` 0.11.1 transport enumerates opaque port IDs and + names, owns each input connection, and copies decoded events into a bounded + nonblocking callback lane with explicit overflow state. The pure decoder and + surface-scoped router cover every channel and 7-bit endpoint, press/release + normalization, press-only toggles, unrelated traffic, and malformed input. + An opt-in monitor lists real ports and watches one selected input without + changing audio or saved configuration. - [ ] **M5.2 Identity spike:** inspect port identifiers and ALSA/udev USB mapping; establish serial/path/manual fallback policy. Acceptance: record metadata actually exposed by tested controllers, distinguish two identical models where possible, and demonstrate explicit ambiguity resolution where not possible. - [ ] **M5.3 Multi-surface lifecycle:** persist user IDs and independent input/output assignment; hotplug scanning/notification, retries and absent placeholders. Tests: unplug/replug/reboot-style port reorder preserve assignments; ambiguous serial-less matches stay unassigned; one failed device does not stop another. - [ ] **M5.4 Pickup:** crossing/tolerance, current physical position, reset on external change/rebind/reconnect/profile switch. Tests: old physical position cannot jump audio at startup; crossing activates; another surface re-arms pickup; above-range target can be picked up at the endpoint. - [ ] **M5.5 Physical smoke test:** one controller -> server -> application audio; then two controllers with overlapping MIDI message numbers. Acceptance: correct applications respond, bindings persist, and USB loss leaves server running. Record controller/firmware and environment. +M5.1 verification on 2026-10-14: nine decoder/router/transport tests pass with +the native transport enabled, seven hardware-free tests pass without default +features, and the locked dependency set builds and tests on Rust 1.88.0. The +host ALSA sequencer probe initialized and enumerated port `14:0`; controller +traffic remains an opt-in checklist item. Locked workspace formatting, +all-target/all-feature checks and tests, doctests, strict Clippy, release build, +and no-default-feature checks/tests pass. + ## M6 — Confirmed MIDI feedback Dependencies: M4, M5.