euclidean_sequencer 0.0.2
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.
- checksums.yaml +7 -0
- data/.envrc +3 -0
- data/.envrc.example +4 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +72 -0
- data/Guardfile +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/build_and_push_gem +32 -0
- data/bin/console +14 -0
- data/bin/euclidean_sequencer +12 -0
- data/bin/setup +8 -0
- data/euclidean_sequencer.gemspec +22 -0
- data/lib/euclidean_sequencer/engine.rb +88 -0
- data/lib/euclidean_sequencer/formator.rb +39 -0
- data/lib/euclidean_sequencer/parser.rb +44 -0
- data/lib/euclidean_sequencer/sequencer.rb +18 -0
- data/lib/euclidean_sequencer.rb +14 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 053bb9f403f5cd1d59f741481089e2a5eedbd9dd36fe36189aa9bf091daaae48
|
4
|
+
data.tar.gz: e3d899f5b7a330ea914f4901d8ca0a4b3a17e6b2b1fe09953c014cbb7c28c667
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ba12fc5f791f382d0d2e75a3505daa6366fa45d915410265fc9aa5e8b8ceca6619c1f34ab4575201f3ad580d9ace66bb4c1f0930377f47cdef1dc1aa12c9107
|
7
|
+
data.tar.gz: 3628217ac93721fcb5f20268594b2ced2621c0deb25b6f79b92f2926829dcc3ef3ee4c6315437d1fe7ea2179a8706ec3bb641f6a5a205a440c964d8f2fb9fb23
|
data/.envrc
ADDED
data/.envrc.example
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at matt@goodguide.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
euclidean_sequencer (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
ffi (1.9.23)
|
12
|
+
formatador (0.2.5)
|
13
|
+
guard (2.14.2)
|
14
|
+
formatador (>= 0.2.4)
|
15
|
+
listen (>= 2.7, < 4.0)
|
16
|
+
lumberjack (>= 1.0.12, < 2.0)
|
17
|
+
nenv (~> 0.1)
|
18
|
+
notiffany (~> 0.0)
|
19
|
+
pry (>= 0.9.12)
|
20
|
+
shellany (~> 0.0)
|
21
|
+
thor (>= 0.18.1)
|
22
|
+
guard-compat (1.2.1)
|
23
|
+
guard-rspec (4.7.3)
|
24
|
+
guard (~> 2.1)
|
25
|
+
guard-compat (~> 1.1)
|
26
|
+
rspec (>= 2.99.0, < 4.0)
|
27
|
+
listen (3.1.5)
|
28
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
29
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
30
|
+
ruby_dep (~> 1.2)
|
31
|
+
lumberjack (1.0.13)
|
32
|
+
method_source (0.9.0)
|
33
|
+
nenv (0.3.0)
|
34
|
+
notiffany (0.1.1)
|
35
|
+
nenv (~> 0.1)
|
36
|
+
shellany (~> 0.0)
|
37
|
+
pry (0.11.3)
|
38
|
+
coderay (~> 1.1.0)
|
39
|
+
method_source (~> 0.9.0)
|
40
|
+
rake (10.5.0)
|
41
|
+
rb-fsevent (0.10.3)
|
42
|
+
rb-inotify (0.9.10)
|
43
|
+
ffi (>= 0.5.0, < 2)
|
44
|
+
rspec (3.7.0)
|
45
|
+
rspec-core (~> 3.7.0)
|
46
|
+
rspec-expectations (~> 3.7.0)
|
47
|
+
rspec-mocks (~> 3.7.0)
|
48
|
+
rspec-core (3.7.1)
|
49
|
+
rspec-support (~> 3.7.0)
|
50
|
+
rspec-expectations (3.7.0)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.7.0)
|
53
|
+
rspec-mocks (3.7.0)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.7.0)
|
56
|
+
rspec-support (3.7.1)
|
57
|
+
ruby_dep (1.5.0)
|
58
|
+
shellany (0.0.1)
|
59
|
+
thor (0.20.0)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
bundler (~> 1.16)
|
66
|
+
euclidean_sequencer!
|
67
|
+
guard-rspec
|
68
|
+
rake (~> 10.0)
|
69
|
+
rspec
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.16.1
|
data/Guardfile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
# Euclidean Sequencer files
|
44
|
+
watch(%r{^(.+)\.rb$})
|
45
|
+
watch(%r{^spec/.+_spec\.rb$})
|
46
|
+
watch(%r{^lib/(.+)\.rb$})
|
47
|
+
watch(%r{^lib/euclidean_sequencer(.+)\.rb$})
|
48
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 TODO: Write your name
|
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,39 @@
|
|
1
|
+
# Euclidean Sequencer
|
2
|
+
|
3
|
+
by Matt Ridenour (mattridenour@gmail.com)
|
4
|
+
Created on Sun Oct 26 2008 (Updated at Wed May 2 2018)
|
5
|
+
|
6
|
+
A class for spaceing a number of ones over a range of zeros as evenly as possible using the Euclidean algorithm.
|
7
|
+
|
8
|
+
For more information on using the Euclidean algorithm in the context of music, please read:
|
9
|
+
[The Euclidean Algorithm Generates Traditional Musical Rhythms by Godfried Toussaint][toussaint].
|
10
|
+
|
11
|
+
Special thanks to Wesen for bringing Euclidean sequencing to my attention and [forging the way using Lisp][wesen].
|
12
|
+
|
13
|
+
## Usage:
|
14
|
+
|
15
|
+
Command Line:
|
16
|
+
```bash
|
17
|
+
$> ./bin/euclidean_sequence --help
|
18
|
+
```
|
19
|
+
Ruby:
|
20
|
+
```ruby
|
21
|
+
require "./lib/sequencer.rb"
|
22
|
+
pulses = 8
|
23
|
+
hits = 5
|
24
|
+
p Sequencer.generate(hits: hits ,pulses: pulses, options: {array: true, offset: 2})
|
25
|
+
```
|
26
|
+
|
27
|
+
Oontz!
|
28
|
+
|
29
|
+
## License
|
30
|
+
[MIT][mit]
|
31
|
+
]
|
32
|
+
## Code of Conduct
|
33
|
+
[Code of Conduct][code_of_conduct]
|
34
|
+
|
35
|
+
[code_of_conduct]: CODE_OF_CONDUCT.md
|
36
|
+
[mit]: LICENSE.txt
|
37
|
+
[toussaint]: http://cgm.cs.mcgill.ca/~godfried/publications/banff.pdf
|
38
|
+
[wesen]: http://ruinwesen.com/blog?id=216
|
39
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
username = ENV.fetch("RUBYGEM_USERNAME")
|
4
|
+
gemfile_path = './euclidean_sequencer.gemspec'
|
5
|
+
gem = Gem::Specification.load(gemfile_path)
|
6
|
+
|
7
|
+
# Login to Rubygems.org:
|
8
|
+
login = `gem signin; echo $?`.chop.to_i
|
9
|
+
unless login == 0
|
10
|
+
p `curl -u #{username} https://rubygems.org/api/v1/api_key.yaml > \
|
11
|
+
~/.gem/credentials; \
|
12
|
+
chmod 0600 ~/.gem/credentials`
|
13
|
+
end
|
14
|
+
|
15
|
+
# Delete old builds:
|
16
|
+
`rm -rf euclidean_sequencer-*.gem`
|
17
|
+
|
18
|
+
# Build gem:
|
19
|
+
build_result = `gem build ./euclidean_sequencer.gemspec`
|
20
|
+
printf("%s", build_result)
|
21
|
+
|
22
|
+
# Yank old gem:
|
23
|
+
# yank_result =`gem yank euclidean_sequencer`
|
24
|
+
# printf("%s", yank_result)
|
25
|
+
|
26
|
+
# Push gem:
|
27
|
+
push_result =`gem push ./euclidean_sequencer-#{gem.version}.gem`
|
28
|
+
printf("%s", push_result)
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "euclidean_sequencer"
|
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,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require './lib/euclidean_sequencer/parser.rb'
|
5
|
+
require './lib/euclidean_sequencer/sequencer.rb'
|
6
|
+
|
7
|
+
load Pathname.new(__FILE__).dirname.parent.join('lib/sequencer.rb')
|
8
|
+
|
9
|
+
options = Parser.parse(ARGV)
|
10
|
+
sequence = Sequencer.generate(hits: options[:hits], pulses: options[:pulses], options: options)
|
11
|
+
|
12
|
+
printf("%s", sequence)
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'euclidean_sequencer'
|
3
|
+
spec.version = '0.0.2'
|
4
|
+
spec.date = '2018-05-04'
|
5
|
+
spec.summary = "Generates sequences of hits spaced as evenly as possible \
|
6
|
+
across given pulses."
|
7
|
+
spec.description = "Generates sequences of hits spaced as evenly as possible \
|
8
|
+
across given pulses using the Euclidean algorithm."
|
9
|
+
spec.authors = ["Matt Ridenour"]
|
10
|
+
spec.email = 'mattridenour@gmail.com'
|
11
|
+
spec.homepage = 'https://gitlab.com/Mattbot/gem-euclidean-sequencer'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
14
|
+
f.match(%r{^(test|spec|features)/})
|
15
|
+
end
|
16
|
+
spec.bindir = "bin"
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
class Engine
|
2
|
+
# The magickal euclidean algorithmical engine!
|
3
|
+
|
4
|
+
def self.run(hits:, pulses:)
|
5
|
+
euclid(hits, pulses)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.euclid(hits, pulses, sequence = nil)
|
11
|
+
# Contruct the sequence if new otherwise continue with current sequence:
|
12
|
+
sequence ||= generate_sequence(hits, pulses)
|
13
|
+
|
14
|
+
# Determine if the algorithm has concluded or another iteration is neccessy:
|
15
|
+
return sequence.sum('') if hits == 0
|
16
|
+
|
17
|
+
# Count the sequence element types (remainder or denominator) for distribution:
|
18
|
+
remainder, denominator = find_remainder_and_denominator(sequence)
|
19
|
+
|
20
|
+
# Determine how many sets of zeros can be nabbed from the pulses at a time,
|
21
|
+
# insuring all the zeros get used up before the algorithm ends.
|
22
|
+
zero_sets = find_zero_sets(hits, pulses, remainder, denominator, sequence.length)
|
23
|
+
|
24
|
+
# Distribute the remainder into the denominator and pop the unnecessary elements:
|
25
|
+
sequence = distribute_and_pop_sequence(sequence, zero_sets, remainder, denominator)
|
26
|
+
|
27
|
+
# Recursion:
|
28
|
+
return euclid(pulses % hits, hits, sequence)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.generate_sequence(hits, pulses)
|
32
|
+
sequence = []
|
33
|
+
pulses.times {|pulse| sequence[pulse] = "0"}
|
34
|
+
hits.times { |hit| sequence[hit] = "1" }
|
35
|
+
sequence
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.find_remainder_and_denominator(sequence)
|
39
|
+
remainder, denominator = [0,0]
|
40
|
+
sequence.each do |element|
|
41
|
+
if element == sequence.last
|
42
|
+
remainder = remainder + 1
|
43
|
+
else
|
44
|
+
denominator = denominator + 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
[remainder,denominator]
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.find_zero_sets(hits, pulses, remainder, denominator, sequence_length)
|
51
|
+
if pulses > hits * 2
|
52
|
+
# Must avoid division by zero:
|
53
|
+
unless hits == 0
|
54
|
+
if denominator == 0
|
55
|
+
zero_sets = 1
|
56
|
+
else
|
57
|
+
# Grab as many zeros as possible:
|
58
|
+
zero_sets = remainder / denominator
|
59
|
+
end
|
60
|
+
# But don't grab as many zeros as impossible:
|
61
|
+
if zero_sets > sequence_length
|
62
|
+
zero_sets = 0
|
63
|
+
end
|
64
|
+
# Scrapping the bottom of the zero barrel:
|
65
|
+
if zero_sets == 0 and remainder > 1
|
66
|
+
zero_sets = 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
# The ratio of hits to pulses isn't so low as to start hording zeros:
|
71
|
+
zero_sets = 1
|
72
|
+
end
|
73
|
+
zero_sets
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.distribute_and_pop_sequence(sequence, zero_sets, remainder, denominator)
|
77
|
+
# Choose the approiate counter for the current size of the sequence:
|
78
|
+
distributions = (remainder > denominator) ? denominator : remainder
|
79
|
+
|
80
|
+
distributions.times do |distribution|
|
81
|
+
zero_sets.times do
|
82
|
+
sequence[distribution] << sequence.pop unless sequence[distribution].nil?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
sequence
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Formator
|
2
|
+
|
3
|
+
def self.format_sequence(sequence:, options: {array: nil, offset: nil})
|
4
|
+
if options[:array] && !options[:offset]
|
5
|
+
return convert_to_array(sequence)
|
6
|
+
end
|
7
|
+
|
8
|
+
if options[:array] && options[:offset]
|
9
|
+
return offset(convert_to_array(sequence), options[:offset])
|
10
|
+
end
|
11
|
+
|
12
|
+
if options[:offset] && !options[:array]
|
13
|
+
return offset(sequence, options[:offset])
|
14
|
+
end
|
15
|
+
|
16
|
+
return sequence
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.convert_to_array(sequence)
|
22
|
+
array = []
|
23
|
+
sequence.length.times { |element| array[element] = sequence[element].to_i }
|
24
|
+
array
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.offset(sequence, offset)
|
28
|
+
if sequence.is_a?(String)
|
29
|
+
return offset_array(sequence.split(//), offset).join
|
30
|
+
end
|
31
|
+
return offset_array(sequence, offset)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.offset_array(array, offset)
|
35
|
+
offset.times { array << array.shift }
|
36
|
+
return array
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class Parser
|
4
|
+
def self.parse(argv)
|
5
|
+
options = Struct.new(:hits, :pulses, :array, :offset)
|
6
|
+
args = options.new()
|
7
|
+
|
8
|
+
opt_parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: euclidean_sequncer [options]"
|
10
|
+
|
11
|
+
opts.on("-h", "--hits=HITS", Integer, "Number of 'on' elements in the sequncer: INTEGER") do |hits|
|
12
|
+
args.hits = hits
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-pPULSES", "--pulses=PULSES", Integer, "Total number of elements in the sequncer: INTEGER") do |pulses|
|
16
|
+
raise Exception if pulses.nil?
|
17
|
+
args.pulses = pulses
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-a", "--array=TRUE", FalseClass, "Output as array (optional): BOOLEAN") do |array|
|
21
|
+
args.array = array
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-o", "--offset=OFFSET", Integer, "Number elements left shifted in the sequence (optional): INTEGER") do |offset|
|
25
|
+
args.offset = offset
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-?", "--help", "Prints this help") do
|
29
|
+
puts opts
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
opt_parser.parse!(argv)
|
36
|
+
rescue Exception => error
|
37
|
+
printf("ERROR: %s \n", error)
|
38
|
+
opt_parser.parse!(["--help"])
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
return args
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require './lib/euclidean_sequencer/engine'
|
2
|
+
require './lib/euclidean_sequencer/formator'
|
3
|
+
|
4
|
+
class Sequencer
|
5
|
+
def self.generate(hits: 0, pulses: 0, options: {array: nil, offset: nil})
|
6
|
+
format_sequence(run(hits, pulses), options)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def self.run(hits, pulses)
|
12
|
+
Engine.run(hits: hits, pulses: pulses)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.format_sequence(sequence, options)
|
16
|
+
Formator.format_sequence(sequence: sequence, options: options)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require './lib/euclidean_sequencer/sequencer.rb'
|
2
|
+
|
3
|
+
module EuclideanSequencer
|
4
|
+
def self.generate(hits: 0, pulses: 0, options: {array: nil, offset: nil})
|
5
|
+
sequence = run(hits, pulses, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.run(hits, pulses, options)
|
11
|
+
Sequencer.generate(hits: hits, pulses: pulses, options: options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: euclidean_sequencer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Ridenour
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-04 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: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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
|
+
description: Generates sequences of hits spaced as evenly as possible across given
|
42
|
+
pulses using the Euclidean algorithm.
|
43
|
+
email: mattridenour@gmail.com
|
44
|
+
executables:
|
45
|
+
- build_and_push_gem
|
46
|
+
- console
|
47
|
+
- euclidean_sequencer
|
48
|
+
- setup
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- ".envrc"
|
53
|
+
- ".envrc.example"
|
54
|
+
- ".gitignore"
|
55
|
+
- ".rspec"
|
56
|
+
- CODE_OF_CONDUCT.md
|
57
|
+
- Gemfile
|
58
|
+
- Gemfile.lock
|
59
|
+
- Guardfile
|
60
|
+
- LICENSE.txt
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- bin/build_and_push_gem
|
64
|
+
- bin/console
|
65
|
+
- bin/euclidean_sequencer
|
66
|
+
- bin/setup
|
67
|
+
- euclidean_sequencer.gemspec
|
68
|
+
- lib/euclidean_sequencer.rb
|
69
|
+
- lib/euclidean_sequencer/engine.rb
|
70
|
+
- lib/euclidean_sequencer/formator.rb
|
71
|
+
- lib/euclidean_sequencer/parser.rb
|
72
|
+
- lib/euclidean_sequencer/sequencer.rb
|
73
|
+
homepage: https://gitlab.com/Mattbot/gem-euclidean-sequencer
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.7.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Generates sequences of hits spaced as evenly as possible across given
|
97
|
+
pulses.
|
98
|
+
test_files: []
|