Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

2. Choose your Track and Play a Note


In this screencast, you'll select the main music track for your DJ Mixer and add a sound that plays when the spacebar is pressed. This screencast will walk you through creating the code, then you’ll try it on your own.

With DJ music, there is usually a consistent sound or repeating musical loop that underlies the 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 adds to the music. To do that, click on your DJ sprite, then select a sound that is a musical loop from the Music Loops menu. A music loop is a sound that is designed to play over and over to make a continuous song. Add blocks that will play your selected sound until it is done whenever the flag is clicked. This will tell the computer to start playing the 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 code often 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 continuously while the DJ is mixing on top of that track. To make that happen, place a forever loop around 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 make that happen, click on the events tab and choose the “when space key pressed” block. Select a sound that will play when the spacebar is pressed. Use the "set instrument" block to specify 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 to see if you like them. If it doesn’t sound quite right the first time, keep trying. Just choose a different instrument and sound and test them again until you find what works best for your project. Try it to see if it works. Look at that! When the 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 sound by pressing a key. Now, it's your turn. Choose a music loop and make it play forever when the flag is clicked. Use the “when space key pressed” block to 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. When you are done with these steps, return to this CS First tab and click the green arrow to move on to the next screencast.

arrow_backward Back
Next arrow_forward
  1. Choose the main music track for your DJ Mixer.
  2. Program the main music track to play continuously when the green flag is clicked.
  3. Use a "forever" loop to make a musical note play forever.