lavalink_rs/python/model/
player.rs

1use crate::model::player::*;
2
3use pyo3::prelude::*;
4use pythonize::{depythonize, pythonize};
5
6pub fn player(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
7    let player = PyModule::new(py, "player")?;
8
9    player.add_class::<Player>()?;
10    player.add_class::<State>()?;
11    player.add_class::<ConnectionInfo>()?;
12    player.add_class::<Filters>()?;
13    player.add_class::<ChannelMix>()?;
14    player.add_class::<Distortion>()?;
15    player.add_class::<Equalizer>()?;
16    player.add_class::<Karaoke>()?;
17    player.add_class::<LowPass>()?;
18    player.add_class::<Rotation>()?;
19    player.add_class::<Timescale>()?;
20    player.add_class::<TremoloVibrato>()?;
21
22    m.add_submodule(&player)?;
23
24    Ok(())
25}
26
27#[pymethods]
28impl ConnectionInfo {
29    #[new]
30    fn new_py(endpoint: String, token: String, session_id: String) -> ConnectionInfo {
31        ConnectionInfo {
32            endpoint,
33            token,
34            session_id,
35        }
36    }
37
38    #[pyo3(name = "fix")]
39    fn fix_py(&mut self) {
40        self.fix()
41    }
42}
43
44#[pymethods]
45impl ChannelMix {
46    #[new]
47    fn new_py() -> ChannelMix {
48        ChannelMix::default()
49    }
50}
51
52#[pymethods]
53impl Distortion {
54    #[new]
55    fn new_py() -> Distortion {
56        Distortion::default()
57    }
58}
59
60#[pymethods]
61impl Equalizer {
62    #[new]
63    fn new_py() -> Equalizer {
64        Equalizer::default()
65    }
66}
67
68#[pymethods]
69impl Karaoke {
70    #[new]
71    fn new_py() -> Karaoke {
72        Karaoke::default()
73    }
74}
75
76#[pymethods]
77impl LowPass {
78    #[new]
79    fn new_py() -> LowPass {
80        LowPass::default()
81    }
82}
83
84#[pymethods]
85impl Rotation {
86    #[new]
87    fn new_py() -> Rotation {
88        Rotation::default()
89    }
90}
91
92#[pymethods]
93impl Timescale {
94    #[new]
95    fn new_py() -> Timescale {
96        Timescale::default()
97    }
98}
99
100#[pymethods]
101impl TremoloVibrato {
102    #[new]
103    fn new_py() -> TremoloVibrato {
104        TremoloVibrato::default()
105    }
106}
107
108#[apply(crate::python::with_getter_setter)]
109#[pymethods]
110impl Filters {
111    getter_setter!(
112        (volume, Option<f64>),
113        (equalizer, Option<Vec<Equalizer>>),
114        (karaoke, Option<Karaoke>),
115        (timescale, Option<Timescale>),
116        (tremolo, Option<TremoloVibrato>),
117        (vibrato, Option<TremoloVibrato>),
118        (rotation, Option<Rotation>),
119        (distortion, Option<Distortion>),
120        (channel_mix, Option<ChannelMix>),
121        (low_pass, Option<LowPass>),
122    );
123
124    #[new]
125    fn new_py() -> Filters {
126        Filters::default()
127    }
128
129    #[getter(plugin_filters)]
130    fn get_plugin_filters(&self, py: Python<'_>) -> PyObject {
131        pythonize(py, &self.plugin_filters).unwrap().into()
132    }
133
134    #[setter(plugin_filters)]
135    fn set_plugin_filters(&mut self, py: Python<'_>, input: PyObject) {
136        self.plugin_filters = depythonize(&input.into_bound(py)).unwrap()
137    }
138}