简体   繁体   中英

No MIDI sound using CoreMIDI, Ruby, Mac OS X Lion

I am reading the book, "Practical Ruby Projects" and just finished chapter 2 where the author gives the Ruby code to play some MIDI sound using a software called "SimpleSynth." Here's link to the particular example: https://github.com/mattybojo/midi_music/blob/master/music.rb

On Mac OS, you're supposed to open a free software called FreeSynth: ( http://notahat.com/simplesynth/ ) which will enable you to hear the sounds being played.

I am supposed to hear something, but I hear nothing after running this code. The script is working correctly. Whenever I close the "FreeSynth" software, Ruby throws out "noMIDIDestinations" error.

Here's the error declaration: class NoMIDIDestinations < Exception; end

And this is the code to raise the exception:

num = C.mIDIGetNumberOfDestinations()
raise NoMIDIDestinations if num < 1    # If no MIDI devices listening raise exception

This basically means that there is no application listenng for MIDI signals.

If I run it with FreeSynth open, it does not throw this exception and I can see it pausing in between the sleep statements.

# This is the code that outputs the sound to a listening MIDI synth
midi = LiveMIDI.new
midi.note_on(0, 60, 100)
sleep(1)
midi.note_off(0, 60)
sleep(1)
midi.program_change(1, 40)
midi.note_on(1, 60, 100)
sleep(1)
midi.note_off(1, 60)

So the script is working correctly, it's just something else that is the problem.

Can anybody help me out with this?

I think the problem might be with the MIDI within MacOS, but I'm not a sound guy, all this MIDI stuff goes over my head. I looked around to see if there was any major change in CoreAudio (Apple's sound framework) regarding MIDI, but didn't find any.

I'm on Macbook Pro, Lion. Are there any alternatives to using the FreeSynth? I downloaded a couple of MIDI Synthesizers but they only had a file named "component." So I'm guessing it's not what I need.

Thanks in advance.

OK, finally found it. Found this: https://www.ruby-toolbox.com/categories/music_midi and https://github.com/arirusso/unimidi

Thanks to folks over at reddit.com/r/ruby http://www.reddit.com/r/ruby/comments/1hwwk5/need_help_finding_a_software_that_takes_in_midi/ Love Reddit.

Note: For some reason stackoverflow does not support URL address with double underscore. The first url is actually "music__midi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM