Swift Playgrounds presents "Swan's Quest,” an interactive adventure in four chapters for all ages. It's time for the grand finale: You've honed your skills with tones, but in this chapter our Hero needs to sequence multi-part harmony.
Discover how to play pitched instruments with MIDI codes, and you just might help our Hero find the rhythm… and complete their quest.
Swan's Quest was created for Swift Playgrounds on iPad and Mac, combining frameworks and resources which power the educational experiences in many of our playgrounds, including Sonic Workshop, Sensor Arcade, and Augmented Reality. To learn more about building your own playgrounds, be sure to watch "Create Swift Playgrounds content for iPad and Mac".
And don't forget to stop by the Developer Forums and share your solution for our side quests.
Hello and welcome to WWDC. Hello and welcome back to Swan's Quest.
I'm Rob, your host. As we go inside the final chapter of our Quest, we hope you had a fun time so far. For this last chapter, we're going to move away from tone outputs and talk about sampled instruments. In this final chapter, you meet with the lizard one last time. The chest from the Swan is a mystery and I don't want to spoil it. Let's just say that sequencers are going to play a key role in solving this challenge. We're going to start with an introduction to sequencers and some tips for constructing one in Swift.
Steven's going to return to discuss the content SDK's API for playing sampled instruments, and a brief overview of the library of instruments provided within the SDK. He's also going to tell you how we sampled them and Garage Band. Finally. we'll wrap up with a final side quest, for those of you who don't want the fun to end. Let's talk about step sequencers.
At the end of the third challenge, the Swan gave us a scroll with two part harmony. Great one, Swan. Unlike our previous challenge, this will require multiple instruments playing at the same time. To play multiple parts at once, we're going to show you how to build a step sequencer. Believe it or not you only need a single timer for the sequencer, and instead of a tone output, we're gonna take advantage of the sampled instruments included in our content SDK. A sequencer is a multi-track timing loop. It is divided into equal chunks or steps which play in sequence over a predefined duration. Each track represents an instance of a pitched instrument. Sequencers are also used with non pitched instruments like percussion. Sequencers are very versatile.
They're great for creating atmospheric background loops or drum beats, which can sit underneath a melody. Step sequencers allow one to layer multiple tracks on top of the other. In the example shown here, there is a horn track, a guitar track, and a percussion track. Each column and the sequence is a quarter note in length. What you see are eight beats or two bars of 4/4, or as you recall in the music biz - common time. Here's an example of a sequencer's timing loop. The timer's interval is determined by dividing the total duration, four seconds by the total number of beats, eight in the sequence. We need to add our tracks and code to play the instruments inside of each track.
Let's check in with Stephen.
Thanks Rob. We include a rich API, an instrument library, with our content SDK.
We first introduced the instruments API and Sensor Arcade and included a template called Sensor Create so you could write your own music. Then last year, we released Sonic Workshop and its companion starting point, Sonic Create.
These both included seven instruments and samples for three octaves of notes.
The fundamental API is the playInstrument method. This API requires a reference to one of the seven instruments included in the playground's content SDK: electric guitar, bass guitar, piano, warm bells, seven synth, bass synth, and the crystal synth. The second item required by the play instrument method is a MIDI note protocol value. These MIDI notes include an 8 bit integer which corresponds to the appropriate MIDI code. Here is an example implementation with the second octave of encoded MIDI notes. Note: we included a value rest. This allows us to represent silent gaps for instruments in the sequence. Before we update our code, we need to discuss tracks. We've included another protocol for you in Sequencer.swift, the track protocol.
This includes an instrument value, the length of the track, and a method which provides the MIDI note for a given step in the sequence. An example implementation might look like this. Remember to check for the existence of the notes property and ensure the index step does not exceed the boundaries of the sequence. With all of the pieces now in place, we can revisit our barebones example. First, we create our two tracks: bass and piano, and combine them into an array. Once those are created, we need to assign note patterns to each track. Finally, we loop through those selected tracks and play the notes for the assigned instrument. Don't forget to call the endPerformance method after the first time through your sequence, so you get credit for your solution.
Let's update the code that recycles the index, after we've completed a loop of the sequence. After we reset the index back to zero, we can call endPerformance and the Swan will know we finished their challenge. Next, I'd like to talk about sampling in Garage Band. One way to create your own instruments is to take your own samples from Garage Band. First, open Garage Band and select keyboard or another instrument you're interested in sampling Within keyboard, there are many instrument options. I've chosen the koto, a traditional Japanese instrument. You'll also notice that you can change many other properties of the instrument, such as the tone and the resonance.
You can also select which scale the keyboard uses. This makes playing your desired notes even easier. Here, I'll select the major scale. Once you've recorded your individual notes, play them to make sure they sound exactly as you want them to. If you want, you can make modifications within the Garage Band editor before you export. Once you're all set, export your song.
The most lossless format is an uncompressed WAV, but you can also export and uncompressed formats. Once you've exported, trim the individual notes and import them into your project to create your instrument. Rob, we should do a really cool side quest for our final one.
I agree, Stephen. Is everyone ready? Are you ready? No spoilers this time.
For this final side quest, we want you to combine everything you've done across the four chapters. Add the tone output as an instrument for your step sequencer. During this episode, we give you tips for completing the final challenge in Swan's quest. You learned about steps sequencers and how they could be used to create multi-part harmony. We introduced you to the presampled instruments included in Swift Playgrounds, and then gave you instructions for sampling and creating your own instruments. We hope you've enjoyed Swan's Quest and learn more about Swift Playgrounds and everything you can accomplish with our Embedded Content SDK. If you need a refresher or just want to play through the fun again, be sure to check out our earlier episodes.
Good luck, have fun, and join us in the forums to share your solutions for
Looking for something specific? Enter a topic above and jump straight to the good stuff.
An error occurred when submitting your query. Please check your Internet connection and try again.