guitar_pro_parser 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +72 -0
  6. data/Rakefile +7 -0
  7. data/guitar_pro_parser.gemspec +25 -0
  8. data/lib/guitar_pro_parser/bar.rb +29 -0
  9. data/lib/guitar_pro_parser/bar_settings.rb +74 -0
  10. data/lib/guitar_pro_parser/beat.rb +42 -0
  11. data/lib/guitar_pro_parser/channel.rb +25 -0
  12. data/lib/guitar_pro_parser/chord_diagram.rb +14 -0
  13. data/lib/guitar_pro_parser/guitar_pro_helper.rb +73 -0
  14. data/lib/guitar_pro_parser/io/input_stream.rb +110 -0
  15. data/lib/guitar_pro_parser/io/reader.rb +759 -0
  16. data/lib/guitar_pro_parser/note.rb +71 -0
  17. data/lib/guitar_pro_parser/page_setup.rb +34 -0
  18. data/lib/guitar_pro_parser/song.rb +113 -0
  19. data/lib/guitar_pro_parser/track.rb +125 -0
  20. data/lib/guitar_pro_parser/version.rb +3 -0
  21. data/lib/guitar_pro_parser.rb +25 -0
  22. data/spec/lib/guitar_pro_parser/bar_settings_spec.rb +176 -0
  23. data/spec/lib/guitar_pro_parser/beat_spec.rb +79 -0
  24. data/spec/lib/guitar_pro_parser/channel_spec.rb +44 -0
  25. data/spec/lib/guitar_pro_parser/guitar_pro_helper_spec.rb +11 -0
  26. data/spec/lib/guitar_pro_parser/io/input_stream_spec.rb +101 -0
  27. data/spec/lib/guitar_pro_parser/note_spec.rb +55 -0
  28. data/spec/lib/guitar_pro_parser/page_setup_spec.rb +26 -0
  29. data/spec/lib/guitar_pro_parser/song_spec.rb +121 -0
  30. data/spec/lib/guitar_pro_parser/track_spec.rb +211 -0
  31. data/spec/lib/guitar_pro_parser_spec.rb +51 -0
  32. data/spec/spec_helper.rb +23 -0
  33. data/spec/tabs/tab.gp4 +0 -0
  34. data/spec/tabs/tab.gp5 +0 -0
  35. data/spec/tabs/test_musical_directions.gp5 +0 -0
  36. metadata +144 -0
@@ -0,0 +1,71 @@
1
+ module GuitarProParser
2
+
3
+ class Note
4
+
5
+ attr_accessor :type,
6
+ :time_independent_duration,
7
+ :accentuated,
8
+ :ghost,
9
+ :dynamic,
10
+ :fret,
11
+ :fingers,
12
+ :vibrato,
13
+ :grace,
14
+ :let_ring,
15
+ :hammer_or_pull,
16
+ :trill,
17
+ :bend,
18
+ :staccato,
19
+ :palm_mute,
20
+ :harmonic,
21
+ :tremolo,
22
+ :slide
23
+
24
+ def initialize
25
+ @type = :normal
26
+ @time_independent_duration = false
27
+ @accentuated = false
28
+ @ghost = false
29
+ @dynamic = 'f'
30
+ @fret = 0
31
+ @fingers = { left: nil, right: nil }
32
+
33
+ @vibrato = false
34
+ @grace = nil
35
+ @let_ring = false
36
+ @hammer_or_pull = false
37
+ @trill = nil
38
+ @bend = nil
39
+ @staccato = false
40
+ @palm_mute = false
41
+ @harmonic = nil
42
+ @tremolo = nil
43
+ @slide = nil
44
+ end
45
+
46
+ def add_left_hand_finger(finger)
47
+ @fingers[:left] = finger
48
+ end
49
+
50
+ def add_right_hand_finger(finger)
51
+ @fingers[:right] = finger
52
+ end
53
+
54
+ def add_grace(fret, dynamic, transition, duration, dead, position)
55
+ @grace = { fret: fret, dynamic: dynamic, transition: transition, duration: duration, dead: dead, position: position }
56
+ end
57
+
58
+ def add_tremolo(speed)
59
+ @tremolo = { speed: speed }
60
+ end
61
+
62
+ def add_harmonic(type)
63
+ @harmonic = { type: type }
64
+ end
65
+
66
+ def add_trill(fret, period)
67
+ @trill = { fret: fret, period: period }
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,34 @@
1
+ module GuitarProParser
2
+
3
+ class PageSetup
4
+
5
+ attr_accessor :page_format_length, :page_format_width, :left_margin, :right_margin, :top_margin, :bottom_margin, :score_size,
6
+ :title, :subtitle, :artist, :album, :lyrics_author, :music_author, :lyrics_and_music_author,
7
+ :copyright_line_1, :copyright_line_2, :page_number, :displayed_fields
8
+
9
+ def initialize
10
+ @page_format_length = 0
11
+ @page_format_width = 0
12
+ @left_margin = 0
13
+ @right_margin = 0
14
+ @top_margin = 0
15
+ @bottom_margin = 0
16
+ @score_size = 0
17
+
18
+ @title = ''
19
+ @subtitle = ''
20
+ @artist = ''
21
+ @album = ''
22
+ @lyrics_author = ''
23
+ @music_author = ''
24
+ @lyrics_and_music_author = ''
25
+ @copyright_line_1 = ''
26
+ @copyright_line_2 = ''
27
+ @page_number = ''
28
+
29
+ @displayed_fields = []
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,113 @@
1
+ require 'guitar_pro_parser/io/reader'
2
+
3
+ module GuitarProParser
4
+
5
+ # This class represents the content of Guitar Pro file.
6
+ # It can be initialized by path to .gp[3,4,5] file. The it will automatically parse its data.
7
+ # Or it can be just instantiated with default values of the attributes.
8
+ #
9
+ # == Attributes
10
+ #
11
+ #
12
+ # * +version+ (float) Version of Guitar Pro
13
+ # * +title+ (string)
14
+ # * +subtitle+ (string)
15
+ # * +artist+ (string)
16
+ # * +album+ (string)
17
+ # * +lyricist+ (string) Author of lyrics (>= 5.0 only)
18
+ # * +composer+ (string) Author of music
19
+ # * +copyright+ (string)
20
+ # * +transcriber+ (string) Author of tabulature
21
+ # * +instructions+ (string)
22
+ # * +notices+ (array) Array of notices (each notice is a string)
23
+ # * +triplet_feel+ (boolean) Shuffle rhythm feel (< 5.0 only)
24
+ # * +lyrics_track+ (integer) Associated track for the lyrics (>= 4.0 only)
25
+ # * +lyrics+ (array) Lyrics data represented as array of hashes with 5 elements
26
+ # (for lyrics lines from 1 to 5). Each line has lyrics' text
27
+ # and number of bar where it starts: {text: "Some text", bar: 1}
28
+ # (>= 4.0 only)
29
+ # * +master_volume+ (integer) Master volume (value from 0 - 200, default is 100) (>= 5.0 only)
30
+ # * +equalizer+ (array) Array of equalizer settings.
31
+ # Each one is represented as number of increments of .1dB the volume for
32
+ # 32Hz band is lowered
33
+ # 60Hz band is lowered
34
+ # 125Hz band is lowered
35
+ # 250Hz band is lowered
36
+ # 500Hz band is lowered
37
+ # 1KHz band is lowered
38
+ # 2KHz band is lowered
39
+ # 4KHz band is lowered
40
+ # 8KHz band is lowered
41
+ # 16KHz band is lowered
42
+ # overall volume is lowered (gain)
43
+ # * +page_setup+ (object) Object of PageSetup class that contains data about page setup (>= 5.0 only)
44
+ # * +tempo+ (string) Tempo as string
45
+ # * +bpm+ (integer) Tempo as beats per minute
46
+ # * +key+ (integer) #TODO: convert digit to something readable (has different format for GP3 and GP4/5)
47
+ # * +octave+ (integer) (>= 4.0 only)
48
+ # * +channels+ (array) Table of midi channels. There are 4 ports and 16 channels, the channels are stored in this order:
49
+ # port1/channel1 - port1/channel2 ... port1/channel16 - port2/channel1 ...
50
+ # * +musical_directions+ (hash) Hash of musical directions definitions.
51
+ # Each symbol is represented as the bar number at which it is placed.
52
+ # If the symbol is not presented its value is nil.
53
+ # There is full list of supported symbols in GuitarProHelper::MUSICAL_DIRECTIONS array (>= 5.0 only)
54
+ # * +master_reverb+ (integer) Selected master reverb setting (in Score information, value from 0 to 60) (>= 5.0 only) #TODO represent as names
55
+ # * +bars_settings+ (array) Array of settings of bars. Doesn't represent bars as containers for notes (look at Bar class for it)
56
+ # * +tracks+ (array) Array of tracks
57
+ #
58
+ class Song
59
+
60
+ include GuitarProHelper
61
+
62
+ attr_accessor :version, :title, :subtitle, :artist, :album, :lyricist, :composer, :copyright,
63
+ :transcriber, :instructions, :notices, :triplet_feel, :lyrics_track, :lyrics,
64
+ :master_volume, :equalizer, :page_setup, :tempo, :bpm, :key, :octave, :channels,
65
+ :musical_directions, :master_reverb, :bars_settings, :tracks
66
+
67
+ def initialize(file_path = nil, headers_only = false)
68
+ # Initialize variables by default values
69
+ @title = ''
70
+ @title = ''
71
+ @subtitle = ''
72
+ @artist = ''
73
+ @album = ''
74
+ @lyricist = ''
75
+ @composer = ''
76
+ @copyright = ''
77
+ @transcriber = ''
78
+ @instructions = ''
79
+ @notices = ''
80
+ @triplet_feel = :no_triplet_feel
81
+ @lyrics_track = 0
82
+ @lyrics = []
83
+ @master_volume = 100
84
+ @equalizer = Array.new(11, 0)
85
+ @page_setup = PageSetup.new
86
+ @tempo = 'Moderate'
87
+ @bpm = 120
88
+ @key = 1
89
+ @octave = 0
90
+ @channels = []
91
+ @musical_directions = Hash[GuitarProHelper::MUSICAL_DIRECTIONS.collect { |elem| [elem, nil] }]
92
+ @master_reverb = 0
93
+
94
+ @bars_settings = []
95
+ @tracks = []
96
+
97
+ # Read data from file
98
+ Reader.new(self, file_path, headers_only) unless file_path.nil?
99
+ end
100
+
101
+ def add_bar_settings
102
+ @bars_settings << BarSettings.new
103
+ @bars_settings.last
104
+ end
105
+
106
+ def add_track
107
+ @tracks << Track.new
108
+ @tracks.last
109
+ end
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,125 @@
1
+ module GuitarProParser
2
+
3
+ # This class represents tracks.
4
+ # Beside track's settings (see attributes) it contain bars (@bars attribute) that contain beats and notes.
5
+ #
6
+ # == Attributes
7
+ #
8
+ # * +drums+ (boolean) Drums track
9
+ # * +twelve_stringed_guitar+ (boolean) 12 stringed guitar track
10
+ # * +banjo+ (boolean) Banjo track
11
+ # * +solo_playback+ (boolean) Marked for solo playback (> 5.0 only)
12
+ # * +mute_playback+ (boolean) Marked for mute playback (> 5.0 only)
13
+ # * +rse_playback+ (boolean) Use RSE playback (track instrument option) (> 5.0 only)
14
+ # * +indicate_tuning+ (boolean) Indicate tuning on the score (track properties) (> 5.0 only)
15
+ # * +name+ (string) Track name
16
+ # * +strings+ (array) Array of MIDI notes each string plays open. E.g. [E5, B4, G4, D4, A3, E3] for standart tuning
17
+ # * +midi_port+ (integer) MIDI port used
18
+ # * +midi_channel+ (integer) MIDI channel used (must be 10 if this is a drum track)
19
+ # * +midi_channel_for_effects+ (integer) MIDI channel used for effects
20
+ # * +frets_count+ (integer) Number of frets used for this instrument
21
+ # * +capo+ (integer) The fret number at which a capo is placed (0 for no capo)
22
+ # * +color+ (array) Track color (RGB intensities). E.g. [255, 0, 0] for red.
23
+ # * +diagrams_below_the_standard_notation+ (boolean) Diagrams/chords below the standard notation (> 5.0 only)
24
+ # * +show_rythm_with_tab+ (boolean) Show rhythm with tab (> 5.0 only)
25
+ # * +force_horizontal_beams+ (boolean) Force horizontal beams (> 5.0 only)
26
+ # * +force_channels_11_to_16+ (boolean) Force channels 11 to 16 (> 5.0 only)
27
+ # * +diagrams_list_on_top_of_score+ (boolean) Diagrams list on top of the score (> 5.0 only)
28
+ # * +diagrams_in_the_score+ (boolean) Diagrams in the score (> 5.0 only)
29
+ # * +auto_let_ring+ (boolean) Auto-Let Ring (> 5.0 only)
30
+ # * +auto_brush+ (boolean) Auto Brush (> 5.0 only)
31
+ # * +extend_rhytmic_inside_the_tab+ (boolean) Extend rhythmic inside the tab (> 5.0 only)
32
+ # * +midi_bank+ (integer) MIDI bank (> 5.0 only)
33
+ # * +human_playing+ (integer) Human playing in percents (track instrument options) (> 5.0 only)
34
+ # * +auto_accentuation+ (integer) Auto-Accentuation on the Beat (track instrument options) (> 5.0 only) # TODO Not sure that it works
35
+ # * +sound_bank+ (integer) Selected sound bank (track instrument options) (> 5.0 only)
36
+ # * +equalizer+ (array) Equalizer setup. Represented as array with this values:
37
+ # number of increments of .1dB the volume for the low frequency band is lowered
38
+ # number of increments of .1dB the volume for the mid frequency band is lowered
39
+ # number of increments of .1dB the volume for the high frequency band is lowered
40
+ # number of increments of .1dB the volume for all frequencies is lowered (gain)
41
+ # (> 5.0 only)
42
+ # * +instrument_effect_1+ (string) Track instrument effect 1 (> 5.0 only)
43
+ # * +instrument_effect_2+ (string) Track instrument effect 2 (> 5.0 only)
44
+ # * +bars+ (array) Bars of this track
45
+ #
46
+ class Track
47
+
48
+ attr_accessor :drums,
49
+ :twelve_stringed_guitar,
50
+ :banjo,
51
+ :solo_playback,
52
+ :mute_playback,
53
+ :rse_playback,
54
+ :indicate_tuning,
55
+ :name,
56
+ :strings,
57
+ :midi_port,
58
+ :midi_channel,
59
+ :midi_channel_for_effects,
60
+ :frets_count,
61
+ :capo,
62
+ :color,
63
+ :diagrams_below_the_standard_notation,
64
+ :show_rythm_with_tab,
65
+ :force_horizontal_beams,
66
+ :force_channels_11_to_16,
67
+ :diagrams_list_on_top_of_score,
68
+ :diagrams_in_the_score,
69
+ :auto_let_ring,
70
+ :auto_brush,
71
+ :extend_rhytmic_inside_the_tab,
72
+ :midi_bank,
73
+ :human_playing,
74
+ :auto_accentuation,
75
+ :sound_bank,
76
+ :equalizer,
77
+ :instrument_effect_1,
78
+ :instrument_effect_2,
79
+ :bars
80
+
81
+ def initialize
82
+ # Initialize attributes by default values
83
+ @drums = false
84
+ @twelve_stringed_guitar = false
85
+ @banjo = false
86
+ @solo_playback = false
87
+ @mute_playback = false
88
+ @rse_playback = false
89
+ @indicate_tuning = false
90
+ @name = 'Track'
91
+ @strings = %w(E5 B4 G4 D4 A3 E3)
92
+ @midi_port = 1
93
+ @midi_channel = 16
94
+ @midi_channel_for_effects = 16
95
+ @frets_count = 24
96
+ @capo = 0
97
+ @color = [255, 0, 0]
98
+
99
+ @diagrams_below_the_standard_notation = false
100
+ @show_rythm_with_tab = false
101
+ @force_horizontal_beams = false
102
+ @force_channels_11_to_16 = false
103
+ @diagrams_list_on_top_of_score = false
104
+ @diagrams_in_the_score = false
105
+
106
+ @auto_let_ring = false
107
+ @auto_brush = false
108
+ @extend_rhytmic_inside_the_tab = false
109
+
110
+ @midi_bank = 0
111
+ @human_playing = 0
112
+ @auto_accentuation = 0
113
+ @sound_bank = 0
114
+
115
+ @equalizer = Array.new(4, 0)
116
+
117
+ @instrument_effect_1 = ''
118
+ @instrument_effect_2 = ''
119
+
120
+ @bars = []
121
+ end
122
+
123
+ end
124
+
125
+ end
@@ -0,0 +1,3 @@
1
+ module GuitarProParser
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'guitar_pro_parser/version'
2
+ require 'guitar_pro_parser/song'
3
+ require 'guitar_pro_parser/page_setup'
4
+ require 'guitar_pro_parser/channel'
5
+ require "guitar_pro_parser/track"
6
+ require "guitar_pro_parser/bar_settings"
7
+ require "guitar_pro_parser/bar"
8
+ require 'guitar_pro_parser/beat'
9
+ require 'guitar_pro_parser/chord_diagram'
10
+ require 'guitar_pro_parser/note'
11
+
12
+ module GuitarProParser
13
+
14
+ # Reads the whole Guitar Pro file and returns song object
15
+ def self.read_file(filename)
16
+ Song.new(filename)
17
+ end
18
+
19
+ # Read only header information (such as title, artist, etc.)
20
+ # from Guitar Pro file
21
+ def self.read_headers(filename)
22
+ Song.new(filename, true)
23
+ end
24
+
25
+ end
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe GuitarProParser::BarSettings do
4
+
5
+ shared_context 'shared bar 1' do
6
+ subject { song.bars_settings[0] }
7
+ end
8
+
9
+ shared_context 'shared bar 2' do
10
+ subject { song.bars_settings[1] }
11
+ end
12
+
13
+ shared_context 'shared bar 3' do
14
+ subject { song.bars_settings[2] }
15
+ end
16
+
17
+ shared_context 'shared 3/4 bar' do
18
+ subject { song.bars_settings[6] }
19
+ end
20
+
21
+ shared_context 'shared 5/8 bar' do
22
+ subject { song.bars_settings[7] }
23
+ end
24
+
25
+ shared_context 'shared has start of repeat' do
26
+ subject { song.bars_settings[8] }
27
+ end
28
+
29
+ shared_context 'shared has end of repeat' do
30
+ subject { song.bars_settings[9] }
31
+ end
32
+
33
+ shared_context 'shared has number of alternate ending' do
34
+ subject { song.bars_settings[12] }
35
+ end
36
+
37
+ shared_examples 'Any Guitar Pro version' do
38
+ context 'bar 1' do
39
+ include_context 'shared bar 1'
40
+
41
+ its(:new_time_signature) { should include(:numerator => 4, :denominator => 4) }
42
+ its(:has_start_of_repeat) { should == false }
43
+ its(:has_end_of_repeat) { should == false }
44
+ its(:repeats_count) { should == 0 }
45
+ its(:alternate_endings) { should == [] }
46
+ its(:marker) { should == {name: 'Pt. 1', color: [255, 0, 0]} }
47
+ its(:new_key_signature) { should == {key: 1, scale: :major} }
48
+ its(:double_bar) { should == true }
49
+ end
50
+
51
+ context 'bar 2' do
52
+ include_context 'shared bar 2'
53
+ its(:marker) { should == {name: 'Second bar', color: [0, 255, 0] } }
54
+ end
55
+
56
+ context 'bar 3' do
57
+ include_context 'shared bar 3'
58
+ its(:marker) { should == {name: 'Pt. 2', color: [255, 0, 0] } }
59
+ end
60
+
61
+ context '3/4 bar' do
62
+ include_context 'shared 3/4 bar'
63
+ its(:new_time_signature) { should include(:numerator => 3, :denominator => nil) }
64
+ end
65
+
66
+ context '5/8 bar' do
67
+ include_context 'shared 5/8 bar'
68
+ its(:new_time_signature) { should include(:numerator => 5, :denominator => 8) }
69
+ end
70
+
71
+ context 'has start of repeat' do
72
+ include_context 'shared has start of repeat'
73
+ its(:has_start_of_repeat) { should == true }
74
+ its(:has_end_of_repeat) { should == false }
75
+ end
76
+
77
+ context 'has end of repeat' do
78
+ include_context 'shared has end of repeat'
79
+ its(:has_start_of_repeat) { should == false }
80
+ its(:has_end_of_repeat) { should == true }
81
+ its(:repeats_count) { should == 1 }
82
+ end
83
+
84
+ context 'has number of alternate ending' do
85
+ include_context 'shared has number of alternate ending'
86
+ its(:alternate_endings) { should_not be_empty }
87
+
88
+ # There is also end of repeat in this bar
89
+ its(:has_end_of_repeat) { should == true }
90
+ its(:repeats_count) { should == 2 }
91
+ end
92
+ end
93
+
94
+
95
+ describe 'Guitar Pro 5' do
96
+ subject(:song) { GuitarProParser::Song.new test_tab_path 5 }
97
+
98
+ it_behaves_like 'Any Guitar Pro version'
99
+
100
+ context 'bar 1' do
101
+ include_context 'shared bar 1'
102
+ its(:new_time_signature) { should include(:beam_eight_notes_by_values => [2, 2, 2, 2]) }
103
+ its(:triplet_feel) { should == :triplet_8th }
104
+ end
105
+
106
+ context 'bar 2' do
107
+ include_context 'shared bar 2'
108
+ its(:triplet_feel) { should == :no_triplet_feel }
109
+ end
110
+
111
+ context 'bar 3' do
112
+ include_context 'shared bar 3'
113
+ its(:triplet_feel) { should == :triplet_16th }
114
+ end
115
+
116
+ context '3/4 bar' do
117
+ include_context 'shared 3/4 bar'
118
+ its(:new_time_signature) { should include(:beam_eight_notes_by_values => [2, 2, 2, 0]) }
119
+ end
120
+
121
+ context '5/8 bar' do
122
+ include_context 'shared 5/8 bar'
123
+ its(:new_time_signature) { should include(:beam_eight_notes_by_values => [3, 2, 0, 0]) }
124
+ end
125
+
126
+ context 'has number of alternate ending' do
127
+ include_context 'shared has number of alternate ending'
128
+ its(:alternate_endings) { should == [1, 2] }
129
+ end
130
+ end
131
+
132
+
133
+ shared_examples 'any bar in Guitar Pro < 5' do
134
+ its(:triplet_feel) { should == :no_triplet_feel }
135
+ end
136
+
137
+ describe 'Guitar Pro 4' do
138
+ subject(:song) { GuitarProParser::Song.new test_tab_path 4 }
139
+
140
+ it_behaves_like 'Any Guitar Pro version'
141
+
142
+ context 'bar 1' do
143
+ include_context 'shared bar 1'
144
+ it_behaves_like 'any bar in Guitar Pro < 5'
145
+ its(:new_time_signature) { should include(:beam_eight_notes_by_values => []) }
146
+ end
147
+
148
+ context 'bar 2' do
149
+ include_context 'shared bar 2'
150
+ it_behaves_like 'any bar in Guitar Pro < 5'
151
+ end
152
+
153
+ context 'bar 3' do
154
+ include_context 'shared bar 3'
155
+ it_behaves_like 'any bar in Guitar Pro < 5'
156
+ end
157
+
158
+ context '3/4 bar' do
159
+ include_context 'shared 3/4 bar'
160
+ it_behaves_like 'any bar in Guitar Pro < 5'
161
+ its(:new_time_signature) { should include(:beam_eight_notes_by_values => []) }
162
+ end
163
+
164
+ context '5/8 bar' do
165
+ include_context 'shared 5/8 bar'
166
+ it_behaves_like 'any bar in Guitar Pro < 5'
167
+ its(:new_time_signature) { should include(:beam_eight_notes_by_values => []) }
168
+ end
169
+
170
+ context 'has number of alternate ending' do
171
+ include_context 'shared has number of alternate ending'
172
+ its(:alternate_endings) { should == [2] }
173
+ end
174
+ end
175
+
176
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ def test_beat(type)
4
+ beats = {
5
+ first: [0, 0, 0],
6
+ second: [0, 0, 1],
7
+ third: [0, 0, 2],
8
+ mix_table: [1, 2, 0]
9
+ }
10
+ track = beats[type][0]
11
+ bar = beats[type][1]
12
+ beat = beats[type][2]
13
+ subject { song.tracks[track].bars[bar].get_beat(beat) }
14
+ end
15
+
16
+ describe GuitarProParser::Beat do
17
+
18
+ shared_examples 'any Guitar Pro version' do
19
+ context '1 beat, 1 bar, 1 track' do
20
+ test_beat :first
21
+
22
+ its(:dotted) { should == false }
23
+ its(:chord_diagram) { should be_nil }
24
+ its(:tuplet) { should be_nil }
25
+ its(:rest) { should be_nil }
26
+
27
+ its(:duration) { should == :eighth }
28
+ its(:text) { should == 'First beat' }
29
+ its(:effects) { should == {} }
30
+ its(:mix_table) { should be_nil }
31
+ its('strings.count') { should == 1 }
32
+ its(:strings) { should include '5' }
33
+ its(:transpose) { should be_nil }
34
+ end
35
+
36
+ context '2 beat, 1 bar, 1 track' do
37
+ test_beat :second
38
+ its(:text) { should == 'Second beat' }
39
+ its('strings.count') { should == 1 }
40
+ its(:strings) { should include '5' }
41
+ end
42
+
43
+ context '3 beat, 1 bar, 1 track' do
44
+ test_beat :third
45
+ its(:text) { should == 'Third beat' }
46
+ its('strings.count') { should == 1 }
47
+ its(:strings) { should include '4' }
48
+ end
49
+ end
50
+
51
+ context 'Guitar Pro 5' do
52
+ subject(:song) { GuitarProParser::Song.new test_tab_path 5 }
53
+ it_behaves_like 'any Guitar Pro version'
54
+
55
+ context 'mix table' do
56
+ test_beat :mix_table
57
+ its(:mix_table) { should == {:instrument=>25,
58
+ :volume=>{:value=>14, :transition=>2, :apply_to=>:all},
59
+ :chorus=>{:value=>2, :transition=>0, :apply_to=>:current},
60
+ :phaser=>{:value=>3, :transition=>1, :apply_to=>:current},
61
+ :rse_effect_2=>"Acoustic - Default", :rse_effect_1=>"Acoustic Tones"} }
62
+ end
63
+ end
64
+
65
+ context 'Guitar Pro 4' do
66
+ subject(:song) { GuitarProParser::Song.new test_tab_path 4 }
67
+ it_behaves_like 'any Guitar Pro version'
68
+
69
+ context 'mix table' do
70
+ test_beat :mix_table
71
+ its(:mix_table) { should == {:instrument=>25,
72
+ :volume=>{:value=>14, :transition=>2, :apply_to=>:all},
73
+ :chorus=>{:value=>2, :transition=>0, :apply_to=>:current},
74
+ :phaser=>{:value=>3, :transition=>1, :apply_to=>:current}} }
75
+ end
76
+ end
77
+
78
+
79
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe GuitarProParser::Channel do
4
+
5
+ shared_examples 'any Guitar Pro version' do
6
+ context 'port 1, channel 1' do
7
+ subject { song.channels[0][0] }
8
+
9
+ its(:instrument) { should == 30 }
10
+ its(:volume) { should == 13 }
11
+ its(:pan) { should == 8 }
12
+ its(:chorus) { should == 0 }
13
+ its(:reverb) { should == 0 }
14
+ its(:phaser) { should == 0 }
15
+ its(:tremolo) { should == 0 }
16
+ end
17
+
18
+ context 'port 1, channel 1' do
19
+ subject { song.channels[0][1] }
20
+ its(:instrument) { should == 30 }
21
+ end
22
+
23
+ context 'port 1, channel 3' do
24
+ subject { song.channels[0][2] }
25
+ its(:instrument) { should == 25 }
26
+ end
27
+
28
+ context 'port 1, channel 10 (drums)' do
29
+ subject { song.channels[0][9] }
30
+ its(:instrument) { should == 0 }
31
+ end
32
+ end
33
+
34
+ context 'Guitar Pro 5' do
35
+ subject(:song) { GuitarProParser::Song.new test_tab_path 5 }
36
+ it_behaves_like 'any Guitar Pro version'
37
+ end
38
+
39
+ context 'Guitar Pro 4' do
40
+ subject(:song) { GuitarProParser::Song.new test_tab_path 4 }
41
+ it_behaves_like 'any Guitar Pro version'
42
+ end
43
+
44
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe GuitarProHelper do
4
+ describe '.digit_to_note' do
5
+ it 'converts digit to correct note' do
6
+ digits = [0, 1, 2]
7
+ notes = ['C0', 'C#0', 'D0']
8
+ digits.count.times { |i| (GuitarProHelper.digit_to_note(digits.fetch(i))).should == notes.fetch(i) }
9
+ end
10
+ end
11
+ end