sergovia 0.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e7fe6512760c2fefbc46909b4140adcc48af41c
4
+ data.tar.gz: d48b7b9bebf1811684896913df9c8dfd2d73b6e1
5
+ SHA512:
6
+ metadata.gz: a7833f4a85b7ce2b075d54c441aa67e06275c4763f3b6b40bef293373d4872908179dfe09c82f4fea3aca876b580abfb83da0e6c0d17ef7dbd24b51cb0fa23cb
7
+ data.tar.gz: 7aa0d1c0839f1743b692a3ba39f2cc6402d399810e355ca5b6fcd47285b4ae67e3f56ac7d9ffb8e005e4b99619658fd66d7630d9857b97bd65febd428aca72fc
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ *.sw*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sergovia.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,138 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
4
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
11
+
12
+ When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
13
+
14
+ To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
15
+
16
+ For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
17
+
18
+ We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
19
+
20
+ Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
21
+
22
+ Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
23
+
24
+ The precise terms and conditions for copying, distribution and modification follow.
25
+
26
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
27
+
28
+ 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
29
+
30
+ Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
31
+
32
+ 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
33
+
34
+ You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
35
+
36
+ 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
37
+
38
+ a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
39
+ b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
40
+ c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
41
+
42
+ These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
43
+
44
+ Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
45
+
46
+ In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
47
+
48
+ 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
49
+
50
+ a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
51
+ b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
52
+ c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
53
+
54
+ The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
55
+
56
+ If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
57
+
58
+ 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
59
+
60
+ 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
61
+
62
+ 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
63
+
64
+ 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
65
+
66
+ If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
67
+
68
+ It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
69
+
70
+ This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
71
+
72
+ 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
73
+
74
+ 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
75
+
76
+ Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
77
+
78
+ 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
79
+
80
+ NO WARRANTY
81
+
82
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
83
+
84
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
85
+
86
+ END OF TERMS AND CONDITIONS
87
+
88
+ How to Apply These Terms to Your New Programs
89
+
90
+ If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
91
+
92
+ To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
93
+
94
+ one line to give the program's name and an idea of what it does.
95
+ Copyright (C) yyyy name of author
96
+
97
+ This program is free software; you can redistribute it and/or
98
+ modify it under the terms of the GNU General Public License
99
+ as published by the Free Software Foundation; either version 2
100
+ of the License, or (at your option) any later version.
101
+
102
+ This program is distributed in the hope that it will be useful,
103
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
104
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105
+ GNU General Public License for more details.
106
+
107
+ You should have received a copy of the GNU General Public License
108
+ along with this program; if not, write to the Free Software
109
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
110
+ Also add information on how to contact you by electronic and paper mail.
111
+
112
+ If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
113
+
114
+ Gnomovision version 69, Copyright (C) year name of author
115
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
116
+ type `show w'. This is free software, and you are welcome
117
+ to redistribute it under certain conditions; type `show c'
118
+ for details.
119
+
120
+ The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
121
+
122
+ You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
123
+
124
+ Yoyodyne, Inc., hereby disclaims all copyright
125
+ interest in the program `Gnomovision'
126
+ (which makes passes at compilers) written
127
+ by James Hacker.
128
+
129
+ signature of Ty Coon, 1 April 1989
130
+ Ty Coon, President of Vice
131
+
132
+ Standard License Header
133
+ Copyright (C) {{year}} {{name of author}}
134
+ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
135
+
136
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
137
+
138
+ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # Sergovia
2
+
3
+ Sergovia produces a list of all possible ways to play a chord on the guitar. It ranks them by their playability. It is primarily intented to be useful to two groups of musicians. The first is composers who do not play the guitar but want to write guitar music. The second is guitarists learning or arranging a new piece. I expect it to mostly be useful to classical musicians, but I hope it will sometimes be effective for other genres.
4
+
5
+ # Usage
6
+
7
+ In this example, we ask sergovia how to play the notes of an open E chord. Sergovia tells us that there is only one way to play those six notes and that it is 100% playable
8
+
9
+ ```ruby
10
+ require 'sergovia'
11
+ Sergovia::Chord.new('e2,b2,e3,g#3,b3,e4').fingerings
12
+ => [#<Sergovia::Fingering:0x000001031b5fb8 @notes=[#<Sergovia::Note:0x0000010114a0d0 @fret=0, @string=6, @pitch=:e2>,
13
+ #<Sergovia::Note:0x00000101148d70 @fret=2, @string=5, @pitch=:b2>,
14
+ #<Sergovia::Note:0x000001011436e0 @fret=2, @string=4, @pitch=:e3>,
15
+ #<Sergovia::Note:0x00000101142498 @fret=1, @string=3, @pitch=:"g#3">,
16
+ #<Sergovia::Note:0x00000101140e90 @fret=0, @string=2, @pitch=:b3>,
17
+ #<Sergovia::Note:0x0000010113ba08 @fret=0, @string=1, @pitch=:e4>],
18
+ @playability=1.0>]
19
+ ```
20
+
21
+ Next we'll ask how many ways there are to play a C major triad starting on the lowest C on the standard tuned guitar. We see that there are 8 ways, but that only 3 of those are easily playable. One of them is maybe possible, but very hard. The remaining 4 are unplayable.
22
+
23
+ ```ruby
24
+ Sergovia::Chord.new('c3,e3,g3').fingerings
25
+ => [#<Sergovia::Fingering:0x00000101150ea8 @notes=[#<Sergovia::Note:0x0000010180b838 @fret=8, @string=6, @pitch=:c3>,
26
+ #<Sergovia::Note:0x0000010180a4d8 @fret=7, @string=5, @pitch=:e3>,
27
+ #<Sergovia::Note:0x00000101808cf0 @fret=5, @string=4, @pitch=:g3>],
28
+ @playability=1.0>,
29
+ #<Sergovia::Fingering:0x00000101151240 @notes=[#<Sergovia::Note:0x0000010180b838 @fret=8, @string=6, @pitch=:c3>,
30
+ #<Sergovia::Note:0x0000010180a4d8 @fret=7, @string=5, @pitch=:e3>,
31
+ #<Sergovia::Note:0x00000101808e58 @fret=0, @string=3, @pitch=:g3>],
32
+ @playability=1.0>,
33
+ #<Sergovia::Fingering:0x00000101152370 @notes=[#<Sergovia::Note:0x0000010180ba40 @fret=3, @string=5, @pitch=:c3>,
34
+ #<Sergovia::Note:0x0000010180a7d0 @fret=2, @string=4, @pitch=:e3>,
35
+ #<Sergovia::Note:0x00000101808e58 @fret=0, @string=3, @pitch=:g3>],
36
+ @playability=1.0>,
37
+ #<Sergovia::Fingering:0x000001011517b8 @notes=[#<Sergovia::Note:0x0000010180b838 @fret=8, @string=6, @pitch=:c3>,
38
+ #<Sergovia::Note:0x0000010180a7d0 @fret=2, @string=4, @pitch=:e3>,
39
+ #<Sergovia::Note:0x00000101808e58 @fret=0, @string=3, @pitch=:g3>],
40
+ @playability=0.1>,
41
+ #<Sergovia::Fingering:0x00000101151c90 @notes=[#<Sergovia::Note:0x0000010180ba40 @fret=3, @string=5, @pitch=:c3>,
42
+ #<Sergovia::Note:0x0000010180a1e0 @fret=12, @string=6, @pitch=:e3>,
43
+ #<Sergovia::Note:0x00000101808e58 @fret=0, @string=3, @pitch=:g3>],
44
+ @playability=0.0>,
45
+ #<Sergovia::Fingering:0x00000101151a88 @notes=[#<Sergovia::Note:0x0000010180ba40 @fret=3, @string=5, @pitch=:c3>,
46
+ #<Sergovia::Note:0x0000010180a1e0 @fret=12, @string=6, @pitch=:e3>,
47
+ #<Sergovia::Note:0x00000101808cf0 @fret=5, @string=4, @pitch=:g3>],
48
+ @playability=0.0>,
49
+ #<Sergovia::Fingering:0x000001011520f0 @notes=[#<Sergovia::Note:0x0000010180ba40 @fret=3, @string=5, @pitch=:c3>,
50
+ #<Sergovia::Note:0x0000010180a7d0 @fret=2, @string=4, @pitch=:e3>,
51
+ #<Sergovia::Note:0x000001018087a0 @fret=15, @string=6, @pitch=:g3>],
52
+ @playability=0.0>,
53
+ #<Sergovia::Fingering:0x000001011514c0 @notes=[#<Sergovia::Note:0x0000010180b838 @fret=8, @string=6, @pitch=:c3>,
54
+ #<Sergovia::Note:0x0000010180a7d0 @fret=2, @string=4, @pitch=:e3>,
55
+ #<Sergovia::Note:0x00000101808ae8 @fret=10, @string=5, @pitch=:g3>],
56
+ @playability=0.0>]
57
+ ```
58
+
59
+ ### Terms as they are used in this project (Lexicon)
60
+
61
+ * Chord
62
+ * A collection of pitches played simultaneously
63
+ * Voicing
64
+ * The order in which notes are stacked for a given chord. For example, (c3,e3,g#3) is a block voicing of a C Major chord, and (e2,c3,g#3) is a different voicing of the same chord. Playing the exact same pitch at a location place on the guitar does not change the voicing. That would only change the fingering. Pitches need be moved to different octaves to change the voicing.
65
+ * Fingering
66
+ * A specific way to play a voicing on a given instrument. For the guitar, this means the a grouping of pitch/string/fret/finger for each note in the chord. Sergovia does not currently attempt to say which finger should be used, so in this gem it is currently pitch/string/fret.
67
+ * Note
68
+ * In this gem (but not in music theory in general) a Note is a combination of a pitch and the location it is played on the guitar. It is like a fingering, but for only one pitch, rathar than a whole chord.
69
+ * Pitch
70
+ * The western music theory represention of a frequency. For example, e2
71
+ * Transcriber
72
+ * Someone (or a ruby class) that prepares a piece of music for a specific instrument that differs from the one(s) it was originally composed for.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
data/TODO.md ADDED
@@ -0,0 +1,6 @@
1
+ * Basic ordering
2
+ * Stretch DONE
3
+ * Make stretch less all or nothing DONE
4
+ * Inverted note order (playing a higher note on a lower string)
5
+ * Known shape modifier (set known playable shapes to a representive playability score)
6
+ * String skipping scorer
@@ -0,0 +1,15 @@
1
+ module Sergovia
2
+ class Chord
3
+ attr_accessor :pitches, :tuning, :frets
4
+
5
+ def initialize(pitch_string, tuning: STANDARD_TUNING, frets: 24)
6
+ @pitch_string = pitch_string
7
+ @tuning = tuning
8
+ @frets = frets
9
+ end
10
+
11
+ def fingerings
12
+ Transcriber.new(tuning: tuning, frets: frets).fingerings(@pitch_string)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Sergovia
2
+ class Fingering
3
+ attr_reader :notes, :playability
4
+
5
+ def initialize(notes:, playability: nil)
6
+ @notes = notes
7
+ @playability = playability
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Sergovia
2
+ class Note
3
+ attr_reader :fret, :string, :pitch
4
+
5
+ def initialize(fret:, string:, pitch:)
6
+ @fret = fret
7
+ @string = string
8
+ @pitch = pitch
9
+ end
10
+
11
+ def ==(other)
12
+ self.fret == other.fret && self.string == other.string && self.pitch == other.pitch
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ module Sergovia
2
+ module Scorers
3
+ class Stretch
4
+
5
+ attr_reader :fingering
6
+
7
+ def initialize(fingering)
8
+ @fingering = fingering
9
+ end
10
+
11
+ def score
12
+ #handle nils
13
+ frets = fingering.notes.map(&:fret).reject { |n| n == 0 }.sort
14
+ if frets.count > 1
15
+ span = (frets.max - frets.min)
16
+ if span > 6
17
+ return 0.00
18
+ elsif span == 6
19
+ return 0.10
20
+ elsif span == 5
21
+ return 0.25
22
+ elsif span == 4
23
+ return 0.75
24
+ else
25
+ return 1.00
26
+ end
27
+ else
28
+ return 1.00
29
+ end
30
+ end
31
+
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,99 @@
1
+ module Sergovia
2
+ class Transcriber
3
+
4
+ attr_reader :tuning, :frets, :fretboard
5
+
6
+ def initialize(tuning:[:e2, :a2, :d3, :g3, :b3, :e4], frets: 24)
7
+ @tuning = tuning
8
+ @frets = frets
9
+ build_fretboard
10
+ end
11
+
12
+ def fingerings(pitch_sting)
13
+ in_theory = theoretical_fingerings(pitch_sting)
14
+ ret = in_theory.reject do |v|
15
+ grouped_by_string = {}
16
+ v.notes.each do |n|
17
+ grouped_by_string[n.string] ||= []
18
+ grouped_by_string[n.string] << n
19
+ end
20
+ grouped_by_string.any? { |k,v| v.size > 1 }
21
+ end
22
+ ret.map do |fingering|
23
+ Fingering.new(notes:fingering.notes, playability: Scorers::Stretch.new(fingering).score)
24
+ end.sort_by(&:playability).reverse
25
+ end
26
+
27
+ def theoretical_fingerings(pitch_string)
28
+ groups = pitch_string.split(",").map do |pitch|
29
+ locations_for(pitch)
30
+ end
31
+ groups.first.product(*groups[1..-1]).map { |n| Fingering.new(notes: n) }
32
+ end
33
+
34
+ def locations_for(pitch)
35
+ original_pitch_name = pitch.to_sym
36
+ pitch = to_sharp_key_notation(original_pitch_name)
37
+
38
+ locations = []
39
+ fretboard.each_with_index do |string, string_num|
40
+ string.each_with_index do |note, fret_num|
41
+ if note == pitch
42
+ locations << Note.new(string: string_num + 1, fret: fret_num, pitch: original_pitch_name)
43
+ end
44
+ end
45
+ end
46
+ locations
47
+ end
48
+
49
+ def increment(pitch)
50
+ pitch_string = pitch.to_s.downcase
51
+ match = /([a-z][#]?[b]?)([0-9])/.match(pitch_string)
52
+ note = match[1].to_sym
53
+ octave = match[2].to_i
54
+ note = to_sharp_key_notation(note)
55
+ if note == :b
56
+ octave += 1
57
+ end
58
+ res_note = pitch_inc_map[note]
59
+ return :"#{res_note}#{octave}"
60
+ end
61
+
62
+ protected
63
+
64
+ def to_sharp_key_notation(pitch)
65
+ pitch_str = pitch.to_s
66
+ pitch_str.gsub!('bb','a#')
67
+ pitch_str.gsub!('db', 'c#')
68
+ pitch_str.gsub!('eb' , 'd#')
69
+ pitch_str.gsub!('gb' , 'f#')
70
+ pitch_str.gsub!('ab' , 'g#')
71
+ pitch_str.to_sym
72
+ end
73
+
74
+ def pitch_inc_map
75
+ @pitch_inc_map ||= {
76
+ :a => :'a#',
77
+ :'a#' => :b,
78
+ :b => :c,
79
+ :c => :'c#',
80
+ :'c#' => :d,
81
+ :d => :'d#',
82
+ :'d#' => :e,
83
+ :e => :f,
84
+ :f => :'f#',
85
+ :'f#' => :g,
86
+ :g => :'g#',
87
+ :'g#' => :a
88
+ }
89
+ end
90
+
91
+ def build_fretboard
92
+ @fretboard ||= @tuning.reverse.map do |starting_pitch|
93
+ (0..@frets - 1).inject([starting_pitch]) do |res, count|
94
+ res << increment(res.last)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,3 @@
1
+ module Sergovia
2
+ VERSION = "0.2.1"
3
+ end
data/lib/sergovia.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'ostruct'
2
+ require "sergovia/version"
3
+ require "sergovia/chord"
4
+ require "sergovia/transcriber"
5
+ require "sergovia/fingering"
6
+ require "sergovia/note"
7
+ require "sergovia/scorers/stretch"
8
+ require "ostruct"
9
+
10
+
11
+ module Sergovia
12
+ STANDARD_TUNING = [:e2, :a2, :d3, :g3, :b3, :e4]
13
+ end
data/sergovia.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sergovia/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sergovia"
8
+ spec.version = Sergovia::VERSION
9
+ spec.authors = ["Joe Cannatti"]
10
+ spec.email = ["joecannatti@gmail.com"]
11
+ spec.summary = %q{A gem to calculate the playability of chords on the guitar}
12
+ spec.description = %q{Sergovia is a Ruby implementation of a simple alogrithm that computes how playable a chord is on the guitar.}
13
+ spec.homepage = "https://github.com/joecannatti/Sergovia"
14
+ spec.license = "GPL-2.0+"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ module Sergovia
3
+ describe Chord do
4
+
5
+ describe "optional args" do
6
+
7
+ it "passes on an altered tuning" do
8
+ fingering = Chord.new('e2,b2', tuning: [:d2, :a2, :d3, :g3, :b3, :e4]).fingerings.first
9
+ fingering.notes.first.string.should eq 6
10
+ fingering.notes.first.fret.should eq 2
11
+ fingering.notes[1].string.should eq 5
12
+ fingering.notes[1].fret.should eq 2
13
+ end
14
+
15
+ it "passes on the number of frets" do
16
+ Chord.new('e6', frets: 24).fingerings.count.should eq 1
17
+ Chord.new('e6', frets: 12).fingerings.count.should eq 0
18
+ end
19
+ end
20
+
21
+ describe "fingerings" do
22
+
23
+ context "an open guitar" do
24
+ it "returns the only possible fingering" do
25
+ Chord.new('e2,a2,d3,g3,b3,e4').fingerings.count.should eq 1
26
+ end
27
+ end
28
+
29
+ context "an open e chord" do
30
+ it "returns the only possible fingering" do
31
+ Chord.new('e2,b2,e3,g#3,b3,e4').fingerings.count.should eq 1
32
+ end
33
+ it "works with ab instead of g#" do
34
+ Chord.new('e2,b2,e3,ab3,b3,e4').fingerings.count.should eq 1
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ module Sergovia
3
+ describe Fingering do
4
+
5
+ describe "instantiation" do
6
+
7
+ it "takes notes and a playbability score" do
8
+ lambda { Fingering.new(notes: [], playability: 0.5) }.should_not raise_error
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ module Sergovia
3
+ describe Note do
4
+
5
+ subject { described_class.new(fret: 0, string: 1, pitch: :e4) }
6
+
7
+ it "accepts and stores fret, string, and pitch" do
8
+ subject.fret.should eq 0
9
+ subject.string.should eq 1
10
+ subject.pitch.should eq :e4
11
+ end
12
+
13
+ describe "==" do
14
+
15
+ it "returns true if all the properties are equal" do
16
+ (described_class.new(fret: 0, string: 1, pitch: :e4) == described_class.new(fret: 0, string: 1, pitch: :e4)).should eq true
17
+ end
18
+
19
+ it "returns false if the properties are not equal" do
20
+ (described_class.new(fret: 0, string: 1, pitch: :e4) == described_class.new(fret: 1, string: 1, pitch: :f4)).should eq false
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ module Sergovia
4
+ describe Scorers::Stretch do
5
+
6
+ it "returns 1.00 for anything with less than a 4 fret span between fretted notes" do
7
+ fingering = Sergovia::Chord.new("e2,b2,e3,g#3,b3,e4").fingerings.first
8
+ described_class.new(fingering).score.should eq 1.00
9
+ end
10
+
11
+ it "returns .75 for a 4 fret span" do
12
+ fingering = Sergovia::Fingering.new(notes: [Note.new(fret: 1, string: 6, pitch: :f2), Note.new(fret: 5, string: 5, pitch: :d3)])
13
+ described_class.new(fingering).score.should eq 0.75
14
+ end
15
+
16
+ it "returns .25 for a 5 fret span" do
17
+ fingering = Sergovia::Fingering.new(notes: [Note.new(fret: 1, string: 6, pitch: :f2), Note.new(fret: 6, string: 5, pitch: :f3)])
18
+ described_class.new(fingering).score.should eq 0.25
19
+ end
20
+
21
+ it "returns .10 for a 6 fret span" do
22
+ fingering = Sergovia::Fingering.new(notes: [Note.new(fret: 1, string: 6, pitch: :f2), Note.new(fret: 7, string: 5, pitch: :f3)])
23
+ described_class.new(fingering).score.should eq 0.10
24
+ end
25
+
26
+ it "returns 0.00 for a 7 fret span" do
27
+ fingering = Sergovia::Fingering.new(notes: [Note.new(fret: 1, string: 6, pitch: :f2), Note.new(fret: 8, string: 5, pitch: :f3)])
28
+ described_class.new(fingering).score.should eq 0.00
29
+ end
30
+
31
+ end
32
+ end
33
+
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+ module Sergovia
3
+ describe Transcriber do
4
+
5
+ describe "instantiation" do
6
+
7
+ it "optionally takes tunings and fret count" do
8
+ v = Transcriber.new(tuning: [:e4, :a4, :d3, :g3, :b3, :d2], frets: 19)
9
+ v.tuning.should eq [:e4, :a4, :d3, :g3, :b3, :d2]
10
+ v.frets.should eq 19
11
+ end
12
+
13
+ it "setups fretboard" do
14
+ Transcriber.new.fretboard.count.should eq 6
15
+ Transcriber.new.fretboard.first[2].should eq :'f#4'
16
+ Transcriber.new.fretboard.first[7].should eq :'b4'
17
+ Transcriber.new.fretboard.first[8].should eq :'c5'
18
+ end
19
+
20
+ end
21
+
22
+ describe "locations_for" do
23
+
24
+ it "returns the only e2" do
25
+ locations = Transcriber.new.locations_for(:e2)
26
+ locations.count.should eq 1
27
+ locations.first.string.should eq 6
28
+ locations.first.fret.should eq 0
29
+ end
30
+ it "returns both a2s" do
31
+ locations = Transcriber.new.locations_for(:a2)
32
+ locations.count.should eq 2
33
+ locations.first.string.should eq 5
34
+ locations.first.fret.should eq 0
35
+ locations[1].string.should eq 6
36
+ locations[1].fret.should eq 5
37
+ end
38
+ it "returns all e4s" do
39
+ locations = Transcriber.new.locations_for(:e4)
40
+ locations.count.should eq 6
41
+ end
42
+
43
+ it "works with sharps" do
44
+ locations = Transcriber.new.locations_for(:'f#2')
45
+ locations.count.should eq 1
46
+ locations.first.string.should eq 6
47
+ locations.first.fret.should eq 2
48
+ end
49
+
50
+ it "works with flats" do
51
+ locations = Transcriber.new.locations_for(:'gb2')
52
+ locations.count.should eq 1
53
+ locations.first.string.should eq 6
54
+ locations.first.fret.should eq 2
55
+ end
56
+ end
57
+
58
+ describe ".increment" do
59
+ it "moves e to f" do
60
+ Transcriber.new.increment(:e4).should eq :f4
61
+ end
62
+ it "moves b to c" do
63
+ Transcriber.new.increment(:b3).should eq :c4
64
+ end
65
+ it "moves c to c#" do
66
+ Transcriber.new.increment(:c3).should eq :'c#3'
67
+ end
68
+ it "moves bb to b" do
69
+ Transcriber.new.increment(:bb3).should eq :'b3'
70
+ end
71
+ it "moves a# to b" do
72
+ Transcriber.new.increment(:'a#3').should eq :'b3'
73
+ end
74
+ it "moves a to a#" do
75
+ Transcriber.new.increment(:'a3').should eq :'a#3'
76
+ end
77
+ end
78
+
79
+ describe "#theoretical_fingerings" do
80
+ it "low a power chord has 6 possibilities" do
81
+ Transcriber.new.theoretical_fingerings("a2,e3").count.should eq 6
82
+ end
83
+ end
84
+
85
+ describe "#fingerings" do
86
+
87
+ it "removes voicings with 2 notes on the same string" do
88
+ Transcriber.new.fingerings("a2,e3").count.should eq 4
89
+ end
90
+
91
+ it "sets the playability value" do
92
+ Transcriber.new.fingerings("a2,e3").map(&:playability).any?(&:nil?).should eq false
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "test" do
4
+
5
+ it "test" do
6
+ expect(1).to eq 1
7
+
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'sergovia'
2
+ RSpec.configure do |config|
3
+ config.expect_with :rspec do |c|
4
+ # ...or explicitly enable both
5
+ c.syntax = [:should, :expect]
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sergovia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Joe Cannatti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-31 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Sergovia is a Ruby implementation of a simple alogrithm that computes
56
+ how playable a chord is on the guitar.
57
+ email:
58
+ - joecannatti@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - TODO.md
69
+ - lib/sergovia.rb
70
+ - lib/sergovia/chord.rb
71
+ - lib/sergovia/fingering.rb
72
+ - lib/sergovia/note.rb
73
+ - lib/sergovia/scorers/stretch.rb
74
+ - lib/sergovia/transcriber.rb
75
+ - lib/sergovia/version.rb
76
+ - sergovia.gemspec
77
+ - spec/lib/sergovia/chord_spec.rb
78
+ - spec/lib/sergovia/fingering_spec.rb
79
+ - spec/lib/sergovia/note_spec.rb
80
+ - spec/lib/sergovia/scorers/stretch_spec.rb
81
+ - spec/lib/sergovia/transcriber_spec.rb
82
+ - spec/lib/sergovia_spec.rb
83
+ - spec/spec_helper.rb
84
+ homepage: https://github.com/joecannatti/Sergovia
85
+ licenses:
86
+ - GPL-2.0+
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: A gem to calculate the playability of chords on the guitar
108
+ test_files:
109
+ - spec/lib/sergovia/chord_spec.rb
110
+ - spec/lib/sergovia/fingering_spec.rb
111
+ - spec/lib/sergovia/note_spec.rb
112
+ - spec/lib/sergovia/scorers/stretch_spec.rb
113
+ - spec/lib/sergovia/transcriber_spec.rb
114
+ - spec/lib/sergovia_spec.rb
115
+ - spec/spec_helper.rb