Hi, if I use an array in a module and want to save the content, is that something that can be done using GetStateInformation or should that be done by serializing the array and save it to disk?
Does anyone have pointers on this?
thanks
Hans
Save arrays with preset - GetStateInformation?
Save arrays with preset - GetStateInformation?
Request for Music
- honki-bobo
- Posts: 306
- Joined: Sat Nov 09, 2019 1:18 pm
Re: Save arrays with preset - GetStateInformation?
Hi Hans,
that is (at least from what I understand) pretty much exactly what this method is there for.
I use it to store user sample data and restore it after loading the module again.
The most convenient way to store primitive data types is to use a ByteBuffer and return the buffer's content as an array.
Restoring the array is equally simple
Hope this helps.
Best regards,
Martin
that is (at least from what I understand) pretty much exactly what this method is there for.
I use it to store user sample data and restore it after loading the module again.
The most convenient way to store primitive data types is to use a ByteBuffer and return the buffer's content as an array.
Code: Select all
public byte[] GetStateInformation() {
ByteBuffer buffer = ByteBuffer.allocate(8 * myArray.length + 4); // assuming the data type in myArray is 64 bit (e.g. double), +4 for the array length (int is 32 bit)
buffer.putInt(myArray.length);
for (int i = 0; i < myArray.length; i++) {
buffer.putDouble(myArray[i]);
}
return buffer.array();
}
Code: Select all
public void SetStateInformation(byte[] stateInfo) {
ByteBuffer buffer = ByteBuffer.wrap(stateInfo);
myArray = new double[buffer.getInt()];
for (int i = 0; i < myArray.length; i++) {
myArray[i] = buffer.getDouble();
}
}
Best regards,
Martin
Re: Save arrays with preset - GetStateInformation?
Cool Martin - that will surely help - will try in the weekend... (busy busy...)
Thank you so much!!
cheers Hans
Thank you so much!!
cheers Hans
Request for Music
Re: Save arrays with preset - GetStateInformation?
by the way Martin, did you find info on how to do this somewhere and have I just been sloppy in my search or are you just that more creative in your programming? Also good to know where I stand... I couldn't figure it out
In my defense though - I have only just started with Java, coming from other languages....
cheers Hans
In my defense though - I have only just started with Java, coming from other languages....
cheers Hans
Request for Music
- honki-bobo
- Posts: 306
- Joined: Sat Nov 09, 2019 1:18 pm
Re: Save arrays with preset - GetStateInformation?
I found some information in the Cherry Audio documentation here:
https://docs.cherryaudio.com/voltage-mo ... -variables
The section on GetStateInformation() and SetStateInformation(byte[] stateInfo) kind of explains the basic idea behind these two methods and gives some hints on how to use them. I have been working with the Java NIO classes in the past and have gained very good experience using them. They are super fast and reliable once you get the hang of it. That's why I used the ByteBuffer instead of the "classical" input/output streams.
And there is no need to defend yourself. Everybody has to start somewhere.
I have a master degree in computer science and have studied for 7 years at the University of Luebeck, Germany. After that I have been working at the University for over 6 years, so I guess I have a good amount of field experience, which is a great motor for creativity
But - just like you - I also came from other languages before going to University (Basic, TurboPascal and Delphi to be exact).
I think you don't need a fancy degree to create great modules that other people can use in their creative process, but some programming experience and background knowledge never hurts. What I have learned over the years is that the most important thing is to never stop learning, experimenting and playing around with stuff.
https://docs.cherryaudio.com/voltage-mo ... -variables
The section on GetStateInformation() and SetStateInformation(byte[] stateInfo) kind of explains the basic idea behind these two methods and gives some hints on how to use them. I have been working with the Java NIO classes in the past and have gained very good experience using them. They are super fast and reliable once you get the hang of it. That's why I used the ByteBuffer instead of the "classical" input/output streams.
And there is no need to defend yourself. Everybody has to start somewhere.
I have a master degree in computer science and have studied for 7 years at the University of Luebeck, Germany. After that I have been working at the University for over 6 years, so I guess I have a good amount of field experience, which is a great motor for creativity
But - just like you - I also came from other languages before going to University (Basic, TurboPascal and Delphi to be exact).
I think you don't need a fancy degree to create great modules that other people can use in their creative process, but some programming experience and background knowledge never hurts. What I have learned over the years is that the most important thing is to never stop learning, experimenting and playing around with stuff.
Re: Save arrays with preset - GetStateInformation?
Pfffff... I fully missed that part in the documentation..doh!!!
Well - I don't have a degree like you, but have been going all the way from Algol, Basic, Pascal, C, PHP, SQL (not really programming language), JavaScript and a bit C++
and some other weird ones (like Forth) over the last god knows how many years
And as you say - the degree is not the most important part - being creative helps as well..
Fortunately I'm actually a graphic designer, so being creative is (somewhere) in my blood...
And further as with any other (OOP) language, if you don't exactly know the library and methods, you're in the dark...
So indeed...learning..learning..learning.. still do that in my music as well..
Thanks!
cheers Hans
Well - I don't have a degree like you, but have been going all the way from Algol, Basic, Pascal, C, PHP, SQL (not really programming language), JavaScript and a bit C++
and some other weird ones (like Forth) over the last god knows how many years
And as you say - the degree is not the most important part - being creative helps as well..
Fortunately I'm actually a graphic designer, so being creative is (somewhere) in my blood...
And further as with any other (OOP) language, if you don't exactly know the library and methods, you're in the dark...
So indeed...learning..learning..learning.. still do that in my music as well..
Thanks!
cheers Hans
Request for Music