Skip to content

Instantly share code, notes, and snippets.

@pedrolcl
Last active October 2, 2019 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrolcl/61e85d6712bf37fab038e4cfb04b1c84 to your computer and use it in GitHub Desktop.
Save pedrolcl/61e85d6712bf37fab038e4cfb04b1c84 to your computer and use it in GitHub Desktop.
import pygame.midi
import time
pygame.midi.init()
#list all midi devices
for x in range( 0, pygame.midi.get_count() ):
print(x,"=",pygame.midi.get_device_info(x))
player = pygame.midi.Output(2)
player.set_instrument(0)
player.note_on(60, 127)
print("PLAYING")
time.sleep(1)
player.note_off(60, 127)
print("STOPPED")
del player
pygame.midi.quit()
@pedrolcl
Copy link
Author

pedrolcl commented Oct 2, 2019

C:\tmp>python3 testpygame.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
0 = (b'MMSystem', b'Microsoft MIDI Mapper', 0, 1, 0)
1 = (b'MMSystem', b'VirtualMIDISynth #1', 0, 1, 0)
2 = (b'MMSystem', b'Microsoft GS Wavetable Synth', 0, 1, 0)
PLAYING
STOPPED

@pedrolcl
Copy link
Author

pedrolcl commented Oct 2, 2019

$ python3 testpygame.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
0 = (b'CoreMIDI', b'VMPK Output', 1, 0, 0)
1 = (b'CoreMIDI', b'VMPK Input', 0, 1, 0)
2 = (b'CoreMIDI', b'SimpleSynth virtual input', 0, 1, 0)
PLAYING
STOPPED

@pedrolcl
Copy link
Author

pedrolcl commented Oct 2, 2019

Output in Linux:
0 = (b'ALSA', b'Midi Through Port-0', 0, 1, 0)
1 = (b'ALSA', b'Midi Through Port-0', 1, 0, 0)
2 = (b'ALSA', b'UM-2 MIDI 1', 0, 1, 0) <-- here is my synth
3 = (b'ALSA', b'UM-2 MIDI 1', 1, 0, 0)
4 = (b'ALSA', b'UM-2 MIDI 2', 0, 1, 0)
5 = (b'ALSA', b'UM-2 MIDI 2', 1, 0, 0)
PLAYING
STOPPED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment