Studying to play the piano is a difficult and enjoyable course of, however each novice can have a dilemma: what sort of instrument to purchase? The selection available in the market is huge, from the tiny two-octave devices like within the picture above to 70kg full-size keyboards in a wood cupboard. On the one hand, having additional keys won’t ever harm; however, there’s all the time a trade-off between dimension, weight, and worth.
Clearly, one of many methods is to simply ask a instructor about what she or he can suggest, however possibly most musicians simply by no means thought of music from that perspective. Is there any extra quantitative approach to discover a solution? Truly, the reply is sure; we are able to simply make a musical notice distribution utilizing Python.
This tutorial will be helpful for learners in knowledge science; it doesn’t require any complicated math or libraries, and the outcomes are simple to interpret. It may also be helpful for individuals who need to be taught to play music however haven’t but determined what sort of instrument to purchase.
Let’s get into it!
Knowledge Supply
For knowledge evaluation, I will probably be utilizing MIDI recordsdata. It’s a fairly previous format; the primary MIDI (Musical Instrument Digital Interface) specification was revealed in 1983. The important thing characteristic of MIDI recordsdata is that they retailer the music not as uncooked audio however within the “unique” notation type. Each document in a midi file comprises the instrument sort, pitch, timing, and different parameters. For instance, I can open a Bagatelle in C minor written by Beethoven in a free MuseScore utility and see one thing like this:
Let’s open the identical file in Python and dump its content material:
import mido # pip3 set up midomid = mido.MidiFile("Beethoven/Bagatelle.mid", clip=True)
for ind, monitor in enumerate(mid.tracks):
print(f"Monitor {ind}")
for merchandise in monitor[:10]:
print(merchandise)
The output appears to be like like this (a full file is longer; right here, I print solely the primary traces from every monitor):