Packages

  • package root
    Definition Classes
    root
  • package o1

    O1Library is a toolkit designed for the course Programming 1 (a.k.a. O1) at Aalto University.

    O1Library is a toolkit designed for the course Programming 1 (a.k.a. O1) at Aalto University. It contains an assortment of tools; most prominently, it provides a framework for simple graphical programming and utilities for playing sound.

    This is the front page of O1Library’s documentation. However, this is probably not the best place to start learning about O1Library as a student. That’s because the relevant content of this library is introduced bit by bit in the chapters of O1’s custom ebook alongside the associated programming concepts and assignments.

    You may still find this documentation useful as a reference. You can also find some optional content here that you may wish to try.

    This front page lists the content available in the top-level package called simply o1. These tools are available with the simple command import o1._ in your Scala programs. Some of them you’ll use a lot; some of them you won’t necessarily need at all.

    The tools listed here are actually implemented in a number of subpackages (o1.gui, o1.sound, etc.); what you see here are just “shortcut aliases” to those actual implementations. The aliases are here to make that convenient import command work and to provide you with this list of links to some of the more commonly used tools in O1Library. The subpackages also contain additional content not listed here.

    O1Library has been developed by Aleksi Lukkarinen and Juha Sorva. Several of the key components in o1.gui and o1.world are built upon Aleksi’s Scala Media Computation Library. Some parts of O1Library draw inspiration from the “teachpacks” of the Racket programming language.

    We are grateful to Riku Autio, Joonatan Honkamaa, Juhani Numminen, Leo Varis, Veera Kahva, and anonymous students for bug reports and fixes. We thank Otto Seppälä for helpful discussions.

    Definition Classes
    root
  • package sound

    Please see one of the two subpackages:

    Please see one of the two subpackages:

    • o1.sound.midi for MIDI sound described in terms of notes, instruments, and other directives
    • o1.sound.sampled for working with recorded sound samples.
    Definition Classes
    o1
  • package midi

    This is one of O1’s sound packages (the other being o1.sound.sampled).

    This is one of O1’s sound packages (the other being o1.sound.sampled). This package provides a simple interface to a part of the more generic MIDI API. In particular, it lets students play MIDI music by writing notes a String and passing them to a function. That function, play, has an alias in the top-level package o1, so it’s accessible to students simply via import o1._.

    Here is a summary of the notation used in the musical Strings that you pass to play and some other functions in this package:

    • "cdefgah" plays seven notes at the default tempo of 120. (N.B. the seventh note is h, not b.)
    • "CDEFGAH" plays them louder.
    • "CDEFGAH/240" plays them at a double tempo of 240.
    • "CD E" has a pause between the second and third note.
    • "CD-E---" has a longer second note and a longer still third note.
    • "C.D.E" produces a staccato-like effect on the first two notes (playing them shorter followed by a pause).
    • ">CDE<<<CDE" plays three notes in a higher octave then shifts three octaves down before playing them again.
    • "C7D3E" plays the c in Octave #7, the d in Octave #3, and the e in the default Octave #5.
    • "CbDBE#7F" has a c-flat, a d-flat, an e-sharp in Octave #7, and a natural f. b and B are equivalent.
    • "C♭D♭E♯7F♮" is a fancy-pants way of writing the same thing.
    • "CDE[13]CDE" plays three notes using the default Instrument #1, then again using Instrument #13.
    • "(CEG)(DF#A)(EG#H)---" plays three chords, the last of which is longer.
    • "CDE&<<[28]efg&[110] F" simultaneously plays the three parts separated by &s.
    • "P:CDE" uses the MIDI percussion channel: each "note" represents a different percussion instrument.
    • "C|D||||E" means the same as ̀"cde": the |s don't do anything, but you can use them to mark bars or whatever.

    For a numbered list of the instruments, see the General MIDI Sound Set; the Instrument object contains the same list as Scala constants.

    Definition Classes
    sound
  • Accidental
  • Chord
  • Flat
  • Instrument
  • Music
  • MusicElem
  • Natural
  • Note
  • OctaveShift
  • Pause
  • Pitch
  • Sequencer
  • Sharp
  • Synthesizer
  • Voice
  • package sampled

    This is one of O1’s sound packages (the other being o1.sound.midi).

    This is one of O1’s sound packages (the other being o1.sound.midi). This package provides a simple interface for loading recorded sound samples.

    The contents of the package have aliases in the top-level package o1, so they are accessible to students simply via import o1._.

    Definition Classes
    sound

package midi

This is one of O1’s sound packages (the other being o1.sound.sampled). This package provides a simple interface to a part of the more generic MIDI API. In particular, it lets students play MIDI music by writing notes a String and passing them to a function. That function, play, has an alias in the top-level package o1, so it’s accessible to students simply via import o1._.

