m for the note A4 is 69 and increases by one for each equal tempered semitone, so this gives us a simple conversion between frequencies and MIDI numbers (again using 440 Hz as the pitch of A4):
In electronic music, pitch is often given by MIDI number: let's call it m for our purposes. Similar equations give n o, the number of octaves from A4, and n c, the number of cents from A4: For a note that lies n semitones higher (or −n semitones lower), the frequency is thenĬonversely, one can obtain n, the number of semitones from A4, from This is usually A4, which is often set at 440 Hz. First, one needs a reference note and frequency. In equal temperament, where all semitones have the same frequency ratio of 2 1/12, conversion between note name and frequency is simple. Now to divide the octave into smaller units. An octave is a ratio of 2:1, so the number of octaves between f 2 and f 1 is
How to do the calculation? Suppose that two notes have frequenciesį 1 and f 2, and a frequency ratio of f 2/f 1. To note converter written by Andrew Botros. to the nearest note and how far it is out of tune, go to the frequency This table is reproduced below but inverted, i.e. to the nearest note and how far it is out of tune), go These data were used to calculate the first table below, which gives the frequency of any standard keyboard note By convention, A4 is often set at 440 Hz. Each semitone therefore has a ratio of 2 1/12 (approximately 1.059). See Frequency and Pitch for more details and an introduction to frequency and pitch.Īn octave is a ratio of 2:1 and, in equal temperament, an octave comprises 12 equal semitones. The musical interval between two notes depends on the ratio of their frequencies. Midi allows for finer pitch definition but it would be far beyond this answer.Note names, MIDI numbers and frequencies are related here in tables and via an application that converts them. (*) it is musically what is called equal temperament. As you have 12 semitones in one octave, you will get C 5 at midi note 81, and the famous A440 (midi note 69) is A 4 in scientific notation.Īs an example for the table Midi note | Scientific notation So C 4 is midi note 69, and midi notes are separated with a semitone(*). (from MIDI Tuning Standard - Frequency values)Īnd finally from C (musical note) - Designation by octave Scientific designation |Octave name | Frequency (Hz) | Other names Ĭonverting from midi note number (d) to frequency (f) is given by the following formula: GM specifies that note number 69 plays A440, which in turn fixes middle C as note number 60. I understand that what you really need is a way to convert a midi note number to a note in standard notation. There is also the issue of timing, but you said that that's not a problem for you. I don't think that you can handle the velocity using a computer keyboard. This means that you might need to be able to send more than one key press event at the same time. Note that in MIDI multiple notes can be played simultaneously, or can overlap in time. The next problem that you will face is sending the key events. From there you can work out the mapping for the MIDI numbers to the supported virtualpiano keys it's this: midi_to_vk = ( The next note, Cs_5, is MIDI 61 which is uppercase T (-t). Middle C is equal to MIDI 60 and this note corresponds to the 25th key on the virtualpiano keyboard which is activated by pressing the letter t. Now all of that is interesting, but you don't really need to convert the MIDI number to a note, you just need to convert it to the keyboard key for that note as used by.
The NoteOnEvent contains timing, MIDI number/pitch and velocity which you can retrieve: > on = midi.NoteOnEvent(tick=0, channel=0, data=) Midi.NoteOffEvent(tick=100, channel=0, data=), Midi.Pattern(format=1, resolution=220, tracks=\ Opening a MIDI file with read_midifile() returns a Pattern object which looks like this (taken from the examples): > midi.read_midifile('example.mid') If you take a look at the midi module that you are using, you will see that there are some constants that can be used to convert notes to their MIDI number and vice versa.