Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit259e6f3

Browse files
committed
update SoundPlayer.cpp, Fix init, exception
1 parent1d8bbbb commit259e6f3

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

‎Jamfile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ local sourceFiles =
346346
PlaySound.cpp
347347
Sound.cpp
348348
SoundFile.cpp
349-
#SoundPlayer.cpp
349+
SoundPlayer.cpp
350350
TimeCode.cpp
351351
TimedEventQueue.cpp
352352

@@ -395,7 +395,7 @@ LINKLIBS on MediaTheme.so = $(LINKLIBS) -lmedia ;
395395
LINKLIBS on PlaySound.so = $(LINKLIBS) -lmedia ;
396396
LINKLIBS on Sound.so = $(LINKLIBS) -lmedia ;
397397
LINKLIBS on SoundFile.so = $(LINKLIBS) -lmedia ;
398-
#LINKLIBS on SoundPlayer.so = $(LINKLIBS) -lmedia ;
398+
LINKLIBS on SoundPlayer.so = $(LINKLIBS) -lmedia ;
399399
LINKLIBS on TimeCode.so = $(LINKLIBS) -lmedia ;
400400
LINKLIBS on TimeSource.so = $(LINKLIBS) -lmedia ;
401401
LINKLIBS on TimedEventQueue.so = $(LINKLIBS) -lmedia ;

‎bindings/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
from .PlaySoundimport*
224224
from .Soundimport*
225225
from .SoundFileimport*
226-
#from .SoundPlayer import *
226+
from .SoundPlayerimport*
227227
from .TimeCodeimport*
228228
from .TimedEventQueueimport*
229229

‎bindings/media/SoundPlayer.cpp‎

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,70 @@
11
#include<pybind11/pybind11.h>
2+
#include<pybind11/functional.h>
23
#include<pybind11/stl.h>
34
#include<pybind11/iostream.h>
45
#include<pybind11/operators.h>
56

67
#include<media/SoundPlayer.h>
8+
#include<media/Sound.h>
79

810
namespacepy= pybind11;
911
usingnamespaceBPrivate;
1012

11-
voiddefine_SoundPlayer(py::module_& m)
13+
PYBIND11_MODULE(SoundPlayer, m)
1214
{
13-
m.attr("SoundPlayNode") =py::cast(SoundPlayNode);
15+
//m.attr("SoundPlayNode") = py::cast(SoundPlayNode);
1416

15-
py::class_<sound_error, std::exception>(m,"sound_error")
17+
/*py::class_<sound_error, std::exception>(m, "sound_error")
1618
.def(py::init<const char *>(), "", py::arg("string"))
1719
.def("what", &sound_error::what, "")
18-
;
20+
;*/
21+
22+
py::register_exception<sound_error>(m,"sound_error");
23+
classsound_error :publicstd::exception {
24+
public:
25+
explicitsound_error(constchar* msg) : message(msg) {}
26+
constchar*what()constnoexceptoverride {
27+
return message;
28+
}
29+
private:constchar* 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();
1938

2039
py::class_<BSoundPlayer>(m,"BSoundPlayer")
21-
.def(py::init<constchar *, 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 *,constchar *, 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 *,constchar *,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<constchar*, 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*,constchar*, 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*,constchar*,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+
2448
.def("InitCheck", &BSoundPlayer::InitCheck,"")
2549
.def("Format", &BSoundPlayer::Format,"")
2650
.def("Start", &BSoundPlayer::Start,"")
2751
.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
2959
.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
3168
.def("SetNotifier", &BSoundPlayer::SetNotifier,"",py::arg("eventNotifierFunction"))
3269
.def("Cookie", &BSoundPlayer::Cookie,"")
3370
.def("SetCookie", &BSoundPlayer::SetCookie,"",py::arg("cookie"))
@@ -50,7 +87,7 @@ py::class_<BSoundPlayer>(m, "BSoundPlayer")
5087
.def("HasData", &BSoundPlayer::HasData,"")
5188
.def("SetHasData", &BSoundPlayer::SetHasData,"",py::arg("hasData"))
5289
;
53-
90+
/*
5491
py::class_<playing_sound>(m, "playing_sound")
5592
.def_readwrite("next", &playing_sound::next, "")
5693
.def_readwrite("current_offset", &playing_sound::current_offset, "")
@@ -69,7 +106,7 @@ py::class_<waiting_sound>(m, "waiting_sound")
69106
.def_readwrite("id", &waiting_sound::id, "")
70107
.def_readwrite("rate", &waiting_sound::rate, "")
71108
.def_readwrite("volume", &waiting_sound::volume, "")
72-
;
109+
;*/
73110

74111

75112
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp