Skip to content

Commit

Permalink
More typing
Browse files Browse the repository at this point in the history
  • Loading branch information
iluvcapra committed Jun 1, 2023
1 parent a6f042c commit 51ed92f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
28 changes: 14 additions & 14 deletions pycmx/channel_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# (c) 2018 Jamie Hardt

from re import (compile, match)
from typing import Dict, Tuple
from typing import Dict, Tuple, Generator

class ChannelMap:
"""
Expand All @@ -24,62 +24,62 @@ def __init__(self, v=False, audio_channels=set()):
self.v = v

@property
def video(self):
def video(self) -> bool:
'True if video is included'
return self.v

@property
def audio(self):
def audio(self) -> bool:
'True if an audio channel is included'
return len(self._audio_channel_set) > 0

@property
def channels(self):
def channels(self) -> Generator[int, None, None]:
'A generator for each audio channel'
for c in self._audio_channel_set:
yield c

@property
def a1(self):
def a1(self) -> bool:
"""True if A1 is included"""
return self.get_audio_channel(1)

@a1.setter
def a1(self,val):
def a1(self, val: bool):
self.set_audio_channel(1,val)

@property
def a2(self):
def a2(self) -> bool:
"""True if A2 is included"""
return self.get_audio_channel(2)

@a2.setter
def a2(self,val):
def a2(self, val: bool):
self.set_audio_channel(2,val)

@property
def a3(self):
def a3(self) -> bool:
"""True if A3 is included"""
return self.get_audio_channel(3)

@a3.setter
def a3(self,val):
def a3(self, val: bool):
self.set_audio_channel(3,val)

@property
def a4(self):
def a4(self) -> bool:
"""True if A4 is included"""
return self.get_audio_channel(4)

@a4.setter
def a4(self,val):
def a4(self,val: bool):
self.set_audio_channel(4,val)

def get_audio_channel(self,chan_num):
def get_audio_channel(self, chan_num) -> bool:
"""True if chan_num is included"""
return (chan_num in self._audio_channel_set)

def set_audio_channel(self,chan_num,enabled):
def set_audio_channel(self,chan_num, enabled: bool):
"""If enabled is true, chan_num will be included"""
if enabled:
self._audio_channel_set.add(chan_num)
Expand Down
15 changes: 7 additions & 8 deletions pycmx/parse_cmx_events.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# pycmx
# (c) 2018 Jamie Hardt

from collections import namedtuple
# from collections import namedtuple

from .parse_cmx_statements import (parse_cmx3600_statements, StmtEvent,StmtFCM )
from .parse_cmx_statements import (parse_cmx3600_statements)
from .edit_list import EditList

def parse_cmx3600(f):
from typing import TextIO

def parse_cmx3600(f: TextIO):
"""
Parse a CMX 3600 EDL.
Args:
f : a file-like object, anything that's readlines-able.
Returns:
An :class:`pycmx.edit_list.EditList`.
:param TextIO f: a file-like object, anything that's readlines-able.
:returns: An :class:`pycmx.edit_list.EditList`.
"""
statements = parse_cmx3600_statements(f)
return EditList(statements)
Expand Down
10 changes: 6 additions & 4 deletions pycmx/parse_cmx_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
from collections import namedtuple
from itertools import count
from typing import TextIO, List


from .util import collimate

Expand All @@ -18,12 +20,12 @@
StmtRemark = namedtuple("Remark",["text","line_number"])
StmtEffectsName = namedtuple("EffectsName",["name","line_number"])
StmtSourceUMID = namedtuple("Source",["name","umid","line_number"])
StmtSplitEdit = namedtuple("SplitEdit",["video","magnitue", "line_number"])
StmtSplitEdit = namedtuple("SplitEdit",["video","magnitude", "line_number"])
StmtMotionMemory = namedtuple("MotionMemory",["source","fps"]) # FIXME needs more fields
StmtUnrecognized = namedtuple("Unrecognized",["content","line_number"])


def parse_cmx3600_statements(file):
def parse_cmx3600_statements(file: TextIO) -> List[object]:
"""
Return a list of every statement in the file argument.
"""
Expand Down Expand Up @@ -109,7 +111,7 @@ def _parse_extended_audio_channels(line, line_number):
else:
return StmtUnrecognized(content=line, line_number=line_number)

def _parse_remark(line, line_number):
def _parse_remark(line, line_number) -> object:
if line.startswith("FROM CLIP NAME:"):
return StmtClipName(name=line[15:].strip() , affect="from", line_number=line_number)
elif line.startswith("TO CLIP NAME:"):
Expand All @@ -119,7 +121,7 @@ def _parse_remark(line, line_number):
else:
return StmtRemark(text=line, line_number=line_number)

def _parse_effects_name(line, line_number):
def _parse_effects_name(line, line_number) -> StmtEffectsName:
name = line[16:].strip()
return StmtEffectsName(name=name, line_number=line_number)

Expand Down
24 changes: 14 additions & 10 deletions pycmx/transition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pycmx
# (c) 2018 Jamie Hardt
# (c) 2023 Jamie Hardt

from typing import Optional

class Transition:
"""
Expand All @@ -19,7 +21,7 @@ def __init__(self, transition, operand, name=None):
self.name = name

@property
def kind(self):
def kind(self) -> Optional[str]:
"""
Return the kind of transition: Cut, Wipe, etc
"""
Expand All @@ -37,50 +39,52 @@ def kind(self):
return Transition.KeyOut

@property
def cut(self):
def cut(self) -> bool:
"`True` if this transition is a cut."
return self.transition == 'C'

@property
def dissolve(self):
def dissolve(self) -> bool:
"`True` if this traansition is a dissolve."
return self.transition == 'D'

@property
def wipe(self):
def wipe(self) -> bool:
"`True` if this transition is a wipe."
return self.transition.startswith('W')

@property
def effect_duration(self):
def effect_duration(self) -> int:
"""The duration of this transition, in frames of the record target.
In the event of a key event, this is the duration of the fade in.
"""
return int(self.operand)

@property
def wipe_number(self):
def wipe_number(self) -> Optional[int]:
"Wipes are identified by a particular number."
if self.wipe:
return int(self.transition[1:])
else:
return None

@property
def key_background(self):
def key_background(self) -> bool:
"`True` if this edit is a key background."
return self.transition == Transition.KeyBackground

@property
def key_foreground(self):
def key_foreground(self) -> bool:
"`True` if this edit is a key foreground."
return self.transition == Transition.Key

@property
def key_out(self):
def key_out(self) -> bool:
"""
`True` if this edit is a key out. This material will removed from
the key foreground and replaced with the key background.
"""
return self.transition == Transition.KeyOut


0 comments on commit 51ed92f

Please sign in to comment.