Old 03-23-2014, 05:38 AM   #1
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default Transposing Items and Regions (Scripts)

I often use these actions:

Item properties: Pitch item down one octave
Item properties: Pitch item down one semitone
Item properties: Pitch item up one octave
Item properties: Pitch item up one semitone

1) Is there a way to protect some items from these actions? This way I could easily select all items in project and transpose them while preserving the pitch on some items such as Drums for example.

2) Another question.. Is there a way to see the new pitch of the notes in pitch modified items inside the midi editor? Right now I think the only indication of a transposed item is a small text on the item [Pitch +2.00] for example. I have seen SWS actions actually move the notes instead of setting item pitch.

Last edited by heda; 04-03-2014 at 02:50 AM. Reason: changed title
heda is offline   Reply With Quote
Old 03-27-2014, 03:14 PM   #2
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

nobody transposing songs ?

I guess there is no way of doing what I asked.. so I may go to Feature Requests
heda is offline   Reply With Quote
Old 03-27-2014, 03:21 PM   #3
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Probably could script something like 'if drum in track name don't do it.' Maybe unselect items etc? If something like that floats your boat, name your poison I'll give a shot shouldn't be too tough. I think. Track name could maybe use console action instead of script.

Last edited by FnA; 03-27-2014 at 04:01 PM.
FnA is offline   Reply With Quote
Old 03-27-2014, 05:51 PM   #4
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

Yes it would be nice to unselect all items from a track if there is some kind of keyword in the track name such as "no transpose".
mmmmm I think there is a way to select tracks by name with SWS extensions... I have to look at it.
Or maybe it could be item specific instead of all items in the track. By looking for the keyword at the item notes.

Then it would be easy to select all items and then unselect no transpose items and use the regular actions to transpose.


another ideal workflow would be something like Cubase transpose track... by using regions. Having a suffix on the region name (+2) would transpose all items inside region except protected ones by track keyword or item note keyword.
Maybe a script that would go and check all region suffixes and transpose items that correspond to each regions. So I can have a region that is at +2 and then a region that goes to +5..etc... change suffix and rerun script to change global transpose. That would be the awesome script
heda is offline   Reply With Quote
Old 03-27-2014, 07:07 PM   #5
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

I think the "awesome script" is doable probably. But probably a little harder to write than this. No time today...

Code:
###unselect items with NO_TRP in name###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def make_usmiL():
    csmi = RPR_CountSelectedMediaItems(0)
    for i in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, i)
        for n in range(RPR_GetMediaItemNumTakes(CurrItem)):
            RGT = RPR_GetTake(CurrItem, n)
            if 'NO_TRP' in str(RPR_GetTakeName(RGT)):
                usmiL.append(CurrItem)
                break

def unselect_from_usmiL():
    while len(usmiL) >= 1:
        unsel_item = usmiL.pop()
        RPR_SetMediaItemSelected(unsel_item, 0)
        RPR_UpdateItemInProject(unsel_item)

usmiL = []
        
with noUIRefresh():
    make_usmiL()
    unselect_from_usmiL()
Seems to be working...
FnA is offline   Reply With Quote
Old 03-28-2014, 02:54 AM   #6
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

ohhh this is great Thank you ...AGAIN
now I have replaced my actions to transpose with a custom action to include your script to unselect NO_TRP items before transposing.
I must find more time to learn scripting.
heda is offline   Reply With Quote
Old 03-28-2014, 08:27 PM   #7
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

The first script will unselect an item if ANY take has NO_TRP in the name. This one will do it based on the active take only.

Code:
###unselect items with NO_TRP in name 2###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def make_usmiL():
    csmi = RPR_CountSelectedMediaItems(0)
    for i in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, i)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, round(CT))
        if 'NO_TRP' in str(RPR_GetTakeName(GT)):
            usmiL.append(CurrItem)

def unselect_from_usmiL():
    while len(usmiL) >= 1:
        unsel_item = usmiL.pop()
        RPR_SetMediaItemSelected(unsel_item, 0)
        RPR_UpdateItemInProject(unsel_item)

usmiL = []
        
with noUIRefresh():
    make_usmiL()
    unselect_from_usmiL()
FnA is offline   Reply With Quote
Old 03-28-2014, 11:39 PM   #8
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

can it be done in EEL? I will end up learning

Maybe this thread should be renamed to "Unselect items with keyword in name" and moved to JS and ReaScript Discussion.

That awesome script about working with regions.. not so much needed now...
I just use the action: "SWS/S&M: Split and select items in region near cursor", and then your script to unselect NO_TRP items and then pitch up or down as needed.
heda is offline   Reply With Quote
Old 03-29-2014, 04:16 AM   #9
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

I don't know. I would hope so. Have not taken the plunge to EEL yet. I probably will wait until a few more simple EEL scripts are out. There's a bunch of scripts one can study for python. Also some fairly good free documentation on the python site. Using the python shell to experiment helps sometimes with loops and functions and such. Glad you don't need the region script. You would have had to explain in higher detail how that should work. Or else someone else should do it.
FnA is offline   Reply With Quote
Old 03-29-2014, 09:50 AM   #10
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,154
Default

hi guys

I've been lurking along on this discussion, and not that I personally need these functions, but it has made me wonder this:

jnif at one time made some py scripts for me that I use as part of a custom action for freezing a track.

what they do is add or subtract a character[*] to the beginning of the track name. Then a track that has that * gets a color and an icon when it is frozen, ..and when unfrozen the *, and color and icon is removed.

jnif calls these "prepend to track name" and "strip first from track name"

So... I assume a similar script could be made to add a set of characters to any selected item's name.... is that true???

OK, IF it is true, what about a set of scripts like so:

prepend to selected media item name:

T+1 T+2, T+3, etc. up to T+12
and
T-1, T-2, T-3, etc. up to T-12

Where each number means a semitone up or down... right?

Then a script to select ONLY items with a given T number in their name.
Then a custom action to act on the selected item with the matching transpose amounts for that number.... you see what I'm thinking?

IF all that could be done, then a nice little toolbar could be made with all those custom actions, ..right?

whachatink?

I am in NOT a script creator but I could post the jnif examples that work for track names if that would help.
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-29-2014, 11:16 AM   #11
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

Hi hopi... I like the idea.
First I prefer to use SWS extensions to transpose items because they actually move the midi notes instead of the regular Pitch actions which only changes the item's pitch properties. This is better to work with the midi editor because you actually see the real notes. Although sometimes you may not want to.
But I also like the regular Pitch up and down actions because they indicate in the name [Pitch +1.00] etc... So I can see which parts have been transposed from the original.

With your idea you could have both advantages... a T+1..etc in the name of the items and the use of SWS actions to transpose. I like the idea.

But the need of a NO_TRP tag to protect items is still needed. so it would be a combination of all scripts
heda is offline   Reply With Quote
Old 03-29-2014, 03:24 PM   #12
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Go ahead and post them hopi. They might not be absolutely necessary, but they sound interesting. spk77 wrote an EEL script to select items of the same name. Looks like handling text strings is a little different in EEL. If you can put as much detail as you can into what you guys want here i'll look into it (python probably) this evening a bit. Already have a bit to go on, but every maybe eliminated helps.
FnA is offline   Reply With Quote
Old 03-29-2014, 04:24 PM   #13
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,154
Default

this jnif's 'Freeze_prepend___to_track_name.py'

Quote:
saveSelection = RPR_NamedCommandLookup('_SWS_SAVESEL')
selFirst = RPR_NamedCommandLookup('_XENAKIOS_SELFIRSTOFSELTRA X')
restoreSelection = RPR_NamedCommandLookup('_SWS_RESTORESEL')
RPR_Undo_BeginBlock2(0)
numTracks = RPR_CountSelectedTracks(0)
RPR_Main_OnCommand(saveSelection, 0)
RPR_Main_OnCommand(selFirst, 0)
selTrack = RPR_GetSelectedTrack(0, 0)
for x in range(1, (numTracks + 1)):
oldTrackName = RPR_GetSetMediaTrackInfo_String(selTrack, "P_NAME", "", 0)
newTrackName = ("*" + oldTrackName[3])
RPR_GetSetMediaTrackInfo_String(selTrack, "P_NAME", newTrackName, 1)
RPR_Main_OnCommand(40285, 0)
selTrack = RPR_GetSelectedTrack(0, 0)
RPR_Main_OnCommand(restoreSelection, 0)
RPR_Undo_EndBlock2(0, "Prepend * to track name", 0)
this is his 'Freeze_strip_first___from_track_name.py'
Quote:
import re
saveSelection = RPR_NamedCommandLookup('_SWS_SAVESEL')
selFirst = RPR_NamedCommandLookup('_XENAKIOS_SELFIRSTOFSELTRA X')
restoreSelection = RPR_NamedCommandLookup('_SWS_RESTORESEL')
RPR_Undo_BeginBlock2(0)
numTracks = RPR_CountSelectedTracks(0)
RPR_Main_OnCommand(saveSelection, 0)
RPR_Main_OnCommand(selFirst, 0)
selTrack = RPR_GetSelectedTrack(0, 0)
for x in range(1, (numTracks + 1)):
selTrackName = RPR_GetSetMediaTrackInfo_String(selTrack, "P_NAME", "", 0)
match = re.match("(.*?\\*)(.*)", selTrackName[3])
if match is not None:
newTrackName = match.group(2)
RPR_GetSetMediaTrackInfo_String(selTrack, "P_NAME", newTrackName, 1)
else:
RPR_Main_OnCommand(65535, 0)
RPR_Main_OnCommand(40285, 0)
selTrack = RPR_GetSelectedTrack(0, 0)
RPR_Main_OnCommand(restoreSelection, 0)
RPR_Undo_EndBlock2(0, "Strip first * from track name", 0)
whatever else you might want, I'm happy to supply if I can.

On the point about NO_TRP, ...sure, fine... whatever is needed

I guess I thought anything that did not have +xx or --xx in the name would just not become selected.

but really I know nothing about this.
I was not even thinking about MIDI items... only about audio items.
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-29-2014, 05:00 PM   #14
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Do you want an input box to enter a number or do you want (to copy yourself) specific scripts?
FnA is offline   Reply With Quote
Old 03-29-2014, 05:46 PM   #15
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,154
Default

good question... never thought about an input box but I can see how that might be great... IF I am understand it right:

would it be like this:

I select some media items, run the script and a box come up that let's me put in some characters that will be added to beginning of the items name? Is that correct?

IF so, I like that idea as it would work for many uses...

now on the other hand, a generic script that we could copy and alter to add a little string, like +1 or -12 or NO-TRP would also be nice... because once we were to make a set of those, they could each be added to a matching custion action... such as:

set the item name to +3 and transpose it up 3 semitones... right?

I'm thinking these then be set up on their own toolbar, with some nice little icons, or text icons,...

Am I on the same page as your thinking???
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-29-2014, 06:19 PM   #16
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Yes and not quite. LOL.

I guess i'm thinking worst case (for me) scenario. I can do both of those. I was just wondering about a more comprehensive solution that would take existing "T+whatevers" into account, but that can wait I suppose. Here's the first two. You can copy and edit them as many times as needed. Things which appear after a pound sign are just comments in python (most of the time.) Little FYIs.

Code:
###prepend take name with T+1###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def prepend_take_name():
    csmi = RPR_CountSelectedMediaItems(0)
    for i in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, i)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]
        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "T+1 " + TN, 1)#change to "T+whatever"

with noUIRefresh():
    prepend_take_name()
Code:
###select items with T+1 in name###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def select_T():
    CMI = RPR_CountMediaItems(0)
    for i in range(CMI):
        CurrItem = RPR_GetMediaItem(0, i)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        if "T+1" in str(RPR_GetTakeName(GT)):#change to "T+whatever"
            RPR_SetMediaItemSelected(CurrItem, 1)
            RPR_UpdateItemInProject(CurrItem)

with noUIRefresh():
    select_T()

Last edited by FnA; 03-30-2014 at 03:14 PM. Reason: error
FnA is offline   Reply With Quote
Old 03-29-2014, 06:33 PM   #17
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Code:
###prepend take name by input box###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def dialog():
    names = "prefix"
    defvalues = ","
    maxreturnlen = 20   # one more than what you expect to get back
    nitems = 1 # number of input boxes
    Query = RPR_GetUserInputs("Enter prefix",nitems,names,defvalues,maxreturnlen)

    if Query[0] == 1: # user clicked OK
        UserValues = Query[4].split(',')

        if UserValues[0] != []:
            PF = str(UserValues[0])
            PFL.append(PF)

def prepend_take_name():
    csmi = RPR_CountSelectedMediaItems(0)
    for i in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, i)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]
        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", PFL[0] + TN, 1)#change to "T+whatever"

PFL = []
dialog()

with noUIRefresh():
    prepend_take_name()

Last edited by FnA; 03-30-2014 at 03:14 PM. Reason: error
FnA is offline   Reply With Quote
Old 03-29-2014, 09:56 PM   #18
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,154
Default

Quote:
Script execution error

Traceback (most recent call last):
File "prepend take name via input box.py", line 40, in <module>
prepend_take_name()
File "prepend take name via input box.py", line 32, in prepend_take_name
GT = RPR_GetTake(CurrItem, round(CT))
File "D://Reaper 64 Portable//Plugins\reaper_python.py", line 1449, in RPR_GetTake
t=(rpr_packp('MediaItem*',p0),c_int(p1))
TypeError: int expected instead of float
this is for the via box input script

not tested the others yet...

I was trying it on a fresh empty midi item...

Did I say THANKS for you gifts?? THANK YOU
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-29-2014, 10:00 PM   #19
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,154
Default

Quote:
Script execution error

Traceback (most recent call last):
File "prepend take name with T+1.py", line 23, in <module>
prepend_take_name()
File "prepend take name with T+1.py", line 18, in prepend_take_name
GT = RPR_GetTake(CurrItem, round(CT))
File "D://Reaper 64 Portable//Plugins\reaper_python.py", line 1449, in RPR_GetTake
t=(rpr_packp('MediaItem*',p0),c_int(p1))
TypeError: int expected instead of float
error for the T+1 script
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-29-2014, 10:04 PM   #20
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,154
Default

Quote:
Script execution error

Traceback (most recent call last):
File "Select Items with T+1 in name.py", line 24, in <module>
select_T()
File "Select Items with T+1 in name.py", line 18, in select_T
GT = RPR_GetTake(CurrItem, round(CT))
File "D://Reaper 64 Portable//Plugins\reaper_python.py", line 1449, in RPR_GetTake
t=(rpr_packp('MediaItem*',p0),c_int(p1))
TypeError: int expected instead of float
and for the select script....
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-30-2014, 04:21 AM   #21
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

same error here

I have changed my mind about using SWS/FNG: transpose selected MIDI items up/down a semitone
Because if you use pooled midi items, they all change. so if you want to transpose a part maintaining the pooling data you must use the regular Pitch up/down actions.. or the SWS: Pitch all takes up/down one semitone

This is my "Transpose Region +1" custom action:
- SWS/S&M: Split and select items in region near cursor
- Custom: unselect_NO_TRP.py
- SWS: Pitch all takes up one semitone

just put the cursor inside the region you want to transpose and click the button. Excellent!

an example test project licecap gif (sorry it may be a bit large?):

Last edited by heda; 03-30-2014 at 04:33 AM.
heda is offline   Reply With Quote
Old 03-30-2014, 09:28 AM   #22
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,154
Default

starting to look close...

fine but ONLY IF what you want to operate on is in a region, eh?

you see, at the start of this discussion, I was thinking not so much about midi but more about audio items...

of course we really would want to deal with both...

