Humdrum Extras

time2matlab manpage


    time2matlab -- Convert a **kern score with performance timing into a matlab array.


    The time2matlab command is used to prepare a Humdrum **kern score to be read into numerical analysis software such as octave, FreeMat, or matlab. The Humdrum file should contain **kern data representing the musical score as well as a **time spine which indicates the absolute time at which the notes occur in a performance. Here is a short example score:
    Running the above score through time2matlab will generate the following data:

    Text following a '%' character are comments which will be ignored when reading the data into matlab. The kern data is converted into a matrix (currently) with seven columns. Each row in the matrix represents one note in the score, and the columns contain information about the note:

    1. Start time of the note. In the above example, the timings are intended to be in milliseconds, but you could also use seconds. In any case, the timing values as stored in the score will be used to generate the timing information in the output file, regardless of the time units used.
    2. Duration of the note. This value subtracts the time at which the note ends in the score from the time that the note starts in the score. For example, the 1CC note in the first **kern spine starts at time index 1300 and ends at time index 8000 when a rest starts in that voice. Therefore, the duration of the 1CC note is 8000 - 1300 = 6700.
    3. MIDI note number of the note's pitch.
    4. Metric level of the note: less than zero means the note is on an off-beat (such as the c# on the 5th line of the input, or the third data line in the output for note number 61). A zero or higher in this column means that the note was played on a beat; and a value greater than zero (1) means that the note was played on the first beat of a measure.
    5. Measure number in which the note occurs.
    6. Absolute beat position of the note in reference to the start of the music.
    7. Track number which indicates which data spine in the original data the note belongs. In this case there are two **kern spines: the first spine which contains 1CC is spine 1, and the next one to the right is spine 2. If the score contains piano music, the track number would typically mean that notes in track 1 are played by the left hand and notes in track 2 are played by the right hand. If the input music were an orchestral score, then the track number would indicate the different instruments of the orchestra.

    The output data should be saved to a file ending in the extension .mat. This will allow you to read the data file into octave or matlab using the load command for further analysis in one of those programs. Below is an example of loading the file into octave via a file called output.mat and then displaying the contents of the variable called output which is created to store the data read from that file.

     octave:1> load output
     octave:2> output
     output =
      Columns 1 through 5:
         1.3000e+03    6.7000e+03    3.6000e+01    1.0000e+00    3.0000e+00
         1.3000e+03    4.0000e+02    6.0000e+01    1.0000e+00    3.0000e+00
         1.7000e+03    7.0000e+02    6.1000e+01   -1.0000e+00    3.0000e+00
         2.4000e+03    6.0000e+02    6.2000e+01    0.0000e+00    3.0000e+00
         3.0000e+03    1.0000e+03    6.4000e+01    0.0000e+00    3.0000e+00
         4.0000e+03    4.0000e+03    6.5000e+01    1.0000e+00    3.0000e+00
         8.0000e+03    1.6000e+04    6.7000e+01    0.0000e+00    4.0000e+00
      Columns 6 and 7:
         0.0000e+00    1.0000e+00
         0.0000e+00    2.0000e+00
         5.0000e-01    2.0000e+00
         1.0000e+00    2.0000e+00
         2.0000e+00    2.0000e+00
         3.0000e+00    2.0000e+00
         4.0000e+00    2.0000e+00

    Use of time2matlab in the Mazurka Project

    The output data from time2matlab is intended for use in Andrew Earis's Expression Algorithm program which takes an audio file and a data file containing estimated note positions generated as output from time2matlab. The Expression Algorithm then produces revised notes attack times based on an analysis of the contents of the audio file.

    Example input data files can be found starting from this page. Links on that page point to preliminary performance data. Input files to time2matlab end in the extension .time, such as this one for a performance of Chopin's mazurka in C-sharp minor, Op. 63, No. 3 as performed by Richard Farrell in particular on the recording found on the CD label EMI Phoenixa CDM 7641362. This file contains the score for the mazurka music along with estimated timings of note attacks (not the exact timings of notes) in the performance. The timing data found in the first column of the .time score is ultimately generated from this file which marks the times of beats in the performance in the recording. This beat file was in turn created by tapping to the beats inside of the audio editor program called Sonic Visualiser, and saved as a text-based annotation file.

    Example output data from the Expression Algorithm software is viewable on this webpage.

    Extracting data without performance information

    If you are only interested in durations based on the score rhythms and not from an actual performance of a file, you can use the gettime program to extract score-based timings rather than timings based on a performance.

    gettime -sp input.krn > output.krn
    time2matlab output.krn

    By default, a tempo of 60 beats per minute will be used when extracting timing information. To use a different tempo, you can add tempo information into the file, such as *MM100 for 100 beats per minute:

    gettime -sp input.krn > output.krn
    time2matlab output.krn



    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 time2matlab program can be downloaded for the following platforms:
    • Linux (i386 processors) (dynamically linked) compiled on 28 Jun 2012.
    • Windows compiled on 29 Jun 2012.
    • Mac OS X/i386 compiled on 13 Nov 2013.
    • Mac OS X/PowerPC (version 10.2 and higher) compiled on 13 May 2009.

    The source code for the program was last modified on 13 Dec 2005. Click here to go to the full source-code download page.