Humdrum Extras

voicecount manpage


    voicecount -- Calculate the number of active voices at any moment in a score.


    voicecount [-a|-p[[--12|--40|-7[-u|-c][input(s)[> output]


-a Append analysis spine as last spine on line of input data.
-c Calculate number of pitch classes in each sonority instead of pitches.
-G Ignore grace notes.
-k Count the number of **kern spines in the data.
-m Sum analysis results by measure.
-M Prefix -m data with the duration of the measure.
-n Count individual notes rather than voices.
-p Prepend analysis spine as first spine on line of input data.
-s Count number of spines rather than fields (subspines).
-u Count unique note numbers (for -7/--12/--40 without -c option).
-v Process only valid segment containing all parts.
-x Only count note attacks.
-y Display duration-weighted frequencies of voice/pitch counts.
-7 Calculate number of base-7 (diatonic) pitches in each sonority.
--12 Calculate number of twelve-tone pitches in each sonority.
--40 Calculate number of base-40 (chromatic) pitches in each sonority.


    The voicecount program counts the number of voices which are currently sounding at any moment in a score. If any voice is resting at the analysis time, it will not be counted. Here is a simple example showing a four-part score with staggered entries.

    voicecount input

    Each line of output analysis corresponds to a line from the input musical score. In this case the first line of data contains only one note (4c) in the first spine. On the second line two voices are sounding, 4d in the first spine and 4c in the third spine. And so on.

    The -a option can be used to append the analysis results as a spine on the far right of the input data, or -p can be used to prepend the analysis spine before the first spine of input data.

    voicecount -a
    voicecount -p

    Spines vs. Fields

    By default the voicecount program will count the number of active voices in all **kern data fields on a line. If a spine splits into two subspines, these will be considered as separate voices when counting.

    voicecount -a

    The -s option is used to treat sub-spines in multiple data fields as a single unit. If a spine is split into two with two sounding notes in different subspines, it will still be counted as only one "voice". This is useful when counting activity by instruments which can have polyphonic lines, such as parts in a string quartet.

    voicecount -as

    Counting by note

    The voicecount program can also be used to count the number of notes sounding at the same time when the -n option is given. When counting pitches, all notes in a voice will be considered (such as in chords, or in subspines). In the following example there is only one voice, but that voice contains multiple notes played in chords.

    voicecount -a input | voicecount -na

    Counting unique pitches

    The -u option can be used to count all unique notes, ignoring any pitch in any voice which has already been counted. The -n is implied when counting unique pitches, so it does not have to be given as well. Pitches can be counted diatonically with the -7 option (where C4, C♯4, and C♭4 all count as the same pitch); as twelve-tone pitches with the --12 option (C♭4 and B♮3 are considered the same pitch); and diatonic pitches with chromatic inflection up to two sharps/flats with the --40 option. If no pitch model is given for counting unique notes, then --40 will be used, which keeps tracks of diatonic notes with up to two chromatic accidental alteration.

    voicecount --12 -up input | voicecount --40 -up | voicecount -7 -up

    Counting by pitch class

    Use the -c option to count unique pitch classes in each vertical sonority. This option should be given along with one of the options -7, --12, or --40; otherwise --40 will be inferred (chromatic pitches with up to double sharps/flats).

    voicecount --12 -c input

    Counting note attacks

    The -x option can be used to only count note attacks on each data line. All sustained notes on the line will be ignored.

    The -m option can be used to sum analysis lines by measure. The barlines in the input data must contain measure numbers at the start of each measure to be counted. Unnumbered barlines will be ignored and subsequent data will be considered part of the preceding measure. The -m option is mostly only useful for counting notes within a measure and will not count the number of voices or pitch classes with in a measure in a useful manner.

    The -M option can be used to prefix the duration of the measure before the count for each measure.

    voicecount -axn | voicecount -axnm | voicecount -axnmM

    **kern spine count

    Using the -k option will output a count of the total number of **kern spines in the file (which start at the top of the data). This is useful for searching for files with a specific number of voices or for determining the maximum voice count possible when using the -s option.

    voicecount -k h://chorales/chor001.krn

    Multiple segments will be listed separately. Here is an example which counts the number of voices in 370 Bach 4-part chorales. The grep command removes the file segment names which are generated automatically when there is more than one segment of data input.

    voicecount -k h://370chorales | grep -v ! | sortcount

    Duration-weighted voice/pitch counts

    The -y (or --summary) option can be used to output a data table showing how often the musical texture is in a particular voice or pitch count.

    For example, here are statistics for 370 Bach chorales:

    voicecount -y h://370chorales
    The analysis results indicate that there are five states for voice counts in the musical texture of the Bach chorales. A Voice count of zero means that all voices are resting. A voice count of 1 indicates a single pitch was sounding; 2 indicates two notes voices were active, and so on. The most common texture is four parts, which occurs 98.89% of the time. The total duration of all music being analyzed is 19,813 quarter notes in the 370 chorales. The duration-weighted average number of active voices is 3.96.

    The -c option can be used with -y to summarize the duration-weighted average number of pitch classes at all moments in the music. As demonstrated below, the average number of duration-weighted pitch class sonorities is 3.19, i.e. typically a triad (with triads typically occurring 72% of the time). 25% of the sonorities contain 4 pitch-classes sounding together—either as seventh chords or as non-harmonic tones.

    voicecount -yc h://370chorales

    Segment filtering

    The -v option can be used to filter out musical segments which have an incomplete number of voices. If a file segment contains a record in the form:
        !!!voices: 4
        !!voices: 4
    then the number of **kern spines in the file must be 4; otherwise, the segment will be skipped over when performing the voicecount analysis.

    Compare a summary analysis of voice counts for the music of Josquin when counting all works including incomplete works with missing parts, and an analysis which removes files which have missing parts.

    Including pieces with missing parts:

    voicecount -y h://jrp/Jos
    Removing pieces with missing parts:

    voicecount -yv h://jrp/Jos

    The duration-weighted average number of voices in all of Josquin's music changes to 3.30 from 3.25 when works with missing parts are removed from the summary analysis.

    Other options

    The -G option can be used to ignore grace notes in a score. Not that duration-weighted summaries automatically ignore grace notes since they have zero score duration.

    voicecount -G
    voicecount -n
    voicecount -nG

    Exclusive interpretations generated by voicecount

    **v#voice count.
    **p#pitch/note count.
    **up#unique pitch count. (same as **40up#).
    **7up#Base-7 unique pitch count (diatonic pitches). For example C♯ and D♭ are different, but C and C♯ are the same..
    **7pc#Base-7 pitch-classes present in the sonority.
    **12up#Base-12 unique pitch count (diatonic pitches). For example, C♯ and D♭ are the same base-12 pitch and will only be counted once.
    **12pc#Base-12 pitches present in the sonority.
    **40up#Base-40 unique pitches. C♯4 and D♭4 are different pitches.
    **40pc#Base-40 pitch classes. C♯ and D♭ are different pitch classes.
    **durDuration in quarter notes (output with -y option).
    **pcentRelative frequency in percent (output with -y option).


    Bach chorale 4-voice double pitch simultaneities

    Here is an example use of voicecount to find the occurrences of two pitches shared between four voices in Bach chorales. In other words four voices are singing only two pitches, which means that two (or more) voices are singing the same pitch. The files and measure/beat locations are listed in the right-most column.

    voicecount -a h://370chorales | voicecount -au --12 | location -Qafmb \
              | ditto -p | ridx -H | grep -P "4\t2"

    This situation occurs seven times in 370 Bach chorales. None of the cases involve simultaneous note attacks. Instead two or three notes sustain from a previous sonority (sustained notes are listed above in parentheses). Note that there is one case where the soprano, alto, and tenor all play the same pitch (chorale 56, measure 12, beat 4). This is also the only case where the double simultaneities occur on a beat.

    To generate the final output, the data is passed twice through voicecount: once to count the number of actively singing voices, and a second time to count the number of unique pitches. The location program then appends the file, measure and beat location of the data lines, and ditto is used to resolve null tokens into their sustained notes.

    Enharmonic spellings within a single sonority

    Are there any sonorities in the 370 Bach chorales which contain any twelve-tone pitches that are given two different diatonic/chromatic spellings?

    voicecount -au --12 h://370chorales | voicecount -au --40 \
          | extractx -s '$1-$' | ridx -H | sortcount

    The answer is no, since the last two columns in the above results are always the same number.

    Here is a list of cases in the Beethoven string quartets where enharmonic spelling differences occur. For example the first line in the list below contains a E♭ and D♯ at the same time.

    extractx -i '**kern' h://beethoven/quartets | voicecount -au --12 \
         | voicecount -au --40 | location -QRafmb | dittox -p \
         | grep -P "3\t4|2\t3|4\t5"

    Usually the enharmonic spelling differences occur on off-beats (only two cases occurring on beats).

    Bach chorale harmonic unisons

    Here is an example showing how to count the number of voices which sing on the same pitch as another voice at the same time.

    voicecount h://370chorales -a | voicecount -au --40 \
          | extractx -f '$1-$' | ridx -H | sortcount

    Lines with unequal values in the last two columns indicate unisons between parts. The total number of unisons is: 2309 + 7 * 2 + 3 = 2326.

    Compare the above method of counting harmonic unisons to using the hint command:

    humcat -s h://370chorales | ditto | hint -a | serialize -c \
           | grep "^P1$" | wc -l
    The differnce between the two methods is that one sonority contains a case where three voices are singing the same pitch. The first method counts this as two unisons while the second case counts this as three unisons.

    Bach chorale notes/measure

    Here is an example of how to determine the highest number of note attacks per measure in Bach chorales.

    voicecount -mx h://chorales | ridx -H | sort | uniq -c | sort -nr -k2

    The greatest number of note attacks in a measure is 33 (occurring 3 times), with 20 note attacks/measure (occurring 490 times) being the most common situation.


    Input arguments or piped data which are expected to be Humdrum files can also be web addresses. For example, if a program can process files like this:
           program file.krn
    It can also read the data over the web:
    Piped data works in a somewhat similar manner:
           cat file.krn | program
    is equivalent to a web file using ths form:
           echo | program

    Besides the http:// protocol, there is another special resource indicator prefix called humdrum:// which downloads data from the kernscores website. For example, using the URI humdrum://brandenburg/bwv1046a.krn:

          program humdrum://brandenburg/bwv1046a.krn
    will download the URL:
    Which is found in the Musedata Bach Brandenburg Concerto collection.

    This online-access of Humdrum data can also interface with the classical Humdrum Toolkit commands by using humcat to download the data from the kernscores website. For example, try the command pipeline:

          humcat humdrum://brandenburg/bwv1046a.krn | census -k


    The compiled voicecount program can be downloaded for the following platforms:
    • Linux (i386 processors) (dynamically linked) compiled on 24 Oct 2013.
    • Mac OS X/i386 compiled on 13 Nov 2013.

    The source code for the program was last modified on 24 Oct 2013. Click here to go to the full source-code download page.