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

new(session) → TempScore click to toggle source

Creates a new TempScore for the given REPL session specified by session. It is called in Alda::REPL::new.

Calls superclass method Alda::Score::new
# File lib/alda-rb/repl.rb, line 106
def initialize session
  super()
  @session = session
end

Public Instance Methods

clear_history() → nil click to toggle source

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
Also aliased as: new, new_score
get_binding() → Binding click to toggle source

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
map() → nil click to toggle source

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
Also aliased as: score_data
new
Alias for: clear_history
new_score
Alias for: clear_history
score() → nil click to toggle source

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
Also aliased as: score_text
score_data
Alias for: map
score_events() → nil click to toggle source

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
score_text
Alias for: score
to_s → String click to toggle source

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