Is there a way to play midi sound without having another application such as garageband opened?
I have the code below where I'm trying to play a note in mac from a python application. Unfortunately I have noticed that the only way that the sound is audible is when garageband is opened.
Is there a way to play midi sound without having another application such as garageband opened?
I know this is possible in java.
import time
import rtmidi as rtmidi
def open_midi():
midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
if available_ports:
print("Available ports")
midiout.open_port(0)
else:
print("Opening virtual ports")
midiout.open_virtual_port("My virtual output")
return midiout
def play(note):
with open_midi() as midiout:
while True:
note_on = [0x90, note, 112] # channel 1, middle C, velocity 112
note_off = [0x80, note, 0]
midiout.send_message(note_on)
time.sleep(0.5)
midiout.send_message(note_off)
time.sleep(0.1)
del midiout
play(60)