From 73c1ab832104823ef6cd5d269027f555122a5274 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 16 Apr 2023 10:49:13 -0700 Subject: [PATCH 01/12] sdl3 --- Cargo.lock | 20 ++++++++----------- Cargo.toml | 9 ++++----- README.md | 56 ++++++++++++++++++++++++++++-------------------------- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b864e2..bc56955 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,8 +183,6 @@ dependencies = [ [[package]] name = "projectm-rs" version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c7adc99c8bb6bfc138265b279ca7d22f1d896b474e0c925abf6f3723403d09d" dependencies = [ "libc", "projectm-sys", @@ -208,7 +206,7 @@ version = "0.1.0" dependencies = [ "libc", "projectm-rs", - "sdl2", + "sdl3", ] [[package]] @@ -272,22 +270,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] -name = "sdl2" -version = "0.35.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7959277b623f1fb9e04aea73686c3ca52f01b2145f8ea16f4ff30d8b7623b1a" +name = "sdl3" +version = "0.0.2" +source = "git+https://github.com/revmischa/sdl3-rs.git#70254bfd9bd64b7ba637f9fd648e1c5cd51d7699" dependencies = [ "bitflags", "lazy_static", "libc", - "sdl2-sys", + "sdl3-sys", ] [[package]] -name = "sdl2-sys" -version = "0.35.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3586be2cf6c0a8099a79a12b4084357aa9b3e0b0d7980e3b67aaf7a9d55f9f0" +name = "sdl3-sys" +version = "0.0.2" +source = "git+https://github.com/revmischa/sdl3-rs.git#70254bfd9bd64b7ba637f9fd648e1c5cd51d7699" dependencies = [ "cfg-if", "libc", diff --git a/Cargo.toml b/Cargo.toml index d5dfdb7..509a2d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,10 @@ rust-version = "1.68.2" [dependencies] libc = "*" -sdl2 = "0.35" -projectm-rs = "1.0.5" -# projectm-rs = { path = "../projectm-rs" } -#projectm-rs = { git = "https://github.com/projectM-visualizer/projectm-rs" } - +sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git" } +# projectm = "1.0.5" +projectm = { path = "../projectm-rs" } +#projectm = { git = "https://github.com/projectM-visualizer/projectm" } # gl = "0.14.0" [features] diff --git a/README.md b/README.md index 861b734..3360e35 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,15 @@
-

Frontend-SDL2-Rust

+

ProjectM

- Example rust app, utilizing the projectM crate + Reference projectM application in Rust, utilizing the projectM crate

- Report Bug + Report Bug ยท - Request Feature + Request Feature

@@ -45,6 +45,7 @@
+ ## Getting Started To get this crate up and running properly, you'll need to install some prerequisites. @@ -56,29 +57,29 @@ development files. To build projectM, both binaries and development files need t #### General build dependencies for all platforms: -* [**Rust**](https://www.rust-lang.org/tools/install) -* A working build toolchain. -* [**CMake**](https://cmake.org/): Used to generate platform-specific build files. -* **OpenGL**: 3D graphics library. Used to render the visualizations. -* or **GLES3**: OpenGL libraries for embedded systems, version 3. Required to build projectM on Android devices, +- [**Rust**](https://www.rust-lang.org/tools/install) +- A working build toolchain. +- [**CMake**](https://cmake.org/): Used to generate platform-specific build files. +- **OpenGL**: 3D graphics library. Used to render the visualizations. +- or **GLES3**: OpenGL libraries for embedded systems, version 3. Required to build projectM on Android devices, Raspberry Pi, Emscripten and the Universal Windows Platform. -* [**glm**](https://github.com/g-truc/glm): OpenGL Mathematics library. Optional, will use a bundled version with +- [**glm**](https://github.com/g-truc/glm): OpenGL Mathematics library. Optional, will use a bundled version with autotools or if not installed. -* [**SDL2**](https://github.com/libsdl-org/SDL): Simple Directmedia Layer. Version 2.0.5 or higher is required to build +- [**SDL3**](https://github.com/libsdl-org/SDL): Simple Directmedia Layer >= 3. Provided by sdl3-rs. the test UI. -* [**LLVM**](https://llvm.org/): Low-Level Virtual Machine. Optional and **experimental**, used to speed up preset +- [**LLVM**](https://llvm.org/): Low-Level Virtual Machine. Optional and **experimental**, used to speed up preset execution by leveraging the LLVM JIT compiler. #### Only relevant for Windows: -* [**vcpkg**](https://github.com/microsoft/vcpkg): C++ Library Manager for Windows. _Optional_, but recommended to +- [**vcpkg**](https://github.com/microsoft/vcpkg): C++ Library Manager for Windows. _Optional_, but recommended to install the aforementioned library dependencies. -* [**GLEW**](http://glew.sourceforge.net/): The OpenGL Extension Wrangler Library. Only required if using CMake to - configure the build, the pre-created solutions use a bundled copy of GLEW. +- [**GLEW**](http://glew.sourceforge.net/): The OpenGL Extension Wrangler Library. Only required if using CMake to +configure the build, the pre-created solutions use a bundled copy of GLEW.

(back to top)

- + ## Usage ``` @@ -92,8 +93,8 @@ cargo build ### If using SDL installed via Homebrew ``` -RUSTFLAGS="-L$(brew --prefix sdl2)/lib" cargo build -RUSTFLAGS="-L$(brew --prefix sdl2)/lib" cargo run +RUSTFLAGS="-L$(brew --prefix sdl3)/lib" cargo build +RUSTFLAGS="-L$(brew --prefix sdl3)/lib" cargo run ``` ### Optimized build @@ -104,9 +105,8 @@ cargo run --release

(back to top)

- - + ## Contributing Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. @@ -122,9 +122,8 @@ Don't forget to give the project a star! Thanks again!

(back to top)

- - + ## License Distributed under the LGPL-2.1 license. See `LICENSE` for more information. @@ -132,6 +131,7 @@ Distributed under the LGPL-2.1 license. See `LICENSE` for more information.

(back to top)

+ ## Support [![Discord][discord-shield]][discord-url] @@ -139,6 +139,7 @@ Distributed under the LGPL-2.1 license. See `LICENSE` for more information.

(back to top)

+ ## Contact Blaquewithaq (Discord: SoFloppy#1289) - [@anomievision](https://twitter.com/anomievision) - anomievision@gmail.com @@ -147,16 +148,17 @@ Blaquewithaq (Discord: SoFloppy#1289) - [@anomievision](https://twitter.com/anom + [contributors-shield]: https://img.shields.io/github/contributors/projectM-visualizer/projectm-rs.svg?style=for-the-badge -[contributors-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/graphs/contributors +[contributors-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/graphs/contributors [forks-shield]: https://img.shields.io/github/forks/projectM-visualizer/projectm-rs.svg?style=for-the-badge -[forks-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/network/members +[forks-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/network/members [stars-shield]: https://img.shields.io/github/stars/projectM-visualizer/projectm-rs.svg?style=for-the-badge -[stars-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/stargazers +[stars-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/stargazers [issues-shield]: https://img.shields.io/github/issues/projectM-visualizer/projectm-rs.svg?style=for-the-badge -[issues-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/issues +[issues-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/issues [license-shield]: https://img.shields.io/github/license/projectM-visualizer/projectm-rs.svg?style=for-the-badge -[license-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/blob/master/LICENSE +[license-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/blob/master/LICENSE [crates-shield]: https://img.shields.io/crates/v/projectm-rs?style=for-the-badge [crates-url]: https://crates.io/crates/projectm-rs [crates-dl-shield]: https://img.shields.io/crates/d/projectm-rs?style=for-the-badge From 68ecc4e3f72b041afcecc34d397f2245172f733a Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 16 Apr 2023 10:58:39 -0700 Subject: [PATCH 02/12] sdl3 --- Cargo.lock | 6 ++++-- Cargo.toml | 4 ++-- src/app.rs | 16 ++++++++-------- src/app/audio.rs | 12 ++++++------ src/app/config.rs | 2 +- src/app/main_loop.rs | 16 ++++++++-------- src/app/video.rs | 4 ++-- src/dummy_audio.rs | 2 +- 8 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc56955..a88f4ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,8 +181,10 @@ dependencies = [ ] [[package]] -name = "projectm-rs" +name = "projectm" version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a14398d9b43666e48c94acb7ad337c1af8f21be46a2cfbff125bd293017ad00" dependencies = [ "libc", "projectm-sys", @@ -205,7 +207,7 @@ name = "projectm_sdl" version = "0.1.0" dependencies = [ "libc", - "projectm-rs", + "projectm", "sdl3", ] diff --git a/Cargo.toml b/Cargo.toml index 509a2d7..3f801cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ rust-version = "1.68.2" [dependencies] libc = "*" sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git" } -# projectm = "1.0.5" -projectm = { path = "../projectm-rs" } +projectm = "1.0.5" +# projectm = { path = "../projectm-rs" } #projectm = { git = "https://github.com/projectM-visualizer/projectm" } # gl = "0.14.0" diff --git a/src/app.rs b/src/app.rs index eacbb89..e593b54 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; -use projectm_rs::core::{ProjectMHandle, Projectm}; -use sdl2::video::GLProfile; +use projectm::core::{ProjectMHandle, Projectm}; +use sdl3::video::GLProfile; pub mod audio; pub mod config; @@ -15,12 +15,12 @@ pub type ProjectMWrapped = Arc>; /// Application state pub struct App { pm: ProjectMWrapped, - playlist: projectm_rs::playlist::Playlist, - sdl_context: sdl2::Sdl, - window: sdl2::video::Window, + playlist: projectm::playlist::Playlist, + sdl_context: sdl3::Sdl, + window: sdl3::video::Window, config: config::Config, audio: audio::Audio, - _gl_context: sdl2::video::GLContext, + _gl_context: sdl3::video::GLContext, } pub fn default_config() -> config::Config { @@ -30,7 +30,7 @@ pub fn default_config() -> config::Config { impl App { pub fn new(config: Option) -> Self { // setup sdl - let sdl_context = sdl2::init().unwrap(); + let sdl_context = sdl3::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); // request GL version @@ -64,7 +64,7 @@ impl App { let pm = Projectm::create(); // and a preset playlist - let playlist = projectm_rs::playlist::Playlist::create(pm); + let playlist = projectm::playlist::Playlist::create(pm); // get/set window size let (width, height) = window.drawable_size(); // highDPI aware diff --git a/src/app/audio.rs b/src/app/audio.rs index 8455f79..0bf0205 100644 --- a/src/app/audio.rs +++ b/src/app/audio.rs @@ -1,5 +1,5 @@ -use projectm_rs::core::ProjectMHandle; -use sdl2::audio::{AudioCallback, AudioDevice, AudioSpecDesired}; +use projectm::core::ProjectMHandle; +use sdl3::audio::{AudioCallback, AudioDevice, AudioSpecDesired}; use std::sync::Arc; use std::sync::Mutex; @@ -15,7 +15,7 @@ pub struct AudioCaptureDevice { } pub struct Audio { - audio_subsystem: sdl2::AudioSubsystem, + audio_subsystem: sdl3::AudioSubsystem, device_index: AudioDeviceIndex, is_capturing: bool, frame_rate: Option, @@ -25,7 +25,7 @@ pub struct Audio { /// Wrapper around the audio subsystem to capture audio and pass it to projectM. impl Audio { - pub fn new(sdl_context: &sdl2::Sdl, projectm: ProjectMWrapped) -> Self { + pub fn new(sdl_context: &sdl3::Sdl, projectm: ProjectMWrapped) -> Self { let audio_subsystem = sdl_context.audio().unwrap(); Self { @@ -106,7 +106,7 @@ impl Audio { // how many samples to capture at a time // should be enough for 1 frame or less // should not be larger than max_samples / channels - let max_samples: usize = projectm_rs::core::Projectm::pcm_get_max_samples() + let max_samples: usize = projectm::core::Projectm::pcm_get_max_samples() .try_into() .unwrap(); let samples_per_frame = (sample_rate / frame_rate) as usize; @@ -183,6 +183,6 @@ impl AudioCallback for AudioCaptureCallback { // we need to pass it to projectm fn callback(&mut self, out: &mut [SampleFormat]) { let pm = *self.pm.lock().unwrap(); - projectm_rs::core::Projectm::pcm_add_float(pm, out.to_vec(), 2); + projectm::core::Projectm::pcm_add_float(pm, out.to_vec(), 2); } } diff --git a/src/app/config.rs b/src/app/config.rs index 8664b4f..915c3c3 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -1,5 +1,5 @@ use crate::app::App; -use projectm_rs::core::Projectm; +use projectm::core::Projectm; use std::path::Path; pub type FrameRate = u32; diff --git a/src/app/main_loop.rs b/src/app/main_loop.rs index d1f8885..d0f8479 100644 --- a/src/app/main_loop.rs +++ b/src/app/main_loop.rs @@ -1,6 +1,6 @@ -use projectm_rs::core::Projectm; -use sdl2::event::Event; -use sdl2::keyboard::Keycode; +use projectm::core::Projectm; +use sdl3::event::Event; +use sdl3::keyboard::Keycode; use crate::app::App; @@ -14,7 +14,7 @@ impl App { // events let mut event_pump = self.sdl_context.event_pump().unwrap(); - let mut timer = self.sdl_context.timer().unwrap(); + let timer = self.sdl_context.timer().unwrap(); // renderLoop 'running: loop { @@ -82,10 +82,10 @@ impl App { Event::KeyUp { keycode: Some(Keycode::I), keymod: - sdl2::keyboard::Mod::LCTRLMOD - | sdl2::keyboard::Mod::RCTRLMOD - | sdl2::keyboard::Mod::LGUIMOD - | sdl2::keyboard::Mod::RGUIMOD, + sdl3::keyboard::Mod::LCTRLMOD + | sdl3::keyboard::Mod::RCTRLMOD + | sdl3::keyboard::Mod::LGUIMOD + | sdl3::keyboard::Mod::RGUIMOD, .. } => { self.audio.open_next_device(); diff --git a/src/app/video.rs b/src/app/video.rs index ef85b3b..e6aba5c 100644 --- a/src/app/video.rs +++ b/src/app/video.rs @@ -5,8 +5,8 @@ impl App { let is_fullscreen = self.window.fullscreen_state(); self.window .set_fullscreen(match is_fullscreen { - sdl2::video::FullscreenType::True => sdl2::video::FullscreenType::Off, - _ => sdl2::video::FullscreenType::True, + sdl3::video::FullscreenType::True => sdl3::video::FullscreenType::Off, + _ => sdl3::video::FullscreenType::True, }) .unwrap(); } diff --git a/src/dummy_audio.rs b/src/dummy_audio.rs index 787d3d4..6a7da0e 100644 --- a/src/dummy_audio.rs +++ b/src/dummy_audio.rs @@ -1,4 +1,4 @@ -use projectm_rs::core::{ProjectMHandle, Projectm}; +use projectm::core::{ProjectMHandle, Projectm}; #[allow(dead_code)] pub fn generate_random_audio_data(projectm_handle: ProjectMHandle) { From 1c1a3a64a028cbd94f618a2a86aa06d42bf01c8b Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 4 Jun 2023 19:25:29 -0700 Subject: [PATCH 03/12] WIP --- .cargo/config.toml | 3 +++ .gitignore | 6 ++---- Cargo.lock | 8 ++------ Cargo.toml | 8 +++++--- src/app.rs | 24 +++++++++++++++++++----- src/app/audio.rs | 19 ++++++++++++------- src/app/config.rs | 2 +- src/app/main_loop.rs | 8 +++++--- src/app/video.rs | 4 ++-- 9 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..a627181 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[env] +# use pipewire for audio +SDL_AUDIODRIVER = "pipewire" diff --git a/.gitignore b/.gitignore index cb96104..bcbfeee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -.* -!.gitignore - -target/ \ No newline at end of file +.vscode/ +target/ diff --git a/Cargo.lock b/Cargo.lock index a88f4ff..ea6c228 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,8 +183,6 @@ dependencies = [ [[package]] name = "projectm" version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a14398d9b43666e48c94acb7ad337c1af8f21be46a2cfbff125bd293017ad00" dependencies = [ "libc", "projectm-sys", @@ -273,8 +271,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "sdl3" -version = "0.0.2" -source = "git+https://github.com/revmischa/sdl3-rs.git#70254bfd9bd64b7ba637f9fd648e1c5cd51d7699" +version = "0.1.0" dependencies = [ "bitflags", "lazy_static", @@ -284,8 +281,7 @@ dependencies = [ [[package]] name = "sdl3-sys" -version = "0.0.2" -source = "git+https://github.com/revmischa/sdl3-rs.git#70254bfd9bd64b7ba637f9fd648e1c5cd51d7699" +version = "0.0.2+sdl3-dev-2023-05-13" dependencies = [ "cfg-if", "libc", diff --git a/Cargo.toml b/Cargo.toml index 3f801cb..c76f1bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,13 @@ rust-version = "1.68.2" [dependencies] libc = "*" -sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git" } -projectm = "1.0.5" -# projectm = { path = "../projectm-rs" } +# sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git" } +sdl3 = { path = "../../sdl3-rs" } +# projectm = "1.0.5" +projectm = { path = "../projectm-rs" } #projectm = { git = "https://github.com/projectM-visualizer/projectm" } # gl = "0.14.0" [features] +static-link = ["sdl3/static-link"] dummy_audio = [] diff --git a/src/app.rs b/src/app.rs index e593b54..990fe98 100644 --- a/src/app.rs +++ b/src/app.rs @@ -31,6 +31,12 @@ impl App { pub fn new(config: Option) -> Self { // setup sdl let sdl_context = sdl3::init().unwrap(); + // print SDL version + let version = sdl3::version::version(); + println!( + "SDL version: {}.{}.{}", + version.major, version.minor, version.patch + ); let video_subsystem = sdl_context.video().unwrap(); // request GL version @@ -45,14 +51,22 @@ impl App { // create window // get screen dimensions let display_index = 0; - let display_mode = video_subsystem.desktop_display_mode(display_index).unwrap(); - let window_width = display_mode.w as u32; - let window_height = display_mode.h as u32; + let driver = video_subsystem.current_video_driver(); + println!("Using video driver: {}", driver); + let display_id = video_subsystem.get_primary_display_id(); + let display_mode = video_subsystem.current_display_mode(display_id).unwrap(); + let window_width = 100; // display_mode.w as u32; + let window_height = 100; // display_mode.h as u32; + println!( + "Display {} is {}x{}", + display_index, window_width, window_height + ); let window = video_subsystem .window("ProjectM", window_width, window_height) .opengl() + .maximized() .position_centered() - .allow_highdpi() + // .allow_highdpi() .build() .expect("could not initialize video subsystem"); @@ -67,7 +81,7 @@ impl App { let playlist = projectm::playlist::Playlist::create(pm); // get/set window size - let (width, height) = window.drawable_size(); // highDPI aware + let (width, height) = window.size(); // TODO: need high DPI support here https://github.com/libsdl-org/SDL/issues/7134 Projectm::set_window_size(pm, width.try_into().unwrap(), height.try_into().unwrap()); // create a mutex to protect the projectM instance diff --git a/src/app/audio.rs b/src/app/audio.rs index 0bf0205..c20dce3 100644 --- a/src/app/audio.rs +++ b/src/app/audio.rs @@ -27,6 +27,10 @@ pub struct Audio { impl Audio { pub fn new(sdl_context: &sdl3::Sdl, projectm: ProjectMWrapped) -> Self { let audio_subsystem = sdl_context.audio().unwrap(); + println!( + "Using audio driver: {}", + audio_subsystem.current_audio_driver() + ); Self { is_capturing: false, @@ -44,7 +48,7 @@ impl Audio { self.frame_rate = frame_rate.into(); #[cfg(not(feature = "dummy_audio"))] - self.begin_audio_capture(); + self.begin_audio_capture(0); } pub fn list_devices(&self) { @@ -60,12 +64,12 @@ impl Audio { pub fn capture_device(&mut self, device_index: AudioDeviceIndex) { self.stop_audio_capture(); self.device_index = device_index; - self.begin_audio_capture(); + self.begin_audio_capture(device_index); } - pub fn get_current_device_name(&self) -> String { + pub fn get_device_name(&self, device_index: AudioDeviceIndex) -> String { self.audio_subsystem - .audio_capture_device_name(self.device_index) + .audio_capture_device_name(device_index) .expect("could not get audio device") } @@ -99,7 +103,7 @@ impl Audio { .collect::>() } - pub fn begin_audio_capture(&mut self) { + pub fn begin_audio_capture(&mut self, device_index: AudioDeviceIndex) { let sample_rate: u32 = 44100; let frame_rate = self.frame_rate.unwrap(); @@ -120,7 +124,7 @@ impl Audio { }; // open audio device for capture - let device_name = self.get_current_device_name(); + let device_name = self.get_device_name(device_index); let audio_device = match self .audio_subsystem // sdl .open_capture(device_name.as_str(), &desired_spec, |_spec| { @@ -150,7 +154,7 @@ impl Audio { } pub fn stop_audio_capture(&mut self) { - let current_device_name = self.get_current_device_name(); + let current_device_name = self.get_device_name(self.device_index); println!("Stopping audio capture for device {}", current_device_name); println!( @@ -165,6 +169,7 @@ impl Audio { device.pause(); self.is_capturing = false; + drop(device); } } diff --git a/src/app/config.rs b/src/app/config.rs index 915c3c3..7cda7df 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -32,7 +32,7 @@ impl Default for Config { // use /usr/local/share/projectM if it exists, otherwise use local paths let resource_dir = "/usr/local/share/projectM"; let dir_exists = Path::new(&resource_dir).exists(); - let preset_path = if dir_exists { + let preset_path = if dir_exists && false { String::from(resource_dir) + "/presets" } else { // just test presets diff --git a/src/app/main_loop.rs b/src/app/main_loop.rs index d0f8479..c82020e 100644 --- a/src/app/main_loop.rs +++ b/src/app/main_loop.rs @@ -111,10 +111,12 @@ impl App { if frame_rate > 0 { // calculate frame time - let frame_time = timer.ticks() - start_time; - if frame_time < 1000 / frame_rate { + let frame_time: u32 = (timer.ticks() - start_time).try_into().unwrap(); + // what do we need to hit target frame rate? + let delay_needed: u32 = 1000 / frame_rate - frame_time; + if delay_needed > 0 { // sleep the remaining frame time - timer.delay(1000 / frame_rate - frame_time); + timer.delay(delay_needed); } } } diff --git a/src/app/video.rs b/src/app/video.rs index e6aba5c..5b00a42 100644 --- a/src/app/video.rs +++ b/src/app/video.rs @@ -5,8 +5,8 @@ impl App { let is_fullscreen = self.window.fullscreen_state(); self.window .set_fullscreen(match is_fullscreen { - sdl3::video::FullscreenType::True => sdl3::video::FullscreenType::Off, - _ => sdl3::video::FullscreenType::True, + sdl3::video::FullscreenType::True => false, + _ => true, }) .unwrap(); } From 65c4ccdcc6842648f0db6eb735976541ebc11251 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 4 Jun 2023 19:25:57 -0700 Subject: [PATCH 04/12] bindgen --- Cargo.toml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c76f1bb..61824e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,12 @@ rust-version = "1.68.2" [dependencies] libc = "*" -# sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git" } -sdl3 = { path = "../../sdl3-rs" } -# projectm = "1.0.5" -projectm = { path = "../projectm-rs" } +projectm = "1.0.5" +# projectm = { path = "../projectm-rs" } #projectm = { git = "https://github.com/projectM-visualizer/projectm" } +sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git", features = ["use-bindgen"] } +# sdl3 = { path = "../../sdl3-rs" } + # gl = "0.14.0" [features] From 292a91688dfd0822fa680c555097b2f6e4ea63e0 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 4 Jun 2023 19:56:18 -0700 Subject: [PATCH 05/12] WIP --- Cargo.lock | 20 +++++++++++++------- Cargo.toml | 5 +++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea6c228..65128b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -173,9 +173,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.55" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0dd4be24fcdcfeaa12a432d588dc59bbad6cad3510c67e74a2b6b2fc950564" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ "unicode-ident", ] @@ -183,6 +183,8 @@ dependencies = [ [[package]] name = "projectm" version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a14398d9b43666e48c94acb7ad337c1af8f21be46a2cfbff125bd293017ad00" dependencies = [ "libc", "projectm-sys", @@ -202,7 +204,7 @@ dependencies = [ [[package]] name = "projectm_sdl" -version = "0.1.0" +version = "0.1.1" dependencies = [ "libc", "projectm", @@ -211,9 +213,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -271,7 +273,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "sdl3" -version = "0.1.0" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "814de6873aef8b24ffe2e10a3436f3f903f09436656c5d729b434746116c42bb" dependencies = [ "bitflags", "lazy_static", @@ -281,7 +285,9 @@ dependencies = [ [[package]] name = "sdl3-sys" -version = "0.0.2+sdl3-dev-2023-05-13" +version = "0.0.5+sdl3-dev-2023-06-04" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db37ff748dc3b771dce9b737e2ae71e99e595881f798611375f222e5caf6c4f6" dependencies = [ "cfg-if", "libc", diff --git a/Cargo.toml b/Cargo.toml index 61824e5..4401dec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "projectm_sdl" -version = "0.1.0" +version = "0.1.1" edition = "2021" rust-version = "1.68.2" @@ -11,7 +11,8 @@ libc = "*" projectm = "1.0.5" # projectm = { path = "../projectm-rs" } #projectm = { git = "https://github.com/projectM-visualizer/projectm" } -sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git", features = ["use-bindgen"] } +# sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git", features = ["use-bindgen"] } +sdl3 = "0.2.0" # sdl3 = { path = "../../sdl3-rs" } # gl = "0.14.0" From e43c9409b923b12dbc79caf7c0cf04e9fba432ee Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 17 Sep 2023 12:17:36 -0700 Subject: [PATCH 06/12] update sdl3 --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65128b2..cf59b67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,9 +273,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "sdl3" -version = "0.2.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "814de6873aef8b24ffe2e10a3436f3f903f09436656c5d729b434746116c42bb" +checksum = "041ee515e152266b6d4ade22db39b0e09486076d06e0eb7ad5cc707d4856ca4f" dependencies = [ "bitflags", "lazy_static", @@ -285,9 +285,9 @@ dependencies = [ [[package]] name = "sdl3-sys" -version = "0.0.5+sdl3-dev-2023-06-04" +version = "0.0.6+sdl3-dev-2023-07-31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db37ff748dc3b771dce9b737e2ae71e99e595881f798611375f222e5caf6c4f6" +checksum = "c9846a96256cb800f754bef64805689a4c75b2a1a6d855064c10321075034673" dependencies = [ "cfg-if", "libc", diff --git a/Cargo.toml b/Cargo.toml index 4401dec..78be15a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ projectm = "1.0.5" # projectm = { path = "../projectm-rs" } #projectm = { git = "https://github.com/projectM-visualizer/projectm" } # sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git", features = ["use-bindgen"] } -sdl3 = "0.2.0" +sdl3 = "0.5.0" # sdl3 = { path = "../../sdl3-rs" } # gl = "0.14.0" From 7855cd0b817eaceff7e0819ff9883a0123d888de Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 17 Sep 2023 15:30:31 -0700 Subject: [PATCH 07/12] Update to use pm-rs 2.0.0-alpha --- .gitignore | 1 + Cargo.lock | 45 ++++++++++++++++++++++++++++---------------- Cargo.toml | 6 +++--- src/app.rs | 30 +++++++++++++---------------- src/app/audio.rs | 23 +++++++++++----------- src/app/config.rs | 14 ++++++-------- src/app/main_loop.rs | 13 +++++-------- src/dummy_audio.rs | 23 +++++++++++----------- 8 files changed, 79 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index bcbfeee..c57db47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/ target/ +.nvim-dap.lua diff --git a/Cargo.lock b/Cargo.lock index cf59b67..9c61931 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,17 +4,18 @@ version = 3 [[package]] name = "bindgen" -version = "0.64.0" +version = "0.66.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" +checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" dependencies = [ - "bitflags", + "bitflags 2.4.0", "cexpr", "clang-sys", "lazy_static", "lazycell", "log", "peeking_take_while", + "prettyplease", "proc-macro2", "quote", "regex", @@ -30,6 +31,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "cc" version = "1.0.79" @@ -108,9 +115,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "libloading" @@ -171,20 +178,28 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettyplease" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" -version = "1.0.59" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] [[package]] name = "projectm" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a14398d9b43666e48c94acb7ad337c1af8f21be46a2cfbff125bd293017ad00" +version = "2.0.0-alpha" dependencies = [ "libc", "projectm-sys", @@ -193,9 +208,7 @@ dependencies = [ [[package]] name = "projectm-sys" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129639861d045eb5cde3547d7eaa8a5366d0822e983055598eb02d5c909208f3" +version = "1.0.8" dependencies = [ "bindgen", "cmake", @@ -277,7 +290,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "041ee515e152266b6d4ade22db39b0e09486076d06e0eb7ad5cc707d4856ca4f" dependencies = [ - "bitflags", + "bitflags 1.3.2", "lazy_static", "libc", "sdl3-sys", @@ -302,9 +315,9 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "91e02e55d62894af2a08aca894c6577281f76769ba47c94d5756bec8ac6e7373" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 78be15a..cb3b977 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,9 @@ rust-version = "1.68.2" [dependencies] libc = "*" -projectm = "1.0.5" -# projectm = { path = "../projectm-rs" } -#projectm = { git = "https://github.com/projectM-visualizer/projectm" } +# projectm = "1.0.5" + projectm = { path = "../projectm-rs", version = "2.0.0-alpha", features = [] } +#projectm = { git = "https://github.com/projectM-visualizer/projectm" nd} # sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git", features = ["use-bindgen"] } sdl3 = "0.5.0" # sdl3 = { path = "../../sdl3-rs" } diff --git a/src/app.rs b/src/app.rs index 990fe98..13ba1f3 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,4 @@ -use std::sync::{Arc, Mutex}; - -use projectm::core::{ProjectMHandle, Projectm}; +use projectm::core::ProjectM; use sdl3::video::GLProfile; pub mod audio; @@ -9,12 +7,13 @@ pub mod main_loop; pub mod playlist; pub mod video; -/// Thread-safe wrapper around the projectM instance. -pub type ProjectMWrapped = Arc>; +pub type ProjectMWrapped = ProjectM; + +use std::rc::Rc; /// Application state pub struct App { - pm: ProjectMWrapped, + pm: Rc, playlist: projectm::playlist::Playlist, sdl_context: sdl3::Sdl, window: sdl3::video::Window, @@ -55,8 +54,8 @@ impl App { println!("Using video driver: {}", driver); let display_id = video_subsystem.get_primary_display_id(); let display_mode = video_subsystem.current_display_mode(display_id).unwrap(); - let window_width = 100; // display_mode.w as u32; - let window_height = 100; // display_mode.h as u32; + let window_width = display_mode.w as u32; + let window_height = display_mode.h as u32; println!( "Display {} is {}x{}", display_index, window_width, window_height @@ -75,23 +74,20 @@ impl App { window.gl_make_current(&gl_context).unwrap(); // initialize projectM - let pm = Projectm::create(); + let pm = Rc::new(ProjectMWrapped::create()); // and a preset playlist - let playlist = projectm::playlist::Playlist::create(pm); + let playlist = projectm::playlist::Playlist::create(&pm); // get/set window size - let (width, height) = window.size(); // TODO: need high DPI support here https://github.com/libsdl-org/SDL/issues/7134 - Projectm::set_window_size(pm, width.try_into().unwrap(), height.try_into().unwrap()); - - // create a mutex to protect the projectM instance - let pm = Arc::new(Mutex::new(pm)); + let (width, height) = window.size(); // TODO: handle pixel density https://github.com/libsdl-org/SDL/blob/main/docs/README-highdpi.md + pm.set_window_size(width.try_into().unwrap(), height.try_into().unwrap()); // initialize audio - let audio = audio::Audio::new(&sdl_context, pm.clone()); + let audio = audio::Audio::new(&sdl_context, Rc::clone(&pm)); Self { - pm: pm.clone(), + pm, playlist, sdl_context, window, diff --git a/src/app/audio.rs b/src/app/audio.rs index c20dce3..438953d 100644 --- a/src/app/audio.rs +++ b/src/app/audio.rs @@ -1,11 +1,11 @@ -use projectm::core::ProjectMHandle; +use projectm::core::ProjectM; use sdl3::audio::{AudioCallback, AudioDevice, AudioSpecDesired}; -use std::sync::Arc; -use std::sync::Mutex; use super::config::FrameRate; use super::ProjectMWrapped; +use std::rc::Rc; + type AudioDeviceIndex = u32; type SampleFormat = f32; // format of audio samples @@ -20,12 +20,12 @@ pub struct Audio { is_capturing: bool, frame_rate: Option, capturing_device: Option>>, - projectm: ProjectMWrapped, + projectm: Rc, } /// Wrapper around the audio subsystem to capture audio and pass it to projectM. impl Audio { - pub fn new(sdl_context: &sdl3::Sdl, projectm: ProjectMWrapped) -> Self { + pub fn new(sdl_context: &sdl3::Sdl, projectm: Rc) -> Self { let audio_subsystem = sdl_context.audio().unwrap(); println!( "Using audio driver: {}", @@ -110,9 +110,7 @@ impl Audio { // how many samples to capture at a time // should be enough for 1 frame or less // should not be larger than max_samples / channels - let max_samples: usize = projectm::core::Projectm::pcm_get_max_samples() - .try_into() - .unwrap(); + let max_samples: usize = ProjectM::pcm_get_max_samples().try_into().unwrap(); let samples_per_frame = (sample_rate / frame_rate) as usize; let buffer_size = std::cmp::min(max_samples / 2, samples_per_frame); println!("Buffer size: {}", buffer_size); @@ -135,7 +133,7 @@ impl Audio { // return callback fn AudioCaptureCallback { - pm: self.projectm.clone(), + pm: Rc::clone(&self.projectm), } }) { Ok(device) => device, @@ -176,7 +174,7 @@ impl Audio { struct AudioCaptureCallback { // we need to keep a reference to the projectm instance to // add the audio data to it - pm: Arc>, + pm: Rc, } unsafe impl Send for AudioCaptureCallback {} unsafe impl Sync for AudioCaptureCallback {} @@ -187,7 +185,8 @@ impl AudioCallback for AudioCaptureCallback { // we are receiving some chunk of audio data // we need to pass it to projectm fn callback(&mut self, out: &mut [SampleFormat]) { - let pm = *self.pm.lock().unwrap(); - projectm::core::Projectm::pcm_add_float(pm, out.to_vec(), 2); + let pm = self.pm.pcm_add_float(out.to_vec(), 2); + // pm.pcm_add_float(out.to_vec(), 2); + // projectm::core::Projectm::pcm_add_float(pm, out.to_vec(), 2); } } diff --git a/src/app/config.rs b/src/app/config.rs index 7cda7df..df2be8b 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -1,5 +1,4 @@ use crate::app::App; -use projectm::core::Projectm; use std::path::Path; pub type FrameRate = u32; @@ -57,7 +56,7 @@ impl Default for Config { impl App { pub fn load_config(&self, config: &Config) { - let pm = *self.pm.lock().unwrap(); + let pm = &self.pm; // load presets if provided if let Some(preset_path) = &config.preset_path { @@ -66,24 +65,24 @@ impl App { // set frame rate if provided if let Some(frame_rate) = config.frame_rate { - Projectm::set_fps(pm, frame_rate) + pm.set_fps(frame_rate); } // load textures if provided if let Some(texture_path) = &config.texture_path { let mut paths: Vec = Vec::new(); paths.push(texture_path.into()); - Projectm::set_texture_search_paths(pm, &paths, 1); + pm.set_texture_search_paths(&paths, 1); } // set beat sensitivity if provided if let Some(beat_sensitivity) = config.beat_sensitivity { - Projectm::set_beat_sensitivity(pm, beat_sensitivity); + pm.set_beat_sensitivity(beat_sensitivity); } // set preset duration if provided if let Some(preset_duration) = config.preset_duration { - Projectm::set_preset_duration(pm, preset_duration); + pm.set_preset_duration(preset_duration); } // set preset shuffle mode @@ -91,7 +90,6 @@ impl App { } pub fn get_frame_rate(&self) -> FrameRate { - let pm = *self.pm.lock().unwrap(); - Projectm::get_fps(pm) + self.pm.get_fps() } } diff --git a/src/app/main_loop.rs b/src/app/main_loop.rs index c82020e..73c91a8 100644 --- a/src/app/main_loop.rs +++ b/src/app/main_loop.rs @@ -1,4 +1,3 @@ -use projectm::core::Projectm; use sdl3::event::Event; use sdl3::keyboard::Keycode; @@ -101,22 +100,20 @@ impl App { dummy_audio::generate_random_audio_data(self.pm); // render a frame - { - let pm = *self.pm.lock().unwrap(); - Projectm::render_frame(pm); - } + self.pm.render_frame(); // swap buffers self.window.gl_swap_window(); if frame_rate > 0 { // calculate frame time - let frame_time: u32 = (timer.ticks() - start_time).try_into().unwrap(); + let frame_time: i32 = (timer.ticks() - start_time).try_into().unwrap(); // what do we need to hit target frame rate? - let delay_needed: u32 = 1000 / frame_rate - frame_time; + let frame_rate_i32: i32 = frame_rate.try_into().unwrap(); + let delay_needed: i32 = 1000 / frame_rate_i32 - frame_time; if delay_needed > 0 { // sleep the remaining frame time - timer.delay(delay_needed); + timer.delay(delay_needed.try_into().unwrap()); } } } diff --git a/src/dummy_audio.rs b/src/dummy_audio.rs index 6a7da0e..6463943 100644 --- a/src/dummy_audio.rs +++ b/src/dummy_audio.rs @@ -1,18 +1,17 @@ -use projectm::core::{ProjectMHandle, Projectm}; +use crate::app::ProjectMWrapped; #[allow(dead_code)] -pub fn generate_random_audio_data(projectm_handle: ProjectMHandle) { - let mut pcm_data: [[libc::c_short; 512]; 2] = [[0; 512]; 2]; - let mut i: libc::c_int = 0 as libc::c_int; - while i < 512 as libc::c_int { - if i % 2 as libc::c_int == 1 as libc::c_int { - pcm_data[0 as libc::c_int as usize][i as usize] = - -(pcm_data[0 as libc::c_int as usize][i as usize] as libc::c_int) as libc::c_short; - pcm_data[1 as libc::c_int as usize][i as usize] = - -(pcm_data[1 as libc::c_int as usize][i as usize] as libc::c_int) as libc::c_short +fn generate_random_audio_data(pm: &ProjectMWrapped) { + // Create a Vec with 1024 elements + // two channels of 512 samples each + let mut pcm_data: Vec = vec![0; 1024]; + + for i in 0..512 { + if i % 2 == 1 { + pcm_data[i * 2] = -(pcm_data[i * 2] as i32) as i16; + pcm_data[i * 2 + 1] = -(pcm_data[i * 2 + 1] as i32) as i16; } - i += 1 } - Projectm::pcm_add_int16(projectm_handle, vec![pcm_data[0][0]], 2) + pm.pcm_add_int16(pcm_data, 2); } From 4b5b3504b4f27d6389a0e2c52112854081de549f Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sun, 17 Sep 2023 15:31:13 -0700 Subject: [PATCH 08/12] WIP --- src/app/audio.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/audio.rs b/src/app/audio.rs index 438953d..bca4c82 100644 --- a/src/app/audio.rs +++ b/src/app/audio.rs @@ -185,8 +185,6 @@ impl AudioCallback for AudioCaptureCallback { // we are receiving some chunk of audio data // we need to pass it to projectm fn callback(&mut self, out: &mut [SampleFormat]) { - let pm = self.pm.pcm_add_float(out.to_vec(), 2); - // pm.pcm_add_float(out.to_vec(), 2); - // projectm::core::Projectm::pcm_add_float(pm, out.to_vec(), 2); + self.pm.pcm_add_float(out.to_vec(), 2); } } From 6ed1411043615965b787a06d6c141ecd9b812eca Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Mon, 18 Sep 2023 14:27:47 -0700 Subject: [PATCH 09/12] use Rc to safely pass around references to pm --- Cargo.lock | 53 +++++++++++++++++++++++++++++++++++++++++++----- Cargo.toml | 9 ++++---- src/app.rs | 30 ++++++++------------------- src/app/audio.rs | 6 +++--- 4 files changed, 65 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c61931..d5c904b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,29 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "bindgen" +version = "0.65.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + [[package]] name = "bindgen" version = "0.66.1" @@ -101,6 +124,25 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "include_dir" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18762faeff7122e89e0857b02f7ce6fcc0d101d5e9ad2ad7846cc01d61b7f19e" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -199,7 +241,7 @@ dependencies = [ [[package]] name = "projectm" -version = "2.0.0-alpha" +version = "2.0.1-alpha" dependencies = [ "libc", "projectm-sys", @@ -210,7 +252,7 @@ dependencies = [ name = "projectm-sys" version = "1.0.8" dependencies = [ - "bindgen", + "bindgen 0.66.1", "cmake", "lazy_static", ] @@ -219,8 +261,10 @@ dependencies = [ name = "projectm_sdl" version = "0.1.1" dependencies = [ + "include_dir", "libc", "projectm", + "rand", "sdl3", ] @@ -286,9 +330,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "sdl3" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "041ee515e152266b6d4ade22db39b0e09486076d06e0eb7ad5cc707d4856ca4f" +version = "0.6.0" dependencies = [ "bitflags 1.3.2", "lazy_static", @@ -302,6 +344,7 @@ version = "0.0.6+sdl3-dev-2023-07-31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9846a96256cb800f754bef64805689a4c75b2a1a6d855064c10321075034673" dependencies = [ + "bindgen 0.65.1", "cfg-if", "libc", "version-compare", diff --git a/Cargo.toml b/Cargo.toml index cb3b977..56cc605 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,13 @@ rust-version = "1.68.2" [dependencies] libc = "*" # projectm = "1.0.5" - projectm = { path = "../projectm-rs", version = "2.0.0-alpha", features = [] } + projectm = { path = "../projectm-rs", version = "2.0.1-alpha", features = [] } #projectm = { git = "https://github.com/projectM-visualizer/projectm" nd} # sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git", features = ["use-bindgen"] } -sdl3 = "0.5.0" -# sdl3 = { path = "../../sdl3-rs" } - +# sdl3 = "0.5.0" +sdl3 = { path = "../../sdl3-rs", version = "0.6.0", features = ["use-bindgen"] } +rand = "0.8.5" +include_dir = "0.7.3" # gl = "0.14.0" [features] diff --git a/src/app.rs b/src/app.rs index 13ba1f3..c0a1375 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,5 +1,7 @@ use projectm::core::ProjectM; -use sdl3::video::GLProfile; +use sdl3::video::{GLProfile, WindowPos}; +use std::convert::TryInto; +use std::rc::Rc; pub mod audio; pub mod config; @@ -7,13 +9,11 @@ pub mod main_loop; pub mod playlist; pub mod video; -pub type ProjectMWrapped = ProjectM; - -use std::rc::Rc; +pub type ProjectMWrapped = Rc; /// Application state pub struct App { - pm: Rc, + pm: ProjectMWrapped, playlist: projectm::playlist::Playlist, sdl_context: sdl3::Sdl, window: sdl3::video::Window, @@ -48,23 +48,11 @@ impl App { assert_eq!(gl_attr.context_version(), (3, 3)); // create window - // get screen dimensions - let display_index = 0; - let driver = video_subsystem.current_video_driver(); - println!("Using video driver: {}", driver); - let display_id = video_subsystem.get_primary_display_id(); - let display_mode = video_subsystem.current_display_mode(display_id).unwrap(); - let window_width = display_mode.w as u32; - let window_height = display_mode.h as u32; - println!( - "Display {} is {}x{}", - display_index, window_width, window_height - ); let window = video_subsystem - .window("ProjectM", window_width, window_height) + .window("ProjectM", 0, 0) .opengl() .maximized() - .position_centered() + .fullscreen() // .allow_highdpi() .build() .expect("could not initialize video subsystem"); @@ -74,13 +62,13 @@ impl App { window.gl_make_current(&gl_context).unwrap(); // initialize projectM - let pm = Rc::new(ProjectMWrapped::create()); + let pm = Rc::new(ProjectM::create()); // and a preset playlist let playlist = projectm::playlist::Playlist::create(&pm); // get/set window size - let (width, height) = window.size(); // TODO: handle pixel density https://github.com/libsdl-org/SDL/blob/main/docs/README-highdpi.md + let (width, height) = window.size_in_pixels(); pm.set_window_size(width.try_into().unwrap(), height.try_into().unwrap()); // initialize audio diff --git a/src/app/audio.rs b/src/app/audio.rs index bca4c82..24b3fbd 100644 --- a/src/app/audio.rs +++ b/src/app/audio.rs @@ -20,12 +20,12 @@ pub struct Audio { is_capturing: bool, frame_rate: Option, capturing_device: Option>>, - projectm: Rc, + projectm: ProjectMWrapped, } /// Wrapper around the audio subsystem to capture audio and pass it to projectM. impl Audio { - pub fn new(sdl_context: &sdl3::Sdl, projectm: Rc) -> Self { + pub fn new(sdl_context: &sdl3::Sdl, projectm: ProjectMWrapped) -> Self { let audio_subsystem = sdl_context.audio().unwrap(); println!( "Using audio driver: {}", @@ -174,7 +174,7 @@ impl Audio { struct AudioCaptureCallback { // we need to keep a reference to the projectm instance to // add the audio data to it - pm: Rc, + pm: ProjectMWrapped, } unsafe impl Send for AudioCaptureCallback {} unsafe impl Sync for AudioCaptureCallback {} From 5227fa4351c75160b89ffbb8e223dbc944aa1335 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sat, 7 Oct 2023 20:33:28 -0700 Subject: [PATCH 10/12] basic config loading --- Cargo.lock | 477 +++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 + src/app.rs | 11 +- src/app/audio.rs | 10 +- src/app/config.rs | 64 +++--- src/app/playlist.rs | 8 +- src/main.rs | 79 +++++++- 7 files changed, 605 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5c904b..1e5da53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,54 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anstream" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "bindgen" version = "0.65.1" @@ -21,7 +69,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn", + "syn 2.0.36", "which", ] @@ -44,7 +92,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn", + "syn 2.0.36", "which", ] @@ -60,6 +108,15 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "cc" version = "1.0.79" @@ -92,6 +149,46 @@ dependencies = [ "libloading", ] +[[package]] +name = "clap" +version = "4.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824956d0dca8334758a5b7f7e50518d66ea319330cbceedcf76905c2f6ab30e3" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122ec64120a49b4563ccaedcbea7818d069ed8e9aa6d829b82d8a4128936b2ab" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.36", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + [[package]] name = "cmake" version = "0.1.50" @@ -101,12 +198,88 @@ dependencies = [ "cc", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "confique" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7944dc1c6dec3f9b3adc127a921affd93baeea3d04c9b2d0a84380a243c9258b" +dependencies = [ + "confique-macro", + "json5", + "serde", + "serde_yaml", + "toml", +] + +[[package]] +name = "confique-macro" +version = "0.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7305b4979ffd6d8b02006da5520b21c66bfab961cd688b9b6db00780f61448ce" +dependencies = [ + "heck 0.3.3", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cpufeatures" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "either" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.8" @@ -124,6 +297,27 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "hashbrown" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "include_dir" version = "0.7.3" @@ -143,6 +337,33 @@ dependencies = [ "quote", ] +[[package]] +name = "indexmap" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -214,6 +435,51 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "pest" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c022f1e7b65d6a24c0dbbd5fb344c66881bc01f3e5ae74a1c8100f2f985d98a4" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35513f630d46400a977c4cb58f78e1bfbe01434316e60c37d27b9ad6139c66d8" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc9fc1b9e7057baba189b5c626e2d6f40681ae5b6eb064dc7c7834101ec8123a" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.36", +] + +[[package]] +name = "pest_meta" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df74e9e7ec4053ceb980e7c0c8bd3594e977fde1af91daba9c928e8e8c6708d" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -227,7 +493,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.36", ] [[package]] @@ -261,18 +527,21 @@ dependencies = [ name = "projectm_sdl" version = "0.1.1" dependencies = [ + "clap", + "confique", "include_dir", "libc", "projectm", "rand", "sdl3", + "serde", ] [[package]] name = "quote" -version = "1.0.28" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -328,6 +597,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + [[package]] name = "sdl3" version = "0.6.0" @@ -350,12 +625,73 @@ dependencies = [ "version-compare", ] +[[package]] +name = "serde" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.36", +] + +[[package]] +name = "serde_yaml" +version = "0.9.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shlex" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.36" @@ -367,18 +703,83 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "thiserror" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.36", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "unicode-ident" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "version-compare" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -417,3 +818,69 @@ 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-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml index 56cc605..5a007b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,9 @@ libc = "*" sdl3 = { path = "../../sdl3-rs", version = "0.6.0", features = ["use-bindgen"] } rand = "0.8.5" include_dir = "0.7.3" +clap = {version="4.4.5", features=["derive"]} +confique = "0.2.4" +serde = "1.0.188" # gl = "0.14.0" [features] diff --git a/src/app.rs b/src/app.rs index c0a1375..ad10b3d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,5 +1,6 @@ +use crate::app::config::Config; use projectm::core::ProjectM; -use sdl3::video::{GLProfile, WindowPos}; +use sdl3::video::GLProfile; use std::convert::TryInto; use std::rc::Rc; @@ -22,12 +23,8 @@ pub struct App { _gl_context: sdl3::video::GLContext, } -pub fn default_config() -> config::Config { - config::Config::default() -} - impl App { - pub fn new(config: Option) -> Self { + pub fn new(config: Option) -> Self { // setup sdl let sdl_context = sdl3::init().unwrap(); // print SDL version @@ -79,7 +76,7 @@ impl App { playlist, sdl_context, window, - config: config.unwrap_or_else(default_config), + config: config.unwrap_or_else(Config::default), audio, _gl_context: gl_context, // keep this around to keep the context alive } diff --git a/src/app/audio.rs b/src/app/audio.rs index 24b3fbd..1b14987 100644 --- a/src/app/audio.rs +++ b/src/app/audio.rs @@ -48,7 +48,7 @@ impl Audio { self.frame_rate = frame_rate.into(); #[cfg(not(feature = "dummy_audio"))] - self.begin_audio_capture(0); + self.begin_audio_capture(AudioDevice:: } pub fn list_devices(&self) { @@ -63,8 +63,10 @@ impl Audio { /// Start capturing audio from device_index. pub fn capture_device(&mut self, device_index: AudioDeviceIndex) { self.stop_audio_capture(); + println!("Capturing audio from device {}", device_index); self.device_index = device_index; self.begin_audio_capture(device_index); + println!("Capturing audio from device {}", device_index); } pub fn get_device_name(&self, device_index: AudioDeviceIndex) -> String { @@ -123,6 +125,7 @@ impl Audio { // open audio device for capture let device_name = self.get_device_name(device_index); + println!("Opening audio device: {}", device_name); let audio_device = match self .audio_subsystem // sdl .open_capture(device_name.as_str(), &desired_spec, |_spec| { @@ -166,8 +169,13 @@ impl Audio { let device = self.capturing_device.take().unwrap(); device.pause(); + println!("Device paused"); + self.is_capturing = false; + + println!("Stopped audio capture"); drop(device); + println!("Dropped audio device"); } } diff --git a/src/app/config.rs b/src/app/config.rs index df2be8b..a2421f6 100644 --- a/src/app/config.rs +++ b/src/app/config.rs @@ -1,20 +1,25 @@ use crate::app::App; -use std::path::Path; +use confique::Config as ConfiqueConfig; +use serde::{Deserialize, Serialize}; +use std::path::{Path, PathBuf}; pub type FrameRate = u32; +const RESOURCE_DIR_DEFAULT: &str = "/usr/local/share/projectM"; + /// Configuration for the application -/// TODO: use config crate to support loading from env/CLI/file. /// Parameters are defined here: https://github.com/projectM-visualizer/projectm/blob/master/src/api/include/projectM-4/parameters.h +// #[derive(Debug, Serialize, Deserialize)] +#[derive(ConfiqueConfig, Debug, Serialize, Deserialize)] pub struct Config { /// Frame rate to render at. Defaults to 60. pub frame_rate: Option, /// Path to the preset directory. Defaults to /usr/local/share/projectM/presets - pub preset_path: Option, + pub preset_path: Option, /// Path to the texture directory. Defaults to /usr/local/share/projectM/textures - pub texture_path: Option, + pub texture_path: Option, /// How sensitive the beat detection is. 1.0 is default. pub beat_sensitivity: Option, @@ -25,28 +30,22 @@ pub struct Config { impl Default for Config { fn default() -> Self { - // get paths to presets and textures - // TODO: get from config file or env - // - // use /usr/local/share/projectM if it exists, otherwise use local paths - let resource_dir = "/usr/local/share/projectM"; - let dir_exists = Path::new(&resource_dir).exists(); - let preset_path = if dir_exists && false { - String::from(resource_dir) + "/presets" - } else { - // just test presets - "./presets".to_owned() - }; - let texture_path = if dir_exists { - String::from(resource_dir) + "/textures" - } else { - // doesn't exist - "./textures".to_owned() - }; + let dir_exists = Path::new(&RESOURCE_DIR_DEFAULT).exists(); + + let preset_path = format!("{}/presets", RESOURCE_DIR_DEFAULT); + let texture_path = format!("{}/textures", RESOURCE_DIR_DEFAULT); Self { - preset_path: Path::new(&preset_path).exists().then(|| preset_path), - texture_path: Path::new(&texture_path).exists().then(|| texture_path), + preset_path: if dir_exists { + Some(preset_path.into()) + } else { + None + }, + texture_path: if dir_exists { + Some(texture_path.into()) + } else { + None + }, frame_rate: Some(60), beat_sensitivity: Some(1.0), preset_duration: Some(10.0), @@ -54,6 +53,20 @@ impl Default for Config { } } +impl Config { + // Merges another Config into this one + pub fn merge(&mut self, mut other: Self) { + self.frame_rate = other.frame_rate.take().or(self.frame_rate.take()); + self.preset_path = other.preset_path.take().or(self.preset_path.take()); + self.texture_path = other.texture_path.take().or(self.texture_path.take()); + self.beat_sensitivity = other + .beat_sensitivity + .take() + .or(self.beat_sensitivity.take()); + self.preset_duration = other.preset_duration.take().or(self.preset_duration.take()); + } +} + impl App { pub fn load_config(&self, config: &Config) { let pm = &self.pm; @@ -70,8 +83,7 @@ impl App { // load textures if provided if let Some(texture_path) = &config.texture_path { - let mut paths: Vec = Vec::new(); - paths.push(texture_path.into()); + let paths = [texture_path.clone().into_os_string().into_string().unwrap()]; pm.set_texture_search_paths(&paths, 1); } diff --git a/src/app/playlist.rs b/src/app/playlist.rs index 47da25f..3b51d6e 100644 --- a/src/app/playlist.rs +++ b/src/app/playlist.rs @@ -1,10 +1,12 @@ +use std::path::PathBuf; + use crate::app::App; impl App { /// Add presets to the playlist recursively skipping duplicates. - pub fn add_preset_path(&self, preset_path: &str) { - self.playlist.add_path(preset_path, true); - println!("added preset path: {}", preset_path); + pub fn add_preset_path(&self, preset_path: &PathBuf) { + self.playlist.add_path(preset_path.to_str().unwrap(), true); + println!("added preset path: {}", preset_path.to_str().unwrap()); println!("playlist size: {}", self.playlist.len()); } diff --git a/src/main.rs b/src/main.rs index 99b16be..d26247f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,84 @@ mod app; mod dummy_audio; +use std::{net::IpAddr, path::PathBuf}; + +use crate::app::config::Config; +use clap::Parser; +use confique::Config as ConfiqueConfig; + +// command line arguments +#[derive(Parser)] +/// ProjectM: the milkdrop-compatible music visualizer. +/// +/// Need help? Join discord: https://discord.gg/uSSggaMBrv +struct Cli { + // /// Get help + // #[clap(short, long)] + // help: bool, + /// Path to preset directory + #[clap(short, long)] + preset_path: Option, + + /// Path to texture directory + #[clap(short, long)] + texture_path: Option, + + /// Path to config file + #[clap(short, long)] + config_path: Option, + + /// Audio input device (name or index) + #[clap(short, long)] + audio_input: Option, +} fn main() -> Result<(), String> { - let config = app::default_config(); - // TODO: parse args here for config - // config.preset_path = Some("./presets/test".to_string()); + // parse command line arguments + let cli = Cli::parse(); - let mut app = app::App::new(Some(config)); - app.init(); + // show help + // cli.help.then(|| usage()); + // Initialize AppConfig with default values + let mut app_config = Config::default(); + + // Load from environment and config files using confique + let file_config = match Config::builder() + .env() + .file( + cli.config_path + .as_ref() + .unwrap_or(&PathBuf::from("conf.toml")), + ) + .file("conf.yaml") + .file("conf.json") + // .file("/usr/local/share/projectM/config.inp") TODO: custom parser + .load() + { + Ok(config) => config, + Err(e) => { + panic!("Error loading config: {}", e); + } + }; + + // Merge the loaded configuration into the default one + app_config.merge(file_config); + + // Override with CLI arguments + if let Some(preset_path) = cli.preset_path { + app_config.preset_path = Some(preset_path); + } + if let Some(texture_path) = cli.texture_path { + app_config.texture_path = Some(texture_path); + } + // Add other CLI overrides as needed + + // Initialize the application + let mut app = app::App::new(Some(app_config)); + app.init(); app.main_loop(); + + Ok(()) } From aaaea04d46307a7d5c06f6faf52cee060ac6d4a9 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sat, 7 Oct 2023 21:22:52 -0700 Subject: [PATCH 11/12] WIP --- .cargo/config.toml | 2 +- src/app/audio.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index a627181..fa9631c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,3 @@ [env] # use pipewire for audio -SDL_AUDIODRIVER = "pipewire" +#SDL_AUDIODRIVER = "pipewire" diff --git a/src/app/audio.rs b/src/app/audio.rs index 1b14987..7f189af 100644 --- a/src/app/audio.rs +++ b/src/app/audio.rs @@ -48,7 +48,7 @@ impl Audio { self.frame_rate = frame_rate.into(); #[cfg(not(feature = "dummy_audio"))] - self.begin_audio_capture(AudioDevice:: + self.begin_audio_capture(0); } pub fn list_devices(&self) { From 22962be0adcafd053372982a118a480ebc9e8502 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Sat, 9 Mar 2024 20:21:29 -0800 Subject: [PATCH 12/12] WIP --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5a007b8..2096eed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ rust-version = "1.68.2" [dependencies] libc = "*" # projectm = "1.0.5" - projectm = { path = "../projectm-rs", version = "2.0.1-alpha", features = [] } + projectm = { path = "../projectm-rs", version = "4.1.0-alpha.1", features = [] } #projectm = { git = "https://github.com/projectM-visualizer/projectm" nd} # sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git", features = ["use-bindgen"] } # sdl3 = "0.5.0"