Juce Tutorial 44- Audio Processor Value Tree State Update 2018 (Creating Plug-in Parameters)

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 a Happy New Year to you this is the first tutorial for 2019 and I'd like to just take a really quick moment to thank everybody that has supported the audio programmer and the channel in the community up to this point the support has been really strong and we just hope to keep on building this for the new year so I'm not gonna really get into that because it's supposed to be a tutorial but maybe I'll do a separate video well I'm kind of a 2018 recap or something like that so before we get started if you like this tutorial be sure to give it a thumbs up and feel free to comment on it with any sort of feedback positive or constructive we're always looking to try to make these tutorials better so we really appreciate your feedback so yeah be sure to let us know what you think so this tutorial is going to be on improvements to the audio processor value tree state class so this is the class that juice uses in order to create parameters so you have parameters that you can modify over time like let's say a filter cutoff you want your user to be able to modify that over time and create automation and have a little drop-down menu where it says filter cutoff where they can choose that and then and then basically change that over time and so this is how we create those sort of parameters and it's also a way for us within our plugin to be able to pass these values around between what's happening with the UI and what's happening behind the scenes with the processor so if you're not sure exactly what I'm talking about that's okay I would advise you strongly to go back to juice tutorial 13 which is audio plug-in basics and just basically watch that one and then probably the next three or four ones that talk about the plug-in the difference between the Eddy editor and the processor and then we have another one which is let's see here so we have the this is mainly an update to juice tutorial 16 which is creating plug-in parameters for user automation so this is an update to that because we have some breaking changes that have happened with the audio processor via Tree State so this has changed and we're going to update that so this is art this is a subject that has come up a couple times in our discord discussion group and and so I thought I'd do is tutorial just to show you the breaking change is the old way of how we used to do things and then now how we need to change that to make it the right way what I've done is I've created a small little project it's just a game tutorial once again it's just based on that juice tutorial 13 and 14 which is a slider that turns volume up and down it's about the most simple type of plug-in that you can create and what we're going to do is we're gonna go through the old way of how things were done which I have here and I'm gonna also got it on a uploaded it to a git repo and I'll put the link to that below so you can follow along and make the changes along with me and let's see so let's go ahead and get started I'm just gonna walk you through this really quick so we just have to defines called gain ID and game name that's just so I don't have to type in so I don't get mixed up and when I'm when I'm looking for for a parameter ID I can just type gain ID and I know that that's what I'm referring to if we go down to our constructor here then we can see that the old way that we had it initialized using tree state so we have an audio processor value tree state object called tree state we have initial initialized that using the initializer list this is the old way of how we used to do it and then what we used to have to do is we had to use this method called create and add parameter and then we had all of these different parameters that we had to add in order to be able to add this now if we scroll down a little bit further to our process block then we will see that we are just naming a variable where we get the value from the gain ID and then we are using that to turn the volume of the incoming audio up and down once again if you have no idea what I'm talking about there and you're not sure what I mean by that make sure that you go back to those other tutorials because I go through all of this stuff in just very in very fine detail so make sure you go through that first and you know what I'm talking about or else you'll probably be a little bit lost in this tutorial so if we go over to the editor side here really quick there was an error that came up commonly in in the tutorials and where they were saying that they were basically getting a crash when they would close the UI and we're going to go ahead and fix that too and I'll show you how that how what that was happening so we'll go ahead and we'll start there so the first thing that we have is that as we went through in the first audio processor value tree State tutorial we have two sides that we need to create in order to to create a audio processor value tree State so you have the parameter that we have on the on the processor side and then we have the attachment that we have on the UI side so the idea is that when a user changes a parameter on the UI that this attachment will relay the value change over to the processor side and then the tree state captures that and then we can and then we can get the value of what the user changed it to which would be here and then we would just use that in our actual audio callback so first thing that we want to do is this scoped pointer is actually deprecated but before I do that I'm gonna tell you why it's why it was crashing for so many people and this was a mistake that I made the reason that it was crashing is that because when you're when you're plugging destructs when you close your plug in what happens is that each one of these destructs from the bottom up so the first thing that destroys is the gain slider then you've got this object that destroys and then the slider value now the problem is is that we don't want this slider attachment to destroy itself before the slider itself okay so we need this to to destruct before the slider so in order to do that so the way that things destruct is from the bottom up okay so what I need to do is I actually need to put this below the gain slider so I'm just going to cut that out of here as you can see we got public access and we still want public access because we need our processor to be able to get the value so what I could do is I could just actually just put public here and then I can paste that like that okay so now that's going to destruct in the right order the slider attachment destructs then the slider it self-destructs so now as I said before a scooped pointer is now deprecated in juice and you can find out more information about that on the juice forum if you'd like so what we're going to do is we're going to actually change this to a std unique pointer so we can go STD unique pointer [Music] it never does my autocomplete when I what happened in the middle of the tutorial so it's just basically all the same stuff here so we got this and then I can just get rid of the scoped pointer like so okay so now we're like this now when we actually allocate memory so the if you know about pointers then the pointer is allocating memory when you go to allocate the memory on the heap here using new that's changed as well so when we're using a unique pointer we can just do you can use the make unique method as you can see it's complaining here and it's saying that this ain't the right we're not making the right call here so what we need to say here is slider value equals stood make unique then we got audio this is what we call it audio processors value straight tree slider attachment object and then our arguments here we're just gonna cut and paste just like so okay so now we can just get rid of this okay so that should be fine now so that's our slider that's our slide our attachment set up and as I said this is what's allocating the memory on the heap for our slider attachment so now what we need to do is we need to go to our processor side and we need to update our our value tree state so as I said the here's our where we've created our object the tree state object here now if you go here and you notice here we have a little warning says create an ad parameter is deprecated and if we tried to run this right now I'm not gonna do it but if we tried to compile it would compile but once we tried to open the plug-in it would actually say it actually wouldn't work properly and so what we're gonna do is we're going to use the documentation here to help us update this method so if you look down here so we have our constructors so this is what we need to do to initialize our our tree state so you can see here that the old one that I used where I where I have the processor object which is this a pointer to this and then and then the undo manager which I have pointing to nothing and if we look at the documentation here we can see that it says this constructor is discouraged and will be deprecated in a future version of juice use the other constructor instead so that's what we're gonna do so now I'm just gonna copy these arguments here so this is our other constructor that we're gonna use and I'm just gonna paste that here so now we have processor processor to connect to so I'm gonna do this then it says undo manager to use I'm gonna do null pointer so we're not going to use an undo manager so now it's gonna say here Const juice identifier and by you tree type so obviously I've gone through this myself before but let's just say that I don't know what that is and for for people that may be starting off just starting off with juice and you say okay juice identifier I don't know what that is right so then we what we would do is we would just go to the juice API here and then we would just we would just go to identifiers and it says represents a string identifier right so this is just what we're gonna call the treaty state like if we want to if we want to refer to the tree state was a string name that we can call it because what we could do is we could actually if we had more than one processor that we were using within our within our application then we might have multiple tree States so we need to know which one that we're referring to so we'll just call this params or parameters parameter all right so that's a string that's fine then we have this one that says parameter layout okay well what's that well let's have a look and see so I had yeah here we go so this says a class two could contain a set of ranged audio parameters an audio process of parameter groups so as you can see this is where we would actually put all of our parameters so where we were before where we were creating and adding parameters we would put all of that here now so I'm just going to I'm just gonna comment those out for a second luckily on the audio processor value tree state documentation if we scroll down a little bit we will see that they've actually given us a nice little kind of example of how to do this right so we can see here that we could just do it like this right so let's just try that first okay where we would just say so we see here that we have a lot of different types of parameters that we can use we've got audio parameter float you got audio parameter int you can use audio parameter boolean you could only a parameter choice so this is for stuff like checkboxes and and menus and things like that but we're doing a gain slider values so we're gonna use audio parameter float right so we're gonna have to so what we're gonna do is this one we're going to just do like this and then we're going to add our first parameter here which is going to be a unique pointer and then this is going to be an audio parameter or float then we have different arguments that we we have arguments that we need to put in here so there's a really long one here that we can use I'm gonna use just this short one so you can see we have two different types of constructors here that we can use we're just gonna use this this one here I'm just gonna copy this like so since it's within a pointer it doesn't autocomplete for us nicely so here we're just going to use the defines that I pointed out earlier the tutorial gained ID game named alright so with that gained addy game name minimum value I'm gonna just put at -48 DB the F is just to make sure that doesn't get casted as a double or anything that it stays as a float and then we got max value we're gonna put at zero point zero and then the default value let's just put at minus fifteen make sure you don't get these wrong because if you do it'll kind of blow your eardrum out when you try to we need to try to play it and it's not a very pleasant sound so so that's so that should be fine right so so basically within these curly brackets here you would put all of your all of your different parameters okay so instead of instead of using the create and add parameter method here so we could just actually get rid of that right so if I wanted to add another parameter like let's just say let's just say for examples sake then I wanted to add another one I would just do that like that see just like that and then I would list them all just one after the other just like that okay I'm going to show you another way to do that that because as you can see if you have like 10 parameters or 50 parameters that would get quite long so I'll show you a way another place that we could put that in just a second so let's just look make sure that we have everything right so we've got decibels to gain here so that's going to take our decibel so so our our number and it's going to convert it to a gain number between 0 0 and 1 okay so I'm just going to compile here and we should be good to go ok cutoff mice out there for a second so let's go here I'm going to add this now I'm just going to turn it on there's our UI so now I'm gonna add the audio file player here and I'm going to just add an audio file here just add anything here we go some Anderson pack so I'm just gonna turn this down because I'm in my headphones don't want my ears to blow out if I got this wrong so as you can see it works [Music] there you go it works pretty simple right so so that's the only thing that you got to do the only new thing that you got to do but now let's let's talk about a way like if we wanted to create a bunch of these parameters right this is something that I got from Tom Pole who's one of the senior developers that works on the juice framework hi Tom if you're watching this tom is the man so what we're gonna do is we're gonna add a method here I'm gonna add it up a little bit above here I'm gonna put it just right below the destructor here so so let's go over here if we're gonna add it here so now let's just think about this right I think this is actually shown here right so here's here's I think Tom actually wrote this so it just says okay so we're going to create a method right it's gonna call create parameter layout and what we're gonna do so we want the return type to be a parameter layout because that's what we need to that's what we need to put in to our our arguments for our value tree state right so so instead of having this here we just need to have the name of our parameter layout so we're gonna create one right and then this is so this is just like creating your parameters I'll show you how to do this so so what we need is we need a method where we're gonna call this audio processor value Tree State our parameter layout right is that right parameter layout create what do you call it create parameter layout so I'm just gonna call that okay so so our return type is going to be an audio process or value tree state parameter layout right so I'm just gonna take this and copy this I know some I know some of you more experienced users will probably thinking why is he going so slow well because there are a lot of people in here that are just beginning so just bear with me because I mean I'm just starting to sew so what we need is we need our fully qualified class which is this gained tutorial audio 3 audio processor and then we call it create parameter layout ok that could be a little bit confusing if you're just starting but that's the correct way to do it okay you have your return type and then you have your fully qualified class and then you have your method name ok so now what we need to do is we need to create a parameter layout ok so the way that he's done it is he's used a vector of unique pointers right so I'm gonna do this a little bit differently than how he did it here because he's got here audio parameter int and what we need is audio parameter float but you can actually do this in a way that will take all all of the different audio parameters whether it's a bull or a choice or enter a float okay so we could do that here so we'll do stood vector then this is audio processor value tree state and then this is going to be called actually I don't even think I need this sorry about that I think it's called ranged audio parameter yeah so if I if I go here you can see arranged audio parameter kind of encompasses all of these things so you can see here we got int float choice and pull all kind of pointing there to the parameters that means that this is a superclass is that right superclass of bull choice float and int I hope I got that right so and this needs to be a unique pointer as well so let's do this unique pointer and then this is an arranged audio parameter okay and then I'm gonna just call this params so this is our container where we're going to put all of our all of our different all of our different parameters right so now I'm going to just create a variable that will be this our gain ID now right so I'm just gonna call this we now we're going to use the auto keyword here all right so dude deep deduces the return type for us so we're gonna call this gain let's say let's just call it game program right and then I can just say like that right so we're just gonna call this auto game program is our pointer now what we need to do is we need to we need to add this push it back into our vector so we can we can do this more efficiently I'm gonna chime going to show you the more efficient way to do this that we could actually do like params pushback right most of you would probably know what that what that's all about and normally we could just say game per am alright and that's fine that'll actually I believe that'll actually work but I don't know it doesn't work actually so so what we need might need to actually use this method so it's called stood move and then let's see if that works and then we need our return type yes so stood move actually moves it actually doesn't copy so so normally if you do push push back this is my understanding I'm kind of a beginner at this so my understanding is that if you're normally if you're doing just a pushback operation you would need to actually copy the this this this object here and then it would basically copy over and then it would delete well stood move actually is able to just move that information over without actually copying and so it makes it more efficient basically that's my understanding if I'm wrong about that or if there's a better way to explain it feel free to comment and and correct me I'm always trying to learn so now we need to just return this as parameter layout so we could just say return programs that begin right so we just we're just going to return this vector programs end and then what we can just say here when we when our layout up here in our in our constructor for our tree state we do just say create create parameter layout so now let's see if this actually will work hopefully thing Crosstour I'll have to do all of this again okay so here we go so I'm just gonna pop up in the UI here so nothing's crashed just yet which is a positive sign and then I'm just gonna add my audio file player just gonna plug these in real quick then I'm going to load up the song that's down so it doesn't blow my ears out boom there you see it works so I hope you found this tutorial really helpful for you once again all we did there was we just went through the new way of creating an audio processor value tree state and how to initialize those parameters and we created a really quick method there create parameter layout and where we created a vector of ranged audio parameters and then we created our our what's it called I'm losing my head here are our parameter and then we just pushed it back into the vector and then we just added the whole list so we could add as many as we wanted there and we would just push all those back and then we would just add that and then just call this method so I hope you enjoyed this tutorial if you have any questions or anything just feel free to comment in in the video or to join our discord platform chat platform where we're able to help each other out and I hope you enjoyed this tutorial and I will see you next time
Info
Channel: The Audio Programmer
Views: 5,820
Rating: undefined out of 5
Keywords: juce, juce framework, c++, audio, tutorial, audio programming, creative programming, creative coding, dsp, digital signal processing, vst, create vst, create plugin, audio plugin, oscillator, synthesizer, maximilian, openframeworks, software development, beginner, easy, max msp
Id: NE8d91yYBJ8
Channel Id: undefined
Length: 30min 42sec (1842 seconds)
Published: Wed Jan 02 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.