forked from ReaTeam/ReaScripts
/
beaunus_clip_splicer_tools.py
92 lines (73 loc) · 2.56 KB
/
beaunus_clip_splicer_tools.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
#! /usr/local/bin/python3
# coding=utf-8
"""A utility module for beaunus_clip_splicer.
"""
TRACK_INDEX = None
def make_generic_dict(args):
"""Given a list of arguments, returns a dictionary with each
argument as a properties in the dictionary.
Args:
args: A list of arguments that will become properties in the
dictionary.
Returns:
A dictionary containing all the data in the arguments.
"""
result = dict()
for key in args:
if args[key]:
result[key] = args[key]
return result
# pylint: disable=unused-argument
def make_media_item(name=None, track=None, filename=None, length=None,
mute=False):
"""Returns a dictionary that represents a media item.
Args:
name: The name of the media item.
track: The track that the media item should appear on.
filename: The file that should be loaded into the media item.
length: The length of the media item.
mute: Whether or not to mute the media item.
Returns:
A dictionary that represents the media item.
"""
result = make_generic_dict(locals())
result['type'] = 'MEDIA ITEM'
return result
# pylint: disable=unused-argument
def make_region(name=None, track=None, path=None, components=None):
"""Returns a dictionary that represents a region.
Args:
name: The name of the region.
track: The track that all children should appear on.
path: The path that all children's files exist in.
components: The components that should be loaded into the region.
Returns:
A dictionary that represents the region.
"""
result = make_generic_dict(locals())
result['type'] = 'REGION'
if not components:
result['components'] = list()
return result
# pylint: disable=global-statement
def make_track(name, pre_track_pause_length=None):
"""Returns a new track. If a pre_track_pause_length is specified,
an empty track of that length is added to the track's component list.
Args:
name: The name of the track.
Returns:
A dictionary that represents a track.
"""
global TRACK_INDEX
if TRACK_INDEX is None:
TRACK_INDEX = 1
track_name = 'Track ' + str(TRACK_INDEX).zfill(2) + ' - ' + name
result = make_region(track_name)
TRACK_INDEX += 1
if pre_track_pause_length:
result['components'].append(
make_media_item(
'PAUSE at beginning of track',
'PAUSES',
length=pre_track_pause_length))
return result