musi 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 708e228cd4ee61de279c589a2cdc091d82928c4eba56d5aaab228c2b4b9bdd69
4
+ data.tar.gz: 8575be6ee3a360b55ad375f942086fe6f95fdd481279b2b5e88a2b1272596af9
5
+ SHA512:
6
+ metadata.gz: 12fb03711aac95ea3cc76687c78fb22cd1bbf4b1ade0715ee0795a67425e9e285e5bfa4462ac950d3e98f1db374514265afba7a049edfd369b8569d379b8f2ff
7
+ data.tar.gz: e919ecfe0b9bdd16b646ea70202669dc22fb2589559235b984d159dc738de5c3d806682e9a7fe52aeb6d794c9787a819fd150be01675e2fe1d7b5e3af0c1c33b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in musi.gemspec
4
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ musi (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.2)
12
+ pry (0.12.2)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ rake (10.5.0)
16
+ rspec (3.8.0)
17
+ rspec-core (~> 3.8.0)
18
+ rspec-expectations (~> 3.8.0)
19
+ rspec-mocks (~> 3.8.0)
20
+ rspec-core (3.8.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-expectations (3.8.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-mocks (3.8.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-support (3.8.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 2.0)
35
+ musi!
36
+ pry
37
+ rake (~> 10.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 <github username>
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.
@@ -0,0 +1,54 @@
1
+ # Musi
2
+
3
+ Welcome to Musi! A very basic gem for calculating intervals in music theory. Pass a note as a string such as "C" or "Ab" to a method and receive a new note in the form of a string.
4
+
5
+ You may sharp or flat a note or raise by perfect 4th and 5th intervals. Minor/Major intervals not yet supported.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'musi'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install musi
23
+
24
+ ## Usage
25
+
26
+ .sharp is a method which will raise the input of a note given as a string by one half step
27
+ .flat is a a method which will lower the input of a note given as a string by one half step
28
+ .raise_whole_step raises a note by a whole step
29
+ .lower_whole_step lowers a note by a whole step
30
+ .raiseP4 raises a note by a perfect fourth
31
+ .lowerP4 lowers a note by a perfect fourth
32
+ .raiseP5 raises a note by a perfect fifth
33
+ .lowerP5 lowers a note by a perfect fifth
34
+
35
+ Musi::Note.sharp("D") => D#
36
+
37
+ Enharmonic spellings such as B# and Gx are currently not supported.
38
+ .raise_whole_step("A#") will raise to "C"
39
+
40
+ Currently only these 8 actions available.
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eselbeus/musi.
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "musi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require "musi/version"
2
+ require 'musi/note'
3
+
4
+ module Musi
5
+ class Error < StandardError; end
6
+
7
+ end
@@ -0,0 +1,137 @@
1
+ # require 'pry'
2
+ module Musi
3
+ class Note
4
+
5
+ @@sharp_notes = {
6
+ "C" => 1,
7
+ "C#" => 2,
8
+ "D" => 3,
9
+ "D#" => 4,
10
+ "E" => 5,
11
+ "F" => 6,
12
+ "F#" => 7,
13
+ "G" => 8,
14
+ "G#" => 9,
15
+ "A" => 10,
16
+ "A#" => 11,
17
+ "B" => 12
18
+ }
19
+ @@flat_notes = {
20
+ "C" => 1,
21
+ "Db" => 2,
22
+ "D" => 3,
23
+ "Eb" => 4,
24
+ "E" => 5,
25
+ "F" => 6,
26
+ "Gb" => 7,
27
+ "G" => 8,
28
+ "Ab" => 9,
29
+ "A" => 10,
30
+ "Bb" => 11,
31
+ "B" => 12
32
+ }
33
+
34
+ #Helper Method for lowering intervals that go below C
35
+ def self.above_zero(next_note)
36
+ if next_note < 1
37
+ next_note += 12
38
+ else
39
+ next_note
40
+ end
41
+ end
42
+
43
+ #Helper method for raising(m2, M2, P4, P5)
44
+ def self.raise_helper(note, modifier)
45
+ if note.include?("b")
46
+ next_note = (@@flat_notes[note] + modifier) % 12
47
+ @@flat_notes.keys.each do |k|
48
+ if @@flat_notes[k] == next_note
49
+ return k
50
+ end
51
+ end
52
+ else
53
+ next_note = (@@sharp_notes[note] + modifier) % 12
54
+ @@sharp_notes.keys.each do |k|
55
+ if @@sharp_notes[k] == next_note
56
+ return k
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def self.raise_helper_minor(note, modifier)
63
+ if !note.include?("#")
64
+ next_note = (@@flat_notes[note] + modifier) % 12
65
+ @@flat_notes.keys.each do |k|
66
+ if @@flat_notes[k] == next_note
67
+ return k
68
+ end
69
+ end
70
+ else
71
+ next_note = (@@sharp_notes[note] + modifier) % 12
72
+ @@sharp_notes.keys.each do |k|
73
+ if @@sharp_notes[k] == next_note
74
+ return k
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ #Helper method for lowering(m2, M2, P4, P5)
81
+ def self.lower_helper(note, modifier)
82
+ if note.include?("#")
83
+ next_note = (@@sharp_notes[note] - modifier) % 12
84
+ @@sharp_notes.keys.each do |k|
85
+ if @@sharp_notes[k] == self.above_zero(next_note)
86
+ return k
87
+ end
88
+ end
89
+ else
90
+ next_note = (@@flat_notes[note] - modifier)
91
+ @@flat_notes.keys.each do |k|
92
+ if @@flat_notes[k] == self.above_zero(next_note)
93
+ return k
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ #m2
100
+ def self.sharp(note)
101
+ self.raise_helper(note, 1)
102
+ end
103
+
104
+ def self.flat(note)
105
+ self.lower_helper(note, 1)
106
+ end
107
+
108
+ #M2
109
+ def self.raise_whole_step(note)
110
+ self.raise_helper(note, 2)
111
+ end
112
+
113
+ def self.lower_whole_step(note)
114
+ self.lower_helper(note, 2)
115
+ end
116
+
117
+ #M3
118
+ def self.raiseP4(note)
119
+ self.raise_helper_minor(note, 5)
120
+ end
121
+
122
+ def self.lowerP4(note)
123
+ self.lower_helper(note, 5)
124
+ end
125
+
126
+ #P5
127
+ def self.raiseP5(note)
128
+ self.raise_helper(note, 7)
129
+ end
130
+
131
+ def self.lowerP5(note)
132
+ self.lower_helper(note, 7)
133
+ end
134
+
135
+ end
136
+
137
+ end
@@ -0,0 +1,3 @@
1
+ module Musi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "musi/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "musi"
8
+ spec.version = Musi::VERSION
9
+ spec.authors = ["Eselbeus"]
10
+ spec.email = ["eselbeus@gmail.com"]
11
+
12
+ spec.summary = %q{Simple music theory gem}
13
+ spec.description = %q{A gem for sharping/flattening notes and raising/lowering by perfect 5ths}
14
+ spec.homepage = "https://github.com/Eselbeus/musi.git"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ #
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # spec.metadata["source_code_uri"] = "https://github.com/Eselbeus/musi.git"
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ # else
26
+ # raise "RubyGems 2.0 or newer is required to protect against " \
27
+ # "public gem pushes."
28
+ # end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ # spec.add_development_dependency "pry"
40
+ spec.add_development_dependency "bundler", "~> 2.0"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "rspec", "~> 3.0"
43
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: musi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eselbeus
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A gem for sharping/flattening notes and raising/lowering by perfect 5ths
56
+ email:
57
+ - eselbeus@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/musi.rb
73
+ - lib/musi/note.rb
74
+ - lib/musi/version.rb
75
+ - musi.gemspec
76
+ homepage: https://github.com/Eselbeus/musi.git
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.0.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Simple music theory gem
99
+ test_files: []