https://github.com/janko/musique
A Ruby gem for manipulating musical constructs.
https://github.com/janko/musique
arithmetic chords intervals music notes ruby scales
Last synced: 6 months ago
JSON representation
A Ruby gem for manipulating musical constructs.
- Host: GitHub
- URL: https://github.com/janko/musique
- Owner: janko
- License: mit
- Created: 2014-01-19T14:37:26.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-04-21T16:40:07.000Z (over 11 years ago)
- Last Synced: 2025-04-03T15:47:11.369Z (7 months ago)
- Topics: arithmetic, chords, intervals, music, notes, ruby, scales
- Language: Ruby
- Homepage:
- Size: 195 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Musique
Musique is a gem for manipulating with musical constructs, such as notes,
chords and intervals.* Source code: [https://github.com/janko-m/musique](https://github.com/janko-m/musique)
* API Documenation: [http://rubydoc.info/github/janko-m/musique/master/frames](http://rubydoc.info/github/janko-m/musique/master/frames)Installation
------------```sh
$ gem install musique
```Usage
-----### `Music::Note`
```rb
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::Chord`
```rb
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`
```rb
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](http://twitter.com/jankomarohnic).
License
-------This project is released under the [MIT license](/LICENSE).