Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even more functionality #27

Merged
merged 11 commits into from
Apr 11, 2024
10 changes: 6 additions & 4 deletions ptsl/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ptsl.errors import CommandError
from ptsl.ops import Operation


PTSL_VERSION = 3


Expand Down Expand Up @@ -195,9 +196,11 @@ def _response_error_json_cleanup(self, json_in: str) -> str:
(for instance, if the server returns a symbold name or numeric string
value, as it sometimes has done in the past. (See `errata`).
"""
print(json_in)
error_dict = json.loads(json_in)
old_val = error_dict['command_error_type']

errors = json.loads(json_in)
error_dict = errors['errors'][0]
old_val = errors['errors'][0]['command_error_type']

if isinstance(old_val, str):
if old_val.isdigit():
error_dict['command_error_type'] = int(old_val)
Expand All @@ -206,7 +209,6 @@ def _response_error_json_cleanup(self, json_in: str) -> str:
pt.CommandErrorType.Value(old_val)
else:
error_dict['command_error_type'] = pt.PT_UnknownError

return json.dumps(error_dict)

def _handle_completed_response(self, operation, response):
Expand Down
110 changes: 97 additions & 13 deletions ptsl/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
PasteSpecialOptions, TrackOffsetOptions, TrackListInvertibleFilter, \
ExportFileType, ResolveDuplicateNamesBy, ExportFormat, \
MemoryLocationReference, MemoryLocationProperties, \
TimeProperties, CL_ClipLocation, SelectionMode
TimeProperties, CL_ClipLocation, \
TrackFormat, TrackType, TrackTimebase, \
AudioOperations, MediaDestination, MediaLocation, \
SpotLocationType, Start, TimeCode, \
TimelineUpdateVideo



@contextmanager
Expand Down Expand Up @@ -216,6 +221,35 @@ def import_data(self,
"""
return ImportSessionDataBuilder(self, session_path)

def import_audio(self,
file_list: List[str],
destination_path: Optional[str] = None,
audio_operations: Optional[AudioOperations] = None,
audio_destination: Optional[MediaDestination] = None,
audio_location: Optional[MediaLocation] = None,
timecode: Optional[str] = None,
location_type: Optional[SpotLocationType] = Start,
location_options: Optional[TrackOffsetOptions] = TimeCode
) -> None:
"""
Import audio data into the currently-open session.
location_data needs to be provided regardless if empty.
Just a basic implementation for audio data import TC based only.
"""
location_data = pt.SpotLocationData(location_type=location_type,
location_options=location_options,
location_value=timecode
)
audio_data = pt.AudioData(file_list=file_list,
destination_path=destination_path,
audio_operations=audio_operations,
audio_destination=audio_destination,
audio_location=audio_location,
location_data=location_data
)
op = ops.Import(import_type=1, audio_data=audio_data)
self.client.run(op)

def select_all_clips_on_track(self, track_name: str):
"""
Select all clips on track.
Expand Down Expand Up @@ -324,28 +358,36 @@ def record_half_speed(self):
self.client.run(ops.RecordHalfSpeed())

def create_memory_location(self,
location_number: int,
name: str,
start_time: str,
end_time: str,
time_properties: TimeProperties,
reference: MemoryLocationReference,
general_properties: MemoryLocationProperties,
comments: str) -> None:
start_time: Optional[str] = None,
memory_number: Optional[int] = None,
name: Optional[str] = None,
end_time: Optional[str] = None,
location: Optional[str] = None,
track_name: Optional[str] = None,
time_properties: Optional[TimeProperties] = None,
reference: Optional[MemoryLocationReference] = None,
general_properties: Optional[MemoryLocationProperties] = None,
comments: Optional[str] = None,
color_index: Optional[int] = None
) -> None:
"""
Create a new memory location.
"""
if general_properties is None:
general_properties = MemoryLocationProperties(track_visibility=False)
op = ops.CreateMemoryLocation(
number=location_number,
number=memory_number,
name=name,
start_time=start_time,
end_time=end_time,
track_name=track_name,
time_properties=time_properties,
reference=reference,
general_properties=general_properties,
comments=comments
comments=comments,
location=location,
color_index=color_index
)

self.client.run(op)

def get_edit_mode(self):
Expand Down Expand Up @@ -770,6 +812,48 @@ def set_session_video_rate_pull(self, pull_rate: 'SessionRatePull'):
op = ops.SetSessionVideoRatePullSettings(video_rate_pull=pull_rate)
self.client.run(op)

def set_timeline_selection(self,
in_time: Optional[str],
play_start_marker_time: Optional[str] = None,
out_time: Optional[str] = None,
pre_roll_start_time: Optional[str] = None,
post_roll_stop_time: Optional[str] = None,
pre_roll_enabled: Optional[TripleBool] = None,
update_video_to: Optional[TimelineUpdateVideo] = None,
propagate_to_satellites: Optional[TripleBool] = None
):
"""
Set Selection at Timecode
"""
op = ops.SetTimelineSelection(play_start_marker_time=play_start_marker_time,
in_time=in_time,
out_time=out_time,
pre_roll_start_time=pre_roll_start_time,
post_roll_stop_time=post_roll_stop_time,
pre_roll_enabled=pre_roll_enabled,
update_video_to=update_video_to,
propagate_to_satellites=propagate_to_satellites
)
self.client.run(op)

def create_new_tracks(self,
number_of_tracks: Optional[int] = None,
track_name: Optional[str] = None,
track_format: Optional[TrackFormat] = None,
track_type: Optional[TrackType] = None,
track_timebase: Optional[TrackTimebase] = None
):
"""
Create new Tracks
"""
op = ops.CreateNewTracks(number_of_tracks=number_of_tracks,
track_name=track_name,
track_format=track_format,
track_type=track_type,
track_timebase=track_timebase
)
self.client.run(op)

def cut(self, special: Optional['AutomationDataOptions'] = None):
"""
Execute an Edit > Cut.
Expand Down Expand Up @@ -823,7 +907,7 @@ def refresh_target_audio_files(self, files: List[str]):
op = ops.RefreshAllModifiedAudioFiles(file_list=files)
self.client.run(op)

def refresh_all_modified_audio_flles(self):
def refresh_all_modified_audio_files(self):
"""
Deprecated: use refresh_all_modified_audio_files() instead
"""
Expand Down
1 change: 1 addition & 0 deletions ptsl/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from .set_session_video_rate_pull_settings import \
SetSessionVideoRatePullSettings


# Pro Tools 2023.3

from .register_connection import RegisterConnection
Expand Down
4 changes: 4 additions & 0 deletions ptsl/ops/memory_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ class EditMemoryLocation(Operation):

class GetMemoryLocations(Operation):
pass


class CreateMemoryLocation(Operation):
pass
Loading