Handle musical notes and their sounds in Python
Project description
munotes
musical-notes
This library is for handling notes and chords in Python.
Note
Note class. Handling note.
This class is used by inputting the note name and octave height, or MIDI note number at initialization.
import munotes as mn
note = mn.Note("A", octave=4)
print(note) # A4
note = mn.Note(69)
print(note) # A4
transpose()
Transpose the note.
note.transpose(2)
print(note) # B4
render()
Get the waveform of the note.
import matplotlib.pyplot as plt
y = note.render('sin')
plt.plot(y[:200])
squere
and sawtooth
are also sapported.
y = note.render('squere')
plt.plot(y[:200])
y = note.render('sawtooth')
plt.plot(y[:200])
Arbitrary waveforms are also supported.
y = note.render(lambda t: np.sin(t) + np.sin(2*t))
plt.plot(y[:200])
play()
Get IPython.display.Audio object.
Notes
Notes class. Handling multiple notes.
This class is used by inputting the notes at initialization.
notes = mn.Notes(
mn.Note("C", octave=4),
mn.Note("E", octave=4),
mn.Note("G", octave=4)
)
print(notes) # C4 E4 G4
Methods are the same as Note
. Ex: transpose()
, render()
, play()
.
Chord
Chord class. Handling chord.
This class generates a Notes object by inputting a chord name at initialization.
from munotes import Chord
chord = Chord("A#m7")
print(chord) # A#m7
print(chord.names) # ['A#', 'C#', 'F', 'G#']
Methods are the same as Note
(and Notes
).
Transpose is also supported by transpose()
chord.transpose(3)
print(chord) # C#m7
print(chord.names) # ['C#', 'E', 'G#', 'B']
Track
Track class. Handling multiple Notes as a sequence.
This class is used by inputting the notes and durations at initialization.
track = mn.Track([
(mn.Note("C", octave=4), 1),
(mn.Note("E", octave=4), 1),
(mn.Note("G", octave=4), 1)
])
Methods are the same as other classes.
But in methods that handling waveform (render()
, play()
, etc), generate the waveform as sequence of notes (like: C -> E -> G).
Stream
Stream class. Handling multiple tracks.
This class is used by inputting the tracks at initialization.
melody = mn.Track([
(mn.Note("C", octave=4), 1),
(mn.Note("D", octave=4), 1),
(mn.Note("E", octave=4), 1)
])
chords = mn.Track([
(mn.Chord("C"), 3),
])
stream = mn.Stream([melody, chords])
Methods are the same as other classes.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.