Metadata-Version: 2.1
Name: midigen
Version: 0.0.7
Author-email: Bryan Johnson <d.bryan.johnson@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Bryan Johnson
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/dbjohnson/midigen
Keywords: midi,generative,audio,music
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Provides-Extra: dev
License-File: LICENSE

# midigen
[![License](https://img.shields.io/github/license/dbjohnson/midigen.svg)]()
[![PyPi](https://img.shields.io/pypi/v/midigen.svg)](https://pypi.python.org/pypi/midigen)
![GHA](https://github.com/dbjohnson/midigen/actions/workflows/tests.yml/badge.svg)


Python library for generating simple chord progression midi files

[demo](https://dbjohnson.github.io/midigen/)

## Installation
```cmd
pip install midigen
```

## Example usage
### Command line

Play a `ii-V-I-vi` pattern in the key of `G`; loop it four times 
```cmd
midigen --key G --chords ii V I vi  --loop 4 --play
```

### Python


```python
import mido
from midigen.notes import Note
from midigen.keys import Key, Mode
from midigen.time import TimeSignature, Measure
from midigen.sequencer import Song, Track


# open new midi port via mido
port = mido.open_output('midigen', virtual=True)

# play C minor scale
Key(Note.C, Mode.Minor).to_track().play(port)

# make a simple ii V I vi chord progression in the key of C
key = Key(Note.C, Mode.Major)
time_signature = TimeSignature(4, 4)
tempo = 90
progression = [2, 5, 1, 6]

chords = Track.from_measures([
    Measure.from_pattern(
        pattern=[
            key.relative_key(degree).chord(
                # default chords are the base triad - try adding extensions
                extensions=[7],
                # pick a voicing close to the root triad
                match_voicing=key.triad()
            )
        ] * time_signature.numerator,
        time_signature=time_signature,
        velocity=90
    )
    for degree in progression
])

# play to port
chords.play(port, tempo=tempo)

# write the song to a MIDI file
Song([chords]).to_midi('midigen.mid', tempo=tempo)
```
