Old 10-29-2012, 12:02 AM   #41
Veto
Human being with feelings
 
Veto's Avatar
 
Join Date: Aug 2010
Posts: 613
Default

Good to hear that Banned, thanks for the feedback
No problem at all, with your help i also learned much about the sys.path in python and the structure on osx and i'm sure this will helpful to others too.
Looking forward to your modifications.
cheers
Veto is offline   Reply With Quote
Old 11-04-2012, 08:10 PM   #42
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

not sure if this is possible with reascript, or if someone could\would do it, though this action would be really useful

"open new project tab with current projects' bpm\time signature'

possible with reascript?
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-05-2012, 07:18 PM   #43
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,314
Default

@gwok,

I'm 99.9% sure it's possible. I'm not on my REAPER machine right now so I can't test it out. If no one else posts a solution I'll see what I can cook up and post either late tonight or possibly tomorrow.
Anton9 is offline   Reply With Quote
Old 11-05-2012, 08:11 PM   #44
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

@Anton9

that would be awesome man, thanks! no rush here - (workin 120bpm atm)
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-07-2012, 01:33 AM   #45
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,314
Default

@gwok,

Ok so I messed around a little bit and this is what I came up with.
It's not the best solution, but it does work. What this script does is it will get the time sig. and BPM at the edit cursor position(this is handy if your project has any tempo/time sig. changes). It then creates a new project tab and sets it's time sig and BPM to match. However because the ReaScript API does'nt have a function for setting the time sig of a project directly without adding a time sig marker the new project tab will include a time sig marker at the begining. I'm going to put in a request to the devs for a set project time sig function and if it's added I'll update the script.

You may also notice in the script there are commands that switch to the previous project tab and then back to the new one.., these had to be added because the transport does'nt refresh with the settings contained in the time sig. marker until playback occurs or like I discovered until you switch tabs. The switch happens really fast so you should'nt even really notice it.

I did come up with another way of creating a new project based on current projects time/BPM using the SNM_SetIntConfigVar() and SNM_SetDoubleConfigVar() functions which would'nt require a marker being added to the new project. However it also has a transport refresh issue so I'm not posting that script for now.

Code:
 
# TEST  (Gets Time sig. and Tempo at cursor position then creates a new project tab with these settings.)

curProj = 0
CurPos = RPR_GetCursorPosition()
Tnum = 0	# Time sig. numerator
Tdnom = 0	# Time sig. denominator
BPM = 0
x = RPR_TimeMap_GetTimeSigAtTime(curProj, CurPos, Tnum, Tdnom, BPM)	# Gets the time sig. and BPM of current project at cursor position

RPR_Main_OnCommand(40859,0)	#Creates new project tab
RPR_SetTempoTimeSigMarker(0, -1, 0, 0, 0, x[4], x[2], x[3], 0)	# Sets new project tabs time sig. and BPM
RPR_UpdateTimeline()	#Updates the timeline
RPR_Main_OnCommand(40862, 0)	# Previous project tab
RPR_Main_OnCommand(40861, 0)	# Next project tab
Anton9 is offline   Reply With Quote
Old 11-07-2012, 10:47 AM   #46
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

Thanks Anton9, so far it's working great. Just had a chance to test quick, but it's totally solid, and I don't see any issues caused by recalling the original tab for that refresh issue.


great stuff, thanks again

g
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-13-2012, 02:40 PM   #47
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

another request in the tempo\time sig vein if anyone is up to it. Store and recall tempo\time sig actions.

So in one tab the settings can be stored, then in another hit load\recall and the settings are set.

thanks,

g
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-14-2012, 01:34 AM   #48
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,314
Default

Hey gwok,

Well thanks to a tip from Jeffos I am now posting the other script I mentioned. It basically does the same thing as the other one except it does'nt put a time sig marker in the new project and it also does'nt rely on the tab switch trick. If I get some time I'll have a try at your other request.

Code:
#Copies the time sig and BPM at the edit cursor's position and creates a new project with these settings

from sws_python import *

curProj = 0
CurPos = RPR_GetCursorPosition()
Tnum = 0	# Time sig. numerator
Tdnom = 0	# Time sig. denominator
BPM = 0
x = RPR_TimeMap_GetTimeSigAtTime(curProj, CurPos, Tnum, Tdnom, BPM)	# Gets the time sig. and BPM of current project at cursor position

RPR_Main_OnCommand(40859,0)	#Creates new project tab

