Coder Social home page Coder Social logo

weiweichen / musicalnumbers Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 24 KB

Musical Numbers - A quest to find out the most musical number in the universe. ๐ŸŽถ๐Ÿ”ข

License: MIT License

Makefile 2.17% Scala 97.83%
folk-music tune-generator

musicalnumbers's Introduction

MusicalNumbers

This is a toy program to entertain the idea of mapping number sequences, such as pi, square roots of numbers, ect. into folk music tunes (i.e. march, jig, reel, etc), or in a more philosophical way, as a quest to find which out the most musical number in the universe.

Let me know ([email protected]) if you have any opinions on the effort or the result of the quest!

Minimum Prerequisite to build and run

  1. jdk (for running java code) https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html

    MacOS: https://www.chrisjmendez.com/2018/10/14/how-to-install-java-on-osx-using-homebrew/

  2. scala-lang (well, since the program is written in Scala) https://www.scala-lang.org/download/

    MacOS: http://sourabhbajaj.com/mac-setup/Scala/README.html

    In case you are not familiar with Scala, Scala is built using Java. Hence the compiled results is a jar file, the same as Java code. Functional programming is really beautiful. You should try it!!

  3. sbt (for building scala program) https://www.scala-sbt.org/index.html

    MacOS: https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Mac.htm0l

Install everything on MacOS (ignore the Spark part): https://medium.freecodecamp.org/installing-scala-and-apache-spark-on-mac-os-837ae57d283f

Scala runs on Java Virtual Machine (JVM), therefore the build/execution environment for this program is platform agnostic. If you use operating systems other than MacOS, install the prerequisites for your platform.

How to build

$ cd MusicalNumbers/
$ sbt assembly

The compiled jar will be target/scala-2.11/MusicalNumbers-assembly-0.0.jar

How to run

$ cd MusicalNumbers/
$ java -jar target/scala-2.11/MusicalNumbers-assembly-0.0.jar \
       -i resources/numbers/the_number_of_pi.txt \
       -t jig -k D -m wrapped -v

Program usage:

$ java -jar target/scala-2.11/MusicalNumbers-assembly-0.0.jar --help 
Musical Numbers 0.0
Usage: MuscialNumbers-X.Y [options]

  -i, --input <value>      Input File Name
  -t, --tunetype <value>   Tune Type, i.e. jig, march, reel
  -k, --key <value>        Tune Key Signature, i.e. C, D, E, F, G, A, B
  -m, --notemapping <value>
                           Note Mapping Strategy, i.e. direct, wrapped
  -r, --rhythmpattern <value>
                           Rhythm Pattern (Support TBD).
  --help                   prints this usage text
  -v, --verbose            verbose is a flag

Program output:

$ java -jar target/scala-2.11/MusicalNumbers-assembly-0.0.jar \
       -i resources/numbers/the_number_of_pi.txt \
       -t jig -k D -m wrapped -v
       
Output File: resources/numbers/the_number_of_pi.abc

X:1
T:The Number Of Pi Jig
M:6/8
L:1/8
R:jig
K:D
DBE BFC|CGF DFB|CAC DCD|BEG CGE|
w: 3 1 4 1 5 9  2 6 5 3 5 8  9 7 9 3 2 3  8 4 6 2 6 4  
DDB DCA|CFA CBB|EBC ABG|CDC CDA:||
w: 3 3 8 3 2 7  9 5 0 2 8 8  4 1 9 7 1 6  9 3 9 9 3 7  
|:FBA FBC|ACA ECE|EFC CDA|ABB GEA|
w: 5 1 0 5 8 2  0 9 7 4 9 4  4 5 9 2 3 0  7 8 1 6 4 0  
GCB GCA|BCC BGC|BAD EBC|FDE CBB:|
w: 6 2 8 6 2 0  8 9 9 8 6 2  8 0 3 4 8 2  5 3 4 2 1 1 

How to check the result

The program outputs the tune in ABC notation: https://en.wikipedia.org/wiki/ABC_notation