and hopefully, when the scripts totally work, we can not be limited by regions, but rather be able to operate on various items by name wherever they exits in a project... right?
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 03-30-2014, 12:58 PM   #23
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

Quote:
Originally Posted by hopi View Post
starting to look close...

fine but ONLY IF what you want to operate on is in a region, eh?

you see, at the start of this discussion, I was thinking not so much about midi but more about audio items...

of course we really would want to deal with both...

and hopefully, when the scripts totally work, we can not be limited by regions, but rather be able to operate on various items by name wherever they exits in a project... right?
normally I only need to transpose all items in a region, except FX and drums, etc. THat needs to create regions... if no regions are used I can just use the same custom action without the selec items in region part. ANd work only on selected items.

The part we still need is to add prefixes to selected items and select items with specific prefix.

a problem about adding prefix to names is that you also need to replace existing prefix. Example: you have some items with prefix T+2 already then you want to change them to T+5... it would have to replace the prefix, not to add another prefix. and then change pitch to 5.

edit: this removes all selected items name: http://forum.cockos.com/showpost.php...&postcount=413
select all items with same name: http://forum.cockos.com/showpost.php...&postcount=425
just need to work on prefix only.. not on full name.

Last edited by heda; 03-30-2014 at 01:17 PM.
heda is offline   Reply With Quote
Old 03-30-2014, 03:00 PM   #24
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

I will work on the other scripts. I think I know what happened. Funny they don't throw an error here, but I changed the round to int, might be the problem. I think this script is better any way. Could probably use S&M Find to select items with "T+" or "t-."

Shit same thing in these scripts. Hold on a sec. OK. changed it. Changed at 6:24 ET 3-30-14

Here's what else I got so far. I made some of these also for the SWS transpose actions. There's an action here to transpose up via input box and relabel the item. It's supposed to take existing transpositions into effect. These versions use 'pitch items up/down an octave/semitone.'

Code:
###Transpose selected Audio items up by input and Relabel###
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)

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def dialog():
    names = "Number of Semitones:"
    defvalues = ","
    maxreturnlen = 20   # one more than what you expect to get back
    nitems = 1 # number of input boxes
    Query = RPR_GetUserInputs("Transpose Audio Items Up",nitems,names,defvalues,maxreturnlen)

    if Query[0] == 1: # user clicked OK
        UserValues = Query[4].split(',')

        if UserValues[0] != []:
            UV = str(UserValues[0])
            DL.append(UV)

def Transpose_Audio_Items_Up():
    with noUIRefresh():
        numST = int(xxxL[0])
        while numST > 0:
            if numST < 12:
                RPR_Main_OnCommand(40204, 0)
                numST = numST - 1
            else:
                RPR_Main_OnCommand(40515, 0)
                numST = numST - 12

def rename_all_selected():
    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]

        if "T+" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("+")[1])
            TN = TN.replace(CurTRPstr, "T+" + str(int(xxxL[0]) + CurTRPnum))
        elif "T-" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("-")[1])
            NewNum = 0 - CurTRPnum + int(xxxL[0])
            if NewNum > 0:
                TN = TN.replace(CurTRPstr, "T+" + str(NewNum))
            elif NewNum < 0:
                TN = TN.replace(CurTRPstr, "T" + str(NewNum))
            else:
                TN = TN.replace(CurTRPstr + " ", "")
        else:
            TN = 'T+' + str(int(xxxL[0])) + ' ' + TN

        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", TN, 1)
        

with undoable("Transpose selected Audio items down by input"):
    DL = []
    dialog()
    xxxL = []

    if str(DL[0]) == (''):
        xxxL.append(1)
    else:
        xxxL.append(float(DL[0].strip('')))

    csmi = RPR_CountSelectedMediaItems(0)

    if csmi == 1:
        Transpose_Audio_Items_Up()
    if csmi > 1:
        result = RPR_MB('Are you sure?', "More than one item selected", 1)
        if result == 1:
            Transpose_Audio_Items_Up()

    rename_all_selected()

Last edited by FnA; 03-30-2014 at 03:26 PM.
FnA is offline   Reply With Quote
Old 03-30-2014, 03:02 PM   #25
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

This one doesn't have the prevent UI refresh in it, but I don't think it really matters. I can fix it later if you can see a difference.

Code:
###Transpose selected Audio items down by input Rename###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

def dialog():
    names = "Number of Semitones:"
    defvalues = ","
    maxreturnlen = 20   # one more than what you expect to get back
    nitems = 1 # number of input boxes
    Query = RPR_GetUserInputs("Transpose Audio Items Down",nitems,names,defvalues,maxreturnlen)

    if Query[0] == 1: # user clicked OK
        UserValues = Query[4].split(',')

        if UserValues[0] != []:
            UV = str(UserValues[0])
            DL.append(UV)

def Transpose_Audio_Items_Down():
    numST = int(xxxL[0])
    while numST > 0:
        if numST < 12:
            RPR_Main_OnCommand(40205, 0)
            numST = numST - 1
        else:
            RPR_Main_OnCommand(40516, 0)
            numST = numST - 12

