Code Monkey home page Code Monkey logo

musique's Introduction

Musique

Musique is a gem for manipulating with musical constructs, such as notes, chords and intervals.

Installation

$ gem install musique

Usage

Music::Note

note = Music::Note.new("C#1")
note.letter     #=> "C"
note.accidental #=> "#"
note.octave     #=> 1

# Comparison
Music::Note.new("C1")  <  Music::Note.new("E1")  #=> true
Music::Note.new("C#1") == Music::Note.new("Db1") #=> true

# Transposing
major_third = Music::Interval.new(3, :major)
Music::Note.new("C1").transpose_up(major_third).name   #=> "E1"
Music::Note.new("E1").transpose_down(major_third).name #=> "C1"

# Difference
Music::Note.new("C2") - Music::Note.new("C1") #=> #<Music::Interval @number=8, @quality=:perfect>

Music::Chord

chord = Music::Chord.new("C#7")
chord.root.name #=> "C#"
chord.kind      #=> "7"

# Notes
Music::Chord.new("C").notes.map(&:name)   #=> ["C", "E", "G"]
Music::Chord.new("Cm7").notes.map(&:name) #=> ["C", "Eb", "G", "Bb"]

# Transposing
major_third = Music::Interval.new(3, :major)
Music::Chord.new("C").transpose_up(major_third).notes.map(&:name) #=> ["E", "G#", "B"]

Music::Interval

interval = Music::Interval.new(3, :minor)
interval.number  #=> 3
interval.quality #=> :minor

# Comparison
Music::Interval.new(3, :minor) >  Music::Interval.new(2, :major)     #=> true
Music::Interval.new(3, :minor) == Music::Interval.new(2, :augmented) #=> true

# Kinds
Music::Interval.new(6, :major).consonance?           #=> true
Music::Interval.new(6, :major).perfect_consonance?   #=> false (perfect consonances are 1, 4, and 5)
Music::Interval.new(6, :major).imperfect_consonance? #=> true
Music::Interval.new(6, :major).dissonance?           #=> false

# Size
Music::Interval.new(3, :major).size #=> 4 (semitones)

Limitations

  • Currently only triads (C/Cm) and seventh chords (C7/Cm7) are supported. The goal is to support all chords in all notations.

  • Double accidentals (๐„ช and ๐„ซ) are not supported yet.

  • Double augmented/diminished intervals are not supported yet.

Social

You can follow me on Twitter, I'm @jankomarohnic.

License

This project is released under the MIT license.

musique's People

Contributors

janko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sarahshin

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.