Old 05-11-2011, 07:26 PM   #1
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
Default Newbie Question Rename Marker

Hi all,
I'm just now trying to figure out a script. I don't have any programming knowledge, but I figured I would at least try with python. I'm trying to see if there is a way to batch rename markers to a Character #. One of the examples from the Reapers api on the wiki site shows AddProjectMarker

I can run this script to insert a marker with # as the name.
Code:
#
# AddProjectMarker.py
#
# AddProjectMarker(ReaProject* proj, bool isrgn, double pos, double rgnend, const char* name, int wantidx)
#------------------------------------------------------------------------------
CURR_PROJ = 0;
pos =  5;
isrgn = 0;
rgnend = 8;
name = "#";
wantidx = 0
retval = RPR_AddProjectMarker(CURR_PROJ, isrgn, pos, rgnend, name, wantidx);
RPR_UpdateTimeline()

#-------------------------------------------------------------------------------
Would it be possible to add multi markers in different positions, or at the beginning of items, or batch rename markers that's already in a project?

Just wondering if anyone could give me a few hints, or clues.
It would greatly be appreciated.
Thanks, Wyatt
__________________
DDP To Cue Writer. | DDP Marker Editor.
WyattRice is offline   Reply With Quote
Old 05-14-2011, 10:44 PM   #2
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
Default

I'm kinda looking for a way with the script above to insert a marker named # at cursor, or items start for the position. So is there a way to modify pos = cursor, or start of item? Sorry for such a noob question. Anyone?
__________________
DDP To Cue Writer. | DDP Marker Editor.
WyattRice is offline   Reply With Quote
Old 05-15-2011, 03:19 AM   #3
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by WyattRice View Post
I'm kinda looking for a way with the script above to insert a marker named # at cursor, or items start for the position. So is there a way to modify pos = cursor, or start of item? Sorry for such a noob question. Anyone?
I'd like to help but I can't test any code myself as ReaScript seems to be completely broken for me in Reaper 4 beta5...Actually I even just had a crash while trying to use ReaScript
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 05-15-2011, 07:04 AM   #4
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

You can get the cursor position using RPR_GetCursorPosition, so I think you could do

pos = RPR_GetCursorPosition()

instead of pos = 5 in that script of yours

I'm far from being fluent with scripts and bound to make the simplest of mistakes all the time, so I don't know if that's all there is to it. EDIT: but i got it right this time, works

For the item start, you need to set a pointer to the selected media item with RPR_GetSelectedMediaItem and then ask for the start time with RPR_GetMediaItemInfo_Value. To set your pos variable to the start of the leftmost selected item you'd replace pos = 5 with

Code:
ItemIndex = 0     # 0 is the first of the selected items
item = RPR_GetSelectedMediaItem(0, ItemIndex)   # sets the pointer
pos = RPR_GetMediaItemInfo_Value(item, "D_POSITION")
Again with no responsibility for correctness, take it as a starting point .

I highly recommend the ReaScript WIKI. Here is the page with all the API functions listed: http://wiki.cockos.com/wiki/index.php/ReaScript_API






EDIT: couldn't resist and checked the item start thing. Seems OK. Here is your script changed to set a marker at each selected item's start time:

Code:
#
# AddProjectMarker at selected item starts.py
#
# AddProjectMarker(ReaProject* proj, bool isrgn, double pos, double rgnend, const char* name, int wantidx)
#------------------------------------------------------------------------------
CURR_PROJ = 0;
pos =  0;
isrgn = 0;
rgnend = 8;
name = "#";
wantidx = 0

ItemIndex = 0
ItemCount = RPR_CountSelectedMediaItems(0)

while ItemCount > ItemIndex:
	item = RPR_GetSelectedMediaItem(0, ItemIndex)
	pos = RPR_GetMediaItemInfo_Value(item, "D_POSITION")

	retval = RPR_AddProjectMarker(CURR_PROJ, isrgn, pos, rgnend, name, wantidx);
	RPR_UpdateTimeline()
	ItemIndex +=1


#-------------------------------------------------------------------------------
All markers are called # still. You might want to do something with the name variable.

