Code copied across from glockenspiel project.