Class: Music::Performance::ScoreSequencer

Inherits:
Object
  • Object
show all
Defined in:
lib/music-performance/arrangement/midi/score_sequencer.rb

Instance Method Summary collapse

Constructor Details

#initialize(score) ⇒ ScoreSequencer

Returns a new instance of ScoreSequencer.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/music-performance/arrangement/midi/score_sequencer.rb', line 5

def initialize score
  start_nps = NoteTimeConverter.notes_per_second(score.start_tempo,
    score.start_meter.beat_duration)
  @start_usec_per_qnote = MidiUtil.usec_per_qnote(start_nps)
  @parts = ScoreCollator.new(score).collate_parts
  
  # part names should all be strings, because 1) a midi track name needs to
  # be a string and 2) the instrument map used to map part names to MIDI
  # program numbers will use part name strings as keys.
  @parts = Hash[ @parts.map {|k,v| [k.to_s,v] } ]
end

Instance Method Details

#make_midi_seq(instr_map = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/music-performance/arrangement/midi/score_sequencer.rb', line 17

def make_midi_seq instr_map = {}
  seq = MIDI::Sequence.new()
  
  # first track for the sequence holds time sig and tempo events
  track0 = MIDI::Track.new(seq)
  seq.tracks << track0
  track0.events << MIDI::Tempo.new(@start_usec_per_qnote)
  track0.events << MIDI::MetaEvent.new(MIDI::META_SEQ_NAME, 'Sequence Name')
  
  channel = 0
  @parts.each do |part_name,part|
    program = 1
    if instr_map.has_key?(part_name)
      program = instr_map[part_name]
    end
    
    pseq = PartSequencer.new(part)
    seq.tracks << pseq.make_midi_track(seq, part_name, channel, seq.ppqn, program)
    channel += 1
  end
  
  return seq
end