JUCE Tutorial: Serialize a Spline with ValueTree

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome everyone in this little juice tutorial i want to talk about the value tree object that i recently learned to use for my little spline drawing editor let me quickly demonstrate what it does you can add splines with a left click can remove splines with the right click and you can drag splines but if they overlap they remove a spline point but the most incredible thing regarding this video is that if you close the window and open it up again then it will reload the state even though these points are not parameters in the audio processor tree state this process is known as serialization and whenever you don't want to use parameters for some information but still want to serialize it for some reason then you might want to use the value 3 object that juice provides you so i got a lot of help from the people in the discord of course because this is a very abstract topic but the goal of this video is to make it accessible to everyone regardless of their access to any community so yeah let's just get started okay so i checked out the documentation for the value tree class the reference for that and it's a bit cryptic in my opinion but let's just talk about it for a while um so yeah we have different constructors one that just gets no arguments one that gets a so-called identifier which is an interesting topic because as you know jews always already has strings the juice string class so what does the identify exactly do there's also a constructor with a lot of weird arguments which i didn't figure out yet and one with a value tree reference so you can set a value tree to another value tree's reference and uh and one of these double references i know they are called differently but i didn't learn that yet you can compare value trees you can check if they are valid but we don't know yet what that means you can create copies we can get the type which is apparently an identifier as well so we'll have to learn what that means and we have so called var objects which are called properties and they also have something to do with identifiers so we'll have to check out that and we have um different functions for the amounts of stuff like num properties removing all properties we can get children can actually we can append children we can remove children so um yeah that's that's basically what you can do even though this is looking rather cryptic and it doesn't tell you immediately what it means um but then i found out that there is also a tutorial about the value tree class and it's very nice very descriptive with a lot of text some solar code some examples and a lot of background information about like the var class the identifier so all the questions that you might have about it and some background information can you you can find it here in the tutorial but this video is more than just checking out the reference and i want to show you some a basic example of using a value to object on my little spline editor here which is a plug-in project by the way let's let's start in the plug-in processor get state information set state information as you know that's the place where you usually save the audio processor value tree state the ap vts in my case and that's still the same place where you do that so nothing different in here and that's pretty cool because i actually added a lot of information to the audio processor value 3 states value 3 but still you don't have to change anything about this which makes this value object very user friendly i'm all now let's get started first of all i don't want to tell you everything about the spline editor at least not yet i think i will make a separate video about that first of all the value tree object that is sitting here is not the value tree of juice as you can see i have to call the namespace for each object this is just more like a hipaa class for the actual value tree that is sitting here and let's see what it does so we instantiate the vibrator spline editor we get all the objects and then also the value tree we give it the audio possible tree state we give it the vibrato spline editor and we give it the identifier of this editor i use this structure to make sure that i can use multiple spline editors in the same program and by just giving them different identifiers at this point it might make sense to pause the video and check out this tutorial to see what an identifier does okay so the value tree is instantiated here let's see what that means um go here and see that the identifier gets its string and then um the other identifiers are just set here normally we have a point we have an x value and an identifier for y and then the value tree is just the initializer with no argument so it's empty now what do these statements do audio processor value tree state is the value tree of the oil processor tree state it also holds the parameters and then we can call get chart with main name and we take the identifier and now there are two options either this identifier does not exist yet which would mean that there are no points in it yet so this is empty which means now when we call this we get um another pointer at this point but if we actually have some points and call the initializer here then it's not null pointer because it will find an object with this uh child name and return that instead now let's pretend like we got an an empty value tree this actually means that it's invalid so i check for is valid and i get into the else so i make a new value tree with the right identifier which is now valid and i append it to the repository state state and that way we get started now every other times which are probably happening more often and that's why it's in the first if state the value already has some points so what are we doing then we clear all the spline points in our vector in case they are not clear for some reason i don't know i'm just very cautious here and then we reserve the amount of children of the tree and then we iterate through the value tree get all the x and y values which are stored as properties and properties as you can see our var objects we cast them to end and then we and place back them to the our spline points so yeah that's actually all you have to do to get started now let's see in which case we actually update the nodes of the value tree with the identifier called web spline in the mouse up function if it was not a right click button so it was a left click button then we add something add spam point and if it was a right click button we remove and if we didn't drag the mouse then we don't have to do anything here because the mouse drag already handles moving the spline points and stuff yeah as i said i will go into more detail when i actually make a video about the spline editor itself but you just have to take my word for it that it works like that for now at the end of the mouse up we can reset the notes we don't need that in mouse drag because that means that while we are dragging it won't reset our notes yet but once we lay them down it resets them and we can also test that by we can go into the reset nodes function which looks like this by the way we remove all children remove all properties then we go through the spine points and add the notes again and i designed my spline editor in a way that the spline points vectors always sorted so that that's why we can just do that and get away with it nicely but in your implementation you might have to care for that so we can what we can do is we can go to value tree and type string and get this method now we have nice little debug string okay now check out the output i click something and we see there are a bunch of values i delete some values and we have less values now i move values and i'm not um laying them down still dragging we don't get a new value but then i laid them down with new values i'm actually fine with the fact that it does not update immediately here because this is only for saving the plug-in state the points are still changed immediately when i well when i drag them so i can work with that well now you basically know everything you need to know to get started except for one thing which is i made a little function for resetting the oil processor value tree state it's very simple all it does is removing all children and properties i use that because when you actually have to figure out this data structure at some point you make a mistake every time you load the plugin and close it again it will load and save new states and if this messed up data structure keeps on adding new stuff or something like that and then you can't work with it anymore and you might end up with the right code but it does not behave correctly because you didn't start on a clean value tree so that's how you clean it up before starting something trying something new so that's something that you definitely need you should also always care about difference between a value tree node and also a property as you can see in my add node function i i want to add the x and y values to something so i make another value 3 so my value 3 holds value trees and this value 3 actually has the identifier of a point it's not the identifier of the whole thing but just the point and it has the property x and y with the corresponding identifiers x and y then i can append this value tree to my point node and that's how my data structure works in here so yeah serialization with value trees that's how you can make it work just to get a little resume about everything the goal of using value trees to serialize information is to have a way of saving information for each plugin that is instantiated in any project without having to fiddle around with stuff like saving stuff to a text file and then loading again the text file and text has to remember which project it corresponds to or something like that it will just do all that for you and that's pretty cool yeah that's what a value tree can be used for okay see ya
Info
Channel: Beats basteln :3
Views: 240
Rating: undefined out of 5
Keywords: juce, framework, c++, pns, dsp, audio, programming, coding, vst, plugin, cubase, daw, tutorial
Id: akKDjNp_Fb8
Channel Id: undefined
Length: 12min 25sec (745 seconds)
Published: Sun Jan 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.