tonal


Nametonal JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/thorwhalen/tonal
SummaryTools for music analysis and generation
upload_time2024-08-30 08:49:39
maintainerNone
docs_urlNone
authorThor Whalen
requires_pythonNone
licensemit
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# tonal
Tools for music analysis and generation


To install:	```pip install tonal```


# Examples

## chords


```python
from tonal import chords_to_wav

chord_sequence = [
    ('Bdim', 120),
    ('Em11', 120),
    ('Amin9', 120),
    ('Dm7', 120),
    'G7',
    'Cmaj7',
]

wav_filepath = chords_to_wav(chord_sequence)

```

If you have [hum](https://pypi.org/project/hum/) you can use it to diplay (and hear) 
the sound:

```python
from hum import Sound
Sound.from_file(wav_filepath).display()
```

![image](https://github.com/thorwhalen/sonification/assets/1906276/49e1002c-fbb6-47d8-b642-aaf46b218e0b)


Change the way the chords are played, and what the name (really, filepath) of the 
midi and wav files produce are.

```python
from tonal.chords import play_arpeggio

Sound.from_file(
    chords_to_wav(chord_sequence, name='test_arpeggio', render_chord=play_arpeggio)
).display()
```

![image](https://github.com/thorwhalen/sonification/assets/1906276/0f046317-3965-4544-ae4b-288a0762ec4d)


## counterpoint

```python
The `translate_in_scale` allows you to translate a sequence of notes, or multiple 
tracks of notes by the given number of steps within the given scale.

>>> stream = translate_in_scale(['C4', 'E4', 'B3', 'C4'], -2, 'C')
>>> stream  # doctest: +ELLIPSIS
<music21.stream.Stream ...>
>>> note_names(stream)
['A3', 'C4', 'G3', 'A3']

For multiple tracks:

>>> tracks = [['C4', 'E4', 'G4'], ['A4', 'C5', 'E5']]
>>> translated_tracks = translate_in_scale(tracks, -2, 'C')
>>> multi_note_names(translated_tracks)
[['A3', 'C4', 'E4'], ['F4', 'A4', 'C5']]

Using some other scales:

With a E major scale:

>>> tracks = [['E4', 'G#4', 'B4'], ['C#5', 'E5', 'G#5']]
>>> translated_tracks = translate_in_scale(tracks, 1, 'E')
>>> multi_note_names(translated_tracks)
[['F#4', 'A4', 'C#5'], ['D#5', 'F#5', 'A5']]

With a D flat major scale:

>>> tracks = [['Db4', 'F4', 'Ab4'], ['Bb4', 'Db5', 'F5']]
>>> translated_tracks = translate_in_scale(tracks, -3, 'Db')
>>> multi_note_names(translated_tracks)
[['A-3', 'C4', 'E-4'], ['F4', 'A-4', 'C5']]

Now let's use a different, "custom" scale, as well as demonstrate the use
of a partial function to get a translator with a fixed input scale:

>>> from functools import partial
>>> from music21.scale import HarmonicMinorScale
>>> translate = partial(
...     translate_in_scale, input_scale='A', scale_creator=HarmonicMinorScale
... )
>>> tracks = [['A4', 'C5', 'E5'], ['G#5', 'A5', 'C6']]
>>> translated_tracks = translate(tracks, 2)
>>> multi_note_names(translated_tracks)
[['C5', 'E5', 'G#5'], ['B5', 'C6', 'E6']]
```

Let's make a four part cycling V-I progression.

```python
from tonal.counterpoint import translate_in_scale, create_score_from_tracks
from tonal.util import play_music21_object

motif = [
    "C4 C4".split(),
    "E4 E4".split(),
    "G4 F4".split(),
    "B4 A4".split(),
]

tracks = translate_in_scale(motif, range(7, -14, -1), 'C')
score = create_score_from_tracks(tracks)
score.show()
play_music21_object(score)
```

<img width="653" alt="image" src="https://github.com/thorwhalen/tonal/assets/1906276/95f14372-e711-4fb5-8024-4692cd25956a">

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thorwhalen/tonal",
    "name": "tonal",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Thor Whalen",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/fc/c3/83d885e60e64a33900e3a88e73d5d0d6a6ff3fb89b0518674951fd8fdcec/tonal-0.0.6.tar.gz",
    "platform": "any",
    "description": "\n# tonal\nTools for music analysis and generation\n\n\nTo install:\t```pip install tonal```\n\n\n# Examples\n\n## chords\n\n\n```python\nfrom tonal import chords_to_wav\n\nchord_sequence = [\n    ('Bdim', 120),\n    ('Em11', 120),\n    ('Amin9', 120),\n    ('Dm7', 120),\n    'G7',\n    'Cmaj7',\n]\n\nwav_filepath = chords_to_wav(chord_sequence)\n\n```\n\nIf you have [hum](https://pypi.org/project/hum/) you can use it to diplay (and hear) \nthe sound:\n\n```python\nfrom hum import Sound\nSound.from_file(wav_filepath).display()\n```\n\n![image](https://github.com/thorwhalen/sonification/assets/1906276/49e1002c-fbb6-47d8-b642-aaf46b218e0b)\n\n\nChange the way the chords are played, and what the name (really, filepath) of the \nmidi and wav files produce are.\n\n```python\nfrom tonal.chords import play_arpeggio\n\nSound.from_file(\n    chords_to_wav(chord_sequence, name='test_arpeggio', render_chord=play_arpeggio)\n).display()\n```\n\n![image](https://github.com/thorwhalen/sonification/assets/1906276/0f046317-3965-4544-ae4b-288a0762ec4d)\n\n\n## counterpoint\n\n```python\nThe `translate_in_scale` allows you to translate a sequence of notes, or multiple \ntracks of notes by the given number of steps within the given scale.\n\n>>> stream = translate_in_scale(['C4', 'E4', 'B3', 'C4'], -2, 'C')\n>>> stream  # doctest: +ELLIPSIS\n<music21.stream.Stream ...>\n>>> note_names(stream)\n['A3', 'C4', 'G3', 'A3']\n\nFor multiple tracks:\n\n>>> tracks = [['C4', 'E4', 'G4'], ['A4', 'C5', 'E5']]\n>>> translated_tracks = translate_in_scale(tracks, -2, 'C')\n>>> multi_note_names(translated_tracks)\n[['A3', 'C4', 'E4'], ['F4', 'A4', 'C5']]\n\nUsing some other scales:\n\nWith a E major scale:\n\n>>> tracks = [['E4', 'G#4', 'B4'], ['C#5', 'E5', 'G#5']]\n>>> translated_tracks = translate_in_scale(tracks, 1, 'E')\n>>> multi_note_names(translated_tracks)\n[['F#4', 'A4', 'C#5'], ['D#5', 'F#5', 'A5']]\n\nWith a D flat major scale:\n\n>>> tracks = [['Db4', 'F4', 'Ab4'], ['Bb4', 'Db5', 'F5']]\n>>> translated_tracks = translate_in_scale(tracks, -3, 'Db')\n>>> multi_note_names(translated_tracks)\n[['A-3', 'C4', 'E-4'], ['F4', 'A-4', 'C5']]\n\nNow let's use a different, \"custom\" scale, as well as demonstrate the use\nof a partial function to get a translator with a fixed input scale:\n\n>>> from functools import partial\n>>> from music21.scale import HarmonicMinorScale\n>>> translate = partial(\n...     translate_in_scale, input_scale='A', scale_creator=HarmonicMinorScale\n... )\n>>> tracks = [['A4', 'C5', 'E5'], ['G#5', 'A5', 'C6']]\n>>> translated_tracks = translate(tracks, 2)\n>>> multi_note_names(translated_tracks)\n[['C5', 'E5', 'G#5'], ['B5', 'C6', 'E6']]\n```\n\nLet's make a four part cycling V-I progression.\n\n```python\nfrom tonal.counterpoint import translate_in_scale, create_score_from_tracks\nfrom tonal.util import play_music21_object\n\nmotif = [\n    \"C4 C4\".split(),\n    \"E4 E4\".split(),\n    \"G4 F4\".split(),\n    \"B4 A4\".split(),\n]\n\ntracks = translate_in_scale(motif, range(7, -14, -1), 'C')\nscore = create_score_from_tracks(tracks)\nscore.show()\nplay_music21_object(score)\n```\n\n<img width=\"653\" alt=\"image\" src=\"https://github.com/thorwhalen/tonal/assets/1906276/95f14372-e711-4fb5-8024-4692cd25956a\">\n",
    "bugtrack_url": null,
    "license": "mit",
    "summary": "Tools for music analysis and generation",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/thorwhalen/tonal"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f3042e75fd5e0a2ceab68e1b03972487f62984fabb3a794323722ba0908160f0",
                "md5": "03fe40e3bb47f7845a2965b47ed0f49d",
                "sha256": "b52dd1268addccb3e2a96c203bab97f8910855ac0def4364419e29259446e301"
            },
            "downloads": -1,
            "filename": "tonal-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "03fe40e3bb47f7845a2965b47ed0f49d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 13888,
            "upload_time": "2024-08-30T08:49:36",
            "upload_time_iso_8601": "2024-08-30T08:49:36.386974Z",
            "url": "https://files.pythonhosted.org/packages/f3/04/2e75fd5e0a2ceab68e1b03972487f62984fabb3a794323722ba0908160f0/tonal-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fcc383d885e60e64a33900e3a88e73d5d0d6a6ff3fb89b0518674951fd8fdcec",
                "md5": "8b323f933bf791ad219a73753dd060e1",
                "sha256": "03394b8a30d645264ac00468c757bef1dfea5f85635fd96e97584d3c75fd0ef8"
            },
            "downloads": -1,
            "filename": "tonal-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "8b323f933bf791ad219a73753dd060e1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12928,
            "upload_time": "2024-08-30T08:49:39",
            "upload_time_iso_8601": "2024-08-30T08:49:39.111884Z",
            "url": "https://files.pythonhosted.org/packages/fc/c3/83d885e60e64a33900e3a88e73d5d0d6a6ff3fb89b0518674951fd8fdcec/tonal-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-30 08:49:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thorwhalen",
    "github_project": "tonal",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "tonal"
}
        
Elapsed time: 0.52473s