string_tensions 0.0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +10 -0
- data/lib/string_tensions/convert.rb +31 -0
- data/lib/string_tensions/version.rb +3 -0
- data/lib/string_tensions.rb +31 -0
- data/string_tensions.gemspec +26 -0
- data/test/helpers.rb +4 -0
- data/test/test_convert.rb +26 -0
- data/test/test_string_tensions.rb +17 -0
- metadata +131 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Choan Galvez
|
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,42 @@
|
|
1
|
+
# StringTensions
|
2
|
+
|
3
|
+
A library for calculating musical string tension (from known unit weight, length and pitch) and unit weight (from known tension, length and pitch).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'string_tensions'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install string_tensions
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Currently the library only accepts input in imperial units (length in inches, unit weight in lbs/inch, tension in lbs). Output is imperial too (unit weight in lbs/inch, tension in lbs).
|
22
|
+
|
23
|
+
Should you need output in International System units, there are some conversors included.
|
24
|
+
|
25
|
+
StringTensions uses [NoteFrequencies](https://github.com/choan/note_frequencies) internally for converting pitches to frequencies.
|
26
|
+
|
27
|
+
Get tension for known unit weight, length and pitch:
|
28
|
+
|
29
|
+
StringTensions.tension_for_pitch(0.00001418, 25.5, "e'")
|
30
|
+
|
31
|
+
Get unit weight for known tension, length and pitch:
|
32
|
+
|
33
|
+
StringTensions.uw_for_pitch(10.4, 25.5, "e'")
|
34
|
+
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'ruby-units'
|
2
|
+
|
3
|
+
module StringTensions
|
4
|
+
module Convert
|
5
|
+
|
6
|
+
def self.kg_to_lbs(kg)
|
7
|
+
unit(kg, 'kg').to('lbs').scalar.to_f
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.lbs_to_kg(pounds)
|
11
|
+
unit(pounds, 'lbs').to('kg').scalar.to_f
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.inches_to_mm(inches)
|
15
|
+
unit(inches, 'inch').to('mm').scalar.to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.mm_to_inches(mm)
|
19
|
+
unit(mm, 'mm').to('inch').scalar.to_f
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.g_m_to_lbs_inch(g)
|
23
|
+
unit(g, 'g/m').to('lbs/inch').scalar.to_f
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.unit(qty, dim)
|
27
|
+
::Unit.new("#{qty} #{dim}")
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "string_tensions/version"
|
2
|
+
require "string_tensions/convert"
|
3
|
+
require "note_frequencies"
|
4
|
+
|
5
|
+
module StringTensions
|
6
|
+
|
7
|
+
K = 386.4
|
8
|
+
|
9
|
+
def self.tension(uw_lbs_inch, length_in_inches, freq)
|
10
|
+
# T (Tension) = (UW x (2 x L x F)**2) / 386.4
|
11
|
+
(uw_lbs_inch * (2 * length_in_inches * freq)**2) / K
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.tension_for_pitch(uw_lbs_inch, length_in_inches, pitch)
|
15
|
+
tension(uw_lbs_inch, length_in_inches, freq_from_pitch(pitch))
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.uw(tension_lbs, length_inches, freq)
|
19
|
+
# UW (unit weight) = (T x 386.4) / (2 x L x F)**2
|
20
|
+
((tension_lbs * K) / (2 * length_inches * freq)**2).to_f
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.uw_for_pitch(tension_lbs, length_inches, pitch)
|
24
|
+
uw(tension_lbs, length_inches, freq_from_pitch(pitch))
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.freq_from_pitch(pitch)
|
28
|
+
NoteFrequencies.frequency_from_name(pitch)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'string_tensions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "string_tensions"
|
8
|
+
spec.version = StringTensions::VERSION
|
9
|
+
spec.authors = ["Choan Galvez"]
|
10
|
+
spec.email = ["choan.galvez@gmail.com"]
|
11
|
+
spec.description = %q{Calculator for musical strings tensions}
|
12
|
+
spec.summary = %q{StringTensions is a module designed for musical string tension/MPL calculations}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "note_frequencies"
|
22
|
+
spec.add_dependency "ruby-units"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
data/test/helpers.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'helpers'
|
3
|
+
require 'string_tensions/convert'
|
4
|
+
|
5
|
+
class ConvertTest < Test::Unit::TestCase
|
6
|
+
def test_mm_to_inches
|
7
|
+
assert_equal 1, StringTensions::Convert.mm_to_inches(25.4)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_inches_to_mm
|
11
|
+
assert_equal 25.4, StringTensions::Convert.inches_to_mm(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_kg_to_lbs
|
15
|
+
assert_equal 2.20462262, round(StringTensions::Convert.kg_to_lbs(1), 8)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_lbs_to_kg
|
19
|
+
assert_equal 4, round(StringTensions::Convert.lbs_to_kg(2.20462262 * 4), 0)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_g_m_to_lbs_inch
|
23
|
+
assert_equal 0.00055997, round(StringTensions::Convert.g_m_to_lbs_inch(10), 8)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'helpers'
|
3
|
+
require 'string_tensions'
|
4
|
+
|
5
|
+
class StringTensionsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_tension
|
8
|
+
assert_equal 10.4, round(StringTensions.tension_for_pitch(0.00001418, 25.5, "e'"), 1)
|
9
|
+
assert_equal 11.6, round(StringTensions.tension_for_pitch(0.00001418, 25.5, "f'"), 1)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_uw
|
13
|
+
assert_equal 0.000014219248492925078, StringTensions.uw_for_pitch(10.4, 25.5, "e'").to_f
|
14
|
+
assert_equal 0.00001793812886799779, StringTensions.uw_for_pitch(13.12, 25.5, "e'").to_f
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: string_tensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Choan Galvez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: note_frequencies
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ruby-units
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Calculator for musical strings tensions
|
79
|
+
email:
|
80
|
+
- choan.galvez@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- lib/string_tensions.rb
|
91
|
+
- lib/string_tensions/convert.rb
|
92
|
+
- lib/string_tensions/version.rb
|
93
|
+
- string_tensions.gemspec
|
94
|
+
- test/helpers.rb
|
95
|
+
- test/test_convert.rb
|
96
|
+
- test/test_string_tensions.rb
|
97
|
+
homepage: ''
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: 714457889
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: 714457889
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.25
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: StringTensions is a module designed for musical string tension/MPL calculations
|
128
|
+
test_files:
|
129
|
+
- test/helpers.rb
|
130
|
+
- test/test_convert.rb
|
131
|
+
- test/test_string_tensions.rb
|