mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 14:31:23 +00:00
Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 81da36f03c | |||
| 8bfa5daf78 | |||
| b816d2aa88 | |||
| 23ae562849 | |||
| e3bc1fd55f | |||
| 15964f205b | |||
| 6a0ac61033 | |||
| 4b802273f4 | |||
| baae7a1ccf | |||
| 654694cecf | |||
| 04ecf66beb | |||
| 0fe94f9112 | |||
| 9fbe42c201 | |||
| fac04c4533 | |||
| f93852bf8e | |||
| 1bb0aa959a | |||
| 7a1723fbcb | |||
| 712a0968a7 | |||
| e98e6bc2f3 | |||
| 5007b483aa | |||
| b936b58e75 | |||
| 502ef2ed89 | |||
| ce5910b9a6 | |||
| b0c670235e | |||
| f1d4ffd7fa | |||
| 6f35ab7b8b | |||
| 9a67f5479a | |||
| b727eba988 | |||
| 330c3d79d4 | |||
| dff20daace | |||
| cdc44328a8 | |||
| ac61a71dcb | |||
| 71c800c396 | |||
| 577a6d279b | |||
| 49e01f0318 | |||
| 5ea9b3b0ba | |||
| ca85d4c369 | |||
| 4499b1d3aa | |||
| d385e5356e | |||
| b4a0dc6a83 | |||
| 2e570b3bb0 | |||
| ee4554286e | |||
| 2c6f0d932e | |||
| 4e7606fdc6 | |||
| 03df631690 | |||
| 6df826f210 | |||
| cdf306cfe9 | |||
| 74a436b171 |
@@ -0,0 +1 @@
|
||||
custom: ['https://boosty.to/arabian']
|
||||
@@ -0,0 +1,84 @@
|
||||
name: Git archive
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-and-upload:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Install apt deps (jq/zip + dev-libs)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
zip jq \
|
||||
libpipewire-0.3-dev \
|
||||
libclang-dev \
|
||||
libasound2-dev
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Rust toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- name: Extract all binary names
|
||||
id: cargo-meta
|
||||
run: |
|
||||
set -euo pipefail
|
||||
BIN_NAMES=$(cargo metadata --no-deps --format-version 1 \
|
||||
| jq -r '.packages[0].targets[] | select(.kind[] | contains("bin")) | .name')
|
||||
# сохраним построчно в выход
|
||||
echo "bin_names<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$BIN_NAMES" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build all release binaries
|
||||
run: cargo build --release --locked
|
||||
|
||||
- name: Package all binaries into one archive
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
COMMIT_SHA="${{ github.sha }}"
|
||||
ARCHIVE_NAME="pwsp-${COMMIT_SHA}-linux-x64.zip"
|
||||
echo "Creating archive: $ARCHIVE_NAME"
|
||||
|
||||
FILES=()
|
||||
while IFS= read -r BIN; do
|
||||
[ -z "$BIN" ] && continue
|
||||
FILES+=("target/release/$BIN")
|
||||
done <<< "${{ steps.cargo-meta.outputs.bin_names }}"
|
||||
|
||||
if [ "${#FILES[@]}" -eq 0 ]; then
|
||||
echo "Error: no binaries were discovered via cargo metadata." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for f in "${FILES[@]}"; do
|
||||
if [ ! -f "$f" ]; then
|
||||
echo "Error: expected binary not found: $f" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Will add: $f"
|
||||
done
|
||||
|
||||
zip -j "$ARCHIVE_NAME" "${FILES[@]}"
|
||||
|
||||
- name: Upload archive as artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: archive
|
||||
path: pwsp-*.zip
|
||||
retention-days: 7
|
||||
@@ -0,0 +1,53 @@
|
||||
name: Git deb
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-and-upload:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Install apt deps (jq/zip + dev-libs)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
zip jq \
|
||||
libpipewire-0.3-dev \
|
||||
libclang-dev \
|
||||
libasound2-dev
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Rust toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- name: Build all release binaries
|
||||
run: cargo build --release --locked
|
||||
|
||||
- name: Install cargo-deb and create .deb
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cargo install --locked cargo-deb
|
||||
export PATH="$HOME/.cargo/bin:$PATH"
|
||||
|
||||
cargo-deb
|
||||
|
||||
- name: Upload .deb(s) as artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: deb-packages
|
||||
path: target/debian/*.deb
|
||||
retention-days: 7
|
||||
@@ -0,0 +1,27 @@
|
||||
name: Git Flatpak
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
pull_request:
|
||||
branches: [main, master]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
flatpak-build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: bilelmoussaoui/flatpak-github-actions:freedesktop-24.08
|
||||
options: --privileged
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Build Flatpak
|
||||
uses: flatpak/flatpak-github-actions/flatpak-builder@v6
|
||||
with:
|
||||
bundle: ru.arabianq.pwsp.flatpak
|
||||
manifest-path: packages/flatpak/ru.arabianq.pwsp.yaml
|
||||
cache: true
|
||||
branch: master
|
||||
build-bundle: true
|
||||
@@ -10,7 +10,7 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: 'Tag to attach assets to (e.g. v1.0.0)'
|
||||
description: "Tag to attach assets to (e.g. v1.0.0)"
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
@@ -32,7 +32,6 @@ jobs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# приоритет 1: входной параметр workflow_dispatch
|
||||
INPUT_TAG="${{ github.event.inputs.tag || '' }}"
|
||||
if [ -n "$INPUT_TAG" ]; then
|
||||
echo "Using input tag: $INPUT_TAG"
|
||||
@@ -40,7 +39,6 @@ jobs:
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# приоритет 2: если запущено событием release
|
||||
EVENT_TAG="${{ github.event.release.tag_name || '' }}"
|
||||
if [ -n "$EVENT_TAG" ]; then
|
||||
echo "Using event tag: $EVENT_TAG"
|
||||
@@ -48,14 +46,12 @@ jobs:
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# приоритет 3: если GITHUB_REF — refs/tags/...
|
||||
if [[ "${GITHUB_REF:-}" =~ ^refs/tags/(.+)$ ]]; then
|
||||
echo "Using GITHUB_REF tag: ${BASH_REMATCH[1]}"
|
||||
echo "tag=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# приоритет 4: пробуем получить последний релиз через API
|
||||
echo "No tag in input/event/GITHUB_REF — querying latest release via API..."
|
||||
LATEST_JSON=$(curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/${{ github.repository }}/releases/latest" || true)
|
||||
TAG_NAME=$(echo "$LATEST_JSON" | jq -r '.tag_name // empty')
|
||||
@@ -91,7 +87,6 @@ jobs:
|
||||
set -euo pipefail
|
||||
BIN_NAMES=$(cargo metadata --no-deps --format-version 1 \
|
||||
| jq -r '.packages[0].targets[] | select(.kind[] | contains("bin")) | .name')
|
||||
# сохраним построчно в выход
|
||||
echo "bin_names<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$BIN_NAMES" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
@@ -107,7 +102,6 @@ jobs:
|
||||
ARCHIVE_NAME="pwsp-${TAG}-linux-x64.zip"
|
||||
echo "Creating archive: $ARCHIVE_NAME"
|
||||
|
||||
# читаем построчно список бинарников и формируем массив файлов
|
||||
FILES=()
|
||||
while IFS= read -r BIN; do
|
||||
[ -z "$BIN" ] && continue
|
||||
@@ -119,7 +113,6 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# проверим, что все бинарники действительно есть
|
||||
for f in "${FILES[@]}"; do
|
||||
if [ ! -f "$f" ]; then
|
||||
echo "Error: expected binary not found: $f" >&2
|
||||
@@ -128,7 +121,6 @@ jobs:
|
||||
echo "Will add: $f"
|
||||
done
|
||||
|
||||
# создаём архив с бинарниками внутри как просто pwsp-gui, pwsp-daemon, pwsp-cli
|
||||
zip -j "$ARCHIVE_NAME" "${FILES[@]}"
|
||||
|
||||
- name: Upload release archive
|
||||
|
||||
@@ -10,7 +10,7 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: 'Tag to attach assets to (e.g. v1.0.0)'
|
||||
description: "Tag to attach assets to (e.g. v1.0.0)"
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
name: Release Flatpak
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: "Tag to attach assets to (e.g. v1.0.0)"
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
flatpak-release:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: bilelmoussaoui/flatpak-github-actions:freedesktop-24.08
|
||||
options: --privileged
|
||||
|
||||
steps:
|
||||
- name: Determine tag to use
|
||||
id: tag
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
INPUT_TAG="${{ github.event.inputs.tag || '' }}"
|
||||
if [ -n "$INPUT_TAG" ]; then
|
||||
echo "tag=$INPUT_TAG" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
EVENT_TAG="${{ github.event.release.tag_name || '' }}"
|
||||
if [ -n "$EVENT_TAG" ]; then
|
||||
echo "tag=$EVENT_TAG" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "${GITHUB_REF:-}" =~ ^refs/tags/(.+)$ ]]; then
|
||||
echo "tag=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "No tag found"
|
||||
echo "tag=" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Fail if no tag determined
|
||||
if: ${{ steps.tag.outputs.tag == '' }}
|
||||
run: |
|
||||
echo "ERROR: No tag determined."
|
||||
exit 1
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ steps.tag.outputs.tag }}
|
||||
|
||||
- name: Build Flatpak
|
||||
uses: flatpak/flatpak-github-actions/flatpak-builder@v6
|
||||
with:
|
||||
bundle: ru.arabianq.pwsp.flatpak
|
||||
manifest-path: packages/flatpak/ru.arabianq.pwsp.yaml
|
||||
cache: true
|
||||
branch: master
|
||||
build-bundle: true
|
||||
|
||||
- name: Upload Flatpak to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag_name: ${{ steps.tag.outputs.tag }}
|
||||
files: ru.arabianq.pwsp.flatpak
|
||||
@@ -0,0 +1,9 @@
|
||||
[submodule "packages/aur"]
|
||||
path = packages/aur
|
||||
url = ssh://aur@aur.archlinux.org/pwsp.git
|
||||
[submodule "packages/aur/standart"]
|
||||
path = packages/aur/standart
|
||||
url = ssh://aur@aur.archlinux.org/pwsp.git
|
||||
[submodule "packages/aur/bin"]
|
||||
path = packages/aur/bin
|
||||
url = ssh://aur@aur.archlinux.org/pwsp-bin.git
|
||||
Generated
+829
-121
File diff suppressed because it is too large
Load Diff
+59
-12
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "pwsp"
|
||||
version = "1.4.0"
|
||||
version = "1.6.0"
|
||||
edition = "2024"
|
||||
authors = ["arabian"]
|
||||
description = "PWSP lets you play audio files through your microphone. Has both CLI and GUI clients."
|
||||
@@ -18,16 +18,39 @@ async-trait = "0.1.89"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.149"
|
||||
|
||||
clap = { version = "4.5.54", default-features = false, features = ["std", "suggestions", "help", "usage", "error-context", "derive"] }
|
||||
clap = { version = "4.5.58", default-features = false, features = [
|
||||
"std",
|
||||
"suggestions",
|
||||
"help",
|
||||
"usage",
|
||||
"error-context",
|
||||
"derive",
|
||||
] }
|
||||
dirs = "6.0.0"
|
||||
itertools = "0.14.0"
|
||||
|
||||
rodio = { version = "0.21.1", default-features = false, features = ["symphonia-all", "playback"] }
|
||||
rodio = { version = "0.21.1", default-features = false, features = [
|
||||
"symphonia-all",
|
||||
"playback",
|
||||
] }
|
||||
pipewire = "0.9.2"
|
||||
rfd = { version = "0.17.2", default-features = false, features = ["xdg-portal"]}
|
||||
rfd = { version = "0.17.2", default-features = false, features = [
|
||||
"xdg-portal",
|
||||
] }
|
||||
opener = { version = "0.8.4", features = ["reveal"] }
|
||||
|
||||
egui = { version = "0.33.3", default-features = false, features = ["default_fonts", "rayon"] }
|
||||
eframe = { version = "0.33.3", default-features = false, features = ["default_fonts", "glow", "x11", "wayland"] }
|
||||
egui = { version = "0.33.3", default-features = false, features = [
|
||||
"default_fonts",
|
||||
"rayon",
|
||||
] }
|
||||
eframe = { version = "0.33.3", default-features = false, features = [
|
||||
"default_fonts",
|
||||
"glow",
|
||||
"x11",
|
||||
"wayland",
|
||||
] }
|
||||
egui_material_icons = "0.5.0"
|
||||
egui_dnd = "0.14.0"
|
||||
|
||||
[[bin]]
|
||||
name = "pwsp-daemon"
|
||||
@@ -50,10 +73,34 @@ panic = "abort"
|
||||
|
||||
[package.metadata.deb]
|
||||
assets = [
|
||||
["target/release/pwsp-daemon", "usr/bin/", "755"],
|
||||
["target/release/pwsp-cli", "usr/bin/", "755"],
|
||||
["target/release/pwsp-gui", "usr/bin/", "755"],
|
||||
["assets/pwsp-gui.desktop", "usr/share/applications/pwsp.desktop", "644"],
|
||||
["assets/icon.png", "usr/share/icons/hicolor/256x256/apps/pwsp.png", "644"],
|
||||
["assets/pwsp-daemon.service", "usr/lib/systemd/user/pwsp-daemon.service", "644"],
|
||||
[
|
||||
"target/release/pwsp-daemon",
|
||||
"usr/bin/",
|
||||
"755",
|
||||
],
|
||||
[
|
||||
"target/release/pwsp-cli",
|
||||
"usr/bin/",
|
||||
"755",
|
||||
],
|
||||
[
|
||||
"target/release/pwsp-gui",
|
||||
"usr/bin/",
|
||||
"755",
|
||||
],
|
||||
[
|
||||
"assets/pwsp-gui.desktop",
|
||||
"usr/share/applications/pwsp.desktop",
|
||||
"644",
|
||||
],
|
||||
[
|
||||
"assets/icon.png",
|
||||
"usr/share/icons/hicolor/256x256/apps/pwsp.png",
|
||||
"644",
|
||||
],
|
||||
[
|
||||
"assets/pwsp-daemon.service",
|
||||
"usr/lib/systemd/user/pwsp-daemon.service",
|
||||
"644",
|
||||
],
|
||||
]
|
||||
@@ -24,6 +24,9 @@ chats on platforms like **Discord, Zoom, or Teamspeak**.
|
||||
* **Position slider** to fast-forward or rewind the audio.
|
||||
* **Persistent Configuration**: The list of added directories and your selected audio output device are saved
|
||||
automatically, so you won't need to reconfigure them every time you launch the application.
|
||||
* **Collapsible Audio Tracks**: You can collapse every audio track to save space.
|
||||
* **Drag and Drop Directories**: Reorder your sound directories easily using drag and drop.
|
||||
* **Automatic Device Detection**: PWSP automatically detects when an input device is connected or disconnected and handles linking/unlinking.
|
||||
|
||||
# **⚙️ How It Works**
|
||||
|
||||
@@ -73,7 +76,7 @@ sudo dnf install pwsp
|
||||
There is pwsp package in AUR.
|
||||
You can install it using yay, paru or any other AUR helper.
|
||||
```bash
|
||||
paru pwsp
|
||||
paru pwsp-bin # or paru pwsp to build it locally
|
||||
```
|
||||
|
||||
## **Installing using cargo**
|
||||
@@ -179,7 +182,6 @@ pwsp-cli --help
|
||||
|
||||
| Key | Action |
|
||||
| :----------------------- | :--------------------------------------------------- |
|
||||
| **Esc** | Close application |
|
||||
| **Space** | Pause / Resume audio |
|
||||
| **Backspace** | Stop all audio tracks |
|
||||
| **Enter** | Play selected file (stops all other tracks) |
|
||||
@@ -206,3 +208,6 @@ a [pull request](https://github.com/arabianq/pipewire-soundpad/pulls).
|
||||
|
||||
This project is licensed under
|
||||
the [MIT License](https://github.com/arabianq/pipewire-soundpad/blob/main/LICENSE).
|
||||
|
||||
# **🤖 AI Wiki**
|
||||
[](https://deepwiki.com/arabianq/pipewire-soundpad)
|
||||
|
||||
@@ -3,7 +3,6 @@ Description=Pipewire Soundpad Daemon
|
||||
After=pipewire.service
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/usr/bin/sleep 10
|
||||
ExecStart=/usr/bin/pwsp-daemon
|
||||
Restart=no
|
||||
RuntimeDirectory=pwsp
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 84 KiB |
Submodule
+1
Submodule packages/aur/bin added at 534cbc33ba
Submodule
+1
Submodule packages/aur/standart added at b381a90a50
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
pwsp-daemon &
|
||||
exec pwsp-gui "$@"
|
||||
@@ -0,0 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Name=PWSP (Soundpad)
|
||||
Comment=Let's you play audio files through you microphone
|
||||
Exec=pwsp-wrapper.sh %u
|
||||
Icon=ru.arabianq.pwsp
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=Audio;Utility;
|
||||
Keywords=soundpad;pipewire;audio;
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component type="desktop-application">
|
||||
<id>ru.arabianq.pwsp</id>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<project_license>MIT</project_license>
|
||||
<name>PWSP</name>
|
||||
<summary>Play audio files through your microphone using PipeWire</summary>
|
||||
<description>
|
||||
<p>
|
||||
PWSP (PipeWire Soundpad) is a tool that allows you to play audio files through your
|
||||
microphone.
|
||||
It features both a graphical user interface and a command-line interface.
|
||||
</p>
|
||||
</description>
|
||||
<launchable type="desktop-id">ru.arabianq.pwsp.desktop</launchable>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<image>
|
||||
https://raw.githubusercontent.com/arabianq/pipewire-soundpad/master/assets/screenshot.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
<url type="homepage">https://pwsp.arabianq.ru</url>
|
||||
<developer_name>arabian</developer_name>
|
||||
<content_rating type="oars-1.1" />
|
||||
</component>
|
||||
@@ -0,0 +1,47 @@
|
||||
app-id: ru.arabianq.pwsp
|
||||
runtime: org.freedesktop.Platform
|
||||
runtime-version: "24.08"
|
||||
sdk: org.freedesktop.Sdk
|
||||
sdk-extensions:
|
||||
- org.freedesktop.Sdk.Extension.rust-stable
|
||||
- org.freedesktop.Sdk.Extension.llvm20
|
||||
command: pwsp-wrapper.sh
|
||||
finish-args:
|
||||
- --share=ipc
|
||||
- --socket=fallback-x11
|
||||
- --socket=wayland
|
||||
- --socket=pulseaudio
|
||||
- --filesystem=xdg-run/pipewire-0
|
||||
- --filesystem=xdg-run/pwsp:create
|
||||
- --filesystem=xdg-run/app/ru.arabianq.pwsp:create
|
||||
- --filesystem=host
|
||||
- --device=all
|
||||
- --device=dri
|
||||
- --share=network
|
||||
- --talk-name=org.freedesktop.portal.Desktop
|
||||
- --talk-name=org.freedesktop.portal.Documents
|
||||
|
||||
build-options:
|
||||
append-path: /usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm20/bin
|
||||
env:
|
||||
CARGO_HOME: /run/build/pwsp/cargo
|
||||
LIBCLANG_PATH: /usr/lib/sdk/llvm20/lib
|
||||
|
||||
modules:
|
||||
- name: pwsp
|
||||
buildsystem: simple
|
||||
build-options:
|
||||
build-args:
|
||||
- --share=network
|
||||
build-commands:
|
||||
- cargo build --release
|
||||
- install -Dm755 target/release/pwsp-daemon /app/bin/pwsp-daemon
|
||||
- install -Dm755 target/release/pwsp-cli /app/bin/pwsp-cli
|
||||
- install -Dm755 target/release/pwsp-gui /app/bin/pwsp-gui
|
||||
- install -Dm755 packages/flatpak/pwsp-wrapper.sh /app/bin/pwsp-wrapper.sh
|
||||
- install -Dm644 assets/icon.png /app/share/icons/hicolor/256x256/apps/ru.arabianq.pwsp.png
|
||||
- install -Dm644 packages/flatpak/ru.arabianq.pwsp.desktop /app/share/applications/ru.arabianq.pwsp.desktop
|
||||
- install -Dm644 packages/flatpak/ru.arabianq.pwsp.metainfo.xml /app/share/metainfo/ru.arabianq.pwsp.metainfo.xml
|
||||
sources:
|
||||
- type: dir
|
||||
path: ../../
|
||||
@@ -4,7 +4,7 @@
|
||||
%global cargo_install_lib 0
|
||||
|
||||
Name: pwsp
|
||||
Version: 1.4.0
|
||||
Version: 1.6.0
|
||||
Release: %autorelease
|
||||
Summary: Lets you play audio files through your microphone
|
||||
|
||||
@@ -92,6 +92,10 @@ enum GetCommands {
|
||||
Input,
|
||||
/// All audio inputs
|
||||
Inputs,
|
||||
/// Version of the daemon
|
||||
DaemonVersion,
|
||||
/// Full player state
|
||||
FullState,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
@@ -146,6 +150,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
GetCommands::Tracks => Request::get_tracks(),
|
||||
GetCommands::Input => Request::get_input(),
|
||||
GetCommands::Inputs => Request::get_inputs(),
|
||||
GetCommands::DaemonVersion => Request::get_daemon_version(),
|
||||
GetCommands::FullState => Request::get_full_state(),
|
||||
},
|
||||
Commands::Set { parameter } => match parameter {
|
||||
SetCommands::Volume { volume, id } => Request::set_volume(volume, id),
|
||||
|
||||
+174
-90
@@ -1,14 +1,13 @@
|
||||
use crate::gui::{SUPPORTED_EXTENSIONS, SoundpadGui};
|
||||
use crate::gui::SoundpadGui;
|
||||
use egui::{
|
||||
Align, AtomExt, Button, Color32, ComboBox, FontFamily, Label, Layout, RichText, ScrollArea,
|
||||
Slider, TextEdit, Ui, Vec2,
|
||||
Align, AtomExt, Button, CollapsingHeader, Color32, ComboBox, CursorIcon, FontFamily, Label,
|
||||
Layout, RichText, ScrollArea, Sense, Slider, TextEdit, Ui, Vec2,
|
||||
};
|
||||
use egui_material_icons::icons;
|
||||
use pwsp::types::audio_player::TrackInfo;
|
||||
use egui_dnd::dnd;
|
||||
use egui_material_icons::icons::*;
|
||||
use pwsp::types::{audio_player::TrackInfo, gui::AppState};
|
||||
use pwsp::utils::gui::format_time_pair;
|
||||
use std::{error::Error, path::PathBuf, time::Instant};
|
||||
|
||||
use pwsp::types::gui::AppState;
|
||||
use std::{error::Error, time::Instant};
|
||||
|
||||
enum TrackAction {
|
||||
Pause(u32),
|
||||
@@ -20,13 +19,13 @@ enum TrackAction {
|
||||
impl SoundpadGui {
|
||||
fn get_volume_icon(volume: f32) -> &'static str {
|
||||
if volume > 0.7 {
|
||||
icons::ICON_VOLUME_UP
|
||||
ICON_VOLUME_UP
|
||||
} else if volume <= 0.0 {
|
||||
icons::ICON_VOLUME_OFF
|
||||
ICON_VOLUME_OFF
|
||||
} else if volume < 0.3 {
|
||||
icons::ICON_VOLUME_MUTE
|
||||
ICON_VOLUME_MUTE
|
||||
} else {
|
||||
icons::ICON_VOLUME_DOWN
|
||||
ICON_VOLUME_DOWN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +44,7 @@ impl SoundpadGui {
|
||||
ui.spacing_mut().item_spacing.y = 5.0;
|
||||
// --------- Back Button and Title ----------
|
||||
ui.horizontal_top(|ui| {
|
||||
let back_button = Button::new(icons::ICON_ARROW_BACK).frame(false);
|
||||
let back_button = Button::new(ICON_ARROW_BACK).frame(false);
|
||||
let back_button_response = ui.add(back_button);
|
||||
if back_button_response.clicked() {
|
||||
self.app_state.show_settings = false;
|
||||
@@ -82,6 +81,10 @@ impl SoundpadGui {
|
||||
self.config.save_to_file().ok();
|
||||
}
|
||||
// --------------------------------
|
||||
|
||||
ui.with_layout(Layout::bottom_up(Align::Min), |ui| {
|
||||
ui.label(format!("GUI version: {}", env!("CARGO_PKG_VERSION")));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,46 +98,45 @@ impl SoundpadGui {
|
||||
|
||||
fn draw_header(&mut self, ui: &mut Ui) {
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
self.draw_controls(ui);
|
||||
});
|
||||
}
|
||||
if self.audio_player_state.tracks.is_empty() {
|
||||
ui.label("No tracks playing");
|
||||
return;
|
||||
}
|
||||
|
||||
fn draw_controls(&mut self, ui: &mut Ui) {
|
||||
if self.audio_player_state.tracks.is_empty() {
|
||||
ui.label("No tracks playing");
|
||||
return;
|
||||
}
|
||||
let tracks = self.audio_player_state.tracks.clone();
|
||||
let mut action = None;
|
||||
|
||||
let tracks = self.audio_player_state.tracks.clone();
|
||||
let mut action = None;
|
||||
|
||||
for track in tracks {
|
||||
ui.label(
|
||||
RichText::new(
|
||||
track
|
||||
.path
|
||||
.file_stem()
|
||||
.unwrap_or_default()
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
for track in tracks {
|
||||
CollapsingHeader::new(
|
||||
RichText::new(
|
||||
track
|
||||
.path
|
||||
.file_stem()
|
||||
.unwrap_or_default()
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.color(Color32::WHITE)
|
||||
.family(FontFamily::Monospace),
|
||||
)
|
||||
.color(Color32::WHITE)
|
||||
.family(FontFamily::Monospace),
|
||||
);
|
||||
if let Some(act) = Self::draw_track_control(ui, &mut self.app_state, &track) {
|
||||
action = Some(act);
|
||||
.default_open(true)
|
||||
.show(ui, |ui| {
|
||||
if let Some(act) = Self::draw_track_control(ui, &mut self.app_state, &track) {
|
||||
action = Some(act);
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
}
|
||||
ui.separator();
|
||||
}
|
||||
|
||||
if let Some(action) = action {
|
||||
match action {
|
||||
TrackAction::Pause(id) => self.pause(Some(id)),
|
||||
TrackAction::Resume(id) => self.resume(Some(id)),
|
||||
TrackAction::ToggleLoop(id) => self.toggle_loop(Some(id)),
|
||||
TrackAction::Stop(id) => self.stop(Some(id)),
|
||||
if let Some(action) = action {
|
||||
match action {
|
||||
TrackAction::Pause(id) => self.pause(Some(id)),
|
||||
TrackAction::Resume(id) => self.resume(Some(id)),
|
||||
TrackAction::ToggleLoop(id) => self.toggle_loop(Some(id)),
|
||||
TrackAction::Stop(id) => self.stop(Some(id)),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_track_control(
|
||||
@@ -169,9 +171,9 @@ impl SoundpadGui {
|
||||
ui.horizontal_top(|ui| {
|
||||
// ---------- Play Button ----------
|
||||
let play_button = Button::new(if track.paused {
|
||||
icons::ICON_PLAY_ARROW
|
||||
ICON_PLAY_ARROW
|
||||
} else {
|
||||
icons::ICON_PAUSE
|
||||
ICON_PAUSE
|
||||
})
|
||||
.corner_radius(15.0);
|
||||
|
||||
@@ -188,9 +190,9 @@ impl SoundpadGui {
|
||||
// ---------- Loop Button ----------
|
||||
let loop_button = Button::new(
|
||||
RichText::new(if track.looped {
|
||||
icons::ICON_REPEAT_ONE
|
||||
ICON_REPEAT_ONE
|
||||
} else {
|
||||
icons::ICON_REPEAT
|
||||
ICON_REPEAT
|
||||
})
|
||||
.size(18.0),
|
||||
)
|
||||
@@ -248,7 +250,7 @@ impl SoundpadGui {
|
||||
// --------------------------------
|
||||
|
||||
// ---------- Stop Button ---------
|
||||
let stop_button = Button::new(icons::ICON_CLOSE).frame(false);
|
||||
let stop_button = Button::new(ICON_CLOSE).frame(false);
|
||||
let stop_button_response = ui.add_sized([30.0, 30.0], stop_button);
|
||||
if stop_button_response.clicked() {
|
||||
action = Some(TrackAction::Stop(track.id));
|
||||
@@ -260,11 +262,37 @@ impl SoundpadGui {
|
||||
}
|
||||
|
||||
fn draw_body(&mut self, ui: &mut Ui) {
|
||||
let dirs_size = Vec2::new(ui.available_width() / 4.0, ui.available_height() - 40.0);
|
||||
let left_panel_width = self
|
||||
.config
|
||||
.left_panel_width
|
||||
.max(100.0)
|
||||
.min(ui.available_width() - 100.0);
|
||||
let dirs_size = Vec2::new(left_panel_width, ui.available_height() - 40.0);
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
self.draw_dirs(ui, dirs_size);
|
||||
ui.separator();
|
||||
|
||||
let (rect, response) = ui.allocate_at_least(
|
||||
Vec2::new(ui.spacing().item_spacing.x, ui.available_height()),
|
||||
Sense::click_and_drag(),
|
||||
);
|
||||
|
||||
if ui.is_rect_visible(rect) {
|
||||
let stroke = ui.visuals().widgets.noninteractive.bg_stroke;
|
||||
ui.painter().vline(rect.center().x, rect.y_range(), stroke);
|
||||
}
|
||||
|
||||
let vertical_separator_response =
|
||||
response.on_hover_and_drag_cursor(CursorIcon::ResizeHorizontal);
|
||||
|
||||
if vertical_separator_response.dragged() {
|
||||
self.config.left_panel_width += vertical_separator_response.drag_delta().x;
|
||||
self.config.left_panel_width = self.config.left_panel_width.clamp(100.0, 500.0);
|
||||
}
|
||||
|
||||
if vertical_separator_response.drag_stopped() {
|
||||
self.config.save_to_file().ok();
|
||||
}
|
||||
|
||||
let files_size = Vec2::new(ui.available_width(), ui.available_height() - 40.0);
|
||||
self.draw_files(ui, files_size);
|
||||
@@ -279,10 +307,14 @@ impl SoundpadGui {
|
||||
ScrollArea::vertical().id_salt(0).show(ui, |ui| {
|
||||
ui.set_min_width(area_size.x);
|
||||
|
||||
let mut dirs: Vec<PathBuf> = self.app_state.dirs.iter().cloned().collect();
|
||||
dirs.sort();
|
||||
for path in dirs.iter() {
|
||||
let mut dirs = self.app_state.dirs.clone();
|
||||
|
||||
dnd(ui, "dnd_directories").show_vec(&mut dirs, |ui, item, handle, _state| {
|
||||
let path = item.clone();
|
||||
ui.horizontal(|ui| {
|
||||
handle.ui(ui, |ui| {
|
||||
ui.label(ICON_DRAG_INDICATOR);
|
||||
});
|
||||
let name = path
|
||||
.file_name()
|
||||
.map(|s| s.to_string_lossy().to_string())
|
||||
@@ -290,7 +322,7 @@ impl SoundpadGui {
|
||||
|
||||
let mut dir_button_text = RichText::new(name.clone());
|
||||
if let Some(current_dir) = &self.app_state.current_dir {
|
||||
if current_dir.eq(path) {
|
||||
if current_dir.eq(&path) {
|
||||
dir_button_text = dir_button_text.color(Color32::WHITE);
|
||||
}
|
||||
}
|
||||
@@ -300,20 +332,49 @@ impl SoundpadGui {
|
||||
|
||||
let dir_button_response = ui.add(dir_button);
|
||||
if dir_button_response.clicked() {
|
||||
self.open_dir(path);
|
||||
self.open_dir(&path);
|
||||
}
|
||||
|
||||
let delete_dir_button = Button::new(icons::ICON_DELETE).frame(false);
|
||||
let delete_dir_button = Button::new(ICON_DELETE).frame(false);
|
||||
let delete_dir_button_response =
|
||||
ui.add_sized([18.0, 18.0], delete_dir_button);
|
||||
if delete_dir_button_response.clicked() {
|
||||
self.remove_dir(&path.clone());
|
||||
self.app_state.dirs_to_remove.insert(path.clone());
|
||||
}
|
||||
|
||||
// Context menu
|
||||
dir_button_response.context_menu(|ui| {
|
||||
if ui
|
||||
.button(format!("{} {}", ICON_OPEN_IN_NEW, "Show"))
|
||||
.clicked()
|
||||
{
|
||||
self.open_dir(&path);
|
||||
}
|
||||
|
||||
if ui
|
||||
.button(format!(
|
||||
"{} {}",
|
||||
ICON_OPEN_IN_BROWSER, "Open in File Manager"
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
if let Err(e) = opener::open(&path) {
|
||||
eprintln!("Failed to open file manager: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
if ui.button(format!("{} {}", ICON_DELETE, "Remove")).clicked() {
|
||||
self.app_state.dirs_to_remove.insert(path.clone());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
self.app_state.dirs = dirs;
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let add_dirs_button = Button::new(icons::ICON_ADD).frame(false);
|
||||
let add_dirs_button = Button::new(ICON_ADD).frame(false);
|
||||
let add_dirs_button_response = ui.add_sized([18.0, 18.0], add_dirs_button);
|
||||
if add_dirs_button_response.clicked() {
|
||||
self.add_dirs();
|
||||
@@ -334,12 +395,17 @@ impl SoundpadGui {
|
||||
fn draw_files(&mut self, ui: &mut Ui, area_size: Vec2) {
|
||||
ui.vertical(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let search_field = ui.add_sized(
|
||||
let search_field_response = ui.add_sized(
|
||||
[ui.available_width(), 22.0],
|
||||
TextEdit::singleline(&mut self.app_state.search_query).hint_text("Search..."),
|
||||
);
|
||||
|
||||
self.app_state.search_field_id = Some(search_field.id);
|
||||
if self.app_state.force_focus_search {
|
||||
search_field_response.request_focus();
|
||||
self.app_state.force_focus_search = false;
|
||||
}
|
||||
|
||||
self.app_state.search_field_id = Some(search_field_response.id);
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
@@ -349,37 +415,15 @@ impl SoundpadGui {
|
||||
ui.set_min_height(area_size.y);
|
||||
|
||||
ui.vertical(|ui| {
|
||||
let mut files: Vec<PathBuf> = self.app_state.files.iter().cloned().collect();
|
||||
files.sort();
|
||||
let files = self.get_filtered_files();
|
||||
|
||||
for entry_path in files {
|
||||
if entry_path.is_dir() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !SUPPORTED_EXTENSIONS
|
||||
.contains(&entry_path.extension().unwrap_or_default().to_str().unwrap())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let file_name = entry_path
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
|
||||
let search_query = self
|
||||
.app_state
|
||||
.search_query
|
||||
.to_lowercase()
|
||||
.trim()
|
||||
.to_string();
|
||||
|
||||
if !file_name.to_lowercase().contains(search_query.as_str()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut file_button_text = RichText::new(file_name);
|
||||
if let Some(current_file) = &self.app_state.selected_file {
|
||||
if current_file.eq(&entry_path) {
|
||||
@@ -402,8 +446,48 @@ impl SoundpadGui {
|
||||
self.play_file(&entry_path, false);
|
||||
}
|
||||
});
|
||||
self.app_state.selected_file = Some(entry_path);
|
||||
self.app_state.selected_file = Some(entry_path.clone());
|
||||
}
|
||||
|
||||
// Context menu
|
||||
file_button_response.context_menu(|ui| {
|
||||
if ui
|
||||
.button(format!("{} {}", ICON_BOLT, "Play Solo"))
|
||||
.clicked()
|
||||
{
|
||||
self.play_file(&entry_path, false);
|
||||
self.app_state.selected_file = Some(entry_path.clone());
|
||||
}
|
||||
|
||||
if ui.button(format!("{} {}", ICON_ADD, "Add New")).clicked() {
|
||||
self.play_file(&entry_path, true);
|
||||
self.app_state.selected_file = Some(entry_path.clone());
|
||||
}
|
||||
|
||||
if ui
|
||||
.button(format!("{} {}", ICON_SWAP_HORIZ, "Replace Last"))
|
||||
.clicked()
|
||||
&& let Some(last_track) = self.audio_player_state.tracks.last()
|
||||
{
|
||||
self.stop(Some(last_track.id));
|
||||
self.play_file(&entry_path, true);
|
||||
self.app_state.selected_file = Some(entry_path.clone());
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
if ui
|
||||
.button(format!(
|
||||
"{} {}",
|
||||
ICON_OPEN_IN_BROWSER, "Show in File Manager"
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
if let Err(e) = opener::reveal(&entry_path) {
|
||||
eprintln!("Failed to open file manager: {}", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -472,7 +556,7 @@ impl SoundpadGui {
|
||||
|
||||
// ---------- Settings button ----------
|
||||
let settings_button =
|
||||
Button::new(icons::ICON_SETTINGS.atom_size(Vec2::new(18.0, 18.0))).frame(false);
|
||||
Button::new(ICON_SETTINGS.atom_size(Vec2::new(18.0, 18.0))).frame(false);
|
||||
let settings_button_response = ui.add_sized([18.0, 18.0], settings_button);
|
||||
if settings_button_response.clicked() {
|
||||
self.app_state.show_settings = true;
|
||||
|
||||
+85
-92
@@ -1,30 +1,47 @@
|
||||
use crate::gui::SoundpadGui;
|
||||
use egui::{Context, Key};
|
||||
use egui::{Context, Key, Modifiers};
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
impl SoundpadGui {
|
||||
fn key_pressed(&self, ctx: &Context, key: Key) -> bool {
|
||||
ctx.input(|i| i.key_pressed(key))
|
||||
}
|
||||
|
||||
fn modifiers(&self, ctx: &Context) -> Modifiers {
|
||||
ctx.input(|i| i.modifiers)
|
||||
}
|
||||
|
||||
pub fn handle_input(&mut self, ctx: &Context) {
|
||||
if ctx.memory(|reader| { reader.focused() }.is_some()) {
|
||||
return;
|
||||
let modifiers = self.modifiers(ctx);
|
||||
|
||||
// Open/close settings
|
||||
if self.key_pressed(ctx, Key::I) {
|
||||
self.app_state.show_settings = !self.app_state.show_settings;
|
||||
}
|
||||
|
||||
ctx.input(|i| {
|
||||
// Close app on espace
|
||||
if i.key_pressed(Key::Escape) {
|
||||
std::process::exit(0);
|
||||
if !self.app_state.show_settings {
|
||||
// Pause / resume audio on space
|
||||
if self.key_pressed(ctx, Key::Space) {
|
||||
self.play_toggle();
|
||||
}
|
||||
|
||||
// Open/close settings
|
||||
if i.key_pressed(Key::I) {
|
||||
self.app_state.show_settings = !self.app_state.show_settings;
|
||||
// Stop all audio tracks on backspace
|
||||
if self.key_pressed(ctx, Key::Backspace) {
|
||||
self.stop(None);
|
||||
}
|
||||
|
||||
if i.key_pressed(Key::Enter) && self.app_state.selected_file.is_some() {
|
||||
// Focus search field
|
||||
if self.key_pressed(ctx, Key::Slash) {
|
||||
self.app_state.force_focus_search = true;
|
||||
}
|
||||
|
||||
// Play selected file on Enter
|
||||
if self.key_pressed(ctx, Key::Enter) && self.app_state.selected_file.is_some() {
|
||||
let path = &self.app_state.selected_file.clone().unwrap();
|
||||
if i.modifiers.ctrl {
|
||||
if modifiers.ctrl {
|
||||
self.play_file(path, true);
|
||||
} else if i.modifiers.shift
|
||||
} else if modifiers.shift
|
||||
&& let Some(last_track) = self.audio_player_state.tracks.last()
|
||||
{
|
||||
self.stop(Some(last_track.id));
|
||||
@@ -34,89 +51,65 @@ impl SoundpadGui {
|
||||
}
|
||||
}
|
||||
|
||||
if !self.app_state.show_settings {
|
||||
// Pause / resume audio on space
|
||||
if i.key_pressed(Key::Space) {
|
||||
self.play_toggle();
|
||||
}
|
||||
// Iterate through dirs and files with Ctrl + Up/Down
|
||||
let arrow_up_pressed = self.key_pressed(ctx, Key::ArrowUp);
|
||||
let arrow_down_pressed = self.key_pressed(ctx, Key::ArrowDown);
|
||||
if modifiers.ctrl && (arrow_up_pressed || arrow_down_pressed) {
|
||||
if modifiers.shift && !self.app_state.dirs.is_empty() {
|
||||
let mut dirs: Vec<PathBuf> = self.app_state.dirs.iter().cloned().collect();
|
||||
dirs.sort();
|
||||
|
||||
// Stop all audio tracks on backspace
|
||||
if i.key_pressed(Key::Backspace) {
|
||||
self.stop(None);
|
||||
}
|
||||
|
||||
// Focus search field
|
||||
if i.key_pressed(Key::Slash) && self.app_state.search_field_id.is_some() {
|
||||
self.app_state.force_focus_id = self.app_state.search_field_id;
|
||||
}
|
||||
|
||||
// Iterate through dirs if there are some
|
||||
if i.modifiers.ctrl {
|
||||
let arrow_up_pressed = i.key_pressed(Key::ArrowUp);
|
||||
let arrow_down_pressed = i.key_pressed(Key::ArrowDown);
|
||||
|
||||
if arrow_up_pressed || arrow_down_pressed {
|
||||
if i.modifiers.shift && !self.app_state.dirs.is_empty() {
|
||||
let mut dirs: Vec<PathBuf> =
|
||||
self.app_state.dirs.iter().cloned().collect();
|
||||
dirs.sort();
|
||||
|
||||
let current_dir_index: i8;
|
||||
if let Some(current_dir) = &self.app_state.current_dir {
|
||||
if let Some(index) = dirs.iter().position(|x| x == current_dir) {
|
||||
current_dir_index = index as i8;
|
||||
} else {
|
||||
current_dir_index = -1;
|
||||
}
|
||||
} else {
|
||||
current_dir_index = -1;
|
||||
}
|
||||
|
||||
let mut new_dir_index: i8;
|
||||
|
||||
new_dir_index = current_dir_index - arrow_up_pressed as i8
|
||||
+ arrow_down_pressed as i8;
|
||||
|
||||
if new_dir_index < 0 {
|
||||
new_dir_index = (dirs.len() - 1) as i8;
|
||||
} else if new_dir_index >= dirs.len() as i8 {
|
||||
new_dir_index = 0;
|
||||
}
|
||||
|
||||
self.open_dir(&dirs[new_dir_index as usize]);
|
||||
} else if self.app_state.current_dir.is_some() {
|
||||
let mut files: Vec<PathBuf> =
|
||||
self.app_state.files.iter().cloned().collect();
|
||||
files.sort();
|
||||
|
||||
let current_files_index: i64;
|
||||
if let Some(selected_file) = &self.app_state.selected_file {
|
||||
if let Some(index) = files.iter().position(|x| x == selected_file) {
|
||||
current_files_index = index as i64;
|
||||
} else {
|
||||
current_files_index = -1;
|
||||
}
|
||||
} else {
|
||||
current_files_index = -1;
|
||||
}
|
||||
|
||||
let mut new_files_index: i64;
|
||||
|
||||
new_files_index = current_files_index - arrow_up_pressed as i64
|
||||
+ arrow_down_pressed as i64;
|
||||
|
||||
if new_files_index < 0 {
|
||||
new_files_index = (files.len() - 1) as i64;
|
||||
} else if new_files_index >= files.len() as i64 {
|
||||
new_files_index = 0;
|
||||
}
|
||||
|
||||
self.app_state.selected_file =
|
||||
Some(files[new_files_index as usize].clone());
|
||||
let current_dir_index: i8;
|
||||
if let Some(current_dir) = &self.app_state.current_dir {
|
||||
if let Some(index) = dirs.iter().position(|x| x == current_dir) {
|
||||
current_dir_index = index as i8;
|
||||
} else {
|
||||
current_dir_index = -1;
|
||||
}
|
||||
} else {
|
||||
current_dir_index = -1;
|
||||
}
|
||||
|
||||
let mut new_dir_index: i8;
|
||||
|
||||
new_dir_index =
|
||||
current_dir_index - arrow_up_pressed as i8 + arrow_down_pressed as i8;
|
||||
|
||||
if new_dir_index < 0 {
|
||||
new_dir_index = (dirs.len() - 1) as i8;
|
||||
} else if new_dir_index >= dirs.len() as i8 {
|
||||
new_dir_index = 0;
|
||||
}
|
||||
|
||||
self.open_dir(&dirs[new_dir_index as usize]);
|
||||
} else if self.app_state.current_dir.is_some() {
|
||||
let files = self.get_filtered_files();
|
||||
|
||||
if files.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let current_files_index = self
|
||||
.app_state
|
||||
.selected_file
|
||||
.as_ref()
|
||||
.and_then(|f| files.iter().position(|x| x == f))
|
||||
.map(|i| i as i64)
|
||||
.unwrap_or(-1);
|
||||
|
||||
let mut new_files_index =
|
||||
current_files_index - arrow_up_pressed as i64 + arrow_down_pressed as i64;
|
||||
|
||||
if new_files_index < 0 {
|
||||
new_files_index = (files.len() - 1) as i64;
|
||||
} else if new_files_index >= files.len() as i64 {
|
||||
new_files_index = 0;
|
||||
}
|
||||
|
||||
self.app_state.selected_file = Some(files[new_files_index as usize].clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
+56
-19
@@ -4,6 +4,7 @@ mod update;
|
||||
|
||||
use eframe::{HardwareAcceleration, NativeOptions, icon_data::from_png_bytes, run_native};
|
||||
use egui::{Context, Vec2, ViewportBuilder};
|
||||
use itertools::Itertools;
|
||||
use pwsp::{
|
||||
types::{
|
||||
audio_player::PlayerState,
|
||||
@@ -87,33 +88,28 @@ impl SoundpadGui {
|
||||
let file_dialog = FileDialog::new();
|
||||
if let Some(paths) = file_dialog.pick_folders() {
|
||||
for path in paths {
|
||||
self.app_state.dirs.insert(path);
|
||||
self.app_state.dirs.push(path);
|
||||
}
|
||||
self.app_state.dirs = self.app_state.dirs.iter().unique().cloned().collect();
|
||||
self.config.dirs = self.app_state.dirs.clone();
|
||||
self.config.save_to_file().ok();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_dir(&mut self, path: &PathBuf) {
|
||||
self.app_state.dirs.remove(path);
|
||||
if let Some(current_dir) = &self.app_state.current_dir
|
||||
&& current_dir == path
|
||||
{
|
||||
self.app_state.current_dir = None;
|
||||
self.app_state.files.clear();
|
||||
}
|
||||
self.config.dirs = self.app_state.dirs.clone();
|
||||
self.config.save_to_file().ok();
|
||||
}
|
||||
|
||||
pub fn open_dir(&mut self, path: &PathBuf) {
|
||||
self.app_state.current_dir = Some(path.clone());
|
||||
self.app_state.files = path
|
||||
.read_dir()
|
||||
.unwrap()
|
||||
.filter_map(|res| res.ok())
|
||||
.map(|entry| entry.path())
|
||||
.collect();
|
||||
match path.read_dir() {
|
||||
Ok(read_dir) => {
|
||||
self.app_state.files = read_dir
|
||||
.filter_map(|res| res.ok())
|
||||
.map(|entry| entry.path())
|
||||
.collect();
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to read directory {:?}: {}", path, e);
|
||||
self.app_state.files.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn play_file(&mut self, path: &PathBuf, concurrent: bool) {
|
||||
@@ -145,6 +141,47 @@ impl SoundpadGui {
|
||||
pub fn stop(&mut self, id: Option<u32>) {
|
||||
make_request_async(Request::stop(id));
|
||||
}
|
||||
|
||||
pub fn get_filtered_files(&self) -> Vec<PathBuf> {
|
||||
let mut files: Vec<PathBuf> = self.app_state.files.iter().cloned().collect();
|
||||
files.sort();
|
||||
|
||||
let search_query = self.app_state.search_query.to_lowercase();
|
||||
let search_query = search_query.trim();
|
||||
|
||||
files
|
||||
.into_iter()
|
||||
.filter(|entry_path| {
|
||||
if entry_path.is_dir() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !SUPPORTED_EXTENSIONS.contains(
|
||||
&entry_path
|
||||
.extension()
|
||||
.unwrap_or_default()
|
||||
.to_str()
|
||||
.unwrap_or_default(),
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !search_query.is_empty() {
|
||||
let file_name = entry_path
|
||||
.file_name()
|
||||
.unwrap_or_default()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
|
||||
if !file_name.to_lowercase().contains(search_query) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
+23
-7
@@ -9,6 +9,24 @@ use std::time::{Duration, Instant};
|
||||
|
||||
impl App for SoundpadGui {
|
||||
fn update(&mut self, ctx: &Context, _frame: &mut EFrame) {
|
||||
// Remove directories
|
||||
for path in self.app_state.dirs_to_remove.drain() {
|
||||
self.app_state.dirs.retain(|x| x != &path);
|
||||
if let Some(current_dir) = &self.app_state.current_dir
|
||||
&& current_dir == &path
|
||||
{
|
||||
self.app_state.current_dir = None;
|
||||
self.app_state.files.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Save directories if changed
|
||||
if !self.config.dirs.eq(&self.app_state.dirs) {
|
||||
self.config.dirs = self.app_state.dirs.clone();
|
||||
self.config.save_to_file().ok();
|
||||
}
|
||||
|
||||
// Seek and volume requests
|
||||
let mut seek_requests = vec![];
|
||||
let mut volume_requests = vec![];
|
||||
|
||||
@@ -57,11 +75,13 @@ impl App for SoundpadGui {
|
||||
}
|
||||
}
|
||||
|
||||
// Sync audio player state
|
||||
{
|
||||
let guard = self.audio_player_state_shared.lock().unwrap();
|
||||
self.audio_player_state = guard.clone();
|
||||
}
|
||||
|
||||
// Handle scale factor changes
|
||||
let old_scale_factor = self.config.scale_factor;
|
||||
let new_scale_factor = ctx.zoom_factor().clamp(0.5, 2.0);
|
||||
|
||||
@@ -72,8 +92,10 @@ impl App for SoundpadGui {
|
||||
self.config.save_to_file().ok();
|
||||
}
|
||||
|
||||
// Handle input
|
||||
self.handle_input(ctx);
|
||||
|
||||
// Draw UI
|
||||
CentralPanel::default().show(ctx, |ui| {
|
||||
if !self.audio_player_state.is_daemon_running {
|
||||
self.draw_waiting_for_daemon(ui);
|
||||
@@ -86,15 +108,9 @@ impl App for SoundpadGui {
|
||||
}
|
||||
|
||||
self.draw(ui).ok();
|
||||
|
||||
if let Some(force_focus_id) = self.app_state.force_focus_id {
|
||||
ui.memory_mut(|reder| {
|
||||
reder.request_focus(force_focus_id);
|
||||
});
|
||||
self.app_state.force_focus_id = None;
|
||||
}
|
||||
});
|
||||
|
||||
// Request repaint
|
||||
ctx.request_repaint_after_secs(1.0 / 60.0);
|
||||
}
|
||||
}
|
||||
|
||||
+57
-36
@@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
types::pipewire::{AudioDevice, DeviceType, Terminate},
|
||||
types::pipewire::{DeviceType, Terminate},
|
||||
utils::{
|
||||
daemon::get_daemon_config,
|
||||
pipewire::{create_link, get_all_devices, get_device},
|
||||
pipewire::{create_link, get_device},
|
||||
},
|
||||
};
|
||||
use rodio::{Decoder, OutputStream, OutputStreamBuilder, Sink, Source};
|
||||
@@ -34,6 +34,15 @@ pub struct TrackInfo {
|
||||
pub paused: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FullState {
|
||||
pub state: PlayerState,
|
||||
pub tracks: Vec<TrackInfo>,
|
||||
pub volume: f32,
|
||||
pub current_input: String,
|
||||
pub all_inputs: HashMap<String, String>,
|
||||
}
|
||||
|
||||
pub struct PlayingSound {
|
||||
pub id: u32,
|
||||
pub sink: Sink,
|
||||
@@ -49,7 +58,7 @@ pub struct AudioPlayer {
|
||||
pub next_id: u32,
|
||||
|
||||
input_link_sender: Option<pipewire::channel::Sender<Terminate>>,
|
||||
pub current_input_device: Option<AudioDevice>,
|
||||
pub input_device_name: Option<String>,
|
||||
|
||||
pub volume: f32, // Master volume
|
||||
}
|
||||
@@ -58,13 +67,6 @@ impl AudioPlayer {
|
||||
pub async fn new() -> Result<Self, Box<dyn Error>> {
|
||||
let daemon_config = get_daemon_config();
|
||||
let default_volume = daemon_config.default_volume.unwrap_or(1.0);
|
||||
let mut default_input_device: Option<AudioDevice> = None;
|
||||
if let Some(name) = daemon_config.default_input_name
|
||||
&& let Ok(device) = get_device(&name).await
|
||||
&& device.device_type == DeviceType::Input
|
||||
{
|
||||
default_input_device = Some(device);
|
||||
}
|
||||
|
||||
let stream_handle = OutputStreamBuilder::open_default_stream()?;
|
||||
|
||||
@@ -74,12 +76,12 @@ impl AudioPlayer {
|
||||
next_id: 1,
|
||||
|
||||
input_link_sender: None,
|
||||
current_input_device: default_input_device.clone(),
|
||||
input_device_name: daemon_config.default_input_name.clone(),
|
||||
|
||||
volume: default_volume,
|
||||
};
|
||||
|
||||
if default_input_device.is_some() {
|
||||
if audio_player.input_device_name.is_some() {
|
||||
audio_player.link_devices().await?;
|
||||
}
|
||||
|
||||
@@ -89,7 +91,10 @@ impl AudioPlayer {
|
||||
fn abort_link_thread(&mut self) {
|
||||
if let Some(sender) = &self.input_link_sender {
|
||||
match sender.send(Terminate {}) {
|
||||
Ok(_) => println!("Sent terminate signal to link thread"),
|
||||
Ok(_) => {
|
||||
println!("Sent terminate signal to link thread");
|
||||
self.input_link_sender = None;
|
||||
}
|
||||
Err(_) => eprintln!("Failed to send terminate signal to link thread"),
|
||||
}
|
||||
}
|
||||
@@ -98,42 +103,43 @@ impl AudioPlayer {
|
||||
async fn link_devices(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
self.abort_link_thread();
|
||||
|
||||
if self.current_input_device.is_none() {
|
||||
let input_device;
|
||||
if let Some(input_device_name) = &self.input_device_name {
|
||||
if let Ok(device) = get_device(input_device_name).await {
|
||||
input_device = device;
|
||||
} else {
|
||||
eprintln!(
|
||||
"Could not find selected input device {}, skipping device linking",
|
||||
input_device_name
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
eprintln!("No input device selected, skipping device linking");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let (input_devices, _) = get_all_devices().await?;
|
||||
|
||||
let mut pwsp_daemon_input: Option<AudioDevice> = None;
|
||||
for input_device in input_devices {
|
||||
if input_device.name == "pwsp-virtual-mic" {
|
||||
pwsp_daemon_input = Some(input_device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if pwsp_daemon_input.is_none() {
|
||||
eprintln!("Could not find pwsp-daemon input device, skipping device linking");
|
||||
let daemon_input;
|
||||
if let Ok(device) = get_device("pwsp-virtual-mic").await {
|
||||
daemon_input = device;
|
||||
} else {
|
||||
eprintln!("Could not find pwsp-virtual-mic device, skipping device linking");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let pwsp_daemon_input = pwsp_daemon_input.unwrap();
|
||||
let current_input_device = self.current_input_device.clone().unwrap();
|
||||
|
||||
let Some(output_fl) = current_input_device.output_fl.clone() else {
|
||||
let Some(output_fl) = input_device.output_fl.clone() else {
|
||||
eprintln!("Failed to get pwsp-daemon output_fl");
|
||||
return Ok(());
|
||||
};
|
||||
let Some(output_fr) = current_input_device.output_fr.clone() else {
|
||||
let Some(output_fr) = input_device.output_fr.clone() else {
|
||||
eprintln!("Failed to get pwsp-daemon output_fr");
|
||||
return Ok(());
|
||||
};
|
||||
let Some(input_fl) = pwsp_daemon_input.input_fl.clone() else {
|
||||
let Some(input_fl) = daemon_input.input_fl.clone() else {
|
||||
eprintln!("Failed to get pwsp-daemon input_fl");
|
||||
return Ok(());
|
||||
};
|
||||
let Some(input_fr) = pwsp_daemon_input.input_fr.clone() else {
|
||||
let Some(input_fr) = daemon_input.input_fr.clone() else {
|
||||
eprintln!("Failed to get pwsp-daemon input_fr");
|
||||
return Ok(());
|
||||
};
|
||||
@@ -292,8 +298,6 @@ impl AudioPlayer {
|
||||
|
||||
self.tracks.insert(id, sound);
|
||||
|
||||
self.link_devices().await?;
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
Err(err) => Err(err.into()),
|
||||
@@ -333,6 +337,23 @@ impl AudioPlayer {
|
||||
}
|
||||
|
||||
pub async fn update(&mut self) {
|
||||
if let Some(input_device_name) = &self.input_device_name {
|
||||
// Unlink devices if selected input device was removed
|
||||
if self.input_link_sender.is_some() && get_device(input_device_name).await.is_err() {
|
||||
// Selected input device was removed
|
||||
eprintln!(
|
||||
"Selected input device {} was removed, unlinking devices",
|
||||
input_device_name
|
||||
);
|
||||
self.abort_link_thread();
|
||||
}
|
||||
// Link devices if not linked
|
||||
else if self.input_link_sender.is_none() {
|
||||
self.link_devices().await.ok();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle looped sounds
|
||||
let mut restarts = vec![];
|
||||
|
||||
for (id, sound) in &self.tracks {
|
||||
@@ -363,7 +384,7 @@ impl AudioPlayer {
|
||||
return Err("Selected device is not an input device".into());
|
||||
}
|
||||
|
||||
self.current_input_device = Some(input_device);
|
||||
self.input_device_name = Some(name.to_string());
|
||||
|
||||
self.link_devices().await?;
|
||||
|
||||
|
||||
+63
-8
@@ -1,9 +1,15 @@
|
||||
use crate::{
|
||||
types::{audio_player::PlayerState, socket::Response},
|
||||
utils::{daemon::get_audio_player, pipewire::get_all_devices},
|
||||
types::{
|
||||
audio_player::{FullState, PlayerState},
|
||||
socket::Response,
|
||||
},
|
||||
utils::{
|
||||
daemon::get_audio_player,
|
||||
pipewire::{get_all_devices, get_device},
|
||||
},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use std::path::PathBuf;
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
#[async_trait]
|
||||
pub trait Executable {
|
||||
@@ -76,6 +82,10 @@ pub struct ToggleLoopCommand {
|
||||
pub id: Option<u32>,
|
||||
}
|
||||
|
||||
pub struct GetDaemonVersionCommand {}
|
||||
|
||||
pub struct GetFullStateCommand {}
|
||||
|
||||
#[async_trait]
|
||||
impl Executable for PingCommand {
|
||||
async fn execute(&self) -> Response {
|
||||
@@ -254,11 +264,15 @@ impl Executable for GetTracksCommand {
|
||||
impl Executable for GetCurrentInputCommand {
|
||||
async fn execute(&self) -> Response {
|
||||
let audio_player = get_audio_player().await.lock().await;
|
||||
if let Some(input_device) = &audio_player.current_input_device {
|
||||
Response::new(
|
||||
true,
|
||||
format!("{} - {}", input_device.name, input_device.nick),
|
||||
)
|
||||
if let Some(input_device_name) = &audio_player.input_device_name {
|
||||
if let Ok(input_device) = get_device(input_device_name).await {
|
||||
Response::new(
|
||||
true,
|
||||
format!("{} - {}", input_device.name, input_device.nick),
|
||||
)
|
||||
} else {
|
||||
Response::new(false, "Failed to get current input device")
|
||||
}
|
||||
} else {
|
||||
Response::new(false, "No input device selected")
|
||||
}
|
||||
@@ -334,3 +348,44 @@ impl Executable for ToggleLoopCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Executable for GetDaemonVersionCommand {
|
||||
async fn execute(&self) -> Response {
|
||||
Response::new(true, env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Executable for GetFullStateCommand {
|
||||
async fn execute(&self) -> Response {
|
||||
let (input_devices, _output_devices) = get_all_devices().await.unwrap();
|
||||
let mut all_inputs = HashMap::new();
|
||||
let mut current_input_nick = String::new();
|
||||
|
||||
let audio_player = get_audio_player().await.lock().await;
|
||||
for device in input_devices {
|
||||
if device.name == "pwsp-virtual-mic" {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(current_input_name) = &audio_player.input_device_name {
|
||||
if device.name == *current_input_name {
|
||||
current_input_nick = format!("{} - {}", device.name, device.nick);
|
||||
}
|
||||
}
|
||||
|
||||
all_inputs.insert(device.name, device.nick);
|
||||
}
|
||||
|
||||
let full_state = FullState {
|
||||
state: audio_player.get_state(),
|
||||
tracks: audio_player.get_tracks(),
|
||||
volume: audio_player.volume,
|
||||
current_input: current_input_nick,
|
||||
all_inputs: all_inputs,
|
||||
};
|
||||
|
||||
Response::new(true, serde_json::to_string(&full_state).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -1,8 +1,9 @@
|
||||
use crate::utils::config::get_config_path;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashSet, error::Error, fs, path::PathBuf};
|
||||
use std::{error::Error, fs, path::PathBuf};
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct DaemonConfig {
|
||||
pub default_input_name: Option<String>,
|
||||
pub default_volume: Option<f32>,
|
||||
@@ -30,28 +31,31 @@ impl DaemonConfig {
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct GuiConfig {
|
||||
pub scale_factor: f32,
|
||||
pub left_panel_width: f32,
|
||||
|
||||
pub save_volume: bool,
|
||||
pub save_input: bool,
|
||||
pub save_scale_factor: bool,
|
||||
pub pause_on_exit: bool,
|
||||
|
||||
pub dirs: HashSet<PathBuf>,
|
||||
pub dirs: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl Default for GuiConfig {
|
||||
fn default() -> Self {
|
||||
GuiConfig {
|
||||
scale_factor: 1.0,
|
||||
left_panel_width: 280.0,
|
||||
|
||||
save_volume: false,
|
||||
save_input: false,
|
||||
save_scale_factor: false,
|
||||
pause_on_exit: false,
|
||||
|
||||
dirs: HashSet::default(),
|
||||
dirs: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -28,19 +28,20 @@ pub struct AppState {
|
||||
|
||||
pub show_settings: bool,
|
||||
pub volume_dragged: bool,
|
||||
pub force_focus_search: bool,
|
||||
|
||||
pub volume_slider_value: f32,
|
||||
|
||||
pub search_field_id: Option<Id>,
|
||||
|
||||
pub ignore_volume_update_until: Option<Instant>,
|
||||
|
||||
pub current_dir: Option<PathBuf>,
|
||||
pub dirs: HashSet<PathBuf>,
|
||||
pub dirs: Vec<PathBuf>,
|
||||
pub dirs_to_remove: HashSet<PathBuf>,
|
||||
|
||||
pub selected_file: Option<PathBuf>,
|
||||
pub files: HashSet<PathBuf>,
|
||||
|
||||
pub search_field_id: Option<Id>,
|
||||
pub force_focus_id: Option<Id>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
|
||||
@@ -155,6 +155,14 @@ impl Request {
|
||||
}
|
||||
Request::new("toggle_loop", args)
|
||||
}
|
||||
|
||||
pub fn get_daemon_version() -> Self {
|
||||
Request::new("get_daemon_version", vec![])
|
||||
}
|
||||
|
||||
pub fn get_full_state() -> Self {
|
||||
Request::new("get_full_state", vec![])
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
@@ -69,6 +69,8 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
|
||||
Some(Box::new(SetLoopCommand { enabled, id }))
|
||||
}
|
||||
"toggle_loop" => Some(Box::new(ToggleLoopCommand { id })),
|
||||
"get_daemon_version" => Some(Box::new(GetDaemonVersionCommand {})),
|
||||
"get_full_state" => Some(Box::new(GetFullStateCommand {})),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
+11
-27
@@ -2,10 +2,9 @@ use crate::{
|
||||
types::{
|
||||
audio_player::AudioPlayer,
|
||||
config::DaemonConfig,
|
||||
pipewire::AudioDevice,
|
||||
socket::{Request, Response},
|
||||
},
|
||||
utils::pipewire::{create_link, get_all_devices},
|
||||
utils::pipewire::{create_link, get_device},
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use std::{error::Error, fs};
|
||||
@@ -36,37 +35,22 @@ pub fn get_daemon_config() -> DaemonConfig {
|
||||
}
|
||||
|
||||
pub async fn link_player_to_virtual_mic() -> Result<(), Box<dyn Error>> {
|
||||
let (input_devices, output_devices) = get_all_devices().await?;
|
||||
|
||||
let mut pwsp_daemon_output: Option<AudioDevice> = None;
|
||||
for output_device in output_devices {
|
||||
if output_device.name == "alsa_playback.pwsp-daemon" {
|
||||
pwsp_daemon_output = Some(output_device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if pwsp_daemon_output.is_none() {
|
||||
eprintln!("Could not find pwsp-daemon output device, skipping device linking");
|
||||
let pwsp_daemon_output;
|
||||
if let Ok(device) = get_device("pwsp-daemon").await {
|
||||
pwsp_daemon_output = device;
|
||||
} else {
|
||||
eprintln!("Could not find alsa_playback.pwsp-daemon device, skipping device linking");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut pwsp_daemon_input: Option<AudioDevice> = None;
|
||||
for input_device in input_devices {
|
||||
if input_device.name == "pwsp-virtual-mic" {
|
||||
pwsp_daemon_input = Some(input_device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if pwsp_daemon_input.is_none() {
|
||||
eprintln!("Could not find pwsp-daemon input device, skipping device linking");
|
||||
let pwsp_daemon_input;
|
||||
if let Ok(device) = get_device("pwsp-virtual-mic").await {
|
||||
pwsp_daemon_input = device;
|
||||
} else {
|
||||
eprintln!("Could not find pwsp-virtual-mic device, skipping device linking");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let pwsp_daemon_output = pwsp_daemon_output.unwrap();
|
||||
let pwsp_daemon_input = pwsp_daemon_input.unwrap();
|
||||
|
||||
let output_fl = pwsp_daemon_output
|
||||
.clone()
|
||||
.output_fl
|
||||
|
||||
+16
-72
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
types::{
|
||||
audio_player::{PlayerState, TrackInfo},
|
||||
audio_player::FullState,
|
||||
config::GuiConfig,
|
||||
gui::AudioPlayerState,
|
||||
socket::{Request, Response},
|
||||
@@ -8,7 +8,6 @@ use crate::{
|
||||
utils::daemon::{is_daemon_running, make_request},
|
||||
};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
error::Error,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
@@ -63,73 +62,13 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
||||
continue;
|
||||
}
|
||||
|
||||
let state_req = Request::get_state();
|
||||
let tracks_req = Request::get_tracks();
|
||||
let volume_req = Request::get_volume();
|
||||
let current_input_req = Request::get_input();
|
||||
let all_inputs_req = Request::get_inputs();
|
||||
let full_state_req = Request::get_full_state();
|
||||
let full_state_res = make_request(full_state_req).await.unwrap_or_default();
|
||||
|
||||
let (state_res, tracks_res, volume_res, current_input_res, all_inputs_res) = tokio::join!(
|
||||
make_request(state_req),
|
||||
make_request(tracks_req),
|
||||
make_request(volume_req),
|
||||
make_request(current_input_req),
|
||||
make_request(all_inputs_req),
|
||||
);
|
||||
if full_state_res.status {
|
||||
let full_state: FullState =
|
||||
serde_json::from_str(&full_state_res.message).unwrap_or_default();
|
||||
|
||||
let state_res = state_res.unwrap_or_default();
|
||||
let tracks_res = tracks_res.unwrap_or_default();
|
||||
let volume_res = volume_res.unwrap_or_default();
|
||||
let current_input_res = current_input_res.unwrap_or_default();
|
||||
let all_inputs_res = all_inputs_res.unwrap_or_default();
|
||||
|
||||
let state = match state_res.status {
|
||||
true => serde_json::from_str::<PlayerState>(&state_res.message).unwrap(),
|
||||
false => PlayerState::default(),
|
||||
};
|
||||
|
||||
let tracks = match tracks_res.status {
|
||||
true => {
|
||||
serde_json::from_str::<Vec<TrackInfo>>(&tracks_res.message).unwrap_or_default()
|
||||
}
|
||||
false => vec![],
|
||||
};
|
||||
|
||||
let volume = match volume_res.status {
|
||||
true => volume_res.message.parse::<f32>().unwrap(),
|
||||
false => 0.0,
|
||||
};
|
||||
|
||||
let current_input = match current_input_res.status {
|
||||
true => current_input_res
|
||||
.message
|
||||
.as_str()
|
||||
.split(" - ")
|
||||
.collect::<Vec<&str>>()
|
||||
.first()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
false => String::new(),
|
||||
};
|
||||
let all_inputs = match all_inputs_res.status {
|
||||
true => all_inputs_res
|
||||
.message
|
||||
.as_str()
|
||||
.split(';')
|
||||
.filter_map(|entry| {
|
||||
let entry = entry.trim();
|
||||
if entry.is_empty() {
|
||||
return None;
|
||||
}
|
||||
entry
|
||||
.split_once(" - ")
|
||||
.map(|(k, v)| (k.trim().to_string(), v.trim().to_string()))
|
||||
})
|
||||
.collect::<HashMap<String, String>>(),
|
||||
false => HashMap::new(),
|
||||
};
|
||||
|
||||
{
|
||||
let mut guard = audio_player_state_shared.lock().unwrap();
|
||||
|
||||
guard.state = match guard.new_state.clone() {
|
||||
@@ -137,12 +76,17 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
||||
guard.new_state = None;
|
||||
new_state
|
||||
}
|
||||
None => state,
|
||||
None => full_state.state,
|
||||
};
|
||||
guard.tracks = tracks.clone();
|
||||
guard.volume = volume;
|
||||
guard.current_input = current_input;
|
||||
guard.all_inputs = all_inputs;
|
||||
guard.tracks = full_state.tracks;
|
||||
guard.volume = full_state.volume;
|
||||
guard.current_input = full_state
|
||||
.current_input
|
||||
.split(" - ")
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.to_string();
|
||||
guard.all_inputs = full_state.all_inputs;
|
||||
guard.is_daemon_running = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,7 +210,11 @@ pub async fn get_device(device_name: &str) -> Result<AudioDevice, Box<dyn Error>
|
||||
input_devices.extend(output_devices);
|
||||
|
||||
for device in input_devices {
|
||||
if device.name == device_name {
|
||||
if device.name == device_name
|
||||
|| device.nick == device_name
|
||||
|| device.name.contains(device_name)
|
||||
|| device.nick.contains(device_name)
|
||||
{
|
||||
return Ok(device);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user