Class: Brevity::ScoreMaker

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/brevity/score_maker.rb

Constant Summary

Constants included from Commands

Commands::DYNAMIC_PARSER, Commands::ENV_EXPRS, Commands::ENV_METER_CHANGES, Commands::ENV_PARTS, Commands::ENV_START_METER, Commands::ENV_START_TEMPO, Commands::ENV_TEMPO_CHANGES, Commands::EXPR_PARSER, Commands::LABEL_PARSER

Instance Method Summary collapse

Methods included from Commands

#class_const, #expr, #meter, #part, #tempo

Instance Method Details

#make_scoreObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/brevity/score_maker.rb', line 26

def make_score
  start_tempo = @env[ENV_START_TEMPO]
  start_meter = @env[ENV_START_METER]\
                
  unless start_tempo.is_a? Numeric
    raise MissingStartTempoError
  end
  
  unless start_meter.is_a? Music::Transcription::Meter
    raise MissingStartMeterError
  end
  
  tcs = @env[ENV_TEMPO_CHANGES]
  mcs = @env[ENV_METER_CHANGES]
  parts = @env[ENV_PARTS]
  
  ## now that start tempo is established, find tempo changes
  ## whose value is not a Tempo object and convert them
  #prev_tempo = start_tempo
  #tcs.keys.sort.each do |offset|
  #  tc = tcs[offset]
  #  tempo = tc.value
  #  if tempo.beat_duration.nil?
  #    tc.value = Music::Transcription::Tempo.new(
  #      tempo.beats_per_minute,prev_tempo.beat_duration)
  #  end
  #  prev_tempo = tc.value
  #end
  
  return Music::Transcription::Score.new(
    start_meter,
    start_tempo,
    parts: parts,
    tempo_changes: tcs,
    meter_changes: mcs
  )
end

#process_nodes(cmd_nodes) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/brevity/score_maker.rb', line 17

def process_nodes cmd_nodes
  self.reset_env
  
  cmd_nodes.each do |cmd_node|
    cmd_method = cmd_node.name.to_sym
    self.send(cmd_method,*cmd_node.args)
  end
end

#reset_envObject



8
9
10
11
12
13
14
15
# File 'lib/brevity/score_maker.rb', line 8

def reset_env
  @env = {}
  @env[ENV_START_TEMPO] = nil
  @env[ENV_TEMPO_CHANGES] = {}
  @env[ENV_METER_CHANGES] = {}
  @env[ENV_EXPRS] = {}
  @env[ENV_PARTS] = {}
end