Load / Save any File to Schematics

Post any examples or modules that you want to share here
Post Reply
User avatar
chackl
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Load / Save any File to Schematics

Post by chackl »

Hello!

I experimented with ruby and binary files - And i got it managed to store any files eaven binary things to the schematic by saving each single byte with ruby.

So packing some files to the VST may now be no problem anymore ;)

Regards
C.Hackl
Attachments
load&save any File.fsm
(291.94 KiB) Downloaded 1468 times
Last edited by chackl on Fri Oct 18, 2013 10:02 am, edited 4 times in total.
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Load / Save any File to Schematics

Post by trogluddite »

This becomes even more powerful when you use the Array.pack and String.unpack methods.
These let you turn any kind of numeric data into String form for saving, and back again - in this case the term "String" is used in its most general sense; a sequence of bytes, not necessarily interpreted as being characters.
For example...

Code: Select all

byte_string = [0.123, 0.543, 1.462, 7.890].pack('F*')

...gives you a String byte-sequence that encodes the array of float numbers (single precision in this case).
And...

Code: Select all

my_array = byte_string.unpack('F*')

...will get you back to the original array.

Also, check out the Marshal class - even more powerful!
This has methods that allow you to turn almost any Ruby object into a serialized String and back again - including even Arrays etc. nested many levels deep.

Code: Select all

hashed_arrays = { "Array1" => [10,20,30], "Array2" => [40,50,60] }
File.open(my_file,"w"){|file| Marshal.dump(hashed_arrays, file)}

hashed_arrays = File.open(my_file, "r"){|file| Marshal.load(file)}

You can even make this work for your own custom classes of object if you define the correct 'load' and 'dump' methods in your new class - all you need is some way to turn your object into a string and back again (possibly by the Marshal methods of any component objects).
There are a few exceptions where this doesn't work - for example many of the FS GUI objects lack the necessary Marshal methods, so, as yet, you can't easily save GraphicsPaths, Pens, etc.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
chackl
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Load / Save any File to Schematics

Post by chackl »

I did an uppdate now:
I had some errors with load ans save state and corrected to the correct file dialog ;)


Torg:
I sea what you mean - i also thought of that way for example combining files into one file with ruby.

There is only one thing why i have not done it jet:
I do not get this F....ING ZLIB running - to compress data ;)


Update is in first post

Regards
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Load / Save any File to Schematics

Post by RJHollins »

Hi C.Hackl,

I'm following along your thread here ... trying to continue learning.

I'm being help on a new file/data SAVE & LOAD routine. TROG posted the Ruby Marshal code which is absolutely great.

I don't want to interrupt your thread at all ... but I was looking at your post as I search for implementing some 'Directory Management' functions to dress out this Marshal routine.

Looking at your code, I see some sections of interest.

I've been using TROG's 'Save Load Application Data settings file' that has default directory locations, find if a file exists, and can create a Folder to store in.

I'm not confident in my writing of RUBY that would involve things like directories or creating folders ... don't need to tempt a disaster :shock: I feel safer with GREEN. Yet was wondering if you had plans to have these type of functions for this module ?

sorry to interrupt ... thanks for your posts !!!
8-)
User avatar
chackl
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Load / Save any File to Schematics

Post by chackl »

Ive just added now a Save Load for complet dirs and subdirs ;)

Regards

EDIT- And i can not upload it ^^
EDIT2 - It got over 2MB so i had to delete the files inside -sorry
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Load / Save any File to Schematics

Post by RJHollins »

:o

maybe the WAV data file is bulking up the filesize ?!?
User avatar
chackl
Posts: 233
Joined: Tue Aug 17, 2010 8:46 pm
Location: Austria / Salzburg

Re: Load / Save any File to Schematics

Post by chackl »

If you save a file within a schematic - it will gow ^^ :P

This is a normal natural Computer phenomenon :P
100% accuracy is the guarantee to your success. The value alters if you combine it with musical creativity.
Post Reply