|
|
|
12-25-2012, 04:13 PM
|
#1
|
Human being with feelings
Join Date: Dec 2012
Location: Geo. area known as Italy
Posts: 59
|
Make Region from sel.item with marker name?
greets
I'm looking for a way to make Reaper create a region from a selected item and automatically give it the name of the marker that is at the beginning of the selected item, so e.g. I've got a marker at 5.1.1. (named "whatever") and a selected midi item from 5.1.1. to 8.1.1.
Is there a script that will create a region from 5.1.1.to 8.1.1. named "whatever"?
I couldn't do this with actions
|
|
|
12-29-2012, 04:38 PM
|
#2
|
Human being with feelings
Join Date: Mar 2012
Location: Kentucky, USA
Posts: 254
|
This script uses SNM functions from the beta SWS builds. It will not work with the general release build or beta builds earlier than #7. The next build could also break it. I tested using Reaper x64 v4.31 and 4.32pre8.
Please make comments/suggestions/improvements. I'd especially like feedback on the best way to deal with fast string handling.
Code:
from reaper_python import *
from sws_python import *
from contextlib import contextmanager
@contextmanager
def undoable(message):
RPR_Undo_BeginBlock2(0)
try:
yield
finally:
RPR_Undo_EndBlock2(0,message,-1)
def getMarkerName(item_start):
marker_idx = 0
marker = (RPR_EnumProjectMarkers2(0,marker_idx,0,0,0,0,0))
while ((marker[0] != 0) and (marker[4] < item_start)) :
marker_idx += 1
marker = (RPR_EnumProjectMarkers2(0,marker_idx,0,0,0,0,0))
marker_ID = marker[7]
try:
fast_Str = SNM_CreateFastString("")
SNM_GetProjectMarkerName(0, marker_ID, False, fast_Str)
marker_name = SNM_GetFastString(fast_Str)
finally:
SNM_DeleteFastString(fast_Str)
return(marker_name)
with undoable('Insert region from selected item using marker name'):
for i in range (RPR_CountSelectedMediaItems(0)):
selected_item = RPR_GetSelectedMediaItem(0, i)
item_start = RPR_GetMediaItemInfo_Value(selected_item, 'D_POSITION')
item_end = item_start + RPR_GetMediaItemInfo_Value(selected_item, 'D_LENGTH')
marker_name = getMarkerName(item_start)
track_color = RPR_GetTrackColor(RPR_GetMediaItem_Track(selected_item))
RPR_AddProjectMarker2(0, True, item_start, item_end, marker_name, 0, track_color)
RPR_UpdateTimeline()
Last edited by mwe; 12-30-2012 at 01:04 AM.
Reason: Cleaned things up a little more
|
|
|
12-30-2012, 02:35 PM
|
#3
|
Human being with feelings
Join Date: Dec 2012
Location: Geo. area known as Italy
Posts: 59
|
I've tried the script in Reaper 4.31 (rev 7). I get an error. Do I need an update?
|
|
|
12-30-2012, 03:05 PM
|
#4
|
Human being with feelings
Join Date: Mar 2012
Location: Kentucky, USA
Posts: 254
|
Quote:
Originally Posted by bergweg
I've tried the script in Reaper 4.31 (rev 7). I get an error. Do I need an update?
|
Well that's no good. By rev 7 you mean SWS v2.3.0 #7? To be truthful, I only tested against #8 and 9 but the whatsnew file lead me to believe #7 would work as well. Is there a sws_python.py file in your Reaper program directory?
|
|
|
12-30-2012, 03:36 PM
|
#5
|
Human being with feelings
Join Date: Dec 2012
Location: Geo. area known as Italy
Posts: 59
|
Quote:
Originally Posted by mwe
By rev 7 you mean SWS v2.3.0 #7?
|
Nope, I mean reaper 4.31 rev 7d61bf.
I have SWS 2.3.0 Build #4
I have Python 2.7 installed, but there is no sws_python.py in my Reaper program directory. (I can however run python scripts)
Where did you get the sws extension v2.3.0 Builds #8 and #9?
|
|
|
12-30-2012, 04:14 PM
|
#6
|
Human being with feelings
Join Date: Mar 2012
Location: Kentucky, USA
Posts: 254
|
I guess we miscommunicated a little. In order for the script to work you have to be using SWS v2.3.0 #7 or later. You can get the latest here. When you run the installer it will put the sws_python.py file in the right place.
I'm using Python 3.2 so I don't know if there will be issues with your 2.7 install. It's not going to hurt to try though.
|
|
|
Thread Tools |
|
Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 05:51 AM.
|