Class: GuitarProParser::Song

Inherits:
Object
  • Object
show all
Includes:
GuitarProHelper
Defined in:
lib/guitar_pro_parser/song.rb

Overview

This class represents the content of Guitar Pro file. It can be initialized by path to .gp file. Then it will automatically parse its data. Or it can be just instantiated with default values of the attributes.

Constant Summary

Constants included from GuitarProHelper

GuitarProHelper::BEND_TYPES, GuitarProHelper::BEND_VIBRATO_TYPES, GuitarProHelper::CHORD_TONALITIES, GuitarProHelper::CHORD_TYPES, GuitarProHelper::DURATIONS, GuitarProHelper::FINGERS, GuitarProHelper::GRACE_NOTE_DURATIONS, GuitarProHelper::GRACE_NOTE_TRANSITION_TYPES, GuitarProHelper::HARMONIC_TYPES, GuitarProHelper::MAP_SLIDE_TYPES_GP4, GuitarProHelper::MAP_SLIDE_TYPES_GP5, GuitarProHelper::MUSICAL_DIRECTIONS, GuitarProHelper::NINE_ELEVEN_THIRTEEN, GuitarProHelper::NOTES, GuitarProHelper::NOTE_DYNAMICS, GuitarProHelper::NOTE_TYPES, GuitarProHelper::REST_TYPES, GuitarProHelper::SLIDE_TYPES, GuitarProHelper::STRING_EFFECTS, GuitarProHelper::STROKE_DIRECTIONS, GuitarProHelper::STROKE_EFFECT_SPEEDS, GuitarProHelper::TREMOLO_PICKING_SPEEDS, GuitarProHelper::TRILL_PERIODS, GuitarProHelper::TRIPLET_FEEL, GuitarProHelper::VERSIONS, GuitarProHelper::VOICES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GuitarProHelper

digit_to_note

Constructor Details

#initialize(file_path = nil, headers_only = false) ⇒ Song

Initializes new Song instance. Parameters: (String) file_path Path to file to read. If is not specified default song instance will be created. (Boolean) headers_only Read only headers information from file if true (much faster than reading every note)



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/guitar_pro_parser/song.rb', line 106

def initialize(file_path = nil, headers_only = false)
  @version = 5.1
  @title = ''
  @title = ''
  @subtitle = ''
  @artist = ''
  @album = ''
  @lyricist = ''
  @composer = ''
  @copyright = ''
  @transcriber = ''
  @instructions = ''
  @notices = ''
  @triplet_feel = :no_triplet_feel
  @lyrics_track = 0
  @lyrics = []
  @master_volume = 100
  @equalizer = Array.new(11, 0)
  @page_setup = PageSetup.new
  @tempo = 'Moderate'
  @bpm = 120
  @key = 1
  @octave = 0
  @channels = []
  @musical_directions = Hash[GuitarProHelper::MUSICAL_DIRECTIONS.collect { |elem| [elem, nil] }]
  @master_reverb = 0
  @bars_settings = []
  @tracks = []

  # Read data from file if it is specified
  Reader.new(self, file_path, headers_only) unless file_path.nil?
end

Instance Attribute Details

#albumObject

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def album
  @album
end

#artistObject

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def artist
  @artist
end

#bars_settingsObject

Array of settings of bars. Doesn’t represent bars as containers for notes (look at Bar class for it)



97
98
99
# File 'lib/guitar_pro_parser/song.rb', line 97

def bars_settings
  @bars_settings
end

#bpmObject

Tempo as beats per minute



63
64
65
# File 'lib/guitar_pro_parser/song.rb', line 63

def bpm
  @bpm
end

#channelsObject

Table of midi channels. There are 4 ports and 16 channels, the channels are stored in this order: port1/channel1 - port1/channel2 … port1/channel16 - port2/channel1 … in array with the format:

[[1,2,...16], [1,2,...16], [1,2,...16], [1,2,...16]]


84
85
86
# File 'lib/guitar_pro_parser/song.rb', line 84

def channels
  @channels
end

#composerObject

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def composer
  @composer
end

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def copyright
  @copyright
end

#equalizerObject

