RPR Main OnCommandEx

From CockosWiki

(Redirected from RPR Main OnCommand)
Jump to: navigation, search

Main Page > REAPER Documentation > ReaScript > ReaScript API, Functions > RPR Main OnCommandEx
Main Page > REAPER Documentation > REAPER API > REAPER API Functions > RPR Main OnCommandEx

Contents

Main_OnCommandEx()

void Main_OnCommandEx(int command, int flag, void* proj)

You can call any REAPER action from ReaScript by using this API function.

e.g. RPR_Main_OnCommand(actionnumber, 0)

Find the action number for a given action by opening the Actions list, scroll the window right to show the action numbers. For example, from ReaScript you can call the REAPER action "Item: Split item under mouse cursor", like this:

RPR_Main_OnCommand(40746, 0)

This and the RPR_MIDIEditor functions are the APIs you need to start with if you're going to use ReaScript as an advanced macro language.

Parameters

int command,
int flag,
void* proj

Returns

void 

Examples

C++

void DoInsRndFileEx(bool RndLen,bool RndOffset,bool UseTimeSel)
{
	if (g_filenames->GetSize()>0)
	{
		int filenameindex=rand() % g_filenames->GetSize();
 
		t_vect_of_Reaper_tracks TheTracks;
		XenGetProjectTracks(TheTracks,true);
		if (TheTracks.size()>0)
		{
		PCM_source *NewPCM=PCM_Source_CreateFromFile(g_filenames->Get(filenameindex));
		MediaItem *NewItem=AddMediaItemToTrack(TheTracks[0]);
		MediaItem_Take *NewTake=AddTakeToMediaItem(NewItem);
		double TimeSelStart=0.0;
		double TimeSelEnd=NewPCM->GetLength();
		GetSet_LoopTimeRange(false,false,&TimeSelStart,&TimeSelEnd,false);
		double ItemPos=TimeSelStart;
		double ItemLen=NewPCM->GetLength();
		double MediaOffset=0.0;
		if (RndOffset) 
		{
			MediaOffset=(NewPCM->GetLength()/RAND_MAX)*rand();
			ItemLen-=MediaOffset;
		}
		if (RndLen) ItemLen=((NewPCM->GetLength()-MediaOffset)/RAND_MAX)*rand();
		if (UseTimeSel) ItemLen=TimeSelEnd-TimeSelStart;
		if (!UseTimeSel) ItemPos=GetCursorPosition();
		GetSetMediaItemTakeInfo(NewTake,"P_SOURCE",NewPCM);
		GetSetMediaItemTakeInfo(NewTake,"D_STARTOFFS",&MediaOffset);
 
		GetSetMediaItemInfo(NewItem,"D_POSITION",&ItemPos);
		GetSetMediaItemInfo(NewItem,"D_LENGTH",&ItemLen);
		Main_OnCommand(40047,0); // build any missing peaks		SetEditCurPos(ItemPos+ItemLen,false,false);
		Undo_OnStateChangeEx("Insert random file (Extended)",4,-1);
 
		UpdateTimeline();
		}
	}	
}

Perl

#
# First.pl
#
 
# simulate pressing the play button in the current project
RPR_Main_OnCommand(1007,0);


Python

import warnings; 
 
SWS_ITEM_COLOR_1 = 53301 
SWS_TRACK_COLOR_1 = 53275 
selTracks =RPR_CountSelectedTracks(0) 
selItems = RPR_CountSelectedMediaItems(0) 
 
if (selTracks>0 and selItems==0): 
  RPR_Main_OnCommand(SWS_TRACK_COLOR_1, 0) 
if (selTracks==0 and selItems>0): 
  RPR_Main_OnCommand(SWS_ITEM_COLOR_1, 0) 
if (selTracks>0 and selItems>0): 
  RPR_Main_OnCommand(SWS_ITEM_COLOR_1, 0) 
  RPR_Main_OnCommand(SWS_TRACK_COLOR_1, 0)

See Also

oncommand: Main_OnCommand, Main_OnCommandEx, MIDIEditor_OnCommand, NamedCommandLookup

(Section automatically generated, edits may be overwritten.)

Stuff

Main Page > REAPER Documentation > ReaScript > ReaScript API, Functions > RPR Main OnCommandEx
Main Page > REAPER Documentation > REAPER API > REAPER API Functions > RPR Main OnCommandEx

Personal tools