SNM_SetIntConfigVar("projmeaslen", x[2])	#Sets the new projects time sig numerator 
SNM_SetIntConfigVar("projtsdenom", x[3])	#Sets the new projects time sig denominator
RPR_SetCurrentBPM(0, x[4], False)	#Sets the new projects BPM
Anton9 is offline   Reply With Quote
Old 11-14-2012, 01:40 PM   #49
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

hey Anton,

thanks for the update, though I'm getting an error with the new script -

[IMG]http://img703.**************/img703/1516/screenshot20121114at139.png[/IMG]

Uploaded with **************
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-14-2012, 02:44 PM   #50
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,314
Default

gwok,

Hmmm, not sure what the error is, the only thing I can think of is maybe when you copied and pasted it the formating got messed up, maybe a line break was inserted or something. Anyway I've uploaded the actual .py file to the stash..., here. https://stash.reaper.fm/14551/Copy2new.py

Let me know if you still get any errors.
Anton9 is offline   Reply With Quote
Old 11-14-2012, 03:10 PM   #51
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

I though the same thing, though I;m getting a different error with the stash version -

[IMG]http://img19.**************/img19/3185/screenshot20121114at309.png[/IMG]

Uploaded with **************
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-14-2012, 10:47 PM   #52
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,314
Default

Ok.., I just thought of one thing it might be. Which version of the SWS extension are you using? This line (from sws_python import *) calls to this file (sws_python.py) which on Windows resides in the (\REAPER\Plugins) directory, on the Mac I'm not sure but the installer should put it where it needs to be. So what I would do is get the latest Beta(sws_2.3.0.8) of the SWS extension. Install and try to run the script again. Let me know how it goes.
Anton9 is offline   Reply With Quote
Old 11-15-2012, 12:25 AM   #53
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

no dice, newest sws installed. I'm starting to wonder if there are some OS conflicts maybe happening here, as some scripts work for me and others don't.

Too bad, I really want to use that tempo\time sig action. Maybe something will come to light.....

cheers
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-15-2012, 12:53 AM   #54
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,314
Default

gwok,

Maybe try "from sws_python import" instead of "from sws_python import * "
or if that does'nt work try it without the "from" just "sws_python import"
Anton9 is offline   Reply With Quote
Old 11-15-2012, 01:28 AM   #55
Jeffos
Mortal
 
Jeffos's Avatar
 
Join Date: Dec 2008
Location: France
Posts: 1,969
Default

gwok, (due to a little "deployment" annoyance on OSX) make sure the script resides in ~/Library/Application Support/REAPER/Scripts, i.e. where sws_python resides. When installing the sws extension, also use the new "double-click" thingy: it installs a few required files for reascript function export (contrary to a simple/portable drag-drop the .dylib file..)
Jeffos is offline   Reply With Quote
Old 11-15-2012, 01:37 AM   #56
Anton9
Human being with feelings
 
Anton9's Avatar
 
Join Date: Jun 2009
Location: Earth
Posts: 1,314
Default

Ahhh..., Jeffos appears and saves the day
Thank you!!!
Anton9 is offline   Reply With Quote
Old 11-15-2012, 03:21 PM   #57
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

thanks guys,

Ok i did the dbl click install of sws, and the scripts folder now has sws_python.py(32\64bit) files. Though I'm still getting the same error as the above post Anton with the script from the stash -
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-15-2012, 03:31 PM   #58
timlloyd
Human being with feelings
 
Join Date: Mar 2010
Posts: 4,713
Default

Just to let you know Anton - seems to work fine here in 10.6.8 with Py 3.2 (reaper 32-bit).

What version of Python are you using Gwok?
timlloyd is offline   Reply With Quote
Old 11-15-2012, 03:40 PM   #59
gwok
Human being with feelings
 
gwok's Avatar
 
Join Date: Jun 2010
Location: Nelson, BC
Posts: 3,264
Default

I'm running 3.3 on OSX 10.6.8, will check out 3.2
__________________
MacPro Xeon, 10.9.5
Reaper 5
gwok is offline   Reply With Quote
Old 11-24-2012, 07:21 AM   #60
john doe
Human being with feelings
 
Join Date: Apr 2011
Posts: 158
Default

sorry, just ignore

Last edited by john doe; 11-27-2012 at 07:20 AM. Reason: double post
john doe is offline   Reply With Quote
Old 12-16-2012, 01:20 PM   #61
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 2,236
Default

Sorry, this didn't belong here...

