Created
February 22, 2009 23:06
-
-
Save jvoorhis/68671 to your computer and use it in GitHub Desktop.
This file contains 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
require 'audio_toolbox' | |
include AudioToolbox | |
player = MusicPlayer.new | |
sequence = MusicSequence.new | |
player.sequence = sequence | |
sequence.midi_endpoint = CoreMIDI.get_destination(ARGV.shift.to_i) | |
tempo = sequence.tracks.tempo | |
tempo.add 0.0, ExtendedTempoEvent.new(:bpm => 120.0) | |
track = MusicTrack.new(sequence) | |
track.add 0.0, MIDINoteMessage.new(:note => 60, :velocity => 64) | |
track.add 1.0, MIDINoteMessage.new(:note => 64, :velocity => 96) | |
track.add 2.0, MIDINoteMessage.new(:note => 67, :velocity => 110) | |
track.add 3.0, MIDINoteMessage.new(:note => 60, :velocity => 110, :duration => 2.0) | |
track.add 3.0, MIDINoteMessage.new(:note => 64, :velocity => 110, :duration => 2.0) | |
track.add 3.0, MIDINoteMessage.new(:note => 67, :velocity => 110, :duration => 2.0) | |
track.add 3.0, MIDINoteMessage.new(:note => 72, :velocity => 110, :duration => 2.0) | |
player.start | |
sleep 3 | |
player.stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment