Old 12-25-2012, 04:13 PM   #1
bergweg
Human being with feelings
 
bergweg's Avatar
 
Join Date: Dec 2012
Location: Geo. area known as Italy
Posts: 59
Default 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
bergweg is offline   Reply With Quote
Old 12-29-2012, 04:38 PM   #2
mwe
Human being with feelings
 
mwe's Avatar
 
Join Date: Mar 2012
Location: Kentucky, USA
Posts: 254
Default

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
mwe is offline   Reply With Quote
Old 12-30-2012, 02:35 PM   #3
bergweg
Human being with feelings
 
bergweg's Avatar
 
Join Date: Dec 2012
Location: Geo. area known as Italy
Posts: 59
Default

I've tried the script in Reaper 4.31 (rev 7). I get an error. Do I need an update?
Attached Images
File Type: jpg marker to region with marker name - sws python error.jpg (53.0 KB, 354 views)
bergweg is offline   Reply With Quote
Old 12-30-2012, 03:05 PM   #4
mwe
Human being with feelings
 
mwe's Avatar
 
Join Date: Mar 2012
Location: Kentucky, USA
Posts: 254
Default

Quote:
Originally Posted by bergweg View Post
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?
mwe is offline   Reply With Quote
Old 12-30-2012, 03:36 PM   #5
bergweg
Human being with feelings
 
bergweg's Avatar
 
Join Date: Dec 2012
Location: Geo. area known as Italy
Posts: 59
Default

Quote:
Originally Posted by mwe View Post
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?
bergweg is offline   Reply With Quote
Old 12-30-2012, 04:14 PM   #6
mwe
Human being with feelings
 
mwe's Avatar
 
Join Date: Mar 2012
Location: Kentucky, USA
Posts: 254
Default

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.
mwe is offline   Reply With Quote
Old 12-30-2012, 06:02 PM   #7
bergweg
Human being with feelings
 
bergweg's Avatar
 
Join Date: Dec 2012
Location: Geo. area known as Italy
Posts: 59
Default

it works with SWS #9 Build, even though the sws_python file was not added to the Reaper directory. Very handy script!

thanks again
bergweg is offline   Reply With Quote
Old 12-30-2012, 07:19 PM   #8
mwe
Human being with feelings
 
mwe's Avatar
 
Join Date: Mar 2012
Location: Kentucky, USA
Posts: 254
Default

Quote:
Originally Posted by bergweg View Post
even though the sws_python file was not added to the Reaper directory
It should be in the program directory (where the reaper executable is). No matter though as long as it's working.
mwe is offline   Reply With Quote
Old 08-21-2018, 06:06 AM   #9
Xaos
Human being with feelings
 
Join Date: Sep 2015
Posts: 158
Default

Had this been implemented in any new releases off SWS or REAPER since v 4? I still can't find a way to do this. Working with limited internet access at the moment, so can't try this script without jumping through a lot of hope, and I'm sure it's probably been broken by Python/REAPER updates since the OP.

Thanks!
__________________
The richest life is the simple one. I just want to make things sing.
Xaos is offline   Reply With Quote
Old 08-21-2018, 08:42 AM   #10
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Find this script (I dont remember where it come from):


Script: beaunus_Name item takes by last marker to cut item.lua

It doesn't need python.
X-Raym is offline   Reply With Quote
Old 08-29-2018, 04:57 AM   #11
Xaos
Human being with feelings
 
Join Date: Sep 2015
Posts: 158
Default

Thanks! That's beautiful!

Unfortunately, I get this error when I run it"

beaunus_Name item takes by last marker to cut item.lua:7: unexpected symbol near '<'

I'm pretty sure it's because the idiot who named the files put the pipe character ( | ) in the filenames. Drives me nuts when people do that. I guess I could just find the right part of the script and wrap the filenames in quotes. I'm a little rusty, but I'm sure I can figure that out. Now that OSes let people use characters like that in filenames, I just kind of assume that script writers are going to quote out the input and output strings to accommodate this kind of goofiness. I just instinctively avoid characters that are used as functions in scripting when naming files.

It would seem to me that that character shouldn't throw the script off any more than a space in the filename would, though. So, maybe that's not the problem after all.
__________________
The richest life is the simple one. I just want to make things sing.
Xaos is offline   Reply With Quote
Old 08-29-2018, 06:25 AM   #12
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

@Xaos
Maybe this would work:
https://forum.cockos.com/showthread....71#post2019071
spk77 is offline   Reply With Quote
Old 08-29-2018, 07:06 AM   #13
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Quote:
I'm pretty sure it's because the idiot who named the files put the pipe character ( | ) in the filenames

Quote:
beaunus_Name item takes by last marker to cut item.lua

Where do you see a pipe characters ?


