Skip to content

Commit 95f7217

Browse files
committed
Merge pull request '1.1.0 release' (#2) from feature/release_prepare into main
Reviewed-on: http://10.10.1.170:30008/buggex/streamcontroller_soundboard/pulls/2
2 parents 1aff968 + 6ca614a commit 95f7217

File tree

18 files changed

+257
-226
lines changed

18 files changed

+257
-226
lines changed

LICENSE

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,8 @@ MIT License
22

33
Copyright (c) 2025 Buggex
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
116

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
9+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

__install__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from os.path import join, abspath, dirname
33

44
toplevel = dirname(abspath(__file__))
5-
create_venv(join(toplevel, ".venv"), join(toplevel, "assets", "requirements.txt"))
5+
create_venv(join(toplevel, "backend", ".venv"), join(toplevel, "backend", "requirements.txt"))
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from src.backend.PluginManager.InputBases import ActionCore
55

66
# Helpers
7-
from com_buggex_sc_soundboard.helpers import Consts
7+
from com_buggex_soundboard.helpers import Consts
88

99
# Import gtk modules - used for the config rows
1010
import gi
@@ -33,7 +33,8 @@ def get_config_rows(self) -> list:
3333
self.load_config_values()
3434

3535
self.ui_sound_path = PathRow(self)
36-
self.ui_sound_path.label.set_label(self.sound_path)
36+
if self.sound_path:
37+
self.ui_sound_path.label.set_label(self.sound_path)
3738

3839
self.ui_volume = Adw.SpinRow.new_with_range(min=0, max=100, step=1)
3940
self.ui_volume.set_title(self.plugin_base.lm.get("actions.play.volume.title"))

assets/Attribution.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

assets/Thumbnail.png

210 KB
Loading

assets/Thumbnail.xcf

663 KB
Binary file not shown.

attribution.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
{
22
"generic": {
3-
"copyright": "",
4-
"original-url": "",
5-
"license": "",
6-
"license-url": "",
3+
"copyright": "BuggeX",
4+
"original-url": "https://github.com/buggex/StreamController-SoundboardPlugin",
5+
"license": "MIT",
6+
"license-url": "https://opensource.org/licenses/MIT",
77
"description": ""
8+
},
9+
"assets/stop.png": {
10+
"copyright": "Google",
11+
"original-url": "https://github.com/google/material-design-icons",
12+
"license": "Apache-2.0",
13+
"license-url": "https://www.apache.org/licenses/LICENSE-2.0.html",
14+
"description": ""
15+
},
16+
"assets/Thumbnail.png": {
17+
"copyright": "Google",
18+
"original-url": "https://github.com/google/material-design-icons",
19+
"license": "Apache-2.0",
20+
"license-url": "https://www.apache.org/licenses/LICENSE-2.0.html",
21+
"description": "Thumbnail partial made with google fonts."
822
}
923
}

backend/backend.py

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,61 @@
11
from streamcontroller_plugin_tools import BackendBase
22

3-
import vlc
4-
import time
3+
from player_interface import PlayerInterface
4+
from player_pygame import PlayerPygame
5+
from player_vlc import PlayerVLC
56

67
from loguru import logger as log
78

8-
PLAY_WAIT_TIME_SECONDS = 0.05
9-
MAX_PLAY_WAIT_TRIES = int(1 / PLAY_WAIT_TIME_SECONDS)
9+
import pygame
10+
import pygame._sdl2.audio as sdl2_audio
11+
12+
# To get access to plugin files
13+
import sys
14+
from pathlib import Path
15+
ABSOLUTE_PLUGIN_PATH = str(Path(__file__).parent.parent.absolute())
16+
sys.path.insert(0, ABSOLUTE_PLUGIN_PATH)
17+
18+
from helpers import Consts
19+
from helpers.Consts import Players
1020

1121
class SoundboardBackend(BackendBase):
12-
def __init__(self, *args, **kwargs):
13-
super().__init__(*args, **kwargs)
22+
player : PlayerInterface
23+
24+
def __init__(self):
25+
super().__init__()
1426
self.device = ""
15-
self.instance = vlc.Instance()
1627
self.player = None
1728

29+
def set_player(self, playerType):
30+
player = Consts.PLAYER_NAMES[playerType]
31+
log.debug(f"new player: {playerType}")
32+
match player:
33+
case Players.Pygame:
34+
self.player = PlayerPygame()
35+
case Players.libVLC:
36+
self.player = PlayerVLC()
37+
case _:
38+
log.error(f"Unknown playerType {playerType} {player}")
39+
40+
if self.player is not None:
41+
self.player.set_device(self.device)
42+
1843
def set_device(self, device):
1944
self.device = device
45+
if self.player is not None:
46+
self.player.set_device(device)
2047

21-
def play_sound(self, path_to_sound, volume=100):
22-
# Stop old
23-
self.stop_sound()
24-
25-
# Start new
26-
media = self.instance.media_new("file://" + path_to_sound)
27-
self.player = media.player_new_from_media()
28-
self.player.audio_output_device_set(None, self.find_device(self.player, self.device))
29-
r = self.player.play()
30-
if r == 0:
31-
# We need for playback to begin before we can set volume
32-
# TODO: Need to find a better solution
33-
tries = 0
34-
while self.player.is_playing() is 0 and tries < MAX_PLAY_WAIT_TRIES:
35-
time.sleep(PLAY_WAIT_TIME_SECONDS)
36-
tries += 1
37-
self.player.audio_set_volume(int(volume))
38-
else:
39-
log.error(f"Failed to play. File: {path_to_sound}")
48+
def play_sound(self, path_to_sound, volume):
49+
if self.player is not None:
50+
self.player.play_sound(path_to_sound, volume)
4051

4152
def stop_sound(self):
42-
if self.player:
43-
self.player.release()
44-
45-
def find_device(self, player, device_name):
46-
devices = player.audio_output_device_enum()
47-
if devices:
48-
device = devices
49-
while device:
50-
device = device.contents
51-
if device_name in str(device.description):
52-
return device.device
53-
device = device.next
54-
return None
55-
56-
backend = SoundboardBackend()
53+
if self.player is not None:
54+
self.player.stop_sound()
55+
56+
def get_audio_devices(self):
57+
if not pygame.mixer.get_init():
58+
pygame.mixer.init()
59+
return sdl2_audio.get_audio_device_names(False)
60+
61+
backend = SoundboardBackend()

backend/player_interface.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from abc import ABC, abstractmethod
2+
3+
# creating interface
4+
class PlayerInterface(ABC):
5+
6+
@abstractmethod
7+
def set_device(self, device):
8+
pass
9+
10+
@abstractmethod
11+
def play_sound(self, path_to_sound, volume):
12+
pass
13+
14+
@abstractmethod
15+
def stop_sound(self):
16+
pass

0 commit comments

Comments
 (0)