Recent

Author Topic: Recommended way to build a resource file from a text file on macOS? [SOLVED]  (Read 1064 times)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
* Mac Mini M1 (silicon)
* macOS 14.6.1
* Lazarus 3.4
* FPC 3.2.2

I would like to build a resource file from a text file that looks like this, but much bigger (~520 lines)

Code: Text  [Select][+][-]
  1. bass
  2. 30, 1, "acid bass", "aggressive + analog + distorted + stereo"
  3. 30, 2, "acouskop", "acoustic + distorted + fm + shaking"
  4. 30, 31, "bass distosine", "acoustic + synthetic"
  5. 30, 32, "bass monster", "analog + distorted + portamento + synthetic"
  6. 30, 74, "chordead", "analog + chords"
  7. 30, 108, "deep corners", "analog + chords"
  8. 30, 112, "dirt acid", "analog + distorted"
  9. 30, 119, "doubleslap", "acoustic + shaking + warm + woody"
  10. 30, 127, "edgy fm", "fm"
  11. 31, 3, "eighty neon", "analog"
  12. 31, 5, "electric bass 1", "acoustic + electric"
  13. 31, 6, "electric bass 2", "acoustic + electric"
  14. 31, 29, "fat model d", "analog + big + noise + portamento + warm"
  15. 31, 36, "flunkly", "analog"
  16. 31, 43, "fm darkness", "aggressive + big + dark + digital + dry + ensemble + fm + noise"
  17. 31, 44, "fm doublebass", "clean + fm + portamento"
  18. 31, 50, "fm slapman", "bright + digital + fm + metallic + stereo"
  19. 31, 54, "forgotten animal", "analog + fm + portamento"
  20. 31, 55, "forty eight db", "analog + distorted"
  21. 31, 56, "fourad", "analog + distorted"
  22. 31, 57, "fretless bass", "acoustic + portamento"
  23. 31, 76, "grittysaw", "analog + distorted"
  24. 31, 86, "hollowrez", "analog"
  25. 31, 107, "juknow that bass", "analog + big + clean + simple + soft + stereo"
  26. 31, 121, "kinespeech", "analog + vocal"
  27. 32, 5, "lacous bass", "acoustic + portamento"
  28. 32, 7, "ladder bass", "analog + lfo + synthetic"
  29. 32, 58, "night bass", "analog + portamento"
  30. 32, 92, "outspoken", "analog"
  31. 32, 109, "piercing bass", "aggressive + big + dark + digital"
  32. 32, 114, "pl-bass", "analog + dry + warm"
  33. 32, 126, "pulzz", "analog"
  34. 33, 5, "reesotto", "aggressive + digital"
  35. 33, 6, "reesy rider", "aggressive + analog + distorted + stereo"
  36. 33, 19, "rusty bass", "dark + digital + fm + soft"
  37. 33, 20, "rusty square", "analog + distorted"
  38. 33, 39, "simpledecay", "analog + distorted"
  39. 33, 41, "simplerez", "analog"
  40. 33, 48, "smooth operator", "acoustic + fm"
  41. 33, 49, "solid square", "analog"
  42. 33, 68, "steroids", "analog + noise"
  43. 33, 74, "sub bass 1", "analog"
  44. 33, 75, "subway", "analog + clean + dark + fm + simple"
  45. 33, 77, "syncat", "analog"
  46. 33, 95, "thrilla bass", "analog + dry"
  47. 33, 114, "velsquare", "analog"
  48. 33, 119, "vintage wide bass", "analog + big + dark + portamento + soft + stereo + warm"
  49. 33, 125, "walking blues", "acoustic"
  50. 33, 127, "wallface", "digital + fm + portamento"
  51.  