def rename_all_selected():
    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]

        if "T-" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = 0 - int(CurTRPstr.split("-")[1])
            TN = TN.replace(CurTRPstr, "T" + str(int(0 - xxxL[0]) + CurTRPnum))
        elif "T+" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("+")[1])
            NewNum = CurTRPnum + (0 - int(xxxL[0]))
            if NewNum > 0:
                TN = TN.replace(CurTRPstr, "T+" + str(NewNum))
            elif NewNum < 0:
                TN = TN.replace(CurTRPstr, "T" + str(NewNum))
            else:
                TN = TN.replace(CurTRPstr + " ", "")
        else:
            TN = 'T-' + str(int(xxxL[0])) + ' ' + TN

        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", TN, 1)
        
with undoable("Transpose selected Audio items down by input"):
    DL = []
    dialog()
    xxxL = []

    if str(DL[0]) == (''):
        xxxL.append(1)
    else:
        xxxL.append(float(DL[0].strip('')))

    csmi = RPR_CountSelectedMediaItems(0)

    if csmi == 1:
        Transpose_Audio_Items_Down()
    if csmi > 1:
        result = RPR_MB('Are you sure?', "More than one item selected", 1)
        if result == 1:
            Transpose_Audio_Items_Down()

    rename_all_selected()

Last edited by FnA; 03-30-2014 at 03:24 PM.
FnA is offline   Reply With Quote
Old 03-30-2014, 03:49 PM   #26
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

Hi FnA.
A small bug on the new scripts. I tried to transpose negative number and it doesn't work very well. it went from T+2 , run the script with -5 and it renamed to T+-3, and the pitch didn't change.
It works nice with positive numbers.

edit: oh.. sorry... there is one different script for up and other for down...
it is working very well
heda is offline   Reply With Quote
Old 03-30-2014, 05:19 PM   #27
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Maybe I'll put it into one eventually. Did you try the edited scripts? I don't know why you guys get that error and I don't...

You know, this subject has gotten me interested in names. If you have more ideas i'm listening. I'll look into what else has been written lately...

Quote:
Originally Posted by heda View Post
The part we still need is to add prefixes to selected items and select items with specific prefix.
Are you thinking of a form of "grouping" substitute? edit-The T+1 etc is useful in the MIDI editor when using the Pitch up/down actions, so I don't know if you would want to select every item in the project based on that. Maybe a suffix would be better as a selection target. Don'know... I'll probably drop this for now unless you guys think of improvements which are needed. Or until I think of something better myself. The things you show in the licecap are fairly slick, but I wonder if used with many items if a slow down would happen. I have noticed the SWS transpose actions are not the fastest updating things in the world...So I don't know if i should drop the input box and just go with a semitone at a time or not. Etc...

Last edited by FnA; 03-31-2014 at 07:20 AM.
FnA is offline   Reply With Quote
Old 03-31-2014, 09:10 PM   #28
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

Thinking about it better, it is better not to select by prefix. You could have various items with the same prefix and wanting to select only some of them. So working with regions is good for me.
I am pretty happy with the scripts as they are right now

Working with item's pitch for transposing MIDI items is not good because when you enter into the midi editor the notes you listen are not the ones that are displayed.
So maybe your script could use the SWS/FNG transpose selected MIDI items up/down a semitone to actually move the notes instead of changing item's pitch. If this is too slow maybe it is better to just work as it is now changing item's pitch and then to have another script that converts item's pitch to "moved notes" and vice-versa just if needed and reset pitch to +0. This would lose the display of transposition in the label [Pitch +x] but it doesn't matter since we now have the T+x prefix!
heda is offline   Reply With Quote
Old 03-31-2014, 09:58 PM   #29
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,154
Default

I don't get those errors... so that's good

If I run the down script, I get the name change [on an audio item] but do not get the pitch change... funny cuz it shows in the items info, but it is not really changed [to my ears]

So I'm wondering a few diff ways:

One way would be to have a script that would only put in the desired first part of a name... we'd need to decide how that should be like T-01, T-02, etc. or T+01, up to say T+12

Then a diff script that would select all items with T-xx in the item name, ...and then we could use existing actions to do the actual pitch amount changes...

So in that way of thinking, the reason for using the T-01 is so that we could also have something that would remove the first 4 characters of an item name, ...so we could rename them with yet another script... [OMG]

What would really be nice, but I don't know if it's possible would be a single script that would prepend the name and also do the pitch change either up or down via a box entry....
[at least atm I think that would be nice]
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 04-02-2014, 09:46 AM   #30
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

That's odd hopi. Here the script works. It changes the name (T-6 etc) and the label (Pitch - 6.00)that you enable in preferences. Go figure. I'll post the SWS style scripts later.

Here's they are. Crap. Forgot the round thing again. Fixed at 2:10 ET

Code:
###Transpose selected MIDI items up by input and Relabel###
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)

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def dialog():
    names = "Number of Semitones:"
    defvalues = ","
    maxreturnlen = 20   # one more than what you expect to get back
    nitems = 1 # number of input boxes
    Query = RPR_GetUserInputs("Transpose MIDI Items Up",nitems,names,defvalues,maxreturnlen)

    if Query[0] == 1: # user clicked OK
        UserValues = Query[4].split(',')

        if UserValues[0] != []:
            UV = str(UserValues[0])
            DL.append(UV)

def Transpose_MIDI_Items_Up():
    with noUIRefresh():
        numST = int(xxxL[0])
        while numST > 0:
            if numST < 12:
                RPR_Main_OnCommand(RPR_NamedCommandLookup('_FNG_MIDI_UP_SEMI'), 0)
                numST = numST - 1
            else:
                RPR_Main_OnCommand(RPR_NamedCommandLookup('_FNG_MIDI_UP_OCT'), 0)
                numST = numST - 12

