Update dependencies, set audio volume

This commit is contained in:
Michael Zhang 2022-01-10 04:30:51 -06:00
parent 38baa566b4
commit 70072b5e1a
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
8 changed files with 1213 additions and 1004 deletions

2111
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -16,17 +16,17 @@ members = [
] ]
[dependencies] [dependencies]
anyhow = "1.0.38" anyhow = "1.0.52"
bass-sys = { path = "bass-sys" } bass-sys = { path = "bass-sys" }
ggez = { git = "https://github.com/ggez/ggez", branch = "devel" } ggez = { git = "https://github.com/ggez/ggez", branch = "devel" }
log = "0.4.13" log = "0.4.14"
stderrlog = "0.5.1" stderrlog = "0.5.1"
num = "0.3.1" num = "0.4.0"
ordered-float = "2.0.1" ordered-float = "2.10.0"
structopt = "0.3.21" structopt = "0.3.25"
image = "0.23.12" image = "0.23.14"
imgui = "0.6.1" imgui = "0.8.2"
imgui-winit-support = "0.6.1" imgui-winit-support = "0.8.2"
framework = { path = "framework" } framework = { path = "framework" }
[dependencies.libosu] [dependencies.libosu]

View file

@ -100,4 +100,10 @@ impl Sound {
bass::BASS_ChannelSetAttribute(self.handle, BASS_ATTRIB_FREQ, val * rate as f32); bass::BASS_ChannelSetAttribute(self.handle, BASS_ATTRIB_FREQ, val * rate as f32);
} }
} }
pub fn set_volume(&self, volume: f32) {
unsafe {
bass::BASS_ChannelSetAttribute(self.handle, BASS_ATTRIB_MUSIC_VOL_GLOBAL, volume);
}
}
} }

View file

