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 \

  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.


-c 1,3

Disregards all channels in the input data except for channels 1 and 3

-n 400

Generate 400 notes of output. The default is 300.

-p 40

The output is given the patch number 40. The default is 82.

-q 5

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.

-r nicerhythms.mid
-r '| midisox nicerhythms.mid - tempo 1.6'

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.


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


  20180226 1.1 produces midi output on stdout
  20180222 1.0 first prototype version


  Peter J Billam,   www.pjb.com.au/comp/contact.html