I've tried creating an LRS file but my build is failing for some reason. The LRS file looked like this...
Code: Text  [Select][+][-]
  1. LazarusResources.Add('OsmosePresetData','TEXT',[
  2.   'bass',
  3.   '',
  4.   '30, 1, "acid bass", "aggressive + analog + distorted + stereo"',
  5.   '30, 2, "acouskop", "acoustic + distorted + fm + shaking"',
  6.   '30, 31, "bass distosine", "acoustic + synthetic"',
  7.   '30, 32, "bass monster", "analog + distorted + portamento + synthetic"',
  8.   '30, 74, "chordead", "analog + chords"',
  9.   '30, 108, "deep corners", "analog + chords"',
  10.   '30, 112, "dirt acid", "analog + distorted"',
  11.   '30, 119, "doubleslap", "acoustic + shaking + warm + woody"',
  12.   '30, 127, "edgy fm", "fm"',
  13.   '31, 3, "eighty neon", "analog"',
  14.   '31, 5, "electric bass 1", "acoustic + electric"',
  15.   '31, 6, "electric bass 2", "acoustic + electric"',
  16.   '31, 29, "fat model d", "analog + big + noise + portamento + warm"',
  17.   '31, 36, "flunkly", "analog"',
  18.   '31, 43, "fm darkness", "aggressive + big + dark + digital + dry + ensemble + fm + noise"',
  19.   '31, 44, "fm doublebass", "clean + fm + portamento"',
  20.   '31, 50, "fm slapman", "bright + digital + fm + metallic + stereo"',
  21.   '31, 54, "forgotten animal", "analog + fm + portamento"',
  22.   '31, 55, "forty eight db", "analog + distorted"',
  23.   '31, 56, "fourad", "analog + distorted"',
  24.   '31, 57, "fretless bass", "acoustic + portamento"',
  25.   '31, 76, "grittysaw", "analog + distorted"',
  26.   '31, 86, "hollowrez", "analog"',
  27.   '31, 107, "juknow that bass", "analog + big + clean + simple + soft + stereo"',
  28.   '31, 121, "kinespeech", "analog + vocal"',
  29.   '32, 5, "lacous bass", "acoustic + portamento"',
  30.   '32, 7, "ladder bass", "analog + lfo + synthetic"',
  31.   '32, 58, "night bass", "analog + portamento"',
  32.   '32, 92, "outspoken", "analog"',
  33.   '32, 109, "piercing bass", "aggressive + big + dark + digital"',
  34.   '32, 114, "pl-bass", "analog + dry + warm"',
  35.   '32, 126, "pulzz", "analog"',
  36.   '33, 5, "reesotto", "aggressive + digital"',
  37.   '33, 6, "reesy rider", "aggressive + analog + distorted + stereo"',
  38.   '33, 19, "rusty bass", "dark + digital + fm + soft"',
  39.   '33, 20, "rusty square", "analog + distorted"',
  40.   '33, 39, "simpledecay", "analog + distorted"',
  41.   '33, 41, "simplerez", "analog"',
  42.   '33, 48, "smooth operator", "acoustic + fm"',
  43.   '33, 49, "solid square", "analog"',
  44.   '33, 68, "steroids", "analog + noise"',
  45.   '33, 74, "sub bass 1", "analog"',
  46.   '33, 75, "subway", "analog + clean + dark + fm + simple"',
  47.   '33, 77, "syncat", "analog"',
  48.   '33, 95, "thrilla bass", "analog + dry"',
  49.   '33, 114, "velsquare", "analog"',
  50.   '33, 119, "vintage wide bass", "analog + big + dark + portamento + soft + stereo + warm"',
  51.   '33, 125, "walking blues", "acoustic"',
  52.   '33, 127, "wallface", "digital + fm + portamento"'
  53. ]);
  54.  

This was based on a suggestion given to me by Claude Sonnet 3.5 AI. Not surprisingly it didn't work!
I'm referencing the LRS file with...
Code: Pascal  [Select][+][-]
  1. {$R OsmosePresetResources.lrs}
  2.  
FWIW..

This is the build error I'm getting...
Code: Text  [Select][+][-]
  1. Compile Project, Target: /Users/carlcaulkett/Code/FPC/Osmose Presets/OsmosePresets: Exit code 1, Errors: 1
  2. view.pas(29,0) Error: Can't open resource file "/Users/carlcaulkett/Code/FPC/Osmose Presets/OsmosePresetResources.lrs"
  3.  

