Skip to content

Commit fe2f45d

Browse files
committed
api doc now includes class methods
1 parent 3571906 commit fe2f45d

File tree

3 files changed

+100
-15
lines changed

3 files changed

+100
-15
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,22 @@ variable number of frames per call.
354354
> An audio device provided by miniaudio, for audio capture (recording).
355355
356356

357+
> *method* ``close (self) ``
358+
359+
> > Halt playback or capture and close down the device.
360+
361+
362+
> *method* ``start (self, callback_generator: Generator[NoneType, Union[bytes, array.array], NoneType]) ``
363+
364+
> > Start the audio device: capture (recording) begins. The recorded audio data is sent to the given
365+
callback generator as raw bytes. (it should already be started before)
366+
367+
368+
> *method* ``stop (self) ``
369+
370+
> > Halt playback or capture.
371+
372+
357373
*class* ``DecodeError``
358374

359375
``DecodeError (self, /, *args, **kwargs)``
@@ -375,13 +391,40 @@ variable number of frames per call.
375391
> Query the audio playback and record devices that miniaudio provides
376392
377393

394+
> *method* ``get_captures (self) -> List[Dict[str, Any]]``
395+
396+
> > Get a list of capture devices and some details about them
397+
398+
399+
> *method* ``get_playbacks (self) -> List[Dict[str, Any]]``
400+
401+
> > Get a list of playback devices and some details about them
402+
403+
378404
*class* ``DuplexStream``
379405

380406
``DuplexStream (self, playback_format: miniaudio.SampleFormat = <SampleFormat.SIGNED16: 2>, playback_channels: int = 2, capture_format: miniaudio.SampleFormat = <SampleFormat.SIGNED16: 2>, capture_channels: int = 2, sample_rate: int = 44100, buffersize_msec: int = 200, playback_device_id: Union[_cffi_backend.CData, NoneType] = None, capture_device_id: Union[_cffi_backend.CData, NoneType] = None) ``
381407

382408
> Joins a capture device and a playback device.
383409
384410

411+
> *method* ``close (self) ``
412+
413+
> > Halt playback or capture and close down the device.
414+
415+
416+
> *method* ``start (self, callback_generator: Generator[Union[bytes, array.array], Union[bytes, array.array], NoneType]) ``
417+
418+
> > Start the audio device: playback and capture begin. The audio data for playback is provided by
419+
the given callback generator, which is sent the recorded audio data at the same time. (it should
420+
already be started before passing it in)
421+
422+
423+
> *method* ``stop (self) ``
424+
425+
> > Halt playback or capture.
426+
427+
385428
*class* ``MiniaudioError``
386429

387430
``MiniaudioError (self, /, *args, **kwargs)``
@@ -396,6 +439,24 @@ variable number of frames per call.
396439
> An audio device provided by miniaudio, for audio playback.
397440
398441

442+
> *method* ``close (self) ``
443+
444+
> > Halt playback or capture and close down the device.
445+
446+
447+
> *method* ``start (self, callback_generator: Generator[Union[bytes, array.array], int, NoneType]) ``
448+
449+
> > Start the audio device: playback begins. The audio data is provided by the given callback
450+
generator. The generator gets sent the required number of frames and should yield the sample data as
451+
raw bytes, a memoryview, an array.array, or as a numpy array with shape (numframes, numchannels).
452+
The generator should already be started before passing it in.
453+
454+
455+
> *method* ``stop (self) ``
456+
457+
> > Halt playback or capture.
458+
459+
399460
*class* ``SoundFileInfo``
400461

401462
``SoundFileInfo (self, name: str, file_format: str, nchannels: int, sample_rate: int, sample_format: miniaudio.SampleFormat, duration: float, num_frames: int) ``
@@ -410,4 +471,14 @@ variable number of frames per call.
410471
> An IO stream that reads as a .wav file, and which gets its pcm samples from the provided producer
411472
412473

474+
> *method* ``close (self) ``
475+
476+
> > Close the file
477+
478+
479+
> *method* ``read (self, amount: int = 9223372036854775807) -> Union[bytes, NoneType]``
480+
481+
> > Read up to the given amount of bytes from the file.
482+
483+
413484

miniaudio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ def __del__(self) -> None:
954954
self.close()
955955