Here is a summary of the notation used in the musical Strings that you pass to play and some other functions in this package:

  • "cdefgah" plays seven notes at the default tempo of 120. (N.B. the seventh note is h, not b.)
  • "CDEFGAH" plays them louder.
  • "CDEFGAH/240" plays them at a double tempo of 240.
  • "CD E" has a pause between the second and third note.
  • "CD-E---" has a longer second note and a longer still third note.
  • "C.D.E" produces a staccato-like effect on the first two notes (playing them shorter followed by a pause).
  • ">CDE<<<CDE" plays three notes in a higher octave then shifts three octaves down before playing them again.
  • "C7D3E" plays the c in Octave #7, the d in Octave #3, and the e in the default Octave #5.
  • "CbDBE#7F" has a c-flat, a d-flat, an e-sharp in Octave #7, and a natural f. b and B are equivalent.
  • "C♭D♭E♯7F♮" is a fancy-pants way of writing the same thing.
  • "CDE[13]CDE" plays three notes using the default Instrument #1, then again using Instrument #13.
  • "(CEG)(DF#A)(EG#H)---" plays three chords, the last of which is longer.
  • "CDE&<<[28]efg&[110] F" simultaneously plays the three parts separated by &s.
  • "P:CDE" uses the MIDI percussion channel: each "note" represents a different percussion instrument.
  • "C|D||||E" means the same as ̀"cde": the |s don't do anything, but you can use them to mark bars or whatever.

For a numbered list of the instruments, see the General MIDI Sound Set; the Instrument object contains the same list as Scala constants.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. midi
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. sealed trait Accidental extends Product with Serializable

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

  2. case class Chord(notes: Seq[MusicElem]) extends MusicElem with Product with Serializable

    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.

    notes

    the MusicElems that play simultanously in this chord

  3. case class Instrument(number: Int) extends MusicElem with Product with Serializable

    A MusicElem that sets the instrument for the upcoming notes.

    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.

    number

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

  4. type MidiUnavailableException = javax.sound.midi.MidiUnavailableException

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

  5. case class Music(tempoSetting: Option[Int], voices: Seq[Voice]) extends Product with Serializable

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

    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

  6. trait MusicElem extends AnyRef

    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.

    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

    the subtypes Note, Chord, Pause, OctaveShift, Instrument

  7. case class Note(pitch: Pitch, length: Int, isStaccato: Boolean) extends MusicElem with Product with Serializable

    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.

    pitch

    the pitch of the note

    length

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

    isStaccato

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

  8. case class OctaveShift(shift: Int) extends MusicElem with OccursInChord with Product with Serializable

    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.

    shift

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

  9. case class Pitch(name: Char, accidental: Accidental, octave: Option[Int]) extends OccursInChord with Product with Serializable

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

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

    name

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

    accidental

    an adjustment to the base frequency

    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 iuzero

  10. case class Voice(notes: Seq[MusicElem], isPercussion: Boolean) extends Product with Serializable

    Represents a single voice within a piece of Music.

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

    notes

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

    isPercussion

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

Value Members

  1. val DefaultOctave: Int

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

  2. val DefaultTempo: Int

    The default tempo (120 beats per minute).

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

  3. val HighVolume: Int

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

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

  4. val MaxVoices: Int

    the maximum number of simultaneous Voices supported by this library.

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

  5. val MediumVolume: Int

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

  6. def parse(musicString: String): Music

    Parses the given musical String and returns the result as a Music object.

    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.

  7. def play(music: Music): Unit

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

  8. def play(music: String): Unit

    Parses the given musical String and plays the music that it describes on the MIDI synthesizer.

    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.

  9. object Flat extends Accidental with Product with Serializable

    Represents the concept of a flat note.

    Represents the concept of a flat note. Assigning this accidental to a Pitch makes it slightly lower.

  10. object Instrument extends Serializable

    This object provides a selection of constants that correspond to the 128 main instruments of the standard MIDI list.

    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.

  11. object Music extends Serializable

    This companion object of class Music just provides a factory method.

  12. object Natural extends Accidental with Product with Serializable

    Represents the concept of a natural note (neither Sharp nor Flat.

  13. object Pause extends MusicElem with Product with Serializable

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

  14. object Sequencer

    This object is an interface to the underlying MIDI 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.

  15. object Sharp extends Accidental with Product with Serializable

    Represents the concept of a sharp note.

    Represents the concept of a sharp note. Assigning this accidental to a Pitch makes it slightly higher.

  16. object Synthesizer

    This object is an interface to the underlying MIDI synthesizer.

    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.

Inherited from AnyRef

Inherited from Any

Ungrouped