class Alda::Score
Includes Alda::EventList
and provides methods to play
, parse
, or export
.
Public Class Methods
Creates an Alda::Score
.
Alda::EventList::new
# File lib/alda-rb/event_list.rb, line 298 def initialize(...) super on_contained end
Public Instance Methods
Clears all the events and variables.
# File lib/alda-rb/event_list.rb, line 308 def clear @events.clear @variables.clear nil end
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
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
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
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
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
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