Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Music and Sound Editing/Generation from MIDI or MML Possible? #589

Open
cannin opened this issue Dec 26, 2024 · 1 comment
Open

Music and Sound Editing/Generation from MIDI or MML Possible? #589

cannin opened this issue Dec 26, 2024 · 1 comment

Comments

@cannin
Copy link

cannin commented Dec 26, 2024

Is it possible to convert MIDI or MML (Music Macro Language) for use with Pyxel? The MML format seems to be similar to what Pyxel uses; is this correct? Is there any automated method (or tips) for converting from MIDI sounds to Pyxel perhaps through MML? Below is my attempt to compare using a simple song. The notes in Pyxel do not seem distinct unless the "r" (rest) pauses are added.

https://onlinesequencer.net/259904 (listen online; download as MIDI file)

https://archeagemmllibrary.com/twinkle-twinkle-little-star/

MML@ccggaag2ffeeddc2ggffeed2ggffeed2ccggaag2ffeeddc2

Demo pyxel App (my manual attempt)

import pyxel

class TwinkleApp:
    def __init__(self):
        pyxel.init(200, 150, title="Twinkle Twinkle Little Star")

        # Define the full melody for the song
        pyxel.sounds[0].set(
            # Melody for the entire song
            (
                "c2rc2rg2rg2ra2ra2rg2r"  # Twinkle, twinkle, little star
                "f2rf2re2re2rd2rd2rc2r"  # How I wonder what you are
                "g2rg2rf2rf2re2re2rd2r"  # Up above the world so high
                "g2rg2rf2rf2re2re2rd2r"  # Like a diamond in the sky
                "c2rc2rg2rg2ra2ra2rg2r"  # Twinkle, twinkle, little star
                "f2rf2re2re2rd2rd2rc2r"  # How I wonder what you are
            ),
            "s",  # Square wave
            "4",  # Volume
            "n",  # No effects
            30,    # Speed
        )

        # Play the melody in loop
        pyxel.play(0, [0], loop=True)

        pyxel.run(self.update, self.draw)

    def update(self):
        if pyxel.btnp(pyxel.KEY_Q):  # Quit the app with Q key
            pyxel.quit()

    def draw(self):
        pyxel.cls(0)
        pyxel.text(20, 70, "Playing Twinkle Twinkle Little Star", 7)
        pyxel.text(20, 90, "Press Q to Quit", 7)

TwinkleApp()
@kitao
Copy link
Owner

kitao commented Dec 29, 2024

Pyxel's text music format is different from MML, but I'm planning to implement the MML feature in 2.2.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants