JUCE 6 Tutorial 01 - Using Namespace Juce: What is it and Why Shouldn't I Use it?

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 we're going to talk a little bit about the juice namespace in juice 6 the juice team have decided to make it mandatory by default to use the juice namespace before you instantiate any juice classes or objects now the question is what does that mean for you and i'm going to show you in this tutorial so let's go ahead and create a new juice project so i'll just do that by going up and saying file new project and here we have our new project i'll just create a plugin we can just call this i'll just call this sample uh sample plugin and i will create it just put this on my desktop and now i'm going to have a new project here that has all of my files and what i could do is i could go up here to the settings and i'll show you this new setting here down here it says add using namespace juice to juiceheader.h and this is disabled by default okay i'll show you what this means right now so let's go ahead and open this up in our ide so just click the center button and this will open our project up in xcode and here we are so normally in a juice tutorial if you've seen any of my juice tutorials in the past we could just instantiate a juice object just by typing the name of the object so for instance if we had the slider class we could normally just say slider like this and we can just compile and it would work but as we can see we're going to get a build failed and it says the error is unknown type name slider did you mean juice slider and this is what i mean by using the juice namespace in front of any juice objects or in front of any juice classes that were instantiating we would need to put juice in front of this class so let's go ahead and try to compile it again and we will see that we will now get build succeeded now the question is why have they decided to do this does this not make things more complicated the reason that they've decided to do this is because sometimes you would get name collisions when you're using multiple libraries so let's say for instance just a hypothetical scenario that we had two ui classes that had a class called slider when the code's trying to compile and we don't have any namespace in front of this slider if we have two ui kits that are both using the class called slider it wouldn't know which slider that you met that doesn't mean the juice slider or doesn't mean this slider from this other library so that's the reason why they have made it where you need to put the name space in front of it and specify that this is the juice slider okay so i'm going to show you a few little tips to help with longer uh names so one of the things that i noticed when i was first starting out when you have these really long name spaces if you get very long to read out so for one i'll give you one example here so we said something like stood unique pointer and then we said juice audio processor value tree state slider attachment and i'll just call this attach one like this let's say we had a couple like this all right and i will do like this and i'll just name them two and three so i remember when i was first starting out this looked like very long and very confusing to me okay so one way that you can abstract this out is by using what's called the using keyword so we could do something like this using attachment equals and then we can make that this long thing here and then what i could do is now i can within this within the scope of this code with so within this header file anywhere where it says juice audio processor value tree state slider attachment i can now just replace that with attachment like this okay and so sometimes that helps to clean up some of the code as well but one thing that i'll say is in terms of best practice it is best practice to use the juice to put the juice namespace in front of the objects to prevent name collisions for smaller projects smaller plug-ins where you're not using any sort of external libraries it's probably okay but in general it's best practice to use the juice name space in front of these objects okay so sometimes you'll see this like a using keyword so using some word some keyword equals this long bit of of nested code right here another way that uh that you could do this or another way that you'll probably see in some code bases is something like this where the hole where you could you use namespace juice like this and then you need to put closing parentheses like this and now anything that's in here that is supposed to be a juice object you can now you don't have to put juice in front of it okay now if i compile this uh what will happen is this will build this build will fail because what i need to do is i need to do the same thing for the cpp file as well okay so in general it's it i guess it depends but uh in general i wouldn't advise to really do this but some code bases that i've seen have really nested namespaces and they're very very long so sometimes you have to do this where you have namespace juice and then sometimes inside inside that you have some sort of other namespace and that what this basically means is that anything in here that has a juice object it'll automatically put the juice namespace in front of it okay and let's try to build here make sure that this build succeeds okay we got a fail unknown type name okay so we just need to put juice in front of this as well like that and now we should get a build succeeded okay so now we got build succeeded just to show you that that works okay so another thing that i'll show you so let's just go out of all this back to the beginning okay like this is that another thing that you can do is you can actually enable the using name using namespace juice like this then we open up in our ide and this will bring you back to the quote-unquote old way where you just instantiate without needing to specify the juice namespace but i would say in tutorials moving forward what we will look to do is we will actually look to do this in the way that i would that i've been told is the best practice which is to use the juice name space so moving forward we will now do it like this and use juice slider rather than just a slider so those are a couple tips to give you some help i hope that that was helpful for you and if you have any questions or if you have any better suggestions please leave a comment below and i hope and uh don't forget to subscribe and drop a like on that as well and i'll see you next time
Info
Channel: The Audio Programmer
Views: 4,047
Rating: undefined out of 5
Keywords: juce, juce framework, dsp, digital signal processing, vst dev, audio dev, audio software development, realtime audio, music tech, music technology, c++, cpp, c plus plus
Id: cJtx30ZRl_0
Channel Id: undefined
Length: 8min 57sec (537 seconds)
Published: Mon Aug 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.