A Python library for implementing music theory in data structures, facilitating the management of relationships between notes and the retrieval of specific information about them.
Project description
How to use
Note object
The Note object is a core component of this package. A note, such as "A", requires detailed context about its properties to be truly useful, including pitch, position, alteration, octave, and other relevant information. The Note object provides access to this information for user reference or for use by other objects and functions within the package.
import noteforge as nf
note = nf.Note("C#") # => C#3, by default, the octave is 3
note_2 = nf.Note("C#",4) # => C4
The note range is from A0 to C8, based on the standard piano keyboard
note = nf.Note("D",8) # this throws an error
Note name
you can get basic information if needed, the note name consists of three parts: [proper name|alteration|octave], each part can be accessed separately
note = nf.Note("C#") # => C#3, by default, the octave is 3
note_proper_name = note.proper_name # => C
name = note.get_name() # => C#
full_name = note.get_full_name() # => C#3
Note position
Use the provided methods to access positional information. There are three positional values: [natural|chromatic|absolute]
chromatic: the chromatic index of the note, based on the 12 standard music notesnatural: the natural index of the note, based on the 7 natural note names that have a proper nameC, D, E, F, G, A, Babsolute: a unique value for each note with the same properties, values range from9(A0) to96(C8), so you can use it as a kind of id
import noteforge as nf
note = nf.Note("A",0)
print(note.get_chromatic_position())
print(note.get_natural_position())
print(note.get_absolute_position())
Another useful properties are:
alteration contribution: the semitone value of the alteration -- if it is 0 the note not has alterationfrequency: the fundamental frequency of the note in Hz
print(note.get_freq()) # get frequency of note, in this case : 27.5 Hz
print(note.get_alteration_contribution())
Intervals
musical intervals are represented by two set of strings
- Intervaldegree : a
strthat represent a valid interval degree, for example[b5,5,#5]has the same degree which5 - IntervalSymbol : a
strthat represent a valid interval with quality (minor, major, perfect, etc...) such as[b5,5,#5]
Get interval
This package works with standard intervals. You can use functions to retrieve any of them, but if the interval between notes is non-conventional, it returns None
root = nf.Note("C")
interval_1 = nf.get_interval_between_notes(root,nf.Note("E")) # = 3 as <str> IntervalSymbol
interval_2 = nf.get_interval_between_notes(root,nf.Note("Fb")) # = None because b4 is not and standard interval
interval_3 = nf.get_interval_between_notes(root,nf.Note("Db")) # = b2 as <str> IntervalSymbol
interval_4 = nf.get_interval_between_notes(root,nf.Note("C#")) # = None because #1 or #15 is not and standard interval
Get interval degree
IntervalSymbol can share the same Intervaldegree
interval = nf.get_interval_between_notes(nf.Note("C"), nf.Note("E")) # = 3 as <str> and IntervalSymbol
interval_2 = nf.get_interval_between_notes(nf.Note("C"), nf.Note("Eb")) # = b3 as <str> and IntervalSymbol
degree = nf.get_interval_degree(interval) # = 3 as <str> Intervaldegree
degree_2 = nf.get_interval_degree(interval_2) # = 3 as <str> Intervaldegree
You can get the value of an Intervaldegree. Some Intervaldegrees are extensions of others, so their degree value can be used to relate them.
print(nf.get_interval_degree_value("2")) # = 2
print(nf.get_interval_degree_value("9")) # = 2
Get Note by interval
You can also use interval to get a note_name or directly a Note object — in the latter case, the octave is calculated automatically
root = nf.Note("A",3)
note_name = nf.get_note_name_by_interval(root,"5") # = E as <str>
note = nf.get_note_by_interval(root,"2") # = E4 as <Note>
Transpositions
you can transpose a note by semitones or interval
Semitone transpose: uses the chromatic scale to transpose without altering the interval degree
note = nf.Note("C", 3)
transposed_note = nf.transpose_note(note, 6)
print(transposed_note.get_full_name()) # F#3
Interval transpose: This prioritizes the interval's degree, then finds a note or note name matching its semitone distance. Applies to any method using intervals to calculate note distance, likenf.get_note_name_by_intervalornf.get_note_by_interval
note = nf.Note("C",3)
transposed_note_2 = nf.get_note_by_interval(note, "#4")
print(transposed_note_2.get_full_name()) # = F#3
transposed_note_3 = nf.get_note_by_interval(note, "b5")
print(transposed_note_3.get_full_name()) # = Gb3
Interval degree transposition: try transform the interval degree while maintaining the interval quality, throwNoneif the result don't exist in standard intervals
interval = "b3"
transposed = nf.transpose_interval_degree(interval,"9") # = b9 as <str> IntervalSymbol
transposed_2 = nf.transpose_interval_degree(interval,"4") # = None, because 'b4' is not an standard interval
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file noteforge-0.0.5.tar.gz.
File metadata
- Download URL: noteforge-0.0.5.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
212edaa7753633c08f2483785fca3d7b636152fc56f66e7808f55e29ec1b8c89
|
|
| MD5 |
a99aebeabf3092503c6056d629d035a0
|
|
| BLAKE2b-256 |
8c2cfc18d17742823b94ba2ef1456218a8578defe387fc4c9ea9eb10b0b760a7
|
File details
Details for the file noteforge-0.0.5-py3-none-any.whl.
File metadata
- Download URL: noteforge-0.0.5-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf3a3a60c971489fae88efe8f0dead09ecb654d0d914c1519110a7817ed7a9f6
|
|
| MD5 |
70ed50b201bb77ed93815273236f532f
|
|
| BLAKE2b-256 |
597aa1080c398dd9d265c15b1abe5f2fb96a23b699328b7eef6a9368ca5586a7
|