As you see, the batch part is basically done by counting the selected items and then go through them one by one in the "while" loop. Asking for the start time, adding the marker and then go to the next item by rising the item index by one, until item index is as high as the number of selected items. Which is where the "while" loop (and the script) ends (bringing the loop to an end is the reason why you did count the items in the first place).
Nice one. Quite sure I am going to build up on that, thanks for the idea .


I am pretty sure you could go a similar route for your batch renaming, using the functions
RPR_EnumProjectMarkers and
RPR_SetProjectMarker

Though the "enum" thing looks complicated and seems to return a list. Don't know how to handle these. Here is where my bit of wisdom ends .


@ Xenakios:
All my humble ReaScripts still work with beta5. From what I hear, Reaper has problems with Python v3.2, though, which fortunately isn't what I have . I think it's the same problems in Reaper v3.x.

Hope this gets sorted.

Last edited by gofer; 05-15-2011 at 07:48 AM.
gofer is offline   Reply With Quote
Old 05-15-2011, 10:57 AM   #5
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
Default

Thank you gofer! Much appreciated.

One more question, Would there be a way to have wantidx = 0 to change to the way normal markers are indexed, instead of all markers being 0?
Edit: From API: Supply wantidx>=0 if you want a particular index number, but you'll get a different index number a region and wantidx is already in use.
Many thanks, Wyatt

Edit: SWS already had renumber marker ids, so I added
Code:
RPR_Main_OnCommand(53083, 0)
So would it be correct to add that at the end of the script?
It works.

Code:
CURR_PROJ = 0;
pos =  0;
isrgn = 0;
rgnend = 8;
name = "#";
wantidx = 0

ItemIndex = 0
ItemCount = RPR_CountSelectedMediaItems(0)

while ItemCount > ItemIndex:
	item = RPR_GetSelectedMediaItem(0, ItemIndex)
	pos = RPR_GetMediaItemInfo_Value(item, "D_POSITION")

	retval = RPR_AddProjectMarker(CURR_PROJ, isrgn, pos, rgnend, name, wantidx);
	RPR_UpdateTimeline()
	ItemIndex +=1
RPR_Main_OnCommand(53083, 0)
__________________
DDP To Cue Writer. | DDP Marker Editor.

Last edited by WyattRice; 05-15-2011 at 12:11 PM. Reason: Edit
WyattRice is offline   Reply With Quote
Old 05-15-2011, 06:48 PM   #6
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

You're welcome, Wyatt .

When calling extension actions, you need to use another approach, because the Cmd ID numbers are given dynamically to non-internal actions. They may change when you update extensions and will not be the same on other computers (my "SWS renumber markers" is 53103). You need to use the long ID string from the Custom ID column (one column further right, _SWSMARKERLIST7 in this case) and the function RPR_NamedCommandLookup().

would look like this:

Code:
renumber_ID = RPR_NamedCommandLookup('_SWSMARKERLIST7')
RPR_Main_OnCommand(renumber_ID, 0)
... but in this case Reaper's internal action "Renumber all markers in timeline order" (40898) seems to do the same thing. So it's simply


RPR_Main_OnCommand (40898, 0)


.
gofer is offline   Reply With Quote
Old 05-16-2011, 05:06 PM   #7
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
Default

Many Many Thanks gofer!
__________________
DDP To Cue Writer. | DDP Marker Editor.
WyattRice is offline   Reply With Quote
Old 05-17-2011, 02:50 AM   #8
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

You're welcome
I'm only given back what I received from very nice and patient persons around here.

Gofer helping out in the dev forum instead of asking noob questions himself - that's progress .
gofer is offline   Reply With Quote
Old 06-05-2014, 08:39 PM   #9
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
Default

I was wondering if anyone could help me with trying to convert this to c++ ?

I want to get the active take name and name the marker with prefix "#" + the take name.

