-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcreate_session_builder.py
132 lines (110 loc) · 3.99 KB
/
create_session_builder.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from ptsl.PTSL_pb2 import SAF_AIFF, SAF_WAVE, \
SR_48000, Bit16, Bit24, Bit32Float, \
IO_Last, IO_StereoMix, IO_51SMPTEMix
import ptsl
from ptsl import ops, util
class CreateSessionBuilder:
def __init__(self, engine: 'ptsl.Engine', name: str, path: str):
self._engine = engine
self._session_name = name
self._path = path
self._audio_format = SAF_WAVE
self._sample_rate = SR_48000
self._bit_depth = Bit24
self._io_settings = IO_Last
self._is_interleaved = False
def audio_format(self, value: str):
"""
:param value: Audio format for the new session. Acceptable
values are "wave" or "aiff".
"""
if value == 'wave':
self._audio_format = SAF_WAVE
elif value == 'aiff':
self._audio_format = SAF_AIFF
else:
assert False, f"Invalid audio_format value {value}"
def wave_format(self):
self.audio_format("wave")
def aiff_format(self):
self.audio_format("aiff")
def sample_rate(self, value: int):
self._sample_rate = util.sample_rate_enum(value)
def bit_depth(self, value: int):
"""
:param value: Bit depth for the new session. Acceptable
values are `16`, `24` or `32`.
"""
if value == 16:
self._bit_depth = Bit16
elif value == 24:
self._bit_depth = Bit24
elif value == 32:
self._bit_depth = Bit32Float
else:
assert False, f"Invalid bit_depth value {value}"
def stereo_io_settings(self):
self._io_settings = IO_StereoMix
def smpte51_io_settings(self):
self._io_settings = IO_51SMPTEMix
def interleaved(self, value: bool):
self._is_interleaved = value
def create(self) -> None:
import pprint
op = ops.CreateSession(
session_name=self._session_name,
file_type=self._audio_format,
sample_rate=self._sample_rate,
input_output_settings=self._io_settings,
is_interleaved=self._is_interleaved,
session_location=self._path,
bit_depth=self._bit_depth,
is_cloud_project=False,
create_from_template=False,
)
print("------")
pprint.pprint(op.request)
self._engine.client.run(op)
class CreateSessionFromTemplateBuilder(CreateSessionBuilder):
def __init__(self, engine: 'ptsl.Engine',
template_name: str,
template_group: str,
name: str,
path: str):
self._template_name = template_name
self._template_group = template_group
super().__init__(engine, name, path)
def create(self):
op = ops.CreateSession(
session_name=self._session_name,
create_from_template=True,
template_group=self._template_group,
template_name=self._template_name,
file_type=self._audio_format,
sample_rate=self._sample_rate,
input_output_settings=self._io_settings,
is_interleaved=self._is_interleaved,
session_location=self._path,
bit_depth=self._bit_depth
)
self._engine.client.run(op)
class CreateSessionFromAAFBuilder(CreateSessionBuilder):
def __init__(self, engine: 'ptsl.Engine',
aaf_path: str,
name: str,
path: str):
self._aaf_path = aaf_path
super().__init__(engine, name, path)
def create(self):
op = ops.CreateSession(
session_name=self._session_name,
file_type=self._audio_format,
sample_rate=self._sample_rate,
input_output_settings=self._io_settings,
is_interleaved=self._is_interleaved,
session_location=self._path,
bit_depth=self._bit_depth,
create_from_aaf=True,
path_to_aaf=self._aaf_path
)
self._engine.client.run(op)