def rename_all_selected():
    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]

        if "T+" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("+")[1])
            TN = TN.replace(CurTRPstr, "T+" + str(int(xxxL[0]) + CurTRPnum))
        elif "T-" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("-")[1])
            NewNum = 0 - CurTRPnum + int(xxxL[0])
            if NewNum > 0:
                TN = TN.replace(CurTRPstr, "T+" + str(NewNum))
            elif NewNum < 0:
                TN = TN.replace(CurTRPstr, "T" + str(NewNum))
            else:
                TN = TN.replace(CurTRPstr + " ", "")
        else:
            TN = 'T+' + str(int(xxxL[0])) + ' ' + TN

        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", TN, 1)
        

with undoable("Transpose selected MIDI items up by input"):
    DL = []
    dialog()
    xxxL = []

    if str(DL[0]) == (''):
        xxxL.append(1)
    else:
        xxxL.append(float(DL[0].strip('')))

    csmi = RPR_CountSelectedMediaItems(0)

    if csmi == 1:
        Transpose_MIDI_Items_Up()
    if csmi > 1:
        result = RPR_MB('Are you sure?', "More than one item selected", 1)
        if result == 1:
            Transpose_MIDI_Items_Up()

    rename_all_selected()
Code:
###Transpose selected MIDI items down by input Relabel###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def dialog():
    names = "Number of Semitones:"
    defvalues = ","
    maxreturnlen = 20   # one more than what you expect to get back
    nitems = 1 # number of input boxes
    Query = RPR_GetUserInputs("Transpose Audio Items Down",nitems,names,defvalues,maxreturnlen)

    if Query[0] == 1: # user clicked OK
        UserValues = Query[4].split(',')

        if UserValues[0] != []:
            UV = str(UserValues[0])
            DL.append(UV)

def Transpose_MIDI_Items_Down():
    with noUIRefresh():
        numST = int(xxxL[0])
        while numST > 0:
            if numST < 12:
                RPR_Main_OnCommand(RPR_NamedCommandLookup('_FNG_MIDI_DN_SEMI'), 0)
                numST = numST - 1
            else:
                RPR_Main_OnCommand(RPR_NamedCommandLookup('_FNG_MIDI_DN_OCT'), 0)
                numST = numST - 12

def rename_all_selected():
    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]

        if "T-" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = 0 - int(CurTRPstr.split("-")[1])
            TN = TN.replace(CurTRPstr, "T" + str(int(0 - xxxL[0]) + CurTRPnum))
        elif "T+" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("+")[1])
            NewNum = CurTRPnum + (0 - int(xxxL[0]))
            if NewNum > 0:
                TN = TN.replace(CurTRPstr, "T+" + str(NewNum))
            elif NewNum < 0:
                TN = TN.replace(CurTRPstr, "T" + str(NewNum))
            else:
                TN = TN.replace(CurTRPstr + " ", "")
        else:
            TN = 'T-' + str(int(xxxL[0])) + ' ' + TN

        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", TN, 1)
        
with undoable("Transpose selected MIDI items down by input"):
    DL = []
    dialog()
    xxxL = []

    if str(DL[0]) == (''):
        xxxL.append(1)
    else:
        xxxL.append(float(DL[0].strip('')))

    csmi = RPR_CountSelectedMediaItems(0)

    if csmi == 1:
        Transpose_MIDI_Items_Down()
    if csmi > 1:
        result = RPR_MB('Are you sure?', "More than one item selected", 1)
        if result == 1:
            Transpose_MIDI_Items_Down()

    rename_all_selected()

Last edited by FnA; 04-02-2014 at 11:11 AM.
FnA is offline   Reply With Quote
Old 04-02-2014, 04:20 PM   #31
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

the scripts working well here. I just removed the confirmation dialog when more than 1 item selected. I can combine this with the unselect NO_TRP script using custom actions by executing the unselect NO_TRP before the transpose and relabel script and all is perfect
And another custom action with the select all items in region first for another button to quickly transpose regions.

now... to be perfect... it would have to use this latest script for midi items(which actually move the notes, but does nothing on audio items), and the other(that change item's pitch) for audio items. I guess it wouldn't be very difficult to check it it is a midi item or an audio item and use one or the other function automatically.
heda is offline   Reply With Quote
Old 04-02-2014, 07:15 PM   #32
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

OK, give these a try then. Seems to be working.
Code:
###Transpose selected items down by input Relabel###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def dialog():
    names = "Number of Semitones:"
    defvalues = ","
    maxreturnlen = 20   # one more than what you expect to get back
    nitems = 1 # number of input boxes
    Query = RPR_GetUserInputs("Transpose Items Down",nitems,names,defvalues,maxreturnlen)

    if Query[0] == 1: # user clicked OK
        UserValues = Query[4].split(',')

        if UserValues[0] != []:
            UV = str(UserValues[0])
            DL.append(UV)

def Transpose_MIDI_Items_Down():
    numST = int(xxxL[0])
    while numST > 0:
        if numST < 12:
            RPR_Main_OnCommand(RPR_NamedCommandLookup('_FNG_MIDI_DN_SEMI'), 0)
            numST = numST - 1
        else:
            RPR_Main_OnCommand(RPR_NamedCommandLookup('_FNG_MIDI_DN_OCT'), 0)
            numST = numST - 12

def Transpose_Audio_Items_Down():
    numST = int(xxxL[0])
    while numST > 0:
        if numST < 12:
            RPR_Main_OnCommand(40205, 0)
            numST = numST - 1
        else:
            RPR_Main_OnCommand(40516, 0)
            numST = numST - 12

def rename_all_selected():
    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]

        if "T-" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = 0 - int(CurTRPstr.split("-")[1])
            TN = TN.replace(CurTRPstr, "T" + str(int(0 - xxxL[0]) + CurTRPnum))
        elif "T+" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("+")[1])
            NewNum = CurTRPnum + (0 - int(xxxL[0]))
            if NewNum > 0:
                TN = TN.replace(CurTRPstr, "T+" + str(NewNum))
            elif NewNum < 0:
                TN = TN.replace(CurTRPstr, "T" + str(NewNum))
            else:
                TN = TN.replace(CurTRPstr + " ", "")
        else:
            TN = 'T-' + str(int(xxxL[0])) + ' ' + TN

        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", TN, 1)