Presumably the format of the LRS file is stopping it from being able to be loaded...

I've since discovered messages that suggest that the RES file format is now preferred over the old LRS format. But how do I build a RES file from a text file? The how-to in the documentation seems not to be up to date. I'd like, eventually, to access the resource using a TResourceStream. Admittedly it's getting quite late here in England, so not a lot is making sense at the moment. A little nudge in the right direction would be most welcome  ;)
« Last Edit: September 20, 2024, 06:22:33 pm by carl_caulkett »
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #1 on: September 17, 2024, 02:55:06 pm »
I eventually managed to build a LRS file using...
Code: Text  [Select][+][-]
  1. lazres OsmosePresetResouces.lrs OsmosePresetResouces.txt

but now I'm having problems loading it into a TResourceStream. What is the recommended way to get the data from my OsmosePresetResouces.lrs into a TStringList in my program?

I've spent the entire morning searching one rabbit hole after another, each with a different, contradictory idea. I grow weary of this  ;)

Thanks in advance!
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #2 on: September 17, 2024, 03:18:40 pm »
I just found this old thread that looked quite promising...
https://forum.lazarus.freepascal.org/index.php/topic,38585.msg262446.html#msg262446

I created an RC file...
Code: Text  [Select][+][-]
  1. OsmosePresetData RCDATA OsmosePresetData.txt
  2.  

and then used it like this...
Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. {$R OsmosePresetData.rc}
  4.  
  5. { TPresetData }
  6.  
  7. constructor TPresetData.Create;
  8. begin
  9.   inherited;
  10.   FLines := TStringList.Create;
  11.   LoadPresetData;
  12. end;
  13.  
  14. destructor TPresetData.Destroy;
  15. begin
  16.   DestroyPresets;
  17.   Flines.Free;
  18. end;
  19.  
  20. procedure TPresetData.CreatePresets;
  21. begin
  22.   FPresets := TObjectList.Create(True);
  23. end;
  24.  
  25. procedure TPresetData.DestroyPresets;
  26. begin
  27.   FPresets.Destroy;
  28. end;
  29.  
  30. procedure TPresetData.LoadPresetData;
  31. var
  32.   rs: TResourceStream;
  33. begin
  34.   rs := TResourceStream.Create(HInstance, 'OsmosePresetData', RT_RCDATA);
  35.   try
  36.     FLines.LoadFromStream(rs);
  37.   finally
  38.     rs.Free;
  39.   end;
  40. end;
  41.  
  42. end.
  43.  

I just tried to run it and it's telling me...
Code: Text  [Select][+][-]
  1. model.pas(93,0) Error: resource compiler "windres" not found, switching to external mode
  2.  

More searching... down another few rabbit holes, no doubt  :o
"It builds... ship it!"

alpine

  • Hero Member
  • *****
  • Posts: 1271
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #4 on: September 17, 2024, 03:49:58 pm »
Use fpcres
 https://forum.lazarus.freepascal.org/index.php/topic,66254.0.html

Thanks! I've just tried that on a RC file that just consists of...
Code: Text  [Select][+][-]
  1. OsmosePresetData RCDATA OsmosePresetData.txt
  2.  

It errored with...
Code: Text  [Select][+][-]
  1. [Tue Sep 17 2024  2:36pm (BST+0100)]
  2. ~/Code/FPC/OsmosePresets  fpcres OsmosePresetData.rc -o OsmosePresetData.res
  3.  
  4. Error: No known file format detected for file 'OsmosePresetData.rc'
  5.  
  6. [2 - USAGE][Tue Sep 17 2024  2:37pm (BST+0100)]
  7. ~/Code/FPC/OsmosePresets
  8.  

@PascalDragon, any idea about this?
« Last Edit: September 17, 2024, 04:08:27 pm by carl_caulkett »
"It builds... ship it!"

alpine

  • Hero Member
  • *****
  • Posts: 1271
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #5 on: September 17, 2024, 04:10:28 pm »
Code: Bash  [Select][+][-]
  1. fpcres OsmosePresetData.rc -o OsmosePresetData.res -of res
