class Alda::REPL::TempScore
The score object used in Alda::REPL
.
Includes Alda
, so it can refer to alda commandline. However, the methods Alda::Score#play
, Alda::Score#parse
and Alda::Score#export
are still retained instead of being overridden by the included module.
When you are in an REPL session, you are actually in an instance of this class, so you can call the instance methods down here when you play with an REPL.
Public Class Methods
Creates a new TempScore
for the given REPL session specified by session
. It is called in Alda::REPL::new
.
Alda::Score::new
# File lib/alda-rb/repl.rb, line 106 def initialize session super() @session = session end
Public Instance Methods
Clears all the modifications that have been made to the score and start a new one. See score
for an example.
# File lib/alda-rb/repl.rb, line 136 def clear_history @session.clear_history end
Returns a Binding for the instance eval local environment of this score. Different callings of this method will return different bindings, and they do not share local variables. This method is called in Alda::REPL::new
.
$ alda-irb > p get_binding.receiver == self true
# File lib/alda-rb/repl.rb, line 154 def get_binding binding end
Prints a data representation of the score. This is the output that you get when you call Alda::Score#parse
.
# File lib/alda-rb/repl.rb, line 187 def map json = Alda.v1? ? parse : @session.message(:score_data) json = JSON.generate JSON.parse(json), indent: ' ', space: ' ', object_nl: ?\n, array_nl: ?\n puts @session.color ? json.blue : json end
Print the history (all Alda code of the score).
$ alda-irb > violin_; a b violin: [a b] > score violin: [a b] > clear_history > score > viola_; c viola: c > score viola: c
# File lib/alda-rb/repl.rb, line 175 def score print @session.color ? @session.history.blue : @session.history nil end
Prints the parsed events output of the score. This is the output that you get when you call Alda::Score#parse
with output: :events
.
# File lib/alda-rb/repl.rb, line 200 def score_events json = Alda.v1? ? parse(output: :events) : @session.message(:score_events) json = JSON.generate JSON.parse(json), indent: ' ', space: ' ', object_nl: ?\n, array_nl: ?\n puts @session.color ? json.blue : json end
Overrides Alda::Score#to_s
. Returns the history.
$ alda-irb > harmonica_; a b c harmonica: [a b c] > guitar_; c g e guitar: [c g e] > p to_s "harmonica: [a b c]\nguitar: [c g e]\n"
# File lib/alda-rb/repl.rb, line 125 def to_s @session.history end