O1Library Docs
Fall 2026
Docs API

# Music

o1.sound.midi.Music
See the Music companion object
final case class Music(tempoSetting: Option[Int], voices: Seq[Voice])

Represents a piece of music that may consist of multiple Voices, which in turn consist of MusicElems such as notes.

Instead of using the constructor, you can use the companion object to construct a `Music` object from a string: e.g., `Music("cdefg&>gfedc")`.

## Parameters

tempoSetting

  a tempo setting (in beats per minute) for the music, if there is one

voices

  the voices that, played simultaneously, make up the piece of music; no more than `MaxVoices` plus a possible percussion track

## Attributes

Companion
  object
Graph
Supertypes
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all

## Members list

### Value members

#### Concrete methods

def play(): Unit

Plays this music using the MIDI synthesizer. This is equivalent to calling `o1.sound.midi.play`. Students have access to the same functionality via the `play` method in the top-level package o1.

Plays this music using the MIDI synthesizer. This is equivalent to calling `o1.sound.midi.play`. Students have access to the same functionality via the `play` method in the top-level package o1.

## Attributes

def toMidi: Sequence

Returns the underlying MIDI sequence.

Returns the underlying MIDI sequence.

## Attributes

override def toString: String

Returns a string description of the music.

Returns a string description of the music.

## Attributes

Definition Classes
  Any

#### Inherited methods

def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

## Attributes

Inherited from:
  Product

def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

## Attributes

Returns

  in the default implementation, an `Iterator[Any]`

Inherited from:
  Product

#### Concrete fields

lazy val nonEmpty: Boolean

whether the `Music` object has any MusicElems at all

whether the `Music` object has any MusicElems at all

## Attributes

lazy val tempo: Int

The tempo of the music in beats per minute. This equals tempoSetting or `DefaultTempo`, if that’s not set.

The tempo of the music in beats per minute. This equals tempoSetting or `DefaultTempo`, if that’s not set.

## Attributes