superfonic / transcription

Transcribe audio files into sheet music.
GNU General Public License v3.0
6 stars 0 forks source link

Pythonic Sheet Music Emulator #16

Open dt-woods opened 3 years ago

dt-woods commented 3 years ago

Is there a way to write notes in a sheet music format?

dt-woods commented 3 years ago

See also abcnotation and LilyPond

dt-woods commented 3 years ago

On the discussion of ABC notation versus lilly pond.

dt-woods commented 3 years ago

Trying mingus. See here for documentation.

  1. Cloned their GitHub repo
  2. Created a new virtual Python environment (virtualenvwrapper)
  3. Ran setup.py in virtual environment: got mingus to work

The online tutorials are weird, but basically works.

import mingus.extra.lilypond as LilyPond

b = Bar()
b + "C"
b + "E"
b + "G"
b + "B"
LilyPond.from_Bar(b)   # "{ \\time 4/4 \\key c \\major c'4 e'4 g'4 b'4 }"

Note that the Note class also exists in LilyPond

print(LilyPond.Note().from_hertz(440))  # prints 'A-4'
dt-woods commented 3 years ago

Yes, and we can map keys to treble clef using LilyPond notation.

c'   # middle C
dt-woods commented 3 years ago

LOL. Mingus can basically replace our utilities.py

from mingus.containers import Note

print(Note().from_hertz(215))   # prints A-3

c = Note().from_hertz(261)
c.note    # prints C
c.octave  # prints 4
dt-woods commented 3 years ago

The issue is when the peak frequency is zero, which presently is set to REST; therefore, we still need the get_note function and at least one if-statement.

Notice that erroneous frequency values to the Note().from_hertz() function throw a ValueError, which can be caught in a try-except block.

dt-woods commented 3 years ago

Notice that mingus assumes a default standard pitch is 440 (the A-4).

dt-woods commented 3 years ago

This works for now:

import mingus.extra.lilypond as LilyPond
from mingus.containers import Bar
from mingus.containers import Note

mb = Bar()
mb.place_notes(Note().from_hertz(440), 4)  # assume quarter notes
mb.place_notes(Note().from_hertz(880), 4)
LilyPond.from_Bar(mb, False, False) # save this to an .ly file