note frequency statistics

• Nov 12, 2015 - 18:03

as everything is computerize it should be possible to produce note frequency statistics such as: middle c occurred 10 times in this piece for a total duration of three seconds. Perhaps even graphs with a picture of a keyboard and how often each note was played.


Comments

In reply to by HenJor

I hate maths, but I have to recognize this could be a very useful tool to composition analysis people.

I just add an screen musical pitch (frequency in Hertz and kiloHertz) showing to each note we are using (when we enter notes).

Greetings & Blessings from Chile!!!!!!!

Juan

In reply to by macrobbair

5jan2012
An article in the strad: For each [Beethoven ] quartet the researchers calculated the percentage
of notes above high G6 (1,586Hz) in the first violin part of the first movement exposition.
Writing in the Christmas edition of the British Medical Journal,
the researchers reported that the use of high notes decreased from 8 per cent
for the op.18 quartets to around 5 per cent for the op.59 group
and then to under 2 per cent for opp.74 & 95.
But once Beethoven had gone totally deaf,
the percentage of high notes increased,
rising to just under 4 per cent in the opp.127-135 quartets

There is another open source project that specializes in this sort of thing, and it is called music21. It's a programming language, not an application with a GUI etc, but it's a language that would make it trivially simple to write a program to count middle C's or whatever you like. It can load MusicXML files created with MuseScore.

In reply to by Marc Sabatella

The main issue would be that if we provide for example the number of notes per pitches in the core of MuseScore. Then we will have another request to show frequencies. Then distribution of note duration, then the noteduration vs the pitches, the number of dynamics, the number of piano dynamics, and so on an so forth.
Everything is possible of course but it's probably better suited for a plugin that anyone can change or indeed something like Music21.

There used to be a plugin for MuseScore 1.3 here https://musescore.org/en/project/scorestats but it hasn't been ported to 2.0.

Another way to count notes would be to save your file as MSCX and use a text editor or command line tool to get the number of occurrences of each note within the file.

Here is how MuseScore stores a Middle C in an MSCX file:

   <pitch>60</pitch> #indicates the note has MIDI pitch 60. See pitch.
   <tpc>14</tpc>     #indicates the note is a C natural. See tonal pitch class.

To count the number of Middle Cs in a file:

Via a text editor

Open the MSCX file in a text editor and use the Find function (Ctrl+F) to count the number of times the above strings occur immediately after each other. Notepad++ can find and count regular expressions:

<pitch>60</pitch>[\n \t]*<tpc>14</tpc>

Via the Command Line (Mac or Linux only)

On Mac and Linux you can do it via the Terminal:

< filename.mscx tr '\n' ' ' | grep -o "<pitch>60</pitch> *<tpc>14</tpc>" | wc -l

Variations:

Alternatively, if you want to count the notes but don't care about which octave they are in:

# Get the number of C naturals (any octave)

Text editor: <tpc>14</tpc>

Terminal: grep -c "<tpc>14</tpc>" filename.mscx

Or if you want to count the audible pitches and don't care about the enharmonics:

# Get the number of Middle Cs and enharmonic equivalents B#, Dbb

Text editor: <pitch>60</pitch>

Terminal: grep -c "<pitch>60</pitch>" filename.mscx

Instead of using a text editor you could use a spreadsheet with the "COUNTIF" or equivalent function. This would work for frequency (search and count for pitch>69, pitch>70 etc.) and for duration, accidentals and for a lot of other things if you'd like to look for them.

But, others are already working on this in terms of analysis of MusicXML files and MIDI files so why re-invent the wheel?

In reply to by macrobbair

Using the command line method to get the data and then passing it to another command line tool such as Gnuplot, or by using underquark's spreadsheet method, you could display the results any way you wanted.

You could, for example, draw an ordinary bar chart, hide the axes and labels if necessary, and then insert an image of a piano keyboard just below the x-axis.

In reply to by shoogle

I have no idea how to use these, I tried looking to see if I had gnuplot and it seems just some libraries; I looked for underquark and came up with nothing on either synaptic or the mint package manager. Is it a matter of installing some new software and then trying to work out how to use it?

In reply to by macrobbair

Gnuplot is a program as well as a library, but it runs in the terminal. This has the advantage that you can write a script to interpret a score and draw a graph, and then that same script would work for any score. There are lots of tutorials for how to do this, it's not hard but it can take a while to get the hang of so you might prefer the spreadsheet method.

Underquark is another user on these forums who commented above. Underquark suggested using the COUNTIF function built into ordinary spreadsheet software such as MS Excel or LibreOffice Calc.

Spreadsheet method:

Note: These calculations can take a while for long scores, so I suggest you test it with a very short one first. Use a score that contains less than 10 notes in total, then try it with a normal length score one you have got it working.

Save your score as a MSCX file and then open it with LibreOffice Calc (change the separater to "Fixed Width" in the import dialog). All of the file data will be in Column A of the spreadsheet. You need to copy the following formulas in column B and C to get the note statistics:

B C D
Lines in file: =1048576-COUNTBLANK($A$1:$A$1048576)
 
Note: Tonal Pitch Class: Occurrences in score:
Fbb -1 =COUNTIF(INDIRECT("A1:A"&$D$1),".*<tpc>"&C4&"</tpc>")
Cbb 0 =COUNTIF(INDIRECT("A1:A"&$D$1),".*<tpc>"&C5&"</tpc>")
Gbb 1 =COUNTIF(INDIRECT("A1:A"&$D$1),".*<tpc>"&C6&"</tpc>")
Dbb 2 =COUNTIF(INDIRECT("A1:A"&$D$1),".*<tpc>"&C7&"</tpc>")
Use the select and corner-drag feature to extend the formulas all the way down to row 38 to cover all of the 33 Tonal Pitch Classes (you will need change the note letters manually).
B## 33 =COUNTIF(INDIRECT("A1:A"&$D$1),".*<tpc>"&C38&"</tpc>")

Once the frequency data is calculated you can make a graph of Occurrences against Tonal Pitch Class, or Occurrences against Note Name. However, every time you make a change to the spreadsheet all of those values will recalculate, so it is best to replace the formulas with the actual results before you do anything else. To do this, select all of the results, copy them and then paste them back over themselves using Edit -> Paste Special -> Values Only.

Gnuplot method:

To install Gnuplot, open a Terminal and type these commands:
(Note: these are the commands for Ubuntu, the commands for Mint are usually the same but they might be a bit different in places. Pay attention to any messages you get on screen.)

sudo apt-get update #this updates your list of packages
sudo apt-get install gnuplot #this installs gnuplot
gnuplot #this launches gnuplot inside the Terminal

#Lets make sure gnuplot is setup correctly
gnuplot> plot sin(x) #this is a test. A new window should appear with a graph.

#if the graph was not drawn, you may need to install another package
gnuplot> quit
sudo apt-get install gnuplot-qt #installs the output package

#now try the test again. If it fails again try installing a different output package:
sudo apt-get install gnuplot-x11

Once you have got Gnuplot to draw a basic graph you can start reading up on how to read data in from a file. You could then write a bash script to parse the MSCX file to get the note statistics (using the grep commands I wrote in the previous post) output these to a text file. You then write a Gnuplot script to read in the new text file and draw a graph. It should also also possible to combine the Gnuplot script into the bash script, but that can be a bit tricky.

Do you still have an unanswered question? Please log in first to post your question.