956956
def start(self, callback_generator: GeneratorTypes) -> None:
957+
"""Start playback or capture, using the given callback generator (should already been started)"""
957958
if self.callback_generator:
958959
raise MiniaudioError("can't start an already started device")
959960
if not inspect.isgenerator(callback_generator):
@@ -1178,6 +1179,7 @@ def __init__(self, pcm_sample_gen: PlaybackCallbackGeneratorType, sample_rate: i
11781179
lib.drflac_free(data[0])
11791180

11801181
def read(self, amount: int = sys.maxsize) -> Optional[bytes]:
1182+
"""Read up to the given amount of bytes from the file."""
11811183
if self.bytes_done >= self.max_bytes or not self.sample_gen:
11821184
return b""
11831185
while len(self.buffered) < amount:
@@ -1194,4 +1196,5 @@ def read(self, amount: int = sys.maxsize) -> Optional[bytes]:
11941196
return result
11951197

11961198
def close(self) -> None:
1199+
"""Close the file"""
11971200
pass

setup.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,26 @@ def miniaudio_test_suite():
3535
)
3636

3737

38-
def make_md_docs(modulename: str = "miniaudio", width: int = 100) -> str:
38+
def make_md_docs(modulename: str = "miniaudio", width: int = 100) -> None:
3939
import importlib
4040
import inspect
4141
module = importlib.import_module(modulename)
4242
documentable_classes = []
4343
documentable_enums = []
4444
documentable_functions = []
45-
for name, item in inspect.getmembers(module):
46-
if inspect.isclass(item) or inspect.isfunction(item):
47-
# consider only non-private classes and functions from the module itself
48-
if item.__module__ == modulename and not item.__name__.startswith('_'):
49-
if inspect.isclass(item):
50-
if issubclass(item, enum.Enum):
51-
documentable_enums.append((item.__name__, item))
52-
else:
53-
documentable_classes.append((item.__name__, item))
54-
elif inspect.isfunction(item):
55-
documentable_functions.append((item.__name__, item))
45+
for name, item in inspect.getmembers(module, lambda x: inspect.isclass(x) or inspect.isfunction(x)):
46+
# consider only non-private classes and functions from the module itself
47+
if item.__module__ == modulename and not item.__name__.startswith('_'):
48+
if inspect.isclass(item):
49+
if issubclass(item, enum.Enum):
50+
documentable_enums.append((item.__name__, item))
51+
else:
52+
documentable_classes.append((item.__name__, item))
53+
elif inspect.isfunction(item):
54+
documentable_functions.append((item.__name__, item))
5655
print("\n\n=================== GENERATED API DOCS =================\n\n")
5756
for name, func in sorted(documentable_functions):
58-
doc = inspect.getdoc(func)
57+
doc = inspect.cleandoc(func.__doc__ or "")
5958
if not doc:
6059
continue # don't output if no docstring
6160
sig = str(inspect.signature(func))
@@ -66,7 +65,7 @@ def make_md_docs(modulename: str = "miniaudio", width: int = 100) -> str:
6665
print(line)
6766
print("\n")
6867
for name, enumk in sorted(documentable_enums):
69-
doc = inspect.getdoc(enumk)
68+
doc = inspect.cleandoc(enumk.__doc__ or "")
7069
if not doc:
7170
continue # don't output if no docstring
7271
print("*enum class* ``{}``".format(name))
@@ -75,7 +74,7 @@ def make_md_docs(modulename: str = "miniaudio", width: int = 100) -> str:
7574
print(line)
7675
print("\n")
7776
for name, klass in sorted(documentable_classes):
78-
doc = inspect.getdoc(klass)
77+
doc = inspect.cleandoc(klass.__doc__ or "")
7978
if not doc:
8079
continue # don't output if no docstring
8180
sig = str(inspect.signature(klass.__init__))
@@ -86,4 +85,16 @@ def make_md_docs(modulename: str = "miniaudio", width: int = 100) -> str:
8685
for line in textwrap.wrap("> "+doc, width):
8786
print(line)
8887
print("\n")
88+
# methods
89+
for mname, method in inspect.getmembers(klass, lambda x: inspect.isfunction(x) or inspect.ismethod(x)):
90+
doc = inspect.cleandoc(method.__doc__ or "")
91+
if mname.startswith('_') or not doc:
92+
continue # don't output if private or no docstring
93+
sig = str(inspect.signature(method))
94+
if sig.endswith("-> None"):
95+
sig = sig[:-7]
96+
print("> *method* ``{} {}``\n".format(mname, sig))
97+
for line in textwrap.wrap("> > "+doc, width):
98+
print(line)
99+
print("\n")
89100
print()

0 commit comments

Comments
 (0)