?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #6 on: September 17, 2024, 06:10:53 pm »
Code: Bash  [Select][+][-]
  1. fpcres OsmosePresetData.rc -o OsmosePresetData.res -of res
?

Thanks! That successfully solved the 'fpcres' issue. Unfortunately I'm still getting problems when I build the app.
See my post at the end of https://forum.lazarus.freepascal.org/index.php/topic,66254.msg530175/topicseen.html#new. I was trying to piggyback on the message in the hope that Thaddy or PascalDragon would step in to help!

In short, though, I'm still getting the build errors...
Code: Text  [Select][+][-]
  1. Error: Duplicate resource: Type = 24, Name = 1, Lang ID = 0000
  2. Error: Error while compiling resources -> Compile with -vd for more details. Check for duplicates.
  3.  

And no executable is built!
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3518
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #7 on: September 17, 2024, 06:13:45 pm »
In short, though, I'm still getting the build errors...
Code: Text  [Select][+][-]
  1. Error: Duplicate resource: Type = 24, Name = 1, Lang ID = 0000
  2. Error: Error while compiling resources -> Compile with -vd for more details. Check for duplicates.
  3.  

Do you still have the generic resource include in your lazarus source-code ? in that case it loads it twice.

Same when you manually added the resource in your project options.

The 'normal' way of doing these kind of things is to include the resource using the resource directive in your source-code and let fpc-res do the conversion automatically for you. Because fpcres is not default (yet) you have to override your compiler settings, see also https://wiki.freepascal.org/FPC_New_Features_Trunk#fpcres_can_compile_RC_files
« Last Edit: September 17, 2024, 06:17:21 pm by TRon »
This tagline is powered by AI

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #8 on: September 17, 2024, 06:36:32 pm »
Thanks for the reply!

This my entire source code now...

Code: Pascal  [Select][+][-]
  1. unit view;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, LResources,
  9.   StdCtrls;
  10.  
  11. type
  12.  
  13.   { TMainView }
  14.  
  15.   TMainView = class(TForm)
  16.     ListBox1: TListBox;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure FormDestroy(Sender: TObject);
  19.     procedure FormShow(Sender: TObject);
  20.   private
  21.     FLines: TStrings;
  22.     procedure LoadPresetData;
  23.   public
  24.   end;
  25.  
  26. var
  27.   MainView: TMainView;
  28.  
  29. implementation
  30.  
  31. {$R 'OsmosePresets.res'}
  32. {$R *.lfm}
  33.  
  34. { TMainView }
  35.  
  36. procedure TMainView.FormCreate(Sender: TObject);
  37. begin
  38.   FLines := TStringList.Create;
  39. end;
  40.  
  41. procedure TMainView.FormDestroy(Sender: TObject);
  42. begin
  43.   FLines.Free;
  44. end;
  45.  
  46. procedure TMainView.FormShow(Sender: TObject);
  47. begin
  48.   LoadPresetData;
  49.   ListBox1.Items := FLines;
  50. end;
  51.  
  52. procedure TMainView.LoadPresetData;
  53. var
  54.   rs: TResourceStream;
  55. begin
  56.   rs := TResourceStream.Create(HInstance, 'OsmosePresets', RT_RCDATA);
  57.   try
  58.     FLines.LoadFromStream(rs);
  59.   finally
  60.     rs.Free;
  61.   end;
  62. end;
  63.  
  64. end.
  65.  

"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3518
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #9 on: September 17, 2024, 06:40:29 pm »
@carl:
inside your main project file (and by default) is a resource directive "{$R *.res}" that also loads your resource. Thus it is effectively done twice.
This tagline is powered by AI

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #10 on: September 17, 2024, 08:41:37 pm »
@carl:
inside your main project file (and by default) is a resource directive "{$R *.res}" that also loads your resource. Thus it is effectively done twice.

That makes sense! Indeed, I've just removed the
Code: Pascal  [Select][+][-]
  1. {$R 'OsmosePresets.res'}