Array of equalizer settings. Each one is represented as number of increments of .1dB the volume for

  • 32Hz band is lowered

  • 60Hz band is lowered

  • 125Hz band is lowered

  • 250Hz band is lowered

  • 500Hz band is lowered

  • 1KHz band is lowered

  • 2KHz band is lowered

  • 4KHz band is lowered

  • 8KHz band is lowered

  • 16KHz band is lowered

  • overall volume is lowered (gain)



54
55
56
# File 'lib/guitar_pro_parser/song.rb', line 54

def equalizer
  @equalizer
end

#instructionsObject

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def instructions
  @instructions
end

#keyObject

Key (signature) at the beginning of the piece. It is encoded as:

  • -1: F (b)

  • 0: C

  • 1: G (#)

  • 2: D (##)

TODO: convert digit to something readable



74
75
76
# File 'lib/guitar_pro_parser/song.rb', line 74

def key
  @key
end

#lyricistObject

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def lyricist
  @lyricist
end

#lyricsObject

Lyrics represented as array of hashes with 5 elements (for lyrics lines from 1 to 5). Each line has lyrics’ text and number of bar where it starts

{text: "Some text", bar: 1}

(>= 4.0 only)



36
37
38
# File 'lib/guitar_pro_parser/song.rb', line 36

def lyrics
  @lyrics
end

#lyrics_trackObject

Associated track for the lyrics (>= 4.0 only)



29
30
31
# File 'lib/guitar_pro_parser/song.rb', line 29

def lyrics_track
  @lyrics_track
end

#master_reverbObject

Selected master reverb setting (in Score information, value from 0 to 60) (>= 5.0 only) TODO: Represent as names



94
95
96
# File 'lib/guitar_pro_parser/song.rb', line 94

def master_reverb
  @master_reverb
end

#master_volumeObject

Master volume (value from 0 - 200, default is 100) (>= 5.0 only)



39
40
41
# File 'lib/guitar_pro_parser/song.rb', line 39

def master_volume
  @master_volume
end

#musical_directionsObject

(Hash) Musical directions definitions. Each symbol is represented as the bar number at which it is placed. If the symbol is not presented its value is nil. There is full list of supported symbols in GuitarProHelper::MUSICAL_DIRECTIONS array (>= 5.0 only)



90
91
92
# File 'lib/guitar_pro_parser/song.rb', line 90

def musical_directions
  @musical_directions
end

#noticesObject

Array of notices



21
22
23
# File 'lib/guitar_pro_parser/song.rb', line 21

def notices
  @notices
end

#octaveObject

Octave. Default value is 0. It becomes 8 if the sheet is to be played one octave higher (8va).



78
79
80
# File 'lib/guitar_pro_parser/song.rb', line 78

def octave
  @octave
end

#page_setupObject

(PageSetup) Data about page setup such as paddings, width, height, etc. (>= 5.0 only)



57
58
59
# File 'lib/guitar_pro_parser/song.rb', line 57

def page_setup
  @page_setup
end

#subtitleObject

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def subtitle
  @subtitle
end

#tempoObject

(String) Tempo text



60
61
62
# File 'lib/guitar_pro_parser/song.rb', line 60

def tempo
  @tempo
end

#titleObject

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def title
  @title
end

#tracksObject

Array of tracks



100
101
102
# File 'lib/guitar_pro_parser/song.rb', line 100

def tracks
  @tracks
end

#transcriberObject

Song information



17
18
19
# File 'lib/guitar_pro_parser/song.rb', line 17

def transcriber
  @transcriber
end

#triplet_feelObject

(Boolean) Shuffle rhythm feel. < 5.0 only. In version 5 of the format it is true when there is at least 1 bar with triplet feel.



26
27
28
# File 'lib/guitar_pro_parser/song.rb', line 26

def triplet_feel
  @triplet_feel
end

#versionObject

Guitar Pro version



14
15
16
# File 'lib/guitar_pro_parser/song.rb', line 14

def version
  @version
end

Instance Method Details

#add_bar_settingsObject



139
140
141
142
# File 'lib/guitar_pro_parser/song.rb', line 139

def add_bar_settings
  @bars_settings << BarSettings.new
  @bars_settings.last
end

#add_trackObject



144
145
146
147
# File 'lib/guitar_pro_parser/song.rb', line 144

def add_track
  @tracks << Track.new
  @tracks.last
end