GTP 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/GTP.gemspec +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +10 -0
- data/lib/GTP/gp4.rb +117 -0
- data/lib/GTP/version.rb +3 -0
- data/lib/GTP.rb +6 -0
- data/test/lib/GTP/gp4_test.rb +53 -0
- data/test/lib/GTP/version_test.rb +8 -0
- data/test/tabs/test.gp3 +0 -0
- data/test/tabs/test.gp4 +0 -0
- data/test/tabs/test.gp5 +0 -0
- data/test/tabs/test2.gp4 +0 -0
- data/test/test_helper.rb +3 -0
- metadata +108 -0
data/.gitignore
ADDED
data/GTP.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'GTP/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "GTP"
|
8
|
+
spec.version = GTP::VERSION
|
9
|
+
spec.authors = ["Thiago Rocha"]
|
10
|
+
spec.email = ["kimo@kimo.io"]
|
11
|
+
spec.description = %q{A Guitar Pro file parser}
|
12
|
+
spec.summary = %q{It parses gtp files}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Thiago Rocha
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# GTP
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'GTP'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install GTP
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/GTP/gp4.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
module GTP
|
2
|
+
class GP4
|
3
|
+
|
4
|
+
attr_accessor :file,
|
5
|
+
:version,
|
6
|
+
:title,
|
7
|
+
:subtitle,
|
8
|
+
:artist,
|
9
|
+
:album,
|
10
|
+
:author,
|
11
|
+
:copyright,
|
12
|
+
:tab,
|
13
|
+
:instruction,
|
14
|
+
:notice,
|
15
|
+
:triplet_feel,
|
16
|
+
:offset
|
17
|
+
attr_reader :file_path
|
18
|
+
|
19
|
+
INTEGER_SIZE = 4
|
20
|
+
|
21
|
+
def initialize(tab_path)
|
22
|
+
@file = File.open(tab_path, "r")
|
23
|
+
@offset = 31
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_string
|
27
|
+
|
28
|
+
self.offset = self.offset+INTEGER_SIZE
|
29
|
+
|
30
|
+
length = IO.binread(self.file, 1, self.offset).bytes.to_a[0].to_i
|
31
|
+
|
32
|
+
self.offset = self.offset + 1
|
33
|
+
|
34
|
+
string = IO.binread(self.file, length, self.offset)
|
35
|
+
|
36
|
+
self.offset = self.offset + length
|
37
|
+
|
38
|
+
return string
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_version
|
42
|
+
|
43
|
+
size = IO.binread(self.file, 1).bytes.to_a[0].to_i
|
44
|
+
|
45
|
+
self.version = IO.binread(self.file, size, 1).strip
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_info
|
49
|
+
parse_title
|
50
|
+
parse_subtitle
|
51
|
+
parse_artist
|
52
|
+
parse_album
|
53
|
+
parse_author
|
54
|
+
parse_copyright
|
55
|
+
parse_tab
|
56
|
+
parse_instruction
|
57
|
+
parse_notice
|
58
|
+
parse_triplet_feel
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_title
|
62
|
+
self.title = read_string
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_subtitle
|
66
|
+
self.subtitle = read_string
|
67
|
+
end
|
68
|
+
|
69
|
+
def parse_artist
|
70
|
+
self.artist = read_string
|
71
|
+
end
|
72
|
+
|
73
|
+
def parse_album
|
74
|
+
self.album = read_string
|
75
|
+
end
|
76
|
+
|
77
|
+
def parse_author
|
78
|
+
self.author = read_string
|
79
|
+
end
|
80
|
+
|
81
|
+
def parse_copyright
|
82
|
+
self.copyright = read_string
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_tab
|
86
|
+
self.tab = read_string
|
87
|
+
end
|
88
|
+
|
89
|
+
def parse_instruction
|
90
|
+
self.instruction = read_string
|
91
|
+
end
|
92
|
+
|
93
|
+
def parse_notice
|
94
|
+
lines = IO.binread(self.file, INTEGER_SIZE, self.offset).unpack("L")[0]
|
95
|
+
|
96
|
+
self.offset = self.offset+INTEGER_SIZE
|
97
|
+
|
98
|
+
notice = ""
|
99
|
+
|
100
|
+
for i in 1..lines-1
|
101
|
+
notice << read_string << "\n"
|
102
|
+
end
|
103
|
+
|
104
|
+
notice << read_string
|
105
|
+
|
106
|
+
self.notice = notice
|
107
|
+
end
|
108
|
+
|
109
|
+
def parse_triplet_feel
|
110
|
+
self.triplet_feel = IO.binread(self.file, 1, self.offset).bytes.to_a[0].to_s
|
111
|
+
end
|
112
|
+
|
113
|
+
def to_json
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/GTP/version.rb
ADDED
data/lib/GTP.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe GTP::GP4 do
|
4
|
+
|
5
|
+
it "must read the file version" do
|
6
|
+
parser = GTP::GP4.new "test/tabs/test.gp4"
|
7
|
+
|
8
|
+
parser.parse_version
|
9
|
+
|
10
|
+
parser.version.must_match %r/FICHIER GUITAR PRO v4./
|
11
|
+
end
|
12
|
+
|
13
|
+
it "must read the tablature info" do
|
14
|
+
parser = GTP::GP4.new "test/tabs/test.gp4"
|
15
|
+
|
16
|
+
parser.parse_info
|
17
|
+
|
18
|
+
parser.title.must_equal "Title"
|
19
|
+
parser.subtitle.must_equal "Subtitle"
|
20
|
+
parser.artist.must_equal "Artist"
|
21
|
+
parser.album.must_equal "Album"
|
22
|
+
parser.author.must_equal "Author"
|
23
|
+
parser.copyright.must_equal "Copyright"
|
24
|
+
parser.tab.must_equal "Tab"
|
25
|
+
parser.instruction.must_equal "Instruction"
|
26
|
+
parser.notice.must_equal "N line 1\nN line 2\nN line 3\nN line 4"
|
27
|
+
parser.triplet_feel.must_match "0"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "must read the tablature lyrics" do
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
it "must read the tablature extra info" do
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
it "must read the tablature measures" do
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
it "must read the tablature tracks" do
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
it "must read the tablature song" do
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
it "must read the tablature chord diagrams" do
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/test/tabs/test.gp3
ADDED
Binary file
|
data/test/tabs/test.gp4
ADDED
Binary file
|
data/test/tabs/test.gp5
ADDED
Binary file
|
data/test/tabs/test2.gp4
ADDED
Binary file
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: GTP
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Thiago Rocha
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-06-30 00:00:00 -03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 3
|
30
|
+
version: "1.3"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
version: "0"
|
43
|
+
type: :development
|
44
|
+
version_requirements: *id002
|
45
|
+
description: A Guitar Pro file parser
|
46
|
+
email:
|
47
|
+
- kimo@kimo.io
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files: []
|
53
|
+
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- GTP.gemspec
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/GTP.rb
|
62
|
+
- lib/GTP/gp4.rb
|
63
|
+
- lib/GTP/version.rb
|
64
|
+
- test/lib/GTP/gp4_test.rb
|
65
|
+
- test/lib/GTP/version_test.rb
|
66
|
+
- test/tabs/test.gp3
|
67
|
+
- test/tabs/test.gp4
|
68
|
+
- test/tabs/test.gp5
|
69
|
+
- test/tabs/test2.gp4
|
70
|
+
- test/test_helper.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: ""
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.3.6
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: It parses gtp files
|
101
|
+
test_files:
|
102
|
+
- test/lib/GTP/gp4_test.rb
|
103
|
+
- test/lib/GTP/version_test.rb
|
104
|
+
- test/tabs/test.gp3
|
105
|
+
- test/tabs/test.gp4
|
106
|
+
- test/tabs/test.gp5
|
107
|
+
- test/tabs/test2.gp4
|
108
|
+
- test/test_helper.rb
|