@ -13,11 +13,25 @@ impl EventHandler for Game {
Ok(()) Ok(())
} }
fn mouse_motion_event(&mut self, _: &mut Context, x: f32, y: f32, _: f32, _: f32) { fn mouse_motion_event(
&mut self,
_: &mut Context,
x: f32,
y: f32,
_: f32,
_: f32,
) -> GameResult {
self.mouse_pos = (x, y); self.mouse_pos = (x, y);
Ok(())
} }
fn mouse_button_down_event(&mut self, _: &mut Context, btn: MouseButton, x: f32, y: f32) { fn mouse_button_down_event(
&mut self,
_: &mut Context,
btn: MouseButton,
x: f32,
y: f32,
) -> GameResult {
match btn { match btn {
MouseButton::Left => { MouseButton::Left => {
use super::seeker::BOUNDS; use super::seeker::BOUNDS;
@ -33,9 +47,16 @@ impl EventHandler for Game {
MouseButton::Right => self.right_drag_start = Some((x, y)), MouseButton::Right => self.right_drag_start = Some((x, y)),
_ => {} _ => {}
} }
Ok(())
} }
fn mouse_button_up_event(&mut self, _: &mut Context, btn: MouseButton, x: f32, y: f32) { fn mouse_button_up_event(
&mut self,
_: &mut Context,
btn: MouseButton,
x: f32,
y: f32,
) -> GameResult {
match btn { match btn {
MouseButton::Left => { MouseButton::Left => {
if let Some((px, py)) = self.left_drag_start { if let Some((px, py)) = self.left_drag_start {
@ -55,14 +76,17 @@ impl EventHandler for Game {
} }
_ => {} _ => {}
} }
Ok(())
} }
fn mouse_wheel_event(&mut self, _: &mut Context, x: f32, y: f32) { fn mouse_wheel_event(&mut self, _: &mut Context, x: f32, y: f32) -> GameResult {
self.seek_by_steps(-y as i32); self.seek_by_steps(-y as i32);
Ok(())
} }
fn key_up_event(&mut self, _: &mut Context, keycode: KeyCode, _: KeyMods) { fn key_up_event(&mut self, _: &mut Context, keycode: KeyCode, _: KeyMods) -> GameResult {
use KeyCode::*; use KeyCode::*;
match keycode { match keycode {
Space => self.toggle_playing(), Space => self.toggle_playing(),
Colon => {} Colon => {}
@ -71,10 +95,19 @@ impl EventHandler for Game {
} }
_ => {} _ => {}
}; };
Ok(())
} }
fn key_down_event(&mut self, _: &mut Context, keycode: KeyCode, mods: KeyMods, _: bool) { fn key_down_event(
&mut self,
_: &mut Context,
keycode: KeyCode,
mods: KeyMods,
_: bool,
) -> GameResult {
use KeyCode::*; use KeyCode::*;
self.keymap.insert(keycode); self.keymap.insert(keycode);
match keycode { match keycode {
Key1 => self.switch_tool_to(Tool::Select), Key1 => self.switch_tool_to(Tool::Select),
@ -111,6 +144,8 @@ impl EventHandler for Game {
} }
_ => {} _ => {}
}; };
Ok(())
} }
fn draw(&mut self, ctx: &mut Context) -> GameResult { fn draw(&mut self, ctx: &mut Context) -> GameResult {

View file

@ -17,7 +17,7 @@ use ggez::{
event::{KeyCode, MouseButton}, event::{KeyCode, MouseButton},
graphics::{ graphics::{
self, CanvasGeneric, Color, DrawMode, DrawParam, FilterMode, GlBackendSpec, Image, Mesh, self, CanvasGeneric, Color, DrawMode, DrawParam, FilterMode, GlBackendSpec, Image, Mesh,
Rect, StrokeOptions, Text, WHITE, Rect, StrokeOptions, Text,
}, },
Context, Context,
}; };
@ -175,6 +175,7 @@ impl Game {
} }
let song = Sound::create(dir.join(&self.beatmap.inner.audio_filename))?; let song = Sound::create(dir.join(&self.beatmap.inner.audio_filename))?;
song.set_volume(0.1);
self.song = Some(song); self.song = Some(song);
self.timestamp_changed()?; self.timestamp_changed()?;
@ -215,7 +216,7 @@ impl Game {
) )
.as_ref(), .as_ref(),
); );
graphics::queue_text(ctx, &text, [0.0, 0.0], Some(WHITE)); graphics::queue_text(ctx, &text, [0.0, 0.0], Some(Color::WHITE));
graphics::draw_queued_text(ctx, DrawParam::default(), None, FilterMode::Linear)?; graphics::draw_queued_text(ctx, DrawParam::default(), None, FilterMode::Linear)?;
struct DrawInfo<'a> { struct DrawInfo<'a> {
@ -399,7 +400,7 @@ impl Game {
ctx, ctx,
DrawMode::Stroke(StrokeOptions::default()), DrawMode::Stroke(StrokeOptions::default()),
drag_rect, drag_rect,
WHITE, Color::WHITE,
)?; )?;
graphics::draw(ctx, &drag_rect, DrawParam::default())?; graphics::draw(ctx, &drag_rect, DrawParam::default())?;
} }

View file

@ -41,7 +41,7 @@ impl Game {
Point2::from([BOUNDS.w, line_y]), Point2::from([BOUNDS.w, line_y]),
], ],
1.0, 1.0,
graphics::WHITE, Color::WHITE,
)?; )?;
graphics::draw(ctx, &line, DrawParam::default())?; graphics::draw(ctx, &line, DrawParam::default())?;
@ -75,7 +75,7 @@ impl Game {
Point2::from([x, 0.8 * BOUNDS.h]), Point2::from([x, 0.8 * BOUNDS.h]),
], ],
4.0, 4.0,
graphics::WHITE, Color::WHITE,
)?; )?;
graphics::draw(ctx, &line, DrawParam::default())?; graphics::draw(ctx, &line, DrawParam::default())?;
} }
@ -85,7 +85,13 @@ impl Game {
}; };
if let Some(canvas) = &self.seeker_cache { if let Some(canvas) = &self.seeker_cache {
graphics::draw(ctx, canvas, DrawParam::default().dest([BOUNDS.x, BOUNDS.y]).scale([1.0, 10.0]))?; graphics::draw(
ctx,
canvas,
DrawParam::default()
.dest([BOUNDS.x, BOUNDS.y])
.scale([1.0, 10.0]),
)?;
} }
Ok(()) Ok(())
} }

View file

