|
|
|
12-23-2018, 06:53 AM
|
#1
|
Human being with feelings
Join Date: Apr 2018
Posts: 33
|
Reascript works on Windows, but not OSX
I've got a lua script that inserts media from a table. I'm reading over text file for file names to grab from a folder, and looping over the table with a repeat loop to put the file names in the table. That's what the f:read is for.
On PC the script works great, but on OSX (10.14.2) it only partially works. On OSX it'll only insert the last filename in the table. So, it seems that the loop isn't iterating fully or correctly.
Has anyone run into this before? Is there a way for me to loop through a table that's more reliable for OSX? The table is being created in the same loop that the media insertion is occurring...maybe I should insert the media in a separate loop after the table is fully iterated?
Thoughts welcome.
Code:
repeat -- Loop 1. This loop gets all file names, and closes the file.
s = f:read ("*l") -- S is a filename. Read one line. *l returns contents of line
if s then -- If s is true (not nill)
file_names_table[x] = s -- New entry. Key = "x" and Value = "s"
x = x + 1 -- Increment array index
reaper.InsertMedia(formattedPath..s, 0)
end
until not s
Last edited by Shreebz; 12-23-2018 at 07:01 AM.
|
|
|
12-24-2018, 08:56 AM
|
#2
|
Human being with feelings
Join Date: Dec 2014
Posts: 371
|
Have you tried debugging by adding logs, counters or some such to get a better understanding what’s actually happening?
|
|
|
12-24-2018, 01:43 PM
|
#4
|
Human being with feelings
Join Date: Apr 2018
Posts: 33
|
I use logs, and the loop cycles how I'd expect according to them. I think it's a bug with the InsertMedia() function being in a loop. I actually broke this out into two loops. One loop to create the table needed, and a second loop that only inserts the media. Same result.
Can anyone confirm that the InsertMedia() function doesn't iterate correctly when called in a loop?
|
|
|
12-24-2018, 01:46 PM
|
#5
|
Human being with feelings
Join Date: Apr 2018
Posts: 33
|
Quote:
Originally Posted by mespotine
|
That's a good tip, thank you for it, but doesn't address the core issue I'm having. If I rewrite this, then I will do it with that scheme.
|
|
|
12-24-2018, 04:44 PM
|
#7
|
Human being with feelings
Join Date: Dec 2014
Posts: 371
|
I wonder if it has something to do with Windows vs. Mac newlines when reading the file (\r\n vs. \n) ?
|
|
|
12-25-2018, 09:12 AM
|
#8
|
Human being with feelings
Join Date: Apr 2018
Posts: 33
|
Quote:
Originally Posted by preferred.nomenclature
I wonder if it has something to do with Windows vs. Mac newlines when reading the file (\r\n vs. \n) ?
|
I think you're right. The files are added to the project bay, but when I right-click an unavailable file and select "rename" there is an extra return carriage in the name. I bet this is causing the issue, and also explains why only the last item in the list is properly imported as the last item has no return carriage below it.
That being said, do you have an idea on how I could make sure this works properly on OSX? Like I said earlier, it works well on Windows.
|
|
|
12-25-2018, 09:55 AM
|
#9
|
Human being with feelings
Join Date: Dec 2014
Posts: 371
|
I’m just getting into Lua myself but surely there’s a way to find and replace “\r” with “” in yor parsed filename before adding it to your table?
|
|
|
12-25-2018, 01:32 PM
|
#10
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
If this is the case, you need to check for
\r\n
on windows and for
\n
on Mac.
Do you use the same file with filenames on Mac and Windows? Or do you create them individually on each system?
The latter case should(tm) be taken care of by the for line-loop, I posted to you earlier.
If its the former, I haven't an idea.
You should output into the ReaScript-Console all filenames returned from the file. If it's missing one or more, then its a hint to the new-line-problem.
Could you post also the file with the filenames you used in both scripts, that caused the problem on Mac?
|
|
|
12-25-2018, 01:35 PM
|
#11
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Quote:
Originally Posted by preferred.nomenclature
I’m just getting into Lua myself but surely there’s a way to find and replace “\r” with “” in yor parsed filename before adding it to your table?
|
Yes, something like:
Code:
filestring=string.gsub(filestring, "\r", "")
|
|
|
12-26-2018, 09:26 AM
|
#12
|
Human being with feelings
Join Date: Apr 2018
Posts: 33
|
Quote:
Originally Posted by mespotine
If this is the case, you need to check for
\r\n
on windows and for
\n
on Mac.
Do you use the same file with filenames on Mac and Windows? Or do you create them individually on each system?
The latter case should(tm) be taken care of by the for line-loop, I posted to you earlier.
If its the former, I haven't an idea.
You should output into the ReaScript-Console all filenames returned from the file. If it's missing one or more, then its a hint to the new-line-problem.
Could you post also the file with the filenames you used in both scripts, that caused the problem on Mac?
|
So, that line loop should, by default, format the filename list to be the way that's needed here? It won't require further string manipulation for different operating systems?
It sounds like I need to rewrite this with your recommended scheme, and that'll solve it. I'll do that.
Thanks for the tips.
Last edited by Shreebz; 12-26-2018 at 10:27 AM.
|
|
|
12-27-2018, 12:26 PM
|
#13
|
Human being with feelings
Join Date: Apr 2018
Posts: 33
|
Thanks for the help here. I finally got it working on both operating systems.
The file:lines() function worked well, but didn't remove the return carriage by default. So, I rewrote the script for naught, as I had to format the return carriage in each line's string anyway. No big deal, though. I'm pretty green, so this was good refactoring experience, and it's good to know what's more efficient. Thanks for the tips.
My stretch goal with this is to create some kind of error logging. Write a text file to the project directory that shows the files that weren't copied...not sure on how to do this just yet.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 03:19 PM.
|