In this screencast, you'll select the main music track for your DJ Mixer and add a soundthat plays when the spacebar is pressed. This screencast will walk you through creatingthe code, then you’ll try it on your own.
With DJ music, there is usually a consistent sound or repeating musical loop that underliesthe entire track. Then, the DJ chooses other sounds to insert and play over that track.
You need to choose a repeating musical loop that will play behind whatever your DJ addsto the music. To do that, click on your DJ sprite, then select a sound that is a musicalloop from the Music Loops menu. A music loop is a sound that is designed to play over andover to make a continuous song. Add blocks that will play your selected sounduntil it is done whenever the flag is clicked. This will tell the computer to start playingthe background music as soon as your project is run.
Test that code to see if it is working properly. Remember, it’s important to test your codeoften as you work to make sure it’s doing what you want it to.
Cool! It works. One problem, though--the music only plays once. You want it to play continuouslywhile the DJ is mixing on top of that track. To make that happen, place a forever looparound it so that it will play over and over again.
Test that out. Now, it will play forever.
The DJ should mix in a note on top of that track when the spacebar is pressed. To makethat happen, click on the events tab and choose the “when space key pressed” block. Selecta sound that will play when the spacebar is pressed. Use the "set instrument" block tospecify the instrument you want played and the "play note" block to choose the sound.
Remember, you can click the block to test the instrument and the note you selected tosee if you like them. If it doesn’t sound quite right the first time, keep trying. Justchoose a different instrument and sound and test them again until you find what worksbest for your project. Try it to see if it works. Look at that! Whenthe spacebar is pressed, a note plays. Great job.
You now have a DJ mixer with a repeating track. The DJ can add a single note to the soundby pressing a key. Now, it's your turn. Choose a music loop andmake it play forever when the flag is clicked. Use the “when space key pressed” blockto set the instrument and play a note. Choose any sounds or notes you like for your music,and tinker with the “play note” or “beats” values until you get a sound you like. Whenyou are done with these steps, return to this CS First tab and click the green arrow tomove on to the next screencast.