from my my unit, and now my project builds.

I'm not out of the woods yet, though! If I run the app, I get a message saying...
Code: Text  [Select][+][-]
  1. The debugger encountered an internal error.
  2.  
  3. Save your work.
  4. You may then hit "Stop", or "Rest Debugger" to terminate the debug session.
  5.  

If I run without debugging, it's giving a run-time error on the TResourceStream.Create line...
Code: Pascal  [Select][+][-]
  1. procedure TMainView.LoadPresetData;
  2. var
  3.   rs: TResourceStream;
  4. begin
  5.   rs := TResourceStream.Create(HInstance, 'OsmosePresets', RT_RCDATA);
  6.   try
  7.     FLines.LoadFromStream(rs);
  8.   finally
  9.     rs.Free;
  10.   end;
  11. end;
  12.  

The error is:
Code: Text  [Select][+][-]
  1. Resource "OsmosePresets" not found.
  2.  
  3. Press OK to ignore and risk data corruption.
  4. Press Abort to kill the program,
  5.  

I confirmed this by commenting out the above method, and the program started, without error, although that was without debugging.

Whatever I do with Debugging enabled, gives me the
Code: Text  [Select][+][-]
  1. The debugger encountered an internal error.
  2.  
  3. Save your work.
  4. You may then hit "Stop", or "Rest Debugger" to terminate the debug session.
  5.  
message!

I suppose what is needed is a way for the main unit code to have the
Code: Pascal  [Select][+][-]
  1. {$R 'OsmosePresets.res'}
  2.  
line, but does it in such a way that it can co-exist in blissful harmony with the *.res in the project file. Or maybe the project file needs to have the *.res replaced with something more specific...

Thanks for your help @TRon, I feel that we are inching towards a solution ;)
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3518
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #11 on: September 17, 2024, 08:57:41 pm »
case of murphy ?  :)

The error is:
Code: Text  [Select][+][-]
  1. Resource "OsmosePresets" not found.
  2. Press OK to ignore and risk data corruption.
  3. Press Abort to kill the program,
  4.  

something is off:

I created an RC file...
Code: Text  [Select][+][-]
  1. OsmosePresetData RCDATA OsmosePresetData.txt
  2.  

Can you see what it is  ? A hint: single vs plural

Quote
Thanks for your help @TRon, I feel that we are inching towards a solution ;)
You are more than welcome,and yes you are close so there is no need to wake up dragons  :)
This tagline is powered by AI

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #12 on: September 17, 2024, 09:12:04 pm »
No! I've now standardised on the name "OsmosePresets" throughout ;)

Here's a funny thing...
The "OsmosePresets.res" as produced by the
Code: Bash  [Select][+][-]
  1. fpcres OsmosePresets.rc -o OsmosePresets.res -of res
  2.  


Gives a result when viewed, that is recognisably containing the right data (see 1st attachment)...

The act of building the project generates a new "OsmosePresets.res" that is largely gibberish but at the start has some XML containing much too much Microsoft Windows related malarky for my comfort (see 2nd attachment)...


« Last Edit: September 17, 2024, 09:15:01 pm by carl_caulkett »
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3518
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #13 on: September 17, 2024, 09:41:21 pm »
No! I've now standardised on the name "OsmosePresets" throughout ;)
Very good !

Hopefully this case of Murphy was enough to have this all memorized for life so you'll never forget (always the best way to learn new things imho)

Quote
Here's a funny thing...
tbh, I do not have nay idea what might have caused that.

That issue is much harder to debug and requires a full project to be able to reproduce.

As a wild guess and at first glance I would say there is something wrong with an offset somewhere as that seems to be an included (windows) resource manifest. Perhaps and hopefully someone more knowledgeable has an idea ?
This tagline is powered by AI

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Recommended way to build a resource file from a text file on macOS?
« Reply #14 on: September 17, 2024, 09:49:23 pm »
What was your recommendation wrt the {$R *.res} in the project file and the {$R 'OsmosePresets.res'} in the main unit?
"It builds... ship it!"

 

TinyPortal © 2005-2018