JUCE 6 Tutorial 08 - The AudioProcessorValueTreeState Class Pt 2 of 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up everybody i'd like to welcome you to another juice tutorial and in this tutorial what we're going to do is we're going to create a visual interface that the user is going to be able to use to connect with the piece of data that we created in our last tutorial so as you may remember in our last tutorial we created this game parameter that sits in our audio processor value tree state and so we see that we have this audio parameter floats called gain goes from zero to one with a default of 0.5 and now we need to create something visual on the user interface that the user is actually going to be able to change to control this parameter so what we'll do is we will go to our plugin editor dot h to get started and before we get started be sure to check out our community on theaudioprogrammer.com forward slash community it's a great place to connect with other audio developers of all levels so we have everybody from teenagers all the way to professionals that are doing this professionally for some of the biggest companies in the world and everything in between so check us out on the audioprogrammer.com forward slash community also if you'd like to see me more tutorials like this uh consider joining our patreon on patreon.com forward slash the audio programmer so let's go ahead and get started so the first thing that we're going to do is we're going to create a gain slider so i will do this by saying juice slider i'll just call this gain slider and then what i'm going to do is i'm going to go to the editor and give this just some parameters so we could just say gain slider set slider style and i've gone over this in previous tutorials so i won't go through this again so we got juice slider slider style rotary horizontal vertical drag and then i will say gain slider set text box style and then i will say juice slider text box below and this will be read only and then we'll give it a width of 100 a height of 50 pixels and then i need to make it a child component of my main component so i do that with add and make visible and we just put a gain slider there we'll give it a little position by saying gain slider set bounds and then we'll put it in the middle of the screen so we'll do get with divided by 2 minus 100 and we'll do get height divided by 2 minus 50 and we'll give it a width of 200 and a height of that'll put it in the middle of the screen for us okay and we'll have a look at what that looks like in a little bit so the next thing that we want to do is now we need to connect it to our data so one thing that you may notice if you've seen our slider tutorial is that i haven't actually given this a range or a default value and the reason that that is is because that's actually going to be defined by our parameter so the parameter is actually going to relay to the slider what the minimum maximum and default values are okay so now we just need to create the connection so what we'll do is we will go to our plug-in editor header file give ourselves a little bit of space and now we will go to our juice documentation so this is the class that we need to create that actually attaches to the the slider to the piece of data this is in the audio processor and so this is the audio processor value tree state slider attachment class okay and as we can see from the description maintains a connection between a slider and a parameter in an audio processor value tree state okay and we see our default constructor here where we have the state that we need to use so it says it asks for an audio processor value tree state object so or a reference to one rather and we can see that if we go to our plugin processor header file that we have our audio processor value tree state object here that sits there called abvts the next thing that it asks for is a parameter id now if you remember going back to our parameters that the first argument that we gave is called a parameter id so it's just asking for that string because what it's doing is it's going into the audio processor value tree state then going into and looking for the parameter id that we're asking for and the final argument is the slider that we want to connect it to so we we're just going into our list of parameters what parameter are we looking for and what slider do we want to connect that parameter to it's really that simple okay so there are a lot of things that are happening under the hood they're a lot more complex that are keeping uh sync between different states and so on and so forth and keeping uh keeping threads in sync but i don't want to get too deep at this point in time so what we need to do is we need to create a slider attachment another thing that i want to call to your attention is that it has in the detailed description this little bit of information where it says uh when this object is deleted the connection is broken make sure your audio processor value tree state and slider are not deleted before this object this object being the slider attachment so one thing that i'll tell you and this took me a while to learn i don't know if anybody ever actually explicitly tells you this but the way that classes are created so when this test audio processor editor is actually created what happens is that it creates from the top down so if i had two sliders here let's just create another one really quick that this one if i say this is 1 and this is 2 then it creates from the top down meaning that gain slider 1 will be created before gain slider 2. now when the when this class destroys so when you delete the plugin when you close the project so on and so forth then what happens is that the order of deletion is in is from the bottom up so gain slider 2 would delete before or destroy before gain slider 1. okay so it goes from the bottom up so with that being said and knowing this piece of information that says when this object is deleted uh the connection is broken make sure that your slider is not deleted before this object do you think that the slider attachment should go below or above the gain slider okay so remember that objects are destroyed from the bottom up and we need the slider to outlive the attachment so if you said that the attachment needs to be below the gain slider then you're correct okay so the attachment needs to destroy itself before the gain slider so what we'll do is we will make this a unique pointer and the we will make it a unique pointer of type juice audio processor value tree state slider attachment and i will just call this game slider attachment okay so there we are and now that we've done that we just need to actually allocate the memory using make unique so the place to do that is in our constructor okay and so what we can say is gain slider attachment equals stood make unique that's what actually creates uh or allocates the memory and so the type of memory that we want to allocate is of type juice audio processor value tree state slider attachment and then in args we just need to give it the arguments for initializing this which is all of this so we need the first thing is audio processor value tree state and state to use so as i was saying before the plug-in processor has an audio processor value tree state object so that's what we need to get access to now how do we get access to this actual object okay so this lives in a class that's called test audio processor so this is something that took me a little while to figure out when i was first starting how do we actually get to the audio processor value tree state object so if we look into plugin editor dot h below our gain slider attachment on line 31 we will see that there is a reference and we know it's a reference because we have this ampersand that happens after the name of the object and there's a reference to a test audio processor called audio processor so a reference to an audio processor means that when you see this line of code line 31 this isn't actually creating an audio processor okay it's not creating a test audio processor this is actually just referring or pointing to a piece of memory that already exists uh of type test audio processor so so if we think of our plug-in processor or our test audio processor class it's been created it's allocated all this memory where all of this data sits like the audio processor value tree state and so on and so that's sitting in a piece of memory and now all we're doing is we're saying hey there's this piece of memory that exists it's a type test audio processor and now i'm now i want to be talking about that particular piece of memory okay i'm not creating a new piece of memory i'm just talking about that particular piece and that took me a little while to wrap my head around but the earlier that you're actually able to understand that concept the smoother your journey into learning c plus plus will be because that's really what it's all about it's all about uh pointing towards particular pieces of memory uh and so that's how we're getting access to our audio processor value tree state so with that being said our first argument which is going to be our audio processor value tree state argument is going to be audio processor which is our reference to the plug-in processor that exists and now we have access to the audio processor value tree state because if we go to the header file we see that in our public section of our class we have this audio processor value tree state object sitting there okay so that's how we got access to that and how we can call it there the second argument for slider attachment is the parameter id so as we said before we have our parameter ids so it's just a list of our parameters that the user is able to modify and this particular one is called gain and so that's how we will refer to it so it's basically saying go into our audio process or value tree state which is essentially our list of all the parameters we can hold the parameter we're looking for is called gain and then the third argument is slider that we want to attach this parameter to which is called gain slider and that's it that is all that we need to do there to attach that visual element to that piece of data that sits in the plug-in processor those two things are now connected and i will now open this plug-in up in a daw to show you what i mean so here we are in ableton and i've just opened up the plugin itself as you can see the name of the plugin is called test and we see that we have a dial here and the dial isn't as big as i would like it to be but there it is we see we see that it has a default value of 0.5 and if we look into our plug-in processor right here we see that that's the default value 0.5 and now it should have a minimum value of 0 and a maximum value of 1. and so if i turn the dial all the way down we see that it has a minimum value of 0 maximum value of 1. so we see that that has worked and that that connection has been made okay and if we take a look here just opening up this little panel we see that we have our parameter name called gain there okay so that's how that so that's how those things correlate see we have the parameter name called gain and that's how that's made and if you're asking well how do you actually open up your plugin in in a daw normally once you build the plug-in it'll put it into the right place where you can actually open up your daw and you should see it there normally it's under uh normally it's under the plug-in company called my company but in my situation i have it as the audio programmer but it's there for you so you can see that that connection has been made now so one question that you might be asking is how do i actually get this parameter back out and return it as a number that i can use alongside any other dsp that i'm actually creating so that's a very common question and i'm going to show you how so right now i'm going to do this in the process block in the audio callback and this is i'm going to console out the value to the console so uh so you're going to see it in the console down here in the bottom right but generally speaking consoling out in the process block is something that you do not want to do okay so don't do that in the process block that's a no-no we'll discuss that a little bit later but it's one of the things that you generally don't do but for demonstration purposes i'm going to do it anyway right now so uh the the command that we or the method that we want to actually get our parameter back is called so we need to go to our apvts object which is once again the audio processor value tree state so that just holds the list of our parameters and then we have this method called get raw parameter value and then we just need to find tell it what uh parameter id that we're looking for so in this case is gain if we command click into get raw parameter value we will see that it returns what's called a stood atomic float pointer so that's quite a bit for a person that's just starting off to actually understand what needs to happen with that how to actually get that value back but i'm gonna show you how to do that right now so what we could do is we will just create a quick variable right now called g and we'll set it equal to what this returns which is going to give us a stood atomic float pointer and then what we need to do is we can use the since this is a pointer we need to use the arrow and then to actually get the value back we can use the command called load okay so that's how you get actually get a value back from a stood atomic float pointer okay now what i'm going to do is i'm going to take it a step further and i'm going to do stood c out and i'm just going to cancel out this this value to the bottom right hand corner in the console there now what i've done is i've set up my x code to actually build and when it builds successfully it will actually open a daw where i can actually debug this plug-in live uh this is something that i haven't covered in any of the previous tutorials yet but i will show you in the next tutorial how to actually do this because it warrants a separate tutorial so now we're in our ableton and i'm just going to load this plugin it's called test and as we can see i've fixed the dial so it's a little bit bigger now and we have this uh we have this value that this that's displaying so this this audio callback this process block is calling again and again and that's why we're continually getting this value of 0.5 that's happening in the console and we will see that as i change it that the value actually changes okay so that's that's how we actually get that value back okay like i said consoling out within the process block is generally uh or always as far as i know frowned upon but in this particular case i'm just doing it for demonstration purposes to show you how to actually get the value back when you're actually trying to take it take the value and use it for uh use it with your dsp so that's everything for this tutorial and in future tutorials we'll be talking about things like how to actually open up your plugin uh when it builds successfully in a daw to be able to debug the plug-in live and also about different parameter uh types such as uh being able to do an audio parameter choice where you're actually able to select between a couple different options uh a button that may turn on and off like audio parameter bull and other parameter types like that so if you enjoyed this tutorial please like and subscribe and i'll see you next time
Info
Channel: The Audio Programmer
Views: 2,921
Rating: undefined out of 5
Keywords: audio programming, creative coding, audio coding, creative programming, digital signal processing, dsp, plugins, vst, software development, ableton, max msp, c++, sample rate, bit depth, nyquist theorem, juce framework, tutorial, beginner, easy, games development, games programming, basics, openFrameworks, open Frameworks, ofx, Maxim, Maximilian, audioprocessorvaluetreestate
Id: xgoSzXgUPpc
Channel Id: undefined
Length: 19min 31sec (1171 seconds)
Published: Thu Oct 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.