@ -50,13 +50,13 @@ impl Game {
ctx, ctx,
DrawMode::Stroke(opts), DrawMode::Stroke(opts),
spline_mapped.as_ref(), spline_mapped.as_ref(),
graphics::WHITE, Color::WHITE,
)?; )?;
graphics::set_canvas(ctx, Some(&canvas)); graphics::set_canvas(ctx, Some(&canvas));
graphics::clear(ctx, Color::new(0.0, 0.0, 0.0, 0.0)); graphics::clear(ctx, Color::new(0.0, 0.0, 0.0, 0.0));
graphics::draw(ctx, &body, DrawParam::default())?; graphics::draw(ctx, &body, DrawParam::default())?;
graphics::set_canvas(ctx, None); graphics::set_canvas(ctx, None);
let mut border_color = graphics::WHITE; let mut border_color = Color::WHITE;
border_color.a = color.a; border_color.a = color.a;
graphics::draw(ctx, &canvas, DrawParam::default().color(border_color))?; graphics::draw(ctx, &canvas, DrawParam::default().color(border_color))?;
@ -70,7 +70,7 @@ impl Game {
ctx, ctx,
DrawMode::Stroke(opts), DrawMode::Stroke(opts),
spline_mapped.as_ref(), spline_mapped.as_ref(),
graphics::WHITE, Color::WHITE,
)?; )?;
graphics::set_canvas(ctx, Some(&canvas)); graphics::set_canvas(ctx, Some(&canvas));
graphics::clear(ctx, Color::new(0.0, 0.0, 0.0, 0.0)); graphics::clear(ctx, Color::new(0.0, 0.0, 0.0, 0.0));
@ -151,7 +151,7 @@ impl Game {
ctx, ctx,
DrawMode::Stroke(StrokeOptions::default()), DrawMode::Stroke(StrokeOptions::default()),
&points_mapped, &points_mapped,
graphics::WHITE, Color::WHITE,
)?; )?;
graphics::draw(ctx, &frame, DrawParam::default())?; graphics::draw(ctx, &frame, DrawParam::default())?;
} }
@ -160,7 +160,7 @@ impl Game {
let mut i = 0; let mut i = 0;
while i < points_mapped.len() { while i < points_mapped.len() {
let fst = points_mapped[i]; let fst = points_mapped[i];
let mut color = graphics::WHITE; let mut color = Color::WHITE;
if i < points_mapped.len() - 1 { if i < points_mapped.len() - 1 {
let snd = points_mapped[i + 1]; let snd = points_mapped[i + 1];
if fst.eq(&snd) { if fst.eq(&snd) {

View file

@ -1,6 +1,6 @@
use anyhow::Result; use anyhow::Result;
use ggez::{ use ggez::{
graphics::{self, Color, DrawMode, DrawParam, LineCap, Mesh, Rect, StrokeOptions, WHITE}, graphics::{self, Color, DrawMode, DrawParam, LineCap, Mesh, Rect, StrokeOptions},
mint::Point2, mint::Point2,
Context, Context,
}; };
@ -19,7 +19,7 @@ pub const TICKS: &[&[(Color, f32)]] = &[
&[], &[],
&[], &[],
&[], &[],
&[(WHITE, 1.0), (BLUE, 0.5), (RED, 0.5), (BLUE, 0.5)], &[(Color::WHITE, 1.0), (BLUE, 0.5), (RED, 0.5), (BLUE, 0.5)],
]; ];
impl Game { impl Game {
@ -37,7 +37,7 @@ impl Game {
Point2::from([timeline_current_line_x, BOUNDS.y + BOUNDS.h]), Point2::from([timeline_current_line_x, BOUNDS.y + BOUNDS.h]),
], ],
2.0, 2.0,
graphics::WHITE, Color::WHITE,
)?; )?;
graphics::draw(ctx, &current_line, DrawParam::default())?; graphics::draw(ctx, &current_line, DrawParam::default())?;
@ -136,7 +136,7 @@ impl Game {
Point2::from([BOUNDS.x + BOUNDS.w, BOUNDS.y + BOUNDS.h]), Point2::from([BOUNDS.x + BOUNDS.w, BOUNDS.y + BOUNDS.h]),
], ],
2.0, 2.0,
graphics::WHITE, Color::WHITE,
)?; )?;
graphics::draw(ctx, &bottom_line, DrawParam::default())?; graphics::draw(ctx, &bottom_line, DrawParam::default())?;