The problem is that you didn't downloaded the RAW file. You probably didn't use Reapack or didn't click on the RAW button on GitHub...
X-Raym is offline   Reply With Quote
Old 08-29-2018, 07:55 AM   #14
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Pretty much any time Lua gives you an error about seeing an unexpected < or >, it's because you downloaded the file as HTML.

Note that some browsers (Safari) make it really, really difficult to download the file properly.

If you have ReaPack, that one's on the default repo and will install properly that way.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 08-29-2018, 06:47 PM   #15
Xaos
Human being with feelings
 
Join Date: Sep 2015
Posts: 158
Default

Yup. I opened 'er up and it was an html file. I used Opera, which looks like it's built on the Chrome engine from what I can tell from a process sample. IDK. This is all out of my wheelhouse.

I grabbed ReaPack. I can't believe I didn't know about this before! Thank you so much.

I'm not sure that script is going to do exactly what I want, but I'm sure I'll find something in that massive amount of resources. What a contribution to the community. I wish I could send him a hundred bucks at least, but it'll have to wait until after I get my studio built. Been out of work for 7 years with spinal tumors. Can't even send the guy a buck just yet, but will send him many as soon as I can!

Cockos, too, who donated a license to the charity I'm doing this for. Cockos not only make the best DAW, they have big hearts, too, and are helping to make a big impact on the ives of some disabled people who have ended up homeless because of Social Security's thievery.

Big thanks to you for pointing me to ReaPack, big thanks to the ReaPack devs, and huge thanks to Cockos and the whole REAPER community!
__________________
The richest life is the simple one. I just want to make things sing.
Xaos is offline   Reply With Quote
Old 08-29-2018, 06:55 PM   #16
Xaos
Human being with feelings
 
Join Date: Sep 2015
Posts: 158
Default

Quote:
Originally Posted by X-Raym View Post
Where do you see a pipe characters ?

Pipe characters where in the original file names of the media items.


The problem is that you didn't downloaded the RAW file. You probably didn't use Reapack or didn't click on the RAW button on GitHub...
Yes, you are correct. I just discovered ReaPack. I use REAPER primarily for voice over, so I run it pretty lean, but I'm ramping up my game to be supporting 3 other voice actors, too, so I've gotta get my workflow tightened up. I'm still a real REAPER newbie.

Thanks for your help.
__________________
The richest life is the simple one. I just want to make things sing.
Xaos is offline   Reply With Quote
Old 08-30-2018, 06:34 AM   #17
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

@Xaos
Do you want to (re)name takes or regions? beaunus_Name item takes by last marker to cut item doesn't set region names, it (re)names takes by marker name. (The original poster wanted to name regions and that's also what mwe's python script does.)

Here's a link to a script that I made for YouOdysseyLeif: https://stash.reaper.fm/34042/spk77_...%20markers.zip
...and this is how it works:
Quote:
Originally Posted by spk77 View Post
spk77_Create regions from audio in between markers.lua
spk77 is offline   Reply With Quote
Old 06-19-2019, 05:18 AM   #18
djabthrash
Human being with feelings
 
Join Date: Dec 2018
Location: Paris (France)
Posts: 155
Default

Quote:
Originally Posted by spk77 View Post
@Xaos
Do you want to (re)name takes or regions? beaunus_Name item takes by last marker to cut item doesn't set region names, it (re)names takes by marker name. (The original poster wanted to name regions and that's also what mwe's python script does.)

Here's a link to a script that I made for YouOdysseyLeif: https://stash.reaper.fm/34042/spk77_...%20markers.zip
...and this is how it works:
@spk77 : In my case my markers are right at the beginning of each item (instead of before), and when i run your script it results in naming the regions after the name of the marker that is at the beginning of the previous item instead of the marker that is at the beginning of the selected item.

You can see this in the picture below (the red arrows at the top show that the name from the marker at the beginning of the previous item ends up in the region of the current item) :

https://ibb.co/1zFr0CG

The behaviour i'm looking for is naming the region after the marker that is placed right at the beginning of each item.

What parameter should i correct in your script to make it act right for my purpose ?

Maybe there is debug mode that allows me to run the script step by step, in order to help me find the right piece of code to customize ?

EDIT : the only workaround i've found so far in my case, is to :

1) move my items slightly to the right (so that my markers are now placed slightly before each item, instead at right at the beginnign of each item)

2) run your script (which creates the regions with the right marker names)

3) move my items back to their original position, using snap and ripple editing mode (moving all tracks)
but it also makes my markers move with my items (which is counterproductive in my case)

4) move back my markers one by one at the beginning of each region (and i use the "Markers: Go to next marker/project end" action to move quickly from one marker to the next, while leaving "snap" on)

This workaround is kind of a PITA, BUT it's still faster than having to create each region and name it after each marker

Last edited by djabthrash; 08-13-2019 at 02:04 AM.
djabthrash is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.