Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 04-23-2020, 01:21 PM   #1
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 43
Default [6.08] SplitMediaItem() seems buggy [SOLVED, not a bug]

Hello there !
I encounter a strange behavior with the SplitMediaItem() function from the API.
I have the following code :
Code:
local selItem = reaper.CountSelectedMediaItems(0)
local position =  reaper.GetCursorPosition()

for i = 0, selItem-1 do
	local item = reaper.GetSelectedMediaItem( 0, i )
	local newItem = reaper.SplitMediaItem( item, position )
end
If I run it with 2 selected items, it only split the first one.
If I run it with 3, it only split the two first ones.

Obviously, I'd like to have all my selected items splited.

Am I doing something wrong here ?

Last edited by JLP; 04-24-2020 at 11:47 AM.
JLP is offline   Reply With Quote
Old 04-23-2020, 02:27 PM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

I think its because as you split the items you are changing the number of the items and messing up the loop indexer. Looping backwards should do the trick,..

Code:
for i = selItem-1, 0, -1 do
  local item = reaper.GetSelectedMediaItem( 0, i )
  local newItem = reaper.SplitMediaItem( item, position )
end
Edgemeal is offline   Reply With Quote
Old 04-23-2020, 11:51 PM   #3
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 43
Default

Thank you, it works !
Feel a bit stupid about it, but well, at least a problem is solved
Should I delete my post or maybe move it to a more appropriate place ?
JLP is offline   Reply With Quote
Old 04-24-2020, 01:57 AM   #4
akademie
Human being with feelings
 
Join Date: Mar 2007
Posts: 3,978
Default

Quote:
Originally Posted by JLP View Post
Thank you, it works !
Feel a bit stupid about it, but well, at least a problem is solved
Should I delete my post or maybe move it to a more appropriate place ?
JLP, please, do not delete the thread, as the question and answer may be helpful for others, instead put [SOLVED, not a bug] at the end of the title of the thread.
Thanks.
akademie 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 06:57 AM.


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