Class: RubySketch::MML

Inherits:
Object
  • Object
show all
Defined in:
lib/rubysketch/mml.rb

Overview

MML (Music Macro Language) compiler.

Constant Summary collapse

TONES =

Oscillator tone types selectable with the ‘@N` command.

%i[
  sine triangle square sawtooth pulse12_5 pulse25 noise
].freeze

Class Method Summary collapse

Class Method Details

.compile(str, streaming = false) ⇒ Sound

Compile MML string into a sound.

Parameters:

  • str (String)

    MML string

  • streaming (Boolean) (defaults to: false)

    if true, creates a streaming sound

Returns:

  • (Sound)

    sound object



23
24
25
26
# File 'lib/rubysketch/mml.rb', line 23

def compile(str, streaming = false)
  seq, duration = compile__! str
  Sound.new Beeps::Sound.new(seq, streaming ? 0 : duration)
end

.play(str) ⇒ nil

Compile and play MML string.

Parameters:

  • str (String)

    MML string

Returns:

  • (nil)

    nil



108
109
110
# File 'lib/rubysketch/mml.rb', line 108

def play(str)
  compile(str).play
end