Code Monkey home page Code Monkey logo

meldy's Introduction

Meldy - A mood-based melody generator

Meldy is a simple grammar-model melody generator, based on a user-provided mood expressed in the valence-arousal plane. It's developed as project for "Advanced Coding Tools and Methodologies" and "Computer Music: Representations and Models" courses of the MSc in Music and Acoustic Engineering of Politecnico di Milano.

Links

Demo Video

demo video thumbnail

Project Description

overview

The main focus of this project is on the melody generation step.

Mood Selection

User is expected to provide a mood for generating the melody. We adopted the dimensional approach from Music Emotion Recognition [9] to describe moods in a two-dimentional plane, so we have valence (i.e. the positivity of the mood) on the x-axis and arousal (i.e. the intensity of the mood) on the y-axis.

mood picker

The picker is realized using p5.js [4] and the relevant code can be found at /front-end/src/p5/mood_picker_sketch.js.

Melody Generation

Melody is generated starting from valence and arousal values, by producing a MusicXML score for music representation. MusicXML is better suited than other formats (e.g. MIDI), because it's meant for notation representation (rather than playing representation), and can effectively carry harmonical information that would be lost in other formats (e.g. enharmonic equivalence, key signature and scale mode [11]).

At first, a mapping is made between the mood and three main music features: scale mode, tempo and central octave of the melody, as shown in the following figure. This mapping is inspired by MER studies on music features [9].

mood mapping

Then, a grammar method [8] is used to generate the relative degrees (within one octave range) and the duration of each note of the melody. In the current version, we are using a hand-crafted Markov Chain that we empirically built by trial and error. Different rulesets are defined for different "snap"-points of both valence and arousal. These can be found in files /back-end/data/grades.yml and /back-end/data/durations.yml. An example of degree-chain is provided in the following picture, assuming a DO-mobile interpretation (i.e. DO = 1ยฐ degree):

grammar

More details on the rationale of the melody generation can be found in /docs/melody-generation.md.

We employed the music21 [1] library for the actual generation of the melody. The relevant code can be found in the class MelodyGenerator in source file /back-end/src/melody.py. Since this is a Python library, this step is run on a separate back-end providing the following communication with the WebApp:

client-server communication

Score display

grammar

The generated MusicXML is finally rendered on the web page thanks to OpenSheetMusicDisplay [2]. From this view, it's possible to playback the generate score, download it to open with a notation software (e.g. MuseScore) or go back to the mood selection view.

Navigation between views is achieved through DOM replacement of HTML fragments. The relevant code can be found at /front-end/src/navigation.js and inside /front-end/src/views/.

Resources

  1. music21: a toolkit for computer-aided musicology.
  2. OpenSheetMusicDisplay: renders MusicXML sheet music in the browser.
  3. OSMD Audio Player: browser based audio player for MusicXML scores.
  4. p5.js: JavaScript port of Processing.
  5. webpack: a bundler for JavaScript and friends.
  6. Flask: Python micro framework for building web applications.
  7. Pipenv: Python development workflow for humans.

Bibliography

  1. McCormack, J. (1996). Grammar based music composition. Complex systems, 96, 321-336.
  2. Yang, Y. H., & Chen, H. H. (2011). Music emotion recognition. CRC Press.
  3. Cuthbert, M., Ariza, C., Hogue, B., & Oberholtzer, J. W. (2020). Music21 Documentation
  4. Sarti, A. (2019). Computer Music: Representation and Models. Course material of MSc in Music and Acoustic Engineering

ยฉ 2020 Matteo Bernardini & Yilin Zhu

meldy's People

Contributors

dependabot[bot] avatar mttbernardini avatar yilin10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

meldy's Issues

App not working

The application stopped working since I shutdown the back-end on Heroku. I decided not to use Heroku for this project since they don't provide a free-tier anymore and this is a really low-demanding didactic project.

Since the back-end generates the melodies, the application is completely unusable at the moment and will keep showing "Network problem" messages when clicking on the "Impress me" button.

I'm considering to migrate the back-end to one of the following platforms:

  • Deta.sh
  • Fly.io
  • Railway.app

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.