RPR Undo OnStateChangeEx2
From CockosWiki
(→Examples) |
(→C++) |
||
Line 14: | Line 14: | ||
==Examples== | ==Examples== | ||
===C++=== | ===C++=== | ||
- | <source lang=cpp> | + | <source lang=cpp highlight="35"> |
+ | 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(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
</source> | </source> | ||
- | |||
===Perl=== | ===Perl=== |
Latest revision as of 20:02, 29 January 2010
Main Page > REAPER Documentation > ReaScript > ReaScript API, Functions > RPR Undo OnStateChangeEx2
Main Page > REAPER Documentation > REAPER API > REAPER API Functions > RPR Undo OnStateChangeEx2
Contents |
OnStateChangeEx2()
void Undo_OnStateChangeEx(const char* descchange, int whichStates, int trackparm) deprecated
void Undo_OnStateChangeEx2(void* proj, const char* descchange, int whichStates, int trackparm)
trackparm=-1 by default,or if updating one fx chain,you can specify track index
Parameters
void* proj, const char* descchange, int whichStates, int trackparm
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
Python
See Also
undo: Undo_BeginBlock, Undo_BeginBlock2, Undo_CanRedo2, Undo_CanUndo2, Undo_DoRedo2, Undo_DoUndo2, Undo_EndBlock, Undo_EndBlock2, Undo_OnStateChange, Undo_OnStateChange2, Undo_OnStateChangeEx, Undo_OnStateChangeEx2, Undo_OnStateChange_Item, CSurf_FlushUndo,
(Section automatically generated, edits above this line may be overwritten.)
Stuff
Main Page > REAPER Documentation > ReaScript > ReaScript API, Functions > RPR Undo OnStateChangeEx2
Main Page > REAPER Documentation > REAPER API > REAPER API Functions > RPR Undo OnStateChangeEx2