Skip to content
Farshad Jafari edited this page Jul 8, 2026 · 1 revision

Generating melodies

This app generates new melodies using an IDyOM model trained on a dataset. A composition in the dataset is selected as a base sequence, the remaining compositions are used for training, and new notes are sampled so that the resulting melody is probable under the model.

The top-level function is generation:idyom-generation. It has four required arguments. These are positional arguments and should be supplied in the following order:

  • dataset-id: the dataset containing the training material
  • base-id: the composition id of the base melody used in generation
  • basic-attributes: a list of basic attributes to generate
  • attributes: a list of viewpoints used in prediction

The generation method is controlled by the :method parameter. The current options are:

  • :metropolis: use Metropolis-Hastings sampling to alter notes in the base melody
  • :gibbs: use Gibbs sampling
  • :random: generate a melody by sampling directly from the predictive distributions

Useful optional parameters are:

  • models: the model configuration to use (default :both+)
  • method: the generation method (default :metropolis); use :gibbs for Gibbs sampling or :random for direct sampling from the predictive distributions
  • context-length: the number of initial events to preserve; if nil, the method's default behaviour is used
  • iterations: the number of sampling iterations
  • events: for Metropolis sampling, stop when the specified proportion of events has changed
  • position: for Metropolis sampling, choose events :forward, :backward or :random
  • pretraining-ids: additional datasets used for pretraining
  • random-state: a random state for replicable output
  • threshold: restrict sampling to events above a given probability threshold; if :max is used, the most probable event is always chosen; if nil (the default), the full distribution is used
  • use-ltms-cache?: whether to reuse cached long-term models; the default is t
  • output-path: if supplied, export the generated melody as a MIDI file; if nil, return the generated sequence
  • output-filename: the filename to use when exporting MIDI

If output-path is nil, the function returns the generated sequence. Otherwise it writes a MIDI file.

The following is an example:

This uses dataset 0, takes composition 0 as the base melody, generates the basic attribute cpitch, and predicts it using the source viewpoints cpintfref and cpint. The method is Metropolis-Hastings sampling with 100 iterations.

CL-USER> (generation:idyom-generation 0 0 '(cpitch) '(cpintfref cpint)
                                      :method :metropolis :iterations 100)

The following example writes the generated melody to a MIDI file:

This uses the same dataset, base composition and viewpoints, but switches to the :random method and writes the resulting melody as idyom-generation.mid in /tmp/.

CL-USER> (generation:idyom-generation 0 0 '(cpitch) '(cpintfref cpint)
                                      :method :random :output-path "/tmp/"
                                      :output-filename "idyom-generation.mid")

Clone this wiki locally