Giter Site home page Giter Site logo

musthe's Introduction

musthe

Music theory implemented in Python. Notes, scales and chords.

It is still in development so feel free to read the code, fork and make pull requests! They are very welcome!

Installation

To install:

$ pip install musthe

Development install

To install as development:

(Optional) Create a virtualenv:

$ python -m venv env
$ source env/bin/activate

Then install:

$ pip install -e .

How to use

It is very simple, everything is coded in a object-oriented style, for example:

$ python
>>> from musthe import *
>>> a = Note('A')  #Default A4
>>> a
Note("A4")
>>> str(a)
'A'

Suppose you want to create tension, so you want the perfect fifth or the minor seventh of that A, so you do:

>>> fifth = Interval('P5')
>>> seventh = Interval('m7')
>>> a+fifth
Note("E5")
>>> str(a+fifth)
'E'
>>> str(a+seventh)
'G'

Though it is important to see that the octaves of those notes are different:

>>> a.octave
4
>>> (a+seventh).octave
5

Now let's see basic chord usage:

>>> Chord(Note('A'), 'M')
Chord(Note('A'), 'M')
>>> Chord(Note('A'), 'M').notes
[Note("A4"), Note("C#5"), Note("E5")]
>>> Chord(Note('Bb'), 'dim').notes
[Note("Bb4"), Note("Db5"), Note("Fb5")]

You can use a string to construct a chord:

>>> Chord('C#aug7') == Chord(Note('C#'), 'aug7')
True

Default chord type is 'M' (Major).

Now lets try scales:

>>> s = Scale(Note('B'), 'major')
>>> [s[i] for i in range(len(s))]
[Note('B4'), Note('C#5'), Note('D#5'), Note('E5'), Note('F#5'), Note('G#5'), Note('A#5')]
>>> s[0]
Note('B4')
>>> s[-11]
Note('E3')

It return a list of Note instances, so if you want a cleaner result should do something like:

>>> s = Scale(Note('B'), 'major')
>>> [str(s[i]) for i in range(len(s))]
['B', 'C#', 'D#', 'E', 'F#', 'G#', 'A#']

To check if notes and chords are contained in a given scale:

>>> Note('D#3') in s
True
>>> Note('F3') in s
False
>>> Chord('C#m') in s
True
>>> Chord('CM') in s
False

Now let's try some advanced stuff: given a list of chords, find all scales that contain those:

>>> chords = [Chord('Cm'), Chord('Fm7'), Chord('Gm')]
>>> for scale in Scale.all():
...     if chords in scale:
...         print(scale)
...
C natural_minor
Eb major

If you have lilypond installed, you can make little melodies using this program, an example is given in 'lilypond_example.py'

Running Tests

From the project root directory, run:

python -m tests.tests

Contributors

License

See license file.

musthe's People

Contributors

barrio avatar bobthenameless avatar edxnull avatar fferri avatar gciruelos avatar guswynn avatar mystery-house avatar nvoster avatar srir avatar sylvainde avatar usonian avatar wfletch avatar zsinx6 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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

musthe's Issues

C# != Db

>>> Note('C#4') == Note('Db4') 
False

How refactor project to a standard python package?

I was wondering about that because I wanna put on Arch Linux Repository and provide too a simple command line interface to do some cool stuff like:

> musthe scale c-major
C D E F G A B

How about that?

why is 12.

%12 because it wraps in B->C and starts over.

why is 12.

and

" e.g. the fifth of

E is: (E F G A) B."

what it's meaning?

thanks for your answer.

Exception: Could not parse the note: C#######################4

>>> from musthe.musthe import *
>>> scale(Note('F'), 'locrian')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    scale(Note('F'), 'locrian')
  File "[...]/musthe/musthe/musthe.py", line 26, in scale
    return [note] + [note+Interval(i) for i in scales[scale_name]]
  File "[...]/musthe/musthe/musthe.py", line 26, in <listcomp>
    return [note] + [note+Interval(i) for i in scales[scale_name]]
  File "[...]/musthe/musthe/musthe.py", line 118, in __add__
    return Note(new_note_tone+accidental+str(new_note_octave))
  File "[...]/musthe/musthe/musthe.py", line 57, in __init__
    raise Exception('Could not parse the note: '+note)
Exception: Could not parse the note: C#######################4

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.