interval-quiz 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.mkd +4 -0
- data/Rakefile +55 -0
- data/bin/interval-quiz +11 -0
- data/lib/interval-quiz.rb +113 -0
- data/spec/interval-quiz_spec.rb +7 -0
- data/spec/spec_helper.rb +2 -0
- metadata +71 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 YOUR NAME
|
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.mkd
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rubygems/specification'
|
4
|
+
require 'date'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
GEM = "interval-quiz"
|
8
|
+
GEM_VERSION = "0.0.1"
|
9
|
+
|
10
|
+
spec = Gem::Specification.new do |s|
|
11
|
+
s.name = GEM
|
12
|
+
s.version = GEM_VERSION
|
13
|
+
s.author = "Nate Murray"
|
14
|
+
s.email = "nate@natemurray.com"
|
15
|
+
s.homepage = "http://www.xcombinator.com"
|
16
|
+
s.description = s.summary = "A gem that provides a quiz on musical intervals"
|
17
|
+
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["README.mkd", "LICENSE"]
|
21
|
+
s.summary = "a quiz for musical intervals"
|
22
|
+
s.bindir = "bin"
|
23
|
+
s.executables = ['interval-quiz']
|
24
|
+
|
25
|
+
# Uncomment this to add a dependency
|
26
|
+
s.add_dependency "interval"
|
27
|
+
|
28
|
+
s.require_path = 'lib'
|
29
|
+
s.files = %w(LICENSE README.mkd Rakefile) + Dir.glob("{lib,spec,bin}/**/*")
|
30
|
+
end
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
desc "Run specs"
|
35
|
+
Spec::Rake::SpecTask.new do |t|
|
36
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
37
|
+
t.spec_opts = %w(-fs --color)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
42
|
+
pkg.gem_spec = spec
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "install the gem locally"
|
46
|
+
task :install => [:package] do
|
47
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "create a gemspec file"
|
51
|
+
task :make_spec do
|
52
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
53
|
+
file.puts spec.to_ruby
|
54
|
+
end
|
55
|
+
end
|
data/bin/interval-quiz
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# load development libs if they exist
|
3
|
+
[File.dirname(__FILE__) + "/../../interval/lib", File.dirname(__FILE__) + "/../lib"].each do |path|
|
4
|
+
$:.unshift(path) if File.exists?(path)
|
5
|
+
end
|
6
|
+
require "rubygems"
|
7
|
+
require "interval"
|
8
|
+
require "interval-quiz"
|
9
|
+
|
10
|
+
quiz = IntervalQuiz.new
|
11
|
+
quiz.run!
|
@@ -0,0 +1,113 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + "/../../interval/lib")
|
2
|
+
require "rubygems"
|
3
|
+
require "interval"
|
4
|
+
require "highline/import"
|
5
|
+
require "madeleine"
|
6
|
+
require "pp"
|
7
|
+
|
8
|
+
class Quiz
|
9
|
+
# Here is the list of intervals by semitone. This is just here for reference:
|
10
|
+
#
|
11
|
+
# 0 Perfect Unison (P1) Diminished second (dim2)
|
12
|
+
# 1 Minor second (m2) Augmented unison (aug1)
|
13
|
+
# 2 Major second (M2) Diminished third (dim3)
|
14
|
+
# 3 Minor third (m3) Augmented second (aug2)
|
15
|
+
# 4 Major third (M3) Diminished fourth (dim4)
|
16
|
+
# 5 Perfect fourth (P4) Augmented third (aug3)
|
17
|
+
# 6 Tritone Augmented fourth (aug4) Diminished fifth (dim5)
|
18
|
+
# 7 Perfect fifth (P5) Diminished sixth (dim6)
|
19
|
+
# 8 Minor sixth (m6) Augmented fifth (aug5)
|
20
|
+
# 9 Major sixth (M6) Diminished seventh (dim7)
|
21
|
+
# 10 Minor seventh (m7) Augmented sixth (aug6)
|
22
|
+
# 11 Major seventh (M7) Diminished octave (dim8)
|
23
|
+
# 12 Perfect octave (P8) Augmented seventh (aug7)
|
24
|
+
|
25
|
+
attr_accessor :intervals # which intervals we will quiz on
|
26
|
+
attr_accessor :abovebelow # array of ["", "-"] if "-" is present, then we are quizzing on intervals below
|
27
|
+
attr_accessor :asked
|
28
|
+
attr_accessor :correct
|
29
|
+
attr_accessor :natural
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
self.asked = 0
|
33
|
+
self.correct = 0
|
34
|
+
self.natural = true
|
35
|
+
end
|
36
|
+
|
37
|
+
def run!
|
38
|
+
loop do
|
39
|
+
|
40
|
+
pitch = Interval::Pitch.random(self.natural)
|
41
|
+
ab = self.abovebelow.rand
|
42
|
+
ab_eng = ab == "-" ? "below" : "above"
|
43
|
+
interval = Interval::Interval.from_string(ab + self.intervals.rand)
|
44
|
+
|
45
|
+
begin
|
46
|
+
answer = ask("what is a #{interval.to_long_name.downcase} #{ab_eng} #{pitch.to_s} #{score_str}? ")
|
47
|
+
self.asked = self.asked + 1
|
48
|
+
rescue EOFError
|
49
|
+
puts "goodbye"
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
real_answer = pitch + interval
|
54
|
+
|
55
|
+
if answer.downcase == real_answer.to_short_name.downcase
|
56
|
+
say "<%= color('correct!', :green) %>"
|
57
|
+
self.correct = correct + 1
|
58
|
+
else
|
59
|
+
say "<%= color('wrong', :red) %>. the answer is #{real_answer.to_short_name}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def score_str
|
65
|
+
return "" unless asked && asked > 0
|
66
|
+
"#{correct}/#{asked} (%d%%)" % [(correct.to_f / asked.to_f) * 100]
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
class IntervalQuiz
|
72
|
+
|
73
|
+
def run!
|
74
|
+
say("Here are the intervals:")
|
75
|
+
intervals =<<-EOF
|
76
|
+
unison p1 a1
|
77
|
+
second m2 M2 d2 a2
|
78
|
+
third m3 M3 d3 a3
|
79
|
+
fourth p4 d4 a4
|
80
|
+
fifth d5 p5 d5 a5
|
81
|
+
sixth m6 M6 d6 a6
|
82
|
+
seventh m7 M7 d7 a7
|
83
|
+
octave p8 d8
|
84
|
+
EOF
|
85
|
+
say(intervals)
|
86
|
+
|
87
|
+
picked = ask("enter the intervals you want (or a blank line to quit):", lambda { |ans| ans} ) do |q|
|
88
|
+
q.gather = ""
|
89
|
+
end
|
90
|
+
|
91
|
+
pp picked
|
92
|
+
|
93
|
+
abovebelow = []
|
94
|
+
choose do |menu|
|
95
|
+
menu.prompt = "do you want to be quizzed on intervals above, below, or both? "
|
96
|
+
menu.choice(:above) { abovebelow = [""] }
|
97
|
+
menu.choice(:below) { abovebelow = ["-"] }
|
98
|
+
menu.choice(:both) { abovebelow = ["", "-"] }
|
99
|
+
end
|
100
|
+
|
101
|
+
q = Quiz.new
|
102
|
+
q.abovebelow = abovebelow
|
103
|
+
q.intervals = picked
|
104
|
+
|
105
|
+
q.run!
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
if $0 == __FILE__
|
111
|
+
quiz = IntervalQuiz.new
|
112
|
+
quiz.run!
|
113
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interval-quiz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nate Murray
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-17 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: interval
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: A gem that provides a quiz on musical intervals
|
26
|
+
email: nate@natemurray.com
|
27
|
+
executables:
|
28
|
+
- interval-quiz
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.mkd
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.mkd
|
37
|
+
- Rakefile
|
38
|
+
- lib/interval-quiz.rb
|
39
|
+
- spec/interval-quiz_spec.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- bin/interval-quiz
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://www.xcombinator.com
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.2
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: a quiz for musical intervals
|
70
|
+
test_files: []
|
71
|
+
|