Code:
C: bool GetSetMediaItemTakeInfo_String(MediaItem_Take* tk, const char* parmname, char* stringNeedBig, bool setnewvalue)
Code:
C: int AddProjectMarker2(ReaProject* proj, bool isrgn, double pos, double rgnend, const char* name, int wantidx, int color)
Code:
item = GetSelectedMediaItem(0, 0); //gets the first selected item, so we can ask it for it's properties
double item_start = GetMediaItemInfo_Value(item, "D_POSITION");	// getting the current item's start time to calculate nudge amount and direction.
double item_length = GetMediaItemInfo_Value(item, "D_LENGTH");	// getting the current item's lenght to calculate the placement of the nexr item.
MediaItem_Take* active_take = GetActiveTake(item);
? = GetSetMediaItemTakeInfo_String(active_take, "P_NAME", name, 1);

ShowConsoleMsg(name);

AddProjectMarker2(0, 0, StartOfNext, 8, "#", 0 - 1, 0x0000FF|0x1000000); // Adds a "#" marker at cursor, and color is red
Many Thanks, Wyatt
__________________
DDP To Cue Writer. | DDP Marker Editor.

Last edited by WyattRice; 06-05-2014 at 08:44 PM.
WyattRice is offline   Reply With Quote
Old 06-06-2014, 08:36 PM   #10
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
Default

Here's what I'm trying to do. Here's the python script.
Code:
# Prepare Track 1 for CD
# Moves items on track 1 to conform with DDP export. First item will start at 2 seconds, each subsequent item will start with a 2 seconds intervall to the previous.
# Places markers with the suffix "#" and the active take name at each item start
# Previously existing markers will be deleted (might add prompt to save as SWS marker set).

RPR_Undo_BeginBlock()

#Remove all markers:
Marker = RPR_EnumProjectMarkers2(0, 0, 0, 0, 0, 0, 0)
IDX = Marker[0]
while IDX > 0:
	MarkIdx = Marker[7]  # gets the last (seventh) item of the return array, the marker index number
	RPR_DeleteProjectMarker( 0, MarkIdx, 0)
	Marker = RPR_EnumProjectMarkers2(0, 0, 0, 0, 0, 0, 0)
	IDX = Marker[0]

RPR_Main_OnCommand(40898, 0) # Was the only workaround I know so far to get the undo behave nice. Renumbers marker ids in order (of course there are none at this point). If I delete this line, Undo has to be hit twice to get to the previous state.

RPR_Main_OnCommand(41238, 0) # save selection set 10
RPR_Main_OnCommand(40289, 0) # unselects all items

# unselect all tracks, select the first track.	Just for convenience. Not necessary to make the script work:
TrackCount = RPR_CountTracks(0)
TrackIndex = 0
while TrackIndex < TrackCount:
	track = RPR_GetTrack(0, TrackIndex)
	RPR_SetTrackSelected(track, 0)
	TrackIndex += 1
	
TrackOne = RPR_GetTrack(0, 0) #The left 0 is "current project" (not clear on this), the right 0 means "the track with the lowest track number (track 1)"
RPR_SetTrackSelected(TrackOne, 1)

ItemCount = RPR_CountTrackMediaItems(TrackOne)
StartOfNext = 2 # first item shall start on 2 seconds in.
ItemIndex = 0
ItemNumber = 0
CurrentItem = 0

item = RPR_GetMediaItem(0, ItemIndex)
RPR_SetMediaItemInfo_Value(item, "B_UISEL", 1)   # "physically" selects the first of the items.

while ItemIndex < ItemCount:
	while ItemNumber < ItemIndex:  # this small inner loop does the "select 1st, 2nd, 3rd ... part. With each iteration of the outer loop, this loop will run through one more time - resulting in one item further right to be the selected one.
		RPR_SetMediaItemInfo_Value(item, "B_UISEL", 0)
		item = RPR_GetMediaItem(0, ItemNumber + 1)
		RPR_SetMediaItemInfo_Value(item, "B_UISEL", 1)
		ItemNumber += 1
	
