Old 01-13-2016, 12:53 AM   #1
Selim Achour
Human being with feelings
 
Join Date: Jan 2016
Location: Tunis, Tunisia
Posts: 8
Default How to use PCM_Source_Destroy ?

Hi to all,

I'm create an action to be able to right click an item and "Delete the item and the Audio File associated with it".

For that I created the lua script below that removes the item then deletes the pcm source it links to.

The problem is that as soon as I call reaper.PCM_Source_Destroy(), reaper crashes.

Any one knows if it's a bug or if I'm missing something ?

Thnax

PS: Also, deleting the item only does not refresh the TCP (that has to be a bug)

-----------------------------------------------------

mediaItem = reaper.GetSelectedMediaItem(0, 0);

if (nil == mediaItem) then

reaper.ShowMessageBox('Please select an Item', 'Hum ...', 0);

else

take = reaper.GetActiveTake(mediaItem);
pcmSource = reaper.GetMediaItemTake_Source(take);
fileName = reaper.GetMediaSourceFileName(pcmSource, '');

msg = 'You\'re about to delete these files from the Hard Drive :\n';
msg = msg .. ' - ' .. fileName .. '\n';

-- todo: more than one item selected ?

if (1 == reaper.ShowMessageBox(msg, 'Warning !!!', 1)) then

mediaTrack = reaper.GetMediaItem_Track(mediaItem);

reaper.DeleteTrackMediaItem(mediaTrack, mediaItem)
--os.remove(fileName);
--reaper.PCM_Source_Destroy(pcmSource);

end

end
Selim Achour is offline   Reply With Quote
Old 01-13-2016, 01:43 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

When you delete an item, the associated PCM_source is also deleted, so you must not delete it yourself.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-13-2016, 06:09 AM   #3
Selim Achour
Human being with feelings
 
Join Date: Jan 2016
Location: Tunis, Tunisia
Posts: 8
Default

Actually no, the file is kept.

Steps to reproduce :
1. Create a session
2. Record some audio
3. Delete the item
4. Save the session

Look and you'll see the audio file is still there on the hard drive.
Selim Achour is offline   Reply With Quote
Old 01-13-2016, 08:02 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by Selim Achour View Post
Actually no, the file is kept.

Steps to reproduce :
1. Create a session
2. Record some audio
3. Delete the item
4. Save the session

Look and you'll see the audio file is still there on the hard drive.
Yes, the file is kept because the item/take and the PCM_source is just a way to refer to the file, it's not the file itself on disk.

So in principle, to be able to delete a media item along with its audio file, you should just do :

1) Get the PCM_source of the item's take and store the file name referred to
2) Delete/remove media item
3) Delete the audio file on disk using the operating system file delete function using the file name retrieved in step 1.

So this is like your original code, except PCM_Source_Destroy isn't called because it's not needed and is in fact going to cause a bug.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-13-2016, 08:48 AM   #5
Selim Achour
Human being with feelings
 
Join Date: Jan 2016
Location: Tunis, Tunisia
Posts: 8
Default

Thank you Xenakios.

It's so weired I thought I'd tried the os.remove without success before moving on to destroy.

It's working now.

Any idea or how to force refresh the edit window. The media item is left there but if I scroll a bit it disappears.
Selim Achour is offline   Reply With Quote
Old 01-13-2016, 09:17 AM   #6
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by Selim Achour View Post

Any idea or how to force refresh the edit window. The media item is left there but if I scroll a bit it disappears.
Use the UpdateArrange function.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-13-2016, 09:25 AM   #7
Selim Achour
Human being with feelings
 
Join Date: Jan 2016
Location: Tunis, Tunisia
Posts: 8
Default

Xenakios you're the man.

Thank you
Selim Achour 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:33 AM.


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