Skip to content

Commit

Permalink
Merge pull request #1 from pablodz/dev-functions
Browse files Browse the repository at this point in the history
✍️ All functions planned implemented
  • Loading branch information
pablodz authored Jun 23, 2021
2 parents f84915d + 7172c06 commit 857b598
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
max-line-length = 120
max-complexity = 30
max-complexity = 35
# ignore = E226,E302,E41,E711,E501,F403,F401,C901
ignore=
F401, # Imported but unused
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# v0.0.92 (2021-06-23)

ALL functions of normal way implemented and documented

# v0.0.89 (2021-06-21)

Automatic documentation fix


# v0.0.85 (2021-06-21)

All documentation online
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/fe82f8353628a4214abd/maintainability)](https://codeclimate.com/github/pablodz/pipewire_python/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/fe82f8353628a4214abd/test_coverage)](https://codeclimate.com/github/pablodz/pipewire_python/test_coverage)

Python controller, player and recorder via pipewire's commands
## **ONLY AUDIO BY NOW [PR & FR WELCOME]**

<hr>

Python controller, player and recorder via pipewire's commands.

- [Pipewire](https://gitlab.freedesktop.org/pipewire/pipewire) is a project that aims to greatly improve handling of audio and video under Linux. (Better than pulseaudio or jack)

Expand Down Expand Up @@ -65,7 +69,6 @@ audio_controller.playback(audio_filename='docs/beers.wav')
audio_controller = Controller(verbose=True)
audio_controller.record(audio_filename='docs/5sec_record.wav',
timeout_seconds=5)

```

## Documentation
Expand Down
28 changes: 26 additions & 2 deletions pipewire_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,34 @@
## Tutorial
Tutorial [here](https://github.com/pablodz/pipewire_python/blob/main/README.py)
```python
from pipewire_python.controller import Controller
# PLAYBACK: normal way
audio_controller = Controller(verbose=True)
audio_controller.set_config(rate=384000,
channels=2,
_format='f64',
volume=0.98,
quality=4,
# Debug
verbose=True)
audio_controller.playback(audio_filename='docs/beers.wav',
# Debug
verbose=True)
# RECORD: normal way
audio_controller = Controller(verbose=True)
audio_controller.record(audio_filename='docs/5sec_record.wav',
timeout_seconds=5,
# Debug
verbose=True)
```
"""

__version__ = "0.0.91"
__version__ = "0.0.92"

import sys

Expand Down
100 changes: 59 additions & 41 deletions pipewire_python/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class Controller:
"""

_pipewire_cli = { # Help
"--help": None, # -h
"--version": None,
"--verbose": None, # -v
"--help": "--help", # -h
"--version": "--version",
"--remote": None, # -r
}

Expand All @@ -70,10 +69,17 @@ class Controller:
"--latency": None, # *default=100ms (SOURCE FILE if not specified)
"--rate": None, # *default=48000
"--channels": None, # [1,2] *default=2
"--channel-map": None, # ["stereo", "surround-51", "FL,FR"...] *default=unknown
"--channel-map": None, # ["stereo", "surround-51", "FL,FR"...] *default="FL,FR"
"--format": None, # [u8|s8|s16|s32|f32|f64] *default=s16
"--volume": None, # [0.0,1.0] *default=1.000
"--quality": None, # -q # [0,15] *default=4
"--verbose": None, # -v
}

_kill_pipewire = {
"all": ["kill", "$(pidof pw-cat)"],
"playback": ["kill", "$(pidof pw-play)"],
"record": ["kill", "$(pidof pw-record)"],
}

def __init__(
Expand Down Expand Up @@ -120,10 +126,18 @@ def __init__(
self.load_list_targets(mode="playback", verbose=verbose)
self.load_list_targets(mode="record", verbose=verbose)

def _help(self):
def _help_cli(
self,
# Debug
verbose: bool = True,
):
"""Get pipewire command line help"""

raise NotImplementedError(MESSAGES_ERROR["NotImplementedError"])
mycommand = ["pipewire", self._pipewire_cli["--help"]]

stdout, _ = _execute_shell_command(command=mycommand, verbose=verbose) # stderr

return stdout

def get_version(
self,
Expand Down Expand Up @@ -157,18 +171,21 @@ def get_version(

return versions

def verbose(self):
"""[⚠️NOT IMPLEMENTED YET]
def verbose(
self,
status: bool = True,
):
"""Get full log of pipewire stream status with the command `pw-cat`
Get full log of pipewire stream status with the following command
An example of pw-cli usage is the code below:
```bash
#!/bin/bash
# For example
pw-cat --playback beers.wav --verbose
```
will generate an output like this:
that will generate an output like this:
```bash
opened file "beers.wav" format 00010002 channels:2 rate:44100
Expand All @@ -179,49 +196,30 @@ def verbose(self):
stream param change: id=2
stream properties:
media.type = "Audio"
media.category = "Playback"
media.role = "Music"
application.name = "pw-cat"
media.filename = "beers.wav"
media.name = "beers.wav"
node.name = "pw-cat"
media.software = "Lavf58.33.100"
media.format = "WAV (Microsoft)"
node.latency = "4410/44100"
stream.is-live = "true"
node.autoconnect = "true"
media.class = "Stream/Output/Audio"
...
now=0 rate=0/0 ticks=0 delay=0 queued=0
remote 0 is named "pipewire-0"
core done
stream state changed connecting -> paused
stream param change: id=2
stream param change: id=15
stream param change: id=15
stream param change: id=4
stream state changed paused -> streaming
stream param change: id=2
set stream volume to 1.000 - success
stream node 73
...
stream param change: id=15
stream param change: id=15
now=13465394419270 rate=1/48000 ticks=35840 delay=512 queued=0
now=13466525228363 rate=1/48000 ticks=90112 delay=512 queued=0
now=13467250652784 rate=1/48000 ticks=124928 delay=512 queued=0
now=13468381462104 rate=1/48000 ticks=179200 delay=512 queued=0
now=13469490934155 rate=1/48000 ticks=232448 delay=512 queued=0
now=13470600406171 rate=1/48000 ticks=285696 delay=512 queued=0
now=13471347166416 rate=1/48000 ticks=321536 delay=512 queued=0
...
stream drained
stream state changed streaming -> paused
stream param change: id=4
stream state changed paused -> unconnected
stream param change: id=4
```
"""

raise NotImplementedError(MESSAGES_ERROR["NotImplementedError"])
if status:
self._pipewire_configs["--verbose"] = " "
else:
pass

def get_config(self):
"""Return config dictionary with default or setup variables, remember that
Expand Down Expand Up @@ -280,7 +278,6 @@ def set_config(
More:
Check all links listed at the beginning of this page
""" # 1 - media_type
if media_type:
self._pipewire_configs["--media-type"] = str(media_type)
Expand Down Expand Up @@ -401,6 +398,12 @@ def set_config(
else:
raise ValueError(f"{MESSAGES_ERROR['ValueError']}[volume='{volume}'] EMPTY VALUE")

# 12 - verbose cli
if verbose: # True
self._pipewire_configs["--verbose"] = " "
else:
pass

if verbose:
print(self._pipewire_configs)

Expand Down Expand Up @@ -564,9 +567,24 @@ def clear_devices(
# Debug
verbose: bool = False,
):
"""[⚠️NOT IMPLEMENTED YET]
Function to stop process running under pipewire.
Example: pw-cat process
"""Function to stop process running under pipewire executed by
python controller and with default process name of `pw-cat`, `pw-play` or `pw-record`.
Args:
mode (`str`) : string to kill process under `pw-cat`, `pw-play` or `pw-record`.
Returns:
- stdoutdict (`dict`) : a dictionary with keys of `mode`.
Example with pipewire:
pw-cat process
"""

raise NotImplementedError(MESSAGES_ERROR["NotImplementedError"])
mycommand = self._kill_pipewire[mode]

if verbose:
print(f"[mycommands]{mycommand}")

stdout, _ = _execute_shell_command(command=mycommand, verbose=verbose)

return {mode: stdout}

0 comments on commit 857b598

Please sign in to comment.