Last edited by ashcat_lt; 12-16-2012 at 01:26 PM.
ashcat_lt is online now   Reply With Quote
Old 03-06-2013, 02:59 PM   #62
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

Are scripters still taking request?

I would love to have a scrip that tells REAPER to set fade time to all selected media item to a percentage of their length, individually, sooo, maybe a popup window that asks for a percentage.



This is useful for creating sample libraries, for example with a piano, you have low notes that have a long decay and high notes which have a short decay. After cutting up the recording, I could then set a length based on a percentage rather than a fixed seconds value.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 03-06-2013, 04:36 PM   #63
timlloyd
Human being with feelings
 
Join Date: Mar 2010
Posts: 4,713
Default

Code:
# -------------------------------------
# Set fade in and/or out length of all
# selected media items to the given
# percentage of their length
#
# (Un)comment lines 25/27 as required
#
# Currently there's no intelligence
# to modify behaviour if both fade
# in and out are given a % > 50 ...
# -------------------------------------

from reaper_python import *

usr_input = RPR_GetUserInputs("Set fade length of item(s)",
                              1, "Percent", "", 1024)

if usr_input[0]:
    RPR_Undo_BeginBlock2(0)
    for i in range(0, RPR_CountSelectedMediaItems(0)):
        item = RPR_GetSelectedMediaItem(0, i)
        length = RPR_GetMediaItemInfo_Value(item, "D_LENGTH")
        fade_len = length * (float(usr_input[4]) / 100.0)
        # set fade in
        # RPR_SetMediaItemInfo_Value(item, "D_FADEINLEN", fade_len)
        # set fade out
        RPR_SetMediaItemInfo_Value(item, "D_FADEOUTLEN", fade_len)
    RPR_Undo_EndBlock2(0, "Set item fade to percentage of length", -1)

RPR_UpdateArrange()

Last edited by timlloyd; 03-06-2013 at 04:49 PM.
timlloyd is offline   Reply With Quote
Old 03-06-2013, 05:11 PM   #64
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

wow! f*** that was fast. thank you!
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 03-06-2013, 11:42 PM   #65
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

Oh man, well I have another request:

user input X seconds --> "Shorten selected media items to X seconds, but only if media item length is greater than X seconds."

Basically, I am trying to define a maximum length for a number of media items. Preferrably, the input format should be 1.000 (which would be 1000ms)

__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 03-07-2013, 12:15 AM   #66
timlloyd
Human being with feelings
 
Join Date: Mar 2010
Posts: 4,713
Default

I haven't tested this, but it should work ...

Code:
# -----------------------------------------------
# Shorten selected media items to X seconds,
# if media item length is greater than X seconds.
# -----------------------------------------------

from reaper_python import *

usr_input = RPR_GetUserInputs("Shorten item(s) if longer than x",
                              1, "x (seconds)", "", 1024)

if usr_input[0]:
    RPR_Undo_BeginBlock2(0)
    for i in range(0, RPR_CountSelectedMediaItems(0)):
        item = RPR_GetSelectedMediaItem(0, i)
        length = RPR_GetMediaItemInfo_Value(item, "D_LENGTH")
        trim_len = float(usr_input[4])
        if length > trim_len:
            RPR_SetMediaItemInfo_Value(item, "D_LENGTH", trim_len)
    RPR_Undo_EndBlock2(0, "Shorten item(s) if longer than x", -1)

RPR_UpdateArrange()
timlloyd is offline   Reply With Quote
Old 03-07-2013, 12:18 AM   #67
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

*throw arms in the air* alright, I give up!

You are too kind. Thank you!
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 03-12-2013, 03:48 PM   #68
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

Alright, I tried out both scripts, very satisfactory!
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 03-28-2013, 02:31 PM   #69
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

Maybe this is a difficult or impossible script. If it is, just let me know if you think it's at least in the realm of possibility. I need a script that does something at the media item's highest peak, so it has to analyze the item to find it.

* Set snap offset of media item(s) to its peak

And this:

* (only useful to me in combination with the above script) Set left edge of media item(s) to its snap offset

Thank you!
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 03-28-2013 at 02:43 PM.
Argitoth is offline   Reply With Quote
Old 04-04-2013, 04:41 PM   #70
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

If anyone could get back to me about the post above, I could offer payment.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 04-04-2013, 08:06 PM   #71
Astonisher
Human being with feelings
 
Join Date: Mar 2013
Posts: 28
Default

