Skip to content

PymidAI is a collection of simple Python scripts designed for generating MIDI files. It works by taking arrays of notes generated by Large Language Models (LLMs)

License

Notifications You must be signed in to change notification settings

EmberNoGlow/PymidAI-Python_Simple_MIDI_Generator_Using_LLM_No_API

Repository files navigation

PymidAI - Python Simple MIDI Generator Using LLM (No API)

Python Library License


What is it?

PymidAI is a collection of simple Python scripts designed for generating MIDI files. It works by taking arrays of notes generated by Large Language Models (LLMs) like ChatGPT, Grok, Deepseek, Gemini, and others. Importantly, PymidAI does not require a direct API for interaction with LLMs.

🔥 How it Works

PymidAI is built for simplicity and accessibility. Follow these steps to create your own MIDI melodies:

  1. Get Note Arrays from an LLM: Use the example prompts provided in the Examples AI Requests folder, or create your own, to generate sequences of notes. The LLM should output data in an array format similar to this:

    [
        # Intro - tremolo motif
        (64, 0.125), (64, 0.125), (67, 0.25), (71, 0.5),  # E-G-B
        (63, 0.333), (66, 0.333), (70, 0.333),  # D#-F#-A triplet
    
        # A Section - ascending sequence
        (64, 0.25), (65, 0.25), (67, 0.25), (69, 0.25),  # E-F-G-A
        (72, 0.75), (71, 0.125), (69, 0.125),  # High B with grace notes
    
        # Chromatic bridge
        (76, 0.5), (75, 0.25), (74, 0.25),  # E-F♯-G
        (73, 0.25), (72, 0.25), (71, 0.25), (70, 0.25),  # Semi-tonal descent
        
        # ... continued for 160 beats (for example) ...
    ]

    Each tuple (pitch, duration) represents a note:

    • pitch: The MIDI note number (e.g., 64 for E4, 67 for G4).
    • duration: The duration of the note in beats (e.g., 0.25 for a quarter note, 0.5 for a half note).
  2. Paste the Array into the Script:

    • For a single melody: Copy your generated array into the mid_gen.py file in the melody variable.
    • For dual hands (treble/bass): Copy your respective arrays into dual_hands_mid_gen.py into the treble and bass variables.
  3. Run the Script: Execute the Python script from your command line:

    python mid_gen.py

    or

    python dual_hands_mid_gen.py

    Upon completion, the script will generate a MIDI file in the current directory.

  4. Open Your MIDI File: You can open the created MIDI file in any Digital Audio Workstation (DAW) such as Reaper, FL Studio, Ableton Live, or use music learning software like Synthesia. Example MIDI files are available in the ExampleMidi folder.

📚 Data Structure Parameters:

Notes_array: List of events where each event is:

        (pitch, duration)         -> Single note
        ([p1, p2, ...], duration) -> Chord
        (None, duration)          -> Rest

🚀 Features

  • Easy to Use: Quickly create short, simple melodies.
  • Uses midiutil: A robust library for MIDI file creation.
  • Clear Code: The code is very simple and ideal for learning MIDI manipulation in Python.
  • Flexibility: You can generate single-hand or dual-hand melodies using different scripts.

👊 Limitations

  • Quality Depends on LLM Prompts: The output is directly dependent on the quality of your prompts to the LLM. It's highly recommended to study the example prompts in the Examples AI Requests folder.
  • No Direct API: PymidAI does not integrate directly with LLMs. You will need to generate your note arrays independently using web interfaces or other available tools.

About

PymidAI is a collection of simple Python scripts designed for generating MIDI files. It works by taking arrays of notes generated by Large Language Models (LLMs)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages