Generating a drum sequence using Python

We are going to generate a MIDI file from a primer in Python, much like we've done in the previous section.

You can follow this example in the chapter_02_example_01.py file in the source code of this chapter. There are more comments and content in the source code, so you should go check it out.
  1. Let's start by downloading the bundle. There are a lot of useful tools in the magenta.music package, and we'll be using it in many examples:
import osimport magenta.music as mmmm.notebook_utils.download_bundle("drum_kit_rnn.mag", "bundles")bundle = mm.sequence_generator_bundle.read_bundle_file( os.path.join("bundles", "drum_kit_rnn.mag"))
  1. We then use the drums generator to initialize the generator class ...

Get Hands-On Music Generation with Magenta now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.