scale_generator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.document +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/README.rdoc +119 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/AMajorScale-intervals.png +0 -0
- data/examples/AMajorScale.png +0 -0
- data/lib/scale_dsl/scale_dsl.rb +47 -0
- data/lib/scale_generator.rb +3 -0
- data/lib/scale_generator/.DS_Store +0 -0
- data/lib/scale_generator/dictionary.rb +28 -0
- data/lib/scale_generator/png_formatter.rb +134 -0
- data/lib/scale_generator/scale.rb +21 -0
- data/scale_generator.gemspec +75 -0
- data/test/helper.rb +18 -0
- data/test/test_scale_generator.rb +115 -0
- metadata +174 -0
data/.DS_Store
ADDED
Binary file
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "rmagick"
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "shoulda", ">= 0"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.8.4"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.8)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
git (1.2.5)
|
8
|
+
i18n (0.6.1)
|
9
|
+
jeweler (1.8.4)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
rdoc
|
14
|
+
json (1.7.5)
|
15
|
+
multi_json (1.3.6)
|
16
|
+
rake (0.9.2.2)
|
17
|
+
rcov (1.0.0)
|
18
|
+
rdoc (3.12)
|
19
|
+
json (~> 1.4)
|
20
|
+
rmagick (2.13.1)
|
21
|
+
shoulda (3.3.2)
|
22
|
+
shoulda-context (~> 1.0.1)
|
23
|
+
shoulda-matchers (~> 1.4.1)
|
24
|
+
shoulda-context (1.0.1)
|
25
|
+
shoulda-matchers (1.4.1)
|
26
|
+
activesupport (>= 3.0.0)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
bundler (~> 1.0.0)
|
33
|
+
jeweler (~> 1.8.4)
|
34
|
+
rcov
|
35
|
+
rdoc (~> 3.12)
|
36
|
+
rmagick
|
37
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 dlbunker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
= scale_generator
|
2
|
+
|
3
|
+
A Ruby library to generate images of guitar, ukulele, mandolin or banjo scale diagrams
|
4
|
+
|
5
|
+
Installation
|
6
|
+
---
|
7
|
+
|
8
|
+
gem install scale_generator
|
9
|
+
|
10
|
+
or if you are using Bundler, add this line to your Gemfile:
|
11
|
+
|
12
|
+
gem 'scale_generator'
|
13
|
+
|
14
|
+
Usage
|
15
|
+
---
|
16
|
+
|
17
|
+
Create a DSL block with your scale definition. For each string block you can define the frets you want a dot placed, the fingering you want to use and the scale intervals for that string. An A Major scale example:
|
18
|
+
|
19
|
+
File.open("./AMajorScale.png", 'w') do |f|
|
20
|
+
diagram = ScaleGenerator::Scale.new(
|
21
|
+
scale 'A Major Scale' do
|
22
|
+
inst_string 1 do
|
23
|
+
frets 4, 5, 7
|
24
|
+
fingering 1, 2, 4
|
25
|
+
intervals 7, 1, 9
|
26
|
+
end
|
27
|
+
inst_string 2 do
|
28
|
+
frets 5, 7
|
29
|
+
fingering 2, 4
|
30
|
+
intervals 5, 13
|
31
|
+
end
|
32
|
+
inst_string 3 do
|
33
|
+
frets 4, 6, 7
|
34
|
+
fingering 1, 3, 4
|
35
|
+
intervals 9, 3, 11
|
36
|
+
end
|
37
|
+
inst_string 4 do
|
38
|
+
frets 4, 6, 7
|
39
|
+
fingering 1, 3, 4
|
40
|
+
intervals 6, 7, 1
|
41
|
+
end
|
42
|
+
inst_string 5 do
|
43
|
+
frets 4, 5, 7
|
44
|
+
fingering 1, 2, 4
|
45
|
+
intervals 3, 4, 5
|
46
|
+
end
|
47
|
+
inst_string 6 do
|
48
|
+
frets 4, 5, 7
|
49
|
+
fingering 1, 2, 4
|
50
|
+
intervals 7, 1, 2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
)
|
54
|
+
f.write diagram.to_png()
|
55
|
+
end
|
56
|
+
|
57
|
+
This will write a basic A Major Scale to <tt>./AMajorScale.png</tt>:
|
58
|
+
|
59
|
+
![A - Major](https://github.com/dlbunker/chord_generator/raw/master/examples/AMajorScale.png)
|
60
|
+
|
61
|
+
If you'd prefer to print the intervals rather than the finger use the true parameter on the .to_png method call:
|
62
|
+
|
63
|
+
File.open("./AMajorScale-intervals.png", 'w') do |f|
|
64
|
+
diagram = ScaleGenerator::Scale.new(
|
65
|
+
scale 'A Major Scale' do
|
66
|
+
inst_string 1 do
|
67
|
+
frets 4, 5, 7
|
68
|
+
fingering 1, 2, 4
|
69
|
+
intervals 7, 1, 9
|
70
|
+
end
|
71
|
+
inst_string 2 do
|
72
|
+
frets 5, 7
|
73
|
+
fingering 2, 4
|
74
|
+
intervals 5, 13
|
75
|
+
end
|
76
|
+
inst_string 3 do
|
77
|
+
frets 4, 6, 7
|
78
|
+
fingering 1, 3, 4
|
79
|
+
intervals 9, 3, 11
|
80
|
+
end
|
81
|
+
inst_string 4 do
|
82
|
+
frets 4, 6, 7
|
83
|
+
fingering 1, 3, 4
|
84
|
+
intervals 6, 7, 1
|
85
|
+
end
|
86
|
+
inst_string 5 do
|
87
|
+
frets 4, 5, 7
|
88
|
+
fingering 1, 2, 4
|
89
|
+
intervals 3, 4, 5
|
90
|
+
end
|
91
|
+
inst_string 6 do
|
92
|
+
frets 4, 5, 7
|
93
|
+
fingering 1, 2, 4
|
94
|
+
intervals 7, 1, 2
|
95
|
+
end
|
96
|
+
end
|
97
|
+
)
|
98
|
+
f.write diagram.to_png(true)
|
99
|
+
end
|
100
|
+
|
101
|
+
This will write a basic A Major Scale with intervals to <tt>./AMajorScale-intervals.png</tt>:
|
102
|
+
|
103
|
+
![A - Major](https://github.com/dlbunker/chord_generator/raw/master/examples/AMajorScale-intervals.png)
|
104
|
+
|
105
|
+
== Contributing to scale_generator
|
106
|
+
|
107
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
108
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
109
|
+
* Fork the project.
|
110
|
+
* Start a feature/bugfix branch.
|
111
|
+
* Commit and push until you are happy with your contribution.
|
112
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
113
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
114
|
+
|
115
|
+
== Copyright
|
116
|
+
|
117
|
+
Copyright (c) 2012 Dan Bunker. See LICENSE.txt for
|
118
|
+
further details.
|
119
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "scale_generator"
|
18
|
+
gem.homepage = "http://github.com/dlbunker/scale_generator"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A Ruby library to generate images of guitar, ukulele, mandolin or banjo scale diagrams}
|
21
|
+
gem.description = %Q{A Ruby library to generate images of guitar, ukulele, mandolin or banjo scale diagrams}
|
22
|
+
gem.email = "mcirque@gmail.com"
|
23
|
+
gem.authors = ["dlbunker"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "scale_generator #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
Binary file
|
Binary file
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ScaleDSL
|
2
|
+
def scale(scale_label, &block)
|
3
|
+
scale_ctx = ScaleContext.new scale_label
|
4
|
+
scale_ctx.instance_exec &block
|
5
|
+
scale_ctx.scale_hash
|
6
|
+
end
|
7
|
+
|
8
|
+
class ScaleContext
|
9
|
+
attr_reader :scale_hash
|
10
|
+
|
11
|
+
def initialize(scale_label)
|
12
|
+
@scale_hash = {:label => scale_label}
|
13
|
+
end
|
14
|
+
|
15
|
+
def inst_string(string_num, &block)
|
16
|
+
str_ctx = StringContext.new
|
17
|
+
str_ctx.instance_exec &block
|
18
|
+
string_hash = {:frets => str_ctx.fret_array, :fingers => str_ctx.finger_array, :intervals => str_ctx.interval_array}
|
19
|
+
@scale_hash[string_num] = string_hash
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class StringContext
|
24
|
+
attr_reader :fret_array
|
25
|
+
attr_reader :finger_array
|
26
|
+
attr_reader :interval_array
|
27
|
+
|
28
|
+
def initialize()
|
29
|
+
@fret_array = []
|
30
|
+
@finger_array = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def frets(*frets)
|
34
|
+
@fret_array = frets
|
35
|
+
end
|
36
|
+
|
37
|
+
def fingering(*fingers)
|
38
|
+
@finger_array = fingers
|
39
|
+
end
|
40
|
+
|
41
|
+
def intervals(*vals)
|
42
|
+
@interval_array = vals
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
include ScaleDSL
|
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ScaleGenerator
|
2
|
+
class Dictionary
|
3
|
+
|
4
|
+
GUITAR_TUNINGS = {
|
5
|
+
:standard => ["E", "A", "D", "G", "B", "E"],
|
6
|
+
:drop_d => ["D", "A", "D", "G", "B", "E"]
|
7
|
+
}
|
8
|
+
|
9
|
+
BASS_TUNINGS = {
|
10
|
+
:standard => ["E", "A", "D", "G"]
|
11
|
+
}
|
12
|
+
|
13
|
+
MANDOLIN_TUNINGS = {
|
14
|
+
:standard => ["G", "D", "A", "E"]
|
15
|
+
}
|
16
|
+
|
17
|
+
UKULELE_TUNINGS = {
|
18
|
+
:c6 => ["G", "C", "E", "A"],
|
19
|
+
:baritone => ["D", "G", "B", "E"]
|
20
|
+
}
|
21
|
+
|
22
|
+
private
|
23
|
+
def self.normalize_frets(frets)
|
24
|
+
join_with = frets.any? { |f| f && f >= 10 } ? "-" : ""
|
25
|
+
frets.map { |f| f.nil? ? "x" : f.to_s }.join(join_with)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'rvg/rvg' # rmagick's RVG (Ruby Vector Graphics)
|
2
|
+
|
3
|
+
module ScaleGenerator
|
4
|
+
Magick::RVG::dpi = 72
|
5
|
+
# Formats a single fingering as png data
|
6
|
+
class PNGFormatter
|
7
|
+
|
8
|
+
def initialize(scale_hash, strings)
|
9
|
+
@scale_hash = scale_hash
|
10
|
+
@strings = strings
|
11
|
+
end
|
12
|
+
|
13
|
+
def print(options={}, show_intervals = false)
|
14
|
+
@label = options[:label]
|
15
|
+
@show_intervals = show_intervals
|
16
|
+
@frets = []
|
17
|
+
|
18
|
+
@scale_hash.each do |key, val|
|
19
|
+
if key.is_a?(Numeric)
|
20
|
+
@frets << val[:frets]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@max_fret = @frets.flatten.max
|
25
|
+
@min_fret = @frets.flatten.min
|
26
|
+
@min_fret = 1 if @max_fret <= 4
|
27
|
+
@number_of_frets = [@max_fret - @min_fret + 1, 4].max
|
28
|
+
|
29
|
+
get_png_data
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def get_png_data
|
35
|
+
width = 160 + (@strings.size * 40)
|
36
|
+
height = 340
|
37
|
+
|
38
|
+
rvg = Magick::RVG.new(40 + (@strings.size * 40), 210).viewbox(0,0,width,height) do |canvas|
|
39
|
+
canvas.background_fill = 'white'
|
40
|
+
|
41
|
+
width_of_chord = 20 + (@strings.size * 40)
|
42
|
+
margin_side_of_chord = (width - width_of_chord) / 2
|
43
|
+
|
44
|
+
height_of_chord = 200
|
45
|
+
margin_top_of_chord = ((height - height_of_chord) * 2 / 3.0).floor
|
46
|
+
margin_bottom_of_chord = ((height - height_of_chord) / 3.0).ceil
|
47
|
+
|
48
|
+
height_of_fret = height_of_chord / @number_of_frets
|
49
|
+
radius_of_finger = (height_of_fret * 0.6) / 2
|
50
|
+
|
51
|
+
width_of_fret = width_of_chord / (@strings.size - 1)
|
52
|
+
|
53
|
+
# Draw all horizontal lines
|
54
|
+
(@number_of_frets+1).times do |n|
|
55
|
+
if n == 0 && @min_fret == 1
|
56
|
+
canvas.line(margin_side_of_chord, n*height_of_fret+margin_top_of_chord, width - margin_side_of_chord, n*height_of_fret+margin_top_of_chord).styles(:stroke=>'black', :stroke_width => 5)
|
57
|
+
else
|
58
|
+
canvas.line(margin_side_of_chord, n*height_of_fret+margin_top_of_chord, width - margin_side_of_chord, n*height_of_fret+margin_top_of_chord)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
(@number_of_frets).times do |i|
|
63
|
+
canvas.text(margin_side_of_chord - radius_of_finger - 4, i*height_of_fret+margin_top_of_chord + height_of_fret / 2 + 10) do |txt|
|
64
|
+
txt.tspan(@min_fret + i).styles(
|
65
|
+
:text_anchor => 'end',
|
66
|
+
:font_size => 24,
|
67
|
+
:font_family => 'helvetica',
|
68
|
+
:fill => 'black')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# bar_drawn = false
|
73
|
+
fret_index = @strings.size
|
74
|
+
@strings.each_with_index do |note, i|
|
75
|
+
# Draw vertical lines
|
76
|
+
canvas.line(i*width_of_fret+margin_side_of_chord, margin_top_of_chord, i*width_of_fret+margin_side_of_chord, height - margin_bottom_of_chord)
|
77
|
+
|
78
|
+
str_ctx = @scale_hash[fret_index]
|
79
|
+
fret_index = fret_index - 1
|
80
|
+
str_ctx[:frets].each_with_index do | fret, ii |
|
81
|
+
# Add a finger
|
82
|
+
if str_ctx[:intervals][ii] == 1
|
83
|
+
canvas.circle(radius_of_finger, i*width_of_fret+margin_side_of_chord,
|
84
|
+
(fret - @min_fret + 1)*height_of_fret - (height_of_fret / 2) + margin_top_of_chord).styles(:fill => 'green')
|
85
|
+
else
|
86
|
+
canvas.circle(radius_of_finger, i*width_of_fret+margin_side_of_chord,
|
87
|
+
(fret - @min_fret + 1)*height_of_fret - (height_of_fret / 2) + margin_top_of_chord)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Add fingering to finger dot
|
91
|
+
if str_ctx[:fingers][ii] && !@show_intervals
|
92
|
+
canvas.text(i*width_of_fret+margin_side_of_chord + 1, (fret - @min_fret + 1)*height_of_fret - (height_of_fret / 2) + margin_top_of_chord + 8) do |txt|
|
93
|
+
txt.tspan(str_ctx[:fingers][ii].to_s).styles(:text_anchor => 'middle',
|
94
|
+
:font_size => 24,
|
95
|
+
:font_family => 'helvetica',
|
96
|
+
:fill => 'white')
|
97
|
+
end
|
98
|
+
elsif @show_intervals
|
99
|
+
canvas.text(i*width_of_fret+margin_side_of_chord + 1, (fret - @min_fret + 1)*height_of_fret - (height_of_fret / 2) + margin_top_of_chord + 8) do |txt|
|
100
|
+
txt.tspan(str_ctx[:intervals][ii].to_s).styles(:text_anchor => 'middle',
|
101
|
+
:font_size => 24,
|
102
|
+
:font_family => 'helvetica',
|
103
|
+
:fill => 'white')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
canvas.text(i*width_of_fret+margin_side_of_chord, height - margin_bottom_of_chord + 20) do |txt|
|
109
|
+
txt.tspan(note).styles(:text_anchor => 'middle',
|
110
|
+
:font_size => 18,
|
111
|
+
:font_family => 'helvetica',
|
112
|
+
:fill => 'black')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
if @label
|
117
|
+
canvas.text(width / 2, margin_top_of_chord / 2) do |txt|
|
118
|
+
txt.tspan(@label).styles(:text_anchor => 'middle',
|
119
|
+
:font_size => 36,
|
120
|
+
:font_family => 'helvetica',
|
121
|
+
:fill => 'black',
|
122
|
+
:font_weight => 'bold')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
img = rvg.draw
|
128
|
+
img = img.trim
|
129
|
+
img.format = 'PNG'
|
130
|
+
img.to_blob
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'scale_generator/png_formatter'
|
2
|
+
require 'scale_generator/dictionary'
|
3
|
+
|
4
|
+
module ScaleGenerator
|
5
|
+
class Scale
|
6
|
+
def initialize(scale_hash, tuning = nil)
|
7
|
+
@scale_hash = scale_hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_png(show_intervals = false, options = {})
|
11
|
+
tuning = (options[:tuning].nil?) ? ScaleGenerator::Dictionary::GUITAR_TUNINGS[:standard] : options[:tuning]
|
12
|
+
|
13
|
+
ScaleGenerator::PNGFormatter.new(@scale_hash, tuning).print(@scale_hash, show_intervals)
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
ScaleGenerator::Dictionary.name_for(frets)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "scale_generator"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["dlbunker"]
|
12
|
+
s.date = "2012-11-14"
|
13
|
+
s.description = "A Ruby library to generate images of guitar, ukulele, mandolin or banjo scale diagrams"
|
14
|
+
s.email = "mcirque@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".DS_Store",
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"examples/AMajorScale-intervals.png",
|
31
|
+
"examples/AMajorScale.png",
|
32
|
+
"lib/scale_dsl/scale_dsl.rb",
|
33
|
+
"lib/scale_generator.rb",
|
34
|
+
"lib/scale_generator/.DS_Store",
|
35
|
+
"lib/scale_generator/dictionary.rb",
|
36
|
+
"lib/scale_generator/png_formatter.rb",
|
37
|
+
"lib/scale_generator/scale.rb",
|
38
|
+
"scale_generator.gemspec",
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/test_scale_generator.rb"
|
41
|
+
]
|
42
|
+
s.homepage = "http://github.com/dlbunker/scale_generator"
|
43
|
+
s.licenses = ["MIT"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = "1.8.15"
|
46
|
+
s.summary = "A Ruby library to generate images of guitar, ukulele, mandolin or banjo scale diagrams"
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<rmagick>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
57
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<rmagick>, [">= 0"])
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<rmagick>, [">= 0"])
|
68
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
72
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'scale_generator'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestScaleGenerator < Test::Unit::TestCase
|
4
|
+
should "generate a scale diagram" do
|
5
|
+
s = scale 'A Major Scale' do
|
6
|
+
inst_string 1 do
|
7
|
+
frets 4, 5, 7
|
8
|
+
fingering 1, 2, 4
|
9
|
+
intervals 7, 1, 9
|
10
|
+
end
|
11
|
+
inst_string 2 do
|
12
|
+
frets 5, 7
|
13
|
+
fingering 2, 4
|
14
|
+
intervals 5, 13
|
15
|
+
end
|
16
|
+
inst_string 3 do
|
17
|
+
frets 4, 6, 7
|
18
|
+
fingering 1, 3, 4
|
19
|
+
intervals 9, 3, 11
|
20
|
+
end
|
21
|
+
inst_string 4 do
|
22
|
+
frets 4, 6, 7
|
23
|
+
fingering 1, 3, 4
|
24
|
+
intervals 6, 7, 1
|
25
|
+
end
|
26
|
+
inst_string 5 do
|
27
|
+
frets 4, 5, 7
|
28
|
+
fingering 1, 2, 4
|
29
|
+
intervals 3, 4, 5
|
30
|
+
end
|
31
|
+
inst_string 6 do
|
32
|
+
frets 5, 7
|
33
|
+
fingering 2, 4
|
34
|
+
intervals 1, 2
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
File.open("./#{s[:label]}.png", 'w') do |f|
|
39
|
+
diagram = ScaleGenerator::Scale.new(
|
40
|
+
scale 'A Major Scale' do
|
41
|
+
inst_string 1 do
|
42
|
+
frets 4, 5, 7
|
43
|
+
fingering 1, 2, 4
|
44
|
+
intervals 7, 1, 9
|
45
|
+
end
|
46
|
+
inst_string 2 do
|
47
|
+
frets 5, 7
|
48
|
+
fingering 2, 4
|
49
|
+
intervals 5, 13
|
50
|
+
end
|
51
|
+
inst_string 3 do
|
52
|
+
frets 4, 6, 7
|
53
|
+
fingering 1, 3, 4
|
54
|
+
intervals 9, 3, 11
|
55
|
+
end
|
56
|
+
inst_string 4 do
|
57
|
+
frets 4, 6, 7
|
58
|
+
fingering 1, 3, 4
|
59
|
+
intervals 6, 7, 1
|
60
|
+
end
|
61
|
+
inst_string 5 do
|
62
|
+
frets 4, 5, 7
|
63
|
+
fingering 1, 2, 4
|
64
|
+
intervals 3, 4, 5
|
65
|
+
end
|
66
|
+
inst_string 6 do
|
67
|
+
frets 4, 5, 7
|
68
|
+
fingering 1, 2, 4
|
69
|
+
intervals 7, 1, 2
|
70
|
+
end
|
71
|
+
end
|
72
|
+
)
|
73
|
+
f.write diagram.to_png()
|
74
|
+
end
|
75
|
+
|
76
|
+
File.open("./#{s[:label]}-intervals.png", 'w') do |f|
|
77
|
+
diagram = ScaleGenerator::Scale.new(
|
78
|
+
scale 'A Major Scale' do
|
79
|
+
inst_string 1 do
|
80
|
+
frets 4, 5, 7
|
81
|
+
fingering 1, 2, 4
|
82
|
+
intervals 7, 1, 9
|
83
|
+
end
|
84
|
+
inst_string 2 do
|
85
|
+
frets 5, 7
|
86
|
+
fingering 2, 4
|
87
|
+
intervals 5, 13
|
88
|
+
end
|
89
|
+
inst_string 3 do
|
90
|
+
frets 4, 6, 7
|
91
|
+
fingering 1, 3, 4
|
92
|
+
intervals 9, 3, 11
|
93
|
+
end
|
94
|
+
inst_string 4 do
|
95
|
+
frets 4, 6, 7
|
96
|
+
fingering 1, 3, 4
|
97
|
+
intervals 6, 7, 1
|
98
|
+
end
|
99
|
+
inst_string 5 do
|
100
|
+
frets 4, 5, 7
|
101
|
+
fingering 1, 2, 4
|
102
|
+
intervals 3, 4, 5
|
103
|
+
end
|
104
|
+
inst_string 6 do
|
105
|
+
frets 4, 5, 7
|
106
|
+
fingering 1, 2, 4
|
107
|
+
intervals 7, 1, 2
|
108
|
+
end
|
109
|
+
end
|
110
|
+
)
|
111
|
+
f.write diagram.to_png(true)
|
112
|
+
end
|
113
|
+
# flunk "something went wrong"
|
114
|
+
end
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scale_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- dlbunker
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-11-14 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
version_requirements: *id001
|
31
|
+
name: rmagick
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
version_requirements: *id002
|
45
|
+
name: shoulda
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 31
|
55
|
+
segments:
|
56
|
+
- 3
|
57
|
+
- 12
|
58
|
+
version: "3.12"
|
59
|
+
version_requirements: *id003
|
60
|
+
name: rdoc
|
61
|
+
prerelease: false
|
62
|
+
type: :development
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 23
|
70
|
+
segments:
|
71
|
+
- 1
|
72
|
+
- 0
|
73
|
+
- 0
|
74
|
+
version: 1.0.0
|
75
|
+
version_requirements: *id004
|
76
|
+
name: bundler
|
77
|
+
prerelease: false
|
78
|
+
type: :development
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 63
|
86
|
+
segments:
|
87
|
+
- 1
|
88
|
+
- 8
|
89
|
+
- 4
|
90
|
+
version: 1.8.4
|
91
|
+
version_requirements: *id005
|
92
|
+
name: jeweler
|
93
|
+
prerelease: false
|
94
|
+
type: :development
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
version_requirements: *id006
|
106
|
+
name: rcov
|
107
|
+
prerelease: false
|
108
|
+
type: :development
|
109
|
+
description: A Ruby library to generate images of guitar, ukulele, mandolin or banjo scale diagrams
|
110
|
+
email: mcirque@gmail.com
|
111
|
+
executables: []
|
112
|
+
|
113
|
+
extensions: []
|
114
|
+
|
115
|
+
extra_rdoc_files:
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.md
|
118
|
+
- README.rdoc
|
119
|
+
files:
|
120
|
+
- .DS_Store
|
121
|
+
- .document
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- README.rdoc
|
127
|
+
- Rakefile
|
128
|
+
- VERSION
|
129
|
+
- examples/AMajorScale-intervals.png
|
130
|
+
- examples/AMajorScale.png
|
131
|
+
- lib/scale_dsl/scale_dsl.rb
|
132
|
+
- lib/scale_generator.rb
|
133
|
+
- lib/scale_generator/.DS_Store
|
134
|
+
- lib/scale_generator/dictionary.rb
|
135
|
+
- lib/scale_generator/png_formatter.rb
|
136
|
+
- lib/scale_generator/scale.rb
|
137
|
+
- scale_generator.gemspec
|
138
|
+
- test/helper.rb
|
139
|
+
- test/test_scale_generator.rb
|
140
|
+
homepage: http://github.com/dlbunker/scale_generator
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
hash: 3
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
version: "0"
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
hash: 3
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
version: "0"
|
166
|
+
requirements: []
|
167
|
+
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 1.8.15
|
170
|
+
signing_key:
|
171
|
+
specification_version: 3
|
172
|
+
summary: A Ruby library to generate images of guitar, ukulele, mandolin or banjo scale diagrams
|
173
|
+
test_files: []
|
174
|
+
|