Old 06-05-2020, 03:42 PM   #1
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default Script slow to execute

So, I'm running this script that I made "it is part of another script that I'm making" but it is slow to select the MIDI track that it is under the time selection

It is supposed to :
1) Create a MIDI in selected track in Time selection
2) Select the MIDI in time selection ( I made a loop to achieve that, maybe a better way?)

Code:
function CreateMIDIandSelect()
time_sel_start, time_sel_end = reaper.GetSet_LoopTimeRange2( 0, false, false, 0, 0, false ) --get info about time sel
      if time_sel_start ~= time_sel_end then --if there is time sel do
      
      sel_track = reaper.GetSelectedTrack( 0, 0 ) -- get selected track
      reaper.CreateNewMIDIItemInProj( sel_track, time_sel_start, time_sel_end, false ) -- create a MIDI item
      reaper.Main_OnCommandEx(40289, 0 , 0)
      itemnumbers= reaper.CountTrackMediaItems( sel_track ) -- LOOP throught ITems in selected track BE CAREFULL TO NOT HAVE OTHER ITEM IN THE SAME POSITION AS THE CREATED MIDI
      
             for i=0,itemnumbers-1 do
             item=reaper.GetTrackMediaItem(sel_track,i)  
             
             item_pos=reaper.GetMediaItemInfo_Value(item, "D_POSITION")
            
             item_length=reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
              
                  if item_pos==time_sel_start and item_pos+item_length==time_sel_end then
               
                  reaper.SetMediaItemSelected(item,1)
                  
                   end
             end
             
             
             
        end 
end

PS: Solved missing UpdateArrange() srry the noob question

Last edited by daniellumertz; 06-05-2020 at 04:05 PM.
daniellumertz is offline   Reply With Quote
Old 06-05-2020, 04:05 PM   #2
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Code:
item = reaper.CreateNewMIDIItemInProj( sel_track, time_sel_start, time_sel_end, false )
reaper.SetMediaItemSelected(item,true)
No need to do all that...
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 06-05-2020, 04:39 PM   #3
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

ohhh of course thanks amagalma!!!
daniellumertz is offline   Reply With Quote
Old 06-07-2020, 03:36 AM   #4
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

No problem!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma 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 10:17 AM.


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