GraphTunes - making music with Markov chains
The idea of modeling music with a Markov chain grew out of twin motivations to create a composing program that leverages common UI metaphors from drawing applications and a desire to avoid the proto-typical linear playback of traditional composing software. The Markov Chain model is particularly interesting because it allows users to impose as little or as much structure on the composition as they wish.
What is it?
The software allows users to draw nodes and directed edges (lines connecting nodes) on the canvas. Each node corresponds to a note of music. Nodes have the following properties:
- Length - how long the pitch will be played (in milliseconds)
- Transition Time - how long to wait before playing the next note (in milliseconds)
Nodes can have an unlimited number of outgoing or incoming edges. Each edge has a probability that it will be selected as the transition during graph traversal. The edge probabilities are constrained so that the probabilities of all outgoing edges from a node sum to 1.
The user "plays" the graph by placing walkers on different nodes of the graph. Walkers traverse the graph by randomly choosing which edges to follow according to their probabilities. Each time a walker hits a new node, a note is played. The walker will take Transition Time milliseconds to reach the next node in the graph. If a node has no outgoing edges, the walker dies.
The application has 4 modes for editing, manipulating, and playing the graph. Each mode has different capabilities:
- Selection mode - allows the user to move node and delete nodes or edges
- Node Drawing mode - allows the user to add nodes to the canvas
- Edge Drawing mode - allows the user to add edges to the canvas
- Playback mode - allows the user to add walkers to the graph
To enter Node Drawing mode, click on the Pen icon in the toolbar. (Alternatively, press Ctrl+N or 2.) Click anywhere on the canvas to create a new node.
To enter Edge Drawing mode, click on the Arrow icon in the toolbar. (Alternatively, press Ctrl+E or 3.) Click on a node, drag the mouse, and release on another node to create an edge from the first node to the second.
Moving or deleting nodes
To enter Selection mode, click on the Move icon in the toolbar. (Alternatively, press Ctrl+S or 1.) Click on a node to select it, and press Backspace, Delete or D to remove it. Click and drag the node to move it.
To enter Selection mode, click on the Move icon in the toolbar. (Alternatively, press Ctrl+S or 1.) Click on an edge to select it, and press Backspace, Delete or D to remove it.
View/Edit node properties
To enter Selection mode, click on the Move icon in the toolbar. (Alternatively, press Ctrl+S or 1.) Click on a node to select it. You can change the node properties in the "Node properties" window and press the "Apply" button to apply your edits. Alternatively, when a node is selected:
- Press the Up or Down keys to increase/decrease pitch.
- Ctrl+Up or Ctrl+Down increases/decreases length by 50ms.
- Shift+Up or Shift+Down increase/decreases transition time by 50ms
View/Edit edge properties
To enter Selection mode, click on the Move icon in the toolbar. (Alternatively, press Ctrl+S or 1.) Select an edge on the graph, and the source node will be displayed in the Node Properties window. You can edit this edge's probability by:
- Changing its probability value in the Node Properties window. Note that whenever "Apply" is clicked, the edge probabilitities are scaled by 1 / sum(probabilities) so that they sum to 1.
- Pressing the Up or Down keys when the edge is selected. This will increase/decrease the probability by .05, and automatically adjusts the probabilities of other edges leaving the source node.
Click on the Play icon in the toolbar to enter Playback mode . (Alternatively, press Ctrl+P or 4.) Click on any node on the graph to add a walker to the graph at that node. Now sit back and enjoy your composition, or lean forward and continue tweaking your graph!
The source code can be downloaded here. It was built on 32-bit Ubuntu linux using the Alsa sound library, stlport, fluidsynth, RtAudio and Qt. The RtAudio library is included in the source zip, and the rest is dynamically linked.
You can email me at crystal (dot) lemire (at) cs (dot) stanford (dot) edu.