Skip to content

Commit

Permalink
Merge pull request #30 from iluvcapra/StephenMachete/master
Browse files Browse the repository at this point in the history
Stephen machete/master
  • Loading branch information
iluvcapra authored Apr 11, 2024
2 parents 074d117 + 985f89c commit b8c5ccb
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 48 deletions.
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
146 changes: 102 additions & 44 deletions ptsl/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
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, SelectionMode


@contextmanager
Expand Down Expand Up @@ -216,6 +220,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 @@ -323,29 +356,40 @@ 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:
def create_memory_location(
self,
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 +814,51 @@ 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,12 +912,6 @@ 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):
"""
Deprecated: use refresh_all_modified_audio_files() instead
"""
self.refresh_all_modified_audio_files()

def refresh_all_modified_audio_files(self):
"""
Refreshes all modified audio files.
Expand All @@ -852,31 +935,6 @@ def select_tracks_by_name(self, names: List[str],
op = ops.SelectTracksByName(track_names=names, selection_mode=mode)
self.client.run(op)

def set_timeline_selection(self, start: str, end: str,
playhead_time: Optional[str]):
"""
Sets temporal selection range
"""
# TODO expose remaining arguments
# string pre_roll_start_time = 4
# string post_roll_stop_time = 5
# TripleBool pre_roll_enabled = 6
# TripleBool post_roll_enabled = 7
# TimelineUpdateVideo update_video_to = 8
# TripleBool propagate_to_satellites = 9

if playhead_time is None:
playhead_time = start

self.client.run(ops.SetTimelineSelection(
play_start_marker_time=playhead_time,
in_time=start,
out_time=end,
pre_roll_start_time=start,
post_roll_stop_time=end,
update_video_to=pt.TUV_None,
))

def get_timeline_selection(self) -> pt.GetTimelineSelectionResponseBody:
"""
Returns data about the current temporal selection, including
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

0 comments on commit b8c5ccb

Please sign in to comment.