o1.sound.midi

Type members

Classlikes

enum Accidental(val shift: Int, val symbol: String)

An adjustment to the frequency of a Pitch: a Flat, a Sharp, or a Natural.

An adjustment to the frequency of a Pitch: a Flat, a Sharp, or a Natural.

Value parameters:
shift

the shift from the base frequency caused by the accidental (in semitones). A positive number means a higher frequency, a negative number a lower one.

symbol

a symbol describing the accidental: "#", "♭", or the empty string

final case class Chord(notes: Seq[MusicElem]) extends MusicElem

Each instance of this class represents a combination of simultaneous Notes or other MusicElems.

Each instance of this class represents a combination of simultaneous Notes or other MusicElems.

Value parameters:
notes

the MusicElems that play simultanously in this chord

Companion:
object
object Chord
Companion:
class
case class Instrument(number: Int) extends MusicElem

A MusicElem that sets the instrument for the upcoming notes. The 128 main instruments of the standard MIDI list are supported. The companion object of this class provides constants that match those instruments.

A MusicElem that sets the instrument for the upcoming notes. The 128 main instruments of the standard MIDI list are supported. The companion object of this class provides constants that match those instruments.

Value parameters:
number

the number of a MIDI instrument between 0 and 127, inclusive

Companion:
object
object Instrument

This object provides a selection of constants that correspond to the 128 main instruments of the standard MIDI list. They are grouped in nested objects (Piano, Strings, etc.). The object PercussionChannel contains constants that correspond to the special sounds available on the MIDI percussion channel.

This object provides a selection of constants that correspond to the 128 main instruments of the standard MIDI list. They are grouped in nested objects (Piano, Strings, etc.). The object PercussionChannel contains constants that correspond to the special sounds available on the MIDI percussion channel.

Companion:
class

An error type that signals the underlying Java MIDI toolkit is unavailable.

An error type that signals the underlying Java MIDI toolkit is unavailable.

object Music

This companion object of class Music provides additional options for creating Music objects.

This companion object of class Music provides additional options for creating Music objects.

Companion:
class
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.

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").

Value 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

Companion:
object
trait MusicElem

A MusicElem is an element describes an aspect of MIDI music: a note, a chord, a pause, or a meta directive such as the change of an instrument. MusicElems put together make a Voice; voices put together compose a piece of Music.

A MusicElem is an element describes an aspect of MIDI music: a note, a chord, a pause, or a meta directive such as the change of an instrument. MusicElems put together make a Voice; voices put together compose a piece of Music.

Each MusicEleme has a length that represents how long it takes to play it. The duration of the shortest audible sound playable with o1.sound.midi is one; other durations are linearly relative to that.

See also:
final case class Note(pitch: Pitch, length: Int, isStaccato: Boolean) extends MusicElem

Each instance of this class represents a single musical note at a set pitch.

Each instance of this class represents a single musical note at a set pitch.

Value parameters:
isStaccato

whether the note should be played staccato so that sound is shorter than its duration

length

the duration of the note: how long it takes to play it

pitch

the pitch of the note

final case class OctaveShift(shift: Int) extends MusicElem

Each instance of this class is a directive that instructs the subsequent notes to play one octave higher or lower.

Each instance of this class is a directive that instructs the subsequent notes to play one octave higher or lower.

Value parameters:
shift

the direction of the shift: +1 means one octave higher, -1 one lower

object Pause extends MusicElem

This object is a MusicElem that represents a short pause in the music.

This object is a MusicElem that represents a short pause in the music.

object Pitch

A companion for class Pitch.

A companion for class Pitch.

Companion:
class
final case class Pitch(name: Char, accidental: Accidental, octave: Option[Int])

A Pitch is a frequency for a note to be played at.

A Pitch is a frequency for a note to be played at.

Value parameters:
accidental

an adjustment to the base frequency

name

the name of the corresponding note, which provides the base frequency; one of "cdefgah" or their upper-case equivalents

octave

the number of the octave relative to DefaultOctave; e.g., -2 means two octaves lower than the default; passing in None has the same effect as passing in zero

Companion:
object
object Sequencer

This object is an interface to the underlying MIDI sequencer. It is a thin Scala wrapper around the sequencer in the Java MIDI API.

This object is an interface to the underlying MIDI sequencer. It is a thin Scala wrapper around the sequencer in the Java MIDI API.

This object is an interface to the underlying MIDI synthesizer. It is a thin Scala wrapper around the synthesizer in the Java MIDI API. Uses the piano sound.

This object is an interface to the underlying MIDI synthesizer. It is a thin Scala wrapper around the synthesizer in the Java MIDI API. Uses the piano sound.

final case class Voice(notes: Seq[MusicElem], isPercussion: Boolean)

Represents a single voice within a piece of Music. A voice consists of MusicElems, primarily notes, in order.

Represents a single voice within a piece of Music. A voice consists of MusicElems, primarily notes, in order.

Value parameters:
isPercussion

whether the notes should not be interpresed as regular notes but as the special sounds defined for the MIDI standard’s percussion channel

notes

the notes (and possible other MusicElems) that compose this voice

Types

An error type that signals the underlying Java MIDI toolkit is unavailable.

An error type that signals the underlying Java MIDI toolkit is unavailable.

Value members

Concrete methods

def parse(musicString: String): Music

Parses the given musical String and returns the result as a Music object. The String must be formatted as described in the package overview. Throws an IllegalArgumentException in case the String was invalid.

Parses the given musical String and returns the result as a Music object. The String must be formatted as described in the package overview. Throws an IllegalArgumentException in case the String was invalid.

def play(music: String): Unit

Parses the given musical String and plays the music that it describes on the MIDI synthesizer. The String must be formatted as described in the package overview. Prints out an error message in case the String was invalid.

Parses the given musical String and plays the music that it describes on the MIDI synthesizer. The String must be formatted as described in the package overview. Prints out an error message in case the String was invalid.

def play(music: Music): Unit

Plays the music described by the given Music object on the MIDI synthesizer.

Plays the music described by the given Music object on the MIDI synthesizer.

Concrete fields

The number (5) of the default octave to play notes from.

The number (5) of the default octave to play notes from.

The default tempo (120 beats per minute). This is used by various methods in with this package when playing music, unless otherwise specified.

The default tempo (120 beats per minute). This is used by various methods in with this package when playing music, unless otherwise specified.

A number (127) that corresponds to the highest possible volume setting available to this MIDI package. (The lowest is zero.)

A number (127) that corresponds to the highest possible volume setting available to this MIDI package. (The lowest is zero.)

the maximum number of simultaneous Voices supported by this library. This number doesn’t include the additional percussion track.

the maximum number of simultaneous Voices supported by this library. This number doesn’t include the additional percussion track.

A number (80) that corresponds to a “medium” volume on the scale from 0 to 127 available to this MIDI package.

A number (80) that corresponds to a “medium” volume on the scale from 0 to 127 available to this MIDI package.