For the first one, try creating the following custom action (you'll have to install the SWS extension if you don't have it already):

+SWS: Move cursor to item peak in sample
+Item: Set snap offset to cursor

Does that work as you want it to on one item? If it does, then putting it into a script to handle multiple selected items and restore the cursor position at the end would be very easy.

For the second one, do you want to just move the media item to where the snap offset was? So if you use the SWS action above to set the edit cursor to peak and then set the snap offset to the cursor, is your second request to move the media item so the left end is at the edit cursor and then cut off the right end of the media item to preserve its previous end point? Or do you just want to shorten the media item from the left end up to the cursor (in which case why set the snap-offset initially at all? you could just skip setting snap offset and immediately cut the item from the left up to the cursor point).

Just slightly confused by what you mean when you say "Set the left edge of media item to snap offset"

If you select the action:
+Item edit: Move left edge of item to edit cursor

Is that similar to the behavior you're looking for? If it is, then this can easily be built into the script as well (or do you want it separate?)

Last edited by Astonisher; 04-04-2013 at 08:26 PM.
Astonisher is offline   Reply With Quote
Old 04-04-2013, 10:03 PM   #72
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

Quote:
Originally Posted by Astonisher View Post
+SWS: Move cursor to item peak in sample
+Item: Set snap offset to cursor

Does that work as you want it to on one item? If it does, then putting it into a script to handle multiple selected items and restore the cursor position at the end would be very easy.
Yes, that would be perfect!

Ok, I know where the confusion is. See, when I said "move" I actually meant "trim".

Sooo

Script 1: Set snap offset of media item to its highest peak (all selected items)
-Now I can adjust snap offsets where needed, I can "preview" the trim.
Script 2: Trim left edge of media item to its snap offset (all selected items)
-Now I commit to my trim.

It's a "set length of time before highest peak" function, but split up in a few steps.

Edit: I'm going to add a 3rd step

Script 3: Expand left edge of media item by X seconds (input format should be 1 = 1 second, .001 = 1ms)
-Now I don't have to arbitrarily move the left edge of selected items, I can input a specific amount of time.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 04-04-2013 at 10:22 PM.
Argitoth is offline   Reply With Quote
Old 04-05-2013, 09:41 AM   #73
Astonisher
Human being with feelings
 
Join Date: Mar 2013
Posts: 28
Default

Quote:
Originally Posted by Argitoth View Post
Yes, that would be perfect!

Ok, I know where the confusion is. See, when I said "move" I actually meant "trim".

Sooo

Script 1: Set snap offset of media item to its highest peak (all selected items)
-Now I can adjust snap offsets where needed, I can "preview" the trim.
Script 2: Trim left edge of media item to its snap offset (all selected items)
-Now I commit to my trim.

It's a "set length of time before highest peak" function, but split up in a few steps.

Edit: I'm going to add a 3rd step

Script 3: Expand left edge of media item by X seconds (input format should be 1 = 1 second, .001 = 1ms)
-Now I don't have to arbitrarily move the left edge of selected items, I can input a specific amount of time.

SCRIPT # 1:
Code:
# -----------------------------------------------
# Set snap offset to highest peak in media item
# -----------------------------------------------

from reaper_python import *

RPR_PreventUIRefresh(1)
RPR_Undo_BeginBlock2(0)

try :	

	num_selected = RPR_CountSelectedMediaItems(0)
	orig_selection = []	

	# Save original item selection and cursor position
	for i in range(num_selected):
		itm = RPR_GetSelectedMediaItem(0, i)
		orig_selection.append(itm)
	orig_cursor = RPR_GetCursorPosition()

	# Item: Unselect all items
	RPR_Main_OnCommand(40289, 0)

	# Process each item
	for itm in orig_selection:
		# Select item
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)

		# SWS: Move cursor to item peak sample
		RPR_Main_OnCommand(RPR_NamedCommandLookup('_SWS_FINDITEMPEAK'), 0)
		
		# Item: Set snap offset to cursor
		RPR_Main_OnCommand(40541, 0)

		# Unselect item
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 0)

	# Restore state
	for itm in orig_selection:
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)
	RPR_SetEditCurPos(orig_cursor, False, False)
		

finally:
	RPR_PreventUIRefresh(-1)
	RPR_Undo_EndBlock2(0,"Set snap offset to highest peak for selected items",-1)
	RPR_UpdateTimeline()


