Skip to content

Commit 1fc58d6

Browse files
committed
Some fixes, recording toggle
1 parent 328dde2 commit 1fc58d6

File tree

5 files changed

+73
-17
lines changed

5 files changed

+73
-17
lines changed

src/sleuthdeck/actions.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,28 @@ def __call__(self, scene: KeyScene, key: Key, click: ClickType):
145145

146146

147147
class SendHotkey(Action):
148-
def __init__(self, title: Union[str, By], *hotkey: str):
148+
def __init__(self, title: Union[str, By] | None, *hotkey: str):
149149
self.title = title
150150
self.hotkey = hotkey
151151

152152
def __call__(self, scene: KeyScene, key: Key, click: ClickType):
153153
print("sending key")
154+
154155
focused_window = get_focused_window()
156+
if self.title:
157+
158+
window = get_window(self.title, attempts=5 * 10)
159+
if not window:
160+
print(f"No window found for {self.title}")
161+
return
162+
print(f"got window {self.title}")
163+
window.focus()
155164

156-
window = get_window(self.title, attempts=5 * 10)
157-
if not window:
158-
print(f"No window found for {self.title}")
159-
return
160-
print(f"got window {self.title}")
161-
window.focus()
162165
from pyautogui import hotkey
163166
hotkey(*self.hotkey)
164167
print("sent")
165-
focused_window.focus()
168+
if self.title:
169+
focused_window.focus()
166170

167171

168172
class DeckBrightness(Action):

src/sleuthdeck/cli.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from multiprocessing import Queue
1111
from types import ModuleType
1212

13+
from StreamDeck.Transport.Transport import TransportError
14+
1315
from sleuthdeck.deck import Deck
1416
from watchdog.events import FileSystemEventHandler
1517

@@ -57,7 +59,7 @@ def run(self):
5759
self.deck.close()
5860
try:
5961
deck = Deck()
60-
except RuntimeError as e:
62+
except (RuntimeError, TransportError):
6163
print("No streamdeck found, waiting 5s")
6264
time.sleep(5)
6365
self.deck = None
@@ -70,6 +72,7 @@ def run(self):
7072
except Exception as e:
7173
print(f"Error: {e}")
7274
traceback.print_exc()
75+
self.deck = None
7376
continue
7477
while self.deck.stream_deck.is_open() and self._reloading_queue.empty():
7578
time.sleep(1)

src/sleuthdeck/plugins/obs/actions.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,30 @@ def set_scene_item_enabled(self, scene: str, name: str, enabled: bool = True):
127127
"sceneItemEnabled": enabled,
128128
})
129129

130-
def stop_recording(self):
131-
return ObsAction(self, lambda obs: obs.call("StopRecord"))
130+
def stop_recording(self, vertical=False):
131+
def execute(obs):
132+
obs.call("StopRecord")
133+
if vertical:
134+
obs.call("CallVendorRequest", {"vendorName": "aitum-vertical-canvas", "requestType": "stop_recording"})
132135

133-
def start_recording(self):
134-
return ObsAction(self, lambda obs: obs.call("StartRecord"))
136+
return ObsAction(self, execute)
137+
138+
139+
def start_recording(self, vertical=False):
140+
def execute(obs):
141+
obs.call("StartRecord")
142+
if vertical:
143+
obs.call("CallVendorRequest", {"vendorName": "aitum-vertical-canvas", "requestType": "start_recording"})
144+
return ObsAction(self, execute)
135145

136146
def set_item_property(self, name: str, property: str, value: Any):
137147
self.call("SetInputSettings", {"inputName": name,
138148
"inputSettings": {property: value},
139149
"overlay": True})
140150

151+
def create_record_chapter(self, name: str):
152+
self.call("CreateRecordChapter", {"chapterName": name})
153+
141154
def get_filter_settings(self, source_name: str, filter_name: str):
142155
return self.call("GetSourceFilter", {"sourceName": source_name,
143156
"filterName": filter_name})

src/sleuthdeck/plugins/presentation/actions.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, obs: OBS, path: str, title_scene_item="Section title",
4646
self.guest2_name_item = guest2_name_item
4747
self.guest2_title_item = guest2_title_item
4848

