Class: Alda::REPL::TempScore

Inherits:
Score
  • Object
show all
Includes:
Alda
Defined in:
lib/alda-rb/repl.rb

Overview

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.

Constant Summary

Constants included from Alda

COMMANDS, COMMANDS_FOR_VERSIONS, GENERATIONS, VERSION

Instance Attribute Summary

Attributes included from EventList

#events, #variables

Instance Method Summary collapse

Methods included from Alda

[], clear_options, deduce_generation, down?, env, pipe, processes, up?

Methods inherited from Score

#clear, #export, #l, #load, #parse, #play, #raw, #save

Methods included from EventList

#==, #events_alda_codes, #has_variable?, #import, #method_missing, #on_contained, #to_a

Constructor Details

#initialize(session) ⇒ TempScore

:call-seq:

new(session) -> TempScore

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



106
107
108
109
# File 'lib/alda-rb/repl.rb', line 106

def initialize session
	super()
	@session = session
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Alda::EventList

Instance Method Details

#clear_historyObject Also known as: new, new_score

:call-seq:

clear_history() -> nil

Clears all the modifications that have been made to the score and start a new one. See #score for an example.



136
137
138
# File 'lib/alda-rb/repl.rb', line 136

def clear_history
	@session.clear_history
end

#get_bindingObject

:call-seq:

get_binding() -> Binding

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


154
155
156
# File 'lib/alda-rb/repl.rb', line 154

def get_binding
	binding
end

#mapObject Also known as: score_data

:call-seq:

map() -> nil

Prints a data representation of the score. This is the output that you get when you call Alda::Score#parse.



187
188
189
190
191
# 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

#scoreObject Also known as: score_text

:call-seq:

score() -> nil

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


175
176
177
178
# File 'lib/alda-rb/repl.rb', line 175

def score
	print @session.color ? @session.history.blue : @session.history
	nil
end

#score_eventsObject

:call-seq:

score_events() -> nil

Prints the parsed events output of the score. This is the output that you get when you call Alda::Score#parse with output: :events.



200
201
202
203
204
# 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

#to_sObject

:call-seq:

to_s -> String

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"


125
126
127
# File 'lib/alda-rb/repl.rb', line 125

def to_s
	@session.history
end