comparison python/src/lib.rs @ 783:ec1e06402a97

Replace SDL2_mixer with the kira crate
author Link Mauve <linkmauve@linkmauve.fr>
date Fri, 21 Nov 2025 10:21:59 +0100
parents a30ce01b9154
children 1f152ca95658
comparison
equal deleted inserted replaced
782:a30ce01b9154 783:ec1e06402a97
1 use pyo3::exceptions::{PyIOError, PyKeyError}; 1 use pyo3::exceptions::{PyIOError, PyKeyError};
2 use pyo3::prelude::*; 2 use pyo3::prelude::*;
3 use pyo3::types::{PyBytes, PyTuple}; 3 use pyo3::types::{PyBytes, PyTuple};
4 use touhou_formats::th06::pos::LoopPoints;
4 use touhou_formats::th06::pbg3; 5 use touhou_formats::th06::pbg3;
5 use touhou_formats::th06::std as stage; 6 use touhou_formats::th06::std as stage;
6 use touhou_formats::th06::msg; 7 use touhou_formats::th06::msg;
7 use std::collections::{BTreeMap, HashMap}; 8 use std::collections::{BTreeMap, HashMap};
8 use std::fs::File; 9 use std::fs::File;
10 use std::path::PathBuf; 11 use std::path::PathBuf;
11 use std::sync::{Arc, Mutex}; 12 use std::sync::{Arc, Mutex};
12 13
13 #[cfg(feature = "glide")] 14 #[cfg(feature = "glide")]
14 mod glide; 15 mod glide;
16
17 mod audio;
15 18
16 #[pyclass(module = "libtouhou")] 19 #[pyclass(module = "libtouhou")]
17 struct PyModel { 20 struct PyModel {
18 inner: stage::Model, 21 inner: stage::Model,
19 } 22 }
94 msg::Instruction::Pause(duration) => (4, (duration,).into_pyobject(py)?), 97 msg::Instruction::Pause(duration) => (4, (duration,).into_pyobject(py)?),
95 msg::Instruction::Animate(side, effect) => (5, (side, effect).into_pyobject(py)?), 98 msg::Instruction::Animate(side, effect) => (5, (side, effect).into_pyobject(py)?),
96 msg::Instruction::SpawnEnemySprite() => (6, ().into_pyobject(py)?), 99 msg::Instruction::SpawnEnemySprite() => (6, ().into_pyobject(py)?),
97 msg::Instruction::ChangeMusic(track) => (7, (track,).into_pyobject(py)?), 100 msg::Instruction::ChangeMusic(track) => (7, (track,).into_pyobject(py)?),
98 msg::Instruction::DisplayDescription(side, index, text) => (8, (side, index, text).into_pyobject(py)?), 101 msg::Instruction::DisplayDescription(side, index, text) => (8, (side, index, text).into_pyobject(py)?),
99 msg::Instruction::ShowScores(unk1) => (8, (unk1,).into_pyobject(py)?), 102 msg::Instruction::ShowScores(unk1) => (9, (unk1,).into_pyobject(py)?),
100 msg::Instruction::Freeze() => (10, ().into_pyobject(py)?), 103 msg::Instruction::Freeze() => (10, ().into_pyobject(py)?),
101 msg::Instruction::NextStage() => (11, ().into_pyobject(py)?), 104 msg::Instruction::NextStage() => (11, ().into_pyobject(py)?),
102 msg::Instruction::Unk2() => (12, ().into_pyobject(py)?), 105 msg::Instruction::Unk2() => (12, ().into_pyobject(py)?),
103 msg::Instruction::SetAllowSkip(boolean) => (13, (boolean,).into_pyobject(py)?), 106 msg::Instruction::SetAllowSkip(boolean) => (13, (boolean,).into_pyobject(py)?),
104 msg::Instruction::Unk3() => (14, ().into_pyobject(py)?), 107 msg::Instruction::Unk3() => (14, ().into_pyobject(py)?),
203 let (_, inner) = msg::Msg::from_slice(&vec).unwrap(); 206 let (_, inner) = msg::Msg::from_slice(&vec).unwrap();
204 Ok(Py::new(py, PyMsg { inner })?) 207 Ok(Py::new(py, PyMsg { inner })?)
205 } 208 }
206 } 209 }
207 210
211 impl Loader {
212 fn get_loop_points(&self, name: &str) -> Result<LoopPoints, ()> {
213 let vec = self.get_file_internal(name).unwrap();
214 let (_, inner) = LoopPoints::from_slice(&vec).unwrap();
215 Ok(inner)
216 }
217 }
218
208 #[pymodule] 219 #[pymodule]
209 mod libtouhou { 220 mod libtouhou {
210 #[pymodule_export] 221 #[pymodule_export]
211 use super::Loader; 222 use super::Loader;
212 223
224 #[pymodule_export]
225 use crate::audio::Audio;
226
213 #[cfg(feature = "glide")] 227 #[cfg(feature = "glide")]
214 #[pymodule_export] 228 #[pymodule_export]
215 use super::glide::module; 229 use super::glide::module;
216 } 230 }