1
1
#include < pybind11/pybind11.h>
2
+ #include < pybind11/functional.h>
2
3
#include < pybind11/stl.h>
3
4
#include < pybind11/iostream.h>
4
5
#include < pybind11/operators.h>
5
6
6
7
#include < media/SoundPlayer.h>
8
+ #include < media/Sound.h>
7
9
8
10
namespace py = pybind11;
9
11
using namespace BPrivate ;
10
12
11
- void define_SoundPlayer (py::module_& m)
13
+ PYBIND11_MODULE (SoundPlayer, m)
12
14
{
13
- m.attr (" SoundPlayNode" ) = py::cast (SoundPlayNode);
15
+ // m.attr("SoundPlayNode") = py::cast(SoundPlayNode);
14
16
15
- py::class_<sound_error, std::exception>(m, " sound_error" )
17
+ /* py::class_<sound_error, std::exception>(m, "sound_error")
16
18
.def(py::init<const char *>(), "", py::arg("string"))
17
19
.def("what", &sound_error::what, "")
18
- ;
20
+ ;*/
21
+
22
+ py::register_exception<sound_error>(m, " sound_error" );
23
+ class sound_error : public std ::exception {
24
+ public:
25
+ explicit sound_error (const char * msg) : message(msg) {}
26
+ const char * what () const noexcept override {
27
+ return message;
28
+ }
29
+ private: const char * message;
30
+ };
31
+ /* In python you can write: except sound_player.sound_error as e: print(f"Caught sound_error: {e.what()}")*/
32
+
33
+ py::enum_<BSoundPlayer::sound_player_notification>(m, " sound_player_notification" , " " )
34
+ .value (" B_STARTED" , BSoundPlayer::sound_player_notification::B_STARTED, " " )
35
+ .value (" B_STOPPED" , BSoundPlayer::sound_player_notification::B_STOPPED, " " )
36
+ .value (" B_SOUND_DONE" , BSoundPlayer::sound_player_notification::B_SOUND_DONE, " " )
37
+ .export_values ();
19
38
20
39
py::class_<BSoundPlayer>(m, " BSoundPlayer" )
21
- .def (py::init<const char *, BufferPlayerFunc, EventNotifierFunc, void *>(), " " , py::arg (" name" )=NULL , py::arg (" playerFunction" )=NULL , py::arg (" eventNotifierFunction" )=NULL , py::arg (" cookie" )=NULL )
22
- .def (py::init<const media_raw_audio_format *, const char *, BufferPlayerFunc, EventNotifierFunc, void *>(), " " , py::arg (" format" ), py::arg (" name" )=NULL , py::arg (" playerFunction" )=NULL , py::arg (" eventNotifierFunction" )=NULL , py::arg (" cookie" )=NULL )
23
- .def (py::init<const media_node &, const media_multi_audio_format *, const char *, const media_input *, BufferPlayerFunc, EventNotifierFunc, void *>(), " " , py::arg (" toNode" ), py::arg (" format" )=NULL , py::arg (" name" )=NULL , py::arg (" input" )=NULL , py::arg (" playerFunction" )=NULL , py::arg (" eventNotifierFunction" )=NULL , py::arg (" cookie" )=NULL )
40
+ // .def(py::init<const char *, BufferPlayerFunc, EventNotifierFunc, void *>(), "", py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL)
41
+ // .def(py::init<const media_raw_audio_format *, const char *, BufferPlayerFunc, EventNotifierFunc, void *>(), "", py::arg("format"), py::arg("name")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL)
42
+ // .def(py::init<const media_node &, const media_multi_audio_format *, const char *, const media_input *, BufferPlayerFunc, EventNotifierFunc, void *>(), "", py::arg("toNode"), py::arg("format")=NULL, py::arg("name")=NULL, py::arg("input")=NULL, py::arg("playerFunction")=NULL, py::arg("eventNotifierFunction")=NULL, py::arg("cookie")=NULL)
43
+
44
+ .def (py::init<const char *, BSoundPlayer::BufferPlayerFunc, BSoundPlayer::EventNotifierFunc, void *>(), py::arg (" name" ) = nullptr , py::arg (" playerFunction" ) = nullptr , py::arg (" eventNotifierFunction" ) = nullptr , py::arg (" cookie" ) = nullptr )
45
+ .def (py::init<const media_raw_audio_format*, const char *, BSoundPlayer::BufferPlayerFunc, BSoundPlayer::EventNotifierFunc, void *>(), py::arg (" format" ), py::arg (" name" ) = nullptr , py::arg (" playerFunction" ) = nullptr , py::arg (" eventNotifierFunction" ) = nullptr , py::arg (" cookie" ) = nullptr )
46
+ .def (py::init<const media_node&, const media_multi_audio_format*, const char *, const media_input*, BSoundPlayer::BufferPlayerFunc, BSoundPlayer::EventNotifierFunc, void *>(), py::arg (" toNode" ), py::arg (" format" ) = nullptr , py::arg (" name" ) = nullptr , py::arg (" input" ) = nullptr , py::arg (" playerFunction" ) = nullptr , py::arg (" eventNotifierFunction" ) = nullptr , py::arg (" cookie" ) = nullptr )
47
+
24
48
.def (" InitCheck" , &BSoundPlayer::InitCheck, " " )
25
49
.def (" Format" , &BSoundPlayer::Format, " " )
26
50
.def (" Start" , &BSoundPlayer::Start, " " )
27
51
.def (" Stop" , &BSoundPlayer::Stop, " " , py::arg (" block" )=true , py::arg (" flush" )=true )
28
- .def (" BufferPlayer" , &BSoundPlayer::BufferPlayer, " " )
52
+ // .def("BufferPlayer", &BSoundPlayer::BufferPlayer, "")
53
+ // attempt1
54
+ // .def("BufferPlayer", [](const BSoundPlayer& self) { return self.BufferPlayer(); },"")
55
+ // attempt2
56
+ .def (" BufferPlayer" , [](const BSoundPlayer& self) -> std::function<void (void *, void *, size_t , const media_raw_audio_format&)> {
57
+ BSoundPlayer::BufferPlayerFunc playerFunc = self.BufferPlayer ();
58
+ return [playerFunc](void * cookie, void * buffer, size_t size, const media_raw_audio_format& format) { if (playerFunc) { playerFunc (cookie, buffer, size, format); } }; }," " ) // TODO test this
29
59
.def (" SetBufferPlayer" , &BSoundPlayer::SetBufferPlayer, " " , py::arg (" " ))
30
- .def (" EventNotifier" , &BSoundPlayer::EventNotifier, " " )
60
+ // .def("EventNotifier", &BSoundPlayer::EventNotifier, "")
61
+ // attempt variadic impossible
62
+ /* .def("EventNotifier", [](const BSoundPlayer& self) -> std::function<void(void*, BSoundPlayer::sound_player_notification, ...)> {
63
+ BSoundPlayer::EventNotifierFunc notifierFunc = self.EventNotifier();
64
+ return [notifierFunc](void* cookie, BSoundPlayer::sound_player_notification what, ...) { if (notifierFunc) { notifierFunc(cookie, what); } }; },"")*/
65
+ .def (" EventNotifier" , [](const BSoundPlayer& self) -> std::function<void (void *, BSoundPlayer::sound_player_notification)> {
66
+ BSoundPlayer::EventNotifierFunc notifierFunc = self.EventNotifier ();
67
+ return [notifierFunc](void * cookie, BSoundPlayer::sound_player_notification what) { if (notifierFunc) { notifierFunc (cookie, what); } }; }," " ) // TODO test this
31
68
.def (" SetNotifier" , &BSoundPlayer::SetNotifier, " " , py::arg (" eventNotifierFunction" ))
32
69
.def (" Cookie" , &BSoundPlayer::Cookie, " " )
33
70
.def (" SetCookie" , &BSoundPlayer::SetCookie, " " , py::arg (" cookie" ))
@@ -50,7 +87,7 @@ py::class_<BSoundPlayer>(m, "BSoundPlayer")
50
87
.def (" HasData" , &BSoundPlayer::HasData, " " )
51
88
.def (" SetHasData" , &BSoundPlayer::SetHasData, " " , py::arg (" hasData" ))
52
89
;
53
-
90
+ /*
54
91
py::class_<playing_sound>(m, "playing_sound")
55
92
.def_readwrite("next", &playing_sound::next, "")
56
93
.def_readwrite("current_offset", &playing_sound::current_offset, "")
@@ -69,7 +106,7 @@ py::class_<waiting_sound>(m, "waiting_sound")
69
106
.def_readwrite("id", &waiting_sound::id, "")
70
107
.def_readwrite("rate", &waiting_sound::rate, "")
71
108
.def_readwrite("volume", &waiting_sound::volume, "")
72
- ;
109
+ ;*/
73
110
74
111
75
112
}
0 commit comments