Old 04-09-2014, 01:44 PM   #1
AbstractDissonance
Human being with feelings
 
Join Date: Mar 2014
Posts: 70
Default Timing script

Here's a script I came up with to help get the time of things.

It prints out something like:

Length Of Time Selection
Samples - 547200
Seconds - 5.700
h:m:s:f - 0:00:05:16
Measures:Beats - 19.1.00
Time - 0:05.700

Length Of Loop Selection
Samples - 3542400
Seconds - 36.900
h:m:s:f - 0:00:36:20
Measures:Beats - 123.1.00
Time - 0:36.900

It was hacked together from very minimal things I found online(there doesn't seem to be very good scripting docs for reaper?).

If anyone can improve please do so, I'm just posting this for prosperity.


Code:
from reaper_python import *
import re, string, sys 

undoBeginBock = lambda : RPR_Undo_BeginBlock2(0)
undoEndBlock = lambda name : RPR_Undo_EndBlock2(0, name, -1)

# Selection commands
unselectAllItems = lambda : RPR_Main_OnCommand(40297, 0) #Unselect all items
selectChildren = lambda : RPR_Main_OnCommand(RPR_NamedCommandLookup("_SWS_SELCHILDREN2"), 0) #Select children of selected folder track(s)
selectOnlyChildren = lambda : RPR_Main_OnCommand(RPR_NamedCommandLookup("_SWS_SELCHILDREN"), 0) #Select only children of selected folders
saveTrackSelection = lambda : RPR_Main_OnCommand(RPR_NamedCommandLookup("_SWS_SAVESEL"), 0) #Save current track selection
restoreTrackSelection = lambda : RPR_Main_OnCommand(RPR_NamedCommandLookup("_SWS_RESTORESEL"), 0) #Restore saved track selection


def msg(m):
    RPR_ShowConsoleMsg(m)

def timeSelLengthInSamples():    
    timeSelLength = RPR_GetSet_LoopTimeRange2(0, 0, 0, 0, 0, 0)[4] - RPR_GetSet_LoopTimeRange2(0, 0, 0, 0, 0, 0)[3]

    """time formatting mode overrides: -1=proj default.
    0=time
    1=measures.beats + time
    2=measures.beats
    3=seconds
    4=samples
    5=h:m:s:f

    void format_timestr_pos(double tpos, char* buf, int buflen, int modeoverride)"""
    # if time selection = 0.5s, sample rate = 44100, buflen = 20, modeoverride = 4, it would return (0.5, '22050', 20, 4)
    # RPR_format_timestr_pos(...)[1] would be 22050
    timeSelInSamples = RPR_format_timestr_pos(timeSelLength, "", 20, 4)[1]
    timeSelInSeconds = RPR_format_timestr_pos(timeSelLength, "", 20, 3)[1]
    timeSelInHMSF = RPR_format_timestr_pos(timeSelLength, "", 20, 5)[1]
    timeSelInMB = RPR_format_timestr_pos(timeSelLength, "", 20, 2)[1]
    X = RPR_format_timestr_pos(timeSelLength, "", 20, 0)[1]
    msg("Length Of Time Selection\n")	
    msg("Samples - " + timeSelInSamples + "\n")
    msg("Seconds - " + timeSelInSeconds + "\n")
    msg("h:m:s:f - " + timeSelInHMSF + "\n")
    msg("Measures:Beats - " + timeSelInMB + "\n")
    msg("Time - " + X + "\n")

def loopSelLengthInSamples():    
    timeSelLength = RPR_GetSet_LoopTimeRange(0, 1, 0, 0, 0)[3] - RPR_GetSet_LoopTimeRange(0, 1, 0, 0, 0)[2]

    """time formatting mode overrides: -1=proj default.
    0=time
    1=measures.beats + time
    2=measures.beats
    3=seconds
    4=samples
    5=h:m:s:f

    void format_timestr_pos(double tpos, char* buf, int buflen, int modeoverride)"""
    # if time selection = 0.5s, sample rate = 44100, buflen = 20, modeoverride = 4, it would return (0.5, '22050', 20, 4)
    # RPR_format_timestr_pos(...)[1] would be 22050
    timeSelInSamples = RPR_format_timestr_pos(timeSelLength, "", 20, 4)[1]
    timeSelInSeconds = RPR_format_timestr_pos(timeSelLength, "", 20, 3)[1]
    timeSelInHMSF = RPR_format_timestr_pos(timeSelLength, "", 20, 5)[1]
    timeSelInMB = RPR_format_timestr_pos(timeSelLength, "", 20, 2)[1]
    X = RPR_format_timestr_pos(timeSelLength, "", 20, 0)[1]
    msg("Length Of Loop Selection\n")	
    msg("Samples - " + timeSelInSamples + "\n")
    msg("Seconds - " + timeSelInSeconds + "\n")
    msg("h:m:s:f - " + timeSelInHMSF + "\n")
    msg("Measures:Beats - " + timeSelInMB + "\n")
    msg("Time - " + X)

timeSelLengthInSamples()
msg("\n");
loopSelLengthInSamples()
AbstractDissonance 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 12:20 AM.


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