Juce Tutorial 46- Creating a Transport using the Tracktion Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up everybody I'd like to welcome another juice tutorial and today what we're going to do is we're going to start digging into the traction engine a little bit so a lot of people have been asking me to create a tutorial on the traction engine and of course one of the challenges is that we don't really have very much documentation on the traction engine itself so what we're going to do is we're going to try to create something super simple so I was thinking is today we could create a very simple transport so transport is what you see in a da W where you can actually play your project or stop the project and so I thought one of the easiest things that we might be able to do is to actually just create a transport object using the traction engine and to actually just console out the time that's on the transport okay so nothing really difficult but the main idea is to start thinking of the traction engine as a da W from the perspective of a developer or Audio programmer and that's what the main objective of this is to do so we're going to create two buttons just play button and a stop button that will start the transport and stop it okay and I'm going to create an audio application and I'm just gonna call this traction and support and I'm gonna create it and I'm gonna put this up on my github after I'm done so you can have a look at it see what I've done here so this might go a little bit slower than what you might be used to with the tutorials just because like I said there's not very much documentation and we're gonna need to dig in to the traction engine itself to see if we can find these things that we're looking for now the first thing that I'm gonna do is I'm gonna actually close Xcode back out because what I've forgotten to do is to add the traction engine module so the way we do that is go to our modules in the producer we can hit plus then it says add a module from a specified folder okay and then I'll go to my development folder and then into my third-party libraries and then into tracks and engine into modules and then we have this folder called traction engine which holds all of our files that we need in order to call the traction engine methods so I'm just going to add that here as we can see it's in red there and if I click on it it'll say that it has missing dependencies that we need the juice DSP module to build it correctly so I can just click add that as a dependency and now we are good and I can open this up in Xcode so this as I said this might go a little bit slower than our normal juice tutorials I hope you can bear with me and we can all learn together and some of these things might not be the most efficient way or you know there you might have a better way of doing some of these things and if you do I welcome you to make comments below because we're all trying to learn these things together and trying to become better audio developers so if we go into the traction engine here we can see and I'm gonna open up a new tab here with command T and what that's going to do is that's going to let me just kind of have the traction engine header file here where I can just continuously come back and reference this okay so here we are in the traction engine header file and I'm also going to pull open one of the traction tutorials just to reference just in case we get lost along the way here and I could do that just going into tutorials I'm just going to try this play back demo here and then I've just got some stuff here that'll help us along the way if we get lost so first thing that we're going to do is look at this traction engine header file and what we can do is we can just scroll down here after all these defines and then we see that we have name space which is traction engine then here we have a whole bunch of classes so this is everything that you would think of that encompasses what's inside of it all except for the graphics okay so pretty much anything you can do in addy aw will be somewhere in here it's just a matter of actually finding it and pulling it out so so if we go back to the tutorial so we're just going to start this like I said you know people have have made comments hey can we build addy aw together and things like that and now I don't really have the skill level to build a D aw that's the only reason why there are maybe only like five or six main D aw use that are out there on the market they're pretty they're pretty hard to build but what I thought is that we could just start really super basic and like I said more than anything is more about gaining an understanding or a better understanding of what how to navigate through the traction engine and get some ideas of how to see ad aw from an audio developer's perspective okay so the first thing that says here is that we have this engine class so every traction engine app starts with an engine instance this performs the initialization and shutdown of the engine okay so first thing we need to do is create an engine instance okay and we have a class here that says engine and I can command click in there and here we have the engine class so the engine is a central class for all traction sessions create an engine before creating any edits okay so we're just going to do that and as we could see here we've got three default constructors so we have three constructors we could choose from rather and I'm just gonna go with this simple one which is this one where it just takes a Asian name as a string and we're just going to do that okay so if we go back here we can declare our class so we so the namespace is traction engine and then we need to create an engine so that's how we're gonna do that here so go traction engine and then believe that scope resolution operator there so engine and then I'm just gonna call this engine and then since we're initializing here we need to use the these curly braces here like that and then we could say we got a string which is called the application name now it would be perfectly fine if we were to just say just call it whatever we called our project which is traction transport pretty sure that that will work so let's just try that just build really quickly while we're building uh as I've said before you know in all the videos if you if you're finding this helpful and you know you liked the video be sure to give it a thumbs up and also subscribe and if you have any sort of feedback constructive or positive I'd love to hear it be sure to make a comment below okay so it's building at the moment and it looks like it's gonna be fine so so while it's doing that I'm just gonna open another tab here I'm gonna show you a little something so if we go to if we go into our juice header file here so as you can see we only have one include dependency here from juice juice header dot H and if I could if I click in there so I'm gonna go back over here sorry it's being a little bit slow so if I just come and click into here good jump the definition to look into what juice header is we can see that it says this follows auto-generated each time you save your project and that so this is what the produce or actually generates when we when we actually open things up in Xcode and this includes all of the dependencies all the modules then we need to use as you can see those line up with what we have here on the left under juice modules that if we scroll a little bit further down then we see that there is a namespace called project info and inside there we have where we can say our name called traction transport so so this is another way that we think that we can tell that the traction engine what are the name of our project is just in case we at some point go back and we actually want to change the name of it so let's just go back here so as I said you know says project info then we use the scope resolution operator to access this project name so I can just do that like this okay so I could go project info project name okay and we will just try to rebuild that again just see if that works that should that should be fine okay so we can see that build succeeded there okay so that's fine for the traction engine okay so now if we go back here and we go to the second part so we see that says edit is a container for a playable arrangement okay so we need one of these if we're going to build a transport so what we need to do is we need to go back into our documentation here and then we have the edit class so I could command click in here and then we see that we're inside here so now we just need to create an edit object so we could do that using these parameters here so this is our as we can see this is our only constructor so we need to declare these things when we create this object okay so this might take a little bit of messing around but hopefully we can we can get through it together so we've got traction engine edit edit object and I'm just gonna call this edit but then I'm just going to throw those in there then we're going to go through these one by one so the engine this is a reference to it to an engine object so we just want our engine in there so just value tree so this is something that I have to have a look at and really think about so my first instinct was okay well I'm just going to create a a value tree object here and then just put that in there that might work I don't might work I don't know if that works or not but another way to think about this and one way that I've learned that I was looking for from the examples was that if we go if we have a look into this section so here we are in the traction engine that the traction engine module then there's a section that's called model that's like all your data model stuff then if we go into edit there's a section here that says edit file operations okay so my understanding of this so it says contains methods for saving and edit to a file so my understanding of this is of course you know you would have your audio process or a value tree state that you're normally where you'd have like your parameters and then you know you're changing your parameters within your project and then you want to save those and those would save to your value tree and then if you want to restore them then you basically load that value tree back up so that is what I understand this is all about okay and I think that that makes sense if we scrolled back down a little bit further we can see that we have we have methods here where where we can load an edit from a project manager we can load it from a file okay like we're loading a project and it looks like maybe back in the past they've used the XML to actually save these so what we could do is we could just create an empty edit with no project okay so what I will do is I will say traction engine and then I could say create empty edit okay so let's just try that so we've got stretching engine create empty edit okay so that should be fine it's complaining at the moment but I'm going to just leave it for a moment because it might be because these other things haven't been initialized correctly yet so now we need to go back in here back down to our traction engine into our edit and wait for this to bring us into our edit file here so so now we have this thing is called an edit role okay so I'm not really sure what to put here so I'm just gonna put for editing okay cuz that's what we're doing I guess so I could say traction and edit for is it capitalized or not for editing okay then we got load context they they set this the null pointer for the examples that I saw I'm just going to do that for now and then number of levels undo levels the store I'm just gonna put 0 for there and it's complaining why is it complaining so what's it saying here says is it complaining hmm it was like it was complaining and then it stopped complaining let's see let's see if it's working oh it's working now okay wait mm oh I got something happened I've I've done something wrong here so this isn't right something's not right here so I got create empty at it traction engine edit and so it's edit role that's that right oh no that's not right just gonna move try something else here okay so don't crash haha cool all right I'm good now I think that yeah that's not really an error okay cool so that's fine so I needed to do yeah because it's within the Edit class so it's an enum within the Edit class so I needed to do traction engine edit edit role for editing okay so that's why that's why that's that is how it is okay great so that's fine for now so now let's let's shift gears for a second and let's try to do let's try to think about these these buttons so we need a play button then we need a stop button okay so we can use the text button class for that play button okay so let's just go to the API right quick here we go so we're so here we are in the text button class and so we can look at the default constructor here we can do it we could just not have anything here or we can give it a button name so I'm just going to do that here so play button I'm just gonna call it play then I've got text button stop button I'm just gonna call it stop okay so that's all fine okay now what we need to do is we just need to give these some just do some some things with them to actually make them visible and that sort of thing I'm just going to change the bounds of this I'm gonna do 200 by 200 get rid of all this stuff so I'm going to do add and make visible play button so that just makes it visible to make visible stop button okay now we need to what's next okay so let's just let's just draw these really quick okay so we could use the Flex box class okay and I think I could actually initialize these with the initial settings so let's go here let's go back to flex box okay so now we got so here we can just defined our what we want here so I'm just gonna copy these I'm gonna paste them in here so then we've got all of these different kind of enums so we've got flexbox Direction flex box wrap a lot of content line items justified content so we're just going to do that here so we've got a flexbox direction and then we want row right then we got flex box wrap no wrap so we do I need to wrap around give you a flexbox a live content just say stretch I guess good do flexbox wide items so we got here stretch I guess then we got flexbox justify content I just put full center ok great so that's initialized and now we just need to use I think flex items here so so we're just gonna go into that really quick so now we got so now we want this one flex I don't can I do this I'm just gonna try something super quick I don't know because because we have this flex so so we have this array of flex items that we can add I'm wondering if I could just do this all in one step so we got flex box items dot ad right because we're so so we're just in the array because because this is a returning an array a juice array so we can actually add in here so now I could do I think I could do it like this so I could do flex item then float with lists I don't know let's try since it's a hundred by since we're 200 by 200 I'm just going to try a hundred by a hundred and then we're gonna do play button here okay flexbox items ad then we'll do flex item 100 100 stop okay and then how do I know how do I tell it where to perform the layout again how to perform the layout so where is it perform layout that's on the on a rectangle object so we need to create a rectangle object so just do rectangle and downs get local bounds so we're just getting the bounds of the area of this component which is going to be 200 200 and then I should be able to just say flexbox perform layout and then on the bounds and then let's just see if that works okay so there we go we have a play button it's not doing anything in a stop button okay so now we're going to so let's think about this so we need to have something so we need to have something that happens when we hit the play button right so so let's just create a method we'll just call it void play and we'll create another method called void stop I'll throw these over here so we've got void main component play and then I'll just do the same thing here void main component stop do that here and I'm just gonna hit this just to make sure that I've actually initialized this properly okay so that's fine okay so now so okay so now when we hit so now when we hit play when we hit the play button we want it to play right so now let's just do this so we can go back to our text button class okay now we need a method that says what happens when we click it so I believe that's in button and here let's scroll down here a bit so oh yeah seeing a I've seen a couple methods that I need to to do here so first one is we need to we need to set the toggle state okay so we need to have the whether the buttons on or off right so to start off with we can say play button dot set toggle state we're gonna set this to false because we want the button to be stopped we want we want it to be stopped when we first start the application and then we're just gonna put a notification type to don't send notification okay and then I'm gonna do the same thing here for the stop button the stop button set toggle state I'm gonna set that to true and then I'm gonna do notification type don't send notification okay so that's fine now what else do we got here so do we have I think it's all on click is a component component method maybe [Music] so let's go back here okay I know that there's a method called unclick I'm not sure where it actually is or is it just looking for it I don't want to just maybe it's from that's sure where it is actually oh I know that there's one in here I'm just for times sake I'm just going to hope you trust me that there that it's in there somewhere so we got play button that on click okay and then we can see that we have a sed function here void so that means that we need to put a lambda in here okay I'm just going to actually just go in here see where this actually inherits from so so it inherits from button I thought I'm just going to says public met remember functions from button on click weird I'm not actually seeing it though I'm actually in the text button class yeah oh here it is yeah so you can assign a lambda to this cop callback object to have a called when the button is clicked so all we're just saying here is when the buttons actually clicked I want something to happen so we could just say play button on click and then we can use the lambda function here so I'm not going to explain what lambdas are at the moment because there are plenty of places to do that and that could be a whole bunch of tutorials so what I'm just gonna say here so in essence this is saying okay when I hit the play button I want it I want this method to activate play okay I'm calling it on this object this object being the play button okay and same thing here I'm gonna do stop button on click equals so I'm calling it on this object I'm just gonna call the stop method okay we haven't actually we haven't actually defined what that is yet but we're going to okay so now what we're going to do is we're going to make so what we need to do is we need to have different states don't we where we're defining if something is playing or some if something's stopped and if something is stopped we want it to play and if something is playing and we have to stop on when what it's stopped okay so we could do that using a enum class so I'm gonna do enum class I'm gonna call this place date okay remember to put these let me pull in at the end there like so and I'm just gonna say play I'm gonna say stop so this is just a little something that helps me just define when something's playing there are certain things on what to happen and when something is stopped there are certain things I want to happen now I'm sure they're they're gonna be you know this isn't going to be like foolproof code here you know this is just like something super quick so let's do okay so so let's just do we have to create a place state object so we've got play state play state we can just give it a default value here so we could say play state stop okay because we when we start the application we want it to be stopped when we when we first start we don't want it to be playing as soon as the application starts right so now here I can say something like this is just something to just start me off in the mentality right so if the place state equals place state if actually don't don't crash please don't crash okay play state equals play state so if we say if we say stop right start like this then we can say place state equals play state play all right this needs to be capitalized by the way okay okay and then we'll just do the opposite here so if play state is equal to play state play play state equals play state need to capitalize these state stop okay and now okay this means to be capitalized now what I'm going to do is I'm going to just test this out just see if this works so I'm just going to put stopped I'm just going to put play here just to make sure that these buttons actually actually work right that's what we want to see so now we're just gonna build and see if this actually works so when we when we click the button when we click the play button it should say play right here right so it says play now it says stopped so that works fine right so it appears that everything is cool so far so now what we need to do is we need to connect the transport to so the transport from our traction engine to these buttons right so I'm just gonna get rid of some of this space here okay so now so let's think about this right so let's have a look at edit so I think so I think this is where we can actually get a hold of our transport so if we just scroll down and check out the methods that we have here so just just scrolling down there okay I'm just gonna look for transport okay so we've got a method here that's called transport control get transport right so that gets so that gets our transport so that'll give us a pointer back to our transport control object okay so now what I could do so let's have a look and see if this works right because I could say I'm just going to comment this out for a moment I'm going to say edit so so because this is in art this is in our edit our Edit class right so where is that method edit get transport so it needs to be traction so we need to go back into traction engine so we got edit get get transport right hopefully this shows up Oh actually I'm sorry we already have an edit we have an edit object so we need edit get transport okay so we've got edit get transport now what we could do is so get transport returns a pointer back to our transport control now if I click into transport control I have all of my transport control methods right so so as you can see we're in traction transport control and now we have a whole bunch of methods methods like play okay so you could say okay let's just try it right so it's a pointer so we need to use the arrow operator it's not Auto completing for me so which makes me always a little bit funny so just send mm CI mm see if in it if enabled I have no idea what that means I'm just going to put false here I guess just see just see what happens you know to see okay did it OH transport control is not a pointer so is it just like that did it did it work okay so I'm just going to erase this for now okay and then I'm gonna try to do this for the same I've been do edit get transport stop okay discard recordings will put true clear devices false I guess we know how many devices really okay so now so now that's that's all good I think that's fine so now we need to let see if there's any way that we can actually get the time right get time when started so we've got get current get current position so we've got get current position I'm just gonna so this is bad practice here if we were actually doing any sort of audio stuff here but I'm just gonna throw this in here I'm just gonna throw this in here the girlfriend's trying to walk in on me while doing this tutorial so so we need to check if it's actually playing so we could do we could do is playing we could use the is playing method so while edit get transport is playing and then let's do so we'll say we'll just call this time I can use this and I could say edit get transport dot get it's a good current position just just looking for the right method here so I think it's get current position let's just try that so the idea is that when this is playing hopefully it will actually console out what the current position is let's see if it actually works so here's my thing okay so it's not actually outputting anything okay so I'm going to just comment these out for a second so see if this actually works okay it's not actually outputting what the time is hmm okay so let me make sure it's actually going through the audio loop a little bit of live debugging here so see if this actually okay it's not actually going through the lube itself what's up with that what have I done let's get next so something's happened here or it's not actually calling the audio block what's up with that not sure why it's not doing that hmm let's see we just try this it's only gonna execute this once I'm just curious if it weird weird very weird when I hit play it's just going to execute it once yep seen that so it's so that's executing once why is it not executing over and over again okay so okay I'm going to try oh man so I'm gonna have to do a timer callback here okay so let me see if I can do this this is just really on-the-fly see if I can see if I can do it like this timer see if I actually know anything or if I'm going to need to start this tutorial again okay so we'll do timer call so now we need a timer callback which is a virtual method see if this actually so we do avoid timer callback I need any parameters now okay so now I'm gonna put this in here void main component timer callback this needs to be marked overrides this is a pure virtual function okay I'm just gonna do this see if this actually compiles oh no what's happened oh that's what happened wrong okay let's see if this works okay so that succeeded so that's fine so now I can should be able to throw this in here so now I need to actually just define when it actually starts okay so so we could have it start whenever when we hit play and then stop when we hit stop right so we'll just do start timer sets the interval so we'll set it I don't know every 10 everyou every 100 milliseconds maybe so we could do something like this where we say so I need to create a timer object right so I'll just call this timer timer then I'll say timer start right is that right timer start timer 100 let's see if that actually works okay unimplemented timer callback okay so let's go back oh I need to I need to do something in here so I did time a callback so okay so why is it it's about the timer callback oh it's an abstract class okay so that means that I don't actually have to clear declare an object so should be something like this primer start timer okay so that's exceeded okay then I'm just gonna start stop the timer stop timer set right stop timer okay so let's see if this see if this actually works after all this oh man my tutorial isn't Oh 50 minutes Wow okay so play hey hey it works oh my goodness I can't believe I actually made it work oh that's so cool yeah so cool there it is it starts and then it stops we could just start it again stop it again and that's it yes that's the transport there so that actually works holy cow that was really I was really panicking that I'd have to start that all over again but yeah it works amazing cool so I hope that wasn't too long-winded for you and I hope you liked this tutorial like I said I'm going to go ahead and upload this to my github and feel free to expand on it and I'd love to see what you come up with and well we'll expand upon this idea in the next tutorial so I hope you enjoyed this and I will see you next time
Info
Channel: The Audio Programmer
Views: 2,017
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, tracktion engine, tracktion, transport, audio programmer
Id: 10dkMCtmSpY
Channel Id: undefined
Length: 52min 1sec (3121 seconds)
Published: Sun Feb 03 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.