Skip to content

Commit 1c1a3a6

Browse files
committed
WIP
1 parent 68ecc4e commit 1c1a3a6

File tree

9 files changed

+51
-31
lines changed

9 files changed

+51
-31
lines changed

.cargo/config.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[env]
2+
# use pipewire for audio
3+
SDL_AUDIODRIVER = "pipewire"

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
.*
2-
!.gitignore
3-
4-
target/
1+
.vscode/
2+
target/

Cargo.lock

+2-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ rust-version = "1.68.2"
88

99
[dependencies]
1010
libc = "*"
11-
sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git" }
12-
projectm = "1.0.5"
13-
# projectm = { path = "../projectm-rs" }
11+
# sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git" }
12+
sdl3 = { path = "../../sdl3-rs" }
13+
# projectm = "1.0.5"
14+
projectm = { path = "../projectm-rs" }
1415
#projectm = { git = "https://github.com/projectM-visualizer/projectm" }
1516
# gl = "0.14.0"
1617

1718
[features]
19+
static-link = ["sdl3/static-link"]
1820
dummy_audio = []

src/app.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ impl App {
3131
pub fn new(config: Option<crate::app::config::Config>) -> Self {
3232
// setup sdl
3333
let sdl_context = sdl3::init().unwrap();
34+
// print SDL version
35+
let version = sdl3::version::version();
36+
println!(
37+
"SDL version: {}.{}.{}",
38+
version.major, version.minor, version.patch
39+
);
3440
let video_subsystem = sdl_context.video().unwrap();
3541

3642
// request GL version
@@ -45,14 +51,22 @@ impl App {
4551
// create window
4652
// get screen dimensions
4753
let display_index = 0;
48-
let display_mode = video_subsystem.desktop_display_mode(display_index).unwrap();
49-
let window_width = display_mode.w as u32;
50-
let window_height = display_mode.h as u32;
54+
let driver = video_subsystem.current_video_driver();
55+
println!("Using video driver: {}", driver);
56+
let display_id = video_subsystem.get_primary_display_id();
57+
let display_mode = video_subsystem.current_display_mode(display_id).unwrap();
58+
let window_width = 100; // display_mode.w as u32;
59+
let window_height = 100; // display_mode.h as u32;
60+
println!(
61+
"Display {} is {}x{}",
62+
display_index, window_width, window_height
63+
);
5164
let window = video_subsystem
5265
.window("ProjectM", window_width, window_height)
5366
.opengl()
67+
.maximized()
5468
.position_centered()
55-
.allow_highdpi()
69+
// .allow_highdpi()
5670
.build()
5771
.expect("could not initialize video subsystem");
5872

@@ -67,7 +81,7 @@ impl App {
6781
let playlist = projectm::playlist::Playlist::create(pm);
6882

6983
// get/set window size
70-
let (width, height) = window.drawable_size(); // highDPI aware
84+
let (width, height) = window.size(); // TODO: need high DPI support here https://github.com/libsdl-org/SDL/issues/7134
7185
Projectm::set_window_size(pm, width.try_into().unwrap(), height.try_into().unwrap());
7286

7387
// create a mutex to protect the projectM instance

src/app/audio.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub struct Audio {
2727
impl Audio {
2828
pub fn new(sdl_context: &sdl3::Sdl, projectm: ProjectMWrapped) -> Self {
2929
let audio_subsystem = sdl_context.audio().unwrap();
30+
println!(
31+
"Using audio driver: {}",
32+
audio_subsystem.current_audio_driver()
33+
);
3034

3135
Self {
3236
is_capturing: false,
@@ -44,7 +48,7 @@ impl Audio {
4448
self.frame_rate = frame_rate.into();
4549

4650
#[cfg(not(feature = "dummy_audio"))]
47-
self.begin_audio_capture();
51+
self.begin_audio_capture(0);
4852
}
4953

5054
pub fn list_devices(&self) {
@@ -60,12 +64,12 @@ impl Audio {
6064
pub fn capture_device(&mut self, device_index: AudioDeviceIndex) {
6165
self.stop_audio_capture();
6266
self.device_index = device_index;
63-
self.begin_audio_capture();
67+
self.begin_audio_capture(device_index);
6468
}
6569

66-
pub fn get_current_device_name(&self) -> String {
70+
pub fn get_device_name(&self, device_index: AudioDeviceIndex) -> String {
6771
self.audio_subsystem
68-
.audio_capture_device_name(self.device_index)
72+
.audio_capture_device_name(device_index)
6973
.expect("could not get audio device")
7074
}
7175

@@ -99,7 +103,7 @@ impl Audio {
99103
.collect::<Vec<_>>()
100104
}
101105

102-
pub fn begin_audio_capture(&mut self) {
106+
pub fn begin_audio_capture(&mut self, device_index: AudioDeviceIndex) {
103107
let sample_rate: u32 = 44100;
104108
let frame_rate = self.frame_rate.unwrap();
105109

@@ -120,7 +124,7 @@ impl Audio {
120124
};
121125

122126
// open audio device for capture
123-
let device_name = self.get_current_device_name();
127+
let device_name = self.get_device_name(device_index);
124128
let audio_device = match self
125129
.audio_subsystem // sdl
126130
.open_capture(device_name.as_str(), &desired_spec, |_spec| {
@@ -150,7 +154,7 @@ impl Audio {
150154
}
151155

152156
pub fn stop_audio_capture(&mut self) {
153-
let current_device_name = self.get_current_device_name();
157+
let current_device_name = self.get_device_name(self.device_index);
154158
println!("Stopping audio capture for device {}", current_device_name);
155159

156160
println!(
@@ -165,6 +169,7 @@ impl Audio {
165169
device.pause();
166170

167171
self.is_capturing = false;
172+
drop(device);
168173
}
169174
}
170175

src/app/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Default for Config {
3232
// use /usr/local/share/projectM if it exists, otherwise use local paths
3333
let resource_dir = "/usr/local/share/projectM";
3434
let dir_exists = Path::new(&resource_dir).exists();
35-
let preset_path = if dir_exists {
35+
let preset_path = if dir_exists && false {
3636
String::from(resource_dir) + "/presets"
3737
} else {
3838
// just test presets

src/app/main_loop.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ impl App {
111111

112112
if frame_rate > 0 {
113113
// calculate frame time
114-
let frame_time = timer.ticks() - start_time;
115-
if frame_time < 1000 / frame_rate {
114+
let frame_time: u32 = (timer.ticks() - start_time).try_into().unwrap();
115+
// what do we need to hit target frame rate?
116+
let delay_needed: u32 = 1000 / frame_rate - frame_time;
117+
if delay_needed > 0 {
116118
// sleep the remaining frame time
117-
timer.delay(1000 / frame_rate - frame_time);
119+
timer.delay(delay_needed);
118120
}
119121
}
120122
}

src/app/video.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ impl App {
55
let is_fullscreen = self.window.fullscreen_state();
66
self.window
77
.set_fullscreen(match is_fullscreen {
8-
sdl3::video::FullscreenType::True => sdl3::video::FullscreenType::Off,
9-
_ => sdl3::video::FullscreenType::True,
8+
sdl3::video::FullscreenType::True => false,
9+
_ => true,
1010
})
1111
.unwrap();
1212
}

0 commit comments

Comments
 (0)