def transpose_all_selected_items_down():
    RPR_Main_OnCommand(40289, 0)#unselect all items

    while len(AudioL) >= 1:
        CurrItem = AudioL.pop()
        RPR_SetMediaItemSelected(CurrItem, 1)
    Transpose_Audio_Items_Down()
         
    RPR_Main_OnCommand(40289, 0)#unselect all items

    while len(MIDIL) >= 1:
        CurrItem = MIDIL.pop()
        RPR_SetMediaItemSelected(CurrItem, 1)
    Transpose_MIDI_Items_Down()

    while len(rsmiL) >= 1:
        CurrItem = rsmiL.pop()
        RPR_SetMediaItemSelected(CurrItem, 1)
        
with undoable("Transpose selected items down"):
    DL = []
    dialog()
    xxxL = []

    if str(DL[0]) == (''):
        xxxL.append(1)
    else:
        xxxL.append(float(DL[0].strip('')))

    AudioL = []
    MIDIL = []
    rsmiL = []

    csmi = RPR_CountSelectedMediaItems(0)
    for i in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, i)
        ActTake = RPR_GetActiveTake(CurrItem)
        Source = RPR_GetMediaItemTake_Source(ActTake)
        Type = RPR_GetMediaSourceType(Source, "", 5)
        if Type[1] == 'MIDI':
            MIDIL.append(CurrItem)
            rsmiL.append(CurrItem)
        else:
            AudioL.append(CurrItem)
            rsmiL.append(CurrItem)

    with noUIRefresh():
        transpose_all_selected_items_down()
        rename_all_selected()
Code:
###Transpose selected items up by input and Relabel###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)

def dialog():
    names = "Number of Semitones:"
    defvalues = ","
    maxreturnlen = 20   # one more than what you expect to get back
    nitems = 1 # number of input boxes
    Query = RPR_GetUserInputs("Transpose Items Up",nitems,names,defvalues,maxreturnlen)

    if Query[0] == 1: # user clicked OK
        UserValues = Query[4].split(',')

        if UserValues[0] != []:
            UV = str(UserValues[0])
            DL.append(UV)

def Transpose_MIDI_Items_Up():
    numST = int(xxxL[0])
    while numST > 0:
        if numST < 12:
            RPR_Main_OnCommand(RPR_NamedCommandLookup('_FNG_MIDI_UP_SEMI'), 0)
            numST = numST - 1
        else:
            RPR_Main_OnCommand(RPR_NamedCommandLookup('_FNG_MIDI_UP_OCT'), 0)
            numST = numST - 12

def Transpose_Audio_Items_Up():
    numST = int(xxxL[0])
    while numST > 0:
        if numST < 12:
            RPR_Main_OnCommand(40204, 0)
            numST = numST - 1
        else:
            RPR_Main_OnCommand(40515, 0)
            numST = numST - 12

def rename_all_selected():
    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]

        if "T+" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("+")[1])
            TN = TN.replace(CurTRPstr, "T+" + str(int(xxxL[0]) + CurTRPnum))
        elif "T-" in TN:
            CurTRPstr = TN.split()[0]
            CurTRPnum = int(CurTRPstr.split("-")[1])
            NewNum = 0 - CurTRPnum + int(xxxL[0])
            if NewNum > 0:
                TN = TN.replace(CurTRPstr, "T+" + str(NewNum))
            elif NewNum < 0:
                TN = TN.replace(CurTRPstr, "T" + str(NewNum))
            else:
                TN = TN.replace(CurTRPstr + " ", "")
        else:
            TN = 'T+' + str(int(xxxL[0])) + ' ' + TN

        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", TN, 1)
        
def transpose_all_selected_items_up():
    RPR_Main_OnCommand(40289, 0)#unselect all items

    while len(AudioL) >= 1:
        CurrItem = AudioL.pop()
        RPR_SetMediaItemSelected(CurrItem, 1)
    Transpose_Audio_Items_Up()
         
    RPR_Main_OnCommand(40289, 0)#unselect all items

    while len(MIDIL) >= 1:
        CurrItem = MIDIL.pop()
        RPR_SetMediaItemSelected(CurrItem, 1)
    Transpose_MIDI_Items_Up()

    while len(rsmiL) >= 1:
        CurrItem = rsmiL.pop()
        RPR_SetMediaItemSelected(CurrItem, 1)

