-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPyReaper.py
360 lines (250 loc) · 7.67 KB
/
PyReaper.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#RPR_APITest()
#PyReaper v0.00002
#by Brent Elliott
#ReaperProject
##get_all_tracks
##get_all_media_items
##get_all_takes
#ReaperTrack
##get_all_children
##get_all_media_items
#ReaperFX
##ReaperMediaItem
##ReaperTake
####get_tracks(selected=True)
####gradient(listOfItemsOrTracks, colorA, colorB)
from math import log
def msg(m):
RPR_ShowConsoleMsg(m)
RPR_ShowConsoleMsg('\n')
#i hate this
def time_to_beats(f):
beat_tuple = RPR_TimeMap2_timeToBeats(0, f, 0, 0, 0, 0)
bars = int(beat_tuple[3]+1)
beats = int(beat_tuple[0]+1)
decimal = int(round(beat_tuple[0]-(beats-1), 2)*100)
return (bars, beats, decimal)
class ReaperProject(object):
def __init__(self, project_number=0):
#set project 0 as default
#globalize this
self.project_number = project_number
class ReaperMediaItem(object):
def __init__(self, id):
self.id = id
def get_all_takes(self):
takes = []
num_takes = RPR_GetMediaItemNumTakes(self.id)
for take in range(num_takes):
takes.append(RPR_GetMediaItemTake(self.id, take))
return takes
#mute
@property
def mute(self):
if RPR_GetMediaItemInfo_Value(self.id, 'B_MUTE') == 0.0:
return False
else:
return True
@mute.setter
def mute(self, b):
if b:
RPR_SetMediaItemInfo_Value(self.id, 'B_MUTE', 1.0)
else:
RPR_SetMediaItemInfo_Value(self.id, 'B_MUTE', 0.0)
@property
def length(self):
return RPR_GetMediaItemInfo_Value(self.id, 'D_LENGTH')
@length.setter
def length(self, l):
pass
@property
def position(self):
return RPR_GetMediaItemInfo_Value(self.id, 'D_POSITION')
@position.setter
def position(self, l):
RPR_GetMediaItemInfo_Value(self.id, 'D_POSITION', l)
@property
def length(self):
return RPR_GetMediaItemInfo_Value(self.id, 'D_LENGTH')
@length.setter
def length(self, l):
RPR_GetMediaItemInfo_Value(self.id, 'D_LENGTH', l)
class ReaperFX(object):
def __init__(self):
class ReaperTrack(object):
def __init__(self, id):
self.id = id
#self.media_items = []
def get_all_media_items(self):
media_items = []
num_items = RPR_GetTrackNumMediaItems(self.id)
for item in range(num_items):
media_items.append(ReaperMediaItem(RPR_GetTrackMediaItem(self.id, item)))
return media_items
@property
def number(self):
return int(RPR_GetMediaTrackInfo_Value(self.id, 'IP_TRACKNUMBER'))
#volume getter and setter
@property
def volume(self):
return RPR_GetMediaTrackInfo_Value(self.id, 'D_VOL')
@volume.setter
def volume(self, value):
RPR_SetMediaTrackInfo_Value(self.id, 'D_VOL', value)
#db getter and setter
@property
def db(self):
volume = RPR_GetMediaTrackInfo_Value(self.id, 'D_VOL')
return (20 * log(volume)) / log(10)
@db.setter
def db(self, value):
volume = 10 ** (float(value) / 20)
RPR_SetMediaTrackInfo_Value(self.id, 'D_VOL', volume)
#pan getter and setter
@property
def pan(self):
return RPR_GetMediaTrackInfo_Value(self.id, 'D_PAN')
@pan.setter
def pan(self, value):
RPR_SetMediaTrackInfo_Value(self.id, 'D_PAN', value)
#mute
@property
def mute(self):
if RPR_GetMediaTrackInfo_Value(self.id, 'B_MUTE') == 0.0:
return False
else:
return True
@mute.setter
def mute(self, b):
if b:
RPR_SetMediaTrackInfo_Value(self.id, 'B_MUTE', 1.0)
else:
RPR_SetMediaTrackInfo_Value(self.id, 'B_MUTE', 0.0)
#solo property
@property
def solo(self):
#replace with GetMediaTrackInfo_Value
flag = RPR_GetTrackState(self.id, 0)[2]
if flag & 16:
return True
else:
return False
@solo.setter
def solo(self, value):
#solo_type
#0 = off
#1 = solo
#2 = solo in place
RPR_SetMediaTrackInfo_Value(self.id, 'I_SOLO', value)
#phase_invert
@property
def phase_invert(self):
if RPR_GetMediaTrackInfo_Value(self.id, 'B_PHASE') == 0.0:
return False
else:
return True
@phase_invert.setter
def phase_invert(self, value):
if value:
RPR_SetMediaTrackInfo_Value(self.id, 'B_PHASE', 1.0)
else:
RPR_SetMediaTrackInfo_Value(self.id, 'B_PHASE', 0.0)
@property
def record_monitor(self):
return int(RPR_GetMediaTrackInfo_Value(self.id, 'I_RECMON'))
@record_monitor.setter
def record_monitor(self, value):
RPR_SetMediaTrackInfo_Value(self.id, 'I_RECMON', value)
@property
def fx_enabled(self):
if RPR_GetMediaTrackInfo_Value(self.id, 'I_FXEN') == 0.0:
return False
else:
return True
@fx_enabled.setter
def fx_enabled(self, value):
if value:
RPR_SetMediaTrackInfo_Value(self.id, 'I_FXEN', 1.0)
else:
RPR_SetMediaTrackInfo_Value(self.id, 'I_FXEN', 0.0)
@property
def record_arm(self):
if RPR_GetMediaTrackInfo_Value(self.id, 'I_RECARM') == 0.0:
return False
else:
return True
@record_arm.setter
def record_arm(self, value):
if value:
RPR_SetMediaTrackInfo_Value(self.id, 'I_RECARM', 1.0)
else:
RPR_SetMediaTrackInfo_Value(self.id, 'I_RECARM', 0.0)
#name getter and setter
@property
def name(self):
return RPR_GetSetMediaTrackInfo_String(self.id, "P_NAME", '', False)[3]
@name.setter
def name(self, value):
#holy shit GetSetTrackState is a disaster
RPR_GetSetMediaTrackInfo_String(self.id, "P_NAME", value, True)
#color getter and setter
@property
def color(self):
return RPR_GetTrackColor(self.id)
@color.setter
def color(self, value):
if type(value) is str:
if value.startswith('#'):
RPR_SetTrackColor(self.id, int(value.strip('#'), 16))
elif type(value) is tuple:
h = '%02x%02x%02x' % value
RPR_SetTrackColor(self.id, int(h, 16))
else:
raise TypeError
#selection
@property
def selected(self):
flag = RPR_GetTrackState(self.id, 0)[2]
if flag & 2:
return True
else:
return False
@selected.setter
def selected(self, value):
if value:
RPR_SetTrackSelected(self.id, 1)
else:
RPR_SetTrackSelected(self.id, 0)
def get_all_tracks():
tracks = []
for i in range(RPR_CountTracks(0)):
tracks.append(ReaperTrack(RPR_GetTrack(0, i)))
return tracks
def get_selected_tracks():
tracks = []
for i in range(RPR_CountSelectedTracks(0)):
tracks.append(ReaperTrack(RPR_GetSelectedTrack(0, i)))
return tracks
for track in get_all_tracks():
#track.phase_invert = True
#track.record_monitor = 2
#track.fx_enabled = True
#track.record_arm = True
#track.db = track.db -0.5
#track.color = '#000000'
media_items = track.get_all_media_items()
if media_items:
for item in media_items:
for take in item.get_all_takes():
msg(take)
#track.color = (100,100,100)
#track.db = 0
#track.pan = -0.1
#msg(track.phase_reverse)
#msg(track.phase_reverse)
#if track.name.startswith('dick'):
# msg(track.volume)
#track.solo = 0
#track.get_media_items()
#for each in track.media_items:
# msg(time_to_beats(each.position))