Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Created using the Midi Library Gem created by Jim Menerad
- # This script generates plain text into a single midi Track
- # All Converion and Application logic Created & Designed by Gabriel G. Updated Aug 24th 2008
- # char "alphabet" Ascii range is 65-122 (not including 91-96) lowercase 97-122 uppercase 65-90
- #
- # Added Features
- # Menu with converting options Read as Followed
- # 1 => User input of text
- # 2 => Read in a text file
- # 3 => User Choose a number of random letters to be generated
- require 'rubygems'
- require 'midilib'
- class Array
- def to_midi(file, note_length='whole')
- midi_max = 108.0
- midi_min = 21.0
- low, high = min, max
- song = MIDI::Sequence.new
- song.tracks << (melody = MIDI::Track.new(song))
- melody.events <<
- MIDI::Tempo.new(MIDI::Tempo.bpm_to_mpq(120))
- melody.events << MIDI::ProgramChange.new(0, 0)
- each do |number|
- midi_note = (midi_min + ((number-midi_min) * (midi_max-low)/high)).to_i
- melody.events << MIDI::NoteOnEvent.new(0, midi_note, 127, 0)
- melody.events << MIDI::NoteOffEvent.new(0, midi_note, 127,
- song.note_to_delta(note_length))
- end
- open(file, 'w') { |f| song.write(f) }
- end
- end
- # WORKS Converts a Requested txt File into Midi
- midi_me_array=[]
- puts "Please enter the title of this track"
- title=gets.upcase.chomp
- puts
- puts"Please enter the text file name you are looking for"
- text =gets.upcase.chomp!
- IO.foreach("#{text}"){|line| p line}
- IO.foreach("#{text}") do |line|
- line.upcase.each_byte {|c| midi_me_array << c - 5 }
- puts midi_me_array
- end
- midi_me_array.to_midi("#{title}.mid")
Add Comment
Please, Sign In to add comment