Skip to content
Documentation

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:

gasPlayground
tempo 88
key "C major"
time_signature 4/4
length bars 12
track piano "Soft felt piano"
track bass "Round upright bass, short notes"
section intro:
length bars 4
flavor "quiet, plenty of space"
bar 1:
piano.play
section main:
length bars 4
flavor "warmer, more movement"
bar 1:
bass.play
section outro:
length bars 4
bass.stop
bar 3:
piano.stop
intro()
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 88 sets 88 beats per minute.
  • key "C major" sets the tonal centre. The model treats it as a suggestion.
  • time_signature 4/4 puts four quarter-note beats in each bar. GAS counts time in bars.
  • length bars 12 sets 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:

gas excerpt
piano.flavor "single line, unhurried, leave space"
piano.timbre "felted, close and dry"
piano.level 0.6
  • flavor describes the performance or mood.
  • timbre describes 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: in main is bar 5 of the piece, and bar 3: in outro is bar 11.
  • A track plays until it is stopped. The piano carries on through main, even though main never mentions it.
  • play and stop before the first bar block happen at bar 1. That is why bass.stop at the top of outro takes the bass out at bar 9. After a bar block, put play and stop inside bar blocks.
  • Section settings last only while the section plays, like the flavor in intro and main. Track settings inside a section need the track name, such as piano.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:

gas excerpt
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:

gas live
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:

gas live
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.