From c1ca8aeaaf25e0d2433bda9cde9c6ede5e045e2c Mon Sep 17 00:00:00 2001 From: Chloe Fontenot Date: Fri, 15 Nov 2024 12:58:56 -0600 Subject: [PATCH] Working audio input selector. Doesn't actually store the state anywhere yet. --- Cargo.lock | 448 +++++++++++++++++++++++++++++++++- Cargo.toml | 1 + README.md | 2 +- src/audio_processor.rs | 13 + src/main.rs | 49 +++- src/resources/main_window.cmb | 11 +- src/resources/main_window.ui | 10 +- 7 files changed, 523 insertions(+), 11 deletions(-) create mode 100644 src/audio_processor.rs diff --git a/Cargo.lock b/Cargo.lock index c408941..3f838d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,37 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "alsa" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7572b7ba83a31e20d1b48970ee402d2e3e0537dcfe0a3ff4d6eb7508617d43" +dependencies = [ + "alsa-sys", + "bitflags 2.6.0", + "cfg-if", + "libc", +] + +[[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 = "android-tzdata" version = "0.1.1" @@ -29,6 +60,24 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "bindgen" +version = "0.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" +dependencies = [ + "bitflags 2.6.0", + "cexpr", + "clang-sys", + "itertools", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -59,6 +108,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bytes" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" + [[package]] name = "cairo" version = "0.0.4" @@ -98,9 +153,26 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8" dependencies = [ + "jobserver", + "libc", "shlex", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-expr" version = "0.17.0" @@ -131,12 +203,33 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "color_quant" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -189,6 +282,49 @@ dependencies = [ "libc", ] +[[package]] +name = "coreaudio-rs" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "321077172d79c662f64f5071a03120748d5bb652f5231570141be24cfcd2bace" +dependencies = [ + "bitflags 1.3.2", + "core-foundation-sys", + "coreaudio-sys", +] + +[[package]] +name = "coreaudio-sys" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ce857aa0b77d77287acc1ac3e37a05a8c95a2af3647d23b15f263bdaeb7562b" +dependencies = [ + "bindgen", +] + +[[package]] +name = "cpal" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "873dab07c8f743075e57f524c583985fbaf745602acbe916a01539364369a779" +dependencies = [ + "alsa", + "core-foundation-sys", + "coreaudio-rs", + "dasp_sample", + "jni", + "js-sys", + "libc", + "mach2", + "ndk", + "ndk-context", + "oboe", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -198,6 +334,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "dasp_sample" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f" + [[package]] name = "dirs" version = "5.0.1" @@ -240,6 +382,12 @@ dependencies = [ "wio", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "equivalent" version = "1.0.1" @@ -260,6 +408,7 @@ name = "fft2midi" version = "0.1.0" dependencies = [ "cairo", + "cpal", "gdk-pixbuf", "gtk4", "libadwaita", @@ -576,6 +725,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "gobject-sys" version = "0.20.4" @@ -716,7 +871,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -752,6 +907,46 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", + "windows-sys 0.45.0", +] + +[[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.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.3.1" @@ -836,6 +1031,15 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "memchr" version = "2.7.4" @@ -851,6 +1055,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.8.0" @@ -861,6 +1071,45 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "ndk" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" +dependencies = [ + "bitflags 2.6.0", + "jni-sys", + "log", + "ndk-sys", + "num_enum", + "thiserror", +] + +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + +[[package]] +name = "ndk-sys" +version = "0.5.0+25.2.9519653" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c196769dd60fd4f363e11d948139556a344e79d451aeb2fa2fd040738ef7691" +dependencies = [ + "jni-sys", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num" version = "0.1.42" @@ -897,6 +1146,17 @@ dependencies = [ "rustc-serialize", ] +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "num-integer" version = "0.1.46" @@ -938,6 +1198,50 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_enum" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "oboe" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8b61bebd49e5d43f5f8cc7ee2891c16e0f41ec7954d36bcb6c14c5e0de867fb" +dependencies = [ + "jni", + "ndk", + "ndk-context", + "num-derive", + "num-traits", + "oboe-sys", +] + +[[package]] +name = "oboe-sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8bb09a4a2b1d668170cfe0a7d5bc103f8999fb316c98099b6a9939c9f2e79d" +dependencies = [ + "cc", +] + [[package]] name = "once_cell" version = "1.20.2" @@ -1145,6 +1449,41 @@ dependencies = [ "thiserror", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-serialize" version = "0.3.25" @@ -1375,6 +1714,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.95" @@ -1451,6 +1802,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" +dependencies = [ + "windows-core 0.54.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -1460,6 +1821,34 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + +[[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.48.0" @@ -1478,6 +1867,21 @@ dependencies = [ "windows-targets 0.52.6", ] +[[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.48.5" @@ -1509,6 +1913,12 @@ dependencies = [ "windows_x86_64_msvc 0.52.6", ] +[[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.48.5" @@ -1521,6 +1931,12 @@ 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.48.5" @@ -1533,6 +1949,12 @@ 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.48.5" @@ -1551,6 +1973,12 @@ 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.48.5" @@ -1563,6 +1991,12 @@ 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.48.5" @@ -1575,6 +2009,12 @@ 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.48.5" @@ -1587,6 +2027,12 @@ 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.48.5" diff --git a/Cargo.toml b/Cargo.toml index e27b210..caaeb75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ gdk-pixbuf = "0.20.4" gtk = { version = "0.9.4", package = "gtk4", features = ["v4_12", "gnome_47"] } adw = { package = "libadwaita", version = "0.7.1", features = ["v1_6"] } plotters = "0.3.7" +cpal = "*" \ No newline at end of file diff --git a/README.md b/README.md index 557a58e..0638dfb 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,4 @@ Libraries used: https://gtk-rs.org/gtk4-rs/git/book/hello_world.html
https://docs.rs/rustfft/latest/rustfft/
https://docs.rs/crate/midir/latest
-https://pipewire.pages.freedesktop.org/pipewire-rs/pipewire/ \ No newline at end of file +https://docs.rs/cpal/latest/cpal/ \ No newline at end of file diff --git a/src/audio_processor.rs b/src/audio_processor.rs new file mode 100644 index 0000000..17e8b16 --- /dev/null +++ b/src/audio_processor.rs @@ -0,0 +1,13 @@ +use cpal::traits::HostTrait; + +pub struct AudioProcessor { + //selected_input_device: usize; +} + +impl AudioProcessor { + fn new() -> AudioProcessor { + AudioProcessor { + // selected_input_device: cpal:: + } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ec91dd9..a121135 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ +use cpal::traits::{DeviceTrait, HostTrait}; use gtk::prelude::*; use gtk::{self, glib, Application}; + mod graph_widget; +mod audio_processor; const APP_ID: &str = "com.chloechristine.ftt2midi"; @@ -33,10 +36,18 @@ fn build_ui(app: &Application) { .object::("input_selector") .expect("Couldn't bind to input_selector"); + let input_selector_dropdown = builder + .object::("input_selector_dropdown") + .expect("Couldn't bind to input_selector_dropdown"); + let midi_device_selector = builder .object::("midi_device_selector") .expect("Couldn't bind to midi_device_selector"); + let midi_device_selector_dropdown = builder + .object::("midi_device_selector_dropdown") + .expect("Couldn't bind to midi_device_selector_dropdown"); + let start_button = builder .object::("start_button") .expect("Couldn't bind to start_button"); @@ -45,13 +56,43 @@ fn build_ui(app: &Application) { fft_graph.set_height_request(500); fft_graph.set_width_request(500); main_grid.attach(&fft_graph, 0, 0, 1, 1); - //main_grid.attach_next_to(&fft_graph, Some(&control_deck), gtk::PositionType::Top, 1, 0); + + input_selector_dropdown.connect_show(move |input_selector_dropdown: >k::PopoverMenu| { + // Get audio interfaces and populate the menu + println!("Input selector opened"); + let hosts = cpal::available_hosts(); + // Build a list of input devices and populate the menu + let device_list_grid = gtk::Box::builder() + .orientation(gtk::Orientation::Vertical) + .build(); + for host_id in hosts { + let host = cpal::host_from_id(host_id).expect("Failed to get host"); + match host.input_devices() { + Ok(devices) => { + let default_button = gtk::Button::with_label("None Selected"); + default_button.connect_clicked(move |_| { + println!("{} {}", -1, "None Selected"); + }); + device_list_grid.append(&default_button); + for (index, device) in devices.enumerate() { + let label = format!("{}", device.name().unwrap()); + println!("{}", label); + let selection_button = gtk::Button::with_label(label.as_str()); + selection_button.connect_clicked(move |_| { + println!("{} {}", index, label); + }); + device_list_grid.append(&selection_button); + } + } + Err(err) => eprintln!("Error printing input devices: {:?}", err), + } + }; + input_selector_dropdown.set_child(Some(&device_list_grid)); + }); //start_button.connect_clicked() - - window.set_application(Some(app)); // Present the window window.present(); -} \ No newline at end of file +} diff --git a/src/resources/main_window.cmb b/src/resources/main_window.cmb index 8e5ce07..ddcc602 100644 --- a/src/resources/main_window.cmb +++ b/src/resources/main_window.cmb @@ -16,8 +16,8 @@ (1,7,"GtkMenuButton","midi_device_selector",3,None,None,None,3,None,None), (1,8,"GtkButton","start_button",3,None,None,None,4,None,None), (1,9,"GtkGrid","main_grid",1,None,None,None,0,None,None), - (1,10,"GtkPopoverMenu",None,7,None,None,None,0,None,None), - (1,11,"GtkPopoverMenu",None,6,None,None,None,0,None,None) + (1,10,"GtkPopoverMenu","midi_device_selector_dropdown",7,None,None,None,0,None,None), + (1,11,"GtkPopoverMenu","input_selector_dropdown",6,None,None,None,0,None,None) (1,1,"GtkApplicationWindow","show-menubar","True",None,None,None,None,None,None,None,None,None), @@ -31,10 +31,14 @@ (1,5,"GtkWidget","margin-start","20",None,None,None,None,None,None,None,None,None), (1,6,"GtkMenuButton","active","True",None,None,None,None,None,None,None,None,None), (1,6,"GtkMenuButton","always-show-arrow","True",None,None,None,None,None,None,None,None,None), + (1,6,"GtkMenuButton","direction","right",None,None,None,None,None,None,None,None,None), (1,6,"GtkMenuButton","icon-name","multimedia-volume-control",None,None,None,None,None,None,None,None,None), + (1,6,"GtkMenuButton","label","None Selected",None,None,None,None,None,None,None,None,None), (1,6,"GtkMenuButton","popover",None,None,None,None,None,11,None,None,None,None), (1,7,"GtkMenuButton","active","True",None,None,None,None,None,None,None,None,None), (1,7,"GtkMenuButton","always-show-arrow","True",None,None,None,None,None,None,None,None,None), + (1,7,"GtkMenuButton","direction","right",None,None,None,None,None,None,None,None,None), + (1,7,"GtkMenuButton","label","None Selected",None,None,None,None,None,None,None,None,None), (1,7,"GtkMenuButton","popover",None,None,None,None,None,10,None,None,None,None), (1,8,"GtkButton","label","Start",None,None,None,None,None,None,None,None,None), (1,8,"GtkWidget","can-target","False",None,None,None,None,None,None,None,None,None), @@ -44,7 +48,8 @@ (1,9,"GtkWidget","hexpand-set","True",None,None,None,None,None,None,None,None,None), (1,9,"GtkWidget","valign","baseline-center",None,None,None,None,None,None,None,None,None), (1,9,"GtkWidget","vexpand","True",None,None,None,None,None,None,None,None,None), - (1,9,"GtkWidget","vexpand-set","True",None,None,None,None,None,None,None,None,None) + (1,9,"GtkWidget","vexpand-set","True",None,None,None,None,None,None,None,None,None), + (1,10,"GtkPopover","position","right",None,None,None,None,None,None,None,None,None) (1,3,4,"GtkGridLayoutChild","column","0",None,None,None,None), diff --git a/src/resources/main_window.ui b/src/resources/main_window.ui index b5c7824..6ef64c4 100644 --- a/src/resources/main_window.ui +++ b/src/resources/main_window.ui @@ -48,9 +48,11 @@ True True + right multimedia-volume-control + None Selected - + 1 @@ -64,8 +66,12 @@ True True + right + None Selected - + + right + 1