mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
Rewrote parsing to handle old & new-style markers
This commit is contained in:
@@ -9,7 +9,8 @@ from .doc_entity import SessionDescriptor, HeaderDescriptor, TrackDescriptor, \
|
|||||||
protools_text_export_grammar = Grammar(
|
protools_text_export_grammar = Grammar(
|
||||||
r"""
|
r"""
|
||||||
document = header files_section? clips_section? plugin_listing?
|
document = header files_section? clips_section? plugin_listing?
|
||||||
track_listing? markers_listing?
|
track_listing? markers_block?
|
||||||
|
|
||||||
header = "SESSION NAME:" fs string_value rs
|
header = "SESSION NAME:" fs string_value rs
|
||||||
"SAMPLE RATE:" fs float_value rs
|
"SAMPLE RATE:" fs float_value rs
|
||||||
"BIT DEPTH:" fs integer_value "-bit" rs
|
"BIT DEPTH:" fs integer_value "-bit" rs
|
||||||
@@ -74,20 +75,27 @@ protools_text_export_grammar = Grammar(
|
|||||||
|
|
||||||
track_clip_state = ("Muted" / "Unmuted")
|
track_clip_state = ("Muted" / "Unmuted")
|
||||||
|
|
||||||
markers_listing = markers_listing_header markers_column_header
|
markers_block = markers_block_header (markers_list / markers_list_simple)
|
||||||
marker_record*
|
|
||||||
markers_listing_header = "M A R K E R S L I S T I N G" rs
|
markers_list_simple = markers_column_header_simple marker_record_simple*
|
||||||
markers_column_header = "# " fs "LOCATION " fs
|
|
||||||
"TIME REFERENCE " fs
|
markers_list = markers_column_header marker_record*
|
||||||
"UNITS " fs
|
|
||||||
"NAME " fs
|
markers_block_header = "M A R K E R S L I S T I N G" rs
|
||||||
("TRACK NAME " fs
|
|
||||||
"TRACK TYPE " fs)?
|
markers_column_header_simple =
|
||||||
"COMMENTS" rs
|
"# LOCATION TIME REFERENCE UNITS NAME COMMENTS" rs
|
||||||
|
|
||||||
|
markers_column_header =
|
||||||
|
"# LOCATION TIME REFERENCE UNITS NAME TRACK NAME TRACK TYPE COMMENTS" rs
|
||||||
|
|
||||||
|
marker_record_simple = integer_value isp fs string_value fs
|
||||||
|
integer_value isp fs string_value fs string_value
|
||||||
|
fs string_value rs
|
||||||
|
|
||||||
marker_record = integer_value isp fs string_value fs integer_value isp fs
|
marker_record = integer_value isp fs string_value fs integer_value isp fs
|
||||||
string_value fs string_value fs
|
string_value fs string_value fs string_value fs
|
||||||
(string_value fs string_value fs)? string_value rs
|
string_value fs string_value rs
|
||||||
|
|
||||||
fs = "\t"
|
fs = "\t"
|
||||||
rs = "\n"
|
rs = "\n"
|
||||||
@@ -234,26 +242,36 @@ class DocParserVisitor(NodeVisitor):
|
|||||||
return node.text
|
return node.text
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def visit_markers_listing(_, visited_children):
|
def visit_markers_block(_, visited_children):
|
||||||
markers = []
|
markers = []
|
||||||
|
|
||||||
for marker in visited_children[2]:
|
for marker in visited_children[1][0][1]:
|
||||||
markers.append(marker)
|
markers.append(marker)
|
||||||
|
|
||||||
return markers
|
return markers
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def visit_marker_record(_, visited_children):
|
def visit_marker_record_simple(_, visited_children):
|
||||||
is_track_marker = False
|
|
||||||
if isinstance(visited_children[12][0], list):
|
|
||||||
is_track_marker = visited_children[12][0][2] == "Track"
|
|
||||||
|
|
||||||
return MarkerDescriptor(number=visited_children[0],
|
return MarkerDescriptor(number=visited_children[0],
|
||||||
location=visited_children[3],
|
location=visited_children[3],
|
||||||
time_reference=visited_children[5],
|
time_reference=visited_children[5],
|
||||||
units=visited_children[8],
|
units=visited_children[8],
|
||||||
name=visited_children[10],
|
name=visited_children[10],
|
||||||
comments=visited_children[13],
|
comments=visited_children[12],
|
||||||
|
track_marker=False)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def visit_marker_record(_, visited_children):
|
||||||
|
track_type = visited_children[15]
|
||||||
|
is_track_marker = (track_type == "Track")
|
||||||
|
|
||||||
|
return MarkerDescriptor(number=visited_children[0],
|
||||||
|
location=visited_children[3],
|
||||||
|
time_reference=visited_children[5],
|
||||||
|
units=visited_children[8],
|
||||||
|
name=visited_children[10],
|
||||||
|
comments=visited_children[16],
|
||||||
track_marker=is_track_marker)
|
track_marker=is_track_marker)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import sys
|
|||||||
import os.path
|
import os.path
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
from ptulsconv import commands
|
from ptulsconv import commands
|
||||||
|
|
||||||
class TestPDFExport(unittest.TestCase):
|
class TestPDFExport(unittest.TestCase):
|
||||||
@@ -15,24 +14,39 @@ class TestPDFExport(unittest.TestCase):
|
|||||||
Setp through every text file in export_cases and make sure it can
|
Setp through every text file in export_cases and make sure it can
|
||||||
be converted into PDF docs without throwing an error
|
be converted into PDF docs without throwing an error
|
||||||
"""
|
"""
|
||||||
|
files = []
|
||||||
files = [os.path.dirname(__file__) + "/../export_cases/Robin Hood Spotting.txt"]
|
files = [os.path.dirname(__file__) + "/../export_cases/Robin Hood Spotting.txt"]
|
||||||
|
for path in files:
|
||||||
|
tempdir = tempfile.TemporaryDirectory()
|
||||||
|
os.chdir(tempdir.name)
|
||||||
|
try:
|
||||||
|
commands.convert(input_file=path, major_mode='doc')
|
||||||
|
except Exception as e:
|
||||||
|
print("Error in test_report_generation")
|
||||||
|
print(f"File: {path}")
|
||||||
|
print(repr(e))
|
||||||
|
raise e
|
||||||
|
finally:
|
||||||
|
tempdir.cleanup()
|
||||||
|
|
||||||
|
def test_report_generation_track_markers(self):
|
||||||
|
files = []
|
||||||
files.append(os.path.dirname(__file__) + "/../export_cases/Test for ptulsconv.txt")
|
files.append(os.path.dirname(__file__) + "/../export_cases/Test for ptulsconv.txt")
|
||||||
for path in files:
|
for path in files:
|
||||||
tempdir = tempfile.TemporaryDirectory()
|
tempdir = tempfile.TemporaryDirectory()
|
||||||
os.chdir(tempdir.name)
|
os.chdir(tempdir.name)
|
||||||
try:
|
try:
|
||||||
commands.convert(input_file=path, major_mode='doc')
|
commands.convert(input_file=path, major_mode='doc')
|
||||||
except:
|
except Exception as e:
|
||||||
print("Error in test_report_generation")
|
print("Error in test_report_generation_track_markers")
|
||||||
print(f"File: {path}")
|
print(f"File: {path}")
|
||||||
print(repr(sys.exception()))
|
print(repr(e))
|
||||||
raise sys.exception()
|
raise e
|
||||||
finally:
|
finally:
|
||||||
tempdir.cleanup()
|
tempdir.cleanup()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user