MIXMIDI USER'S MANUAL NAME mm - mix or manipulate symbolic musical data SYNOPSIS mm [-opt] [input2.mid] ... DESCRIPTION MIXMIDI reads one or more MIDI files, combines them, and writes the resulting MIDI file. It may be used to average over several takes of the same tune, or to reconcile differing arrangements of a tune. It may be deliberately misused to create mashups of tunes of no relation to each other. The last MIDI file specified is for the output, which must not already exist. MIXMIDI never overwrites existing files. EXAMPLES mm song1.mid song2.mid result.mid Mixes song1.mid with song2.mid, and writes result.mid OVERVIEW MIXMIDI treats the input as a list of events, and decides which events correspond by the method of data clustering. This can be a time-consuming operation. Processing a single verse is more satisfactory than an entire song; symphonies are out of the question. Each track of each file is considered entirely separately. That is, events on track 5 of the first file will only be mixed with events on track 5 of the second, third, etc. input files. MIXMIDI is intended to supplement, not replace, ordinary MIDI editing programs. Another MIDI editor will be necessary to prepare the files for mixing. This preparation will include: Transposing tunes to the same key Adding or removing silence at the beginning Adding or removing repeats to get the same song structure MODES OF OPERATION In addition to mixing, several other operations on MIDI files are available. These differ in if they act on multiple input files, or on a single file. Single file operations are: ------------------------------------- PASS THRU () Reads input to output. This will remove non-conforming MIDI events, and can correct errors caused by tracks that have junk data at the end. Example: mm input.mid output.mid ALIGN. (option -A) The user has added a track marking the beat. The times of all events are adjusted, to make this beat perfectly steady. SEPARATE CHANNELS. (option -C) Events are moved to different tracks according to their channel. Channel 1 is placed on track 2, channel 2 is placed on track 3, and so on. Track 1 is reserved for tempo changes and metadata. DETECT KEY. (option -K) Writes an output file in which the previous key changes have been replaced by detected key changes. LENGTHY ANALYSIS. (option -L) Estimates the voice assignments, meter, and chord changes, and writes a piano-roll style view of the piece. (See below) VOICE SEPARATION (option -P) Estimates the voice assignments (for example, Soprano, Alto, Tenor, Bass) on tracks with simultaneous notes. The notes are moved to as many additional tracks as are required to separate them. QUANTIZE. (option -Q) Events are moved in time to their nearest beat at the detected high-frequency tempo. This is typically the nearest eighth note. STEADY BEAT. (option -S) Events are moved in time so that the detected beat is perfectly steady. DETECT TEMPOS. (option -T) Mark the file with the tempo changes that have been detected. Notice that this is quite different from option -S. Option -T draws bar lines to fit the performed notes, and does not change the time of any event. Option -S moves the notes to fit a regular grid! FAKE-O VELOCITY. (option -V) Enhances the dynamic contrast by adjusting note velocities. The adjustments are proportional to a calculated "melodic salience" which is probably better nothing, but it won't replace a good original performance. DISUNION. (option -W) Undoes option -U, splitting each track into a separate file. The names of the output files are not adjustable. They are always called trk00001.mid, trk00002.mid, and so on. If these files already exist, the operation will fail. ZERO. (option -Z) Moves all events to the first track and writes a type-0 MIDI file. This operation can usually be undone with option -C, if the tracks are identified with channels. Nothing is done to ensure this, however. If multiple tracks have the same channel, the resulting type-0 file cannot be exactly separated. (but see option -P) Multiple file operations are: ----------------------------------- INTERSECTION. (option -I) Intersection is like a mix operation, but the only events in the output are those in which a matching event was present in every input file. RID. (option -R) This is a mix operation, but one or more of the input files are to be removed. The name of each file to be removed must be preceded with -R on the command line. Then, each event in the output is included if it does not contain a matching event from one of the files to be removed. UNION. (option -U) Takes several input files and stacks the tracks into a single file that contains all of them. MUTUAL EXCLUSION. (option -X) Mutual exclusion is like a mix operation, but the only events in the output are those in which a matching event was present in exactly one input file. THE GENETIC ALGORITHM For evolution, all that is needed is variety, heredity, and selection. The clustering algorithm provides a means of heredity, and it draws many random numbers which provide ample variety. Some music analysis routines are included to provide selection. The genetic algorithm is an extremely time-consuming operation, which will soak up all the computer power you care to throw at it. There is no guarantee, either, that after waiting say, a month, that the result will be worth anything. The greatest shortcoming is probably in the music analysis routines, which were written with speed in mind as opposed to the best quality. PROGRAM POLYPH aka MELISMA2 A better music analysis program has been written by Dr. David Temperley and is distributed for research purposes. MIXMIDI can call polyph either to print its analysis, or as input to the genetic algorithm. Please observe: 1. This makes the genetic algorithm even slower. 2. Program polyph is NOT in the public domain, and is not licensed for commercial or recreational use. The MIXMIDI package does not contain polyph or depend on it. This feature is enabled only by editing the source code. META AND SYSEX EVENTS MIXMIDI takes some care to preserve meta and System Exclusive events. It does not alter them, but eliminates duplicates. In particular, copyright notices are left in place. OPTIONS -A Align times to click track. Which track must be specified by a number following the A, like: mm -A13 input.mid output.mid if the clicks are on track 13. Any kind of channel event may be used for the clicks, such as notes, or any controller. Marker events may be used also. Other types of meta events are ignored, because many editing programs insert them automatically. -B All files begin at time 0. If they don't begin at time 0, make them begin at time zero. You could do this in a MIDI editing program, but if this is the only change you need to make, it's a lot faster to specify it on the command line. -C Move events to tracks according to their channel. Schedule events and ordinary events are handled differently. Schedule events (tempo, SMPTE offset, time signature, and key signature) are moved to track 1. Ordinary channel events are moved to a track number one greater than their channel number, so that channel 1 is on track 2, and so on, out to track 17. -D Specify drum channels. Events on channels marked as drums will be omitted from chord and key finding, and will receive extra emphasis in rhythm detection. If option -D is omitted, channel 10 is assumed to be the drum channel. Multiple drum channels may be declared, like: mm -D10 -D11 input1.mid input2.mid output.mid to have drums on both channels 10 and 11. Alternatively, option -D may be specified without a number, like: mm -D input1.mid input2.mid output.mid to have no drum channel at all. -E Mix by expectation maximization method. After the usual k-means clustering pass, run the expectation maximization algorithm. This is many times slower, but tends to give better results. -F Scale times so files finish together. This will work only if the times of each event in the input files are proportional. Usually, things are not so simple, and files of differing lengths have a differing song structure as well. To get reasonable results, they must be made to agree by hand-editing before running MIXMIDI. -G Run genetic algorithm. The number of generations must be given, like: mm -G1000 input1.mid input2.mid output.mid To go 1000 generations. Or, if you have a config file you would like to use: mm -G1000 some.cfg input1.mid input2.mid output.mid The last file name is for output. Aside from that, the order is not important. -H Use alternative initial clusters. This is an optional option. Try it and see if you get better results. The difference is small. -I Mix, yield the intersection of input. -J Jitter the input. This changes note events, adding or subtracting a small random value from their times, velocities, and durations. There is a small probability of changing the pitch of each note by a few semitones. I don't know why you would want to do this. It has been implemented because it is the "mutate" step of the genetic algorithm. Try it if you like. -K Detect key signatures. The automatic key detection is better than throwing darts, but that's about it. Do not depend on this answer. -L Long form output. (See below) Option -L may be used to view the analysis of a MIDI without writing an output file, like: mm -L solo.mid -M Mix using meter information. This is good to do if the meter in the MIDI file is correct. Often, files are recorded without a metronome and the performer is content to "let the bar lines fall where they may." If a file does not have meter indicated correctly, you may attempt to detect it with option -T, or mark the beats one by one and use drastic option -A. -N Permit overlapping notes. MIXMIDI assumes that a certain note on a certain channel can be sounded in a single instance, and that the note must be turned off before it can be turned on again. Enforcing this assumption causes MIXMIDI to tamper perhaps needlessly with its input. Option -N conflicts with mixing and conflicts with analysis, and so it can only be used for pass thru, union, disunion, and zero operations. -O Use the mean instead of the median for averaging events. This is an optional option; try it and see how you like it. -P Separate input by counterpoint analysis. So that: mm -P choir.mid satb.mid will move each part onto its own track. -Q Quantize. Changes the times of each event to a position on the detected metrical grid. This is not the same as the declared grid given by the tempo events in the file. The results may be better or worse, depending on how well the detection worked. -R Mix, omit data from specified file(s). This allows you to subtract MIDI music, like: mm input1.mid input2.mid -R omit.mid output.mid This mixes files input1.mid, input2.mid, and omit.mid, then discards all the mixed events that contain an event that originated from omit.mid, writing the results to output.mid -S Force steady tempo. This first estimates a metrical position for every event, then changes the times of all events so that they occupy the same metrical position in a new, constant tempo. The results will be better or worse depending on how well the meter was detected. -T Detect tempo changes. This estimates a metrical position for every event, then creates a set of tempo changes so that their metrical position indicated in the file agrees with their times. -U Combine tracks into one file, as: mm -U input1.mid input2.mid input3.mid total.mid -V Enhance velocity. Velocity of each note event is adjusted in proportion with its melodic salience. This is good for livening up score transcriptions that have no velocity contrast. -W Separate tracks to files, for example: mm -W input.mid will create the files trk00001.mid, trk00002.mid, etc. -X Mix, yield mutual exclusion of input. -Y Mix, with a user-specified yield fraction. Mixing is done separately for each track, and each kind of event (notes, pitch bend, reverb, etc.) By default, the starting value for the number of output events for each track and kind is the median of the count of this kind of event on this track among all the file. Option -Y overrides this default and sets a fraction of input events for a target of the number of output events. This is only a target, because enough memory is allocated only for the greatest number of events in any of the input files, and because the data clustering subroutines can change this number as they find proper. The letter Y must be followed by a number which is interpreted as if it had a leading decimal point. So to form about 1/3 as many events as the total events (per track, per kind) instead of 1/2 as many, use: mm -Y333 input1.mid input2.mid output.mid -Z Combine tracks into a type-0 file. All events are moved to track 1. mm -Z type1.mid type0.mid This can be useful if you want to mix events that are on different tracks. The speed of the clustering algorithm deteriorates badly with increasing size of the input, so keep things separate until you know you want to join them. -$ Extract configuration data from files. A filename ending in .cfg must be specified for the result. This file must not already exist, so for example: mm -$ input1.mid input2.mid input3.mid something.cfg will create a new config file that may be used to influence future analyses. Config files do not have an effect on mixing. Specifically, the config file collects statistics on the frequencies of pitches, chords, average tempo, and tempo changes. They have an effect on key finding, tempo finding with -S or -T, and on the genetic algorithm. Since the estimation of some of these quantities depends on an analysis which in turn depends on these very values, it is possible and useful to specify a config file and extract a config file in the same run, like: mm -$ old.cfg input1.mid input2.mid input3.mid new.cfg Analysis is much faster than mixing, and it will be advantageous to base the config file on a much larger collection than three files as shown here. -? Show summary of what the options do. Options are not case-sensitive. FILES Config files for MIXMIDI are optional. The configuration file contains probabilities estimated from a collection of MIDI files that are LABELED WITH THE CORRECT KEY SIGNATURES. All these probabilities have default values that are hard-coded into the program. They have an effect on the fitness rating of a sequence, when option -G is used, and have an effect in estimating keys and rhythms, when options -K, -S, or -T are used. PIANO ROLL OUTPUT Specifying option -L produces a piano-roll style text output. Left to right: is time in seconds, a representation of meter at 3 levels, an 88-note view of what notes are sounding, chords, and key changes. The number at the beginning of a note indicates what stream it has been assigned. The various punctuation marks : | + * # indicate velocity, with more strokes in the punctuation mark for louder notes. Next are the detected chords, and the key changes indicated in the file, unless option -K has been specified, in which case they are the detected key changes. As an example: MIXMIDI version 5 Nov 2017 ________________________________ analysis of stranger_on_the_shore_gr.mid ________________________________ 166.145 ///// \\\\\\ 166.110 | /// --------- : 166.075 | // ////// : 166.040 \ | : 149.275 ////// -------- * + + + + 149.240 /// /// * + + + + 149.205 | | * + + + + 149.170 | \\\\ * + + + + 149.135 \ | --------- * + + + + 149.100 \\ \\\ /////// * * * * + 149.065 \\\ \\\\\\ // * + 149.030 \\\ -------- * + 148.995 \\\\ --------- \\\\\ * + 148.960 \\\\\ -------- --------- * + 148.925 \\\\\ ///// ////// * + 148.890 \\\\\\ /// | * + 148.855 \\\\\\\ | | * + + 148.820 \\\\\\\ \\\\\\ * + + 148.785 -------- | --------- * + + 148.750 -------- \\\ ///// * + + * + + + + 148.715 --------- \\\\\\ | ++ * + + + + * + + + + 148.680 --------- -------- | ++ * + + + + * * + + + 148.645 --------- --------- \\\\\\\ 00 * 0 0 9 0 * + * + + G9 148.610 --------- -------- --------- + + + 148.575 --------- ////// ///// * + + Dm6 148.540 --------- /// + + 148.505 --------- | \\ + + 148.470 -------- \\\\\\\ + + + 148.435 -------- \\ --------- + + + 148.400 /////// \\\\ //// 0 0 + + 148.365 /////// \\\\\\\ + + 148.330 ////// -------- \\ * + + 148.295 ///// --------- -------- * + + 148.260 //// -------- -------- * + + 148.225 //// ////// /// * + + 148.190 /// /// * + + 148.155 // | \\\\ * + + + 148.120 // --------- * + + + 148.085 | | /////// * + + + 148.050 | \\\ // * + + + * + + 148.015 \\\\\\ + + * + + + + + + + 0.175 --------- -------- 0.140 --------- /// 0.105 --------- | 0.070 --------- \\\ \\\\ 0.035 --------- \\\\\ --------- 0.000 --------- \\\\\\\ /////// Bb Bb Major harmonic probability: -810.601746 rhythmic probability: -11633.7666 melodic probability: -34977.6602 affinity probabililty: -6021.30420 weighted score: -50311.4453 The score is the program's rating of the sequence based on some fairly tentative models. It should not be taken to literally. In particular, the affinity rating is not a real probability at all. For historical accuracy, the piano roll must be read from bottom to top. CONFORMING TO Intended to support all events described in "The Complete MIDI 1.0 Detailed Specification" The MIDI Manufacturers Association La Habra, California www.midi.org and also the new events: RPN 05, 3D controllers, XMF patch type, and hi-res velocity. SEE ALSO midicsv, csvmidi, mf2t, t2mf, timidity, fluidsynth "Music and Probability" David Temperley MIT Press, 2007 Further references are given in the source code. HISTORY 2017 - initial public release 2011 - earliest original code