Skip to content

Commit 15b32d6

Browse files
committed
Add cached api end points (part 3) (following #130, #131), refactoring sound api (closes #42).
1 parent 85d68f3 commit 15b32d6

File tree

17 files changed

+920
-879
lines changed

17 files changed

+920
-879
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ display = { version = "0.3", path = "api/display", package = "playdate-display",
2525
fs = { version = "0.2", path = "api/fs", package = "playdate-fs", default-features = false }
2626
gfx = { version = "0.3", path = "api/gfx", package = "playdate-graphics", default-features = false }
2727
menu = { version = "0.1", path = "api/menu", package = "playdate-menu", default-features = false }
28-
sound = { version = "0.1", path = "api/sound", package = "playdate-sound", default-features = false }
28+
sound = { version = "0.2", path = "api/sound", package = "playdate-sound", default-features = false }
2929
sprite = { version = "0.1", path = "api/sprite", package = "playdate-sprite", default-features = false }
3030
system = { version = "0.3", path = "api/system", package = "playdate-system", default-features = false }
3131
sys = { version = "0.1", path = "api/sys", package = "playdate-sys", default-features = false }

api/playdate/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ Just run `cargo new <your options>` and add do following:
100100

101101
- - -
102102

103-
Made with ❤️‍🔥 by [my](https://a.koz.world).
103+
Made with ❤️‍🔥 by [me](https://a.koz.world).
104104

105105
This software is not sponsored or supported by Panic.

api/sound/Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "playdate-sound"
3-
version = "0.1.6"
3+
version = "0.2.0"
44
readme = "README.md"
55
description = "High-level sound API built on-top of Playdate API"
66
keywords = ["playdate", "sdk", "api", "gamedev"]
@@ -44,12 +44,6 @@ name = "sp-simple"
4444
crate-type = ["dylib", "staticlib"]
4545
path = "examples/sp-simple.rs"
4646

47-
# [[example]]
48-
# name = "sp-cached"
49-
# crate-type = ["dylib", "staticlib"]
50-
# path = "examples/sp-cached.rs"
51-
# required-features = ["bindings-derive-cache"]
52-
5347
[[example]]
5448
name = "fp-simple"
5549
crate-type = ["dylib", "staticlib"]

api/sound/examples/fp-simple.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl State {
3434
/// Updates the state
3535
fn update(&mut self) -> Option<()> {
3636
let text: Cow<str> = if let Some(player) = self.player.as_ref() {
37-
let offset = player.try_get_offset().ok()?;
38-
let length = player.try_get_length().ok()?;
37+
let offset = player.get_offset();
38+
let length = player.get_length();
3939
format!("{:.2} / {:.2}", offset, length).into()
4040
} else {
4141
"no player".into()
@@ -76,15 +76,15 @@ impl State {
7676
(*(*sys::API).display).setRefreshRate?(60.0);
7777

7878
// create player
79-
self.player = Player::try_new().ok()?.into();
79+
self.player = Player::new().ok()?.into();
8080
let player = self.player.as_ref()?;
8181

8282
// load sound
8383
const SOUND_PATH: &Path = "sfx/main_theme.pda";
84-
player.try_load_into_player(SOUND_PATH).ok()?;
84+
player.load_into_player(SOUND_PATH).ok()?;
8585

8686
// start playback
87-
player.try_play(Repeat::LoopsEndlessly).ok()?;
87+
player.play(Repeat::LoopsEndlessly);
8888
},
8989
_ => {},
9090
}

api/sound/examples/sp-simple.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ impl State {
3535
/// Updates the state
3636
fn update(&mut self) -> Option<()> {
3737
let text: Cow<str> = if let Some(player) = self.player.as_ref() {
38-
let offset = player.try_get_offset().ok()?;
39-
let length = player.try_get_length().ok()?;
38+
let offset = player.get_offset();
39+
let length = player.get_length();
4040
format!("{:.2} / {:.2}", offset, length).into()
4141
} else {
4242
"no player".into()
@@ -77,16 +77,16 @@ impl State {
7777
(*(*sys::API).display).setRefreshRate?(60.0);
7878

7979
// create player
80-
self.player = Player::try_new().ok()?.into();
80+
self.player = Player::new().ok()?.into();
8181
let player = self.player.as_ref()?;
8282

8383
// load sound
8484
const SOUND_PATH: &Path = "sfx/main_theme.pda";
85-
let sample = Sample::new_from_file(SOUND_PATH);
86-
player.try_set_sample(&sample).ok()?;
85+
let sample = Sample::new_from_file(SOUND_PATH).ok()?;
86+
player.set_sample(&sample);
8787

8888
// start playback
89-
player.try_play(Repeat::LoopsEndlessly, 1.0).ok()?;
89+
player.play(Repeat::LoopsEndlessly, 1.0);
9090
},
9191
_ => {},
9292
}

api/sound/src/error.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ pub type ApiError = sys::error::Error<self::Error>;
66

77
#[derive(Debug)]
88
pub enum Error {
9+
/// The file does not exist.
910
FileNotExist,
11+
1012
/// Causes when allocation failed and/or null-ptr returned.
1113
Alloc,
14+
15+
/// Error caused by the file system.
16+
Fs(fs::error::Error),
1217
}
1318

1419
impl fmt::Display for Error {
1520
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1621
match &self {
17-
Error::FileNotExist => write!(f, "Snd: File doesn't exist"),
1822
Error::Alloc => write!(f, "Snd: Allocation failed"),
23+
Error::FileNotExist => write!(f, "Snd: File doesn't exist"),
24+
Error::Fs(err) => err.fmt(f),
1925
}
2026
}
2127
}
@@ -25,5 +31,9 @@ impl Into<ApiError> for Error {
2531
fn into(self) -> ApiError { ApiError::Api(self) }
2632
}
2733

34+
impl From<fs::error::Error> for Error {
35+
fn from(err: fs::error::Error) -> Self { Self::Fs(err) }
36+
}
37+
2838

2939
impl core::error::Error for Error {}

api/sound/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
#![feature(error_in_core)]
33
#![feature(const_trait_impl)]
44

5-
#[macro_use]
65
extern crate sys;
76
extern crate alloc;
87

98
pub mod error;
109
pub mod player;
1110
pub mod sample;
1211

12+
// TODO: sound: channel, synth, sequence, effect, lfo, envelope, source!, etc..
13+
1314

1415
pub mod prelude {
1516
pub use crate::error::ApiError as SndApiError;

0 commit comments

Comments
 (0)