There are many free software for converting ABC notation into sheet music, and some can also generate the MIDI file for listening, such as:

MuseScore: https://musescore.org/en/download (with abc import https://musescore.org/en/project/abc-import)

EasyABC: https://sourceforge.net/projects/easyabc/

A full list of software for ABC notation can be found at: http://abcnotation.com/software

Resources:

The program takes a txt file containing the number sequence as input.

Some of the sample numbers are located at resources/numbers/*.txt. The source of the numbers are from https://apod.nasa.gov/htmltest/rjn_dig.html

TODO

  1. It's quite obvious that rhythm is an integral part of a ear-pleasing tune. Hence, the program shall take some rhythm patterns to add some cadence to the tunes.

  2. Support for more tune types such as polka, waltz, strathspey, ect.

  3. Support for chromatic scales instead of diatonic scales only.

  4. Auto generator for number sequences, such as generating first k digits of square root N, square root of an imaginary number?

  5. Use different repetition patterns for digits.

  6. ...

About

Author: Weiwei Chen ([email protected])

Link: http://www.cecs.uci.edu/~weiweic/

musicalnumbers's People

Contributors

weiweichen avatar

Stargazers

 avatar

Watchers

 avatar  avatar

musicalnumbers's Issues

Some concrete ideas from Neil

Neil:

My favourite way to skew an even distribution is to take the log base 2 of n (or 2^n if you want to skew the other way). Which I think is neat because we're dealing with ratios so much.

Rhythm is another pattern to explore. I don't have as much theory on this, maybe make the last note at least a crotchet and insert pseudo-random crotchets throughout the music. I like the idea of working the fibonacci sequence into it but I'm not sure how or whether it would work (since everything else is so based around integer ratios)

The other one is that folk tunes rely heavily on the call-and-response idea. Maybe there's a general way to measure how 'call-and-response'y a tune is and optimise for that. Or it's probably easier to hardcode a pattern where bar 9 is a repeat of bar 1 and bar 13 is a repeat of bar 5 (this is why we should use index 0 everyone, it makes much more sense than index 1!).

Neil's idea for a tune generator

Neil:

But even without resorting to ML, here are some patterns you might be able to exploit in a more logical tune generator:

Some notes appear more than others; in (very) rough order of precedence: root, octave, fifth, fourth, second, seventh, third, sixth. The cool thing is that there are actually many root notes working in a tune at the same time - the root of the key, the root of the phrase (usually the root of the chord that goes with the phrase, and there could be many but the most basic one is usually also related to the key), the previous note... I think you could create some measure of how much a note 'fits' harmonically into the tune based on that and skew your algorithm towards notes that fit. But don't totally exclude the weirder notes; they make it interesting and can twist a phrase into having a different root. The position of the note in the tune also affects how much it needs to fit. The last note of the part is heavily skewed towards either being the root of the key or, occasionally, the fifth (you know those tunes that just never want to stop repeating - they usually end on an unresolved fifth). The end of a four-bar phrase usually also skews more towards a root, octave, fifth or fourth.

The reason behind that is super-interesting, but I can't find any good short explanations (here's a longer but very interesting read: https://arxiv.org/html/1202.4212), You can derive it from the fact that we like frequency multiples of the root note and that our brains are bad at distinguishing octaves (which are ratios of 2:1).

Neural Network for folk tune generator.

Neil: I have a... complex relationship with ML (read: I actively avoid it where possible), but perhaps this is one of the places that a neural net can do better than logic or stats, simply because of the endless self-referential and recursive nature of music. I like the idea of training a network to recognise good patterns of rhythm or harmony and using the deep-dream idea to find what the network believes is the 'best' pattern.

Weiwei: This can a very interesting setup to try out ML, as I likewise have been avoiding it, but since Iโ€™m now working in a ML/AI infrastructure company, I probably should get my hands dirty sooner than later. To train a neural network, weโ€™ll need structured training data, probably some web crawling for abc notations + parsing infrastructures need to be in place first to be able to feed data to the model. Letโ€™s see how will ML perform in doing creative things.

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.