Coder Social home page Coder Social logo

music-gen's Introduction

music-gen

Generating Simple Musical Compositions Using Genetic Algorithms.

Usage

Please use either Python 3.11 or pypy3 to run the program for best performance.

pypy3 music-gen.py

All configurable parameters are given to the main MusicGA class constructor:

clen      - composition length
poplen    - population size
mutrate   - mutation rate
targetfit - target fitness

After initializing the GA system, it has to be populated with the given scale as parameter. A valid scale is just an array of integers, representing MIDI note numbers, from which the GA system generates compositions and chooses random notes for mutation.

For example, a single octave of the C Major scale:

C_MAJOR  = [60, 62, 64, 65, 67, 69, 71, 72]

After running the system, the population is evolved until the target fitness is reached. The resulting (best) member of the population is saved into a midi file (currently just named mga_best.mid).

Fitness

The principle behind the current fitness function is to punish for "ugly" notes and patterns and "reward" for nice ones.

For example, "ugly" patterns include:

  • Jumps larger than 7 semitones between two consecutive notes.
  • A single note repeated more than 3 times in a row.
  • Multiple subtonic and supertonic notes.

And some "nice" patterns include:

  • Ending note is the same as the starting note (for easier looping).
  • Three consecutive rising notes (do-re-mi).
  • Three consecutive notes forming a "hat" (do-re-do).
  • Multiple tonic, mediant and dominant notes.

Most of these patterns were chosen almost completely by feeling alone and for this reason they should be reconsidered.

Much more testing is also required to balance out the amount of punishment and reward in each of these cases.

music-gen's People

Contributors

tonysln avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.