Skip to content

Instantly share code, notes, and snippets.

@jvoorhis
Created February 22, 2009 23:06
Show Gist options
  • Save jvoorhis/68671 to your computer and use it in GitHub Desktop.
Save jvoorhis/68671 to your computer and use it in GitHub Desktop.
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