Class: GuitarProParser::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/guitar_pro_parser/io/reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(song, file_path, headers_only) ⇒ Reader

Returns a new instance of Reader.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
63
64
65
# File 'lib/guitar_pro_parser/io/reader.rb', line 8

def initialize(song, file_path, headers_only)
  @song = song
  @file_path = file_path

  @input = InputStream.new(file_path)

  read_version
  read_info
  read_notices
  @song.triplet_feel = @input.read_boolean if @version < 5.0
  read_lyrics if @version >= 4.0

  if @version > 5.0
    @song.master_volume = @input.read_integer 
    @input.skip_integer
    11.times { |n| @song.equalizer[n] = @input.read_byte }
  end
  
  read_page_setup if @version >= 5.0
  read_tempo
  read_key
  @song.octave = @input.read_byte if @version >= 4.0
  read_channels
  read_musical_directions if @version >= 5.0
  @song.master_reverb = @input.read_integer if @version >= 5.0

  bars_count = @input.read_integer
  tracks_count = @input.read_integer

  if headers_only
    bars_count.times { @song.add_bar_settings }
    tracks_count.times { @song.add_track }
    return
  end

  bars_count.times { read_bars_settings }
  tracks_count.times { read_track }
  @input.skip_byte if @version >= 5.0
  
  @song.bars_settings.each do |bar_settings| 
    @song.tracks.each do |track|
      bar = Bar.new

      voices_count = @version >= 5.0 ? 2 : 1

      voices_count.times do |voice_number|
        voice = GuitarProHelper::VOICES.fetch(voice_number)
        beats_count = @input.read_integer
        beats_count.times { read_beat(track, bar, voice) }
      end

      track.bars << bar

      # Padding
      @input.skip_byte if @version >= 5.0
    end
  end
end