Old 11-06-2014, 06:35 PM   #1
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default How do you write to file with EEL?

I am using fprintf but keep getting error:

Code:
fprintf(): file handle 2000031.000000 not valid
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 11-11-2014, 12:34 AM   #2
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

bumpity
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 11-11-2014, 01:26 AM   #3
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

Have you opened the file for writing?


>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is offline   Reply With Quote
Old 11-11-2014, 07:13 PM   #4
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

Code:
file1 = fopen("D:\\Desktop\\eeltext.txt","w");
file2 = fopen("D:\\Desktop\\eeltext2.txt","w");

msg(sprintf(#,"file1 = %i\n\n",file1));
msg(sprintf(#,"file2 = %i\n\n",file2));

fwrite(file1,"this is file 1",100);
fwrite(file2,"this is file 2",100);
produces:

Code:
file1 = 1000000

file2 = 1000001
why? what are these numbers? I guess the only logical explanation is that there's some kind of "open file array" and those numbers represent the spot in the array that stores the file path.

Is there any way to check if file is write protected? Will fopen return non-integer if it is write protected or does not exist?
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-11-2014 at 08:09 PM.
Argitoth is offline   Reply With Quote
Old 11-11-2014, 07:30 PM   #5
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

What's the easiest way to append to file? fwrite and fprintf both overwrite the file.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 11-12-2014, 01:18 AM   #6
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

Read or locate to the end.


Edit: look at functions such as: fgetc, fgetp, fread, fseek, ftell, feof.

How you read and write depends on whether you open the file for "write" (w) or "write binary" (wb).

I think fseek(fp, 0, 1) or fseek(fp, 1, 1) is the quickest way, but fgetc(fp) will return -1 if you're there to confirm it, or feof(fp) will return nonzero.

Hope this helps...



>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.

Last edited by planetnine; 11-12-2014 at 03:02 AM.
planetnine is offline   Reply With Quote
Old 11-25-2014, 10:49 PM   #7
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

Thanks that helped! How would you remove characters from a file? e.g. the last two characters of the file.

Edit: It seems like as soon as I use
Code:
f = fopen("D:\\Desktop\\filelist.txt","w");
all text in file is erased... waaaat?!?!?!

Edit: The character limit of a string is 16256... so I can't read the whole file into a string to "save" it before writing.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-26-2014 at 09:03 AM.
Argitoth is offline   Reply With Quote
Old 11-26-2014, 12:34 AM   #8
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

why does the API say w,wb,r,rb are the only options? reascript guide lying again!

It fails to warn that "w mode truncates file to 0"! That's like... really useful to know.

I read about possible modes here: http://php.net/manual/en/function.fopen.php

"a" seems to work.
Edit: "w+" seems to work

I bet the rest of those modes work too.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 11-26-2014, 02:00 AM   #9
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

Quote:
Originally Posted by Argitoth View Post
Thanks that helped! How would you remove characters from a file? e.g. the last two characters of the file.

Edit: It seems like as soon as I use
Code:
f = fopen("D:\\Desktop\\filelist.txt","w");
all text in file is erased... waaaat?!?!?!

Edit: The character limit is 16252 or something... so I can't read the whole file into a string to "save" it before writing.

I've not got myself into that situation yet, so thanks for the warning, but I can only suggest reading the thing in chunks and writing to the only thing better than a large string -another data file


I wonder if there's a way of truncating or re-setting the eof? I can't see anything looking through.





>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is offline   Reply With Quote
Old 11-26-2014, 10:17 AM   #10
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

I've tried everything, seeking to end of file -1 and adding a null character (they show up as "NULL" characters in text editor), overwriting some text near the end (problem is the length of the file is not changed so you are left with extra characters in replace of the one you want to get rid of).
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 11-26-2014, 11:43 AM   #11
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

Code:
r = read   seek to beginning  create    if file not exist
x = write  seek to beginning  fail      if file exist
c = write  seek to beginning  create    if file not exist
w = write  seek to beginning  overwrite if file exist
a = write  seek to end        create    if file not exist

+ = modifier for read/write, e.g. "a+"
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-26-2014 at 02:01 PM.
Argitoth is offline   Reply With Quote
Old 11-26-2014, 12:17 PM   #12
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

Is the datafille format pre-existing, or your own?

Reserve some bytes at the beginning to store the data length. That's what wav files do -each chunk has a 4-byte descriptor and chunk length, and the file length is stored in the first chunk.

Is there an eof character? I suppose not in a binary file. Sorry, don't now how to force it, I've only ever read, created or added-to files.


>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is offline   Reply With Quote
Old 11-26-2014, 01:04 PM   #13
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

no such thing as EOF character.

btw, when reading a file by line (fgets reads the file per line) you get the \n at the in the string, so you need to do a match for "%S\n" to remove it.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-26-2014 at 01:23 PM.
Argitoth is offline   Reply With Quote
Old 11-26-2014, 01:38 PM   #14
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

Quote:
Originally Posted by planetnine View Post
Is the datafille format pre-existing, or your own?
not my own, see post: http://forum.cockos.com/showthread.p...02&postcount=8
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 11-26-2014, 02:15 PM   #15
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

it looks like fgets fails if there's no newline at the end...... sucks. I tried reading char at end of file and adding "\n" if it is needed, after doing so, the file gets converted to binary (I'm using r+ mode for read/write). I tried c+ mode but that just crashes REAPER.

I GIVE UP! EEL is ok for writing files (that 16256 string char limit is annoying), but when it comes to reading/editing, better just stick to python.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-26-2014 at 02:31 PM.
Argitoth is offline   Reply With Quote
Old 11-26-2014, 02:52 PM   #16
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

I think the procedure is to write a new one as you read the old one, putting the edits in the new one, and overwriting the old file with the new file (OS stuff)

That's what I'd do anyway.


>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is offline   Reply With Quote
Old 11-26-2014, 03:17 PM   #17
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

omg FINALLY.. figured it out.

marked in red is the crap needed to deal with newlines. I'm just REALLY glad that when you do #string = "" it really becomes blank and not "refusing to overwrite memory."

warning: path is hardcoded to D:\Desktop\namelist.txt, change path before use.
Code:
/* Create list of selected media item names and reread list */

/* by Elan Hickler
   www.elanhickler.com
   www.Soundemote.com  */

#fp = "D:\\Desktop\\namelist.txt";
f = fopen(#fp, "w");
items = CountSelectedMediaItems(0);

i=0;
loop(items,
  TakeList[i] = GetActiveTake(GetSelectedMediaItem(0, i));
  i+=1;
);

i=0;
ShowConsoleMsg(sprintf(#, "Writing list of items to %s ...", #fp));
loop(items,
  GetTakeName(#name, TakeList[i]);
  fwrite(f, #name, 0);
  i+=1;
  i < items ? fwrite(f, "\n", 0); //prevent trailing newline
);
fclose(f);
ShowConsoleMsg("COMPLETE!\n...waiting for file input...");
Undo_OnStateChange("");

GetUserFileNameForRead(#fp, "readfile", ".txt") != 1 ? ShowConsoleMsg("CANCELED!\n\n") : (
  ShowConsoleMsg("\nReading...");
  f = fopen(#fp, "r");
  Undo_BeginBlock();
  i=0;len=1;
  while(!break) (
    len = fgets(f, #name);
    !matchi("%s\n", #name, #strip) ? matchi("%s", #name, #strip);
    matchi("\n", #strip) ? #strip = "";
    GetSetMediaItemTakeInfo_String(TakeList[i], "P_NAME", #strip, 1);
    len && i <= items ? i+=1 : break=1;
  );
  ShowConsoleMsg(sprintf(#,"%i lines read, %i media items renamed.\n", i,items));
  i != items || fgets(f, #) != 0 ? ShowConsoleMsg(
    sprintf(#,"\nWARNING! %i lines does not match %i media items.\n", i,items)
  );
  ShowConsoleMsg("\n");
  Undo_EndBlock("Rename selected media items based on list", -1);
  fclose(f);
);
When I write my mega-awesome string functions I won't have to deal with this.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-26-2014 at 05:13 PM.
Argitoth is offline   Reply With Quote
Old 11-26-2014, 05:18 PM   #18
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

uhh ok. No. I had not figured it out. BUT NOW I HAVE! Jeez, everything I need to do ends up requiring reading character by character and appending to string. That's not the upsetting part, it's the fact that I don't understand the original thought process that created these half-useless string functions. Whoever invented C-langauge... I'm guessing string functions including fgets, match, strcat, etc. work on the basis of char functions. I'm hoping that my use of char functions is just as efficient as string functions. If not, oh well... bottom line, I'm done using C-type string functions. I started working on this at maybe 10am or 11, it's now after 5pm. No more string functions.

Code:
/* Write and then read list of selected media item names */

/* by Elan Hickler
   www.elanhickler.com
   www.Soundemote.com  */

function msg(str) (ShowConsoleMsg(str));

items = CountSelectedMediaItems(0);

i=0;
loop(items,
  TakeList[i] = GetActiveTake(GetSelectedMediaItem(0, i));
  i+=1;
);

#fp = "D:\\Desktop\\namelist.txt";
f = fopen(#fp, "w");
i=0;
msg(sprintf(#, "Writing list of items to %s ...", #fp));
loop(items,
  GetTakeName(#name, TakeList[i]);
  fwrite(f, #name, 0);
  i+=1;
  i < items ? fwrite(f, "\n", 0);
);
fclose(f);
msg("COMPLETE!\n...waiting for file input...");
Undo_OnStateChange("");

GetUserFileNameForRead(#fp, "readfile", ".txt") != 1 ? ShowConsoleMsg("CANCELED!\n\n") : (
  msg("\nReading...");
  f = fopen(#fp, "r");
  Undo_BeginBlock();
  i=EOF=0;
  while(i < items && !EOF) (
    x=break=0;#str="";
    while(!break) (
      c = fgetc(f); c == '\n' || c == -1 ? break=1 : str_setchar(#str,x,c);
      x+=1
    );
    GetSetMediaItemTakeInfo_String(TakeList[i], "P_NAME", #str, 1);
    c == -1 ? EOF=1;
    i+=1;
  );
  msg(sprintf(#,"%i media items renamed.\n", i));
  i != items || !EOF ? ShowConsoleMsg(
    sprintf(#,"WARNING! Lines do not match number of media items!\n")
  );
  ShowConsoleMsg("\n");
  Undo_EndBlock("Rename selected media items based on list", -1);
  fclose(f);
);
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-26-2014 at 06:21 PM.
Argitoth is offline   Reply With Quote
Old 11-26-2014, 05:26 PM   #19
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default

I feel for ya. You can see my reluctance when I typically do this, which is relative childs play...

Code:
If File.Exists(path) = False Then File.WriteAllText(path, string)
       'or
If File.exists = True Then File.AppendAllText(path,string)
Lawrence is offline   Reply With Quote
Old 11-26-2014, 05:31 PM   #20
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

I literally threw an object across the room in anger at one point.

Ok so here's a bit more of an explanation of why I couldn't use string functions.

according to string functions:
Code:
text \n moretext \n moreMOREtext \n
3 \n? oh that's 3 lines.

WRONG.

That's 4 lines. Here's how it's rendered in any text editor:
Code:
text
moretext
moreMOREtext
<blank line here>
It's 3 lines followed by a blank line. The blank line means "" <blank>, it does NOT mean END OF FILE. Why? Because sometimes I want the last item in the list to be blank SO THAT the function I am running deals with the last item as <blank> instead of ending 1 item early.

Ok, well why not just add a blank line at the end so I can use string functions? I would argue that any modern software does NOT depend/make use of trailing new lines. No software I use depends on that, except maybe Native Instruments Kontakt (which is completely stupid by the way, causes errors and doesn't even let you know about it if you forget to add the trailing newline in image/gui definition text files).

In other words, if I had to make sure that new line was there, I would be constantly having to do manual checks, making sure I have that trailing newline every time I interact with the function in question. I do hand-editing as well as batch processing text files / text processing all day and I do not have time to debug a missing newline.
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-26-2014 at 05:53 PM.
Argitoth is offline   Reply With Quote
Old 11-26-2014, 05:35 PM   #21
Lawrence
Human being with feelings
 
Join Date: Mar 2007
Posts: 21,551
Default

I haven't played with EEL much but many languages seem have specific functions for that, like "writeline" where the command itself implies a new line for every string write.

It's kinda like "debug.print" which always makes a new line... so to end the text with an empty line... debug.print or writeline an empty string... if EEL has a comparable function.

But yeah, IIRC, \n is pretty common for "newline". I hate that in JS, it causes major issues with some text formatting if you aren't aware of how to get around it.
Lawrence is offline   Reply With Quote
Old 11-26-2014, 05:54 PM   #22
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

I think char functions is where it's at.

If any programming gurus will respond, please give us your knowledge on best practices of use of char and/or string functions. Is it ok to always use char functions or can that be inefficient versus good use of string functions?

Edit: I bet some string functions are more efficient, they probably make use of memory copying, which is probably more efficient that, reading/appending single characters. I dunno! (unless it's all the same under the hood?)
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-26-2014 at 06:20 PM.
Argitoth is offline   Reply With Quote
Old 11-26-2014, 06:42 PM   #23
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

I thin I used fread, fgetc, fseek and str_getchar when I was reading wav files. You can pull the function apart if you want to: Item Marer Tool thread.

The function is called "get_bwf_data" and starts around line 900.

Edit: It just uses fopen (binary), fread and fclose, but you're welcome to look through the data parsing and file handling. The script reads hex stored in the name field of a marker to find the GUID of a take, it's source file, etc, and reads the BWF offset out of the wave file and stores it in an array. There are a mixed bag of parsing methods used, I don't know how much it will help you, but it's reasonably well commented.


Code:
opchn = fopen(#filenamebuf, "rb");  // open file for read
			opchn !=0 ?
			(
				fread(opchn, #riff_header, 4); // import riff header
				fread(opchn, #file_size_buf, 4); // import file size as string
				fo +=8;
				file_size = str_getchar(#file_size_buf, 0, 'iu'); // read file size, double, LE	
				fread(opchn, #wave_header, 4); // import wave header
				fo +=4;
				
				while ((bext_found ==0) && (fo < file_size))
				(
					#hex_section ="";
					fread(opchn, #chunk_header, 4); // import chunk header
					//gfx_printf("ChH:%s ", #chunk_header);
					fread(opchn, #chunk_size_buf, 4); // import chunk size as string
					chunk_size = str_getchar(#chunk_size_buf, 0, 'iu'); // read file size, double, LE	
					fo +=8;
					//gfx_printf("ChSz:%d ", chunk_size);
					fread(opchn, #chunk_data_buf, chunk_size); // import chunk data as string
					fo += chunk_size;

					ch_offset = 0;
					
					//gfx_printf("Chunk:%s", #hex_section);	
					//gfx_x = xs(x); gfx_y +=gfx_texth; 
					
					strcmp(#chunk_header, "bext") == 0 ? (bext_found =1):(bext_found =0);
				);
				bext_found == 0 ? bext_time_offset =0;
				bext_found == 1 ?
				(
					strcpy_substr(#bext_Description, #chunk_data_buf, 0, 256);
					strcpy_substr(#bext_Originator, #chunk_data_buf, 256, 32);
					strcpy_substr(#bext_OriginatorReference, #chunk_data_buf, (256+32), 32);
					strcpy_substr(#bext_OriginationDate, #chunk_data_buf, (256+32+32), 10);
					strcpy_substr(#bext_OriginationTime, #chunk_data_buf, (256+32+32+10), 8); // left these "open" to show the obvious structure
					strcpy_substr(#bext_TimeRefLow, #chunk_data_buf, (256+32+32+10+8), 4);    // SMPTE codes and LUFS data follow these
					strcpy_substr(#bext_TimeRefHigh, #chunk_data_buf, (256+32+32+10+8+4), 4); // see EBU Tech 3285 v2 etc for more details.
					strcpy_substr(#bext_VersionNum, #chunk_data_buf, (256+32+32+10+8+4+4), 2); // 
					// I stopped here, but the full set of bext metadata can be retrieved -PM me for further details/help -planetnine

					bext_TimeRefLow = str_getchar(#bext_TimeRefLow, 0, 'iu'); // unsigned integer
					bext_TimeRefHigh = str_getchar(#bext_TimeRefHigh, 0, 'iu'); // unsigned integer
					bext_VersionNum = str_getchar(#bext_VersionNum, 0, 'su'); // unsigned short integer
					bext_time_offset = ((bext_TimeRefHigh * 4294967295) + bext_TimeRefLow)/GetMediaSourceSampleRate(GetMediaItemTake_Source(bwf_take)); // combine high & low bytes & sample rate
					format_timestr_pos(bext_time_offset, #bext_time_offset_buf, ecp_format); // format time offset to ecp format
				);
				fclose(opchn); // close file


>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is offline   Reply With Quote
Old 11-27-2014, 10:28 AM   #24
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

fgets is around 10x faster than fgetc. If you append chars to string, fgets is 20x faster.

I could only use fgets if ftruncate and a+ read/write mode was working.

Edit: Last night I don't know why it wasn't working, but it seems to be working now: a+ and r+ read&write modes.

Edit: Wait a minute, so I did a full script comparison of using fgets and fgetc for my purposes, fgetc won by .2 milliseconds... I'm confused.

here's the speed test if anyone is interested
Code:
GetUserFileNameForRead(#fp, "readfile", ".txt") != 1 ? ShowConsoleMsg("CANCELED!\n\n") : (

  time_precise(tt0);

  msg("\nReading...");
  f = fopen(#fp, "r");
  Undo_BeginBlock();
  i=0;
  while(!feof(f)) (
    len = fgets(f, #name);
    str_getchar(#name, len-1) == '\n' ? str_delsub(#name, len-1, 1);
    //GetSetMediaItemTakeInfo_String(TakeList[i], "P_NAME", #str, 1);
    i+=1;
  );
  msg(sprintf(#,"%i media items renamed.\n", i));
  i != items || !EOF ? ShowConsoleMsg(
    sprintf(#,"WARNING! Lines do not match number of media items!\n")
  );
  ShowConsoleMsg("\n");
  Undo_EndBlock("Rename selected media items based on list", -1);
  fclose(f);

  time_precise(tt1);

);

GetUserFileNameForRead(#fp, "readfile", ".txt") != 1 ? ShowConsoleMsg("CANCELED!\n\n") : (

  time_precise(tt2);

  msg("\nReading...");
  f = fopen(#fp, "r");
  Undo_BeginBlock();
  i=EOF=0;
  while(!EOF) (
    x=break=0;#str="";
    while(!break) (
      c = fgetc(f); c == '\n' || c == -1 ? break=1 : str_setchar(#str,x,c);
      x+=1
    );
    //GetSetMediaItemTakeInfo_String(TakeList[i], "P_NAME", #str, 1);
    c == -1 ? EOF=1;
    i+=1;
  );
  msg(sprintf(#,"%i media items renamed.\n", i));
  i != items || !EOF ? ShowConsoleMsg(
    sprintf(#,"WARNING! Lines do not match number of media items!\n")
  );
  ShowConsoleMsg("\n");
  Undo_EndBlock("Rename selected media items based on list", -1);
  fclose(f);

  time_precise(tt3);

);

ShowConsoleMsg(sprintf(#, "time: %g\n", tt1-tt0));
ShowConsoleMsg(sprintf(#, "time: %g\n", tt3-tt2));
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-27-2014 at 11:27 AM.
Argitoth is offline   Reply With Quote
Old 11-28-2014, 04:38 PM   #25
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

yeaahhh ummmm....


yeahh....


ahuh....


mmmhmmm...


I'm done with EEL. I tranlsated my EEL code to C++. EEL takes 14 seconds to do with C++ does in about 1 second.

Anyone want to get on the reaper extension bandwagon? I figured out the basics thanks to Xenakios and Breeder (http://forum.cockos.com/showthread.php?t=93355).

Edit: Oh, let me post my code! It's 3 different actions. EEL took 14 seconds to read a ~5000 line txt file and store it in media item names, C++ took about 1 second.
Code:
void ActionWriteNameList()
{
	auto items = CountSelectedMediaItems(0);
	if (!items) return;

	vector<string> List(items);
	auto i = 0; // local counter
	for (; i < items; ++i) {
		List[i] = GetTakeName(GetActiveTake(GetSelectedMediaItem(0, i)));
		List[i] += "\n";
	}
	List.back().pop_back();

	ofstream f("d:\\desktop\\namelist.txt");
	for (i = 0; i < items; i++) f << List[i];	
	f.close();
}

void ActionWriteFileList()
{
	auto items = CountSelectedMediaItems(0);
	if (!items) return;

	vector<string> List(items);
	char charbuf[FNLEN];
	auto i = 0; //local counter
	for (; i < items; ++i) {
		GetMediaSourceFileName(GetMediaItemTake_Source(GetActiveTake(GetSelectedMediaItem(0, i))), charbuf, FNLEN);
		List[i] = charbuf; 
		List[i] += "\n";
	}
	List.back();

	ofstream f("d:\\desktop\\filelist.txt");
	for (i = 0; i < items; i++) f << List[i];	
	f.close();
}

void ActionReadList()
{
	auto items = CountSelectedMediaItems(0);
	if (!items) return;

	ifstream f("d:\\desktop\\namelist.txt");
	char str[FNLEN];
	auto i = 0;
	while (!f.eof() && i < items) {
		f.getline(str, FNLEN);
		GetSetMediaItemTakeInfo_String(GetActiveTake(GetSelectedMediaItem(0,i)),"P_NAME", str, 1);
		++i;
	}
	f.close();
}
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 11-28-2014 at 04:58 PM.
Argitoth is offline   Reply With Quote
Old 11-28-2014, 05:42 PM   #26
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

Heh, break out the big guns!!



>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is offline   Reply With Quote
Old 11-29-2014, 11:05 AM   #27
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,891
Default

Quote:
Originally Posted by Argitoth View Post
I'm done with EEL.
You lasted a lot longer than I expected. It's useful for quick and dirty portable scripts but if you're trying to do anything complicated you need to do it in C. You'll be much happier in the IDE.
IXix is offline   Reply With Quote
Old 11-29-2014, 01:43 PM   #28
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

Quote:
Originally Posted by IXix View Post
You lasted a lot longer than I expected. It's useful for quick and dirty portable scripts but if you're trying to do anything complicated you need to do it in C. You'll be much happier in the IDE.
Oh come on now! I would have lasted to my dying breath if Xenakios didn't say the(my)day!
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 11-29-2014, 01:57 PM   #29
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

Wait wait... I'm sorry, I have to make a double post.

IXix, so you're telling me you've been watching me suffer from afar, all for your sadistic pleasure?

Wow... just... wow...
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template
Argitoth is offline   Reply With Quote
Old 11-30-2014, 03:08 PM   #30
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,891
Default

Quote:
Originally Posted by Argitoth View Post
IXix, so you're telling me you've been watching me suffer from afar, all for your sadistic pleasure?
A guy's got to get his kicks somehow.
IXix 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 05:08 PM.


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