Created
August 16, 2013 08:57
-
-
Save kafecho/6248352 to your computer and use it in GitHub Desktop.
Random MIDI tune with Scala and the Java MIDI API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.kafecho.learning.midi | |
import javax.sound.midi.MidiSystem | |
import javax.sound.midi.ShortMessage | |
import scala.util.Random | |
object MidiTest extends App { | |
val rcvr = MidiSystem.getReceiver | |
while (true) { | |
val myMsg = new ShortMessage | |
myMsg.setMessage(ShortMessage.NOTE_ON, 8, Random.nextInt.abs % 127, 93) | |
rcvr.send(myMsg, -1) | |
Thread.sleep(100) | |
} | |
} |
I did quite a lot of MIDI work but that was ages ago, however I can't remember from the top of my head. Have a look at: http://docs.oracle.com/javase/tutorial/sound/ for inspiration
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THANK YOU SO MUCH FOR POSTING THIS CODE! I'VE BEEN TRYING TO FIGURE OUT HOW TO GENERATE SOUND, IN A SIMPLE WAY, USING SCALA (USING OS X) FOR 3 WEEKS. WHEN YOU HAVE TIME, CAN YOU PLEASE CREATE AN EXAMPLE OF HOW TO CHANGE THE TYPE OF SOUND /INSTRUMENT THAT'S PLAYED?
THANK YOU
WARRIOR XXL