SCRIPT #2:
Code:
# -----------------------------------------------
# Trim edge to snap offset for selected items
# -----------------------------------------------


from reaper_python import *

RPR_PreventUIRefresh(1)
RPR_Undo_BeginBlock2(0)

try :	

	num_selected = RPR_CountSelectedMediaItems(0)
	orig_selection = []	

	# Save original item selection and cursor position
	for i in range(num_selected):
		itm = RPR_GetSelectedMediaItem(0, i)
		orig_selection.append(itm)
	orig_cursor = RPR_GetCursorPosition()

	# Item: Unselect all items
	RPR_Main_OnCommand(40289, 0)

	# Process each item
	for itm in orig_selection:
		# Select item
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)

		# Put cursor at snap offset
		pos = RPR_GetMediaItemInfo_Value(itm, "D_POSITION")
		offset = RPR_GetMediaItemInfo_Value(itm, "D_SNAPOFFSET")	
		RPR_SetEditCurPos(pos+offset, False, False)
		
		# Item edit: Trim left edge of item to edit cursor
		RPR_Main_OnCommand(41305, 0)

		# Unselect item
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 0)

	# Restore state
	for itm in orig_selection:
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)
	RPR_SetEditCurPos(orig_cursor, False, False)
		

finally:
	RPR_PreventUIRefresh(-1)
	RPR_Undo_EndBlock2(0,"Trim edge to snap offset for selected items",-1)
	RPR_UpdateTimeline()

Unfortunately had to do it with selecting items individually and moving the edit cursor around, so it's not completely elegant, but it works as expected.

Regarding SCRIPT #3, how do you want the snap offset to be treated in that case? (preserve where it was at in time before the added length or have it move with the left edge?)
Astonisher is offline   Reply With Quote
Old 04-05-2013, 11:57 AM   #74
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

Ah yes! Thank you. For the "expand left edge" should not affect snap offset.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 04-06-2013, 12:45 AM   #75
Astonisher
Human being with feelings
 
Join Date: Mar 2013
Posts: 28
Default

Quote:
Originally Posted by Argitoth View Post
Ah yes! Thank you. For the "expand left edge" should not affect snap offset.
Here ya go,

SCRIPT #3
Code:
# -------------------------------------------------------
# Expand left edge of selected media items by X seconds
# -------------------------------------------------------


from reaper_python import *

RPR_PreventUIRefresh(1)
RPR_Undo_BeginBlock2(0)

try :

	inpt = RPR_GetUserInputs("Expand left edge of items",  1, "x (seconds): ", "", 10)
	if inpt[0]:
		try:
			x_sec = float(inpt[4])
		except:
			RPR_ShowMessageBox("Invalid input!", "Error", 0)
			raise
	
		num_selected = RPR_CountSelectedMediaItems(0)
		orig_selection = []	

		# Save original item selection and cursor position
		for i in range(num_selected):
			itm = RPR_GetSelectedMediaItem(0, i)
			orig_selection.append(itm)
		orig_cursor = RPR_GetCursorPosition()

		# Item: Unselect all items
		RPR_Main_OnCommand(40289, 0)	

		# Process each item
		for itm in orig_selection:
			# Select item
			RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)

			# Put cursor X seconds to left of media item
			pos = RPR_GetMediaItemInfo_Value(itm, "D_POSITION")
			RPR_SetEditCurPos(pos-x_sec, False, False)
		
			# Item: Trim left edge of item to edit cursor
			RPR_Main_OnCommand(41305, 0)

			# Unselect item
			RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 0)

		# Restore state
		for itm in orig_selection:
			RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)
		RPR_SetEditCurPos(orig_cursor, False, False)
		

finally:
	RPR_PreventUIRefresh(-1)
	RPR_Undo_EndBlock2(0,"Expand left edge of items by X second(s)",-1)
	RPR_UpdateTimeline()
Similar method as the first two scripts.
Astonisher is offline   Reply With Quote
Old 04-06-2013, 05:07 PM   #76
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

In the peak script you are using RPR_Main_OnCommand(RPR_NamedCommandLookup('_SWS_FI NDITEMPEAK'), 0)

using sws extension to do a find peak command.

Does sws have a "find first point above X db?" So, it could potentially place the snap offset point where the media item first reaches a certain db.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 04-07-2013, 01:32 PM   #77
Astonisher
Human being with feelings
 
Join Date: Mar 2013
Posts: 28
Default

Quote:
Originally Posted by Argitoth View Post
In the peak script you are using RPR_Main_OnCommand(RPR_NamedCommandLookup('_SWS_FI NDITEMPEAK'), 0)

using sws extension to do a find peak command.

Does sws have a "find first point above X db?" So, it could potentially place the snap offset point where the media item first reaches a certain db.
Hmm I don't think SWS has anything like that (at least not that I know of).

Not sure if this is what you're looking for, but it's the closest solution I was able to find:

Code:
# ---------------------------------------------------
# Set snap offset to threshold dB for selected items
# ---------------------------------------------------


from reaper_python import *

RPR_PreventUIRefresh(1)
RPR_Undo_BeginBlock2(0)

try :	

	num_selected = RPR_CountSelectedMediaItems(0)
	orig_selection = []	


	# Save original item selection and cursor position
	for i in range(num_selected):
		itm = RPR_GetSelectedMediaItem(0, i)
		orig_selection.append(itm)
	orig_cursor = RPR_GetCursorPosition()

	# Transient detection sensitivity/threshold: adjust... (toggle dialog)
	RPR_Main_OnCommand(41208, 0)
	RPR_ShowMessageBox("Adjust transient detection settings.\nClick OK when done.", "Set snap offset to threshold dB", 0)
	RPR_Main_OnCommand(41208, 0)

	# Item: Unselect all items
	RPR_Main_OnCommand(40289, 0)

	# Process each item
	for itm in orig_selection:
		# Select item
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)

		# Move cursor to left edge of item
		RPR_SetEditCurPos(RPR_GetMediaItemInfo_Value(itm, "B_POSITION"), False, False)

		# Item navigaton: Move cursor to next transient in items
		RPR_Main_OnCommand(40375, 0)		

		# Item: Set snap offset to cursor
		RPR_Main_OnCommand(40541, 0)

		# Unselect item
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 0)

	# Restore state
	for itm in orig_selection:
		RPR_SetMediaItemInfo_Value(itm, "B_UISEL", 1)
	RPR_SetEditCurPos(orig_cursor, False, False)
		

finally:
	RPR_PreventUIRefresh(-1)
	RPR_Undo_EndBlock2(0,"Set snap offset to threshold dB for selected items",-1)
	RPR_UpdateTimeline()
Basically, it uses Reaper's transient detection system to set the snap offset at the first transient.
(NOTE1: You may have to set "Sensitivity" to 100%)
(NOTE2: Just realized that on Mac OS, the second dialog box with the "Click OK" prompt prevents adjusting the sliders/settings in the Transient dialog. If this is an issue, then delete the three lines starting with 'RPR_Main_OnCommand(41208, 0)' and simply open the Transient dialog settings on your own before running the script.)

If that's not quite it, then there IS a way to read the samples via ReaScript, but it will be very slow, especially on larger item sizes (or multiple items).

Last edited by Astonisher; 04-07-2013 at 03:54 PM.
Astonisher is offline   Reply With Quote
Old 04-07-2013, 03:13 PM   #78
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

I just tried it out, omg, that just might do it! I have to verify with a friend of mine. Basically, I'm trying to turn REAPER into the perfect tool for cutting samples for use in a sample library and it's almost perfect. You can almost export entire recordings as discreet samples with a handful of buttons, auto-named, cut, organized into folders, etc.

SWS's "sort by peak" saved my life, for example.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 04-07-2013, 07:14 PM   #79
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Phoenix, AZ
Posts: 2,037
Default

I experimented with ReaFIR Gate mode to get rid of most of the noise before using the transient detector. The transient detector then is smart enough to skip other noises. So it works! Your latest script is extremely helpful, using only the first slice/transient. That's genius!
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 04-08-2013, 04:09 PM   #80
Astonisher
Human being with feelings
 
Join Date: Mar 2013
Posts: 28
Default

Quote:
Originally Posted by Argitoth View Post
I experimented with ReaFIR Gate mode to get rid of most of the noise before using the transient detector. The transient detector then is smart enough to skip other noises. So it works! Your latest script is extremely helpful, using only the first slice/transient. That's genius!
Awesome, glad it worked out!

Not sure if you've tried playing around with the "Sensitivity" setting, but I seem to recall setting it to 100% made it detect the first dB threshold correctly (you can hit a checkbox to visually see a line where the threshold is on the waveform). Setting sensitivity low seemed to make the behavior less accurate (at least for the purpose of finding the very first time a threshold dB was exceeded).
Astonisher 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 11:35 PM.


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