Guest User

Untitled

a guest
May 27th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. # Created using the Midi Library Gem created by Jim Menerad
  2.  
  3. # This script generates plain text into a single midi Track
  4. # All Converion and Application logic Created & Designed by Gabriel G. Updated Aug 24th 2008
  5. # char "alphabet" Ascii range is 65-122 (not including 91-96) lowercase 97-122 uppercase 65-90
  6. #
  7. # Added Features
  8. # Menu with converting options Read as Followed
  9. # 1 => User input of text
  10. # 2 => Read in a text file
  11. # 3 => User Choose a number of random letters to be generated
  12. require 'rubygems'
  13. require 'midilib'
  14.  
  15.  
  16. class Array
  17.  
  18. def to_midi(file, note_length='whole')
  19. midi_max = 108.0
  20. midi_min = 21.0
  21. low, high = min, max
  22.  
  23. song = MIDI::Sequence.new
  24. song.tracks << (melody = MIDI::Track.new(song))
  25.  
  26. melody.events <<
  27. MIDI::Tempo.new(MIDI::Tempo.bpm_to_mpq(120))
  28. melody.events << MIDI::ProgramChange.new(0, 0)
  29. each do |number|
  30. midi_note = (midi_min + ((number-midi_min) * (midi_max-low)/high)).to_i
  31. melody.events << MIDI::NoteOnEvent.new(0, midi_note, 127, 0)
  32. melody.events << MIDI::NoteOffEvent.new(0, midi_note, 127,
  33. song.note_to_delta(note_length))
  34. end
  35. open(file, 'w') { |f| song.write(f) }
  36. end
  37. end
  38.  
  39. # WORKS Converts a Requested txt File into Midi
  40. midi_me_array=[]
  41. puts "Please enter the title of this track"
  42. title=gets.upcase.chomp
  43. puts
  44. puts"Please enter the text file name you are looking for"
  45. text =gets.upcase.chomp!
  46. IO.foreach("#{text}"){|line| p line}
  47. IO.foreach("#{text}") do |line|
  48. line.upcase.each_byte {|c| midi_me_array << c - 5 }
  49. puts midi_me_array
  50. end
  51. midi_me_array.to_midi("#{title}.mid")
Add Comment
Please, Sign In to add comment