49+
self.current_section_idx = 0
4950
try:
5051
self._reload()
5152
except ConnectionError:
@@ -54,11 +55,11 @@ def __init__(self, obs: OBS, path: str, title_scene_item="Section title",
5455
if not self.event.sections:
5556
return
5657

57-
self.current_section_idx = 0
5858
self.title_scene_item = title_scene_item
5959
self.byline_scene_item = byline_scene_item
6060
self.title_scene = title_scene
6161
self.overlay_scene = overlay_scene
62+
self._recording = False
6263

6364
def _reload(self):
6465
with open(self.path, "r") as stream:
@@ -95,6 +96,7 @@ def action(scene: KeyScene, key: Key, click: ClickType):
9596
section = self._next_section()
9697

9798
self._update_labels(section, next_scene=section.scene)
99+
self.obs.create_record_chapter(section.title)
98100

99101
return action
100102

@@ -104,13 +106,26 @@ def action(scene: KeyScene, key: Key, click: ClickType):
104106
self._reload()
105107
self.current_section_idx = 0
106108
self._update_labels(self.event.sections[0])
109+
self.obs.create_record_chapter(self.event.sections[self.current_section_idx].title)
110+
111+
return action
112+
113+
def toggle_record(self) -> Action:
114+
def action(scene: KeyScene, key: Key, click: ClickType):
115+
if self._recording:
116+
self.obs.stop_recording(vertical=True)
117+
self._recording = False
118+
else:
119+
self.obs.start_recording(vertical=True)
120+
self._recording = True
107121

108122
return action
109123

110124
def previous_section(self) -> Action:
111125
def action(scene: KeyScene, key: Key, click: ClickType):
112126
section = self._previous_section()
113127
self._update_labels(section, next_scene=section.scene)
128+
self.obs.create_record_chapter(section.title)
114129

115130
return action
116131

src/work.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def run(deck: Deck):
8888
]
8989
),
9090
)
91+
scene1.add(
92+
(0, 2),
93+
OBSKey(text="Standing", actions=[obs.change_scene("Camera only (standing)")]),
94+
)
9195

9296
scene1.add(
9397
(0, 3),
@@ -143,7 +147,11 @@ def run(deck: Deck):
143147
scene1.add(
144148
(2, 0),
145149
FontAwesomeKey(name="regular/file-audio", tint="green", actions=[
146-
SendHotkey(By.window_class("spotify.Spotify"), "space"),
150+
#SendHotkey(By.window_class("spotify.Spotify"), "space"),
151+
SendHotkey(None, "ctrl", "shift", "alt", "m"),
152+
Wait(2),
153+
SendHotkey(None, "space"),
154+
SendHotkey(None, "ctrl", "shift", "alt", "m"),
147155
]),
148156
)
149157

@@ -166,6 +174,16 @@ def run(deck: Deck):
166174
)]
167175
),
168176
)
177+
scene1.add(
178+
(2, 3),
179+
FontAwesomeKey(
180+
"regular/window-restore",
181+
text="",
182+
actions=[
183+
Command("/home/mrdon/dev/dev-machine/windows.py", "-restore")
184+
]
185+
),
186+
)
169187

170188
sleep_toggle = Toggle(
171189
on_enable=DeckBrightness(5),
@@ -415,10 +433,13 @@ def _build_webinar_scene_base(obs, parent_scene, presso, webinar_scene):
415433

416434
])])
417435
)
436+
418437
webinar_scene.add(
419438
(1, 4),
420-
FontAwesomeKey("solid/camera", text="T Cam", actions=[obs.toggle_source("[Scene] Me corner (shadowed)"),
421-
]),
439+
FontAwesomeKey("solid/camera", text="Record", actions=[Toggle(
440+
on_enable=obs.start_recording(vertical=True),
441+
on_disable=obs.stop_recording(vertical=True),
442+
)]),
422443
)
423444
webinar_scene.add(
424445
(2, 1),

0 commit comments

Comments
 (0)