# select all following items, so they will get nudged all together in the "apply nudge" step:
	while CurrentItem < ItemCount - 1:
		item = RPR_GetMediaItem(0, CurrentItem + 1)
		RPR_SetMediaItemInfo_Value(item, "B_UISEL", 1)	
		CurrentItem += 1

	item = RPR_GetSelectedMediaItem(0, 0) # gets the first selected item, so we can ask it for it's properties
	item_start = RPR_GetMediaItemInfo_Value(item, "D_POSITION")	# getting the current item's start time to calculate nudge amount and direction.
	item_length = RPR_GetMediaItemInfo_Value(item, "D_LENGTH")	# getting the current item's lenght to calculate the placement of the nexr item.
	active_take = RPR_GetActiveTake(item) # pointer to active take
	take_name = RPR_GetSetMediaItemTakeInfo_String(active_take, "P_NAME", "", False)[3] # gets name of active take
	marker_name = "# " + take_name # prefixes the take's name with "#". This will be the name of our "#" markers
	if StartOfNext < item_start:  # finds the relation of actual item start and the desired position
		RPR_ApplyNudge(0, 0, 0, 1, item_start - StartOfNext, 1, 0)	# nudges all selected items leftward, so the first selected item starts at the desired (StartOfNext) position.
	else:
		RPR_ApplyNudge(0, 0, 0, 1, StartOfNext - item_start, 0, 0)  # nudges all selected items rightward, so the first selected item starts at the desired (StartOfNext) position.

	RPR_AddProjectMarker(0, 0, StartOfNext, 8, marker_name, ItemNumber + 1) # puts "#" marker at item start.
	StartOfNext = StartOfNext + item_length +2  # prepares desired item start for the next loop iteration.
	ItemIndex +=1 
	
RPR_Main_OnCommand(41248, 0) # load selection set 10	
RPR_UpdateTimeline()
RPR_Undo_EndBlock("Prepare track 1 for CD burning",0)
Just trying to figure out how to get the string name out of this for c code.
Code:
take_name = RPR_GetSetMediaItemTakeInfo_String(active_take, "P_NAME", "", False)[3] # gets name of active take
marker_name = "# " + take_name # prefixes the take's name with "#". This will be the name of our "#" markers
Could anyone give me a hint or snippet?
Thanks,Wyatt
__________________
DDP To Cue Writer. | DDP Marker Editor.
WyattRice is offline   Reply With Quote
Old 06-09-2014, 04:10 PM   #11
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Believe it or not, this isn't entirely simple! It would require some experimenting to see which way is the correct one... Raw C "strings" are not the nicest things in the universe to deal with. There's always the danger of a memory leak and/or undefined behavior. (I've had both when using the Reaper API, it's not always clear how Reaper handles the C "strings".)

I'll try to see in the coming days to see about a likely correct solution, if someone else doesn't provide an answer they believe is right in the mean time.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 06-09-2014, 10:16 PM   #12
WyattRice
Human being with feelings
 
WyattRice's Avatar
 
Join Date: Sep 2009
Location: Virginia
Posts: 2,068
Default

Thanks for replying.
Here's a old snippet that was actually yours.
Would something like this work?
Code:
char *TakeName=(char*)GetSetMediaItemTakeInfo(active_take,"P_NAME",NULL);
		std::string mName ="# ";            
		mName +=TakeName;
		int lastindex = mName.find_last_of("."); 
		std::string rawname = mName.substr(0, lastindex);
then
Code:
AddProjectMarker2(0, 0, StartOfNext, 8, rawname.c_str(), 0 - 1, 0x0000FF|0x1000000);
Thanks,Wyatt
__________________
DDP To Cue Writer. | DDP Marker Editor.
WyattRice is offline   Reply With Quote
Old 06-10-2014, 03:25 AM   #13
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by WyattRice View Post
Thanks for replying.
Here's a old snippet that was actually yours.
Would something like this work?
Code:
char *TakeName=(char*)GetSetMediaItemTakeInfo(active_take,"P_NAME",NULL);
		std::string mName ="# ";            
		mName +=TakeName;
		int lastindex = mName.find_last_of("."); 
		std::string rawname = mName.substr(0, lastindex);
then
Code:
AddProjectMarker2(0, 0, StartOfNext, 8, rawname.c_str(), 0 - 1, 0x0000FF|0x1000000);
Thanks,Wyatt
Well, I probably would have ended up suggesting something like that. If it compiles and runs, I guess it can be assumed it works...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios 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 05:00 AM.


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