with undoable("Transpose selected MIDI items up"):
    DL = []
    dialog()
    xxxL = []

    if str(DL[0]) == (''):
        xxxL.append(1)
    else:
        xxxL.append(float(DL[0].strip('')))

    AudioL = []
    MIDIL = []
    rsmiL = []

    csmi = RPR_CountSelectedMediaItems(0)
    for i in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, i)
        ActTake = RPR_GetActiveTake(CurrItem)
        Source = RPR_GetMediaItemTake_Source(ActTake)
        Type = RPR_GetMediaSourceType(Source, "", 5)
        if Type[1] == 'MIDI':
            MIDIL.append(CurrItem)
            rsmiL.append(CurrItem)
        else:
            AudioL.append(CurrItem)
            rsmiL.append(CurrItem)

    with noUIRefresh():
        transpose_all_selected_items_up()
        rename_all_selected()
FnA is offline   Reply With Quote
Old 04-03-2014, 02:47 AM   #33
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

Excellent!!




I have managed to do a script to Add/Remove NO_TRP prefix to selected items based on your scripts FnA Starting to learn! Look at the NO_TRP button in the gif.

Code:
### Add/remove NO_TRP to take name###
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def noUIRefresh():
    RPR_PreventUIRefresh(1)
    try:
        yield
    finally:
        RPR_PreventUIRefresh(-1)


def prepend_take_name():
    csmi = RPR_CountSelectedMediaItems(0)
    for c in range(csmi):
        CurrItem = RPR_GetSelectedMediaItem(0, c)
        CT = RPR_GetMediaItemInfo_Value(CurrItem, "I_CURTAKE")
        GT = RPR_GetTake(CurrItem, int(CT))
        TN = RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", "", 0)[3]

        if "(NO_TRP) " in TN:
            TN = TN.replace("(NO_TRP) ", "")
        else:
            TN = '(NO_TRP) ' + TN

        RPR_GetSetMediaItemTakeInfo_String(GT, "P_NAME", TN, 1)
        

with noUIRefresh():
    prepend_take_name()
Also attached two new toolbar icons for region transpose custom actions which are also attached as a ReaperKeyMap file. that can be imported in actions.
Attached Images
File Type: png toolbar_region_pitch_increase_semitone.png (599 Bytes, 122 views)
File Type: png toolbar_region_pitch_decrease_semitone.png (581 Bytes, 142 views)
Attached Files
File Type: reaperkeymap transpose region.ReaperKeyMap (336 Bytes, 61 views)
heda is offline   Reply With Quote
Old 04-05-2014, 02:07 AM   #34
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

today I just discovered a small error.. if you click cancel in the input dialog. script execution error: line 105, in <module> if str(DL[0]) == (''): IndexError: list index out of range

it is not very important This happened to me because I forgot to select items first and I had no items selected.. it should warn no items are selected instead of displaying the input dialog.. so I clicked cancel and then discovered the error.

I managed to do a variation of the script without input dialog, for 1 octave transposing directly.
heda is offline   Reply With Quote
Old 04-05-2014, 09:30 AM   #35
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Glad you're taking the plunge to learn scripting. I'm still in learn mode myself. Nice icons too.
FnA is offline   Reply With Quote
Old 04-05-2014, 11:27 AM   #36
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

Thanks. I don't know if I should learn EEL instead...
spk77 has translated one into EEL here http://forum.cockos.com/showpost.php...6&postcount=21
heda is offline   Reply With Quote
Old 05-12-2014, 12:34 PM   #37
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

I've got one problem using the transposing scripts today when using pooled MIDI items. I select all items including pooled MIDI items. The script should unselect all pooled items except one because all the other items will get transposed once one of them is modified. The script is doing it for each pooled item which get transposed several times instead of one because it affects to all of them on each iteration.

so I guess the easiest way to fix this would be to unselect pooled items before the transposing function. I have found the action select all other media items that share pooled MIDI source data. But I haven't found any action to unselect all pooled items except one of them. Maybe it is possible with scripting?
heda is offline   Reply With Quote
Old 02-05-2015, 04:12 PM   #38
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

I guess you could call these prereleases? They include pooled item handling. They rename all items sharing the pool. There's one line that can be commented out to limit it to selected only. They reselect what you had when you run the script, but I forgot about the no trp thing. It considers everything not in project MIDI to be "audio," meaning the pitch item action will be run on those items. I made a limit of 99 on the length of the take name. Transpose naming "maxes out" at 99 too. A large number of pooled items/pools will slow the script quite a bit, and to a lesser extent a large number of any selected items.


New scripts in post 55

Last edited by FnA; 02-11-2015 at 11:40 AM. Reason: new scripts post 55
FnA is offline   Reply With Quote
Old 02-05-2015, 05:06 PM   #39
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,605
Default

nice!! You did the EEL translation and integrated pooled item handling? It's nice that pooled items are also renamed. I'll check this out now. I think the NO_TRP feature is important. I am going to test it later.
heda is offline   Reply With Quote
Old 02-05-2015, 05:38 PM   #40
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

It shouldn't be too hard to put that in. Probably better to incorporate it in the script itself I suppose.
FnA 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 09:32 PM.


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