MXVK Vulkan Framework 0.35.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
media.py
Go to the documentation of this file.
1## @file media.py
2## @brief Optional media and timing wrappers.
3
4from pathlib import Path
5
6from ._native import mxvk
7
8
10 ## @brief A straightforward elapsed-time stopwatch.
11
12 def __init__(self, name: str = "app") -> None:
13 ## @brief Create and start a steady-clock stopwatch named @p name.
14 self.native = mxvk.SteadyStopwatch(name)
15 self.native.start(name)
16
17 def seconds(self) -> float:
18 ## @brief Return elapsed seconds since the latest start.
19 return self.native.time_passed() / 1000.0
20
21 def restart(self, name: str = "app") -> None:
22 ## @brief Restart measurement with an optional label.
23 self.native.start(name)
24
25 def close(self) -> None:
26 ## @brief Stop the timer and release its native handle.
27 if self.native is not None:
28 self.native.stop()
29 self.native = None
30
31
32class Sound:
33 ## @brief Optional WAV and music playback helper.
34
35 def __init__(self) -> None:
36 ## @brief Initialize the audio mixer.
37 if not getattr(mxvk, "has_mixer", False):
38 raise RuntimeError("MXVK was built without MIXER support")
40 self.native.init()
41
42 def load_wav(self, path: str | Path) -> int:
43 ## @brief Load a WAV file and return its playback ID.
44 return self.native.load_wav(str(path))
45
46 def play(self, sound_id: int, loops: int = 0) -> int:
47 ## @brief Play a loaded WAV and return its mixer channel.
48 return self.native.play_wav(sound_id, loops)
49
50 def close(self) -> None:
51 ## @brief Release mixer resources.
52 if self.native is not None:
53 self.native.cleanup()
54 self.native = None
55
56
57class Camera:
58 ## @brief Optional OpenCV camera or video reader.
59
60 def __init__(self, source: int | str | Path = 0) -> None:
61 ## @brief Open camera index or video-file @p source.
62 if not getattr(mxvk, "has_cv", False):
63 raise RuntimeError("MXVK was built without CV support")
64 self.native = mxvk.Capture()
65 if isinstance(source, int):
66 self.native.open_camera(source)
67 else:
68 self.native.open(str(source))
69
70 def frame(self, *, flip_y: bool = False) -> object | None:
71 ## @brief Read the next RGBA NumPy frame, or @c None at end of stream.
72 return self.native.read_rgba(flip_y)
73
74 def close(self) -> None:
75 ## @brief Close the camera or video file.
76 if self.native is not None:
77 self.native.close()
78 self.native = None
SDL3_mixer-based audio manager.
object|None frame(self, *, bool flip_y=False)
Definition media.py:70
native
Open camera index or video-file source.
Definition media.py:64
None close(self)
Definition media.py:74
None __init__(self, int|str|Path source=0)
Optional OpenCV camera or video reader.
Definition media.py:60
native
Initialize the audio mixer.
Definition media.py:39
None close(self)
Definition media.py:50
None __init__(self)
Optional WAV and music playback helper.
Definition media.py:35
int load_wav(self, str|Path path)
Definition media.py:42
int play(self, int sound_id, int loops=0)
Definition media.py:46
None __init__(self, str name="app")
A straightforward elapsed-time stopwatch.
Definition media.py:12
None restart(self, str name="app")
Definition media.py:21
float seconds(self)
Definition media.py:17
native
Create and start a steady-clock stopwatch named name.
Definition media.py:14