When Marbles Falling onto Piano Keys Happen to Play Music

“If you wish to reverse entropy, you must first reinvent the universe” — Carl Sagan (not really)

Prior work

Prerequisite: Inventing the Universe

Method 1: Non-colliding samples

  1. Pick a random initial condition (start position and velocity) above the pegboard for a single marble
  2. Run the simulation until the marble lands on a key
  3. Record the path the marble took
  4. Go to step 1 until you have paths of marbles hitting all the keys you need

Method 2: Sample splicing

  1. Simulate a ball falling through an infinite pegboard, starting from the peg at the origin.
  2. When the ball collides with a peg, remember the offset between the ball and the peg and move the ball back to the peg at the origin with the same offset. It will fall the exact same way because the pegboard is the same no matter where the ball is.
  3. Record the paths of the ball in between collisions and record the offset and exit velocity of each collision. Put this data into the viable path lookup.
the pegboard is the same no matter where the ball is
visualization of the offsets and exit velocities in the viable path lookup
  1. Start with a collision with a peg that results in the ball free-falling (not colliding with anything) and striking the right piano key at the right time,
  2. Pick a viable path that ends with the most similar collision and run backwards until there is a ball-ball collision.
  3. On ball-ball collision, switch both balls into “on-demand” reverse simulation, as in simulate the physics mathematically backwards instead of using a lookup. We can avoid ball-ball collisions from exploding by making the balls have perfectly elastic collisions that conserve energy.
  4. On ball-peg collision where the ball is in “on-demand” reverse simulation, switch to the viable path lookup and pick the closest viable path.
  5. There are conditions where this fails, like when a ball is blocked from going from a piano key to the peg board, in which case pick a different viable path until it works. Otherwise, due to the viable path lookup, we are guaranteed to have the balls eventually go back up.
yellow/white marbles: “on-demand” reverse simulation. other marbles: lookup

Results

classical piano, MIDI from http://www.kunstderfuge.com/chopin.htm
jazz piano, MIDI extracted from https://www.youtube.com/watch?v=ci-sgp3Ul60

Other Details

Physical Modeling Sound Synthesis

top to bottom: ball-peg collisions, ball-ball collisions, ball-floor collisions
made in Bitwig
available as a p5.js sketch

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store