midimarkov - Markov-chain music reconstruction
midimarkov t.mid | aplaymidi - &
muscript -midi bach/opfer/ric6_rec | midimarkov > t2.mid
muscript -midi ~/mus/solosuite/one ~/mus/solosuite/two \
~/mus/solosuite/three | midisox_lua - - pitch -300 \
| midimarkov -p 21 -n 60 -c 1,3,4,7 -r r.mid > t2.mid
# This iteration increases fidelity to a subset of motifs
midimarkov t2.mid | midimarkov | midimarkov > t3.mid
muscript -midi ~/mus/bach/bwv1008 | midimarkov -n 800 > t4.mid
midimarkov -n 400 -p 74 -c 0 \
http://www.pjb.com.au/muscript/samples/folkdance.mid
muscript -midi ~/mus/solosuite/one | midisox_lua - - pitch -1200 \
| midimarkov -n 60 -r "| midisox r.mid - tempo 1.7" > t5.mid
midimarkov is a Lua program which uses a modified Markov algorithm on midi files.
The 'midi file' may also be a pipe (beginning with a
"|" as in sox notation), as in this example:
midimarkov -p 31 -n 60 '| muscript -midi ~/mus/solosuite/one'
It produces its midi output on stdout
It uses the MIDI.lua module, which is available from
www.luarocks.org
It works most reliably on single-line music.
Disregards all channels in the input data except for channels 1 and 3
Sets the Depth of the markov chain -
the number of notes which will be used as the context for
selecting each next note.
See also the
-s and
-S options.
Generate 500 notes of output. The default is 400.
The output is given the patch number 40. The default is 82.
Quantises the durations of the input-file, to the nearest
5 milliseconds in this example.
This makes it easier for the
output-durations to leap around from one section of the input to another -
which may or may not be desirable.
Uses this separate midi file for the rhythm data.
This rhythm file is not read literally;
it is also put through the Markov algorithm.
The rhythm file may also be a pipe (beginning with a "|"
as in sox notation), as in the second example.
Print on stderr some statistics on the lists in which items were found,
in addition to producing the normal midi output on stdout.
For Example:
Pitches:
Here, of the 400 output-notes,
177 of their pitches could be found sharing their previous 4 pitches.
53 were found sharing the previous 3,
65 were found sharing the previous 2, and
105 could only be found sharing the previous note.
found[4]=177 found[3]=53 found[2]=65 found[1]=105
Delta-times:
found[4]=164 found[3]=135 found[2]=86 found[1]=15
In the case of this input-file, there is a good case for increasing the depth
with -d 5 or even -d 6
Print on stderr some statistics on the lists in which items were found. The normal midi output on stdout is suppressed.
Print the Version
Next: perhaps something similar using midialsa.lua with live midi input, perhaps letting input-notes through while adding them to the input-array and remaining silent, and then when the input goes silent, generating a markov continuation of it - something like an uninterruptable solo. This needs the ability to add to the array in real-time.
Investigate the effects of iteration: what does it converge on ? how do varying output-sizes affect it ?
The source is available at www.pjb.com.au/midi/free/midimarkov
The MIDI.lua module is available from
www.luarocks.org
so you should be able to install it by:
luarocks install midi
20180730 1.2 introduces the loops to Arg.depth 20180226 1.1 produces midi output on stdout 20180222 1.0 first prototype version
Peter J Billam, www.pjb.com.au/comp/contact.html
MIDI.lua
luarocks.org/modules/peterbillam
luarocks.org/modules/peterbillam/midi
www.pjb.com.au/midi
www.pjb.com.au/comp/lua/MIDI.html
www.pjb.com.au