song_pro 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7926744caec7f509bb70754bda4dfb77ffa68dcd72566de3489162d9fd215ea
4
+ data.tar.gz: 8899b2137302c1e95862a0db9bae954bc7e055b1f45ef65c384984b82da5cfb2
5
+ SHA512:
6
+ metadata.gz: 946d6c7f401224daafb65c57b1a9e33ba9a7b2c887a7149e02228d19c38a8d9c8f2bc511ec56a49f536e6ab1fb02338a45493ccfc2279ab710cbe11f30b7c4cb
7
+ data.tar.gz: ffcea2097a1e359d0ab8715059309dcd86775ce553211862bd95e0ef2d94f75bd4dcf389c3889c5e1f39ee02e569b7be78f395039c9a28a57bee0654bf5489d4
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in song_pro.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ song_pro (0.1.1)
5
+ markaby
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ builder (3.2.3)
12
+ diff-lcs (1.3)
13
+ jaro_winkler (1.5.1)
14
+ markaby (0.9.0)
15
+ builder
16
+ parallel (1.12.1)
17
+ parser (2.5.1.2)
18
+ ast (~> 2.4.0)
19
+ powerpack (0.1.2)
20
+ rainbow (3.0.0)
21
+ rake (10.5.0)
22
+ rspec (3.8.0)
23
+ rspec-core (~> 3.8.0)
24
+ rspec-expectations (~> 3.8.0)
25
+ rspec-mocks (~> 3.8.0)
26
+ rspec-core (3.8.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-expectations (3.8.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-mocks (3.8.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-support (3.8.0)
35
+ rubocop (0.58.2)
36
+ jaro_winkler (~> 1.5.1)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.5, != 2.5.1.1)
39
+ powerpack (~> 0.1)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (~> 1.0, >= 1.0.1)
43
+ ruby-progressbar (1.10.0)
44
+ unicode-display_width (1.4.0)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 1.16)
51
+ rake (~> 10.0)
52
+ rspec (~> 3.0)
53
+ rubocop
54
+ song_pro!
55
+
56
+ BUNDLED WITH
57
+ 1.16.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Brian Kelly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # SongPro [![Build Status](https://travis-ci.org/spilth/song_pro.svg?branch=master)](https://travis-ci.org/spilth/song_pro)
2
+
3
+ SongPro is a text format for transcribing songs.
4
+
5
+ This project is a Ruby Gem that converts the song into a data model that can then be converted into various output formats such as text or HTML.
6
+
7
+ It is heavily inspired by [ChordPro](https://www.chordpro.org/).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'song_pro'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install song_pro
24
+
25
+ ## Usage
26
+
27
+ Given then file `bad-moon-rising.sng` with the following contents:
28
+
29
+ ```
30
+ @title=Bad Moon Rising
31
+ @artist=Cleedence Clearwater Revival
32
+
33
+ # Intro
34
+
35
+ [D][A][G][D]
36
+
37
+ # Verse 1
38
+
39
+ [D]I see a [A]bad [G]moon a-[D]rising
40
+ [D]I see [A]trouble [G]on the [D]way
41
+ [D]I see [A]earth-[G]quakes and [D]lightnin'
42
+ [D]I see [A]bad [G]times to-[D]day
43
+ ```
44
+
45
+ You can then parse the file to create a `Song` object:
46
+
47
+ ```ruby
48
+ require 'song_pro'
49
+
50
+ text = File.read('bad-moon-rising.sng')
51
+ song = SongPro.parse(text)
52
+
53
+ puts song.title
54
+ # Bad Moon Rising
55
+
56
+ puts song.artist
57
+ # Creedence Clearwater Revival
58
+
59
+ puts song.sections[1].title
60
+ # Verse 1
61
+
62
+ ```
63
+ ## SongPro Format
64
+
65
+ - Attributes are declared using: `@key=value`
66
+ - Sections are declared using: `# Section Name`
67
+ - Chords are declared using: `[Xy#]`
68
+
69
+ ```
70
+ @title=Bad Moon Rising
71
+ @artist=Cleedence Clearwater Revival
72
+
73
+ # Intro
74
+
75
+ [D][A][G][D]
76
+
77
+ # Verse 1
78
+
79
+ [D]I see a [A]bad [G]moon a-[D]rising
80
+ [D]I see [A]trouble [G]on the [D]way
81
+ [D]I see [A]earth-[G]quakes and [D]lightnin'
82
+ [D]I see [A]bad [G]times to-[D]day
83
+ ```
84
+
85
+ ## Song Object
86
+
87
+ - a **Song** can have a Title
88
+ - a **Song** can have an Artist
89
+ - a **Song** has zero or more **Sections**
90
+ - a **Section** has zero or more **Lines**
91
+ - a **Line** has one or more **Parts**
92
+ - a **Part** has a **Chord** and **Lyric**
93
+ - a **Chord** is the textual representation of a single chord
94
+ - this may be empty
95
+ - a **Lyric** is the textual representation of lyrics
96
+ - this may be empty
97
+
98
+ ## Development
99
+
100
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101
+
102
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
103
+
104
+ ## Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/spilth/song_pro>.
107
+
108
+ ## License
109
+
110
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "song_pro"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Line
4
+ attr_accessor :parts, :tablature
5
+
6
+ def initialize
7
+ @parts = []
8
+ @tablature = nil
9
+ end
10
+
11
+ def tablature?
12
+ return @tablature != nil
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Part
4
+ attr_accessor :lyric, :chord
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Section
4
+ attr_accessor :name, :lines
5
+
6
+ def initialize(name: '')
7
+ @name = name
8
+ @lines = []
9
+ end
10
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'markaby'
4
+
5
+ class Song
6
+ attr_accessor :title,
7
+ :artist,
8
+ :capo,
9
+ :key,
10
+ :tempo,
11
+ :year,
12
+ :album,
13
+ :tuning,
14
+ :sections
15
+
16
+ def initialize
17
+ @sections = []
18
+ end
19
+
20
+ def to_html
21
+ mab = Markaby::Builder.new(song: self)
22
+ mab.div.song do
23
+ h1.title song.title if song.title
24
+ h2.artist song.artist if song.artist
25
+
26
+ dl.information do
27
+ if song.tuning
28
+ dt.tuning 'Tuning'
29
+ dd.tuning song.tuning
30
+ end
31
+ if song.capo
32
+ dt.capo 'Capo'
33
+ dd.capo song.capo
34
+ end
35
+ if song.key
36
+ dt.key 'Key'
37
+ dd.key song.key
38
+ end
39
+ if song.tempo
40
+ dt.tempo 'Tempo'
41
+ dd.tempo song.tempo
42
+ end
43
+ if song.year
44
+ dt.year 'Year'
45
+ dd.year song.year
46
+ end
47
+ if song.album
48
+ dt.album 'Album'
49
+ dd.album song.album
50
+ end
51
+ end
52
+
53
+ song.sections.each do |section|
54
+ div.section do
55
+ div.name section.name
56
+ div.lines do
57
+ section.lines.each do |line|
58
+ if line.tablature?
59
+ div.tablature do
60
+ line.tablature
61
+ end
62
+ else
63
+ div.line do
64
+ line.parts.each do |part|
65
+ div.part do
66
+ div.chord part.chord
67
+ div.lyric part.lyric
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ mab.to_s
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module SongPro
2
+ VERSION = '0.1.1'.freeze
3
+ end
data/lib/song_pro.rb ADDED
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'song_pro/version'
4
+ require 'song_pro/song'
5
+ require 'song_pro/section'
6
+ require 'song_pro/line'
7
+ require 'song_pro/part'
8
+
9
+ module SongPro
10
+ SECTION_REGEX = /#\s*([^$]*)/
11
+ ATTRIBUTE_REGEX = /@(\w*)=([^%]*)/
12
+ CHORDS_AND_LYRICS_REGEX = /(\[[\w#b\/]+\])?([\w\s',.!\(\)_\-"]*)/i
13
+
14
+ def self.parse(lines)
15
+ song = Song.new
16
+ current_section = nil
17
+
18
+ lines.split("\n").each do |text|
19
+ if text.start_with?('@')
20
+ process_attribute(song, text)
21
+ elsif text.start_with?('#')
22
+ current_section = process_section(song, text)
23
+ else
24
+ process_lyrics_and_chords(song, current_section, text)
25
+ end
26
+ end
27
+
28
+ song
29
+ end
30
+
31
+ def self.process_section(song, text)
32
+ matches = SECTION_REGEX.match(text)
33
+ name = matches[1].strip
34
+ current_section = Section.new(name: name)
35
+ song.sections << current_section
36
+
37
+ current_section
38
+ end
39
+
40
+ def self.process_attribute(song, text)
41
+ matches = ATTRIBUTE_REGEX.match(text)
42
+ key = matches[1]
43
+ value = matches[2].strip
44
+
45
+ if song.respond_to?("#{key}=".to_sym)
46
+ song.send("#{key}=", value)
47
+ else
48
+ puts "WARNING: Unknown attribute '#{key}'"
49
+ end
50
+ end
51
+
52
+ def self.process_lyrics_and_chords(song, current_section, text)
53
+ return if text == ''
54
+
55
+ if current_section.nil?
56
+ current_section = Section.new(name: '')
57
+ song.sections << current_section
58
+ end
59
+
60
+ line = Line.new
61
+
62
+ if text.start_with?('|')
63
+ line.tablature = text
64
+ else
65
+ captures = text.scan(CHORDS_AND_LYRICS_REGEX).flatten
66
+
67
+ captures.each_slice(2) do |pair|
68
+ part = Part.new
69
+ chord = pair[0]&.strip || ''
70
+ part.chord = chord.delete('[').delete(']')
71
+ part.lyric = pair[1]&.strip || ''
72
+
73
+ line.parts << part unless (part.chord == '') && (part.lyric == '')
74
+ end
75
+ end
76
+
77
+ current_section.lines << line
78
+ end
79
+ end
data/song_pro.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'song_pro/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'song_pro'
9
+ spec.version = SongPro::VERSION
10
+ spec.authors = ['Brian Kelly']
11
+ spec.email = ['polymonic@gmail.com ']
12
+
13
+ spec.summary = 'Converts SongPro files to HTML'
14
+ spec.description = 'Provides classes for creating, parsing and rendering SongPro files'
15
+ spec.homepage = 'https://songpro.org'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ 'public gem pushes.'
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_dependency 'markaby'
35
+ spec.add_development_dependency 'bundler', '~> 1.16'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+ spec.add_development_dependency 'rubocop'
39
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: song_pro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Kelly
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: markaby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Provides classes for creating, parsing and rendering SongPro files
84
+ email:
85
+ - 'polymonic@gmail.com '
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".ruby-version"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/song_pro.rb
102
+ - lib/song_pro/line.rb
103
+ - lib/song_pro/part.rb
104
+ - lib/song_pro/section.rb
105
+ - lib/song_pro/song.rb
106
+ - lib/song_pro/version.rb
107
+ - song_pro.gemspec
108
+ homepage: https://songpro.org
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.7.6
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Converts SongPro files to HTML
133
+ test_files: []