Skip to content

Step: Play Midi from code to debug #46

@EloiStree

Description

@EloiStree

You may want to play midi to make sound.
But it is also nice for debugging purpose.
So let s look around if we can make a python midi player to be call from UDP message and IID

To test 🤖

import pygame.midi
import time

# Initialize MIDI
pygame.midi.init()

# Open the default output device
player = pygame.midi.Output(pygame.midi.get_default_output_id())

instrument = 0  # 0 = Acoustic Grand Piano
player.set_instrument(instrument)

# Notes for a C major scale (C4 to C5)
notes = [60, 62, 64, 65, 67, 69, 71, 72]

for note in notes:
    player.note_on(note, 127)   # note_on(note, velocity)
    time.sleep(0.5)             # play for 0.5s
    player.note_off(note, 127)

# Cleanup
del player
pygame.midi.quit()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions