Write a score
This tutorial teaches GAS through one score, which you edit in the playground. The playground runs in your browser, so there is nothing to install. The score has a piano that starts alone, a bass that joins in the middle, and an ending that winds down:
tempo 88key "C major"time_signature 4/4length bars 12track piano "Soft felt piano"track bass "Round upright bass, short notes"section intro:length bars 4flavor "quiet, plenty of space"bar 1:piano.playsection main:length bars 4flavor "warmer, more movement"bar 1:bass.playsection outro:length bars 4bass.stopbar 3:piano.stopintro()main()outro()
Choose Playground above the score to open it. The playground compiles the score as you type. The status line says whether it compiled, the editor underlines errors and warnings, and the timeline shows each track and the events on each bar. The language reference explains what each error means.
To hear the score, press Play and choose an audio source. Shared audio uses this site’s access when it is available. Your own key uses a Gemini API key from a project with access to Lyria RealTime. You can edit and compile without either. Music that is already playing keeps the version you started, so press Stop, then Play, to hear each edit.
The model writes the notes from your descriptions, so each run sounds different. Supported models explains which parts of a score the model acts on.
Set the frame
The first four lines set the musical clock:
tempo 88sets 88 beats per minute.key "C major"sets the tonal centre. The model treats it as a suggestion.time_signature 4/4puts four quarter-note beats in each bar. GAS counts time in bars.length bars 12sets how long the piece is.
Only length is required. Tempo defaults to 120 and the time signature to 4/4.
Describe the tracks
track piano "Soft felt piano" declares an instrument named piano. The description is plain language, so describe the sound you want rather than naming a preset.
Three settings shape a track. Try adding them below the track piano line:
piano.flavor "single line, unhurried, leave space"piano.timbre "felted, close and dry"piano.level 0.6
flavordescribes the performance or mood.timbredescribes the character of the sound.level, from 0 to 1, sets how prominent the track is. The model produces one mix, so this changes the track’s influence rather than its volume.
Written at the top of the score, these settings are the track’s defaults.
Build the piece from sections
A section is a named stretch of music, with its contents indented beneath it. Each section here sets its own length with length bars 4; a section without one takes the global length. Watch the timeline as you read:
- Bars count from 1 inside each section.
bar 1:inmainis bar 5 of the piece, andbar 3:inoutrois bar 11. - A track plays until it is stopped. The piano carries on through
main, even thoughmainnever mentions it. playandstopbefore the first bar block happen at bar 1. That is whybass.stopat the top ofoutrotakes the bass out at bar 9. After a bar block, putplayandstopinside bar blocks.- Section settings last only while the section plays, like the
flavorinintroandmain. Track settings inside a section need the track name, such aspiano.level 0.6. Put one in a bar block to change it at that bar.
Arrange the sections
The calls at the bottom set the order the sections play in. A section only plays when it is called, and you can call it more than once:
intro()main()main()outro()
This arrangement is 16 bars long, so change the length to length bars 16. The compiler warns you when the length and the arrangement disagree. Repeating a section replays its instructions without restarting tracks that are already playing.
Choose how it ends
length has three forms:
| Form | Behaviour |
|---|---|
length bars 16 |
Play once, then stop |
length bars 16 loop |
Repeat the arrangement until stopped |
length infinite |
Play the arrangement once, then hold its final state until stopped |
For infinite to hold a sound, leave some tracks playing at the end. This score stops both instruments in outro.
Change the length to length bars 16 loop and press Play, so the music keeps going for the next step.
Change it while it plays
While the music plays, enter this in Live command and press Send:
piano.flavor "busier, left hand walking"tempo 96
The music changes without restarting. Each statement gets a row that shows whether it was applied. The model generates audio a little ahead of what you hear, so a change can take a few moments to arrive.
Live commands can declare and start tracks, change track settings, and set tempo. A new track starts silent until you play it:
track lead "bright square lead"lead.flavor "short answers, leave space"lead.play
Everything else, such as sections and the arrangement, belongs to the score. The language reference lists exactly what live commands accept.
A live change sits on top of the score rather than editing it. It lasts until the music stops, and the next Play starts from the score again. To make these changes from your own code, see Connect with an application.
This tutorial covers the parts of GAS you need for most scores. The language reference lists every keyword and where it can go, including notes and motif for writing musical material in Alda notation.
Next: Run locally — compile a score on your machine and play it from your own application.