class Alda::Score

Includes Alda::EventList and provides methods to play, parse, or export.

Public Class Methods

new(&block) → Alda::Score click to toggle source

Creates an Alda::Score.

Calls superclass method Alda::EventList::new
# File lib/alda-rb/event_list.rb, line 298
def initialize(...)
  super
  on_contained
end

Public Instance Methods

clear() → nil click to toggle source

Clears all the events and variables.

# File lib/alda-rb/event_list.rb, line 308
def clear
  @events.clear
  @variables.clear
  nil
end
export(**opts) → String click to toggle source

Exports the score.

Returns the command line output of the alda command.

Run command alda help to see available options that can be specified in opts.

Alda::Score.new { piano_; c }.export output: 'temp.mid'
# (outputs a midi file called temp.mid)
# File lib/alda-rb/event_list.rb, line 258
def export **opts
  Alda.export code: self, **opts
end
load(filename) → Alda::InlineLisp click to toggle source

Loads alda codes from a file.

Actually appends a Alda::InlineLisp event of alda-code lisp call.

# File lib/alda-rb/event_list.rb, line 278
def load filename
  event = Alda::InlineLisp.new :alda_code, File.read(filename)
  @events.push event
  event
end
parse(**opts) → String click to toggle source

Parses the score.

Returns the JSON string of the parse result.

Run command alda help to see available options that can be specified in opts.

Alda::Score.new { piano_; c }.parse output: :events
# => "[{\"event-type\":...}]\n"
# File lib/alda-rb/event_list.rb, line 241
def parse **opts
  Alda.parse code: self, **opts
end
play(**opts) → String click to toggle source

Plays the score.

Returns the command line output of the alda command.

Run command alda help to see available options that can be specified in opts.

Alda::Score.new { piano_; c; d; e }.play
# => "[27713] Parsing/evaluating...\n[27713] Playing...\n"
# (and plays the sound)
Alda::Score.new { piano_; c; d; e }.play from: 1
# (plays only an E note)
# File lib/alda-rb/event_list.rb, line 224
def play **opts
  Alda.play code: self, **opts
end
save(filename) → nil click to toggle source

Saves the alda codes into a file.

# File lib/alda-rb/event_list.rb, line 267
def save filename
  File.open(filename, 'w') { _1.puts to_s }
end
to_s() → String click to toggle source

Returns a String containing the alda codes representing the score.

# File lib/alda-rb/event_list.rb, line 289
def to_s
  events_alda_codes
end