-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2a48f5e
Showing
15 changed files
with
1,407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.pyc | ||
.DS_Store | ||
*.egg-info | ||
/dist/ | ||
MANIFEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
language: python | ||
python: | ||
- '2.7' | ||
- '3.6' | ||
|
||
script: | ||
- python setup.py test | ||
|
||
deploy: | ||
provider: pypi | ||
user: Kanma | ||
password: | ||
secure: "vQk+kmXThe1zyrEeu64Q+OWT0ca8Vnn3tHXWIRxHr2K2bId/GG8RswM0NEL1JZLgL9eauOBElLa2fwYimzwN4ODU00s2Oe48iBeTqhvkf2rA5XEItLwUpitxcIk9mCjiI17pEKT/5cnLwNj596PDBjcP9zBh6qwmDGSYsRurLTCaV134Ti5zS9FgY0C/Jq11cD0cyHcP6HR79ksCbfkfBxtHy3uk21S/Vi+xfVkhFhvo2J0khzua8E6ot+uOObh8OI8G51ZhII+lVMBget1+6BAYsMMirw6fcjaDoWzpaor+wI7lEkitiAonURE/EwxSo+wXeDxxZpzVX9b4FKNpSnflCvHErw5Jue8XaOm8aI+w8s04QQJmxMkNcLUoNZy790arD37O1GYdRdgz5GgeZ25pYKmtgkxm9KuMhzIp5lDPMIAc2KTywpTao35I0tE86mxGiwubDkDIGvP+OE+ChlWqHgXHM/qZmwWIw4x2AX54VUXT5xc2G0BrSgfxrO1x9op4drQBo0v3Cqpm+nhyCuq9mhlQSdTNo8UseI7TnBqtFius6XfRBiu9ipCgAxt/WGTvrE+VknyZVHVqItavW/CF7u8Q5BHZfxnqcCydYiyFiHe+Hgi+SsW3SBhIAU1pqwE8/p5TvU61Vj4zZ5UDQLWgKJbpIpyK6QZY1v4GPKY=" | ||
on: | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright 2017 Philip Abbet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include README.rst | ||
include LICENSE.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
================= | ||
piano_fingering | ||
================= | ||
|
||
.. image:: https://travis-ci.org/Kanma/piano_fingering.svg?branch=v1.0.0 | ||
:target: https://travis-ci.org/Kanma/piano_fingering | ||
|
||
|
||
A Python library to automatically determine the fingering of a serie of notes. | ||
|
||
The algorithm is adapted from the corresponding one from | ||
https://github.com/blakewest/performer, by Blake West. | ||
|
||
|
||
|
||
Installation | ||
============ | ||
|
||
To install this library, do:: | ||
|
||
$ pip install piano_fingering | ||
|
||
|
||
|
||
Usage | ||
===== | ||
|
||
Single notes | ||
------------ | ||
|
||
The algorithm takes a list of MIDI notes as input:: | ||
|
||
from piano_fingering import computeFingering | ||
|
||
notes = [ | ||
60, | ||
62, | ||
64, | ||
65, | ||
67, | ||
69, | ||
71, | ||
72, | ||
] | ||
|
||
fingered_notes = computeFingering(notes, 'right') # or 'left' | ||
|
||
|
||
The code above will produce the following output:: | ||
|
||
fingered_notes = [ | ||
{'notes': [60], 'fingers': [1]}, | ||
{'notes': [62], 'fingers': [2]}, | ||
{'notes': [64], 'fingers': [3]}, | ||
{'notes': [65], 'fingers': [1]}, | ||
{'notes': [67], 'fingers': [2]}, | ||
{'notes': [69], 'fingers': [3]}, | ||
{'notes': [71], 'fingers': [4]}, | ||
{'notes': [72], 'fingers': [5]}, | ||
] | ||
|
||
|
||
Chords | ||
------ | ||
|
||
You can add chords to the list too:: | ||
|
||
notes = [ | ||
[60, 62, 64], | ||
[67, 71, 74], | ||
] | ||
|
||
fingered_notes = computeFingering(notes, 'right') | ||
|
||
|
||
The code above will produce the following output:: | ||
|
||
fingered_notes = [ | ||
{'notes': [60, 62, 64], 'fingers': [1, 2, 3]}, | ||
{'notes': [67, 71, 74], 'fingers': [1, 3, 5]}, | ||
] | ||
|
||
|
||
Rests | ||
----- | ||
|
||
A rest is specified by an empty list. Note that the algorithm doesn't take | ||
rests in consideration. They are supported to help the user of the library to | ||
use the result list. It is up to you to separate your notes on long rests, | ||
so the fingering of one part of the song doesn't affect another one. | ||
|
||
Example:: | ||
|
||
notes = [ | ||
60, | ||
[], | ||
64, | ||
] | ||
|
||
fingered_notes = computeFingering(notes, 'right') | ||
|
||
|
||
The code above will produce the following output:: | ||
|
||
fingered_notes = [ | ||
{'notes': [60], 'fingers': [1]}, | ||
{'notes': [], 'fingers': []}, | ||
{'notes': [64], 'fingers': [3]}, | ||
] | ||
|
||
|
||
User-defined fingering | ||
---------------------- | ||
|
||
In case the algorithm doesn't produce a fingering that you find optimal, you | ||
can constrain it by specifying your own fingering on the input:: | ||
|
||
notes = [ | ||
60, | ||
62, | ||
64, | ||
{'notes': [65], 'fingers': [4]}, | ||
67, | ||
69, | ||
71, | ||
72, | ||
] | ||
|
||
fingered_notes = computeFingering(notes, 'right') # or 'left' | ||
|
||
|
||
The code above will produce the following output:: | ||
|
||
fingered_notes = [ | ||
{'notes': [60], 'fingers': [1]}, | ||
{'notes': [62], 'fingers': [2]}, | ||
{'notes': [64], 'fingers': [3]}, | ||
{'notes': [65], 'fingers': [4]}, | ||
{'notes': [67], 'fingers': [1]}, | ||
{'notes': [69], 'fingers': [2]}, | ||
{'notes': [71], 'fingers': [3]}, | ||
{'notes': [72], 'fingers': [4]}, | ||
] | ||
|
||
|
||
Converting a note name to a MIDI note | ||
------------------------------------- | ||
|
||
Two helpers functions are provided to convert note names (like *C5*, *A#*, *Bb3*) | ||
to MIDI notes. | ||
|
||
To convert a single note name, use:: | ||
|
||
from piano_fingering import nameToMidi | ||
|
||
midi_note = nameToMidi('C4') | ||
|
||
When the octave isn't indicated, '5' is assumed. | ||
|
||
|
||
To convert a list of notes (with the same format than for *computeFingering()* in | ||
the above examples), use:: | ||
|
||
from piano_fingering import listToMidi | ||
|
||
notes = [ | ||
'C5', | ||
['C5', 'E5', 'G5'], | ||
{'notes': ['C5'], 'fingers': [1]}, | ||
] | ||
|
||
midi_notes = listToMidi(notes) | ||
|
||
|
||
|
||
Running tests | ||
============= | ||
|
||
In the source package, do:: | ||
|
||
$ python setup.py test | ||
|
||
|
||
|
||
License | ||
======= | ||
|
||
*piano_fingering* is is made available under the MIT License. The text of the license | ||
is in the file "LICENSE.txt". | ||
|
||
Under the MIT License you may use *piano_fingering* for any purpose you wish, without | ||
warranty, and modify it if you require, subject to one condition: | ||
|
||
"The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software." | ||
|
||
In practice this means that whenever you distribute your application, whether as binary | ||
or as source code, you must include somewhere in your distribution the text in the file | ||
"LICENSE.txt". This might be in the printed documentation, as a file on delivered media, | ||
or even on the credits / acknowledgements of the runtime application itself; any of | ||
those would satisfy the requirement. | ||
|
||
Even if the license doesn't require it, please consider to contribute your modifications | ||
back to the community. | ||
|
||
|
||
|
||
Special thanks to | ||
================= | ||
|
||
Blake West, for the initial javascript implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from piano_fingering.cost import createCostDatabase | ||
from piano_fingering.fingering import computeFingering | ||
from piano_fingering.midi import listToMidi | ||
from pprint import pprint | ||
|
||
|
||
right_hand_cost_database, left_hand_cost_database = createCostDatabase() | ||
|
||
print(right_hand_cost_database['48,50,1,2']) | ||
print(left_hand_cost_database['48,50,1,2']) | ||
print(left_hand_cost_database['48,50,5,4']) | ||
|
||
notes = [ | ||
'C4', | ||
'D4', | ||
'E4', | ||
'F4', | ||
'G4', | ||
'A4', | ||
'B4', | ||
'C5', | ||
[], | ||
'C5', | ||
'B4', | ||
'A4', | ||
'G4', | ||
'F4', | ||
'E4', | ||
'D4', | ||
'C4', | ||
[], | ||
['E4', 'G4', 'C5'], | ||
dict(notes=['E4', 'G4', 'B4'], fingers=[1, 3, 5]), | ||
['F4', 'A4', 'C5'], | ||
['F4', 'A4', 'D5'], | ||
] | ||
|
||
notes = listToMidi(notes) | ||
|
||
|
||
notes = computeFingering(notes, 'left') | ||
|
||
pprint(notes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .fingering import computeFingering | ||
from .midi import nameToMidi | ||
from .midi import listToMidi |
Oops, something went wrong.