stringed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ *idea
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@stringed"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.14.2 ()" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stringed.gemspec
4
+ gemspec
5
+
6
+ gem 'music'
7
+
8
+ group :development, :test do
9
+ gem "pry"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stringed (0.0.1)
5
+ music (~> 0.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.11)
11
+ activesupport (= 3.2.11)
12
+ builder (~> 3.0.0)
13
+ activesupport (3.2.11)
14
+ i18n (~> 0.6)
15
+ multi_json (~> 1.0)
16
+ builder (3.0.4)
17
+ coderay (1.0.8)
18
+ diff-lcs (1.1.3)
19
+ i18n (0.6.1)
20
+ method_source (0.8.1)
21
+ multi_json (1.5.0)
22
+ music (0.6.2)
23
+ activemodel (~> 3.2)
24
+ pry (0.9.10)
25
+ coderay (~> 1.0.5)
26
+ method_source (~> 0.8)
27
+ slop (~> 3.3.1)
28
+ rspec (2.11.0)
29
+ rspec-core (~> 2.11.0)
30
+ rspec-expectations (~> 2.11.0)
31
+ rspec-mocks (~> 2.11.0)
32
+ rspec-core (2.11.1)
33
+ rspec-expectations (2.11.3)
34
+ diff-lcs (~> 1.1.3)
35
+ rspec-mocks (2.11.2)
36
+ slop (3.3.3)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ music
43
+ pry
44
+ rspec (~> 2.0)
45
+ stringed!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 pmacydna@gmail.com
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
+ # Stringed
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'stringed'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install stringed
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
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,38 @@
1
+ module Stringed
2
+
3
+ class Instrument
4
+
5
+ attr_accessor :strings, :neck_length
6
+
7
+ def initialize(strings,neck_length)
8
+ @strings = strings.map{ |string| InstrumentString.new(string.to_s)}
9
+ @neck_length = neck_length
10
+ end
11
+
12
+ def matches(note)
13
+ matches = []
14
+ strings.each do |string|
15
+ matches << string.matches(note, {limit: @neck_length})
16
+ end
17
+ matches
18
+ end
19
+
20
+ def chord_matches(chord)
21
+ matches = []
22
+ strings.each do |string|
23
+ string_matches = []
24
+ chord.notes.each do |note|
25
+ string_matches << string.matches(note.name,{ limit: @neck_length })
26
+ end
27
+ matches << string_matches.flatten.compact.sort
28
+ end
29
+ matches
30
+ end
31
+
32
+ def in_range?(fret_no)
33
+ fret_no >= 0 and fret_no <= neck_length
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,44 @@
1
+ module Stringed
2
+
3
+ class InstrumentString
4
+ include Music
5
+
6
+ attr_reader :root_note
7
+
8
+ def initialize(root_note)
9
+ @root_note = Music::Note.new(root_note.to_s)
10
+ end
11
+
12
+ def fret_note(fret_no)
13
+ fret_note = @root_note
14
+ fret_no.times{ fret_note = fret_note.next }
15
+ fret_note
16
+ end
17
+
18
+ def fret_no(fret_note)
19
+ Music::Note.note_distance(@root_note.to_s, fret_note.to_s)
20
+ end
21
+
22
+ def self.octave_up(fret_no)
23
+ fret_no + 12
24
+ end
25
+
26
+ def self.octave_down(fret_no)
27
+ fret_no - 12
28
+ end
29
+
30
+ def to_s
31
+ @root_note.to_s
32
+ end
33
+
34
+ def matches(note_name, options={})
35
+ limit = options.has_key?(:limit) ? options[:limit] : 20
36
+ matches = []
37
+ (0..limit).each do |fret|
38
+ matches.push fret if fret_note(fret).name == note_name
39
+ end
40
+ matches
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Stringed
2
+ VERSION = "0.0.1"
3
+ end
data/lib/stringed.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "music"
2
+ require "stringed/version"
3
+ require "stringed/instrument"
4
+ require "stringed/instrument_string"
5
+
6
+ module Stringed
7
+ # Your code goes here...
8
+
9
+ class Music::Note
10
+ def name
11
+ self.to_s.delete(self.octave.to_s)
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'pry'
4
+
5
+ require File.dirname(__FILE__) + '/../lib/stringed.rb'
6
+
7
+ include Stringed
8
+ include Music
9
+
10
+ RSpec.configure do |config|
11
+ config.color_enabled = true
12
+ config.formatter = 'documentation'
13
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stringed::Instrument do
4
+
5
+ let(:guitar) { Stringed::Instrument.new(%w( E2 A2 D3 G3 B3 E4 ), 20) }
6
+
7
+ it "should have strings" do
8
+ guitar.strings.count.should == 6
9
+ end
10
+
11
+ it "should have a neck length" do
12
+ guitar.neck_length.should == 20
13
+ end
14
+
15
+ it "should know where all the matches for a given note are" do
16
+ guitar.matches('F').should eq [[1,13], [8,20], [3,15], [10], [6,18], [1,13]]
17
+ guitar.matches('D').should eq [[10], [5, 17], [0, 12], [7, 19], [3, 15], [10]]
18
+ end
19
+
20
+ it "should know where all the matches for a given chord are" do
21
+ guitar.chord_matches(Chord.new(['C4', 'E4', 'G4'])).should eq [[0, 3, 8, 12, 15, 20],
22
+ [3, 7, 10, 15, 19],
23
+ [2, 5, 10, 14, 17],
24
+ [0, 5, 9, 12, 17],
25
+ [1, 5, 8, 13, 17, 20],
26
+ [0, 3, 8, 12, 15, 20]]
27
+ end
28
+
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe InstrumentString do
4
+
5
+ let(:e2){ InstrumentString.new('E2') }
6
+
7
+ context "InstrumentString#new" do
8
+ it {
9
+ e2.root_note.should eq Note.new('E2')
10
+ }
11
+ it { InstrumentString.new(Note.new('A2')).root_note.to_s.should eq 'A2' }
12
+ end
13
+
14
+ it "should know what note is at any fret" do
15
+ e2.fret_note(4).should eq Note.new('G#2')
16
+ e2.fret_note(5).should eq Note.new('A2' )
17
+ end
18
+
19
+ it "should know what fret to use for a pitch" do
20
+ e2.fret_no('G2').should eq 3
21
+ e2.fret_no('D#3').should eq 11
22
+ end
23
+
24
+ it "should know how the fret_no an octave up from any given fret_no" do
25
+ InstrumentString.octave_up(0).should == 12
26
+ end
27
+
28
+ it "should know how the fret_no an octave down from any given fret_no" do
29
+ InstrumentString.octave_down(12).should == 0
30
+ end
31
+
32
+ it { e2.to_s.should eq "E2" }
33
+
34
+ it "should know the matches for a note name" do
35
+ e2.matches("F", :limit => 20).should eq [1,13]
36
+ e2.matches("F", :limit => 30).should eq [1,13,25]
37
+ end
38
+
39
+ it "should know the matches for a chord"
40
+
41
+ end
data/stringed.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stringed/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "stringed"
8
+ gem.version = Stringed::VERSION
9
+ gem.authors = ["andrewthomascampbell@gmail.com"]
10
+ gem.email = ["andrewthomascampbell.com"]
11
+ gem.description = %q{A library for Stringed instruments.}
12
+ gem.summary = %q{Recognizes chords and notes for any stringed instrument and any tuning.}
13
+ gem.homepage = "https://github.com/andycamp/stringed"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency 'music', '~> 0.6'
20
+ gem.add_development_dependency 'rspec', '~> 2.0'
21
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stringed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - andrewthomascampbell@gmail.com
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: music
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.6'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
46
+ description: A library for Stringed instruments.
47
+ email:
48
+ - andrewthomascampbell.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rvmrc
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - lib/stringed.rb
61
+ - lib/stringed/instrument.rb
62
+ - lib/stringed/instrument_string.rb
63
+ - lib/stringed/version.rb
64
+ - spec/spec_helper.rb
65
+ - spec/stringed/instrument_spec.rb
66
+ - spec/stringed/instrument_string_spec.rb
67
+ - stringed.gemspec
68
+ homepage: https://github.com/andycamp/stringed
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.24
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Recognizes chords and notes for any stringed instrument and any tuning.
92
+ test_files:
93
+ - spec/spec_helper.rb
94
+ - spec/stringed/instrument_spec.rb
95
+ - spec/stringed/instrument_string_spec.rb