music-utils 0.3.20

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ # Redcar project directory #
2
+ .redcar/
3
+
4
+ # build directory
5
+ pkg/
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.0.1 (April 23, 2011)
2
+
3
+ Features:
4
+
5
+ - Added support to full diatonic scale in quality method
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+ gem "rake", ' ~> 0.8'
3
+ gem "rspec", '~> 2.5'
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ rake (0.8.7)
6
+ rspec (2.5.0)
7
+ rspec-core (~> 2.5.0)
8
+ rspec-expectations (~> 2.5.0)
9
+ rspec-mocks (~> 2.5.0)
10
+ rspec-core (2.5.1)
11
+ rspec-expectations (2.5.0)
12
+ diff-lcs (~> 1.1.2)
13
+ rspec-mocks (2.5.0)
14
+
15
+ PLATFORMS
16
+ ruby
17
+ x86-mingw32
18
+
19
+ DEPENDENCIES
20
+ rake (~> 0.8)
21
+ rspec (~> 2.5)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Jorge Luis Pérez (jorgeluis700@gmail.com)
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,28 @@
1
+ music-utils
2
+ =========
3
+
4
+ Utils for music. At the moment only one class to classify intervals.
5
+
6
+ Examples
7
+ --------
8
+ Simple intervals:
9
+
10
+ * Interval.new('do', 'mi', 0).number #=> 3 (3th)
11
+ * Interval.new('do', 'mi', 0).semitone #=> 4 (semi-tones)
12
+ * Interval.new('do', 'mi', 0).quality #=> M (major)
13
+
14
+ Compound intervals:
15
+
16
+ * Interval.new('do', 'mi', 1).number #=> 10 (10th)
17
+ * Interval.new('do', 'mi', 1).semitone #=> 16 (semi-tones)
18
+ * Interval.new('do', 'mi', 1).quality #=> M (major)
19
+
20
+ To Do
21
+ -----
22
+ * Add support to note alterations
23
+
24
+ Copyright
25
+ ---------
26
+
27
+ Copyright (c) 2011 Jorge Luis Pérez. See LICENSE for details.
28
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ task :default => [:spec]
8
+
9
+ # RSpec tasks
10
+ desc "Run all examples"
11
+ RSpec::Core::RakeTask.new(:spec) do |spec|
12
+ spec.ruby_opts = '-I lib'
13
+ spec.pattern = 'spec/**/*_spec.rb'
14
+ spec.rspec_opts = ['--color --format doc']
15
+ spec.fail_on_error = false
16
+ end
17
+
18
+ # Gems tasks
19
+ desc "Load the gemspec"
20
+ task :load_gemspec do
21
+ @gemspec = eval(File.read(Dir["*.gemspec"].first))
22
+ end
23
+
24
+ desc "Validate the gemspec"
25
+ task :gemspec => :load_gemspec do
26
+ @gemspec.validate
27
+ end
28
+
29
+ desc "Build gem locally"
30
+ task :build => :gemspec do
31
+ system "gem build #{@gemspec.name}.gemspec"
32
+ FileUtils.mkdir_p "pkg"
33
+ FileUtils.mv "#{@gemspec.name}-#{@gemspec.version}.gem", "pkg"
34
+ end
35
+
36
+ desc "Install gem locally"
37
+ task :install => :build do
38
+ system "gem install pkg/#{@gemspec.name}-#{@gemspec.version}"
39
+ end
40
+
41
+ desc "Clean automatically generated files"
42
+ task :clean do
43
+ FileUtils.rm_rf "pkg"
44
+ end
data/lib/interval.rb ADDED
@@ -0,0 +1,83 @@
1
+ # Scales module
2
+ module Scales
3
+ DIATONIC_SCALE = ['do', 're', 'mi', 'fa', 'sol', 'la', 'si']
4
+ QUALITIES = {
5
+ 2 => {0 => 'd', 1 => 'm', 2 => 'M', 3 => 'A'},
6
+ 3 => {2 => 'd', 3 => 'm', 4 => 'M', 5 => 'A'},
7
+ 4 => {3 => 'dd', 4 => 'd', 5 => 'P', 6 => 'A', 7 => 'AA'},
8
+ 5 => {5 => 'dd', 6 => 'd', 7 => 'P', 8 => 'A', 9 => 'AA'},
9
+ 6 => {7 => 'd', 8 => 'm', 9 => 'M', 10 => 'A'},
10
+ 7 => {9 => 'd', 10 => 'm', 11 => 'M', 12 => 'A'},
11
+ 8 => {10 => 'dd', 11 => 'd', 12 => 'P', 13 => 'A', 14 => 'AA'}
12
+ }
13
+ end
14
+
15
+ # This class represents a music interval
16
+ class Interval
17
+ include Scales
18
+
19
+ def initialize(note1, note2, step)
20
+ @note1 = note1
21
+ @note2 = note2
22
+ @step = step
23
+ end
24
+
25
+ # It classifies the diatonic interval
26
+ def number
27
+ # initialize counter and index of scale
28
+ i = DIATONIC_SCALE.index(@note1)
29
+ count = 1
30
+
31
+ # No unison
32
+ if @note1 == @note2
33
+ count += 1; i += 1
34
+ end
35
+
36
+ # Counting notes
37
+ while DIATONIC_SCALE[i] != @note2
38
+ i += 1
39
+ if i > DIATONIC_SCALE.length
40
+ i = 0; next
41
+ end
42
+ count += 1
43
+ end
44
+ count = count + (8 * @step) - 1 if @step > 0
45
+ count
46
+ end
47
+
48
+ # Returns the number of semitones
49
+ def semitone
50
+ # initialize counter and index of scale
51
+ i = DIATONIC_SCALE.index(@note1)
52
+ count = 0
53
+
54
+ # No unison
55
+ if @note1 == @note2
56
+ count += 1; i += 1
57
+ end
58
+
59
+ # Counting semi-tones
60
+ while DIATONIC_SCALE[i] != @note2
61
+ i += 1
62
+ if i > DIATONIC_SCALE.length
63
+ i = 0; next
64
+ end
65
+
66
+ # from 'mi' to 'fa' and 'si' to 'do' there 1 semi-tone
67
+ if DIATONIC_SCALE[i] == 'fa' or DIATONIC_SCALE[i] == 'do'
68
+ count += 1
69
+ else
70
+ count += 2
71
+ end
72
+ end
73
+
74
+ count = count + (12 * @step) if @step > 0
75
+ count
76
+ end
77
+
78
+ # Returns the quality of the interval
79
+ def quality
80
+ QUALITIES[number][semitone]
81
+ end
82
+
83
+ end
@@ -0,0 +1,22 @@
1
+
2
+ Gem::Specification.new do |s|
3
+ # Basic Info
4
+ s.name = 'music-utils'
5
+ s.version = '0.3.20'
6
+ s.summary = 'music-utils'
7
+ s.description = 'Utils for music'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Jorge Luis Pérez']
10
+ s.email = ['jorgeluis700@gmail.com']
11
+ s.homepage = 'http://github.com/jorgeluis700/music-utils'
12
+ s.license = 'MIT'
13
+
14
+ # Files and Paths
15
+ s.files = `git ls-files`.split("\n")
16
+ s.require_path = 'lib'
17
+
18
+ # Dependencies
19
+ s.add_development_dependency('rspec')
20
+ s.required_rubygems_version = ">= 1.3.6"
21
+
22
+ end
@@ -0,0 +1,56 @@
1
+ require 'interval'
2
+
3
+ describe Interval do
4
+
5
+ context "Number of intervals" do
6
+ it "the number of simple interval do-mi should be a 3rd" do
7
+ i = Interval.new('do', 'mi', 0)
8
+ i.number.should == 3
9
+ end
10
+
11
+ it "the number of simple interval do-do should be an 8th" do
12
+ i = Interval.new('do', 'do', 0)
13
+ i.number.should == 8
14
+ end
15
+
16
+ it "the number of do-mi compound interval should be a 10th" do
17
+ i = Interval.new('do', 'mi', 1)
18
+ i.number.should == 10
19
+ end
20
+ end
21
+
22
+ context "Number of semitones of intervals" do
23
+ it "simple interval do-mi should be 4 semitones" do
24
+ i = Interval.new('do', 'mi', 0)
25
+ i.semitone.should == 4
26
+ end
27
+
28
+ it "simple interval do-do should be 12 semitones" do
29
+ i = Interval.new('do', 'do', 0)
30
+ i.semitone.should == 12
31
+ end
32
+
33
+ it "compound interval do-mi should be 16 semitones" do
34
+ i = Interval.new('do', 'mi', 1)
35
+ i.semitone.should == 16
36
+ end
37
+ end
38
+
39
+ context "Interval qualities" do
40
+ it "quality of interval do-re should be M" do
41
+ i = Interval.new('do', 're', 0)
42
+ i.quality.should == 'M'
43
+ end
44
+
45
+ it "quality of interval do-mi should be M" do
46
+ i = Interval.new('do', 'mi', 0)
47
+ i.quality.should == 'M'
48
+ end
49
+
50
+ it "quality of interval do-do should be P" do
51
+ i = Interval.new('do', 'do', 0)
52
+ i.quality.should == 'P'
53
+ end
54
+ end
55
+ end
56
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: music-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.20
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jorge Luis Pérez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-04-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &24133836 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *24133836
25
+ description: Utils for music
26
+ email:
27
+ - jorgeluis700@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - CHANGELOG.md
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - lib/interval.rb
40
+ - music-utils.gemspec
41
+ - spec/interval_spec.rb
42
+ homepage: http://github.com/jorgeluis700/music-utils
43
+ licenses:
44
+ - MIT
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ segments:
56
+ - 0
57
+ hash: -731370575
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 1.3.6
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.7.2
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: music-utils
70
+ test_files: []