lavalink_rs/python/model/
player.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use crate::model::player::*;

use pyo3::prelude::*;
use pythonize::{depythonize, pythonize};

pub fn player(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
    let player = PyModule::new(py, "player")?;

    player.add_class::<Player>()?;
    player.add_class::<State>()?;
    player.add_class::<ConnectionInfo>()?;
    player.add_class::<Filters>()?;
    player.add_class::<ChannelMix>()?;
    player.add_class::<Distortion>()?;
    player.add_class::<Equalizer>()?;
    player.add_class::<Karaoke>()?;
    player.add_class::<LowPass>()?;
    player.add_class::<Rotation>()?;
    player.add_class::<Timescale>()?;
    player.add_class::<TremoloVibrato>()?;

    m.add_submodule(&player)?;

    Ok(())
}

#[pymethods]
impl ConnectionInfo {
    #[new]
    fn new_py(endpoint: String, token: String, session_id: String) -> ConnectionInfo {
        ConnectionInfo {
            endpoint,
            token,
            session_id,
        }
    }

    #[pyo3(name = "fix")]
    fn fix_py(&mut self) {
        self.fix()
    }
}

#[pymethods]
impl ChannelMix {
    #[new]
    fn new_py() -> ChannelMix {
        ChannelMix::default()
    }
}

#[pymethods]
impl Distortion {
    #[new]
    fn new_py() -> Distortion {
        Distortion::default()
    }
}

#[pymethods]
impl Equalizer {
    #[new]
    fn new_py() -> Equalizer {
        Equalizer::default()
    }
}

#[pymethods]
impl Karaoke {
    #[new]
    fn new_py() -> Karaoke {
        Karaoke::default()
    }
}

#[pymethods]
impl LowPass {
    #[new]
    fn new_py() -> LowPass {
        LowPass::default()
    }
}

#[pymethods]
impl Rotation {
    #[new]
    fn new_py() -> Rotation {
        Rotation::default()
    }
}

#[pymethods]
impl Timescale {
    #[new]
    fn new_py() -> Timescale {
        Timescale::default()
    }
}

#[pymethods]
impl TremoloVibrato {
    #[new]
    fn new_py() -> TremoloVibrato {
        TremoloVibrato::default()
    }
}

#[apply(crate::python::with_getter_setter)]
#[pymethods]
impl Filters {
    getter_setter!(
        (volume, Option<f64>),
        (equalizer, Option<Vec<Equalizer>>),
        (karaoke, Option<Karaoke>),
        (timescale, Option<Timescale>),
        (tremolo, Option<TremoloVibrato>),
        (vibrato, Option<TremoloVibrato>),
        (rotation, Option<Rotation>),
        (distortion, Option<Distortion>),
        (channel_mix, Option<ChannelMix>),
        (low_pass, Option<LowPass>),
    );

    #[new]
    fn new_py() -> Filters {
        Filters::default()
    }

    #[getter(plugin_filters)]
    fn get_plugin_filters(&self, py: Python<'_>) -> PyObject {
        pythonize(py, &self.plugin_filters).unwrap().into()
    }

    #[setter(plugin_filters)]
    fn set_plugin_filters(&mut self, py: Python<'_>, input: PyObject) {
        self.plugin_filters = depythonize(&input.into_bound(py)).unwrap()
    }
}