1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
from pathlib import Path
from . import SoloTool
from .storage import FileSystemStorageBackend, FileBrowserStorageBackend
class SessionManager():
def __init__(self, sessionPath: str):
self._sessionPath = sessionPath
from re import search
match = search(r"^([a-z0-9]+://)", sessionPath)
if not match or match.group(0) == "file://":
self._backend = FileSystemStorageBackend(sessionPath)
elif match.group(0) in ["http://", "https://"]:
self._backend = FileBrowserStorageBackend(sessionPath)
else:
raise ValueError(f"Unsupported session path: {sessionPath}")
def getSessions(self) -> list[str]:
return self._backend.listSessions()
def loadSession(self, id: str, player=None) -> SoloTool:
session = self._backend.readSession(id)
st = SoloTool(player=player)
for i, entry in enumerate(session):
songPath = entry["path"]
keyPoints = entry.get("key_points", [])
volume = entry.get("vol", 1.0)
st.addSong(songPath, keyPoints=keyPoints, volume=volume)
return st
def saveSession(self, soloTool: SoloTool, id: str) -> None:
session = []
for i, song in enumerate(soloTool.songs):
entry = {
"path": song,
"key_points" : soloTool._keyPoints[i],
"vol" : soloTool._volumes[i]
}
session.append(entry)
self._backend.writeSession(session, id)
def saveRecording(self, recording: Path, destination: str) -> None:
self._backend.writeRecording(recording, destination)
|