Code Monkey home page Code Monkey logo

music-arithmetic's Introduction

music-arithmetic

Language for describing music compositions in exact frequencies.

Build Status

Dependencies

Examples

This is an example of music arithmetic code. As you see you can just write notes from the equally tempered scale by the usual names.

(
    c (e, g) (f, a) (e, g) (d, f) (c, e) (g/2, (d d) | .5) c
)

The same piece but in pure notation is like this.

261.6 * (
    1 (5/4, 3/2) (4/3, 5/3) (5/4, 3/2) (9/8, 4/3) (1, 5/4) (3/4, (9/8 9/8) | .5) 1
)

One can store this into a file, like example.ma and export it to midi it using the command python3 export_midi.py example.ma example.mid.

To be implemented

  • Convert music21 format to out own format
  • Convert frequencies to vectors

Language description

Numbers can be constructed by the usual expressions. Numbers are frequencies by default. A duration parameter can be specified after a | symbol, which has a low precedence. Parenthesis are not needed for tuples anymore, so they can replace curly brackets.

So we have the rational numbers with the usual operators extended with frequency constants and the operators:

  • * and / (precedence 4)
  • | (duration operator, precedence 3)
  • (serial operator, precedence 2)
  • , (parallel operator, precedence 1)

The advantage of choosing this precedence order is that we can write multiple voices easily.

(
    c g a g f e d   c,
    c e f e d c g/2 c
)

An equivalent way of writing this piece in a chord-by-chord fashion could be as follows.

(
    c (e, g) (f, a) (e, g) (d, f) (c, e) (g/2, (d d) | .5) c
)

Here is a brief motivation why this syntax was chosen. If we swap the precedence order of , and , the parts would look like this.

(
   (c g a g f e (d d) | 1/2 c),
   (c e f e d c g           c) / 2
)
(
    c e, g f, a e, g f, a e, g g/2, (d d) | 1/2 c
)

Although it requires less parenthesis, it is also less readable, because intuitively commas are seperators, more than spaces.

In practice you would place parenthesis around chords and melodies anyway, to specify duration. So in the end it doesn't matter too much.

music-arithmetic's People

Contributors

chtenb avatar

Stargazers

Mattias avatar

Watchers

 avatar Mattias 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.